From 438cb0590e808cd84c493ce65bef3bf2cac1c551 Mon Sep 17 00:00:00 2001 From: Yann Bertrand <5855339+yannbertrand@users.noreply.github.com> Date: Sun, 13 Sep 2020 15:24:51 +0200 Subject: [PATCH] :globe_with_meridians: Add internationalization support --- .../__snapshots__/write-tree.test.js.snap | 70 -- build/docsify/build.js | 23 +- build/docsify/write-tree.js | 15 +- build/docsify/write-tree.test.js | 144 +-- .../__snapshots__/write-tree.test.js.snap | 1019 ----------------- build/production/build.js | 24 +- build/production/write-tree.js | 38 +- build/production/write-tree.test.js | 170 +-- .../__snapshots__/write-tree.test.js.snap | 250 ---- build/vuepress/build.js | 24 +- build/vuepress/write-tree.js | 16 +- build/vuepress/write-tree.test.js | 146 +-- 12 files changed, 89 insertions(+), 1850 deletions(-) diff --git a/build/docsify/__snapshots__/write-tree.test.js.snap b/build/docsify/__snapshots__/write-tree.test.js.snap index 987b3ea..3d0d7b8 100644 --- a/build/docsify/__snapshots__/write-tree.test.js.snap +++ b/build/docsify/__snapshots__/write-tree.test.js.snap @@ -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) -" -`; diff --git a/build/docsify/build.js b/build/docsify/build.js index 15e8d84..512b1c5 100644 --- a/build/docsify/build.js +++ b/build/docsify/build.js @@ -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 } +} diff --git a/build/docsify/write-tree.js b/build/docsify/write-tree.js index e88a1ae..f561c1e 100644 --- a/build/docsify/write-tree.js +++ b/build/docsify/write-tree.js @@ -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 } diff --git a/build/docsify/write-tree.test.js b/build/docsify/write-tree.test.js index a8d5b6b..e83726f 100644 --- a/build/docsify/write-tree.test.js +++ b/build/docsify/write-tree.test.js @@ -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') diff --git a/build/production/__snapshots__/write-tree.test.js.snap b/build/production/__snapshots__/write-tree.test.js.snap index 9fc1616..701f992 100644 --- a/build/production/__snapshots__/write-tree.test.js.snap +++ b/build/production/__snapshots__/write-tree.test.js.snap @@ -1,101 +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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -174,15 +78,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -exports[`write-tree no categories should write the netlify _headers file 1`] = ` -"/* - Content-Security-Policy: default-src 'self'; style-src 'self' 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' 'sha256-PjBkwE8xcYZAp+HsnzzOVNqa/Ra+/v1Fnx6f0PW6ic4=' 'unsafe-hashes' 'sha256-laxniBKFE69CPUpLCGftSNNcrHa/q3ajB6sagR6TudM='; - X-Frame-Options: DENY - X-Content-Type-Options: nosniff - X-XSS-Protection: 1; mode=block -" -`; - exports[`write-tree one category, no page with image should write a category/readme.md file using the category template 1`] = ` "--- metaTitle: \\"Category | macOS defaults\\" @@ -290,106 +185,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -555,107 +350,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -823,107 +517,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -1081,107 +674,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -1343,107 +835,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -1601,107 +992,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -1865,107 +1155,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -2176,108 +1365,6 @@ Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the " `; -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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\\" @@ -2513,109 +1600,3 @@ The list will soon be open sourced! You'll always be welcome to submit PRs, unti Thank you! I built it using [VuePress](https://vuepress.vuejs.org/). I liked the experience a lot. " `; - -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 ✨' -head: - - - - link - - rel: \\"preload\\" - href: \\"/logo.svg\\" - as: \\"image\\" - - - - link - - rel: \\"apple-touch-icon\\" - sizes: \\"180x180\\" - href: \\"/apple-touch-icon.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"32x32\\" - href: \\"/favicon-32x32.png\\" - - - - link - - rel: \\"icon\\" - type: \\"image/png\\" - sizes: \\"16x16\\" - href: \\"/favicon-16x16.png\\" - - - - link - - rel: \\"manifest\\" - href: \\"/site.webmanifest\\" - - - - link - - rel: \\"mask-icon\\" - href: \\"/safari-pinned-tab.svg\\" - color: \\"#004bbd\\" - - - - meta - - name: 'viewport' - content: 'width=device-width,initial-scale=1' - - - - meta - - name: \\"msapplication-TileColor\\" - content: \\"#da532c\\" - - - - meta - - name: \\"theme-color\\" - content: \\"#ffffff\\" - - - - meta - - http-equiv: \\"Content-Type\\" - content: \\"text/html; charset=utf-8\\" - - - - meta - - property: \\"twitter:site\\" - content: \\"@macos_defaults\\" - - - - meta - - property: \\"twitter:creator\\" - content: \\"@_YannBertrand\\" - - - - meta - - property: \\"og:site_name\\" - content: \\"macOS defaults\\" - - - - meta - - property: \\"og:url\\" - content: \\"https://inspiring-hopper-66c5ab.netlify.app\\" - - - - meta - - property: \\"og:type\\" - content: \\"website\\" - - - - meta - - property: \\"og:image:alt\\" - content: \\"\\" - - - - meta - - name: \\"author\\" - content: \\"Yann Bertrand\\" -evergreen: true -plugins: - - '@vuepress/medium-zoom' -themeConfig: - logo: '/logo.svg' - 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' -" -`; diff --git a/build/production/build.js b/build/production/build.js index 15e8d84..cae9f98 100644 --- a/build/production/build.js +++ b/build/production/build.js @@ -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 } +} diff --git a/build/production/write-tree.js b/build/production/write-tree.js index ee29e17..6846484 100644 --- a/build/production/write-tree.js +++ b/build/production/write-tree.js @@ -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 } diff --git a/build/production/write-tree.test.js b/build/production/write-tree.test.js index e4c93e3..d44d265 100644 --- a/build/production/write-tree.test.js +++ b/build/production/write-tree.test.js @@ -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') diff --git a/build/vuepress/__snapshots__/write-tree.test.js.snap b/build/vuepress/__snapshots__/write-tree.test.js.snap index 13bf2df..62eb08c 100644 --- a/build/vuepress/__snapshots__/write-tree.test.js.snap +++ b/build/vuepress/__snapshots__/write-tree.test.js.snap @@ -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' -" -`; diff --git a/build/vuepress/build.js b/build/vuepress/build.js index 15e8d84..cae9f98 100644 --- a/build/vuepress/build.js +++ b/build/vuepress/build.js @@ -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 } +} diff --git a/build/vuepress/write-tree.js b/build/vuepress/write-tree.js index 7174dcc..6846484 100644 --- a/build/vuepress/write-tree.js +++ b/build/vuepress/write-tree.js @@ -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 } diff --git a/build/vuepress/write-tree.test.js b/build/vuepress/write-tree.test.js index 58b2b0c..d44d265 100644 --- a/build/vuepress/write-tree.test.js +++ b/build/vuepress/write-tree.test.js @@ -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')