🚨 Run Prettier

This commit is contained in:
Yann Bertrand 2020-11-27 13:45:16 +01:00
parent 0aa9085661
commit a6a996ddd2
95 changed files with 2360 additions and 1395 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -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(

View file

@ -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')

View file

@ -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)
}

View file

@ -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}`)
})
@ -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}`)
})
@ -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}`)
})
@ -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}`)
})
@ -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')

View file

@ -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)
}

View file

@ -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')

View file

@ -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}`,

View file

@ -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')

View file

@ -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

View file

@ -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

View file

@ -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 {
</a>
<div>
<h5>Docs</h5>
<a href="/">
Home
</a>
<a href="/">Home</a>
</div>
<div>
<h5>More</h5>
@ -28,7 +26,8 @@ class Footer extends React.Component {
<div className="social">
<a
href={`https://twitter.com/${this.props.config.twitterUsername}`}
className="twitter-follow-button">
className="twitter-follow-button"
>
Follow @{this.props.config.twitterUsername}
</a>
</div>
@ -36,8 +35,8 @@ class Footer extends React.Component {
</div>
</section>
</footer>
);
)
}
}
module.exports = Footer;
module.exports = Footer

View file

@ -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

View file

@ -1,18 +1,16 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="0; url=docs/" />
<script type="text/javascript">
window.location.href = 'docs/'
</script>
<title>macOS defaults</title>
</head>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="0; url=docs/" />
<script type="text/javascript">
window.location.href = 'docs/';
</script>
<title>macOS defaults</title>
</head>
<body>
If you are not redirected automatically, follow this
<a href="docs/">link</a>.
</body>
<body>
If you are not redirected automatically, follow this
<a href="docs/">link</a>.
</body>
</html>

View file

@ -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))
)
}

View file

@ -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')

View file

@ -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)
}

View file

@ -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')

View file

@ -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}`)

View file

@ -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')

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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(

View file

@ -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')

View file

@ -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`
)
}

View file

@ -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')

View file

@ -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)
}

View file

@ -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')

View file

@ -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}`
)
}
})
})

View file

@ -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')

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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"
}

View file

@ -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(

View file

@ -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')

View file

@ -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
)
}

View file

@ -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')

View file

@ -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)
}

View file

@ -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')

View file

@ -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}`,

View file

@ -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. <br> `defaults command`'
message: 'This an alert message. <br> `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')

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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(

View file

@ -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')

View file

@ -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
)
}

View file

@ -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')

View file

@ -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)
}

View file

@ -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')

View file

@ -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}`,

View file

@ -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')

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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')
}

View file

@ -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')
}

View file

@ -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')
}

View file

@ -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')
}

View file

@ -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')
}

View file

@ -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')
}

View file

@ -22,5 +22,5 @@ module.exports = {
}
return { filepath: `${outputPath}/dock` }
}
},
}

View file

@ -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')
}

View file

@ -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')
}

View file

@ -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)
}
@ -23,7 +27,9 @@ module.exports = {
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'
)
}

View file

@ -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)
}
@ -23,7 +27,9 @@ module.exports = {
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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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)))()

View file

@ -52,7 +52,9 @@ class MacRunner {
* @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}`
)
)
}
/**

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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

View file

@ -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)}`)

View file

@ -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'
)
}

View file

@ -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'
)
}

View file

@ -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')
}

View file

@ -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"