From a6a996ddd24f8be13fcef74edda36f856ed5f19f Mon Sep 17 00:00:00 2001 From: Yann Bertrand <5855339+yannbertrand@users.noreply.github.com> Date: Fri, 27 Nov 2020 13:45:16 +0100 Subject: [PATCH] :rotating_light: Run Prettier --- build/docsify/__mocks__/fs.js | 6 +- build/docsify/build.js | 46 ++++- build/docsify/readme.md | 15 +- build/docsify/write-categories.js | 23 ++- build/docsify/write-categories.test.js | 81 ++++---- build/docsify/write-config.js | 42 +++- build/docsify/write-config.test.js | 123 ++++++------ build/docsify/write-homepage.js | 5 +- build/docsify/write-homepage.test.js | 81 ++++---- build/docsify/write-pages.js | 35 +++- build/docsify/write-pages.test.js | 167 ++++++++-------- build/docusaurus/__mocks__/fs.js | 6 +- build/docusaurus/readme.md | 20 +- .../templates/website/core/Footer.js | 13 +- .../templates/website/siteConfig.js | 12 +- .../templates/website/static/index.html | 28 ++- build/docusaurus/write-config.js | 53 +++-- build/docusaurus/write-config.test.js | 81 ++++---- build/docusaurus/write-homepage.js | 5 +- build/docusaurus/write-homepage.test.js | 85 ++++---- build/docusaurus/write-pages.js | 12 +- build/docusaurus/write-pages.test.js | 183 +++++++++--------- build/github/__mocks__/fs.js | 6 +- build/github/build.js | 2 +- build/github/readme.md | 4 + build/github/write-categories.js | 12 +- build/github/write-categories.test.js | 3 +- build/github/write-config.js | 5 +- build/github/write-config.test.js | 4 +- build/github/write-homepage.js | 5 +- build/github/write-homepage.test.js | 81 ++++---- build/github/write-pages.js | 26 ++- build/github/write-pages.test.js | 167 ++++++++-------- build/production/__mocks__/fs.js | 6 +- build/production/build.js | 21 +- build/production/readme.md | 3 + .../.vuepress/public/site.webmanifest | 36 ++-- build/production/write-categories.js | 12 +- build/production/write-categories.test.js | 81 ++++---- build/production/write-config.js | 139 ++++++++++--- build/production/write-config.test.js | 49 ++--- build/production/write-homepage.js | 5 +- build/production/write-homepage.test.js | 81 ++++---- build/production/write-pages.js | 24 ++- build/production/write-pages.test.js | 179 ++++++++--------- build/vuepress/__mocks__/fs.js | 6 +- build/vuepress/build.js | 21 +- build/vuepress/readme.md | 12 +- build/vuepress/write-categories.js | 12 +- build/vuepress/write-categories.test.js | 81 ++++---- build/vuepress/write-config.js | 19 +- build/vuepress/write-config.test.js | 39 ++-- build/vuepress/write-homepage.js | 5 +- build/vuepress/write-homepage.test.js | 81 ++++---- build/vuepress/write-pages.js | 24 ++- build/vuepress/write-pages.test.js | 167 ++++++++-------- record/dock/autohide-delay/0.5.js | 32 ++- record/dock/autohide-delay/0.js | 32 ++- record/dock/autohide-time-modifier/0.5.js | 32 ++- record/dock/autohide-time-modifier/0.js | 32 ++- record/dock/autohide-time-modifier/2.js | 32 ++- record/dock/mineffect/genie.js | 40 ++-- record/dock/mineffect/scale.js | 40 ++-- record/dock/mineffect/suck.js | 40 ++-- record/dock/orientation/bottom.js | 19 +- record/dock/orientation/left.js | 13 +- record/dock/orientation/right.js | 13 +- record/dock/readme.js | 2 +- record/dock/show-recents/false.js | 15 +- record/dock/show-recents/true.js | 15 +- record/dock/tilesize/36.js | 32 ++- record/dock/tilesize/48.js | 32 ++- record/finder/AppleShowAllFiles/false.js | 21 +- record/finder/AppleShowAllFiles/true.js | 21 +- .../FXEnableExtensionChangeWarning/false.js | 42 ++-- .../FXEnableExtensionChangeWarning/true.js | 42 ++-- record/finder/NSTableViewDefaultSizeMode/1.js | 47 +++-- record/finder/NSTableViewDefaultSizeMode/2.js | 47 +++-- record/finder/NSTableViewDefaultSizeMode/3.js | 47 +++-- .../NSToolbarTitleViewRolloverDelay/0.5.js | 47 +++-- .../NSToolbarTitleViewRolloverDelay/0.js | 47 +++-- .../NSToolbarTitleViewRolloverDelay/1.js | 47 +++-- record/index.js | 4 +- record/mac-runner.js | 24 ++- record/menubar/DateFormat/EEE_HH.mm.ss.js | 36 +++- .../menubar/DateFormat/EEE_d_MMM_HH.mm.ss.js | 36 +++- record/menubar/DateFormat/EEE_h.mm.ss.js | 36 +++- record/menubar/FlashDateSeparators/false.js | 36 +++- record/menubar/FlashDateSeparators/true.js | 36 +++- record/readme.md | 8 +- record/record.js | 21 +- record/screenshots/disable-shadow/false.js | 35 +++- record/screenshots/disable-shadow/true.js | 35 +++- record/utils.js | 74 +++++-- record/yarn.lock | 5 + 95 files changed, 2360 insertions(+), 1395 deletions(-) diff --git a/build/docsify/__mocks__/fs.js b/build/docsify/__mocks__/fs.js index 7acdea5..ac9770a 100644 --- a/build/docsify/__mocks__/fs.js +++ b/build/docsify/__mocks__/fs.js @@ -1,4 +1,4 @@ -const fs = jest.genMockFromModule('fs'); +const fs = jest.genMockFromModule('fs') const result = {} @@ -9,7 +9,7 @@ fs.writeFileSync = jest.fn((path, content) => { fs.copyFileSync = jest.fn((origin, destination) => { result[destination] = `copied:${origin}` }) -fs.readFakeFileSync = jest.fn(path => result[path]) -fs.readFileSync = jest.requireActual("fs").readFileSync +fs.readFakeFileSync = jest.fn((path) => result[path]) +fs.readFileSync = jest.requireActual('fs').readFileSync module.exports = fs diff --git a/build/docsify/build.js b/build/docsify/build.js index 328f295..fa0fb38 100644 --- a/build/docsify/build.js +++ b/build/docsify/build.js @@ -16,17 +16,49 @@ 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 }, - ] + { + 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 - writeHomepage(supportedLanguage, `${templatesPath}${url}`, `${destinationPath}${url}`) - writeCategories(supportedLanguage, `${templatesPath}${url}`, `${destinationPath}${url}`, isFallback) - writePages(supportedLanguage, `${templatesPath}${url}`, `${destinationPath}${url}`, isFallback) - writeConfig(supportedLanguage, supportedLanguages, `${templatesPath}${url}`, `${destinationPath}${url}`, isFallback) + writeHomepage( + supportedLanguage, + `${templatesPath}${url}`, + `${destinationPath}${url}` + ) + writeCategories( + supportedLanguage, + `${templatesPath}${url}`, + `${destinationPath}${url}`, + isFallback + ) + writePages( + supportedLanguage, + `${templatesPath}${url}`, + `${destinationPath}${url}`, + isFallback + ) + writeConfig( + supportedLanguage, + supportedLanguages, + `${templatesPath}${url}`, + `${destinationPath}${url}`, + isFallback + ) }) function getSafeDefaults(localizedDefaults, fallbackDefaults) { diff --git a/build/docsify/readme.md b/build/docsify/readme.md index d4279ef..4391c94 100644 --- a/build/docsify/readme.md +++ b/build/docsify/readme.md @@ -1,43 +1,52 @@ # docsify Build + ![Docsify build status](https://api.netlify.com/api/v1/badges/8af81039-12cc-4080-a434-d8f162d5c416/deploy-status) ## My opinion + docsify was the easiest to setup as it's pretty much the same markdown as VuePress. ### 😄 Good + - Really easy to setup & deploy - index.html direct access - Provides 3 other themes than the Vue default one ### 😕 Bad + - Requires JavaScript - Internationalization is not documented and tough to setup - The full text search is pretty bad - The docsify-cli is really basic ### 😫 Ugly + - The pure theme ## How does it work? + Here is the built website architecture: + - [`index.html`](./templates/index.html) - * A basic HTML file that will build the pages dynamically from the others files using the docsify JS library + - A basic HTML file that will build the pages dynamically from the others files using the docsify JS library - [`_sidebar.md`](./templates/_sidebar.md.handlebars) - * The sidebar configuration which is really easy to setup + - The sidebar configuration which is really easy to setup - `readme.md` - * The main page content + - The main page content All the other pages are markdown files that are carefully put under their folder (e.g. `screenshot/disable-shadow.md`). Assets are stored at the same level. It is deployed as is on Netlify! I also added some plugins ([JS libs in the index.html file](./templates/index.html#L27)): + - [prismjs prism-bash](https://docsify.js.org/#/language-highlight) for language highliting - [docsify search](https://docsify.js.org/#/plugins?id=full-text-search) to get a full text search - [docsify zoom-image](https://docsify.js.org/#/plugins?id=zoom-image) to add Medium zoom on images - [docsify copy-to-clipboard](https://docsify.js.org/#/plugins?id=copy-to-clipboard) to... Copy code ## Try locally + ### 🏗 Install ```sh diff --git a/build/docsify/write-categories.js b/build/docsify/write-categories.js index 8ba8ae0..b36d2c1 100644 --- a/build/docsify/write-categories.js +++ b/build/docsify/write-categories.js @@ -1,16 +1,29 @@ const fs = require('fs') const Handlebars = require('handlebars') -module.exports = ({ defaults }, templatesPath, destinationPath, needAsset = false) => { +module.exports = ( + { defaults }, + templatesPath, + destinationPath, + needAsset = false +) => { if (defaults.categories !== null) { - const categoryTemplate = fs.readFileSync(`${templatesPath}/category.md.handlebars`, 'utf8') + const categoryTemplate = fs.readFileSync( + `${templatesPath}/category.md.handlebars`, + 'utf8' + ) const renderCategory = Handlebars.compile(categoryTemplate) - defaults.categories.forEach(category => { + defaults.categories.forEach((category) => { fs.mkdirSync(`${destinationPath}/${category.folder}`) const categoryReadmeContent = renderCategory(category) - fs.writeFileSync(`${destinationPath}/${category.folder}/readme.md`, categoryReadmeContent) + fs.writeFileSync( + `${destinationPath}/${category.folder}/readme.md`, + categoryReadmeContent + ) - if (!needAsset) { return } + if (!needAsset) { + return + } if (category.image !== undefined) { fs.copyFileSync( diff --git a/build/docsify/write-categories.test.js b/build/docsify/write-categories.test.js index 3c61b40..94c92b8 100644 --- a/build/docsify/write-categories.test.js +++ b/build/docsify/write-categories.test.js @@ -22,10 +22,10 @@ describe('write-categories', () => { image: { filename: 'category.png', width: 740, - height: 80 - } - } - ] + height: 80, + }, + }, + ], }) ) @@ -65,18 +65,18 @@ describe('write-categories', () => { { value: '~/Desktop', default: true, - text: 'output when value is ~/Desktop' + text: 'output when value is ~/Desktop', }, { value: '~/Pictures', - text: 'output when value is ~/Pictures' - } + text: 'output when value is ~/Pictures', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -107,14 +107,14 @@ describe('write-categories', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] + versions: ['Big Sur'], }, { key: 'page2', @@ -125,19 +125,19 @@ describe('write-categories', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -168,16 +168,16 @@ describe('write-categories', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] + versions: ['Big Sur'], + }, + ], }, { folder: 'category2', @@ -193,19 +193,19 @@ describe('write-categories', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -225,5 +225,6 @@ describe('write-categories', () => { }) }) -const callWriteCategories = defaults => writeCategories({ defaults }, templatesPath, destinationPath, true) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteCategories = (defaults) => + writeCategories({ defaults }, templatesPath, destinationPath, true) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/docsify/write-config.js b/build/docsify/write-config.js index 784f005..8ad98d2 100644 --- a/build/docsify/write-config.js +++ b/build/docsify/write-config.js @@ -8,20 +8,46 @@ Handlebars.registerHelper('ifCond', function (v1, v2, options) { return options.inverse(this) }) -module.exports = (supportedLanguage, supportedLanguages, templatesPath, destinationPath, rootConfig = false) => { - const sidebarTemplate = fs.readFileSync(`${templatesPath}/_sidebar.md.handlebars`, 'utf8') +module.exports = ( + supportedLanguage, + supportedLanguages, + templatesPath, + destinationPath, + rootConfig = false +) => { + const sidebarTemplate = fs.readFileSync( + `${templatesPath}/_sidebar.md.handlebars`, + 'utf8' + ) const sidebarContent = Handlebars.compile(sidebarTemplate)(supportedLanguage) fs.writeFileSync(`${destinationPath}/_sidebar.md`, sidebarContent) - const navbarTemplate = fs.readFileSync(`${templatesPath}/_navbar.md.handlebars`, 'utf8') - const navbarContent = Handlebars.compile(navbarTemplate)({ currentUrl: supportedLanguage.url, ...supportedLanguages }) + const navbarTemplate = fs.readFileSync( + `${templatesPath}/_navbar.md.handlebars`, + 'utf8' + ) + const navbarContent = Handlebars.compile(navbarTemplate)({ + currentUrl: supportedLanguage.url, + ...supportedLanguages, + }) fs.writeFileSync(`${destinationPath}/_navbar.md`, navbarContent) - if (!rootConfig) { return } + if (!rootConfig) { + return + } - fs.copyFileSync(`${templatesPath}/favicon.ico`, `${destinationPath}/favicon.ico`) + fs.copyFileSync( + `${templatesPath}/favicon.ico`, + `${destinationPath}/favicon.ico` + ) - const indexTemplate = fs.readFileSync(`${templatesPath}/index.html.handlebars`, 'utf8') - const indexContent = Handlebars.compile(indexTemplate)({ ...supportedLanguage, ...supportedLanguages }) + const indexTemplate = fs.readFileSync( + `${templatesPath}/index.html.handlebars`, + 'utf8' + ) + const indexContent = Handlebars.compile(indexTemplate)({ + ...supportedLanguage, + ...supportedLanguages, + }) fs.writeFileSync(`${destinationPath}/index.html`, indexContent) } diff --git a/build/docsify/write-config.test.js b/build/docsify/write-config.test.js index 48f292f..66e4d8b 100644 --- a/build/docsify/write-config.test.js +++ b/build/docsify/write-config.test.js @@ -13,10 +13,16 @@ describe('write-config', () => { }) describe('no categories', () => { - beforeEach(() => callWriteConfig({ url: '/', home: 'Home', defaults: { categories: null } })) + beforeEach(() => + callWriteConfig({ + url: '/', + home: 'Home', + defaults: { categories: null }, + }) + ) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) @@ -43,7 +49,7 @@ describe('write-config', () => { callWriteConfig({ url: '/', home: 'Home', - defaults: { + defaults: { categories: [ { folder: 'category', @@ -52,16 +58,16 @@ describe('write-config', () => { image: { filename: 'category.png', width: 740, - height: 80 - } - } - ] - } + height: 80, + }, + }, + ], + }, }) ) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) @@ -88,7 +94,7 @@ describe('write-config', () => { callWriteConfig({ url: '/', home: 'Home', - defaults: { + defaults: { categories: [ { folder: 'category', @@ -105,24 +111,24 @@ describe('write-config', () => { { value: '~/Desktop', default: true, - text: 'output when value is ~/Desktop' + text: 'output when value is ~/Desktop', }, { value: '~/Pictures', - text: 'output when value is ~/Pictures' - } + text: 'output when value is ~/Pictures', + }, ], - versions: ['Big Sur'] - } - ] - } - ] - } + versions: ['Big Sur'], + }, + ], + }, + ], + }, }) ) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) @@ -149,7 +155,7 @@ describe('write-config', () => { callWriteConfig({ url: '/', home: 'Home', - defaults: { + defaults: { categories: [ { folder: 'category', @@ -166,14 +172,14 @@ describe('write-config', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] + versions: ['Big Sur'], }, { key: 'page2', @@ -184,25 +190,25 @@ describe('write-config', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] - } + versions: ['Big Sur'], + }, + ], + }, + ], + }, }) ) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) @@ -229,7 +235,7 @@ describe('write-config', () => { callWriteConfig({ url: '/', home: 'Home', - defaults: { + defaults: { categories: [ { folder: 'category1', @@ -246,16 +252,16 @@ describe('write-config', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] + versions: ['Big Sur'], + }, + ], }, { folder: 'category2', @@ -271,25 +277,25 @@ describe('write-config', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] - } + versions: ['Big Sur'], + }, + ], + }, + ], + }, }) ) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) @@ -315,8 +321,15 @@ describe('write-config', () => { const supportedLanguages = { languages: [ { url: '/fr/', lang: 'fr-FR' }, - { url: '/', lang: 'en-US' } + { url: '/', lang: 'en-US' }, ], } -const callWriteConfig = supportedLanguage => writeConfig(supportedLanguage, supportedLanguages, templatesPath, destinationPath, true) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteConfig = (supportedLanguage) => + writeConfig( + supportedLanguage, + supportedLanguages, + templatesPath, + destinationPath, + true + ) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/docsify/write-homepage.js b/build/docsify/write-homepage.js index 5f65b7a..6a439ae 100644 --- a/build/docsify/write-homepage.js +++ b/build/docsify/write-homepage.js @@ -4,7 +4,10 @@ const Handlebars = require('handlebars') module.exports = ({ defaults }, templatesPath, destinationPath) => { mkdirIfNeededSync(destinationPath) - const homeTemplate = fs.readFileSync(`${templatesPath}/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) } diff --git a/build/docsify/write-homepage.test.js b/build/docsify/write-homepage.test.js index 64d1400..39522f0 100644 --- a/build/docsify/write-homepage.test.js +++ b/build/docsify/write-homepage.test.js @@ -31,10 +31,10 @@ describe('write-homepage', () => { image: { filename: 'category.png', width: 740, - height: 80 - } - } - ] + height: 80, + }, + }, + ], }) ) @@ -63,18 +63,18 @@ describe('write-homepage', () => { { value: '~/Desktop', default: true, - text: 'output when value is ~/Desktop' + text: 'output when value is ~/Desktop', }, { value: '~/Pictures', - text: 'output when value is ~/Pictures' - } + text: 'output when value is ~/Pictures', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -103,14 +103,14 @@ describe('write-homepage', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] + versions: ['Big Sur'], }, { key: 'page2', @@ -121,19 +121,19 @@ describe('write-homepage', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -162,16 +162,16 @@ describe('write-homepage', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] + versions: ['Big Sur'], + }, + ], }, { folder: 'category2', @@ -187,19 +187,19 @@ describe('write-homepage', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -210,5 +210,6 @@ describe('write-homepage', () => { }) }) -const callWriteHomepage = defaults => writeHomepage({ defaults }, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteHomepage = (defaults) => + writeHomepage({ defaults }, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/docsify/write-pages.js b/build/docsify/write-pages.js index f1d2130..9ce5ca1 100644 --- a/build/docsify/write-pages.js +++ b/build/docsify/write-pages.js @@ -1,20 +1,41 @@ const fs = require('fs') const Handlebars = require('handlebars') -module.exports = ({ defaults, url }, templatesPath, destinationPath, needAsset = false) => { +module.exports = ( + { defaults, url }, + templatesPath, + destinationPath, + needAsset = false +) => { if (defaults.categories !== null) { - const pageTemplate = fs.readFileSync(`${templatesPath}/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 } + if (keys === undefined) { + return + } keys.forEach(({ domain, ...page }) => { - const pageReadmeContent = renderPage({ ...page, folder, name, domain, url }) - fs.writeFileSync(`${destinationPath}/${folder}/${page.key}.md`, pageReadmeContent) + const pageReadmeContent = renderPage({ + ...page, + folder, + name, + domain, + url, + }) + fs.writeFileSync( + `${destinationPath}/${folder}/${page.key}.md`, + pageReadmeContent + ) - if (!needAsset) { return } + if (!needAsset) { + return + } - page.examples.forEach(example => { + page.examples.forEach((example) => { if (example.image !== undefined) { fs.copyFileSync( `../../images/${folder}/${page.key}/${example.image.filename}`, diff --git a/build/docsify/write-pages.test.js b/build/docsify/write-pages.test.js index 0467bd8..50a3af7 100644 --- a/build/docsify/write-pages.test.js +++ b/build/docsify/write-pages.test.js @@ -32,18 +32,18 @@ describe('write-pages', () => { { value: '~/Desktop', default: true, - text: 'output when value is ~/Desktop' + text: 'output when value is ~/Desktop', }, { value: '~/Pictures', - text: 'output when value is ~/Pictures' - } + text: 'output when value is ~/Pictures', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -75,32 +75,32 @@ describe('write-pages', () => { folder: 'another-category', key: 'another-key', name: 'com.apple.category2 another-key', - value: true + value: true, }, { folder: 'a-third-category', key: 'a-third-key', name: 'com.apple.category2 a-third-key', - value: 0.5 + value: 0.5, }, ], examples: [ { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], versions: ['Big Sur'], - after: 'killall App' - } - ] - } - ] + after: 'killall App', + }, + ], + }, + ], }) ) @@ -131,19 +131,19 @@ describe('write-pages', () => { { value: '~/Desktop', default: true, - text: 'output when value is ~/Desktop' + text: 'output when value is ~/Desktop', }, { value: '~/Pictures', - text: 'output when value is ~/Pictures' - } + text: 'output when value is ~/Pictures', + }, ], versions: ['Big Sur'], - after: 'killall App' - } - ] - } - ] + after: 'killall App', + }, + ], + }, + ], }) ) @@ -174,23 +174,23 @@ describe('write-pages', () => { examples: [ { value: 'start', - text: 'output when value is start' + text: 'output when value is start', }, { value: 'middle', default: true, - text: 'output when value is middle' + text: 'output when value is middle', }, { value: 'end', - text: 'output when value is end' - } + text: 'output when value is end', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -224,23 +224,23 @@ describe('write-pages', () => { image: { filename: 'true.png', width: 600, - height: 400 - } + height: 400, + }, }, { value: false, image: { filename: 'false.png', width: 400, - height: 200 - } - } + height: 200, + }, + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -292,23 +292,23 @@ describe('write-pages', () => { video: { filename: '0.mp4', width: 750, - height: 400 - } + height: 400, + }, }, { value: '0.5', video: { filename: '0.5.mp4', width: 720, - height: 390 - } - } + height: 390, + }, + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -358,14 +358,14 @@ describe('write-pages', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] + versions: ['Big Sur'], }, { key: 'page2', @@ -376,19 +376,19 @@ describe('write-pages', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -422,16 +422,16 @@ describe('write-pages', () => { { value: true, default: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] + versions: ['Big Sur'], + }, + ], }, { folder: 'category2', @@ -447,19 +447,19 @@ describe('write-pages', () => { examples: [ { value: true, - text: 'output when value is true' + text: 'output when value is true', }, { value: false, default: true, - text: 'output when value is false' - } + text: 'output when value is false', + }, ], - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -475,5 +475,6 @@ describe('write-pages', () => { }) }) -const callWritePages = defaults => writePages({ defaults, url: '/' }, templatesPath, destinationPath, true) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWritePages = (defaults) => + writePages({ defaults, url: '/' }, templatesPath, destinationPath, true) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/docusaurus/__mocks__/fs.js b/build/docusaurus/__mocks__/fs.js index 7acdea5..ac9770a 100644 --- a/build/docusaurus/__mocks__/fs.js +++ b/build/docusaurus/__mocks__/fs.js @@ -1,4 +1,4 @@ -const fs = jest.genMockFromModule('fs'); +const fs = jest.genMockFromModule('fs') const result = {} @@ -9,7 +9,7 @@ fs.writeFileSync = jest.fn((path, content) => { fs.copyFileSync = jest.fn((origin, destination) => { result[destination] = `copied:${origin}` }) -fs.readFakeFileSync = jest.fn(path => result[path]) -fs.readFileSync = jest.requireActual("fs").readFileSync +fs.readFakeFileSync = jest.fn((path) => result[path]) +fs.readFileSync = jest.requireActual('fs').readFileSync module.exports = fs diff --git a/build/docusaurus/readme.md b/build/docusaurus/readme.md index 9142c3f..4224621 100644 --- a/build/docusaurus/readme.md +++ b/build/docusaurus/readme.md @@ -1,35 +1,42 @@ # Docusaurus Build + ![Docusaurus build status](https://api.netlify.com/api/v1/badges/92522518-2bcc-4086-8926-6c3534666011/deploy-status) ## My opinion + Docusaurus was quite though to setup. It goes too far for my need. It's certainly more suited for real project documentation. ### 😄 Good + - Default theme is nice - It's possible to use React components - Default theme got a footer ### 😕 Bad + - The new project boilerplate is too complicated. Would have prefer something simpler but extensible as I need it - Search is only available using Algolia ### 😫 Ugly + - Didn't find a way not to have that `/docs/` base href ## How does it work? + Here is the built website architecture: + - [`website/package.json`](./templates/website/package.json) - * To install docusaurus + - To install docusaurus - [`website/siteConfig.js`](./templates/website/siteConfig.js) - * Main configuration + - Main configuration - [`website/sidebars.json`](./templates/website/sidebars.json.handlebars) - * Construct sidebar architecture + - Construct sidebar architecture - [`website/core/Footer.js`](./templates/website/core/Footer.js) - * A React footer... I'm not even sure I can throw this one away + - A React footer... I'm not even sure I can throw this one away - [`website/static/index.html`](./templates/website/static/index.html) - * The page the user accesses if he goes to `/`. It just redirects to `/docs/`... + - The page the user accesses if he goes to `/`. It just redirects to `/docs/`... - `docs/readme.md` - * The main page content + - The main page content All the other pages are markdown files that are carefully put under their folder (e.g. `docs/screenshot/disable-shadow.md`). Assets are stored under the `docs/assets` folder. @@ -38,6 +45,7 @@ I didn't implement internationalization as it requires the use of the [Crowdin]( There is a second build phase where Docusaurus generates the static website. ## Try locally + ### 🏗 Install ```sh diff --git a/build/docusaurus/templates/website/core/Footer.js b/build/docusaurus/templates/website/core/Footer.js index 79f3ad9..3604363 100644 --- a/build/docusaurus/templates/website/core/Footer.js +++ b/build/docusaurus/templates/website/core/Footer.js @@ -1,4 +1,4 @@ -const React = require('react'); +const React = require('react') class Footer extends React.Component { render() { @@ -17,9 +17,7 @@ class Footer extends React.Component {