.action(function () { if (commander.args.length === 1) { console.log("Target details not specified"); console.log(commander.helpInformation()); exit(ERROR_VALUE); } name = commander.args[0]; ip = commander.args[1]; type = commander.type ? commander.type : "device"; if (commander.password && typeof commander.password === 'string') { password = commander.password; } if (commander.pin && typeof commander.pin === 'string') { pin = commander.pin; } if (!isValidIp(ip)) { console.log("Invalid IP: " + ip); console.log(commander.helpInformation()); exit(ERROR_VALUE); } if (!isValidType(type)) { console.log("Invalid target type: " + type); console.log(commander.helpInformation()); exit(ERROR_VALUE); } if (!isValidPin(pin)) { console.log("Invalid PIN: " + pin); console.log(commander.helpInformation()); exit(ERROR_VALUE); } if (properties.targets.hasOwnProperty(name)) { console.log("Overwriting target: " + name); } properties.targets[name] = {"ip": ip, "type": type, "password": password, "pin": pin}; });
// ////////////////////////////////////////////////////////////////////////// function buildAndStart () { if (/^https?:\/\//.test(Program.file)) { const url = Program.file.replace(/^(https?:\/\/)([^/:]+)(?=:\d+|\/)/, function (m, a, b) { if (!/\d+\.\d+\.\d+\.\d+/.test(a)) { return a + Hosts.findRealHost(b); } else { return m; } }); Config.entryBundleUrl = url; startServerAndLaunchDevtool(); } else { const filePath = Path.resolve(Program.file); const ext = Path.extname(filePath); if (!Fs.existsSync(filePath)) { console.error(filePath + ': No such file or directory'); return Exit(0); } if (ext === '.we' || ext === '.vue') { buildFileAndWatchIt(Program.mode, filePath).then(function () { startServerAndLaunchDevtool(Program.file); }, function (err) { if (err) { console.log(err, err.stack); } Exit(0); }); } else if (ext === '.js') { buildFileAndWatchIt('copy', filePath).then(function () { startServerAndLaunchDevtool(Program.file); }); } else if (!ext) { // 处理目录 if (Fs.statSync(filePath).isDirectory()) { Config.root = filePath; buildFileAndWatchIt(Program.mode, filePath).then(function () { startServerAndLaunchDevtool(Program.entry); }, function (err) { if (err) { console.log(err, err.stack); } Exit(0); }); } else { console.error(Program.file + ' is not a directory!'); Exit(0); } } else { console.error('Error:unsupported file type: ', ext); return Exit(0); } } }
needle.get(url, {}, function(err, resp, data) { // request error if (err) { console.log(err.toString()); exit(1); } // Mixpanel API error if (data.error) { console.log('Mixpanel API error: ' + data.error); exit(1); } // return total count if (argv.total) { console.log(data.total); exit(0); } // note: properties page_size and total are only returned if no page parameter // is set in the request (not even page=0). Hence they are only available // in the first response. if (data.page == 0) { // remember total results and page_size total = data.total; page_size = data.page_size; // use session id from now on to speed up API response params.session_id = data.session_id; // beginning of json array if (argv.format == 'json' && !argv.noarray) { console.log('['); } } total -= data.results.length; var isLastQuery = total < 1; processResults(data, isLastQuery); // if not done, keep querying for additional pages if (!isLastQuery) { // get next page params.page = data.page + 1; doQuery(params); } else { // end of json array if (argv.format == 'json' && !argv.noarray) { console.log(']'); } exit(0); } });
exit_handler: function (err) { if (err) { if (typeof err === "string") { console.error(err); } else { console.error("An error has occurred"); } exit(ERROR_VALUE); } else { exit(0); } }
.action(function () { if (commander.args.length === 1) { console.log('No target specified'); console.log(commander.helpInformation()); exit(ERROR_VALUE); } targetName = commander.args[0]; if (!properties.targets.hasOwnProperty(targetName)) { console.log("Target: '" + targetName + "' not found"); console.log(commander.helpInformation()); exit(ERROR_VALUE); } delete properties.targets[targetName]; });
chimp.init(function (err) { if (err) { log.error(err); log.debug('Error in chimp init', err); } exit(err ? 2 : 0); });
require("read-file-stdin")(input, function(err, buffer) { if (err) { throw err } try { var css = cssnext(buffer.toString(), config) require("write-file-stdout")(output, css) if (verbose && output) { log(color.cyan("Output written"), output) } } catch (e) { console.error() console.error(color.bold("cssnext encounters an error:")) console.error() console.error(color.red(e.message)) if (e.stack) { console.error(e.stack.split("\n").slice(1).join("\n").grey) console.error() } console.error("If this error looks like a bug, please report it here:") console.error(color.grey("❯ ") + color.cyan(pkg.bugs.url)) console.error() if (!config.watch) { exit(2) } } })
function exitAndLog(code) { let end = new Date().getTime(); let time = end - start; code = code || 0; console.log('\nTool executed in'.gray, `${time / 1000}`.cyan, 'seconds | Exit code:'.gray, !code ? '0'.green : `${code}`.red); return exit(code); }
Expose.prototype.exit = function (code) { if (code !== 0) { this.reporter.output.ln().error('Closing with exit code ' + code).clear(); exitProcess(code); } else { } };
function fatal(e, errcode) { var msg = ('Fatal: ' + (e.message || e)).red; console.log(msg); exit(errcode || 1); }
(function () { var args = process.argv; if (args.length < 3 || (args[2] === '--help' || args[2] === '-h')) { console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' <path_to_project>'); exit(1); } else { exports.updateProject(args[2]); } })();
cursor.toArray(function (err, result) { if (err) exit(3); writeToFile(path.join(cacheDir, fileName), result); cursor.close(); conn.close(); var duration = moment.duration(Date.now() - startTime); logger.info('Done. ', sensorName, timeFrame, fileName, 'Duration:', duration.humanize()); });
function die(why) { 'use strict'; var o = commandOptions(); con.warn(why); con.warn("Usage: " + pro.argv[1] + " [--" + Object.keys(o).sort().join("] [--") + "] [--] <scriptfile>..."); exit(1); }
cmdModule(dat, argv, function(err) { if (err) { if (cmd === 'init') { console.error(err.message) exit(0) } return onerror(err) } setImmediate(close) })
const onError = async (err, test) => { await onFailure(test, err); if (err.type === 'ProcessTerminatedError') { console.error( 'A worker process has quit unexpectedly! ' + 'Most likely this is an initialization error.', ); exit(1); } };
syncher.run(function () { db.drain(); for (var key = 0 ; key < arguments.length ; ++key) { var err = arguments[key][0]; if (err) { console.error(err); exit(1); } } });
export const runCLI = async ( argv: Argv, projects: Array<Path>, ): Promise<{results: AggregatedResult, globalConfig: GlobalConfig}> => { const realFs = require('fs'); const fs = require('graceful-fs'); fs.gracefulify(realFs); let results; // If we output a JSON object, we can't write anything to stdout, since // it'll break the JSON structure and it won't be valid. const outputStream = argv.json || argv.useStderr ? process.stderr : process.stdout; argv.version && printVersionAndExit(outputStream); const {globalConfig, configs, hasDeprecationWarnings} = getConfigs( projects, argv, outputStream, ); if (argv.clearCache) { configs.forEach(config => { rimraf.sync(config.cacheDirectory); process.stdout.write(`Cleared ${config.cacheDirectory}\n`); }); exit(0); } await _run( globalConfig, configs, hasDeprecationWarnings, outputStream, (r: AggregatedResult) => (results = r), ); if (argv.watch || argv.watchAll) { // If in watch mode, return the promise that will never resolve. // If the watch mode is interrupted, watch should handle the process // shutdown. return new Promise(() => {}); } if (!results) { throw new Error( 'AggregatedResult must be present after test run is complete', ); } return Promise.resolve({globalConfig, results}); };
push: function(flags) { var source = flags.from; var target = flags.to; // Check flags if (!source || !target) { throw new Error('flags `from` and `to` required'); } // Get configurations var config = exports.getConfig(); // Check environments if (!config.environments[source]) { cli.error('Source environment \''+source+'\' does not exist'); exit(1); } else if (!config.environments[target]) { cli.error('Target environment \''+target+'\' does not exist'); exit(1); } var options = config.options; var source_options = config.environments[source]; var target_options = config.environments[target]; // Generate backup directories and paths var source_backup_paths = util.generate_backup_paths(source, options); var target_backup_paths = util.generate_backup_paths(target, options); // Dump source DB util.db_dump(source_options, source_backup_paths); // Search and Replace database refs util.db_adapt(source_options.url, target_options.url, source_backup_paths.file); // Dump target DB util.db_dump(target_options, target_backup_paths); // Import dump to target DB util.db_import(target_options, source_backup_paths.file); }
const readResultsAndExit = ( result: ?AggregatedResult, globalConfig: GlobalConfig, ) => { const code = !result || result.success ? 0 : globalConfig.testFailureExitCode; process.on('exit', () => (process.exitCode = code)); if (globalConfig.forceExit) { exit(code); } };
syncher.run(function (keyArgs, certArgs) { var err = keyArgs[0] || certArgs[0]; if (err) { console.error(err); return exit(1); } this.server = https.createServer({ key: keyArgs[1], cert: certArgs[1] }, listener.bind(this)); this.dispatch({type: 'create'}); }.bind(this));
(err, _, metadata) => { if (err || !metadata) { return; } if (metadata.activationValue === quitAnswer) { exit(0); return; } if (metadata.activationValue === restartAnswer) { this._startRun(this._globalConfig); } },
process.on('uncaughtException', function (err) { if (err.stack) { err.stack.split("\n").forEach(function (line) { logger.logcrit(line); }); } else { logger.logcrit('Caught exception: ' + JSON.stringify(err)); } logger.dump_logs(); exit(1); });
function complete(program, args){ if (!args.length) { if (process.platform === 'win32') { console.error('Command completion not supported on Windows'); exit(2); } console.log(fs.readFileSync(__dirname + '/completion.sh', 'utf8')); exit(); } if (!program) { console.error('Program for completion is not set'); exit(2); } console.log((program.parse(args.slice(1), true) || []).join('\n')); exit(); };
.action(function () { if (commander.args.length === 1) { console.log("Target details not specified"); console.log(commander.helpInformation()); exit(ERROR_VALUE); } targetName = commander.args[0]; ip = commander.args[1]; type = commander.type ? commander.type : "device"; if (type === "simulator") { type = "emulator"; } if (commander.password && typeof commander.password === 'string') { password = commander.password; } if (commander.pin && typeof commander.pin === 'string') { pin = commander.pin; } if (!isValidType(type)) { console.log("Invalid target type: " + type); console.log(commander.helpInformation()); exit(ERROR_VALUE); } if (typeof ip !== 'string') { console.log("host is required"); console.log(commander.helpInformation()); exit(ERROR_VALUE); } if (!isValidPin(pin)) { console.log("Invalid PIN: " + pin); console.log(commander.helpInformation()); exit(ERROR_VALUE); } if (properties.targets.hasOwnProperty(targetName)) { console.log("Overwriting target: " + targetName); } targetName = targetName.replace(/ /g, "-"); properties.targets[targetName] = {"ip": ip, "type": type, "password": password, "pin": pin}; });
function isValidType(type) { var result = true; if (typeof type !== 'string') { console.log("target type is required"); console.log(commander.helpInformation()); exit(ERROR_VALUE); } else if (!(type === 'device' || type === 'emulator')) { result = false; } return result; }
const printDebugInfoAndExitIfNeeded = ( argv, globalConfig, configs, outputStream, ) => { if (argv.debug || argv.showConfig) { logDebugMessages(globalConfig, configs, outputStream); } if (argv.showConfig) { exit(0); } };
.then(files => { const errors = [] files.forEach(function processFile(file) { const content = fs.readFileSync(file) const result = amdextract.parse(content) const error = {} result.results.forEach(function (r) { const unusedPaths = r.unusedPaths.filter((path) => { return !excludedPaths.includes(path) }) totalUnusedPaths += unusedPaths.length if (unusedPaths.length > 0) { totalFilesWithUnusedPaths++ error.unusedPaths = unusedPaths } totalUnusedDependencies += r.unusedDependencies.length if (r.unusedDependencies.length > 0) { totalFilesWithUnusedDependencies++ error.unusedDependencies = r.unusedDependencies } if (error.unusedDependencies || error.unusedPaths) { error.file = file errors.push(error) } totalProcessedFiles++ }); }); !statsOnly && displayErrors(errors) console.log(` Total unused paths: ${totalUnusedPaths} in ${totalFilesWithUnusedPaths} file${totalFilesWithUnusedPaths > 1 ? 's' : ''}. Total unused dependencies: ${totalUnusedDependencies} in ${totalFilesWithUnusedDependencies} file${totalFilesWithUnusedDependencies > 1 ? 's' : ''}. Total processed files: ${totalProcessedFiles} `) if (totalFilesWithUnusedPaths || totalFilesWithUnusedDependencies) { exit(1) } })
export async function run(maybeArgv?: Argv, project?: Path) { try { const argv: Argv = buildArgv(maybeArgv, project); const projects = getProjectListFromCLIArgs(argv, project); const {results, globalConfig} = await runCLI(argv, projects); readResultsAndExit(results, globalConfig); } catch (error) { clearLine(process.stderr); clearLine(process.stdout); console.error(chalk.red(error.stack)); exit(1); throw error; } }
const printDebugInfoAndExitIfNeeded = ( argv, globalConfig, configs, outputStream, ) => { if (argv.debug) { logDebugMessages(globalConfig, configs, outputStream); return; } if (argv.showConfig) { logDebugMessages(globalConfig, configs, process.stdout); exit(0); } };
loadConfig: function(file) { if (!file) { return; } if (!shelljs.test("-e", file)) { cli.error("Cannot find config file: " + file); exports.exit(1); } try { var config = JSON.parse(stripJsonComments(shelljs.cat(file))); return config; } catch (err) { cli.error('Cannot parse config file: ' + file + '\nError:' + err); exit(1); } },