/** * @param {string} message * @param {string} linkTitle * @param {string} linkUrl */ function printErrorWithLink(message, linkTitle, linkUrl) { console.error(`${kleur.bold.red(message)}\n\n${linkTitle}\n${kleur.underline(linkUrl)}\n`); }
/** * @param {string} header * @param {object} object */ function verbose(header, object) { logger.debug(kleur.bold(header) + '\n\n' + stringify(object)); }
/** * @param {object} urls */ function printServerInstructions(urls) { console.log(`You can now view your style guide in the browser:`); console.log(); console.log(` ${kleur.bold('Local:')} ${urls.localUrlForTerminal}`); if (urls.lanUrlForTerminal) { console.log(` ${kleur.bold('On your network:')} ${urls.lanUrlForTerminal}`); } console.log(); }
// Check for unknown fields map(config, (value, key) => { if (!schema[key]) { // Try to guess const possibleOptions = Object.keys(schema); const suggestion = possibleOptions.reduce((suggestion, option) => { const steps = leven(option, key); if (steps < 2) { return option; } return suggestion; }, null); throw new StyleguidistError( `Unknown config option ${kleur.bold(key)} was found, the value is:\n` + stringify(value) + (suggestion ? `\n\nDid you mean ${kleur.bold(suggestion)}?` : '') ); } });
// Do not show nasty stack traces for Styleguidist errors process.on('uncaughtException', err => { if (err.code === 'EADDRINUSE') { printErrorWithLink( `Another server is running at port ${ config.serverPort } already. Please stop it or change the default port to continue.`, 'You can change the port using the `serverPort` option in your style guide config:', consts.DOCS_CONFIG ); } else if (err instanceof StyleguidistError) { console.error(kleur.bold.red(err.message)); logger.debug(err.stack); } else { console.error(err.toString()); console.error(err.stack); } process.exit(1); });
summaryPass(count) { return green(`${bold('✔ PASS')}: ${count}`); }
function commandHelp() { console.log( [ kleur.underline('Usage'), '', ' ' + kleur.bold('styleguidist') + ' ' + kleur.cyan('<command>') + ' ' + kleur.yellow('[<options>]'), '', kleur.underline('Commands'), '', ' ' + kleur.cyan('build') + ' Build style guide', ' ' + kleur.cyan('server') + ' Run development server', ' ' + kleur.cyan('help') + ' Display React Styleguidist help', '', kleur.underline('Options'), '', ' ' + kleur.yellow('--config') + ' Config file path', ' ' + kleur.yellow('--open') + ' Open Styleguidist in the default browser', ' ' + kleur.yellow('--verbose') + ' Print debug information', ].join('\n') ); }
const message = isString(isRequired) ? isRequired : `${kleur.bold(key)} config option is required.`; throw new StyleguidistError(message, key); logger.warn(`${key} config option is deprecated. ${props.deprecated}`); } else if (props.removed) { throw new StyleguidistError(`${kleur.bold(key)} config option was removed. ${props.removed}`); throw Error(`Wrong type ${kleur.bold(type)} specified for ${kleur.bold(key)} in schema.`); `${kleur.bold(key)} config option should be ${typesList(types)}, received ${typeDetect( value )}.\n` + if (shouldBeFile(types) && !fs.existsSync(value)) { throw new StyleguidistError( `A file specified in ${kleur.bold(key)} config option does not exist:\n${value}`, key ); `A directory specified in ${kleur.bold(key)} config option does not exist:\n${value}`, key );
summaryFail(count) { return red(`${bold('✔ FAIL')}: ${count}`); }
summarySkip(count) { return yellow(`${bold('⚠ SKIP')}: ${count}`); }