@mail-core/cli
Version:
Инструментарий для написания cli-скриптов
62 lines • 2.04 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.runFile = void 0;
const path_1 = require("path");
const child_process_1 = require("child_process");
const command_1 = require("../../../command/command");
function runFile(console, file, args, rest) {
delete rest._;
delete rest.$0;
Object.entries(rest).forEach(([key, val]) => {
args.push(`--${key}=${val}`);
});
const RUN_CMD = path_1.resolve(__dirname, '..', '..', 'run');
console.verbose('run:', RUN_CMD, file, args);
const child = child_process_1.spawn(RUN_CMD, [file].concat(args), {
stdio: 'inherit',
cwd: process.cwd(),
env: process.env,
});
child.on('close', (code) => {
console.verbose(`Exit code:`, code);
process.exit(code);
});
return child;
}
exports.runFile = runFile;
exports.run = command_1.createCommand({
name: 'run',
describe: 'Run ts/js with ts-node or node',
options: {
file: {
desc: '*.{ts,js} file',
type: 'string',
positional: true,
interactive: true,
demandOption: true,
},
args: {
desc: 'Arguments',
array: true,
type: 'string',
default: [],
positional: true,
},
},
async handler(_a, { console }) {
var { file, args } = _a, rest = __rest(_a, ["file", "args"]);
await runFile(console, file, args, rest);
},
});
//# sourceMappingURL=index.js.map