mirror of
https://github.com/yannbertrand/macos-defaults
synced 2024-12-15 06:02:40 +00:00
75 lines
4.2 KiB
JavaScript
75 lines
4.2 KiB
JavaScript
const fs = require('fs')
|
|
const Handlebars = require('handlebars')
|
|
|
|
module.exports = (defaults, destinationPath) => {
|
|
fs.mkdirSync(destinationPath)
|
|
fs.mkdirSync(`${destinationPath}/.vuepress`)
|
|
fs.mkdirSync(`${destinationPath}/.vuepress/public`)
|
|
fs.mkdirSync(`${destinationPath}/.vuepress/styles`)
|
|
|
|
fs.copyFileSync('./templates/.vuepress/public/android-chrome-192x192.png', `${destinationPath}/.vuepress/public/android-chrome-192x192.png`)
|
|
fs.copyFileSync('./templates/.vuepress/public/android-chrome-512x512.png', `${destinationPath}/.vuepress/public/android-chrome-512x512.png`)
|
|
fs.copyFileSync('./templates/.vuepress/public/apple-touch-icon.png', `${destinationPath}/.vuepress/public/apple-touch-icon.png`)
|
|
fs.copyFileSync('./templates/.vuepress/public/browserconfig.xml', `${destinationPath}/.vuepress/public/browserconfig.xml`)
|
|
fs.copyFileSync('./templates/.vuepress/public/favicon.ico', `${destinationPath}/.vuepress/public/favicon.ico`)
|
|
fs.copyFileSync('./templates/.vuepress/public/favicon-16x16.png', `${destinationPath}/.vuepress/public/favicon-16x16.png`)
|
|
fs.copyFileSync('./templates/.vuepress/public/favicon-32x32.png', `${destinationPath}/.vuepress/public/favicon-32x32.png`)
|
|
fs.copyFileSync('./templates/.vuepress/public/logo.svg', `${destinationPath}/.vuepress/public/logo.svg`)
|
|
fs.copyFileSync('./templates/.vuepress/public/mstile-150x150.png', `${destinationPath}/.vuepress/public/mstile-150x150.png`)
|
|
fs.copyFileSync('./templates/.vuepress/public/robots.txt', `${destinationPath}/.vuepress/public/robots.txt`)
|
|
fs.copyFileSync('./templates/.vuepress/public/safari-pinned-tab.svg', `${destinationPath}/.vuepress/public/safari-pinned-tab.svg`)
|
|
fs.copyFileSync('./templates/.vuepress/public/site.webmanifest', `${destinationPath}/.vuepress/public/site.webmanifest`)
|
|
fs.copyFileSync('./templates/.vuepress/styles/index.styl', `${destinationPath}/.vuepress/styles/index.styl`)
|
|
fs.copyFileSync('./templates/.vuepress/styles/palette.styl', `${destinationPath}/.vuepress/styles/palette.styl`)
|
|
|
|
const homeTemplate = fs.readFileSync('./templates/home.md.handlebars', 'utf8')
|
|
const rootReadmeContent = Handlebars.compile(homeTemplate)(defaults)
|
|
fs.writeFileSync(`${destinationPath}/readme.md`, rootReadmeContent)
|
|
|
|
const vuepressConfig = fs.readFileSync('./templates/.vuepress/config.yml.handlebars', 'utf8')
|
|
const vuepressConfigContent = Handlebars.compile(vuepressConfig)(defaults)
|
|
fs.writeFileSync(`${destinationPath}/.vuepress/config.yml`, vuepressConfigContent)
|
|
|
|
if (defaults.categories !== null) {
|
|
const categoryTemplate = fs.readFileSync('./templates/category.md.handlebars', 'utf8')
|
|
const renderCategory = Handlebars.compile(categoryTemplate)
|
|
defaults.categories.forEach(category => {
|
|
fs.mkdirSync(`${destinationPath}/${category.folder}`)
|
|
const categoryReadmeContent = renderCategory(category)
|
|
fs.writeFileSync(`${destinationPath}/${category.folder}/readme.md`, categoryReadmeContent)
|
|
|
|
if (category.image !== undefined) {
|
|
fs.copyFileSync(
|
|
`../../images/${category.folder}/${category.image.filename}`,
|
|
`${destinationPath}/${category.folder}/${category.image.filename}`
|
|
)
|
|
}
|
|
})
|
|
|
|
const pageTemplate = fs.readFileSync('./templates/page.md.handlebars', 'utf8')
|
|
const renderPage = Handlebars.compile(pageTemplate)
|
|
defaults.categories.forEach(({ folder, name, keys }) => {
|
|
if (keys === undefined) { return }
|
|
|
|
keys.forEach(({ domain, ...page }) => {
|
|
const pageReadmeContent = renderPage({ ...page, folder, name, domain })
|
|
fs.writeFileSync(`${destinationPath}/${folder}/${page.key}.md`, pageReadmeContent)
|
|
|
|
page.examples.forEach(example => {
|
|
if (example.image !== undefined) {
|
|
fs.copyFileSync(
|
|
`../../images/${folder}/${page.key}/${example.image.filename}`,
|
|
`${destinationPath}/${folder}/${folder}-${page.key}-${example.image.filename}`
|
|
)
|
|
}
|
|
if (example.video !== undefined) {
|
|
fs.copyFileSync(
|
|
`../../images/${folder}/${page.key}/${example.video.filename}`,
|
|
`${destinationPath}/${folder}/${folder}-${page.key}-${example.video.filename}`
|
|
)
|
|
}
|
|
})
|
|
})
|
|
})
|
|
}
|
|
}
|