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 {
Docs
- - Home - + Home
More
@@ -28,7 +26,8 @@ class Footer extends React.Component {
+ className="twitter-follow-button" + > Follow @{this.props.config.twitterUsername}
@@ -36,8 +35,8 @@ class Footer extends React.Component {
- ); + ) } } -module.exports = Footer; +module.exports = Footer diff --git a/build/docusaurus/templates/website/siteConfig.js b/build/docusaurus/templates/website/siteConfig.js index 61ccf4a..755cb2d 100644 --- a/build/docusaurus/templates/website/siteConfig.js +++ b/build/docusaurus/templates/website/siteConfig.js @@ -8,7 +8,11 @@ const siteConfig = { headerLinks: [ { doc: 'index', label: 'Home' }, - { href: '//github.com/yannbertrand/macos-defaults', label: 'GitHub', external: true }, + { + href: '//github.com/yannbertrand/macos-defaults', + label: 'GitHub', + external: true, + }, ], headerIcon: 'img/docusaurus.svg', @@ -27,7 +31,7 @@ const siteConfig = { onPageNav: 'separate', cleanUrl: true, - twitterUsername: '_YannBertrand' -}; + twitterUsername: '_YannBertrand', +} -module.exports = siteConfig; +module.exports = siteConfig diff --git a/build/docusaurus/templates/website/static/index.html b/build/docusaurus/templates/website/static/index.html index 152b56a..2a0bdd0 100644 --- a/build/docusaurus/templates/website/static/index.html +++ b/build/docusaurus/templates/website/static/index.html @@ -1,18 +1,16 @@ + + + + + macOS defaults + - - - - - macOS defaults - - - - If you are not redirected automatically, follow this - link. - - - \ No newline at end of file + + If you are not redirected automatically, follow this + link. + + diff --git a/build/docusaurus/write-config.js b/build/docusaurus/write-config.js index 48bc960..5ead07a 100644 --- a/build/docusaurus/write-config.js +++ b/build/docusaurus/write-config.js @@ -2,7 +2,8 @@ const fs = require('fs') const Handlebars = require('handlebars') Handlebars.registerHelper('renderJsonCategories', (categories) => { - const renderJsonPagesArray = (folder, keys) => keys.map(({ key }) => `"${folder}/${key}"`).join(', ') + const renderJsonPagesArray = (folder, keys) => + keys.map(({ key }) => `"${folder}/${key}"`).join(', ') const defaultsCategories = '"Home": ["index"]' if (categories === null) { @@ -11,7 +12,10 @@ Handlebars.registerHelper('renderJsonCategories', (categories) => { return [ defaultsCategories, - ...categories.map(({ folder, name, keys }) => `"${name}": [${renderJsonPagesArray(folder, keys)}]`) + ...categories.map( + ({ folder, name, keys }) => + `"${name}": [${renderJsonPagesArray(folder, keys)}]` + ), ].join(',\n ') }) @@ -22,15 +26,42 @@ module.exports = (defaults, templatesPath, destinationPath) => { fs.mkdirSync(`${destinationPath}/website/static`) fs.mkdirSync(`${destinationPath}/website/static/img`) - fs.copyFileSync(`${templatesPath}/website/package.json`, `${destinationPath}/website/package.json`) - fs.copyFileSync(`${templatesPath}/website/yarn.lock`, `${destinationPath}/website/yarn.lock`) - fs.copyFileSync(`${templatesPath}/website/siteConfig.js`, `${destinationPath}/website/siteConfig.js`) - fs.copyFileSync(`${templatesPath}/website/core/Footer.js`, `${destinationPath}/website/core/Footer.js`) - fs.copyFileSync(`${templatesPath}/website/static/index.html`, `${destinationPath}/website/static/index.html`) - fs.copyFileSync(`${templatesPath}/website/static/img/docusaurus.svg`, `${destinationPath}/website/static/img/docusaurus.svg`) - fs.copyFileSync(`${templatesPath}/website/static/img/favicon.ico`, `${destinationPath}/website/static/img/favicon.ico`) + fs.copyFileSync( + `${templatesPath}/website/package.json`, + `${destinationPath}/website/package.json` + ) + fs.copyFileSync( + `${templatesPath}/website/yarn.lock`, + `${destinationPath}/website/yarn.lock` + ) + fs.copyFileSync( + `${templatesPath}/website/siteConfig.js`, + `${destinationPath}/website/siteConfig.js` + ) + fs.copyFileSync( + `${templatesPath}/website/core/Footer.js`, + `${destinationPath}/website/core/Footer.js` + ) + fs.copyFileSync( + `${templatesPath}/website/static/index.html`, + `${destinationPath}/website/static/index.html` + ) + fs.copyFileSync( + `${templatesPath}/website/static/img/docusaurus.svg`, + `${destinationPath}/website/static/img/docusaurus.svg` + ) + fs.copyFileSync( + `${templatesPath}/website/static/img/favicon.ico`, + `${destinationPath}/website/static/img/favicon.ico` + ) - const sidebarsConfig = fs.readFileSync(`${templatesPath}/website/sidebars.json.handlebars`, 'utf8') + const sidebarsConfig = fs.readFileSync( + `${templatesPath}/website/sidebars.json.handlebars`, + 'utf8' + ) const sidebarsConfigContent = Handlebars.compile(sidebarsConfig)(defaults) - fs.writeFileSync(`${destinationPath}/website/sidebars.json`, JSON.parse(JSON.stringify(sidebarsConfigContent))) + fs.writeFileSync( + `${destinationPath}/website/sidebars.json`, + JSON.parse(JSON.stringify(sidebarsConfigContent)) + ) } diff --git a/build/docusaurus/write-config.test.js b/build/docusaurus/write-config.test.js index 11d2e99..50f0008 100644 --- a/build/docusaurus/write-config.test.js +++ b/build/docusaurus/write-config.test.js @@ -24,7 +24,7 @@ describe('write-config', () => { beforeEach(() => callWriteConfig({ categories: null })) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/website/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/website/${file}`) }) @@ -56,23 +56,23 @@ 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}/website/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/website/${file}`) }) @@ -104,14 +104,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', @@ -122,24 +122,24 @@ 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}/website/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/website/${file}`) }) @@ -171,16 +171,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', @@ -195,24 +195,24 @@ 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}/website/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/website/${file}`) }) @@ -227,5 +227,6 @@ describe('write-config', () => { }) }) -const callWriteConfig = defaults => writeConfig(defaults, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteConfig = (defaults) => + writeConfig(defaults, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/docusaurus/write-homepage.js b/build/docusaurus/write-homepage.js index 4f24a95..a9edcaa 100644 --- a/build/docusaurus/write-homepage.js +++ b/build/docusaurus/write-homepage.js @@ -5,7 +5,10 @@ module.exports = (defaults, templatesPath, destinationPath) => { fs.mkdirSync(destinationPath) fs.mkdirSync(`${destinationPath}/docs`) - 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}/docs/readme.md`, rootReadmeContent) } diff --git a/build/docusaurus/write-homepage.test.js b/build/docusaurus/write-homepage.test.js index 10df865..44c6645 100644 --- a/build/docusaurus/write-homepage.test.js +++ b/build/docusaurus/write-homepage.test.js @@ -31,10 +31,10 @@ describe('write-homepage', () => { image: { filename: 'category.png', width: 740, - height: 80 - } - } - ] + height: 80, + }, + }, + ], }) ) @@ -62,25 +62,23 @@ 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'], + }, + ], + }, + ], }) ) it('should write a docs/readme.md file using the home template', () => { - const docsReadmeContent = readFile( - `${destinationPath}/docs/readme.md` - ) + const docsReadmeContent = readFile(`${destinationPath}/docs/readme.md`) expect(docsReadmeContent).toMatchSnapshot() }) }) @@ -103,14 +101,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 +119,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'], + }, + ], + }, + ], }) ) @@ -161,16 +159,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', @@ -185,19 +183,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'], + }, + ], + }, + ], }) ) @@ -208,5 +206,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/docusaurus/write-pages.js b/build/docusaurus/write-pages.js index 1176680..1dfe675 100644 --- a/build/docusaurus/write-pages.js +++ b/build/docusaurus/write-pages.js @@ -5,16 +5,22 @@ module.exports = (defaults, templatesPath, destinationPath) => { fs.mkdirSync(`${destinationPath}/assets`) 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 }) => { keys.forEach(({ domain, ...page }) => { mkdirIfNeededSync(`${destinationPath}/${folder}`) const pageReadmeContent = renderPage({ ...page, folder, name, domain }) - fs.writeFileSync(`${destinationPath}/${folder}/${page.key}.md`, pageReadmeContent) + fs.writeFileSync( + `${destinationPath}/${folder}/${page.key}.md`, + pageReadmeContent + ) - page.examples.forEach(example => { + page.examples.forEach((example) => { if (example.image !== undefined) { mkdirIfNeededSync(`${destinationPath}/assets/${folder}`) mkdirIfNeededSync(`${destinationPath}/assets/${folder}/${page.key}`) diff --git a/build/docusaurus/write-pages.test.js b/build/docusaurus/write-pages.test.js index d08188d..d754957 100644 --- a/build/docusaurus/write-pages.test.js +++ b/build/docusaurus/write-pages.test.js @@ -31,18 +31,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'], + }, + ], + }, + ], }) ) @@ -73,32 +73,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', + }, + ], + }, + ], }) ) @@ -128,19 +128,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', + }, + ], + }, + ], }) ) @@ -170,23 +170,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'], + }, + ], + }, + ], }) ) @@ -219,23 +219,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'], + }, + ], + }, + ], }) ) @@ -286,23 +286,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'], + }, + ], + }, + ], }) ) @@ -351,14 +351,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', @@ -369,33 +369,29 @@ 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'], + }, + ], + }, + ], }) ) it('should write a category/page1.md file using the page template', () => { - const pageReadmeContent = readFile( - `${destinationPath}/category/page1.md` - ) + const pageReadmeContent = readFile(`${destinationPath}/category/page1.md`) expect(pageReadmeContent).toMatchSnapshot() }) it('should write a category/page2.md file using the page template', () => { - const pageReadmeContent = readFile( - `${destinationPath}/category/page2.md` - ) + const pageReadmeContent = readFile(`${destinationPath}/category/page2.md`) expect(pageReadmeContent).toMatchSnapshot() }) }) @@ -418,16 +414,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', @@ -442,37 +438,34 @@ 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'], + }, + ], + }, + ], }) ) it('should write a category1/page.md file using the page template', () => { - const pageReadmeContent = readFile( - `${destinationPath}/category1/page.md` - ) + const pageReadmeContent = readFile(`${destinationPath}/category1/page.md`) expect(pageReadmeContent).toMatchSnapshot() }) it('should write a category2/page.md file using the page template', () => { - const pageReadmeContent = readFile( - `${destinationPath}/category2/page.md` - ) + const pageReadmeContent = readFile(`${destinationPath}/category2/page.md`) expect(pageReadmeContent).toMatchSnapshot() }) }) }) -const callWritePages = defaults => writePages(defaults, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWritePages = (defaults) => + writePages(defaults, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/github/__mocks__/fs.js b/build/github/__mocks__/fs.js index 7acdea5..ac9770a 100644 --- a/build/github/__mocks__/fs.js +++ b/build/github/__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/github/build.js b/build/github/build.js index 030132e..14f4355 100644 --- a/build/github/build.js +++ b/build/github/build.js @@ -14,7 +14,7 @@ const initialDestinationPath = 'dist-initial' const destinationPath = 'dist' writeHomepage({}, templatesPath, initialDestinationPath) -writeConfig({}, templatesPath,initialDestinationPath) +writeConfig({}, templatesPath, initialDestinationPath) writeHomepage(defaults, templatesPath, destinationPath) writeCategories(defaults, templatesPath, destinationPath) diff --git a/build/github/readme.md b/build/github/readme.md index 9a90dbf..cb42bb3 100644 --- a/build/github/readme.md +++ b/build/github/readme.md @@ -1,15 +1,18 @@ # GitHub Build + ![GitHub build status](https://github.com/yannbertrand/macos-defaults/workflows/Build%20GitHub/badge.svg) Instead of building a website, I wanted to try constructing GitHub readmes linked from one to the other. As the project is simple, I thought it could be a decent choice. ## My opinion + Unfortunately, it's not possible to display videos in GitHub Flavored Markdown. Images can't be sized using HTML `width` and `height` to avoid [Cumulative Layout Shift](https://web.dev/cls/). I also didn't a find a proper way to internationalize. Apart from that I'm sure it could be used for real small projects as it avoids setting up anything else. ## How does it work? + The [build-github.yml](../../.github/workflows/build-github.yml) GitHub Action workflow is triggered when the [defaults.yml file](../../defaults.yml) or the related build scripts are updated. This workflow compile a `dist` folder where [gitmoji-changelog](https://github.com/frinyvonnick/gitmoji-changelog) is run and everything is commited and pushed to the [current](https://github.com/yannbertrand/macos-defaults/tree/current) branch. @@ -19,6 +22,7 @@ There is also some complicated stuff to build a clean initial commit, that's the The GitHub action that runs gitmoji-changelog and pushes to the other branch can be found on [gha-publish-to-git](https://github.com/yannbertrand/gha-publish-to-git/tree/develop). ## Try locally + ### 🏗 Install ```sh diff --git a/build/github/write-categories.js b/build/github/write-categories.js index 456c588..95b1898 100644 --- a/build/github/write-categories.js +++ b/build/github/write-categories.js @@ -3,12 +3,18 @@ const Handlebars = require('handlebars') module.exports = (defaults, templatesPath, destinationPath) => { if (defaults.categories !== undefined) { - 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 (category.image !== undefined) { fs.copyFileSync( diff --git a/build/github/write-categories.test.js b/build/github/write-categories.test.js index 76b1603..2b596c4 100644 --- a/build/github/write-categories.test.js +++ b/build/github/write-categories.test.js @@ -227,5 +227,6 @@ describe('write-categories', () => { }) }) -const callWriteCategories = (defaults) => writeCategories(defaults, templatesPath, destinationPath) +const callWriteCategories = (defaults) => + writeCategories(defaults, templatesPath, destinationPath) const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/github/write-config.js b/build/github/write-config.js index 87e7276..042e29a 100644 --- a/build/github/write-config.js +++ b/build/github/write-config.js @@ -2,5 +2,8 @@ const fs = require('fs') module.exports = (defaults, templatesPath, destinationPath) => { fs.copyFileSync(`${templatesPath}/license`, `${destinationPath}/license`) - fs.copyFileSync(`${templatesPath}/.gitmoji-changelogrc`, `${destinationPath}/.gitmoji-changelogrc`) + fs.copyFileSync( + `${templatesPath}/.gitmoji-changelogrc`, + `${destinationPath}/.gitmoji-changelogrc` + ) } diff --git a/build/github/write-config.test.js b/build/github/write-config.test.js index f73f6b0..ffb2428 100644 --- a/build/github/write-config.test.js +++ b/build/github/write-config.test.js @@ -17,7 +17,7 @@ describe('write-config', () => { }) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) @@ -25,4 +25,4 @@ describe('write-config', () => { }) const callWriteConfig = () => writeConfig({}, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/github/write-homepage.js b/build/github/write-homepage.js index eb01594..2067c75 100644 --- a/build/github/write-homepage.js +++ b/build/github/write-homepage.js @@ -4,7 +4,10 @@ const Handlebars = require('handlebars') module.exports = (defaults, templatesPath, destinationPath) => { fs.mkdirSync(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/github/write-homepage.test.js b/build/github/write-homepage.test.js index 274eb03..76e09ed 100644 --- a/build/github/write-homepage.test.js +++ b/build/github/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/github/write-pages.js b/build/github/write-pages.js index 81ef6fa..8703806 100644 --- a/build/github/write-pages.js +++ b/build/github/write-pages.js @@ -3,22 +3,36 @@ const Handlebars = require('handlebars') module.exports = (defaults, templatesPath, destinationPath) => { if (defaults.categories !== undefined) { - 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 }) => { fs.mkdirSync(`${destinationPath}/${folder}/${page.key}`) const pageReadmeContent = renderPage({ ...page, name, domain }) - fs.writeFileSync(`${destinationPath}/${folder}/${page.key}/readme.md`, pageReadmeContent) + fs.writeFileSync( + `${destinationPath}/${folder}/${page.key}/readme.md`, + pageReadmeContent + ) - page.examples.forEach(example => { + page.examples.forEach((example) => { if (example.image !== undefined) { - fs.copyFileSync(`../../images/${folder}/${page.key}/${example.image.filename}`, `${destinationPath}/${folder}/${page.key}/${example.image.filename}`) + fs.copyFileSync( + `../../images/${folder}/${page.key}/${example.image.filename}`, + `${destinationPath}/${folder}/${page.key}/${example.image.filename}` + ) } if (example.video !== undefined) { - fs.copyFileSync(`../../images/${folder}/${page.key}/${example.video.filename}`, `${destinationPath}/${folder}/${page.key}/${example.video.filename}`) + fs.copyFileSync( + `../../images/${folder}/${page.key}/${example.video.filename}`, + `${destinationPath}/${folder}/${page.key}/${example.video.filename}` + ) } }) }) diff --git a/build/github/write-pages.test.js b/build/github/write-pages.test.js index 52a00a7..506c9c4 100644 --- a/build/github/write-pages.test.js +++ b/build/github/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'], + }, + ], + }, + ], }) ) @@ -426,16 +426,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', @@ -451,19 +451,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'], + }, + ], + }, + ], }) ) @@ -483,5 +483,6 @@ describe('write-pages', () => { }) }) -const callWritePages = defaults => writePages(defaults, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWritePages = (defaults) => + writePages(defaults, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/production/__mocks__/fs.js b/build/production/__mocks__/fs.js index 7acdea5..ac9770a 100644 --- a/build/production/__mocks__/fs.js +++ b/build/production/__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/production/build.js b/build/production/build.js index b170dfe..27c6061 100644 --- a/build/production/build.js +++ b/build/production/build.js @@ -17,15 +17,28 @@ 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) }, - ] + { + url: '/fr/', + lang: 'fr-FR', + home: 'Accueil', + defaults: getSafeDefaults(defaultsFr, defaults), + }, + ], } supportedLanguages.languages.forEach((supportedLanguage) => { const { defaults, url } = supportedLanguage writeHomepage(defaults, `${templatesPath}${url}`, `${destinationPath}${url}`) - writeCategories(defaults, `${templatesPath}${url}`, `${destinationPath}${url}`) - writePages(supportedLanguage, `${templatesPath}${url}`, `${destinationPath}${url}`) + writeCategories( + defaults, + `${templatesPath}${url}`, + `${destinationPath}${url}` + ) + writePages( + supportedLanguage, + `${templatesPath}${url}`, + `${destinationPath}${url}` + ) }) writeConfig(supportedLanguages, templatesPath, destinationPath) diff --git a/build/production/readme.md b/build/production/readme.md index bbcbced..17a0aae 100644 --- a/build/production/readme.md +++ b/build/production/readme.md @@ -1,12 +1,15 @@ # Production Build + ![macos-defaults.com build status](https://api.netlify.com/api/v1/badges/44ddda91-1e32-4e41-9afc-5f640b33aca7/deploy-status) ## How does it work? + It's similar to the VuePress build with a few tweaks (accent color, assets, SEO stuff...). See [VuePress' build detail](../vuepress/readme.md) for more explanations. ## Try locally + ### 🏗 Install ```sh diff --git a/build/production/templates/.vuepress/public/site.webmanifest b/build/production/templates/.vuepress/public/site.webmanifest index cf423ad..e85d4ae 100644 --- a/build/production/templates/.vuepress/public/site.webmanifest +++ b/build/production/templates/.vuepress/public/site.webmanifest @@ -1,20 +1,20 @@ { - "name": "macOS defaults", - "short_name": "macOS defaults", - "icons": [ - { - "src": "/android-chrome-192x192.png", - "sizes": "192x192", - "type": "image/png" - }, - { - "src": "/android-chrome-512x512.png", - "sizes": "512x512", - "type": "image/png" - } - ], - "theme_color": "#ffffff", - "background_color": "#ffffff", - "start_url": "https://macos-defaults.com", - "display": "standalone" + "name": "macOS defaults", + "short_name": "macOS defaults", + "icons": [ + { + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "start_url": "https://macos-defaults.com", + "display": "standalone" } diff --git a/build/production/write-categories.js b/build/production/write-categories.js index 2a0e316..8031b18 100644 --- a/build/production/write-categories.js +++ b/build/production/write-categories.js @@ -11,12 +11,18 @@ Handlebars.registerHelper('lowerCase', (string) => { module.exports = (defaults, templatesPath, destinationPath) => { 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 (category.image !== undefined) { fs.copyFileSync( diff --git a/build/production/write-categories.test.js b/build/production/write-categories.test.js index e6d9818..3fbe0b1 100644 --- a/build/production/write-categories.test.js +++ b/build/production/write-categories.test.js @@ -23,10 +23,10 @@ describe('write-categories', () => { image: { filename: 'category.png', width: 740, - height: 80 - } - } - ] + height: 80, + }, + }, + ], }) ) @@ -67,18 +67,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'], + }, + ], + }, + ], }) ) @@ -109,14 +109,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', @@ -127,19 +127,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'], + }, + ], + }, + ], }) ) @@ -170,16 +170,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', @@ -195,19 +195,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'], + }, + ], + }, + ], }) ) @@ -227,5 +227,6 @@ describe('write-categories', () => { }) }) -const callWriteCategories = defaults => writeCategories(defaults, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteCategories = (defaults) => + writeCategories(defaults, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/production/write-config.js b/build/production/write-config.js index 2858fce..b3afe97 100644 --- a/build/production/write-config.js +++ b/build/production/write-config.js @@ -10,35 +10,118 @@ module.exports = (supportedLanguages, templatesPath, destinationPath) => { fs.mkdirSync(`${destinationPath}/.vuepress/public`) fs.mkdirSync(`${destinationPath}/.vuepress/styles`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/android-chrome-192x192.png`, `${destinationPath}/.vuepress/public/android-chrome-192x192.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/android-chrome-512x512.png`, `${destinationPath}/.vuepress/public/android-chrome-512x512.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/apple-touch-icon-120x120-precomposed.png`, `${destinationPath}/.vuepress/public/apple-touch-icon-120x120-precomposed.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/apple-touch-icon-120x120.png`, `${destinationPath}/.vuepress/public/apple-touch-icon-120x120.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/apple-touch-icon-152x152-precomposed.png`, `${destinationPath}/.vuepress/public/apple-touch-icon-152x152-precomposed.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/apple-touch-icon-152x152.png`, `${destinationPath}/.vuepress/public/apple-touch-icon-152x152.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/apple-touch-icon-precomposed.png`, `${destinationPath}/.vuepress/public/apple-touch-icon-precomposed.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/apple-touch-icon.png`, `${destinationPath}/.vuepress/public/apple-touch-icon.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/browserconfig.xml`, `${destinationPath}/.vuepress/public/browserconfig.xml`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/favicon.ico`, `${destinationPath}/.vuepress/public/favicon.ico`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/favicon-16x16.png`, `${destinationPath}/.vuepress/public/favicon-16x16.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/favicon-32x32.png`, `${destinationPath}/.vuepress/public/favicon-32x32.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/logo.svg`, `${destinationPath}/.vuepress/public/logo.svg`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/media-1x1.jpg`, `${destinationPath}/.vuepress/public/media-1x1.jpg`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/media-1x1.webp`, `${destinationPath}/.vuepress/public/media-1x1.webp`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/media-2x1.jpg`, `${destinationPath}/.vuepress/public/media-2x1.jpg`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/media-2x1.webp`, `${destinationPath}/.vuepress/public/media-2x1.webp`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/mstile-150x150.png`, `${destinationPath}/.vuepress/public/mstile-150x150.png`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/robots.txt`, `${destinationPath}/.vuepress/public/robots.txt`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/safari-pinned-tab.svg`, `${destinationPath}/.vuepress/public/safari-pinned-tab.svg`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/site.webmanifest`, `${destinationPath}/.vuepress/public/site.webmanifest`) - fs.copyFileSync(`${templatesPath}/.vuepress/styles/index.styl`, `${destinationPath}/.vuepress/styles/index.styl`) - fs.copyFileSync(`${templatesPath}/.vuepress/styles/palette.styl`, `${destinationPath}/.vuepress/styles/palette.styl`) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/android-chrome-192x192.png`, + `${destinationPath}/.vuepress/public/android-chrome-192x192.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/android-chrome-512x512.png`, + `${destinationPath}/.vuepress/public/android-chrome-512x512.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/apple-touch-icon-120x120-precomposed.png`, + `${destinationPath}/.vuepress/public/apple-touch-icon-120x120-precomposed.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/apple-touch-icon-120x120.png`, + `${destinationPath}/.vuepress/public/apple-touch-icon-120x120.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/apple-touch-icon-152x152-precomposed.png`, + `${destinationPath}/.vuepress/public/apple-touch-icon-152x152-precomposed.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/apple-touch-icon-152x152.png`, + `${destinationPath}/.vuepress/public/apple-touch-icon-152x152.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/apple-touch-icon-precomposed.png`, + `${destinationPath}/.vuepress/public/apple-touch-icon-precomposed.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/apple-touch-icon.png`, + `${destinationPath}/.vuepress/public/apple-touch-icon.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/browserconfig.xml`, + `${destinationPath}/.vuepress/public/browserconfig.xml` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/favicon.ico`, + `${destinationPath}/.vuepress/public/favicon.ico` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/favicon-16x16.png`, + `${destinationPath}/.vuepress/public/favicon-16x16.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/favicon-32x32.png`, + `${destinationPath}/.vuepress/public/favicon-32x32.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/logo.svg`, + `${destinationPath}/.vuepress/public/logo.svg` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/media-1x1.jpg`, + `${destinationPath}/.vuepress/public/media-1x1.jpg` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/media-1x1.webp`, + `${destinationPath}/.vuepress/public/media-1x1.webp` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/media-2x1.jpg`, + `${destinationPath}/.vuepress/public/media-2x1.jpg` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/media-2x1.webp`, + `${destinationPath}/.vuepress/public/media-2x1.webp` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/mstile-150x150.png`, + `${destinationPath}/.vuepress/public/mstile-150x150.png` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/robots.txt`, + `${destinationPath}/.vuepress/public/robots.txt` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/safari-pinned-tab.svg`, + `${destinationPath}/.vuepress/public/safari-pinned-tab.svg` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/site.webmanifest`, + `${destinationPath}/.vuepress/public/site.webmanifest` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/styles/index.styl`, + `${destinationPath}/.vuepress/styles/index.styl` + ) + fs.copyFileSync( + `${templatesPath}/.vuepress/styles/palette.styl`, + `${destinationPath}/.vuepress/styles/palette.styl` + ) - const netlifyHeadersTemplate = fs.readFileSync(`${templatesPath}/.vuepress/public/_headers.handlebars`, 'utf8') + const netlifyHeadersTemplate = fs.readFileSync( + `${templatesPath}/.vuepress/public/_headers.handlebars`, + 'utf8' + ) const netlifyHeadersContent = Handlebars.compile(netlifyHeadersTemplate)() - fs.writeFileSync(`${destinationPath}/.vuepress/public/_headers`, netlifyHeadersContent) + fs.writeFileSync( + `${destinationPath}/.vuepress/public/_headers`, + netlifyHeadersContent + ) - const vuepressConfig = fs.readFileSync(`${templatesPath}/.vuepress/config.yml.handlebars`, 'utf8') - const vuepressConfigContent = Handlebars.compile(vuepressConfig)(supportedLanguages) - fs.writeFileSync(`${destinationPath}/.vuepress/config.yml`, vuepressConfigContent) + const vuepressConfig = fs.readFileSync( + `${templatesPath}/.vuepress/config.yml.handlebars`, + 'utf8' + ) + const vuepressConfigContent = Handlebars.compile(vuepressConfig)( + supportedLanguages + ) + fs.writeFileSync( + `${destinationPath}/.vuepress/config.yml`, + vuepressConfigContent + ) } diff --git a/build/production/write-config.test.js b/build/production/write-config.test.js index 1863d58..0ec9bb6 100644 --- a/build/production/write-config.test.js +++ b/build/production/write-config.test.js @@ -28,7 +28,7 @@ const copiedFiles = [ '.vuepress/public/safari-pinned-tab.svg', '.vuepress/public/site.webmanifest', '.vuepress/styles/index.styl', - '.vuepress/styles/palette.styl' + '.vuepress/styles/palette.styl', ] describe('write-config', () => { @@ -41,19 +41,23 @@ describe('write-config', () => { }) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) }) it('should write the netlify _headers file', () => { - const netlifyHeadersContent = readFile(`${destinationPath}/.vuepress/public/_headers`) + const netlifyHeadersContent = readFile( + `${destinationPath}/.vuepress/public/_headers` + ) expect(netlifyHeadersContent).toMatchSnapshot() }) it('should write a vuepress config.yml file using the template', () => { - const vuepressConfigContent = readFile(`${destinationPath}/.vuepress/config.yml`) + const vuepressConfigContent = readFile( + `${destinationPath}/.vuepress/config.yml` + ) expect(vuepressConfigContent).toMatchSnapshot() }) }) @@ -73,8 +77,8 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] + }, + ], }, { folder: 'category2', @@ -83,11 +87,11 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] - } - ] - } + }, + ], + }, + ], + }, }, { url: '/fr/', @@ -102,8 +106,8 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] + }, + ], }, { folder: 'categorie2', @@ -112,14 +116,15 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] - } - ] - } - } - ] + }, + ], + }, + ], + }, + }, + ], } -const callWriteConfig = () => writeConfig(supportedLanguages, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteConfig = () => + writeConfig(supportedLanguages, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/production/write-homepage.js b/build/production/write-homepage.js index cb9f7c4..3f27d64 100644 --- a/build/production/write-homepage.js +++ b/build/production/write-homepage.js @@ -8,7 +8,10 @@ Handlebars.registerHelper('lowerCase', (string) => { module.exports = (defaults, templatesPath, destinationPath) => { fs.mkdirSync(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/production/write-homepage.test.js b/build/production/write-homepage.test.js index 04d3f27..330f4d3 100644 --- a/build/production/write-homepage.test.js +++ b/build/production/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/production/write-pages.js b/build/production/write-pages.js index 77f0881..1731648 100644 --- a/build/production/write-pages.js +++ b/build/production/write-pages.js @@ -7,16 +7,30 @@ Handlebars.registerHelper('escapeDoubleQuote', (string) => { module.exports = ({ defaults, url }, templatesPath, destinationPath) => { 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.toLowerCase()}.md`, pageReadmeContent) + const pageReadmeContent = renderPage({ + ...page, + folder, + name, + domain, + url, + }) + fs.writeFileSync( + `${destinationPath}/${folder}/${page.key.toLowerCase()}.md`, + pageReadmeContent + ) - 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/production/write-pages.test.js b/build/production/write-pages.test.js index de32a81..f43958d 100644 --- a/build/production/write-pages.test.js +++ b/build/production/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', + }, + ], + }, + ], }) ) @@ -173,13 +173,13 @@ describe('write-pages', () => { examples: [], deleteAlert: { type: 'danger', - message: 'This an alert message.
`defaults command`' + message: 'This an alert message.
`defaults command`', }, - versions: ['Big Sur'] - } - ] - } - ] + versions: ['Big Sur'], + }, + ], + }, + ], }) ) @@ -210,23 +210,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'], + }, + ], + }, + ], }) ) @@ -260,23 +260,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'], + }, + ], + }, + ], }) ) @@ -328,23 +328,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'], + }, + ], + }, + ], }) ) @@ -394,14 +394,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', @@ -412,19 +412,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'], + }, + ], + }, + ], }) ) @@ -458,16 +458,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', @@ -483,19 +483,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'], + }, + ], + }, + ], }) ) @@ -511,5 +511,6 @@ describe('write-pages', () => { }) }) -const callWritePages = defaults => writePages({ defaults, url: '/' }, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWritePages = (defaults) => + writePages({ defaults, url: '/' }, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/vuepress/__mocks__/fs.js b/build/vuepress/__mocks__/fs.js index 7acdea5..ac9770a 100644 --- a/build/vuepress/__mocks__/fs.js +++ b/build/vuepress/__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/vuepress/build.js b/build/vuepress/build.js index b170dfe..27c6061 100644 --- a/build/vuepress/build.js +++ b/build/vuepress/build.js @@ -17,15 +17,28 @@ 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) }, - ] + { + url: '/fr/', + lang: 'fr-FR', + home: 'Accueil', + defaults: getSafeDefaults(defaultsFr, defaults), + }, + ], } supportedLanguages.languages.forEach((supportedLanguage) => { const { defaults, url } = supportedLanguage writeHomepage(defaults, `${templatesPath}${url}`, `${destinationPath}${url}`) - writeCategories(defaults, `${templatesPath}${url}`, `${destinationPath}${url}`) - writePages(supportedLanguage, `${templatesPath}${url}`, `${destinationPath}${url}`) + writeCategories( + defaults, + `${templatesPath}${url}`, + `${destinationPath}${url}` + ) + writePages( + supportedLanguage, + `${templatesPath}${url}`, + `${destinationPath}${url}` + ) }) writeConfig(supportedLanguages, templatesPath, destinationPath) diff --git a/build/vuepress/readme.md b/build/vuepress/readme.md index c3d4e1c..9a39ce1 100644 --- a/build/vuepress/readme.md +++ b/build/vuepress/readme.md @@ -1,28 +1,35 @@ # VuePress Build + ![VuePress build status](https://api.netlify.com/api/v1/badges/e73b1f35-9442-45e1-b7b4-6eed2b102a9c/deploy-status) ## My opinion + VuePress was really easy to setup. ### 😄 Good + - Really easy to setup & deploy - Default theme is nice - It's possible to use Vue components - Development mode is pleasant ### 😕 Bad + - Documentation is not super easy - Lack of other official themes ### 😫 Ugly + - 🤷‍♂️ ## How does it work? + Here is the built website architecture: + - [`.vuepress/config.yml`](./templates/.vuepress/config.yml.handlebars) - * Contains the whole VuePress configuration from title to sidebar config + - Contains the whole VuePress configuration from title to sidebar config - `readme.md` - * The main page content + - The main page content All the other pages (including translations) are markdown files that are carefully put under their folder (e.g. `screenshot/disable-shadow.md`). Assets are stored at the same level. @@ -31,6 +38,7 @@ There is a second build phase where VuePress generates the static website. I also added the [@vuepress/medium-zoom](https://v1.vuepress.vuejs.org/plugin/official/plugin-medium-zoom.html) plugin to add Medium zoom on images. ## Try locally + ### 🏗 Install ```sh diff --git a/build/vuepress/write-categories.js b/build/vuepress/write-categories.js index ed70170..a680683 100644 --- a/build/vuepress/write-categories.js +++ b/build/vuepress/write-categories.js @@ -7,12 +7,18 @@ Handlebars.registerHelper('lowerCase', (string) => { module.exports = (defaults, templatesPath, destinationPath) => { 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 (category.image !== undefined) { fs.copyFileSync( diff --git a/build/vuepress/write-categories.test.js b/build/vuepress/write-categories.test.js index e6d9818..3fbe0b1 100644 --- a/build/vuepress/write-categories.test.js +++ b/build/vuepress/write-categories.test.js @@ -23,10 +23,10 @@ describe('write-categories', () => { image: { filename: 'category.png', width: 740, - height: 80 - } - } - ] + height: 80, + }, + }, + ], }) ) @@ -67,18 +67,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'], + }, + ], + }, + ], }) ) @@ -109,14 +109,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', @@ -127,19 +127,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'], + }, + ], + }, + ], }) ) @@ -170,16 +170,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', @@ -195,19 +195,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'], + }, + ], + }, + ], }) ) @@ -227,5 +227,6 @@ describe('write-categories', () => { }) }) -const callWriteCategories = defaults => writeCategories(defaults, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteCategories = (defaults) => + writeCategories(defaults, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/vuepress/write-config.js b/build/vuepress/write-config.js index a1dfaa4..4e53ffb 100644 --- a/build/vuepress/write-config.js +++ b/build/vuepress/write-config.js @@ -9,9 +9,20 @@ module.exports = (supportedLanguages, templatesPath, destinationPath) => { fs.mkdirSync(`${destinationPath}/.vuepress`) fs.mkdirSync(`${destinationPath}/.vuepress/public`) - fs.copyFileSync(`${templatesPath}/.vuepress/public/favicon.ico`, `${destinationPath}/.vuepress/public/favicon.ico`) + fs.copyFileSync( + `${templatesPath}/.vuepress/public/favicon.ico`, + `${destinationPath}/.vuepress/public/favicon.ico` + ) - const vuepressConfig = fs.readFileSync(`${templatesPath}/.vuepress/config.yml.handlebars`, 'utf8') - const vuepressConfigContent = Handlebars.compile(vuepressConfig)(supportedLanguages) - fs.writeFileSync(`${destinationPath}/.vuepress/config.yml`, vuepressConfigContent) + const vuepressConfig = fs.readFileSync( + `${templatesPath}/.vuepress/config.yml.handlebars`, + 'utf8' + ) + const vuepressConfigContent = Handlebars.compile(vuepressConfig)( + supportedLanguages + ) + fs.writeFileSync( + `${destinationPath}/.vuepress/config.yml`, + vuepressConfigContent + ) } diff --git a/build/vuepress/write-config.test.js b/build/vuepress/write-config.test.js index b03a2ac..68ab180 100644 --- a/build/vuepress/write-config.test.js +++ b/build/vuepress/write-config.test.js @@ -17,7 +17,7 @@ describe('write-config', () => { }) it('should copy some static files', () => { - copiedFiles.forEach(file => { + copiedFiles.forEach((file) => { const fileContent = readFile(`${destinationPath}/${file}`) expect(fileContent).toEqual(`copied:${templatesPath}/${file}`) }) @@ -46,8 +46,8 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] + }, + ], }, { folder: 'category2', @@ -56,11 +56,11 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] - } - ] - } + }, + ], + }, + ], + }, }, { url: '/fr/', @@ -75,8 +75,8 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] + }, + ], }, { folder: 'categorie2', @@ -85,14 +85,15 @@ const supportedLanguages = { { key: 'page', title: 'Page', - } - ] - } - ] - } - } - ] + }, + ], + }, + ], + }, + }, + ], } -const callWriteConfig = () => writeConfig(supportedLanguages, templatesPath, destinationPath) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWriteConfig = () => + writeConfig(supportedLanguages, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/build/vuepress/write-homepage.js b/build/vuepress/write-homepage.js index cb9f7c4..3f27d64 100644 --- a/build/vuepress/write-homepage.js +++ b/build/vuepress/write-homepage.js @@ -8,7 +8,10 @@ Handlebars.registerHelper('lowerCase', (string) => { module.exports = (defaults, templatesPath, destinationPath) => { fs.mkdirSync(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/vuepress/write-homepage.test.js b/build/vuepress/write-homepage.test.js index 04d3f27..330f4d3 100644 --- a/build/vuepress/write-homepage.test.js +++ b/build/vuepress/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/vuepress/write-pages.js b/build/vuepress/write-pages.js index 3f91381..428a015 100644 --- a/build/vuepress/write-pages.js +++ b/build/vuepress/write-pages.js @@ -3,16 +3,30 @@ const Handlebars = require('handlebars') module.exports = ({ defaults, url }, templatesPath, destinationPath) => { 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.toLowerCase()}.md`, pageReadmeContent) + const pageReadmeContent = renderPage({ + ...page, + folder, + name, + domain, + url, + }) + fs.writeFileSync( + `${destinationPath}/${folder}/${page.key.toLowerCase()}.md`, + pageReadmeContent + ) - 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/vuepress/write-pages.test.js b/build/vuepress/write-pages.test.js index 734aead..875b646 100644 --- a/build/vuepress/write-pages.test.js +++ b/build/vuepress/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) -const readFile = file => fs.readFakeFileSync(file, 'utf8') +const callWritePages = (defaults) => + writePages({ defaults, url: '/' }, templatesPath, destinationPath) +const readFile = (file) => fs.readFakeFileSync(file, 'utf8') diff --git a/record/dock/autohide-delay/0.5.js b/record/dock/autohide-delay/0.5.js index 52055a1..f8057e8 100644 --- a/record/dock/autohide-delay/0.5.js +++ b/record/dock/autohide-delay/0.5.js @@ -9,9 +9,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock autohide-delay with param set to 0.5') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-delay -float 0.5 && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-delay -float 0.5 && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock autohide-delay command') + console.error( + 'An error occured while setting up the dock autohide-delay command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -26,8 +30,10 @@ module.exports = { const recordWidth = 441 const recordHeight = 120 const cropArea = { - x: pos2.x - recordWidth / 2, y: 0, - width: recordWidth, height: recordHeight + x: pos2.x - recordWidth / 2, + y: 0, + width: recordWidth, + height: recordHeight, } robot.moveMouse(pos1.x, pos1.y) @@ -57,18 +63,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock autohide-delay environment') + console.error( + 'An error occured while cleaning the dock autohide-delay environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/0.5`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock' + ) } diff --git a/record/dock/autohide-delay/0.js b/record/dock/autohide-delay/0.js index 9c09e40..2a16d2d 100644 --- a/record/dock/autohide-delay/0.js +++ b/record/dock/autohide-delay/0.js @@ -9,9 +9,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock autohide-delay with param set to 0') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-delay -float 0 && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-delay -float 0 && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock autohide-delay command') + console.error( + 'An error occured while setting up the dock autohide-delay command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -26,8 +30,10 @@ module.exports = { const recordWidth = 441 const recordHeight = 120 const cropArea = { - x: pos2.x - recordWidth / 2, y: 0, - width: recordWidth, height: recordHeight + x: pos2.x - recordWidth / 2, + y: 0, + width: recordWidth, + height: recordHeight, } robot.moveMouse(pos1.x, pos1.y) @@ -57,18 +63,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock autohide-delay environment') + console.error( + 'An error occured while cleaning the dock autohide-delay environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/0`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-delay && killall Dock' + ) } diff --git a/record/dock/autohide-time-modifier/0.5.js b/record/dock/autohide-time-modifier/0.5.js index 23fa7bf..14db1cb 100644 --- a/record/dock/autohide-time-modifier/0.5.js +++ b/record/dock/autohide-time-modifier/0.5.js @@ -9,9 +9,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock autohide-time-modifier with param set to 0.5') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-time-modifier -float 0.5 && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-time-modifier -float 0.5 && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock autohide-time-modifier command') + console.error( + 'An error occured while setting up the dock autohide-time-modifier command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -26,8 +30,10 @@ module.exports = { const recordWidth = 441 const recordHeight = 120 const cropArea = { - x: pos2.x - recordWidth / 2, y: 0, - width: recordWidth, height: recordHeight + x: pos2.x - recordWidth / 2, + y: 0, + width: recordWidth, + height: recordHeight, } robot.moveMouse(pos1.x, pos1.y) @@ -57,18 +63,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock autohide-time-modifier environment') + console.error( + 'An error occured while cleaning the dock autohide-time-modifier environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/0.5`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock' + ) } diff --git a/record/dock/autohide-time-modifier/0.js b/record/dock/autohide-time-modifier/0.js index 19380dd..966e17e 100644 --- a/record/dock/autohide-time-modifier/0.js +++ b/record/dock/autohide-time-modifier/0.js @@ -9,9 +9,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock autohide-time-modifier with param set to 0') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-time-modifier -float 0 && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-time-modifier -float 0 && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock autohide-time-modifier command') + console.error( + 'An error occured while setting up the dock autohide-time-modifier command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -26,8 +30,10 @@ module.exports = { const recordWidth = 441 const recordHeight = 120 const cropArea = { - x: pos2.x - recordWidth / 2, y: 0, - width: recordWidth, height: recordHeight + x: pos2.x - recordWidth / 2, + y: 0, + width: recordWidth, + height: recordHeight, } robot.moveMouse(pos1.x, pos1.y) @@ -57,18 +63,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock autohide-time-modifier environment') + console.error( + 'An error occured while cleaning the dock autohide-time-modifier environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/0`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock' + ) } diff --git a/record/dock/autohide-time-modifier/2.js b/record/dock/autohide-time-modifier/2.js index f564b67..2d4d04f 100644 --- a/record/dock/autohide-time-modifier/2.js +++ b/record/dock/autohide-time-modifier/2.js @@ -9,9 +9,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock autohide-time-modifier with param set to 2') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-time-modifier -float 2 && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-time-modifier -float 2 && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock autohide-time-modifier command') + console.error( + 'An error occured while setting up the dock autohide-time-modifier command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -26,8 +30,10 @@ module.exports = { const recordWidth = 441 const recordHeight = 120 const cropArea = { - x: pos2.x - recordWidth / 2, y: 0, - width: recordWidth, height: recordHeight + x: pos2.x - recordWidth / 2, + y: 0, + width: recordWidth, + height: recordHeight, } robot.moveMouse(pos1.x, pos1.y) @@ -57,18 +63,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock autohide-time-modifier environment') + console.error( + 'An error occured while cleaning the dock autohide-time-modifier environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/2`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.dock autohide && defaults delete com.apple.dock autohide-time-modifier && killall Dock' + ) } diff --git a/record/dock/mineffect/genie.js b/record/dock/mineffect/genie.js index 9d6ac14..19b6d87 100644 --- a/record/dock/mineffect/genie.js +++ b/record/dock/mineffect/genie.js @@ -3,15 +3,23 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { console.log('> Recording dock mineffect with param set to genie') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock mineffect -string genie && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock mineffect -string genie && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock mineffect command') + console.error( + 'An error occured while setting up the dock mineffect command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -25,12 +33,16 @@ module.exports = { const recordWidth = 750 const recordHeight = 750 const cropArea = { - x: width - recordWidth, y: 0, - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: 0, + width: recordWidth, + height: recordHeight, } const windowCropArea = { - x: cropArea.x+21, y: 156, - width: 668, height: 568 + x: cropArea.x + 21, + y: 156, + width: 668, + height: 568, } await moveAndResizeApp('System Preferences', windowCropArea, height) @@ -61,18 +73,24 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock mineffect && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock mineffect && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock mineffect environment') + console.error( + 'An error occured while cleaning the dock mineffect environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/genie`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock mineffect && killall Dock') } diff --git a/record/dock/mineffect/scale.js b/record/dock/mineffect/scale.js index 53dbbd3..f26b2d1 100644 --- a/record/dock/mineffect/scale.js +++ b/record/dock/mineffect/scale.js @@ -3,15 +3,23 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { console.log('> Recording dock mineffect with param set to scale') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock mineffect -string scale && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock mineffect -string scale && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock mineffect command') + console.error( + 'An error occured while setting up the dock mineffect command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -25,12 +33,16 @@ module.exports = { const recordWidth = 750 const recordHeight = 750 const cropArea = { - x: width - recordWidth, y: 0, - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: 0, + width: recordWidth, + height: recordHeight, } const windowCropArea = { - x: cropArea.x+21, y: 156, - width: 668, height: 568 + x: cropArea.x + 21, + y: 156, + width: 668, + height: 568, } await moveAndResizeApp('System Preferences', windowCropArea, height) @@ -61,18 +73,24 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock mineffect && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock mineffect && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock mineffect environment') + console.error( + 'An error occured while cleaning the dock mineffect environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/scale`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock mineffect && killall Dock') } diff --git a/record/dock/mineffect/suck.js b/record/dock/mineffect/suck.js index cd403f6..5e9ec8e 100644 --- a/record/dock/mineffect/suck.js +++ b/record/dock/mineffect/suck.js @@ -3,15 +3,23 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { console.log('> Recording dock mineffect with param set to suck') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock mineffect -string suck && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock mineffect -string suck && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock mineffect command') + console.error( + 'An error occured while setting up the dock mineffect command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -25,12 +33,16 @@ module.exports = { const recordWidth = 750 const recordHeight = 750 const cropArea = { - x: width - recordWidth, y: 0, - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: 0, + width: recordWidth, + height: recordHeight, } const windowCropArea = { - x: cropArea.x+21, y: 156, - width: 668, height: 568 + x: cropArea.x + 21, + y: 156, + width: 668, + height: 568, } await moveAndResizeApp('System Preferences', windowCropArea, height) @@ -61,18 +73,24 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.dock mineffect && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.dock mineffect && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock mineffect environment') + console.error( + 'An error occured while cleaning the dock mineffect environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/suck`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock mineffect && killall Dock') } diff --git a/record/dock/orientation/bottom.js b/record/dock/orientation/bottom.js index 45e3c97..63913ea 100644 --- a/record/dock/orientation/bottom.js +++ b/record/dock/orientation/bottom.js @@ -8,7 +8,12 @@ module.exports = { try { const runner = new MacRunner() await runner - .setDefault('com.apple.dock', 'orientation', '-string bottom', 'killall Dock') + .setDefault( + 'com.apple.dock', + 'orientation', + '-string bottom', + 'killall Dock' + ) .wait(2000) .captureScreen(`${outputPath}/bottom-tmp.png`) .deleteDefault('com.apple.dock', 'orientation', 'killall Dock') @@ -19,17 +24,23 @@ module.exports = { } try { - await compressPngImage(`${outputPath}/bottom-tmp.png`, outputPath, 'bottom') + await compressPngImage( + `${outputPath}/bottom-tmp.png`, + outputPath, + 'bottom' + ) } catch (compressPngImageError) { logRollbackInfo() throw new Error(compressPngImageError) } return { filepath: `${outputPath}/bottom` } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock orientation && killall Dock') } diff --git a/record/dock/orientation/left.js b/record/dock/orientation/left.js index f219d0e..3995bd4 100644 --- a/record/dock/orientation/left.js +++ b/record/dock/orientation/left.js @@ -8,7 +8,12 @@ module.exports = { try { const runner = new MacRunner() await runner - .setDefault('com.apple.dock', 'orientation', '-string left', 'killall Dock') + .setDefault( + 'com.apple.dock', + 'orientation', + '-string left', + 'killall Dock' + ) .wait(2000) .captureScreen(`${outputPath}/left-tmp.png`) .deleteDefault('com.apple.dock', 'orientation', 'killall Dock') @@ -26,10 +31,12 @@ module.exports = { } return { filepath: `${outputPath}/left` } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock orientation && killall Dock') } diff --git a/record/dock/orientation/right.js b/record/dock/orientation/right.js index f57998d..0077ec6 100644 --- a/record/dock/orientation/right.js +++ b/record/dock/orientation/right.js @@ -8,7 +8,12 @@ module.exports = { try { const runner = new MacRunner() await runner - .setDefault('com.apple.dock', 'orientation', '-string right', 'killall Dock') + .setDefault( + 'com.apple.dock', + 'orientation', + '-string right', + 'killall Dock' + ) .wait(2000) .captureScreen(`${outputPath}/right-tmp.png`) .deleteDefault('com.apple.dock', 'orientation', 'killall Dock') @@ -26,10 +31,12 @@ module.exports = { } return { filepath: `${outputPath}/right` } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock orientation && killall Dock') } diff --git a/record/dock/readme.js b/record/dock/readme.js index 59ffc81..98751e8 100644 --- a/record/dock/readme.js +++ b/record/dock/readme.js @@ -22,5 +22,5 @@ module.exports = { } return { filepath: `${outputPath}/dock` } - } + }, } diff --git a/record/dock/show-recents/false.js b/record/dock/show-recents/false.js index b05c9d7..b10017d 100644 --- a/record/dock/show-recents/false.js +++ b/record/dock/show-recents/false.js @@ -8,9 +8,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock show-recents with param set to false') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock show-recents -bool false && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock show-recents -bool false && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock show-recents command') + console.error( + 'An error occured while setting up the dock show-recents command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -30,11 +34,12 @@ module.exports = { } return { filepath: `${outputPath}/false` } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock show-recents && killall Dock') } - \ No newline at end of file diff --git a/record/dock/show-recents/true.js b/record/dock/show-recents/true.js index 05efc96..85c36ec 100644 --- a/record/dock/show-recents/true.js +++ b/record/dock/show-recents/true.js @@ -8,9 +8,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock show-recents with param set to true') - const { stderr: setEnvError } = await exec('defaults write com.apple.dock show-recents -bool true && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.dock show-recents -bool true && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock show-recents command') + console.error( + 'An error occured while setting up the dock show-recents command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -30,11 +34,12 @@ module.exports = { } return { filepath: `${outputPath}/true` } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) console.info('defaults delete com.apple.dock show-recents && killall Dock') } - \ No newline at end of file diff --git a/record/dock/tilesize/36.js b/record/dock/tilesize/36.js index 42d00c2..58567ae 100644 --- a/record/dock/tilesize/36.js +++ b/record/dock/tilesize/36.js @@ -9,9 +9,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock icon size with param set to 36') - const { stderr: setEnvError } = await exec('defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.dock tilesize -int 36 && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.dock tilesize -int 36 && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock tilesize command') + console.error( + 'An error occured while setting up the dock tilesize command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -21,9 +25,11 @@ module.exports = { // Screenshot robot.keyTap('3', ['command', 'shift']) - + await delay(1000) - const screenshot = (await glob(`/Users/${process.env.USER}/Desktop/*.png`)).pop() + const screenshot = ( + await glob(`/Users/${process.env.USER}/Desktop/*.png`) + ).pop() try { await compressPngImage(screenshot, outputPath, '36') @@ -32,18 +38,26 @@ module.exports = { throw new Error(compressPngImageError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock tilesize environment') + console.error( + 'An error occured while cleaning the dock tilesize environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/36` } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock' + ) } diff --git a/record/dock/tilesize/48.js b/record/dock/tilesize/48.js index 608d8ec..3989949 100644 --- a/record/dock/tilesize/48.js +++ b/record/dock/tilesize/48.js @@ -9,9 +9,13 @@ module.exports = { run: async (outputPath) => { console.log('> Recording dock icon size with param set to 48') - const { stderr: setEnvError } = await exec('defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.dock tilesize -int 48 && killall Dock') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.dock tilesize -int 48 && killall Dock' + ) if (setEnvError) { - console.error('An error occured while setting up the dock tilesize command') + console.error( + 'An error occured while setting up the dock tilesize command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -21,9 +25,11 @@ module.exports = { // Screenshot robot.keyTap('3', ['command', 'shift']) - + await delay(1000) - const screenshot = (await glob(`/Users/${process.env.USER}/Desktop/*.png`)).pop() + const screenshot = ( + await glob(`/Users/${process.env.USER}/Desktop/*.png`) + ).pop() try { await compressPngImage(screenshot, outputPath, '48') @@ -32,18 +38,26 @@ module.exports = { throw new Error(compressPngImageError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock tilesize environment') + console.error( + 'An error occured while cleaning the dock tilesize environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/48` } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock tilesize && killall Dock' + ) } diff --git a/record/finder/AppleShowAllFiles/false.js b/record/finder/AppleShowAllFiles/false.js index 087ca9d..84baa44 100644 --- a/record/finder/AppleShowAllFiles/false.js +++ b/record/finder/AppleShowAllFiles/false.js @@ -8,10 +8,19 @@ module.exports = { try { const runner = new MacRunner() await runner - .setDefault('com.apple.Finder', 'AppleShowAllFiles', '-bool false', 'killall Finder') + .setDefault( + 'com.apple.Finder', + 'AppleShowAllFiles', + '-bool false', + 'killall Finder' + ) .openApp('Finder', '~') .captureApp('Finder', `${outputPath}/false.png`) - .deleteDefault('com.apple.Finder', 'AppleShowAllFiles', 'killall Finder') + .deleteDefault( + 'com.apple.Finder', + 'AppleShowAllFiles', + 'killall Finder' + ) .run() } catch (runnerError) { logRollbackInfo() @@ -30,6 +39,10 @@ module.exports = { } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.Finder AppleShowAllFiles && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.Finder AppleShowAllFiles && killall Finder' + ) } diff --git a/record/finder/AppleShowAllFiles/true.js b/record/finder/AppleShowAllFiles/true.js index b3ca53c..982c27c 100644 --- a/record/finder/AppleShowAllFiles/true.js +++ b/record/finder/AppleShowAllFiles/true.js @@ -8,10 +8,19 @@ module.exports = { try { const runner = new MacRunner() await runner - .setDefault('com.apple.Finder', 'AppleShowAllFiles', '-bool true', 'killall Finder') + .setDefault( + 'com.apple.Finder', + 'AppleShowAllFiles', + '-bool true', + 'killall Finder' + ) .openApp('Finder', '~') .captureApp('Finder', `${outputPath}/true.png`) - .deleteDefault('com.apple.Finder', 'AppleShowAllFiles', 'killall Finder') + .deleteDefault( + 'com.apple.Finder', + 'AppleShowAllFiles', + 'killall Finder' + ) .run() } catch (runnerError) { logRollbackInfo() @@ -30,6 +39,10 @@ module.exports = { } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.Finder AppleShowAllFiles && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.Finder AppleShowAllFiles && killall Finder' + ) } diff --git a/record/finder/FXEnableExtensionChangeWarning/false.js b/record/finder/FXEnableExtensionChangeWarning/false.js index 072eace..5628790 100644 --- a/record/finder/FXEnableExtensionChangeWarning/false.js +++ b/record/finder/FXEnableExtensionChangeWarning/false.js @@ -3,15 +3,25 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder FXEnableExtensionChangeWarning with param set to false') + console.log( + '> Recording finder FXEnableExtensionChangeWarning with param set to false' + ) - const { stderr: setEnvError } = await exec('defaults write com.apple.finder FXEnableExtensionChangeWarning -string false && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.finder FXEnableExtensionChangeWarning -string false && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder FXEnableExtensionChangeWarning command') + console.error( + 'An error occured while setting up the finder FXEnableExtensionChangeWarning command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -37,8 +47,10 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } await moveAndResizeApp('Finder', cropArea, height) @@ -79,19 +91,27 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder FXEnableExtensionChangeWarning environment') + console.error( + 'An error occured while cleaning the finder FXEnableExtensionChangeWarning environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } await delay(1000) return { filepath: `${outputPath}/false`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder' + ) } diff --git a/record/finder/FXEnableExtensionChangeWarning/true.js b/record/finder/FXEnableExtensionChangeWarning/true.js index 8b0fa66..c24b3ae 100644 --- a/record/finder/FXEnableExtensionChangeWarning/true.js +++ b/record/finder/FXEnableExtensionChangeWarning/true.js @@ -3,15 +3,25 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder FXEnableExtensionChangeWarning with param set to true') + console.log( + '> Recording finder FXEnableExtensionChangeWarning with param set to true' + ) - const { stderr: setEnvError } = await exec('defaults write com.apple.finder FXEnableExtensionChangeWarning -string true && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.finder FXEnableExtensionChangeWarning -string true && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder FXEnableExtensionChangeWarning command') + console.error( + 'An error occured while setting up the finder FXEnableExtensionChangeWarning command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -37,8 +47,10 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } await moveAndResizeApp('Finder', cropArea, height) @@ -71,19 +83,27 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder FXEnableExtensionChangeWarning environment') + console.error( + 'An error occured while cleaning the finder FXEnableExtensionChangeWarning environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } await delay(1000) return { filepath: `${outputPath}/true`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.finder FXEnableExtensionChangeWarning && killall Finder' + ) } diff --git a/record/finder/NSTableViewDefaultSizeMode/1.js b/record/finder/NSTableViewDefaultSizeMode/1.js index 08aff4c..d29283c 100644 --- a/record/finder/NSTableViewDefaultSizeMode/1.js +++ b/record/finder/NSTableViewDefaultSizeMode/1.js @@ -2,15 +2,26 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, captureImage, compressPngImage } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + captureImage, + compressPngImage, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder NSTableViewDefaultSizeMode with param set to 1') + console.log( + '> Recording finder NSTableViewDefaultSizeMode with param set to 1' + ) - const { stderr: setEnvError } = await exec('defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 1 && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 1 && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder NSTableViewDefaultSizeMode command') + console.error( + 'An error occured while setting up the finder NSTableViewDefaultSizeMode command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -32,8 +43,10 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } await moveAndResizeApp('Finder', cropArea, height) @@ -42,8 +55,10 @@ module.exports = { // Screenshot captureImage( - cropArea.x, height - recordHeight - cropArea.y, - cropArea.width, cropArea.height + cropArea.x, + height - recordHeight - cropArea.y, + cropArea.width, + cropArea.height ).write(screenshot) try { @@ -53,9 +68,13 @@ module.exports = { throw new Error(compressPngImageError) } - const { stderr: deleteEnvError } = await exec('defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder NSTableViewDefaultSizeMode environment') + console.error( + 'An error occured while cleaning the finder NSTableViewDefaultSizeMode environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } @@ -66,6 +85,10 @@ module.exports = { } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder' + ) } diff --git a/record/finder/NSTableViewDefaultSizeMode/2.js b/record/finder/NSTableViewDefaultSizeMode/2.js index b6545ec..252cb1c 100644 --- a/record/finder/NSTableViewDefaultSizeMode/2.js +++ b/record/finder/NSTableViewDefaultSizeMode/2.js @@ -2,15 +2,26 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, captureImage, compressPngImage } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + captureImage, + compressPngImage, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder NSTableViewDefaultSizeMode with param set to 2') + console.log( + '> Recording finder NSTableViewDefaultSizeMode with param set to 2' + ) - const { stderr: setEnvError } = await exec('defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 2 && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 2 && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder NSTableViewDefaultSizeMode command') + console.error( + 'An error occured while setting up the finder NSTableViewDefaultSizeMode command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -32,8 +43,10 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } await moveAndResizeApp('Finder', cropArea, height) @@ -42,8 +55,10 @@ module.exports = { // Screenshot captureImage( - cropArea.x, height - recordHeight - cropArea.y, - cropArea.width, cropArea.height + cropArea.x, + height - recordHeight - cropArea.y, + cropArea.width, + cropArea.height ).write(screenshot) try { @@ -53,9 +68,13 @@ module.exports = { throw new Error(compressPngImageError) } - const { stderr: deleteEnvError } = await exec('defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder NSTableViewDefaultSizeMode environment') + console.error( + 'An error occured while cleaning the finder NSTableViewDefaultSizeMode environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } @@ -66,6 +85,10 @@ module.exports = { } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder' + ) } diff --git a/record/finder/NSTableViewDefaultSizeMode/3.js b/record/finder/NSTableViewDefaultSizeMode/3.js index 493bb7b..2d13934 100644 --- a/record/finder/NSTableViewDefaultSizeMode/3.js +++ b/record/finder/NSTableViewDefaultSizeMode/3.js @@ -2,15 +2,26 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, captureImage, compressPngImage } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + captureImage, + compressPngImage, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder NSTableViewDefaultSizeMode with param set to 3') + console.log( + '> Recording finder NSTableViewDefaultSizeMode with param set to 3' + ) - const { stderr: setEnvError } = await exec('defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 3 && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 3 && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder NSTableViewDefaultSizeMode command') + console.error( + 'An error occured while setting up the finder NSTableViewDefaultSizeMode command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -32,8 +43,10 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } await moveAndResizeApp('Finder', cropArea, height) @@ -42,8 +55,10 @@ module.exports = { // Screenshot captureImage( - cropArea.x, height - recordHeight - cropArea.y, - cropArea.width, cropArea.height + cropArea.x, + height - recordHeight - cropArea.y, + cropArea.width, + cropArea.height ).write(screenshot) try { @@ -53,9 +68,13 @@ module.exports = { throw new Error(compressPngImageError) } - const { stderr: deleteEnvError } = await exec('defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder NSTableViewDefaultSizeMode environment') + console.error( + 'An error occured while cleaning the finder NSTableViewDefaultSizeMode environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } @@ -66,6 +85,10 @@ module.exports = { } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder' + ) } diff --git a/record/finder/NSToolbarTitleViewRolloverDelay/0.5.js b/record/finder/NSToolbarTitleViewRolloverDelay/0.5.js index 5a8249e..a6dc157 100644 --- a/record/finder/NSToolbarTitleViewRolloverDelay/0.5.js +++ b/record/finder/NSToolbarTitleViewRolloverDelay/0.5.js @@ -3,15 +3,25 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder NSToolbarTitleViewRolloverDelay with param set to 0.5') + console.log( + '> Recording finder NSToolbarTitleViewRolloverDelay with param set to 0.5' + ) - const { stderr: setEnvError } = await exec('defaults write NSGlobalDomain NSToolbarTitleViewRolloverDelay -float 0.5 && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write NSGlobalDomain NSToolbarTitleViewRolloverDelay -float 0.5 && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder NSToolbarTitleViewRolloverDelay command') + console.error( + 'An error occured while setting up the finder NSToolbarTitleViewRolloverDelay command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -25,11 +35,16 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } const pos1 = { x: cropArea.x + recordWidth / 3, y: cropArea.y } - const pos2 = { x: cropArea.x + recordWidth / 3, y: cropArea.y - recordHeight / 2 + 38 } + const pos2 = { + x: cropArea.x + recordWidth / 3, + y: cropArea.y - recordHeight / 2 + 38, + } await moveAndResizeApp('Finder', cropArea, height) robot.moveMouse(pos1.x, pos1.y) @@ -54,19 +69,27 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder NSToolbarTitleViewRolloverDelay environment') + console.error( + 'An error occured while cleaning the finder NSToolbarTitleViewRolloverDelay environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } await delay(1000) return { filepath: `${outputPath}/0.5`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder' + ) } diff --git a/record/finder/NSToolbarTitleViewRolloverDelay/0.js b/record/finder/NSToolbarTitleViewRolloverDelay/0.js index 4d2d114..ab400d6 100644 --- a/record/finder/NSToolbarTitleViewRolloverDelay/0.js +++ b/record/finder/NSToolbarTitleViewRolloverDelay/0.js @@ -3,15 +3,25 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder NSToolbarTitleViewRolloverDelay with param set to 0') + console.log( + '> Recording finder NSToolbarTitleViewRolloverDelay with param set to 0' + ) - const { stderr: setEnvError } = await exec('defaults write NSGlobalDomain NSToolbarTitleViewRolloverDelay -float 0 && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write NSGlobalDomain NSToolbarTitleViewRolloverDelay -float 0 && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder NSToolbarTitleViewRolloverDelay command') + console.error( + 'An error occured while setting up the finder NSToolbarTitleViewRolloverDelay command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -25,11 +35,16 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } const pos1 = { x: cropArea.x + recordWidth / 3, y: cropArea.y } - const pos2 = { x: cropArea.x + recordWidth / 3, y: cropArea.y - recordHeight / 2 + 38 } + const pos2 = { + x: cropArea.x + recordWidth / 3, + y: cropArea.y - recordHeight / 2 + 38, + } await moveAndResizeApp('Finder', cropArea, height) robot.moveMouse(pos1.x, pos1.y) @@ -54,19 +69,27 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder NSToolbarTitleViewRolloverDelay environment') + console.error( + 'An error occured while cleaning the finder NSToolbarTitleViewRolloverDelay environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } await delay(1000) return { filepath: `${outputPath}/0`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder' + ) } diff --git a/record/finder/NSToolbarTitleViewRolloverDelay/1.js b/record/finder/NSToolbarTitleViewRolloverDelay/1.js index 4bf0fcb..76aa9f8 100644 --- a/record/finder/NSToolbarTitleViewRolloverDelay/1.js +++ b/record/finder/NSToolbarTitleViewRolloverDelay/1.js @@ -3,15 +3,25 @@ const delay = require('delay') const robot = require('robotjs') const util = require('util') const exec = util.promisify(require('child_process').exec) -const { makeAppActive, moveAndResizeApp, compressVideo } = require('../../utils') +const { + makeAppActive, + moveAndResizeApp, + compressVideo, +} = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording finder NSToolbarTitleViewRolloverDelay with param set to 1') + console.log( + '> Recording finder NSToolbarTitleViewRolloverDelay with param set to 1' + ) - const { stderr: setEnvError } = await exec('defaults write NSGlobalDomain NSToolbarTitleViewRolloverDelay -float 1 && killall Finder') + const { stderr: setEnvError } = await exec( + 'defaults write NSGlobalDomain NSToolbarTitleViewRolloverDelay -float 1 && killall Finder' + ) if (setEnvError) { - console.error('An error occured while setting up the finder NSToolbarTitleViewRolloverDelay command') + console.error( + 'An error occured while setting up the finder NSToolbarTitleViewRolloverDelay command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -25,11 +35,16 @@ module.exports = { const recordWidth = 720 const recordHeight = 404 const cropArea = { - x: width / 2 - recordWidth / 2, y: 345, - width: recordWidth, height: recordHeight + x: width / 2 - recordWidth / 2, + y: 345, + width: recordWidth, + height: recordHeight, } const pos1 = { x: cropArea.x + recordWidth / 3, y: cropArea.y } - const pos2 = { x: cropArea.x + recordWidth / 3, y: cropArea.y - recordHeight / 2 + 38 } + const pos2 = { + x: cropArea.x + recordWidth / 3, + y: cropArea.y - recordHeight / 2 + 38, + } await moveAndResizeApp('Finder', cropArea, height) robot.moveMouse(pos1.x, pos1.y) @@ -54,19 +69,27 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder') + const { stderr: deleteEnvError } = await exec( + 'defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the finder NSToolbarTitleViewRolloverDelay environment') + console.error( + 'An error occured while cleaning the finder NSToolbarTitleViewRolloverDelay environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } await delay(1000) return { filepath: `${outputPath}/1`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete NSGlobalDomain NSToolbarTitleViewRolloverDelay && killall Finder' + ) } diff --git a/record/index.js b/record/index.js index 55e01b4..2fed340 100644 --- a/record/index.js +++ b/record/index.js @@ -1,3 +1,3 @@ -const record = require('./record'); +const record = require('./record') -(async () => await record(process.argv.slice(2, process.argv.length)))(); +;(async () => await record(process.argv.slice(2, process.argv.length)))() diff --git a/record/mac-runner.js b/record/mac-runner.js index eb228d7..555a485 100644 --- a/record/mac-runner.js +++ b/record/mac-runner.js @@ -48,11 +48,13 @@ class MacRunner { } /** - * Make active a running application + * Make active a running application * @param {*} appName Application name */ activateApp(appName) { - return this.register(() => execCommand(`osascript -e 'tell application "${appName}" to activate'`)) + return this.register(() => + execCommand(`osascript -e 'tell application "${appName}" to activate'`) + ) } /** @@ -66,7 +68,11 @@ class MacRunner { moveAndResizeApp(appName, x, y, width, height) { const h = { start: x, end: x + width } const v = { start: y, end: y + height } - return this.register(() => execCommand(`osascript -e 'tell application "${appName}" to set the bounds of the first window to {${h.start}, ${v.start}, ${h.end}, ${v.end}}'`)) + return this.register(() => + execCommand( + `osascript -e 'tell application "${appName}" to set the bounds of the first window to {${h.start}, ${v.start}, ${h.end}, ${v.end}}'` + ) + ) } /** @@ -86,7 +92,9 @@ class MacRunner { * @param {*} output Output file name (png) */ captureScreenRect(x, y, width, height, output) { - return this.register(() => execCommand(`screencapture -R${x},${y},${width},${height} ${output}`)) + return this.register(() => + execCommand(`screencapture -R${x},${y},${width},${height} ${output}`) + ) } /** @@ -95,7 +103,11 @@ class MacRunner { * @param {*} output Output file name (png) */ captureApp(appName, output) { - return this.register(() => execCommand(`screencapture -o -l$(osascript -e 'tell app "${appName}" to id of window 1') ${output}`)) + return this.register(() => + execCommand( + `screencapture -o -l$(osascript -e 'tell app "${appName}" to id of window 1') ${output}` + ) + ) } /** @@ -155,4 +167,4 @@ async function execCommand(command, delay = 1000) { await wait(delay) } -module.exports = MacRunner \ No newline at end of file +module.exports = MacRunner diff --git a/record/menubar/DateFormat/EEE_HH.mm.ss.js b/record/menubar/DateFormat/EEE_HH.mm.ss.js index 226c6ba..2592240 100644 --- a/record/menubar/DateFormat/EEE_HH.mm.ss.js +++ b/record/menubar/DateFormat/EEE_HH.mm.ss.js @@ -7,13 +7,19 @@ const { makeAppActive, compressVideo } = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording menu bar clock DateFormat with param set to "EEE HH:mm:ss"') + console.log( + '> Recording menu bar clock DateFormat with param set to "EEE HH:mm:ss"' + ) // Set the menu bar menuExtras to only show the clock, it will be on the left of notification center, siri, and spotlight search. - const { stderr: setEnvError } = await exec(`defaults write com.apple.menuextra.clock DateFormat -string "EEE HH:mm:ss" && killall SystemUIServer && sleep 10`) + const { stderr: setEnvError } = await exec( + `defaults write com.apple.menuextra.clock DateFormat -string "EEE HH:mm:ss" && killall SystemUIServer && sleep 10` + ) if (setEnvError) { - console.error('An error occured while setting up the menu bar clock DateFormat command') + console.error( + 'An error occured while setting up the menu bar clock DateFormat command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -24,8 +30,10 @@ module.exports = { const recordWidth = 400 const recordHeight = 22 const cropArea = { - x: width - recordWidth, y: height - recordHeight, // Film the menu bar, which is 22 pixels - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: height - recordHeight, // Film the menu bar, which is 22 pixels + width: recordWidth, + height: recordHeight, } // Action! @@ -42,18 +50,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer && sleep 5') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer && sleep 5' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the menu bar clock DateFormat environment') + console.error( + 'An error occured while cleaning the menu bar clock DateFormat environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/EEE_HH.mm.ss`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer' + ) } diff --git a/record/menubar/DateFormat/EEE_d_MMM_HH.mm.ss.js b/record/menubar/DateFormat/EEE_d_MMM_HH.mm.ss.js index 2a80c2f..9494709 100644 --- a/record/menubar/DateFormat/EEE_d_MMM_HH.mm.ss.js +++ b/record/menubar/DateFormat/EEE_d_MMM_HH.mm.ss.js @@ -7,13 +7,19 @@ const { makeAppActive, compressVideo } = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording menu bar clock DateFormat with param set to "EEE d MMM HH:mm:ss"') + console.log( + '> Recording menu bar clock DateFormat with param set to "EEE d MMM HH:mm:ss"' + ) // Set the menu bar menuExtras to only show the clock, it will be on the left of notification center, siri, and spotlight search. - const { stderr: setEnvError } = await exec(`defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM HH:mm:ss" && killall SystemUIServer && sleep 10`) + const { stderr: setEnvError } = await exec( + `defaults write com.apple.menuextra.clock DateFormat -string "EEE d MMM HH:mm:ss" && killall SystemUIServer && sleep 10` + ) if (setEnvError) { - console.error('An error occured while setting up the menu bar clock DateFormat command') + console.error( + 'An error occured while setting up the menu bar clock DateFormat command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -24,8 +30,10 @@ module.exports = { const recordWidth = 400 const recordHeight = 22 const cropArea = { - x: width - recordWidth, y: height - recordHeight, // Film the menu bar, which is 22 pixels - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: height - recordHeight, // Film the menu bar, which is 22 pixels + width: recordWidth, + height: recordHeight, } // Action! @@ -42,18 +50,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer && sleep 5') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer && sleep 5' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the menu bar clock DateFormat environment') + console.error( + 'An error occured while cleaning the menu bar clock DateFormat environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/EEE_d_MMM_HH.mm.ss`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer' + ) } diff --git a/record/menubar/DateFormat/EEE_h.mm.ss.js b/record/menubar/DateFormat/EEE_h.mm.ss.js index 467e724..48997d1 100644 --- a/record/menubar/DateFormat/EEE_h.mm.ss.js +++ b/record/menubar/DateFormat/EEE_h.mm.ss.js @@ -7,13 +7,19 @@ const { makeAppActive, compressVideo } = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording menu bar clock DateFormat with param set to "EEE h:mm:ss"') + console.log( + '> Recording menu bar clock DateFormat with param set to "EEE h:mm:ss"' + ) // Set the menu bar menuExtras to only show the clock, it will be on the left of notification center, siri, and spotlight search. - const { stderr: setEnvError } = await exec(`defaults write com.apple.menuextra.clock DateFormat -string "EEE h:mm:ss" && killall SystemUIServer && sleep 10`) + const { stderr: setEnvError } = await exec( + `defaults write com.apple.menuextra.clock DateFormat -string "EEE h:mm:ss" && killall SystemUIServer && sleep 10` + ) if (setEnvError) { - console.error('An error occured while setting up the menu bar clock DateFormat command') + console.error( + 'An error occured while setting up the menu bar clock DateFormat command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -24,8 +30,10 @@ module.exports = { const recordWidth = 400 const recordHeight = 22 const cropArea = { - x: width - recordWidth, y: height - recordHeight, // Film the menu bar, which is 22 pixels - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: height - recordHeight, // Film the menu bar, which is 22 pixels + width: recordWidth, + height: recordHeight, } // Action! @@ -42,18 +50,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer && sleep 5') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer && sleep 5' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the menu bar clock DateFormat environment') + console.error( + 'An error occured while cleaning the menu bar clock DateFormat environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/EEE_h.mm.ss`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.menuextra.clock DateFormat && killall SystemUIServer' + ) } diff --git a/record/menubar/FlashDateSeparators/false.js b/record/menubar/FlashDateSeparators/false.js index 2b304a4..d4288f8 100644 --- a/record/menubar/FlashDateSeparators/false.js +++ b/record/menubar/FlashDateSeparators/false.js @@ -7,13 +7,19 @@ const { makeAppActive, compressVideo } = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording menu bar clock FlashDateSeparators with param set to false') + console.log( + '> Recording menu bar clock FlashDateSeparators with param set to false' + ) // Set the menu bar menuExtras to only show the clock, it will be on the left of notification center, siri, and spotlight search. - const { stderr: setEnvError } = await exec(`defaults write com.apple.menuextra.clock FlashDateSeparators -bool false && killall SystemUIServer && sleep 10`) + const { stderr: setEnvError } = await exec( + `defaults write com.apple.menuextra.clock FlashDateSeparators -bool false && killall SystemUIServer && sleep 10` + ) if (setEnvError) { - console.error('An error occured while setting up the menu bar clock FlashDateSeparators command') + console.error( + 'An error occured while setting up the menu bar clock FlashDateSeparators command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -24,8 +30,10 @@ module.exports = { const recordWidth = 400 const recordHeight = 22 const cropArea = { - x: width - recordWidth, y: height - recordHeight, // Film the menu bar, which is 22 pixels - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: height - recordHeight, // Film the menu bar, which is 22 pixels + width: recordWidth, + height: recordHeight, } // Action! @@ -42,18 +50,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer && sleep 10') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer && sleep 10' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the menu bar clock FlashDateSeparators environment') + console.error( + 'An error occured while cleaning the menu bar clock FlashDateSeparators environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/false`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer' + ) } diff --git a/record/menubar/FlashDateSeparators/true.js b/record/menubar/FlashDateSeparators/true.js index 33d6ee2..69b7dc0 100644 --- a/record/menubar/FlashDateSeparators/true.js +++ b/record/menubar/FlashDateSeparators/true.js @@ -7,13 +7,19 @@ const { makeAppActive, compressVideo } = require('../../utils') module.exports = { run: async (outputPath) => { - console.log('> Recording menu bar clock FlashDateSeparators with param set to true') + console.log( + '> Recording menu bar clock FlashDateSeparators with param set to true' + ) // Set the menu bar menuExtras to only show the clock, it will be on the left of notification center, siri, and spotlight search. - const { stderr: setEnvError } = await exec(`defaults write com.apple.menuextra.clock FlashDateSeparators -bool true && killall SystemUIServer && sleep 10`) + const { stderr: setEnvError } = await exec( + `defaults write com.apple.menuextra.clock FlashDateSeparators -bool true && killall SystemUIServer && sleep 10` + ) if (setEnvError) { - console.error('An error occured while setting up the menu bar clock FlashDateSeparators command') + console.error( + 'An error occured while setting up the menu bar clock FlashDateSeparators command' + ) logRollbackInfo() throw new Error(setEnvError) } @@ -24,8 +30,10 @@ module.exports = { const recordWidth = 400 const recordHeight = 22 const cropArea = { - x: width - recordWidth, y: height - recordHeight, // Film the menu bar, which is 22 pixels - width: recordWidth, height: recordHeight + x: width - recordWidth, + y: height - recordHeight, // Film the menu bar, which is 22 pixels + width: recordWidth, + height: recordHeight, } // Action! @@ -42,18 +50,26 @@ module.exports = { throw new Error(compressVideoError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer && sleep 10') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer && sleep 10' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the menu bar clock FlashDateSeparators environment') + console.error( + 'An error occured while cleaning the menu bar clock FlashDateSeparators environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/true`, isVideo: true } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer' + ) } diff --git a/record/readme.md b/record/readme.md index 7bc06eb..c4621f0 100644 --- a/record/readme.md +++ b/record/readme.md @@ -5,21 +5,25 @@ All the images and videos you will find on **macos-defaults** are built programmatically. It's done using **Node.js** scripts found in this folder subfolders. Programmatic record serves 2 goals: + - Record similar actions with different `defaults` config. - Make it easy to replay when a new version comes out. ## Technical overview + The [record.js](./record.js) file launches subfolders' recording scripts. The scripts are all the `.js` files in this folder subfolders. There is one script per screenshot/video. These scripts share the same workflow: + 1. Set a `defaults` command value 2. Prepare the recording using [robot.js](https://github.com/octalmage/robotjs) 3. Record using [Aperture](https://github.com/wulkano/aperture-node) 4. Post production (resize, compress, move) 5. Reset the `defaults` value -I try to keep as much similarity as possible for same-command examples. + I try to keep as much similarity as possible for same-command examples. Some [utils](./utils.js) are available to simplify scripts dev: + - `captureImage(x, y, width, height)` capture a screenshot using [jimp](https://github.com/oliver-moran/jimp) - `x`: position from the left border of the screen. - `y`: position from the bottom border of the screen. @@ -43,9 +47,11 @@ Some [utils](./utils.js) are available to simplify scripts dev: I consider removing the resize/compression part and upload these assets to a media CDN like [Cloudinary](https://cloudinary.com) to serve optimal resources based on user preferences. ## Launch locally + This part is only useful if you want to add a command. I **strongely recommand** not to launch the scripts locally if you don't want to mess up your config. ### 💻 My setup + I'm personally launching these scripts on a 15" 2015 MacBook Pro running the latest macOS developer beta version. I log in as another account when I want to work on the scripts. The scripts should be agnostic from the hardware they run on, please let me know if some of them do not by [opening an issue](https://github.com/yannbertrand/macos-defaults/issues/new). ### 🏗 Install diff --git a/record/record.js b/record/record.js index c2f417a..bc3e35f 100644 --- a/record/record.js +++ b/record/record.js @@ -6,15 +6,16 @@ const { makeAppActive } = require('./utils') module.exports = async (files) => { try { - const scriptFiles = files.length > 0 ? files : await glob('!(node_modules)/**/*.js') + const scriptFiles = + files.length > 0 ? files : await glob('!(node_modules)/**/*.js') console.info(`\nFound ${scriptFiles.length} scripts to run.`) console.info('Please close Safari and do not move the mouse until the end.') console.info('It should take a few minutes, go grab a drink!\n') console.info('iTerm should reopen when its done.\n') - const prompt = new Confirm('Ready?'); - if (!await prompt.run()) return + const prompt = new Confirm('Ready?') + if (!(await prompt.run())) return robot.keyTap('h', 'command') @@ -30,13 +31,19 @@ module.exports = async (files) => { await makeAppActive('iTerm') - console.info(`\nAll videos and screenshots were successfully recorded. You can use your mouse again\n`) + console.info( + `\nAll videos and screenshots were successfully recorded. You can use your mouse again\n` + ) } catch (error) { if (error.code === 'RECORDER_TIMEOUT') { console.error(error.message) console.info('The recorder timed out.') - console.info('You probably need to activate the screen recording feature for the terminal you\'re using.') - console.info('You\'ll find that settings under: System Parameters > Security & Confidentiality > Confidentiality > Screen recording') + console.info( + "You probably need to activate the screen recording feature for the terminal you're using." + ) + console.info( + "You'll find that settings under: System Parameters > Security & Confidentiality > Confidentiality > Screen recording" + ) } else if (error.code === 'ENOTDIR') { console.error(error.message) console.info('A mandatory folder was not found.') @@ -46,4 +53,4 @@ module.exports = async (files) => { } } -const getImagePath = file => path.normalize(`../images/${path.dirname(file)}`) +const getImagePath = (file) => path.normalize(`../images/${path.dirname(file)}`) diff --git a/record/screenshots/disable-shadow/false.js b/record/screenshots/disable-shadow/false.js index 553f866..a5b0e41 100644 --- a/record/screenshots/disable-shadow/false.js +++ b/record/screenshots/disable-shadow/false.js @@ -9,15 +9,22 @@ module.exports = { run: async (outputPath) => { console.log('> Recording screenshot disable-shadow with param set to false') - const { stderr: setEnvError } = await exec('defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.screencapture disable-shadow -bool false') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.screencapture disable-shadow -bool false' + ) if (setEnvError) { - console.error('An error occured while setting up the screenshot disble-shadow command') + console.error( + 'An error occured while setting up the screenshot disble-shadow command' + ) logRollbackInfo() throw new Error(setEnvError) } // Preparation - robot.moveMouse(robot.getScreenSize().width / 2, robot.getScreenSize().height / 2) + robot.moveMouse( + robot.getScreenSize().width / 2, + robot.getScreenSize().height / 2 + ) robot.mouseClick() await makeAppActive('Safari') @@ -42,7 +49,9 @@ module.exports = { robot.keyTap('w', 'command') await delay(1000) - const screenshot = (await glob(`/Users/${process.env.USER}/Desktop/*.png`)).pop() + const screenshot = ( + await glob(`/Users/${process.env.USER}/Desktop/*.png`) + ).pop() try { await compressPngImage(screenshot, outputPath, 'false') @@ -51,18 +60,26 @@ module.exports = { throw new Error(compressPngImageError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock autohide-delay environment') + console.error( + 'An error occured while cleaning the dock autohide-delay environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/false`, isVideo: false } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow' + ) } diff --git a/record/screenshots/disable-shadow/true.js b/record/screenshots/disable-shadow/true.js index b89bd6e..309bd67 100644 --- a/record/screenshots/disable-shadow/true.js +++ b/record/screenshots/disable-shadow/true.js @@ -9,15 +9,22 @@ module.exports = { run: async (outputPath) => { console.log('> Recording screenshot disable-shadow with param set to true') - const { stderr: setEnvError } = await exec('defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.screencapture disable-shadow -bool true') + const { stderr: setEnvError } = await exec( + 'defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.screencapture disable-shadow -bool true' + ) if (setEnvError) { - console.error('An error occured while setting up the screenshot disble-shadow command') + console.error( + 'An error occured while setting up the screenshot disble-shadow command' + ) logRollbackInfo() throw new Error(setEnvError) } // Preparation - robot.moveMouse(robot.getScreenSize().width / 2, robot.getScreenSize().height / 2) + robot.moveMouse( + robot.getScreenSize().width / 2, + robot.getScreenSize().height / 2 + ) robot.mouseClick() await makeAppActive('Safari') @@ -42,7 +49,9 @@ module.exports = { robot.keyTap('w', 'command') await delay(1000) - const screenshot = (await glob(`/Users/${process.env.USER}/Desktop/*.png`)).pop() + const screenshot = ( + await glob(`/Users/${process.env.USER}/Desktop/*.png`) + ).pop() try { await compressPngImage(screenshot, outputPath, 'true') @@ -51,18 +60,26 @@ module.exports = { throw new Error(compressPngImageError) } - const { stderr: deleteEnvError } = await exec('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow') + const { stderr: deleteEnvError } = await exec( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow' + ) if (deleteEnvError) { - console.error('An error occured while cleaning the dock autohide-delay environment') + console.error( + 'An error occured while cleaning the dock autohide-delay environment' + ) logRollbackInfo() throw new Error(deleteEnvError) } return { filepath: `${outputPath}/true`, isVideo: false } - } + }, } function logRollbackInfo() { - console.info('Please manually run this command to make sure everything is properly reset:') - console.info('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow') + console.info( + 'Please manually run this command to make sure everything is properly reset:' + ) + console.info( + 'defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.screencapture disable-shadow' + ) } diff --git a/record/utils.js b/record/utils.js index a4c9263..6b87e89 100644 --- a/record/utils.js +++ b/record/utils.js @@ -15,9 +15,12 @@ module.exports.captureImage = (x, y, w, h) => { let red, green, blue pic.image.forEach((byte, i) => { switch (i % 4) { - case 0: return blue = byte - case 1: return green = byte - case 2: return red = byte + case 0: + return (blue = byte) + case 1: + return (green = byte) + case 2: + return (red = byte) case 3: image.bitmap.data[i - 3] = red image.bitmap.data[i - 2] = green @@ -28,7 +31,11 @@ module.exports.captureImage = (x, y, w, h) => { return image } -module.exports.compressPngImage = async (inputPath, outputFolder, outputName) => { +module.exports.compressPngImage = async ( + inputPath, + outputFolder, + outputName +) => { const tmpOutput = `${outputFolder}/${outputName}-tmp.png` const finalOutput = `${outputFolder}/${outputName}.png` @@ -38,12 +45,15 @@ module.exports.compressPngImage = async (inputPath, outputFolder, outputName) => return new Promise((resolve, reject) => { console.info(' Compressing PNG image') sharp(tmpOutput) - .resize(740, undefined, { fit: sharp.fit.inside, withoutEnlargement: true }) + .resize(740, undefined, { + fit: sharp.fit.inside, + withoutEnlargement: true, + }) .toFormat('png') .toBuffer() - .then(resizedBuffer => { + .then((resizedBuffer) => { const responseBuffer = pngquant.compress(resizedBuffer) - fs.writeFile(finalOutput, responseBuffer, writeFileError => { + fs.writeFile(finalOutput, responseBuffer, (writeFileError) => { removeSync(tmpOutput) if (writeFileError) { console.error('An error occured while saving the image') @@ -77,7 +87,22 @@ function resizeVideo(input, output) { console.info(' Resizing video') return new Promise((resolve, reject) => { - const ffmpeg = spawn('ffmpeg', ['-i', input, '-vf', 'scale=\'min(740,iw)\':-2', '-c:v', 'libx264', '-crf', '18', '-preset', 'veryslow', '-y', '-c:a', 'copy', output]) + const ffmpeg = spawn('ffmpeg', [ + '-i', + input, + '-vf', + "scale='min(740,iw)':-2", + '-c:v', + 'libx264', + '-crf', + '18', + '-preset', + 'veryslow', + '-y', + '-c:a', + 'copy', + output, + ]) if (process.env.NODE_ENV === 'DEBUG') { ffmpeg.stderr.on('data', function (message) { @@ -85,7 +110,7 @@ function resizeVideo(input, output) { }) } - ffmpeg.on('exit', ffmpegExitCode => { + ffmpeg.on('exit', (ffmpegExitCode) => { if (ffmpegExitCode === '1') { return reject('ffmpeg') } @@ -103,7 +128,14 @@ function removeSync(file) { module.exports.makeAppActive = async (appName) => { return new Promise((resolve, reject) => { - const osascript = spawn('osascript', ['-e', 'try', '-e', `tell application "${appName}" to activate`, '-e', 'end try']) + const osascript = spawn('osascript', [ + '-e', + 'try', + '-e', + `tell application "${appName}" to activate`, + '-e', + 'end try', + ]) if (process.env.NODE_ENV === 'DEBUG') { osascript.stderr.on('data', function (message) { @@ -111,7 +143,7 @@ module.exports.makeAppActive = async (appName) => { }) } - osascript.on('exit', osascriptExitCode => { + osascript.on('exit', (osascriptExitCode) => { if (osascriptExitCode === '1') { return reject('osascript') } @@ -123,10 +155,24 @@ module.exports.makeAppActive = async (appName) => { module.exports.moveAndResizeApp = async (appName, cropArea, screenHeight) => { const x = { start: cropArea.x, end: cropArea.x + cropArea.width } - const y = { start: screenHeight - cropArea.y - cropArea.height, end: screenHeight - cropArea.y } + const y = { + start: screenHeight - cropArea.y - cropArea.height, + end: screenHeight - cropArea.y, + } return new Promise((resolve, reject) => { - const osascript = spawn('osascript', ['-e', 'try', '-e', `tell application "${appName}"`, '-e', `set the bounds of the first window to {${x.start}, ${y.start}, ${x.end}, ${y.end}}`, '-e', 'end tell', '-e', 'end try']) + const osascript = spawn('osascript', [ + '-e', + 'try', + '-e', + `tell application "${appName}"`, + '-e', + `set the bounds of the first window to {${x.start}, ${y.start}, ${x.end}, ${y.end}}`, + '-e', + 'end tell', + '-e', + 'end try', + ]) if (process.env.NODE_ENV === 'DEBUG') { osascript.stderr.on('data', function (message) { @@ -134,7 +180,7 @@ module.exports.moveAndResizeApp = async (appName, cropArea, screenHeight) => { }) } - osascript.on('exit', osascriptExitCode => { + osascript.on('exit', (osascriptExitCode) => { if (osascriptExitCode === '1') { return reject('osascript') } diff --git a/record/yarn.lock b/record/yarn.lock index 31d3b64..c1d253b 100644 --- a/record/yarn.lock +++ b/record/yarn.lock @@ -1529,6 +1529,11 @@ prebuild-install@^6.0.0: tunnel-agent "^0.6.0" which-pm-runs "^1.0.0" +prettier@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.0.tgz#8a03c7777883b29b37fb2c4348c66a78e980418b" + integrity sha512-yYerpkvseM4iKD/BXLYUkQV5aKt4tQPqaGW6EsZjzyu0r7sVZZNPJW4Y8MyKmicp6t42XUPcBVA+H6sB3gqndw== + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"