Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
processCallback: (process) => {
byline(process.stderr).on('data', (chunk) => {
// if (chunk.startsWith('Counting objects: ')) {
// const percent = this.tryParse(chunk)
// if (percent) {
// console.log('total object', percent)
// this.setReceivingProgress(repo, percent)
// }
// return
// }
if (chunk.startsWith('Receiving objects: ')) {
const percent = this.tryParse(chunk);
if (percent) {
// console.log('receiving progress', percent)
this.setReceivingProgress(repo, percent);
}
return;
}
export function spawn (cmd, args, opts) {
const child = chip.spawn(cmd, args, opts);
const stdout = byline(child.stdout);
const stderr = byline(child.stderr);
const lines = [];
let onData = function (data) {
const time = (new Date()).getTime();
lines.push([ time, data.toString() ]); // TODO chalk stdout/stderr?
const { thresholds } = this; // eslint-disable-line no-invalid-this
if (thresholds) {
for (const key in thresholds) {
if (data.indexOf(key) >= 0) {
const p = thresholds[key];
log.showProgress(p);
if (DEBUG_THRESHOLDS) {
lines.push([ time, '************' ]);
lines.push([ time, p + ': ' + key ]);
lines.push([ time, '************' ]);
export function spawn (cmd, args, opts) {
const child = chip.spawn(cmd, args, opts);
const stdout = byline(child.stdout);
const stderr = byline(child.stderr);
const lines = [];
let onData = function (data) {
const time = (new Date()).getTime();
lines.push([ time, data.toString() ]); // TODO chalk stdout/stderr?
const { thresholds } = this; // eslint-disable-line no-invalid-this
if (thresholds) {
for (const key in thresholds) {
if (data.indexOf(key) >= 0) {
const p = thresholds[key];
log.showProgress(p);
if (DEBUG_THRESHOLDS) {
lines.push([ time, '************' ]);
lines.push([ time, p + ': ' + key ]);
lines.push([ time, '************' ]);
}
async function _exec(args: Arguments) {
consoleLog(chalk.magenta(`Executing Shell command:`), chalkConsoleValue(JSON.stringify(args)));
const taskPromise = spawnAsync(...args);
byline(taskPromise.child.stdout).on("data", (chunk) => consoleLog(formatChunk(chunk)));
byline(taskPromise.child.stderr).on("data", (chunk) => consoleError(formatChunk(chunk)));
taskPromise.child.on("uncaughtException", (error) => {
consoleError(`Failed Shell command execution (uncaught exception): ${JSON.stringify(args)}`, error);
process.exit(1);
});
try {
const {status: exitCode} = await taskPromise;
if (exitCode) {
consoleError(`Failed Shell command execution (${exitCode} exit code): ${JSON.stringify(args)}`);
process.exit(exitCode);
}
} catch (error) {
consoleError(`Failed Shell command execution: ${JSON.stringify(args)}`, error.stack);
process.exit(1);
async function _exec(args: Arguments) {
consoleLog(chalk.magenta(`Executing Shell command:`), chalkConsoleValue(JSON.stringify(args)));
const taskPromise = spawnAsync(...args);
byline(taskPromise.child.stdout).on("data", (chunk) => consoleLog(formatChunk(chunk)));
byline(taskPromise.child.stderr).on("data", (chunk) => consoleError(formatChunk(chunk)));
taskPromise.child.on("uncaughtException", (error) => {
consoleError(`Failed Shell command execution (uncaught exception): ${JSON.stringify(args)}`, error);
process.exit(1);
});
try {
const {status: exitCode} = await taskPromise;
if (exitCode) {
consoleError(`Failed Shell command execution (${exitCode} exit code): ${JSON.stringify(args)}`);
process.exit(exitCode);
}
} catch (error) {
consoleError(`Failed Shell command execution: ${JSON.stringify(args)}`, error.stack);
process.exit(1);
}
processCallback: ({stderr}) => {
byline(stderr).on("data", (chunk) => consoleLog(formatChunk(chunk)));
},
...options,
LOG_LEVELS.value(JSON.stringify({command, args, options}, null, 2)),
);
const spawnPromise = spawnAsync(command, args, options);
if (printStd) {
const {stdout, stderr} = spawnPromise.child;
if (stdout) {
byline(stdout).on("data", (chunk) => {
LOG(chalk(formatStreamChunk(chunk)));
});
}
if (stderr) {
byline(stderr).on("data", (chunk) => {
LOG(chalk(formatStreamChunk(chunk)));
});
}
}
try {
return await spawnPromise;
} catch (error) {
const omitProps: Array>> = ["output", "stderr", "stdout"];
omitProps.forEach((omitProp) => delete error[omitProp]);
throw error;
}
}
export async function execShell(
[command, args, options]: Arguments,
{printStd = true}: { printStd?: boolean } = {},
): Promise>> {
LOG(
LOG_LEVELS.title("Executing Shell command:"),
LOG_LEVELS.value(JSON.stringify({command, args, options}, null, 2)),
);
const spawnPromise = spawnAsync(command, args, options);
if (printStd) {
const {stdout, stderr} = spawnPromise.child;
if (stdout) {
byline(stdout).on("data", (chunk) => {
LOG(chalk(formatStreamChunk(chunk)));
});
}
if (stderr) {
byline(stderr).on("data", (chunk) => {
LOG(chalk(formatStreamChunk(chunk)));
});
}
}
try {
return await spawnPromise;
} catch (error) {
const omitProps: Array>> = ["output", "stderr", "stdout"];
omitProps.forEach((omitProp) => delete error[omitProp]);
return new Promise((resolve, reject) => {
const ret = []
const fstream = fs.createReadStream(path, {encoding: 'utf8'})
const lstream = byline(fstream)
let linesRead = 0
lstream.on('readable', () => {
while (linesRead < lcount) {
let line
line = lstream.read()
if (line === null) {
resolve(ret)
return
} else {
ret.push(line)
linesRead++
}
}
fstream.pause()
resolve(ret)
})