mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-05 02:16:32 +00:00

- update Theia to `1.39.0`, - remove the application packager and fix the security vulnerabilities, - bundle the backed application with `webpack`, and - enhance the developer docs. Co-authored-by: Akos Kitta <a.kitta@arduino.cc> Co-authored-by: per1234 <accounts@perglass.com> Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { spawn } from 'node:child_process';
|
|
|
|
export function spawnCommand(
|
|
command: string,
|
|
args: string[],
|
|
onError: (error: Error) => void = (error) => console.log(error),
|
|
stdIn?: string
|
|
): Promise<string> {
|
|
return new Promise<string>((resolve, reject) => {
|
|
const cp = spawn(command, args, { windowsHide: true });
|
|
const outBuffers: Buffer[] = [];
|
|
const errBuffers: Buffer[] = [];
|
|
cp.stdout.on('data', (b: Buffer) => outBuffers.push(b));
|
|
cp.stderr.on('data', (b: Buffer) => errBuffers.push(b));
|
|
cp.on('error', (error) => {
|
|
onError(error);
|
|
reject(error);
|
|
});
|
|
cp.on('exit', (code, signal) => {
|
|
if (code === 0) {
|
|
const result = Buffer.concat(outBuffers).toString('utf8');
|
|
resolve(result);
|
|
return;
|
|
}
|
|
if (errBuffers.length > 0) {
|
|
const message = Buffer.concat(errBuffers).toString('utf8').trim();
|
|
const error = new Error(
|
|
`Error executing ${command} ${args.join(' ')}: ${message}`
|
|
);
|
|
onError(error);
|
|
reject(error);
|
|
return;
|
|
}
|
|
if (signal) {
|
|
const error = new Error(`Process exited with signal: ${signal}`);
|
|
onError(error);
|
|
reject(error);
|
|
return;
|
|
}
|
|
if (code) {
|
|
const error = new Error(`Process exited with exit code: ${code}`);
|
|
onError(error);
|
|
reject(error);
|
|
return;
|
|
}
|
|
});
|
|
if (stdIn !== undefined) {
|
|
cp.stdin.write(stdIn);
|
|
cp.stdin.end();
|
|
}
|
|
});
|
|
}
|