Website : rimsha.abasa.com
backdoor
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
canvas
/
node_modules
/
wsrun
/
build
/
Filename :
cmd-process.js
back
Copy
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CmdProcess = void 0; const child_process_1 = require("child_process"); const Bromise = require("bluebird"); const originalSplit = require("split"); const enums_1 = require("./enums"); const utils_1 = require("./utils"); const SPLIT_OPTIONS = { trailing: false }; const SPLIT_MAPPER = (x) => x; const split = () => originalSplit(/\r?\n/, SPLIT_MAPPER, SPLIT_OPTIONS); class CmdProcess { constructor(console, cmd, pkgName, opts) { this.console = console; this.cmd = cmd; this.pkgName = pkgName; this.opts = opts; this._closed = utils_1.defer(); this._finished = utils_1.defer(); this._exitCode = utils_1.defer(); this._cancelled = utils_1.defer(); this.pkgName = pkgName; this.opts = opts; if (this.opts.doneCriteria) this.doneCriteria = new RegExp(this.opts.doneCriteria); } /** * Finished will return true even if the process hasn't exited, if doneCriteria was found in * the output. Useful for watch processes that have initialization. * * It will also get rejected if there is a non-favorable exit code. */ get finished() { return this._finished.promise; } /** * Exitcode is always resolved with the exit code, never rejected. */ get exitCode() { return this._exitCode.promise; } get result() { return Bromise.race([this._exitCode.promise, this._cancelled.promise]); } /** * ExitError is like exitCode, except it gets rejected when the exit code is nonzero */ get exitError() { return this.exitCode.then(c => { if (c != 0) throw new Error('`' + this.cmdString + '` failed with exit code ' + c); }); } get cmdString() { return this.cmd.join(' '); } start() { this._start(this.cmd); this.cp.once('close', code => { this._closed.resolve(code); this._exitCode.resolve(code); }); this.cp.once('exit', code => this._exitCode.resolve(code)); this.exitCode.then(code => { if (code > 0) { const msg = '`' + this.cmdString + '` failed with exit code ' + code; if (!this.opts.silent) this.console.error(this.autoAugmentLine(msg)); if (this.opts.rejectOnNonZeroExit) return this._finished.reject(new Error(msg)); } this._finished.resolve(); }); // ignore if unhandled this._finished.promise.catch(() => { }); } stop() { if (this.cp) { this.cp.removeAllListeners('close'); this.cp.removeAllListeners('exit'); this.cp.kill('SIGINT'); } this._cancelled.resolve(enums_1.ResultSpecialValues.Cancelled); } autoPrefix(line) { return this.opts.prefixer ? this.opts.prefixer(this.opts.path, this.pkgName, line) : line; } autoPathRewrite(line) { return this.opts.pathRewriter ? this.opts.pathRewriter(this.opts.path, line) : line; } autoAugmentLine(line) { line = this.autoPathRewrite(line); line = this.autoPrefix(line); return line; } _start(cmd) { let sh; let args; // cross platform compatibility if (process.platform === 'win32') { sh = 'cmd'; args = ['/c'].concat(cmd); } else { ; [sh, ...args] = cmd; //sh = 'bash' //shFlag = '-c' } this.cmd = cmd; this.cp = child_process_1.spawn(sh, args, { cwd: this.opts.path || (process.versions.node < '8.0.0' ? process.cwd : process.cwd()), env: Object.assign(process.env, process.stdout.isTTY ? { FORCE_COLOR: process.env.FORCE_COLOR || '1' } : {}), stdio: this.opts.collectLogs || this.opts.prefixer != null || this.opts.doneCriteria ? 'pipe' : 'inherit' }); if (this.cp.stdout) this.cp.stdout.pipe(split()).on('data', (line) => { this.console.log(this.autoAugmentLine(line)); if (this.doneCriteria && this.doneCriteria.test(line)) this._finished.resolve(); }); if (this.cp.stderr) this.cp.stderr.pipe(split()).on('data', (line) => { this.console.error(this.autoAugmentLine(line)); if (this.doneCriteria && this.doneCriteria.test(line)) this._finished.resolve(); }); } } exports.CmdProcess = CmdProcess; //# sourceMappingURL=cmd-process.js.map