Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.childOutpipe.stdout.pipe(stdout, { end: false })
this.childOutpipe.stderr.pipe(stderr, { end: false })
this.childOutpipe.on('exit', (code, signal) => {
this.log(`outpipe ${exitmsg(code, signal)}`)
this.childOutpipe = undefined
if (!this.childCommand) return onexit()
})
}
if (this.command) {
// Generate argument strings from templates.
const cmd = this.args.map(tmpl => tmpl(this.options))
this.log(`executing command "${[this.command].concat(cmd).join(' ')}"`)
this.childCommand = spawn(this.command, cmd, { cwd, env })
this.childCommand.stderr.pipe(stderr, { end: false })
// If `outpipe`, pipe `stdout` into `outpipe` command.
if (this.childOutpipe) {
this.childCommand.stdout.pipe(this.childOutpipe.stdin)
} else {
this.childCommand.stdout.pipe(stdout, { end: false })
}
this.childCommand.on('exit', (code, signal) => {
this.log(`command ${exitmsg(code, signal)}`)
this.childCommand = undefined
if (!this.childOutpipe) return onexit()
})
} else {
// No data to write to `outpipe`.
return new Promise((resolve, reject) => {
// Run npm install
const npm = spawn('npm', ['install', '--loglevel=error'], {
cwd: dirPath,
stdio: 'inherit',
});
npm.on('close', (code) => {
if (code !== 0) {
return reject(new Error('npm install failed with status code: ' + code));
}
return resolve(dirPath);
});
});
}
function crossEnv(args, options = {}) {
const [envSetters, command, commandArgs] = parseCommand(args)
const env = getEnvVars(envSetters)
if (command) {
const proc = spawn(
// run `path.normalize` for command(on windows)
commandConvert(command, env, true),
// by default normalize is `false`, so not run for cmd args
commandArgs.map(arg => commandConvert(arg, env)),
{
stdio: 'inherit',
shell: options.shell,
env,
},
)
process.on('SIGTERM', () => proc.kill('SIGTERM'))
process.on('SIGINT', () => proc.kill('SIGINT'))
process.on('SIGBREAK', () => proc.kill('SIGBREAK'))
process.on('SIGHUP', () => proc.kill('SIGHUP'))
proc.on('exit', (code, signal) => {
let crossEnvExitCode = code
.concat(optUtils.phantomPage)
.concat(optUtils.phantomCallback));
filteredOptions.site = site;
filteredOptions.path = path;
filteredOptions.streaming = streaming;
var phantomArgs = [phantomScript, JSON.stringify(filteredOptions)];
if (options.phantomConfig) {
phantomArgs = Object.keys(options.phantomConfig).map(function (key) {
return '--' + key + '=' + options.phantomConfig[key];
}).concat(phantomArgs);
}
var phantomProc = crossSpawn.spawn(options.phantomPath, phantomArgs);
// This variable will contain our timeout ID.
var timeoutID = null;
// Whether or not we've called our callback already.
var calledCallback = false;
// Only set the timer if the timeout has been specified (by default it's not)
if (options.timeout) {
timeoutID = setTimeout(function() {
// The phantomjs process didn't exit in time.
// Double-check we didn't already call the callback already as that would
// happen when the process has already exited. Sending a SIGKILL to a PID
// that might be handed out to another process could be potentially very
// dangerous.
export default async function init({ flow }) {
const spinner = ora('Setting up your new ExpressX project...').start();
await fs.copy(join(__dirname, '../../src/init/template'), join(cwd, '.'));
await fs.ensureDir(join(cwd, 'views/partials'));
spinner.text = 'Installing dependencies...';
const proc = spawn('npm', ['install']);
proc.on('exit', async (code) => {
if (code === 0) {
if (flow) {
try {
await installFlow();
} catch (e) {
spinner.fail('There was an error installing dependencies.');
}
}
spinner.stop();
console.log();
console.log(ls.success, chalk.green('Woohoo! Everything is good to go!'));
console.log('To start your app, just run:');
console.log();
return new Promise(resolve => {
const proc = spawn(command, args, options);
const transform = new ReadlineTransform({ skipEmpty: true });
proc.stdout.setEncoding('utf8');
proc.stdout
.pipe(transform)
.pipe(JSONStream.parse())
.pipe(
eventStream.mapSync(data => {
if (!data) return;
try {
stdoutListener(data);
} catch (error) {
stderrListener(error);
}
})
);
return new Promise((resolve, reject) => {
const [command, args] = cliCommand
const child = spawn(command, args)
child.on('error', error => {
reject(error)
})
child.stdout.on('data', cliMessage => {
if (!cliMessage) {
return
}
const cliVersion = findCLIVersionInMessage(cliMessage.toString())
if (cliVersion) {
resolve(cliVersion)
} else {
reject(cliMessage)
const spawnRenderer = (entryPointPath: string, args: string) => {
const child: Object = spawn(
'node',
[entryPointPath].concat(args),
{ stdio: ['inherit', 'pipe', 'inherit', 'ipc'] },
);
child.on('error', (error) => {
throw new Error(error);
});
child.on('exit', (code) => {
if (code && code !== 0) {
throw new Error(`Renderer process exited with code ${code}`);
}
});
return child;
};
const spawnServer = (
{ logger }: CLIContext,
entryPointPath: string,
args: string[],
): Object => {
const child: Object = spawn('node', [entryPointPath].concat(args), {
stdio: ['ipc', 'inherit', 'inherit'],
});
logMessage(logger, child);
return child;
};
return new Promise((resolve, reject) => {
const child = crossspawn.spawn(this.cmd, this.args, {
cwd: this.cwd,
stdio: [
"ignore",
fs.openSync(stdoutFile, "a"),
fs.openSync(stderrFile, "a")
]
});
child.on("error", (abortError: any) => {
reject(captureOutput(abortError, null));
});
child.on("close", (statusCode: number) => {
if (statusCode === 0) {
resolve(captureOutput(null, statusCode));
} else {
reject(captureOutput(null, statusCode));
}