forked from sproutcore/build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
141 lines (129 loc) · 4.07 KB
/
index.js
File metadata and controls
141 lines (129 loc) · 4.07 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*jshint node:true */
// the basic setup of the build tools is to first parse the configuration
// the configuration should contain specific settings for either dev or deploy / serve or build
//var vm = require('vm');
var util = require('util');
//var http = require('http');
//var repl = require('repl');
var dirname = __dirname; // dirname of this file
//var events = require('events');
var pathlib = require('path');
var env = require('sproutnode');
var files = [
'lib/core.js',
'lib/node_wrap.js',
'lib/fs.js',
'lib/proxy.js',
'lib/project.js',
'lib/file.js',
'lib/filetypes.js',
'lib/appbuilder.js',
'lib/api.js',
'lib/framework.js',
'lib/theme.js',
'lib/installer.js'
];
// we need to install some new stuff in the running context
files.forEach(function (f) {
env.loadFile(pathlib.join(dirname, f));
});
module.exports.__env = env;
module.exports.startDevServer = function (projectpath, opts) {
env.setPath('BT.runMode', "debug");
try {
env.setPath('BT.projectPath', projectpath);
env.setPath('BT.curPath', projectpath);
env.setPath('BT.btPath', dirname);
var p = pathlib.join(projectpath, 'sc_config');
env.loadFile(p); // this should actually load the config
//env.runCode("SC.Benchmark.verbose = true;");
if (opts.hasDebugServer) {
env.setPath("BT.debugServer", true);
}
if (opts.runBenchmarks) {
env.setPath("BT.runBenchmarks", true);
}
if (opts.logLevel) {
env.runCode("SC.Logger.logOutputLevel = '"+opts.logLevel+"'");
}
env.runCode("SC.run(function() { BT.projectManager.startServer(); })");
if (opts.hasREPL) {
env.repl();
}
//env.runCode("console.log(__dirname);");
}
catch (e) {
util.log('error caught: ' + util.inspect(e, true, 10));
if (e.code === 'ENOENT') {
util.log("You did not create a valid project config file");
throw e;
}
else if (e.message.indexOf("EMFILE") > -1 && e.message.indexOf("Too many opened files") > -1) {
util.log("It seems your OS only allows a very limited number of open files. On OSX and Linux please run ulimit -n 4096");
process.exit(1);
//throw e;
}
else {
throw e;
}
}
};
module.exports.startInstall = function (projectpath, opts) {
env.setPath('BT.runMode', "install");
env.setPath('BT.projectPath', projectpath);
env.setPath('BT.curPath', projectpath);
env.setPath('BT.btPath', dirname);
var code = "SC.run(function () { BT.startInstall('";
code += opts.gitUrl + "', { ";
if (opts.isGlobal) code += "isGlobal: true, ";
if (opts.isSilent) {
code += "isSilent: true, ";
}
if (opts.branch) {
code += "branch: '" + opts.branch + "'";
}
code += "}); });";
//util.log("about to run code: " + code);
try {
env.runCode(code);
}
catch (e) {
throw e;
}
};
module.exports.startBuild = function (projectpath, opts) {
env.setPath('BT.runMode', "build");
env.setPath('BT.projectPath', projectpath);
env.setPath('BT.curPath', projectpath);
env.setPath('BT.btPath', dirname);
env.setPath('BT.startTime', Date.now());
try {
if (opts.runBenchmarks) {
env.setPath("BT.runBenchmarks", true);
}
if (opts.logLevel) {
env.runCode("SC.Logger.logOutputLevel = '"+opts.logLevel+"'");
}
var p = pathlib.join(projectpath, 'sc_config');
env.loadFile(p); // this should actually load the config
var code = "SC.run(function() { BT.projectManager.startBuild(" + JSON.stringify(opts) + "); });";
var r = env.runCode(code);
//util.log('return value of r: ' + util.inspect(r));
if (r === "done") process.exit(0);
}
catch (err) {
util.log('error caught: ' + util.inspect(err, true, 10));
if (err.code === 'ENOENT') {
util.log("You did not create a valid project config file");
throw err;
}
else if (err.message.indexOf("EMFILE") > -1 && err.message.indexOf("Too many opened files") > -1) {
util.log("It seems your OS only allows a very limited number of open files. On OSX and Linux please run ulimit -n 4096");
process.exit(1);
//throw e;
}
else {
throw err;
}
}
};