UNPKG

@ainc/script

Version:

Script compiler for typescript

46 lines 1.36 kB
/** ***************************************** * Created by edonet@163.com * Created on 2021-06-27 15:18:50 ***************************************** */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.fork = exports.spawn = void 0; /** ***************************************** * 加载依赖 ***************************************** */ const os = require("os"); const cp = require("child_process"); /** ***************************************** * 执行命令 ***************************************** */ function spawn(command, args, options) { return new Promise((resolve, reject) => { const shell = os.platform() !== 'linux'; const child = cp.spawn(command, args || [], { shell, stdio: 'inherit', ...options }); // 监听事件 child.on('close', resolve); child.on('error', reject); }); } exports.spawn = spawn; /** ***************************************** * 执行文件 ***************************************** */ function fork(file, args, options) { return new Promise((resolve, reject) => { const child = cp.fork(file, args || [], { stdio: 'inherit', detached: true, ...options }); // 监听事件 child.on('close', resolve); child.on('error', reject); }); } exports.fork = fork; //# sourceMappingURL=cp.js.map