mirror of https://github.com/wg-easy/wg-easy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
587 B
29 lines
587 B
import childProcess from 'child_process';
|
|
|
|
export function exec(
|
|
cmd: string,
|
|
{ log }: { log: boolean | string } = { log: true }
|
|
) {
|
|
if (typeof log === 'string') {
|
|
console.log(`$ ${log}`);
|
|
} else if (log === true) {
|
|
console.log(`$ ${cmd}`);
|
|
}
|
|
|
|
if (process.platform !== 'linux') {
|
|
return Promise.resolve('');
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
childProcess.exec(
|
|
cmd,
|
|
{
|
|
shell: 'bash',
|
|
},
|
|
(err, stdout) => {
|
|
if (err) return reject(err);
|
|
return resolve(String(stdout).trim());
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|