-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·78 lines (69 loc) · 2.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
/*jslint
evil: true,
maxerr: 8,
maxlen: 96,
node: true,
nomen: true,
*/
(function (self) {
'use strict';
var local;
// run shared js-env code
(function () {
// init local
local = {};
local.modeJs = (function () {
try {
return self.phantom.version &&
typeof require('webpage').create === 'function' &&
'phantom';
} catch (errorCaughtPhantom) {
return module.exports &&
typeof process.versions.node === 'string' &&
typeof require('http').createServer === 'function' &&
'node';
}
}());
}());
switch (local.modeJs) {
// run node js-env code
case 'node':
module.exports = require('./package.json');
module.exports.__dirname = __dirname;
module.exports.processSpawn = function (arg0, argList, options) {
arg0 = arg0 || process.argv[2];
if (arg0 === 'alljs') {
module.exports.processSpawn('phantomjs', argList, options);
module.exports.processSpawn('slimerjs', argList, options);
return;
}
argList = argList || process.argv.slice(3);
options = options || { stdio: [0, 1, 2] };
switch (argList[0]) {
case 'eval':
argList = [__filename].concat(argList);
break;
}
return require('child_process').spawn(__dirname + '/' + arg0, argList, options);
};
// run the cli
if (module === require.main) {
module.exports.processSpawn();
}
break;
// run phantom js-env code
case 'phantom':
// require modules
local.system = require('system');
switch (local.system.args[1]) {
case 'eval':
eval(local.system.args[2]);
break;
default:
self.phantom.exit();
break;
}
break;
}
}(this));