-
Notifications
You must be signed in to change notification settings - Fork 74
/
server.js
executable file
·121 lines (101 loc) · 3.78 KB
/
server.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env node
var path = require('path');
var architect = require("architect");
var spawn = require("child_process").spawn;
var fs = require("fs");
// TODO: Need better args parser.
var configName = process.argv[2] || "default";
// when command line arguments are passed into this, we ignore them
// when loading the config file.
if (configName.indexOf("-") === 0) {
configName = "default";
}
// If a password is given as a command line parameter, we hide it
// in the title of the process instead of displaying it in plain
// text.
var title_parts = process.argv.slice();
title_parts.forEach(function(element, index, array) {
if (element === '--password') {
array[index+1] = 'xxxxxxxx';
}
});
process.title = title_parts.join(' ');
var debug = false;
var packed = false;
var packedName = "";
var exists = fs.existsSync || path.existsSync;
for (var p = 2; p < process.argv.length; p++) {
if (process.argv[p] === "-d") {
debug = true;
// ppc debug doesn't exist, or it's older than three days--rebuild it (FIXME)
if(!exists("plugins-client/lib.ppc/www/ppc/ppc_debug.js") ||
(exists("plugins-client/lib.ppc/www/ppc/ppc_debug.js")) &&
((new Date() - fs.statSync("plugins-client/lib.ppc/www/ppc/ppc_debug.js").mtime.valueOf()) / 86400000) >= 3) {
console.log("Building ppcdebug for first run...");
var buildDebug = spawn("npm", ["run-script", "build-debug"]);
buildDebug.stderr.setEncoding("utf8");
buildDebug.stderr.on('data', function (data) {
console.error(data);
});
buildDebug.on('exit', function (code) {
if (code !== 0) {
console.error('build-debug process exited with code ' + code);
process.exit(code);
}
boot();
});
}
else
boot();
}
else if (process.argv[p] === "-P") {
packed = true;
if (process.argv[p + 1] && process.argv[p + 1].indexOf("-") < 0) // use this specific packed file
packedName = process.argv[++p];
else
packedName = "c9os.min.js";
configName = "packed";
if(!exists("plugins-client/lib.packed/www/" + packedName) && !exists("plugins-client/lib.packed/www/" + packedName + ".gz")) {
console.log("Building packed file for first run...Please wait...");
console.log(" |\\ _,,,---,,_\n" +
" /,`.-'`' -. ;-;;,_\n" +
" |,4- ) )-,_..;\\ ( `'-'\n" +
" '---''(_/--' `-'\\_) Felix Lee");
var buildPackage = spawn("npm", ["run-script", "build-packed"]);
buildPackage.stderr.setEncoding("utf8");
buildPackage.stderr.on('data', function (data) {
console.error(data);
});
buildPackage.on('exit', function (code) {
if (code !== 0) {
console.error('build-package process exited with code ' + code);
process.exit(code);
}
boot();
});
}
else
boot();
}
}
if (debug == false && packed == false)
boot();
function boot() {
var configPath = path.resolve(__dirname, "./configs/", configName);
var plugins = require(configPath);
// server plugins
plugins.forEach(function(plugin) {
if (plugin.packagePath && /\.\/pylon.core$/.test(plugin.packagePath)) {
plugin.debug = debug;
plugin.packed = packed;
plugin.packedName = packedName;
}
});
architect.createApp(architect.resolveConfig(plugins, __dirname + "/plugins-server"), function (err, app) {
if (err) {
console.error("While starting the '%s':", configPath);
throw err;
}
console.log("Started '%s'!", configPath);
});
}