UNPKG

2.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var child_process_1 = require("child_process");
4var chek_1 = require("chek");
5var argv_1 = require("./argv");
6var logger_1 = require("./logger");
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.
41var 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 */
54function exec(cmd, args, options) {
55 // If true user wants stdout to output value
56 // instead of using inherit outputting
57 // to process.stdout stream.
58 if (options === true)
59 options = { stdio: 'pipe' };
60 options = chek_1.extend({}, spawnDefaults, options);
61 if (chek_1.isString(args))
62 args = argv_1.splitArgs(args);
63 // Ensure command and arguments.
64 if (!cmd)
65 logger_1.log.error('Cannot execute process with command of undefined.');
66 // Spawn child.
67 var child = child_process_1.spawnSync(cmd, args, options);
68 if (child.stdout)
69 return child.stdout.toString();
70}
71exports.methods = {
72 command: exec,
73 node: exec.bind(null, 'node'),
74 npm: exec.bind(null, 'npm'),
75 git: exec.bind(null, 'git')
76};
77//# sourceMappingURL=exec.js.map
\No newline at end of file