1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var child_process_1 = require("child_process");
|
4 | var chek_1 = require("chek");
|
5 | var logger = require("./logger");
|
6 | var log = logger.get();
|
7 | // COMMANDS REFERENCE //
|
8 | // access, adduser, bin, bugs, c, cache, completion, config,
|
9 | // ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
|
10 | // help, help-search, i, init, install, install-test, it, link,
|
11 | // list, ln, login, logout, ls, outdated, owner, pack, ping,
|
12 | // prefix, prune, publish, rb, rebuild, repo, restart, root,
|
13 | // run, run-script, s, se, search, set, shrinkwrap, star,
|
14 | // stars, start, stop, t, tag, team, test, tst, un, uninstall,
|
15 | // unpublish, unstar, up, update, v, version, view, whoami
|
16 | // FLAGS REFERENCE //
|
17 | // -v: --version
|
18 | // -h, -?, --help, -H: --usage
|
19 | // -s, --silent: --loglevel silent
|
20 | // -q, --quiet: --loglevel warn
|
21 | // -d: --loglevel info
|
22 | // -dd, --verbose: --loglevel verbose
|
23 | // -ddd: --loglevel silly
|
24 | // -g: --global
|
25 | // -C: --prefix
|
26 | // -l: --long
|
27 | // -m: --message
|
28 | // -p, --porcelain: --parseable
|
29 | // -reg: --registry
|
30 | // -f: --force
|
31 | // -desc: --description
|
32 | // -S: --save
|
33 | // -P: --save-prod
|
34 | // -D: --save-dev
|
35 | // -O: --save-optional
|
36 | // -B: --save-bundle
|
37 | // -E: --save-exact
|
38 | // -y: --yes
|
39 | // -n: --yes false
|
40 | // Default spawn options.
|
41 | var spawnDefaults = {
|
42 | cwd: process.cwd(),
|
43 | stdio: 'inherit',
|
44 | shell: true
|
45 | };
|
46 | /**
|
47 | * Exec
|
48 | * Executes command using child process.
|
49 | *
|
50 | * @param cmd node, npm or shell command to be executed.
|
51 | * @param args arguments to be passed to command.
|
52 | * @param options the child process spawn options.
|
53 | */
|
54 | function exec(cmd, args, options) {
|
55 | // If true user wants stdout to output
|
56 | // instead of using inherit outputting
|
57 | // to process.stdout.
|
58 | if (options === true)
|
59 | options = { stdio: 'pipe' };
|
60 | options = chek_1.extend({}, spawnDefaults, options);
|
61 | if (chek_1.isString(args))
|
62 | args = args.split(' ');
|
63 | // Ensure command and arguments.
|
64 | if (!cmd)
|
65 | log.error('cannot execute process with command or arguments of undefined.').exit();
|
66 | // Spawn child.
|
67 | var child = child_process_1.spawnSync(cmd, args, options);
|
68 | // Get the output.
|
69 | var output = child.output || [];
|
70 | output = output.slice(1, 2) || '';
|
71 | output = String(output).replace(/\n/, '');
|
72 | return output;
|
73 | }
|
74 | exports.methods = {
|
75 | command: exec,
|
76 | node: exec.bind(null, 'node'),
|
77 | npm: exec.bind(null, 'npm')
|
78 | };
|
79 | //# sourceMappingURL=exec.js.map |
\ | No newline at end of file |