本文整理汇总了TypeScript中child_process.spawnSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript spawnSync函数的具体用法?TypeScript spawnSync怎么用?TypeScript spawnSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spawnSync函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: findYarnVersion
findYarnVersion(path => {
let result = spawnSync(
'node',
[path, '--cwd', 'app', 'install', '--force'],
options
)
if (result.status !== 0) {
process.exit(result.status)
}
result = spawnSync(
'git',
['submodule', 'update', '--recursive', '--init'],
options
)
if (result.status !== 0) {
process.exit(result.status)
}
result = spawnSync('node', [path, 'compile:tslint'], options)
if (result.status !== 0) {
process.exit(result.status)
}
result = spawnSync('node', [path, 'compile:script'], options)
if (result.status !== 0) {
process.exit(result.status)
}
})
示例2: detect
export function detect(): DartSdkExecutableMap {
let sdk: DartSdkExecutableMap;
try {
const dartExecutable = which.sync('dart');
if (process.platform === 'win32') {
sdk = {
ANALYZER: 'dartanalyzer.bat',
DARTDOCGEN: 'dartdoc.bat',
DARTFMT: 'dartfmt.bat',
PUB: 'pub.bat',
VM: 'dart.exe'
};
} else {
sdk = {
ANALYZER: 'dartanalyzer',
DARTDOCGEN: 'dartdoc',
DARTFMT: 'dartfmt',
PUB: 'pub',
VM: 'dart'
};
}
console.log('Dart SDK detected:', dartExecutable);
console.log('- dart: ' + child_process.spawnSync(sdk.VM, ['--version']).stderr.toString().replace(/\n/g, ''));
console.log('- pub: ' + child_process.spawnSync(sdk.PUB, ['--version']).stdout.toString().replace(/\n/g, ''));
return sdk;
} catch (e) {
console.log('Dart SDK is not available.');
return null;
}
}
示例3: getCurrentGitUser
/** Returns the name and email of the Git user that creates this release build. */
function getCurrentGitUser() {
const userName = spawnSync('git', ['config', 'user.name'], {cwd: buildConfig.projectDir})
.stdout.toString().trim();
const userEmail = spawnSync('git', ['config', 'user.email'], {cwd: buildConfig.projectDir})
.stdout.toString().trim();
return `${userName} <${userEmail}>`;
}
示例4: it
it('should be able to use the d.ts', async () => {
console.log(`${__filename} staging area: ${stagingPath}`);
cp.spawnSync('npm', ['pack'], spawnOpts);
const tarball = `${pkg.name}-${pkg.version}.tgz`;
await (mvp as Function)(tarball, `${stagingPath}/googleapis.tgz`);
await ncpp('test/fixtures/kitchen', `${stagingPath}/`);
cp.spawnSync(
'npm',
['install'],
Object.assign({cwd: `${stagingPath}/`}, spawnOpts)
);
}).timeout(80000);
示例5: setup
async function setup(): Promise<void> {
console.log('*** Test data:', testDataPath);
console.log('*** Preparing smoketest setup...');
const keybindingsUrl = `https://raw.githubusercontent.com/Microsoft/vscode-docs/master/scripts/keybindings/doc.keybindings.${getKeybindingPlatform()}.json`;
console.log('*** Fetching keybindings...');
await new Promise((c, e) => {
https.get(keybindingsUrl, res => {
const output = fs.createWriteStream(keybindingsPath);
res.on('error', e);
output.on('error', e);
output.on('close', c);
res.pipe(output);
}).on('error', e);
});
if (!fs.existsSync(workspacePath)) {
console.log('*** Creating workspace file...');
const workspace = {
folders: [
{
path: toUri(path.join(testRepoLocalDir, 'public'))
},
{
path: toUri(path.join(testRepoLocalDir, 'routes'))
},
{
path: toUri(path.join(testRepoLocalDir, 'views'))
}
]
};
fs.writeFileSync(workspacePath, JSON.stringify(workspace, null, '\t'));
}
if (!fs.existsSync(testRepoLocalDir)) {
console.log('*** Cloning test project repository...');
cp.spawnSync('git', ['clone', testRepoUrl, testRepoLocalDir]);
} else {
console.log('*** Cleaning test project repository...');
cp.spawnSync('git', ['fetch'], { cwd: testRepoLocalDir });
cp.spawnSync('git', ['reset', '--hard', 'FETCH_HEAD'], { cwd: testRepoLocalDir });
cp.spawnSync('git', ['clean', '-xdf'], { cwd: testRepoLocalDir });
}
console.log('*** Running npm install...');
cp.execSync('npm install', { cwd: testRepoLocalDir, stdio: 'inherit' });
console.log('*** Smoketest setup done!\n');
}
示例6: checkInstallation
export function checkInstallation(executable: Executable, projectDir: string) {
const child = spawnSync(executable, ['version'], {
cwd: projectDir,
shell: false,
});
return child.status === 0;
}
示例7: spawnSync
export function spawnSync(tool: string,
args: string[],
toolchain: Toolchain = 'default',
options?: child_process.SpawnOptions)
{
return child_process.spawnSync(tool, toolchainPrefix(toolchain).concat(args), options);
}
示例8: validateWorkspace
function validateWorkspace(): void {
try {
let spawn = require("child_process").spawnSync;
let rubocop = spawn(rubocopPath, ["-f", "j", vscode.workspace.rootPath], { cwd: vscode.workspace.rootPath });
let rubocopOutput = JSON.parse(rubocop.stdout);
let arr = [];
for (var r = 0; r < rubocopOutput.files.length; r++) {
var rubocopFile = rubocopOutput.files[r];
let uri: vscode.Uri = vscode.Uri.file((path.join(vscode.workspace.rootPath, rubocopFile.path)));
var offenses = rubocopFile.offenses;
let diagnostics: vscode.Diagnostic[] = [];
for (var i = 0; i < offenses.length; i++) {
let _line = parseInt(offenses[i].location.line) - 1;
let _start = parseInt(offenses[i].location.column) - 1;
let _end = parseInt(_start + offenses[i].location.length);
let diagRange = new vscode.Range(_line, _start, _line, _end);
let diagMsg = `${offenses[i].message} (${offenses[i].cop_name})`;
let diagSeverity = convertSeverity(offenses[i].severity);
let diagnostic = new vscode.Diagnostic(diagRange, diagMsg, diagSeverity);
diagnostics.push(diagnostic);
}
arr.push([uri, diagnostics]);
}
diagnosticCollection.clear();
diagnosticCollection.set(arr);
}
catch(err) {
console.log(err);
}
return;
}
示例9: shellSpawnSync
export default function shellSpawnSync(args) {
if (args === 'shell') {
args = [platform() === 'win32' ? 'cmd.exe' : 'bash'];
}
if (prettyPrint) {
console.log('::: %s', args.join(' '));
}
const child = spawnSync(args[0], args.slice(1), {
stdio: 'inherit',
cwd: process.cwd(),
env: process.env,
});
if (child) {
if (child.error) {
console.error(`can't run command "${args[0]}"\n %s`, child.error.message);
return child.status || 127;
} else {
return child.status;
}
} else {
console.error(`can't run command "${args[0]}"`);
return 127;
}
};
示例10: checkPublishBranch
export function checkPublishBranch(version: string) {
const versionType = getSemverVersionType(version);
const branchName = spawnSync('git', ['symbolic-ref', '--short', 'HEAD'],
{cwd: buildConfig.projectDir}).stdout.toString().trim();
if (branchName === 'master') {
if (versionType === 'major') {
return;
}
throw `Publishing of "${versionType}" releases should not happen inside of the ` +
`${bold('master')} branch.`;
}
const branchNameMatch = branchName.match(publishBranchNameRegex) || [];
const branchDigits = branchNameMatch.slice(1, 4);
if (branchDigits[2] === 'x' && versionType !== 'patch') {
throw `Cannot publish a "${versionType}" release inside of a patch branch (${branchName})`;
}
if (branchDigits[1] === 'x' && versionType !== 'minor') {
throw `Cannot publish a "${versionType}" release inside of a minor branch (${branchName})`;
}
throw `Cannot publish a "${versionType}" release from branch: "${branchName}". Releases should `
+ `be published from "master" or the according publish branch (e.g. "6.x", "6.4.x")`;
}
示例11: StringBuilder
vs.window.showErrorMessage(`Sorry! '${action}' encountered an error.`, "Report Issue").then(() => {
try {
const sb = new StringBuilder();
sb.appendLine("Platform: " + process.platform);
sb.appendLine();
sb.appendLine("Exception:");
sb.appendLine(serializeError(error));
const uri = `https://github.com/joelday/vscode-docthis/issues/new?title=${
encodeURIComponent(`Exception thrown in '${action}': ${error.message}`)
}&body=${
encodeURIComponent(sb.toString())
}`;
if (process.platform !== "win32") {
openurl.open(uri, openErr => { console.error("Failed to launch browser", openErr); });
} else {
const proc = childProcess.spawnSync("cmd", [
"/c",
"start",
uri.replace(/[&]/g, "^&")
]);
}
}
catch (reportErr) {
reportError(reportErr, "Report Error");
}
});
示例12: compileShader
function compileShader(projectDir, type, from, to, temp, platform, nokrafix) {
let compiler = '';
if (Project.koreDir !== '') {
if (nokrafix) {
compiler = path.resolve(Project.koreDir, 'Tools', 'kfx', 'kfx' + exec.sys());
}
else {
compiler = path.resolve(Project.koreDir, 'Tools', 'krafix', 'krafix' + exec.sys());
}
}
if (fs.existsSync(path.join(projectDir.toString(), 'Backends'))) {
let libdirs = fs.readdirSync(path.join(projectDir.toString(), 'Backends'));
for (let ld in libdirs) {
let libdir = path.join(projectDir.toString(), 'Backends', libdirs[ld]);
if (fs.statSync(libdir).isDirectory()) {
let exe = path.join(libdir, 'krafix', 'krafix-' + platform + '.exe');
if (fs.existsSync(exe)) {
compiler = exe;
}
}
}
}
if (compiler !== '') {
child_process.spawnSync(compiler, [type, from, to, temp, platform]);
}
}
示例13: terminate
export function terminate(process: ChildProcess, cwd?: string): boolean {
if (isWindows) {
try {
// This we run in Atom execFileSync is available.
// Ignore stderr since this is otherwise piped to parent.stderr
// which might be already closed.
let options: any = {
stdio: ['pipe', 'pipe', 'ignore']
}
if (cwd) {
options.cwd = cwd
}
cp.execFileSync(
'taskkill',
['/T', '/F', '/PID', process.pid.toString()],
options
)
return true
} catch (err) {
return false
}
} else if (isLinux || isMacintosh) {
try {
let cmd = join(pluginRoot, 'bin/terminateProcess.sh')
let result = cp.spawnSync(cmd, [process.pid.toString()])
return result.error ? false : true
} catch (err) {
return false
}
} else {
process.kill('SIGKILL')
return true
}
}
示例14: uploadResults
/** Uploads the coverage results to the firebase database. */
function uploadResults(results: any): Promise<void> {
let latestSha = spawnSync('git', ['rev-parse', 'HEAD']).stdout.toString().trim();
let database = openFirebaseDashboardDatabase();
return database.ref('coverage-reports').child(latestSha).set(results)
.then(() => database.goOffline(), () => database.goOffline());
}
示例15: _spawnGitProcess
/**
* Spawns a child process running Git. The "stderr" output is inherited and will be printed
* in case of errors. This makes it easier to debug failed commands.
*/
private _spawnGitProcess(args: string[], printStderr = true): SpawnSyncReturns<string> {
return spawnSync('git', args, {
cwd: this.projectDir,
stdio: ['pipe', 'pipe', printStderr ? 'inherit' : 'pipe'],
encoding: 'utf8',
});
}