Initial commit
[yaffs-website] / node_modules / cross-spawn / index.js
1 'use strict';
2
3 var cp = require('child_process');
4 var parse = require('./lib/parse');
5 var enoent = require('./lib/enoent');
6
7 var cpSpawnSync = cp.spawnSync;
8
9 function spawn(command, args, options) {
10     var parsed;
11     var spawned;
12
13     // Parse the arguments
14     parsed = parse(command, args, options);
15
16     // Spawn the child process
17     spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
18
19     // Hook into child process "exit" event to emit an error if the command
20     // does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
21     enoent.hookChildProcess(spawned, parsed);
22
23     return spawned;
24 }
25
26 function spawnSync(command, args, options) {
27     var parsed;
28     var result;
29
30     if (!cpSpawnSync) {
31         try {
32             cpSpawnSync = require('spawn-sync');  // eslint-disable-line global-require
33         } catch (ex) {
34             throw new Error(
35                 'In order to use spawnSync on node 0.10 or older, you must ' +
36                 'install spawn-sync:\n\n' +
37                 '  npm install spawn-sync --save'
38             );
39         }
40     }
41
42     // Parse the arguments
43     parsed = parse(command, args, options);
44
45     // Spawn the child process
46     result = cpSpawnSync(parsed.command, parsed.args, parsed.options);
47
48     // Analyze if the command does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
49     result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
50
51     return result;
52 }
53
54 module.exports = spawn;
55 module.exports.spawn = spawn;
56 module.exports.sync = spawnSync;
57
58 module.exports._parse = parse;
59 module.exports._enoent = enoent;