mirror of
https://github.com/yannbertrand/macos-defaults
synced 2024-11-15 08:07:07 +00:00
🌐 Add internationalization support
This commit is contained in:
parent
9c8b7a2aeb
commit
438cb0590e
12 changed files with 89 additions and 1850 deletions
|
@ -1,10 +1,5 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`write-tree no categories should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree no categories should write an empty readme.md file using the home template 1`] = `
|
||||
"# macOS \`defaults\` list
|
||||
Uncomplete list of macOS \`defaults\` commands with demos ✨
|
||||
|
@ -44,12 +39,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, no page with image should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with image example should write a category/page.md file using the page template 1`] = `
|
||||
"# Page
|
||||
|
||||
|
@ -112,13 +101,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with image example should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
- [Page](category/page)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text and possible values example should write a category/page.md file using the page template 1`] = `
|
||||
"# Page
|
||||
|
||||
|
@ -189,13 +171,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text and possible values example should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
- [Page](category/page)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with an after command should write a category/page.md file using the page template 1`] = `
|
||||
"# Page
|
||||
|
||||
|
@ -256,13 +231,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with an after command should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
- [Page](category/page)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with requirements should write a category/page.md file using the page template 1`] = `
|
||||
"# Page
|
||||
|
||||
|
@ -327,13 +295,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with requirements should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
- [Page](category/page)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with special chars values should write a category/page.md file using the page template 1`] = `
|
||||
"# Page
|
||||
|
||||
|
@ -394,13 +355,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with special chars values should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
- [Page](category/page)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with video example should write a category/page.md file using the page template 1`] = `
|
||||
"# Page
|
||||
|
||||
|
@ -467,13 +421,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with video example should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
- [Page](category/page)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, two pages should write a category/page1.md file using the page template 1`] = `
|
||||
"# Page 1
|
||||
|
||||
|
@ -571,14 +518,6 @@ Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, two pages should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category](category/)
|
||||
- [Page 1](category/page1)
|
||||
- [Page 2](category/page2)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree two categories, one page in each should write a category1/page.md file using the page template 1`] = `
|
||||
"# Page
|
||||
|
||||
|
@ -685,12 +624,3 @@ Please update [this file](https://github.com/yannbertrand/macos-defaults/blob/ma
|
|||
Thank you! I built it using [docsify](https://docsify.js.org/). Take a look at [my report](https://github.com/yannbertrand/macos-defaults/tree/master/build/docsify#readme) if you want to use it.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree two categories, one page in each should write a sidebar config file using the sidebar template 1`] = `
|
||||
"* [Home](/)
|
||||
* [Category 1](category1/)
|
||||
- [Page](category1/page)
|
||||
* [Category 2](category2/)
|
||||
- [Page](category2/page)
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -2,8 +2,29 @@ const fs = require('fs')
|
|||
const YAML = require('yaml')
|
||||
|
||||
const writeTree = require('./write-tree')
|
||||
const writeConfig = require('./write-config')
|
||||
|
||||
const input = fs.readFileSync('../../defaults.yml', 'utf8')
|
||||
const inputFr = fs.readFileSync('../../defaults-fr.yml', 'utf8')
|
||||
const defaults = YAML.parse(input)
|
||||
const defaultsFr = YAML.parse(inputFr)
|
||||
|
||||
writeTree(defaults, 'docs')
|
||||
const templatesPath = 'templates'
|
||||
const destinationPath = 'docs'
|
||||
|
||||
const supportedLanguages = {
|
||||
languages: [
|
||||
{ url: '/fr/', lang: 'fr-FR', home: 'Accueil', defaults: getSafeDefaults(defaultsFr, defaults), isFallback: false },
|
||||
{ url: '/', lang: 'en-US', home: 'Home', defaults: defaults, isFallback: true },
|
||||
]
|
||||
}
|
||||
|
||||
supportedLanguages.languages.forEach((supportedLanguage) => {
|
||||
const { url, isFallback } = supportedLanguage
|
||||
writeTree(supportedLanguage, `${templatesPath}${url}`, `${destinationPath}${url}`)
|
||||
writeConfig(supportedLanguage, supportedLanguages, `${templatesPath}${url}`, `${destinationPath}${url}`, isFallback)
|
||||
})
|
||||
|
||||
function getSafeDefaults(localizedDefaults, fallbackDefaults) {
|
||||
return { ...fallbackDefaults, ...localizedDefaults }
|
||||
}
|
||||
|
|
|
@ -1,22 +1,15 @@
|
|||
const fs = require('fs')
|
||||
const Handlebars = require('handlebars')
|
||||
|
||||
module.exports = (defaults, destinationPath) => {
|
||||
module.exports = (defaults, templatesPath, destinationPath) => {
|
||||
fs.mkdirSync(destinationPath)
|
||||
|
||||
fs.copyFileSync('./templates/index.html', `${destinationPath}/index.html`)
|
||||
fs.copyFileSync('./templates/favicon.ico', `${destinationPath}/favicon.ico`)
|
||||
|
||||
const homeTemplate = fs.readFileSync('./templates/home.md.handlebars', 'utf8')
|
||||
const homeTemplate = fs.readFileSync(`${templatesPath}/home.md.handlebars`, 'utf8')
|
||||
const rootReadmeContent = Handlebars.compile(homeTemplate)(defaults)
|
||||
fs.writeFileSync(`${destinationPath}/readme.md`, rootReadmeContent)
|
||||
|
||||
const sidebarConfigTemplate = fs.readFileSync('./templates/_sidebar.md.handlebars', 'utf8')
|
||||
const sidebarConfigContent = Handlebars.compile(sidebarConfigTemplate)(defaults)
|
||||
fs.writeFileSync(`${destinationPath}/_sidebar.md`, sidebarConfigContent)
|
||||
|
||||
if (defaults.categories !== null) {
|
||||
const categoryTemplate = fs.readFileSync('./templates/category.md.handlebars', 'utf8')
|
||||
const categoryTemplate = fs.readFileSync(`${templatesPath}/category.md.handlebars`, 'utf8')
|
||||
const renderCategory = Handlebars.compile(categoryTemplate)
|
||||
defaults.categories.forEach(category => {
|
||||
fs.mkdirSync(`${destinationPath}/${category.folder}`)
|
||||
|
@ -31,7 +24,7 @@ module.exports = (defaults, destinationPath) => {
|
|||
}
|
||||
})
|
||||
|
||||
const pageTemplate = fs.readFileSync('./templates/page.md.handlebars', 'utf8')
|
||||
const pageTemplate = fs.readFileSync(`${templatesPath}/page.md.handlebars`, 'utf8')
|
||||
const renderPage = Handlebars.compile(pageTemplate)
|
||||
defaults.categories.forEach(({ folder, name, keys }) => {
|
||||
if (keys === undefined) { return }
|
||||
|
|
|
@ -3,8 +3,8 @@ jest.mock('fs')
|
|||
|
||||
const writeTree = require('./write-tree')
|
||||
|
||||
const destinationPath = './dist'
|
||||
const copiedFiles = ['index.html', 'favicon.ico']
|
||||
const templatesPath = 'templates'
|
||||
const destinationPath = 'dist'
|
||||
|
||||
describe('write-tree', () => {
|
||||
afterEach(() => {
|
||||
|
@ -14,22 +14,10 @@ describe('write-tree', () => {
|
|||
describe('no categories', () => {
|
||||
beforeEach(() => callWriteTree({ categories: null }))
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write an empty readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(`${destinationPath}/_sidebar.md`)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
describe('one category, no page', () => {
|
||||
|
@ -51,25 +39,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -124,25 +98,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -207,25 +167,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -276,25 +222,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -349,25 +281,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -425,25 +343,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -519,25 +423,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -625,25 +515,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -722,25 +598,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a sidebar config file using the sidebar template', () => {
|
||||
const sidebarConfigContent = readFile(
|
||||
`${destinationPath}/_sidebar.md`
|
||||
)
|
||||
expect(sidebarConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category1/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category1/readme.md`
|
||||
|
@ -767,5 +629,5 @@ describe('write-tree', () => {
|
|||
})
|
||||
})
|
||||
|
||||
const callWriteTree = sourceFile => writeTree(sourceFile, destinationPath)
|
||||
const callWriteTree = sourceFile => writeTree(sourceFile, templatesPath, destinationPath)
|
||||
const readFile = file => fs.readFakeFileSync(file, 'utf8')
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,8 +2,30 @@ const fs = require('fs')
|
|||
const YAML = require('yaml')
|
||||
|
||||
const writeTree = require('./write-tree')
|
||||
const writeConfig = require('./write-config')
|
||||
|
||||
const input = fs.readFileSync('../../defaults.yml', 'utf8')
|
||||
const inputFr = fs.readFileSync('../../defaults-fr.yml', 'utf8')
|
||||
const defaults = YAML.parse(input)
|
||||
const defaultsFr = YAML.parse(inputFr)
|
||||
|
||||
writeTree(defaults, 'docs')
|
||||
const templatesPath = 'templates'
|
||||
const destinationPath = 'docs'
|
||||
|
||||
const supportedLanguages = {
|
||||
languages: [
|
||||
{ url: '/', lang: 'en-US', home: 'Home', defaults: defaults },
|
||||
{ url: '/fr/', lang: 'fr-FR', home: 'Accueil', defaults: getSafeDefaults(defaultsFr, defaults) },
|
||||
]
|
||||
}
|
||||
|
||||
supportedLanguages.languages.forEach((supportedLanguage) => {
|
||||
const { defaults, url } = supportedLanguage
|
||||
writeTree(defaults, `${templatesPath}${url}`, `${destinationPath}${url}`)
|
||||
})
|
||||
|
||||
writeConfig(supportedLanguages, templatesPath, destinationPath)
|
||||
|
||||
function getSafeDefaults(localizedDefaults, fallbackDefaults) {
|
||||
return { ...fallbackDefaults, ...localizedDefaults }
|
||||
}
|
||||
|
|
|
@ -1,45 +1,15 @@
|
|||
const fs = require('fs')
|
||||
const Handlebars = require('handlebars')
|
||||
|
||||
module.exports = (defaults, destinationPath) => {
|
||||
module.exports = (defaults, templatesPath, 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/media-1x1.jpg', `${destinationPath}/.vuepress/public/media-1x1.jpg`)
|
||||
fs.copyFileSync('./templates/.vuepress/public/media-1x1.webp', `${destinationPath}/.vuepress/public/media-1x1.webp`)
|
||||
fs.copyFileSync('./templates/.vuepress/public/media-2x1.jpg', `${destinationPath}/.vuepress/public/media-2x1.jpg`)
|
||||
fs.copyFileSync('./templates/.vuepress/public/media-2x1.webp', `${destinationPath}/.vuepress/public/media-2x1.webp`)
|
||||
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 netlifyHeadersTemplate = fs.readFileSync('./templates/.vuepress/public/_headers.handlebars', 'utf8')
|
||||
const netlifyHeadersContent = Handlebars.compile(netlifyHeadersTemplate)()
|
||||
fs.writeFileSync(`${destinationPath}/.vuepress/public/_headers`, netlifyHeadersContent)
|
||||
|
||||
const homeTemplate = fs.readFileSync('./templates/home.md.handlebars', 'utf8')
|
||||
const homeTemplate = fs.readFileSync(`${templatesPath}/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 categoryTemplate = fs.readFileSync(`${templatesPath}/category.md.handlebars`, 'utf8')
|
||||
const renderCategory = Handlebars.compile(categoryTemplate)
|
||||
defaults.categories.forEach(category => {
|
||||
fs.mkdirSync(`${destinationPath}/${category.folder}`)
|
||||
|
@ -54,7 +24,7 @@ module.exports = (defaults, destinationPath) => {
|
|||
}
|
||||
})
|
||||
|
||||
const pageTemplate = fs.readFileSync('./templates/page.md.handlebars', 'utf8')
|
||||
const pageTemplate = fs.readFileSync(`${templatesPath}/page.md.handlebars`, 'utf8')
|
||||
const renderPage = Handlebars.compile(pageTemplate)
|
||||
defaults.categories.forEach(({ folder, name, keys }) => {
|
||||
if (keys === undefined) { return }
|
||||
|
|
|
@ -3,27 +3,8 @@ jest.mock('fs')
|
|||
|
||||
const writeTree = require('./write-tree')
|
||||
|
||||
const destinationPath = './dist'
|
||||
const copiedFiles = [
|
||||
'.vuepress/public/android-chrome-192x192.png',
|
||||
'.vuepress/public/android-chrome-512x512.png',
|
||||
'.vuepress/public/apple-touch-icon.png',
|
||||
'.vuepress/public/browserconfig.xml',
|
||||
'.vuepress/public/favicon.ico',
|
||||
'.vuepress/public/favicon-16x16.png',
|
||||
'.vuepress/public/favicon-32x32.png',
|
||||
'.vuepress/public/logo.svg',
|
||||
'.vuepress/public/media-1x1.jpg',
|
||||
'.vuepress/public/media-1x1.webp',
|
||||
'.vuepress/public/media-2x1.jpg',
|
||||
'.vuepress/public/media-2x1.webp',
|
||||
'.vuepress/public/mstile-150x150.png',
|
||||
'.vuepress/public/robots.txt',
|
||||
'.vuepress/public/safari-pinned-tab.svg',
|
||||
'.vuepress/public/site.webmanifest',
|
||||
'.vuepress/styles/index.styl',
|
||||
'.vuepress/styles/palette.styl'
|
||||
]
|
||||
const templatesPath = 'templates'
|
||||
const destinationPath = 'dist'
|
||||
|
||||
describe('write-tree', () => {
|
||||
afterEach(() => {
|
||||
|
@ -33,29 +14,10 @@ describe('write-tree', () => {
|
|||
describe('no categories', () => {
|
||||
beforeEach(() => callWriteTree({ categories: null }))
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write the netlify _headers file', () => {
|
||||
const netlifyHeadersContent = readFile(`${destinationPath}/.vuepress/public/_headers`)
|
||||
expect(netlifyHeadersContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write an empty readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
describe('one category, no page', () => {
|
||||
|
@ -77,25 +39,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -150,25 +98,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -233,25 +167,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -302,25 +222,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -375,25 +281,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -451,25 +343,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -545,25 +423,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -651,25 +515,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -748,25 +598,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category1/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category1/readme.md`
|
||||
|
@ -793,5 +629,5 @@ describe('write-tree', () => {
|
|||
})
|
||||
})
|
||||
|
||||
const callWriteTree = sourceFile => writeTree(sourceFile, destinationPath)
|
||||
const callWriteTree = sourceFile => writeTree(sourceFile, templatesPath, destinationPath)
|
||||
const readFile = file => fs.readFakeFileSync(file, 'utf8')
|
||||
|
|
|
@ -1,25 +1,5 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`write-tree no categories should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree no categories should write an empty readme.md file using the home template 1`] = `
|
||||
"---
|
||||
metaTitle: 'macOS defaults'
|
||||
|
@ -68,30 +48,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, no page with image should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with image example should write a category/page.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page | Category | macOS defaults'
|
||||
|
@ -169,31 +125,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with image example should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
- 'category/page'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text and possible values example should write a category/page.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page | Category | macOS defaults'
|
||||
|
@ -273,31 +204,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text and possible values example should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
- 'category/page'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with an after command should write a category/page.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page | Category | macOS defaults'
|
||||
|
@ -367,31 +273,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with an after command should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
- 'category/page'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with requirements should write a category/page.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page | Category | macOS defaults'
|
||||
|
@ -465,31 +346,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with requirements should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
- 'category/page'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with special chars values should write a category/page.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page | Category | macOS defaults'
|
||||
|
@ -559,31 +415,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with text example with special chars values should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
- 'category/page'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with video example should write a category/page.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page | Category | macOS defaults'
|
||||
|
@ -659,31 +490,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, one page with video example should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
- 'category/page'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, two pages should write a category/page1.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page 1 | Category | macOS defaults'
|
||||
|
@ -793,32 +599,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree one category, two pages should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category
|
||||
collapsable: false
|
||||
path: '/category/'
|
||||
children:
|
||||
- 'category/page1'
|
||||
- 'category/page2'
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree two categories, one page in each should write a category1/page.md file using the page template 1`] = `
|
||||
"---
|
||||
metaTitle: 'Page | Category 1 | macOS defaults'
|
||||
|
@ -940,33 +720,3 @@ Please update [this file](https://github.com/yannbertrand/macos-defaults/blob/ma
|
|||
Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). Take a look at [my report](https://github.com/yannbertrand/macos-defaults/tree/master/build/vuepress#readme) if you want to use it.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`write-tree two categories, one page in each should write a vuepress config.yml file using the template 1`] = `
|
||||
"---
|
||||
|
||||
title: 'macOS defaults'
|
||||
description: 'Uncomplete list of macOS defaults commands with demos ✨'
|
||||
evergreen: true
|
||||
plugins:
|
||||
- '@vuepress/medium-zoom'
|
||||
themeConfig:
|
||||
repo: 'yannbertrand/macos-defaults'
|
||||
nav:
|
||||
- text: 'Home'
|
||||
link: '/'
|
||||
activeHeaderLinks: false
|
||||
sidebar:
|
||||
- title: 'Home'
|
||||
path: '/'
|
||||
- title: Category 1
|
||||
collapsable: false
|
||||
path: '/category1/'
|
||||
children:
|
||||
- 'category1/page'
|
||||
- title: Category 2
|
||||
collapsable: false
|
||||
path: '/category2/'
|
||||
children:
|
||||
- 'category2/page'
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -2,8 +2,30 @@ const fs = require('fs')
|
|||
const YAML = require('yaml')
|
||||
|
||||
const writeTree = require('./write-tree')
|
||||
const writeConfig = require('./write-config')
|
||||
|
||||
const input = fs.readFileSync('../../defaults.yml', 'utf8')
|
||||
const inputFr = fs.readFileSync('../../defaults-fr.yml', 'utf8')
|
||||
const defaults = YAML.parse(input)
|
||||
const defaultsFr = YAML.parse(inputFr)
|
||||
|
||||
writeTree(defaults, 'docs')
|
||||
const templatesPath = 'templates'
|
||||
const destinationPath = 'docs'
|
||||
|
||||
const supportedLanguages = {
|
||||
languages: [
|
||||
{ url: '/', lang: 'en-US', home: 'Home', defaults: defaults },
|
||||
{ url: '/fr/', lang: 'fr-FR', home: 'Accueil', defaults: getSafeDefaults(defaultsFr, defaults) },
|
||||
]
|
||||
}
|
||||
|
||||
supportedLanguages.languages.forEach((supportedLanguage) => {
|
||||
const { defaults, url } = supportedLanguage
|
||||
writeTree(defaults, `${templatesPath}${url}`, `${destinationPath}${url}`)
|
||||
})
|
||||
|
||||
writeConfig(supportedLanguages, templatesPath, destinationPath)
|
||||
|
||||
function getSafeDefaults(localizedDefaults, fallbackDefaults) {
|
||||
return { ...fallbackDefaults, ...localizedDefaults }
|
||||
}
|
||||
|
|
|
@ -1,23 +1,15 @@
|
|||
const fs = require('fs')
|
||||
const Handlebars = require('handlebars')
|
||||
|
||||
module.exports = (defaults, destinationPath) => {
|
||||
module.exports = (defaults, templatesPath, destinationPath) => {
|
||||
fs.mkdirSync(destinationPath)
|
||||
fs.mkdirSync(`${destinationPath}/.vuepress`)
|
||||
fs.mkdirSync(`${destinationPath}/.vuepress/public`)
|
||||
|
||||
fs.copyFileSync('./templates/.vuepress/public/favicon.ico', `${destinationPath}/.vuepress/public/favicon.ico`)
|
||||
|
||||
const homeTemplate = fs.readFileSync('./templates/home.md.handlebars', 'utf8')
|
||||
const homeTemplate = fs.readFileSync(`${templatesPath}/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 categoryTemplate = fs.readFileSync(`${templatesPath}/category.md.handlebars`, 'utf8')
|
||||
const renderCategory = Handlebars.compile(categoryTemplate)
|
||||
defaults.categories.forEach(category => {
|
||||
fs.mkdirSync(`${destinationPath}/${category.folder}`)
|
||||
|
@ -32,7 +24,7 @@ module.exports = (defaults, destinationPath) => {
|
|||
}
|
||||
})
|
||||
|
||||
const pageTemplate = fs.readFileSync('./templates/page.md.handlebars', 'utf8')
|
||||
const pageTemplate = fs.readFileSync(`${templatesPath}/page.md.handlebars`, 'utf8')
|
||||
const renderPage = Handlebars.compile(pageTemplate)
|
||||
defaults.categories.forEach(({ folder, name, keys }) => {
|
||||
if (keys === undefined) { return }
|
||||
|
|
|
@ -3,8 +3,8 @@ jest.mock('fs')
|
|||
|
||||
const writeTree = require('./write-tree')
|
||||
|
||||
const destinationPath = './dist'
|
||||
const copiedFiles = ['.vuepress/public/favicon.ico']
|
||||
const templatesPath = 'templates'
|
||||
const destinationPath = 'dist'
|
||||
|
||||
describe('write-tree', () => {
|
||||
afterEach(() => {
|
||||
|
@ -14,24 +14,10 @@ describe('write-tree', () => {
|
|||
describe('no categories', () => {
|
||||
beforeEach(() => callWriteTree({ categories: null }))
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write an empty readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
describe('one category, no page', () => {
|
||||
|
@ -53,25 +39,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -126,25 +98,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -209,25 +167,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -278,25 +222,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -351,25 +281,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -427,25 +343,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -521,25 +423,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -627,25 +515,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category/readme.md`
|
||||
|
@ -724,25 +598,11 @@ describe('write-tree', () => {
|
|||
})
|
||||
)
|
||||
|
||||
it('should copy some static files', () => {
|
||||
copiedFiles.forEach(file => {
|
||||
const fileContent = readFile(`${destinationPath}/${file}`)
|
||||
expect(fileContent).toEqual(`copied:./templates/${file}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should write a readme.md file using the home template', () => {
|
||||
const rootReadmeContent = readFile(`${destinationPath}/readme.md`)
|
||||
expect(rootReadmeContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a vuepress config.yml file using the template', () => {
|
||||
const vuepressConfigContent = readFile(
|
||||
`${destinationPath}/.vuepress/config.yml`
|
||||
)
|
||||
expect(vuepressConfigContent).toMatchSnapshot()
|
||||
})
|
||||
|
||||
it('should write a category1/readme.md file using the category template', () => {
|
||||
const categoryReadmeContent = readFile(
|
||||
`${destinationPath}/category1/readme.md`
|
||||
|
@ -769,5 +629,5 @@ describe('write-tree', () => {
|
|||
})
|
||||
})
|
||||
|
||||
const callWriteTree = sourceFile => writeTree(sourceFile, destinationPath)
|
||||
const callWriteTree = sourceFile => writeTree(sourceFile, templatesPath, destinationPath)
|
||||
const readFile = file => fs.readFakeFileSync(file, 'utf8')
|
||||
|
|
Loading…
Reference in a new issue