本文整理汇总了TypeScript中cross-spawn.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export default async function(name: string): Promise<NpmPackageDetails[]> {
const conf = new Configstore(name);
let commands: NpmPackageDetails[] = conf.get('commands') || [];
if (commands.length) {
const lastUpdated = conf.get('lastUpdated');
if (Date.now() - lastUpdated >= ONE_DAY) {
spawn(process.execPath, [join(__dirname, 'detachedCheckForNewCommands.js'), JSON.stringify({ name })], {
detached: true,
stdio: 'ignore'
}).unref();
}
} else {
commands = await getLatestCommands(name);
}
return commands;
}
示例2: Promise
return new Promise((resolve, reject) => {
let command: string
let args: string[]
if (useYarn) {
command = 'yarnpkg'
args = ['add', '--exact']
Array.prototype.push.apply(args, dependencies)
} else {
command = 'npm'
args = ['install', '--save', '--save-exact'].concat(dependencies)
}
if (verbose) {
args.push('--verbose')
}
const child = spawn(command, args, { stdio: 'inherit' })
child.on('close', (code: number) => {
if (code !== 0) {
reject({
command: `${command} ${args.join(' ')}`,
})
return
}
resolve()
})
})
示例3: Promise
return new Promise((resolve, reject) => {
chdir(join(homedir(), "ledeConfig"));
const installer = spawn("npm", ["install"], { cwd: join(homedir(), "ledeConfig")});
installer.stdout.pipe(process.stdout);
installer.stderr.pipe(process.stderr);
installer.on("exit", resolve);
});
示例4: Promise
return new Promise((resolve, reject) => {
const child = spawn(command, args, options);
if (pipe) {
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
}
child.on("exit", resolve);
child.on("error", reject);
});
示例5: spawn
beforeAll(done => {
const child: ChildProcess = spawn('node', [cliPath, '-y'], {
cwd: targetDir,
stdio: ['ignore', 'ignore', process.stderr]
});
child.on('exit', code => {
if (code === 0) {
done();
} else {
done.fail(new Error(`confc command exit ${code}`));
}
});
}, 5000);
示例6: spawnWrapper
function spawnWrapper(cmd: string, args: string[], opts: any, callback): void {
const stdout = [];
// const stderr = [];
const child = spawn(cmd, args, opts);
child.stdout.on('data', (data) => stdout.push(data));
// child.stderr.on('data', data => stderr.push(data));
child.once('close', (code: number) => {
callback(null, Buffer.concat(stdout).toString());
});
child.once('error', (err: Error) => {
log.error('spawn-error', err.stack);
callback(err);
});
return child;
}
示例7: Promise
return new Promise((resolve, reject) => {
let command: string
let args: string[]
if (useYarn) {
command = 'yarnpkg'
args = ['add', '--exact']
if (!isOnline) {
args.push('--offline')
}
;[].push.apply(args, dependencies)
if (!isOnline) {
console.log(chalk.yellow('You appear to be offline.'))
console.log(chalk.yellow('Falling back to the local Yarn cache.'))
console.log()
}
} else {
checkNpmVersion()
command = 'npm'
args = ['install', '--save', '--save-exact'].concat(dependencies)
}
if (verbose) {
args.push('--verbose')
}
const child = spawn(command, args, { stdio: 'inherit' })
child.on('close', (code: number) => {
if (code !== 0) {
reject({
command: `${command} ${args.join(' ')}`,
})
return
}
resolve()
})
})
示例8: Promise
let promise = new Promise((resolve, reject) => {
let { ignoreStdio, ...nodeOptions } = options;
// @ts-ignore: cross-spawn declares "args" to be a regular array instead of a read-only one
child = spawn(command, args, nodeOptions);
let stdout = '';
let stderr = '';
if (!ignoreStdio) {
if (child.stdout) {
child.stdout.on('data', data => {
stdout += data;
});
}
if (child.stderr) {
child.stderr.on('data', data => {
stderr += data;
});
}
}
let completionListener = (code: number | null, signal: string | null) => {
child.removeListener('error', errorListener);
let result: SpawnResult = {
pid: child.pid,
output: [stdout, stderr],
stdout,
stderr,
status: code,
signal,
};
if (code !== 0) {
let error = signal
? new Error(`${command} exited with signal: ${signal}`)
: new Error(`${command} exited with non-zero code: ${code}`);
if (error.stack && previousStackString) {
error.stack += `\n${previousStackString}`
}
Object.assign(error, result);
reject(error);
} else {
resolve(result);
}
};
let errorListener = (error: Error) => {
if (ignoreStdio) {
child.removeListener('exit', completionListener);
} else {
child.removeListener('close', completionListener);
}
Object.assign(error, {
pid: child.pid,
output: [stdout, stderr],
stdout,
stderr,
status: null,
signal: null,
});
reject(error);
};
if (ignoreStdio) {
child.once('exit', completionListener);
} else {
child.once('close', completionListener);
}
child.once('error', errorListener);
}) as SpawnPromise<SpawnResult>;
示例9: Promise
return new Promise((resolve, reject) => {
const proc = spawn("npm", ["run", script], { cwd: join(homedir(), "ledeConfig")});
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
proc.on("exit", resolve)
});
示例10: Promise
return new Promise((resolve, reject) => {
spawn('npm', ['-s', 'pack'], { stdio: 'inherit', cwd: path })
.on('close', resolve)
.on('error', reject);
});