module.exports = async function() { console.log(green('Setup Puppeteer')); const browser = await puppeteer.launch({ headless: true, /* slowMo: 300 */ args: ['--no-sandbox'] }); global.__BROWSER__ = browser; mkdirp.sync(DIR); fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint()); };
test('test ./help.js', (t) => { const messages = [] const globals = { console: { log(message) { messages.push(message.trim()) } }, process: { exitCode: 0 } } const help = proxyquire('./help.js', { './src/globals.js': globals }) help('testing.js', ['test-command'], '', { parameters: [ { name: 'p0', description: 'the description', required: true }, { name: 'p1', multiple: true, type(val) { if (val == null) { return ['a', 'b'] } return val } } ], options: [ { name: 'aaa', alias: 'a', multiple: true, description: 'a Boolean' }, { name: 'bbb', alias: 'b', required: true, description: 'a Number', type(val) { if (val == null) { return 100 } return Number(val) } } ], commands: [] }) help('testing.js', ['test-command'], 'a test command', { parameters: [{ name: 'p0', description: 'the description', required: true }], options: [{ name: 'aaa', alias: 'a', description: 'a Boolean' }], commands: [ { command: ['test-command', 'sub'], description: 'a sub command', parameters: [{ name: 'p1', description: 'the description', required: true }], options: [{ name: 'bbb', alias: 'b', description: 'a Boolean' }] } ] }) help('testing.js', ['test-command'], 'a test command', { options: [{ name: 'aaa', alias: 'a', multiple: true, description: 'a Boolean' }], parameters: [], commands: [] }) help('testing.js', ['test-command'], 'a test command'.split(' ').join('\n'), {options: [], parameters: [], commands: []}) t.plan(2) t.equals(globals.process.exitCode, 1) t.deepEquals([ outdent` ${green('Usage:')} testing.js test-command [-a]... (-b <bbb>) <p0> [<p1>]... ${green('Parameters:')} <p0> the description <p1> [default: ["a","b"]] ${green('Options:')} -a, --aaa a Boolean -b, --bbb <bbb> a Number [default: 100] `, outdent` ${green('Description:')} a test command ${green('Usage:')} testing.js test-command [-a] <p0> ${green('Parameters:')} <p0> the description ${green('Options:')} -a, --aaa a Boolean ${green('Commands:')} testing.js test-command sub [-b] <p1> `, outdent` ${green('Description:')} a test command ${green('Usage:')} testing.js test-command [-a]... ${green('Options:')} -a, --aaa a Boolean `, outdent` ${green('Description:')} a test command ${green('Usage:')} testing.js test-command ` ], messages) })
renderOption(cursor, v, i) { let title; if (v.disabled) title = cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);else title = cursor === i ? color.cyan().underline(v.title) : v.title; return (v.selected ? color.green(figures.radioOn) : figures.radioOff) + ' ' + title; } // shared with autocompleteMultiselect
invisible: { scale: 0, render: input => '' }, default: { scale: 1, render: input => `${input}` } }); const render = type => styles[type] || styles.default; // icon to signalize a prompt. const symbols = Object.freeze({ aborted: c.red(figures.cross), done: c.green(figures.tick), default: c.cyan('?') }); const symbol = (done, aborted) => aborted ? symbols.aborted : done ? symbols.done : symbols.default; // between the question and the user's input. const delimiter = completing => c.gray(completing ? figures.ellipsis : figures.pointerSmall); const item = (expandable, expanded) => c.gray(expandable ? expanded ? figures.pointerSmall : '+' : figures.line); module.exports = { styles, render, symbols, symbol,
.map((v, i) => { let title; if (v.disabled) title = c === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title); else title = c === i ? color.cyan().underline(v.title) : v.title; return (v.selected ? color.green(figures.tick) : ' ') + ' ' + title })
module.exports = async function() { console.log(green('Teardown Puppeteer')); await global.__BROWSER__.close(); rimraf.sync(DIR) };
/** * Logs a build success * * @param {string} fileName * @param {array} duration the duration as provided by hrtime() */ logBuildSuccess (fileName, duration) { this.logWithDuration(`${kleur.green("Build finished")}: ${kleur.yellow(fileName)}`, duration); }
/** * Logs the start of a build */ logBuildStart () { this.log(kleur.green(`Build started`)); }
module.exports = (name, command, description, {options, parameters, commands}) => { process.exitCode = 1 const lines = [] if (description) { const trimmedDescription = description.trim() const lineCount = trimmedDescription.split('\n').length if (lineCount > 1) { lines.push('', green('Description:'), '', trimmedDescription) } else { lines.push('', `${green('Description:')} ${trimmedDescription}`) } } lines.push('', `${green('Usage:')}${getUsage(name, command, {options, parameters})}`) const longestArg = longest([ ...parameters.map((definition) => `<${definition.name}>`), ...options.map((definition) => getOptionSignature(definition)) ]) if (parameters.length) { lines.push('', green('Parameters:'), '') for (const definition of parameters) { let line = ` <${definition.name}>${spaces(longestArg - definition.name.length - 2)} ` if (definition.description) { line += `${definition.description} ` } if (definition.type != null) { const _default = definition.type() if (_default != null) { line += `[default: ${JSON.stringify(_default)}]` } } lines.push(line.trimRight()) } } if (options.length) { lines.push('', green('Options:'), '') for (const definition of options) { const signature = getOptionSignature(definition) let line = ` ${signature + spaces(longestArg - signature.length)} ` if (definition.description) { line += `${definition.description} ` } if (definition.type != null) { const _default = definition.type() if (_default != null) { line += `[default: ${JSON.stringify(_default)}]` } } lines.push(line.trimRight()) } } if (commands.length) { lines.push('', green('Commands:'), '', ...commandList(name, commands)) } lines.push('') console.log(lines.join('\n')) }