2020-09-09 22:05:23 +00:00
|
|
|
const glob = require('glob-promise')
|
|
|
|
const path = require('path')
|
|
|
|
const robot = require('robotjs')
|
|
|
|
const Confirm = require('prompt-confirm')
|
|
|
|
const { makeAppActive } = require('./utils')
|
|
|
|
|
|
|
|
module.exports = async (files) => {
|
|
|
|
try {
|
2020-11-27 12:45:16 +00:00
|
|
|
const scriptFiles =
|
|
|
|
files.length > 0 ? files : await glob('!(node_modules)/**/*.js')
|
2020-09-09 22:05:23 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2020-11-27 12:45:16 +00:00
|
|
|
const prompt = new Confirm('Ready?')
|
|
|
|
if (!(await prompt.run())) return
|
2020-09-09 22:05:23 +00:00
|
|
|
|
|
|
|
robot.keyTap('h', 'command')
|
|
|
|
|
|
|
|
for (const scriptFile of scriptFiles) {
|
|
|
|
const script = require(`./${scriptFile}`)
|
2020-11-23 20:36:09 +00:00
|
|
|
try {
|
|
|
|
await script.run(getImagePath(scriptFile))
|
|
|
|
} catch (error) {
|
|
|
|
await makeAppActive('iTerm')
|
|
|
|
throw error
|
|
|
|
}
|
2020-09-09 22:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await makeAppActive('iTerm')
|
|
|
|
|
2020-11-27 12:45:16 +00:00
|
|
|
console.info(
|
|
|
|
`\nAll videos and screenshots were successfully recorded. You can use your mouse again\n`
|
|
|
|
)
|
2020-09-09 22:05:23 +00:00
|
|
|
} catch (error) {
|
|
|
|
if (error.code === 'RECORDER_TIMEOUT') {
|
|
|
|
console.error(error.message)
|
|
|
|
console.info('The recorder timed out.')
|
2020-11-27 12:45:16 +00:00
|
|
|
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"
|
|
|
|
)
|
2020-09-09 22:05:23 +00:00
|
|
|
} else if (error.code === 'ENOTDIR') {
|
|
|
|
console.error(error.message)
|
|
|
|
console.info('A mandatory folder was not found.')
|
|
|
|
} else {
|
|
|
|
console.error('An error occured while recording', error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 12:45:16 +00:00
|
|
|
const getImagePath = (file) => path.normalize(`../images/${path.dirname(file)}`)
|