const task = message => { progress = animateProgress(message); process.stdout.write(message); return error => { if (error) { process.stderr.write(error); } clearTimeout(progress); return addCheckmark(() => newLine()); }; }
function echoServer (type, cb) { if (typeof type === 'function') return echoServer('http', type) var script = path.join(__dirname, '_echo_server.js') var cp = exec(`node "${script}" ${type}`) cp.stderr.pipe(process.stderr) cp.stdout.once('data', function (chunk) { var port = chunk.trim().split('\n')[0] cb(cp, port) }) }
function execute(command) { // eslint-disable-next-line no-console console.log(`npm-scripts.js [INFO] executing command: ${command}`); try { execSync(command, { stdio: [ 'ignore', process.stdout, process.stderr ] }); } catch (error) { process.exit(1); } }
const isStdWritable = stream => stream === process.stdout || stream === process.stderr
const extractFromFile = async filename => { try { const code = await readFile(filename); const output = await transform(code, { filename, presets, plugins }); const messages = get(output, 'metadata.react-intl.messages', []); for (const message of messages) { for (const locale of appLocales) { const oldLocaleMapping = oldLocaleMappings[locale][message.id]; // Merge old translations into the babel extracted instances where react-intl is used const newMsg = locale === DEFAULT_LOCALE ? message.defaultMessage : ''; localeMappings[locale][message.id] = oldLocaleMapping || newMsg; } } } catch (error) { process.stderr.write(`\nError transforming file: ${filename}\n${error}\n`); } }
exec(command: string, quiet: boolean, options?: any) { return new Promise((resolve, reject) => { try { const child = childProcess.exec( command, Object.assign({ encoding: 'utf8', wraning: false, maxBuffer: Infinity }, options), (error, stdout, stderr) => { if (error) { console.warn( 'Command run error, please check if there has the same issue here: https://github.com/weexteam/weex-toolkit/issues/337', ) reject(error) } else { resolve() } }, ) if (!quiet) { child.stdout.pipe(process.stdout) } child.stderr.pipe(process.stderr) } catch (e) { console.error('execute command failed :', command) reject(e) } }) }
/** * Log an animated "loading" message * @param {String|Number} name - The name of the draft-log, this is needed to retrieve it later * @param {string} text - The text to be logged * @returns {Promise<void | string>} TODO */ async draft(name, text) { //If the terminal cannot handle draft logs, make a simple log if (!process.stderr.isTTY) { return this.info(text); } this.drafts.set(name, { spinning: true, text, // @ts-ignore draft: console.draft(this.info(`${frames[0]} ${text}`, true)) }); for (let i = 0; this.drafts.get(name).spinning; i++) { await sleep(50); this.drafts.get(name).draft(this.info(`${frames[i % frames.length]} ${text}`, true)); } }
async function main() { const child = childProcess.exec('npm run test') child.stdout.on('data', (data) => { process.stdout.write(data) }) child.stderr.on('data', (data) => { process.stderr.write(data) }) child.on('exit', () => { process.exit() }) setTimeout(() => { child.kill() process.exit() }, kCiTestTimeout) }
spawn( command: string, args: string[], cwd: string, wait: number = 30 * 1000 ) { return new Promise((resolve, reject) => { const child = spawn(command, args, { cwd, detached: true }); const timeout = setTimeout(() => { const message = `${command} ${args.toString()} exited with timeout after ${ wait / 1000 } seconds`; child.kill(message as never); reject(message); clearTimeout(timeout); }, wait); child.stdout.on('data', (data) => process.stdout.write(data)); child.stderr.on('data', (data) => process.stderr.write(data)); child.on('close', (code) => { clearTimeout(timeout); if (!code) { resolve(code); } else { reject(code); } }); }); }
const executeCommand = ( command: string, args: string[] = [], options?: SpawnOptionsWithoutStdio ) => { return new Promise<ProcessReturn>((resolve, reject) => { const child = spawn(command, args, options); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); let data = ''; let error = ''; child.stderr.on('data', (out) => (error += out)); child.stdout.on('data', (out) => { data += out.toString(); }); child.on('close', (code: number) => { if (code !== 0) { reject({ data, code, error } as ProcessReturn); } else { resolve({ data, code } as ProcessReturn); } }); }); }
const executeCommand = ( command: string, args: string[] = [], options?: SpawnOptionsWithoutStdio ) => { return new Promise<ProcessReturn>((resolve, reject) => { const child = spawn(command, args, options); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); let data = ''; let error = ''; child.stderr.on('data', (out) => (error += out)); child.stdout.on('data', (out) => { data += out.toString(); }); child.on('close', (code: number) => { if (code !== 0) { reject({ data, code, error } as ProcessReturn); } else { resolve({ data, code } as ProcessReturn); } }); }); }
spawn( command: string, args: string[], cwd: string, wait: number = 30 * 1000 ) { return new Promise((resolve, reject) => { const child = spawn(command, args, { cwd, detached: true }); const timeout = setTimeout(() => { const message = `${command} ${args.toString()} exited with timeout after ${ wait / 1000 } seconds`; child.kill(message as never); reject(message); clearTimeout(timeout); }, wait); child.stdout.on('data', (data) => process.stdout.write(data)); child.stderr.on('data', (data) => process.stderr.write(data)); child.on('close', (code) => { clearTimeout(timeout); if (!code) { resolve(code); } else { reject(code); } }); }); }