UNPKG

1.38 kBJavaScriptView Raw
1var spawn = require('child_process').spawn;
2var exec = require('child_process').exec;
3var path = require('path');
4var fs = require('fs');
5var _ = require('underscore');
6
7// Just some utilities to `run` meteor commands
8Command = {
9 // execute a command and print it's output to the screen
10 spawn: function(meteorExec, args, package_dir, fn) {
11 var options = {customFds: [0,1,2]};
12 if (package_dir) {
13 options.env = _.extend({PACKAGE_DIRS: package_dir}, process.env);
14 }
15
16 spawn(meteorExec, args, options)
17 .on('error', function(err) {
18 // yikes! can't find the executable!
19 if (err.code === 'ENOENT') {
20 if (meteorExec === 'meteor') {
21 console.log("Can't find meteor executable!".red.bold);
22 console.log();
23 console.log("Please install meteor from http://meteor.com".red)
24 } else {
25 // XXX: is this possible?
26 console.log(("Can't find executable at " + meteorExec).red.bold);
27 console.log();
28 console.log("Please run mrt uninstall --system, and try again.".red);
29 }
30 }
31 })
32 .on('exit', fn);
33 },
34
35 // execute a command and return it's output to fn
36 exec: function(meteorExec, args, fn) {
37 args.unshift(meteorExec);
38 var command = args.join(' ');
39 exec(command, fn);
40 }
41};
42
43module.exports = Command;