async function start() { const logger = await Logger('Launcher') logger.info(chalk`======================================== {bold ${center(`Botpress Server`, 40)}} {dim ${center(`Version ${sdk.version}`, 40)}} {dim ${center(`OS ${process.distro.toString()}`, 40)}} ========================================`) global.printErrorDefault = err => { logger.attachError(err).error('Unhandled Rejection') } const modules: sdk.ModuleEntryPoint[] = [] const globalConfig = await Config.getBotpressConfig() const loadingErrors: Error[] = [] let modulesLog = '' const resolver = new ModuleResolver(logger) for (const entry of globalConfig.modules) { try { if (!entry.enabled) { modulesLog += os.EOL + `${chalk.dim('⊝')} ${entry.location} ${chalk.gray('(disabled)')}` continue } const moduleLocation = await resolver.resolve(entry.location) const rawEntry = resolver.requireModule(moduleLocation) const entryPoint = ModuleLoader.processModuleEntryPoint(rawEntry, entry.location) modules.push(entryPoint) process.LOADED_MODULES[entryPoint.definition.name] = moduleLocation modulesLog += os.EOL + `${chalk.greenBright('⦿')} ${entry.location}` } catch (err) { modulesLog += os.EOL + `${chalk.redBright('⊗')} ${entry.location} ${chalk.gray('(error)')}` loadingErrors.push(new FatalError(err, `Fatal error loading module "${entry.location}"`)) } } logger.info(`Using ${chalk.bold(modules.length.toString())} modules` + modulesLog) for (const err of loadingErrors) { logger.attachError(err).error('Error starting Botpress') } if (loadingErrors.length) { process.exit(1) } await Botpress.start({ modules }).catch(err => { logger.attachError(err).error('Error starting Botpress') process.exit(1) }) logger.info(`Botpress is ready at http://${process.HOST}:${process.PORT}/`) }
it('undefined x 2', () => { const cRes = color('%s %s', undefined, undefined) const nRes = nocolor('%s %s', undefined, undefined) assert.equal(cRes, `${gray('undefined')} ${gray('undefined')}`) assert.equal(nRes, 'undefined undefined') })
function ilog(ctx: any, start: any, len: any, err: any, event: any = null) { const status = err ? (err.status || 500) : (ctx.status || 404); let length: any; if (~[204, 205, 304].indexOf(status)) { length = ''; } else if (null == len) { length = '-'; } else { length = bytes(len); } const upstream = err ? chalk.red('xxx') : event === 'close' ? chalk.yellow('-x-') : chalk.gray('-->'); if (err) { ctx.logger.error( upstream, chalk.bold(ctx.method), chalk.gray(ctx.originalUrl), status, time(start), length ); } else { ctx.logger.info( upstream, chalk.bold(ctx.method), chalk.gray(ctx.originalUrl), status, time(start), length ); } }
public persistLog(logLevel: LogLevel, messages: any[]): this { messages = this.formatMessages(logLevel, messages); if (this.sourceName) { messages.unshift(gray('[' + this.format(logLevel, this.sourceName) + ']')); } messages.unshift( gray('[' + this.format(logLevel, moment().format('HH:mm:ss')) + '] ')); switch (logLevel) { case 'emergency': case 'alert': case 'critical': case 'error': console.error(messages.shift(), ...messages); break; case 'warning': case 'notice': console.warn(messages.shift(), ...messages); break; default: console.log(messages.shift(), ...messages); } return this; };
it('array x 8', () => { const cRes = color('%s', [ , undefined, null, [], {}, '', { '': undefined }, { '': null } ]) const nRes = nocolor('%s', [ , undefined, null, [], {}, '', { '': undefined }, { '': null } ]) const _ = semver.gte(process.version, 'v0.11.0') ? '' : '\n ' const cExp = `[ ` + `,${_} ${gray('undefined')}` + `,${_} ${bold(null)}` + `,${_} []` + `,${_} {}` + `,${_} ${green(`''`)}` + `,${_} { ${green(`''`)}: ${gray('undefined')} }` + `,${_} { ${green(`''`)}: ${bold('null')} }` + ` ]` const nExp = `[ ` + `,${_} undefined` + `,${_} null` + `,${_} []` + `,${_} {}` + `,${_} ''` + `,${_} { '': undefined }` + `,${_} { '': null }` + ` ]` assert.equal(cRes, cExp) assert.equal(nRes, nExp) })
export const usageRoot = (showQuickstart: boolean) => ` Serverless GraphQL backend for frontend developers (${chalk.underline('https://www.graph.cool')}) ${chalk.dim('Usage:')} ${chalk.bold('graphcool')} [command] ${chalk.dim('Commands:')}${showQuickstart ? ` quickstart Open Graphcool Quickstart examples`: ''} init Create a new project push Push project file changes pull Download the latest project file export Export project data endpoints Print GraphQL endpoints console Open Graphcool Console playground Open GraphQL Playground projects List projects delete Delete existing projects auth Sign up or login version Print version Run 'graphcool COMMAND --help' for more information on a command. ${chalk.dim('Examples:')} ${chalk.gray('-')} Initialize a new Graphcool project ${chalk.cyan('$ graphcool init')} ${chalk.gray('-')} Local setup of an existing project ${chalk.cyan('$ graphcool pull -p <project-id | alias>')} ${chalk.gray('-')} Update live project with local changes ${chalk.cyan('$ graphcool push')} `
.map(([optionName, option]) => [ [optionName, ...(option.aliases || [])] .map(dasherizeOption) .map(x => chalk.bold.blue(x)) .join(chalk.gray(', ')), option.description, chalk.gray(`[${chalk.underline(option.type)}]`), ])
this.project.documents.entries.forEach((document: Document) => { console.log( ' ', chalk.gray('Format:'), chalk.white.bold(document.format) ) console.log(' ', chalk.gray('Path:'), chalk.white.bold(document.path)) console.log('') })
this.ruleFailures.forEach((failure: RuleFailure) => { // Error positions are zero-based from tslint, and must be incremented by 1 failures.push([ " ", chalk.gray("line " + (failure.getStartPosition().line + 1)), chalk.gray("col " + (failure.getStartPosition().character + 1)), chalk.red(failure.getFailure()) ]); });
async function gitTags() { const { version } = JSON.parse(readFileSync(DIST_PACKAGE_PATH, 'utf8')); console.log(chalk.green(`Tagging with ${version}`)); const { stdout: tag } = await exec(`git tag v${version}`); const { stdout: push } = await exec(`git push --tags`); if (tag) { console.log(chalk.gray(tag)); } if (push) { console.log(chalk.gray(push)); } }