child_process#SpawnOptionsWithoutStdio TypeScript Examples
The following examples show how to use
child_process#SpawnOptionsWithoutStdio.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dev-server.ts From image-optimizer with MIT License | 6 votes |
function startElectron () {
if (electronProcess) return
const args = ['.', rendererPort] as SpawnOptionsWithoutStdio
electronProcess = spawn('electron', args)
electronProcess?.stdout?.on('data', data => {
console.log(chalk.blueBright('[Electron] ') + chalk.white(data.toString()))
})
electronProcess?.stderr?.on('data', data => {
console.log(chalk.redBright('[Electron] ') + chalk.white(data.toString()))
})
}
Example #2
Source File: techdocs-cli.test.ts From backstage with Apache License 2.0 | 6 votes |
executeCommand = (
command: string,
args: string[],
options?: SpawnOptionsWithoutStdio,
): Promise<{
exit: number;
stdout: string;
stderr: string;
}> => {
return new Promise(resolve => {
const stdout: Buffer[] = [];
const stderr: Buffer[] = [];
const shell = process.platform === 'win32';
const proc = spawn(command, args, { ...options, shell });
proc.stdout?.on('data', data => {
stdout.push(Buffer.from(data));
});
proc.stderr?.on('data', data => {
stderr.push(Buffer.from(data));
});
proc.on('exit', code => {
resolve({
exit: code ?? 0,
stdout: Buffer.concat(stdout).toString('utf8'),
stderr: Buffer.concat(stderr).toString('utf8'),
});
});
});
}
Example #3
Source File: processManager.ts From cli with Apache License 2.0 | 6 votes |
public spawn(
command: string,
args?: ReadonlyArray<string>,
options?: SpawnOptionsWithoutStdio
): ChildProcessWithoutNullStreams {
const process = nativeSpawn(command, args, {
detached: true,
...options,
});
process.on('exit', this.onExit(process));
this.processes.add(process);
return process;
}
Example #4
Source File: terminal.ts From cli with Apache License 2.0 | 6 votes |
public constructor(
command: string,
args?: ReadonlyArray<string>,
options?: SpawnOptionsWithoutStdio,
processManager: ProcessManager = new ProcessManager(),
debugName?: string
) {
this.childProcess = processManager.spawn(command, args, options);
const fileLogger = new FileLogger(
debugName ?? `${command}-${args?.join('-')}`.replace(/[^\w\d]/g, '-')
);
this.logIntoFile(fileLogger);
this.orchestrator = new Orchestrator(this.childProcess);
}
Example #5
Source File: handlers.ts From solita with Apache License 2.0 | 6 votes |
export function handleAnchor(
config: SolitaConfigAnchor,
prettierConfig?: PrettierOptions
) {
const { idlDir, binaryInstallDir, programDir } = config
const spawnArgs = ['build', '--idl', idlDir]
const spawnOpts: SpawnOptionsWithoutStdio = {
cwd: programDir,
}
const rustbinConfig: RustbinConfig = {
rootDir: binaryInstallDir,
binaryName: 'anchor',
binaryCrateName: 'anchor-cli',
libName: 'anchor-lang',
cargoToml: path.join(programDir, 'Cargo.toml'),
dryRun: false,
...config.rustbin,
}
return handle(config, rustbinConfig, spawnArgs, spawnOpts, prettierConfig)
}
Example #6
Source File: handlers.ts From solita with Apache License 2.0 | 6 votes |
export function handleShank(
config: SolitaConfigShank,
prettierConfig?: PrettierOptions
) {
const { idlDir, binaryInstallDir, programDir } = config
const spawnArgs = ['idl', '--out-dir', idlDir, '--crate-root', programDir]
const spawnOpts: SpawnOptionsWithoutStdio = {
cwd: programDir,
}
const rustbinConfig: RustbinConfig = {
rootDir: binaryInstallDir,
binaryName: 'shank',
binaryCrateName: 'shank-cli',
libName: 'shank',
cargoToml: path.join(programDir, 'Cargo.toml'),
dryRun: false,
}
return handle(config, rustbinConfig, spawnArgs, spawnOpts, prettierConfig)
}
Example #7
Source File: spawn-promise.ts From relate with GNU General Public License v3.0 | 6 votes |
spawnPromise = (
command: string,
args: string[] = [],
options: SpawnOptionsWithoutStdio = {},
stream: ReadStream | Transform | undefined = undefined,
): Promise<string> => {
return new Promise((resolve, reject) => {
let commandEscaped = command;
let argsEscaped = args;
if (process.platform === 'win32') {
// https://nodejs.org/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows
commandEscaped = `"${command}"`;
argsEscaped = args.map((arg) => `"${arg}"`);
options.shell = true;
}
const child = spawn(commandEscaped, argsEscaped, options);
if (stream) {
stream.pipe(child.stdin);
}
const data: string[] = [];
const collect = (chunk: Buffer): void => {
data.push(chunk.toString());
};
child.stderr.on('data', collect);
child.stderr.on('error', reject);
child.stderr.on('close', () => resolve(data.join('')));
child.stderr.on('end', () => resolve(data.join('')));
child.stdout.on('data', collect);
child.stdout.on('error', reject);
child.stdout.on('close', () => resolve(data.join('')));
child.stdout.on('end', () => resolve(data.join('')));
});
}
Example #8
Source File: handlers.ts From solita with Apache License 2.0 | 5 votes |
async function handle(
config: SolitaConfig,
rustbinConfig: RustbinConfig,
spawnArgs: string[],
spawnOpts: SpawnOptionsWithoutStdio,
prettierConfig?: PrettierOptions
) {
const { programName, idlDir, sdkDir } = config
const { fullPathToBinary, binVersion, libVersion }: RustbinMatchReturn =
await rustbinMatch(rustbinConfig, confirmAutoMessageLog)
if (binVersion == null) {
throw new Error(
`rustbin was unable to determine installed version ${rustbinConfig.binaryName}, it may ` +
`not have been installed correctly.`
)
}
return new Promise<void>((resolve, reject) => {
const idlGenerator = spawn(fullPathToBinary, spawnArgs, spawnOpts)
.on('error', (err) => {
logError(`${programName} idl generation failed`)
reject(err)
})
.on('exit', async () => {
logInfo('IDL written to: %s', path.join(idlDir, `${programName}.json`))
const idl = await enhanceIdl(config, binVersion, libVersion)
await generateTypeScriptSDK(
idl,
sdkDir,
prettierConfig,
config.typeAliases,
config.serializers
)
resolve()
})
idlGenerator.stdout.on('data', (buf) => process.stdout.write(buf))
idlGenerator.stderr.on('data', (buf) => process.stderr.write(buf))
})
}