1 | /**
|
2 | * This code is closed source and Confidential and Proprietary to
|
3 | * Appcelerator, Inc. All Rights Reserved. This code MUST not be
|
4 | * modified, copied or otherwise redistributed without express
|
5 | * written permission of Appcelerator. This file is licensed as
|
6 | * part of the Appcelerator Platform and governed under the terms
|
7 | * of the Appcelerator license agreement.
|
8 | */
|
9 | var debug = require('debug')('appc:run');
|
10 | /**
|
11 | * run the real appc binary by setting up the correct environment location
|
12 | * and then delegate directly (via a spawn) to the real appc binary in our package
|
13 | */
|
14 | function run (installBin, additionalArgs, cb, dontexit) {
|
15 | var spawn = require('child_process').spawn,
|
16 | path = require('path'),
|
17 | util = require('./util');
|
18 |
|
19 | // append any incoming program args
|
20 | var args = [ installBin ].concat(process.argv.splice(2));
|
21 |
|
22 | // add any additional args
|
23 | if (additionalArgs) {
|
24 | args = args.concat(additionalArgs);
|
25 | }
|
26 |
|
27 | // get the environment
|
28 | var env = process.env;
|
29 |
|
30 | // setup our node environment by first appending our appc node_modules
|
31 | env.NODE_PATH = path.resolve(path.join(path.dirname(installBin),'..','node_modules')) + path.delimiter +
|
32 | // and then our global cache directory
|
33 | path.join(util.getCacheDir(),'node_modules') + path.delimiter +
|
34 | // then pickup any paths already setup in our env
|
35 | (env.NODE_PATH || '');
|
36 |
|
37 | debug('run with env=%j, args=%o',env,args);
|
38 |
|
39 | // create our child process which simply inherits this process stdio
|
40 | var child = spawn(process.execPath,args,{env:env, stdio:'inherit'});
|
41 |
|
42 | // on exit of child, exit ourselves with same exit code
|
43 | child.on('close',function(code){
|
44 | if (cb) { cb(code); }
|
45 | if (!dontexit) { process.exit(code); }
|
46 | });
|
47 | }
|
48 |
|
49 | module.exports = run;
|