forked from xeolabs/scenejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·310 lines (247 loc) · 10.8 KB
/
build.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/env node
/*
SceneJS WebGL Scene Graph Engine
Copyright (c) 2013, Lindsay Kay
All rights reserved.
*/
(function () {
var version = "3.1";
var ncp = require('ncp').ncp;
var sys = require('util');
var fs = require('fs');
var path = require('path');
var TYPE = "all"; // Default Type
var FLAGS = {
all:{
core:true
},
scripts:{
core:true
},
docs:{
core:false,
documents:true
},
dev:{
devtemplate:true
}
};
var isHelp = false;
//parse command line argments
process.argv.forEach(function (val, index, array) {
if (val == "--help") {
sys.print('SceneJS Build Script\n');
sys.print('Usage:\n');
sys.print('build [type] [options]\n');
sys.print('eg building scripts without documentation,\n build SCRIPTS --without-documents\n');
sys.print('\n');
sys.print('Types:\n');
sys.print('all - (DEFAULT) build all options\n');
sys.print('scripts - build the compiled script and uglify\n');
sys.print('docs - build documents\n');
sys.print('dev - build development template\n');
sys.print('\n');
sys.print('Options:\n');
sys.print('--without-uglify : builds without using the uglify JS compiler\n');
sys.print('--without-documents : (DEFAULT) builds without creating docs using the node-jsdoc-toolkit\n');
sys.print('\n');
sys.print('--with-uglify : (DEFAULT) builds using the uglify JS compiler\n');
sys.print('--with-documents : builds the docs using the node-jsdoc-toolkit\n');
isHelp = true;
return;
}
if (FLAGS[val]) {
FLAGS = FLAGS[val];
TYPE = val;
}
if (val.substr(0, 10) == "--without-") {
if (FLAGS[TYPE]) FLAGS = FLAGS[TYPE];
FLAGS[val.substr(10)] = false;
}
if (val.substr(0, 7) == "--with-") {
if (FLAGS[TYPE]) FLAGS = FLAGS[TYPE];
FLAGS[val.substr(7)] = true;
}
});
//if type not set then use default
if (FLAGS[TYPE]) {
FLAGS = FLAGS[TYPE];
}
var FILES = {
core:[
"licenses/license-header.js",
//--------------------------------------------------------------------
// Integrated 3rd party libs
//--------------------------------------------------------------------
// RequireJS supports dynamic loading of dependencies by plugins
// We're wrapping it in a conditional to define it if not already defined.
"src/lib/requireWrapperStart.js",
"src/lib/require.js",
"src/lib/requireWrapperEnd.js",
"src/lib/webgl-debug-utils.js",
//--------------------------------------------------------------------
// SceneJS
//--------------------------------------------------------------------
// Core
"src/core/map.js",
"src/core/scenejs.js",
// Synchronises the plugins' RequireJS 3rd-party libs route to the plugin path config,
// so that the plugins' require calls can find their 'lib' directory relative to their plugins directory
"src/lib/requireConfig.js",
"src/core/eventManager.js",
"src/core/plugins.js",
"src/core/events.js",
"src/core/canvas.js",
"src/core/engine.js",
"src/core/errors.js",
"src/core/config.js",
"src/core/log.js",
"src/core/math.js",
"src/core/webgl.js",
"src/core/status.js",
// Scene graph classes
"src/core/scene/nodeEvents.js",
"src/core/scene/core.js",
"src/core/scene/coreFactory.js",
"src/core/scene/node.js",
"src/core/scene/nodeFactory.js",
"src/core/scene/camera.js",
"src/core/scene/clips.js",
"src/core/scene/enable.js",
"src/core/scene/flags.js",
"src/core/scene/framebuf.js",
"src/core/scene/geometry.js",
"src/core/scene/layer.js",
"src/core/scene/library.js",
"src/core/scene/lights.js",
"src/core/scene/lookAt.js",
"src/core/scene/material.js",
"src/core/scene/morphGeometry.js",
"src/core/scene/name.js",
"src/core/scene/renderer.js",
"src/core/scene/scene.js",
"src/core/scene/shader.js",
"src/core/scene/shaderParams.js",
"src/core/scene/tag.js",
"src/core/scene/texture.js",
"src/core/scene/xform.js",
"src/core/scene/matrix.js",
"src/core/scene/rotate.js",
"src/core/scene/translate.js",
"src/core/scene/scale.js",
"src/core/scene/modelXFormStack.js",
"src/core/nodeTypes.js",
// Display list classes
"src/core/display/display.js",
"src/core/display/programSourceFactory.js",
"src/core/display/programSource.js",
"src/core/display/programFactory.js",
"src/core/display/program.js",
"src/core/display/objectFactory.js",
"src/core/display/object.js",
"src/core/display/renderContext.js",
// Display list state chunks
"src/core/display/chunks/chunk.js",
"src/core/display/chunks/chunkFactory.js",
"src/core/display/chunks/cameraChunk.js",
"src/core/display/chunks/clipsChunk.js",
"src/core/display/chunks/drawChunk.js",
"src/core/display/chunks/flagsChunk.js",
"src/core/display/chunks/framebufChunk.js",
"src/core/display/chunks/geometryChunk.js",
"src/core/display/chunks/lightsChunk.js",
"src/core/display/chunks/listenersChunk.js",
"src/core/display/chunks/lookAtChunk.js",
"src/core/display/chunks/materialChunk.js",
"src/core/display/chunks/morphGeometryChunk.js",
"src/core/display/chunks/nameChunk.js",
"src/core/display/chunks/programChunk.js",
"src/core/display/chunks/rendererChunk.js",
"src/core/display/chunks/shaderChunk.js",
"src/core/display/chunks/shaderParamsChunk.js",
"src/core/display/chunks/textureChunk.js",
"src/core/display/chunks/xformChunk.js"
]
};
sys.print("Generating file list\n");
var getFileList = function (list, all) {
if (!list) {
list = [];
}
for (var flag in FLAGS) {
if ((FLAGS[flag] || all) && FILES[flag]) {
for (var i = 0; i < FILES[flag].length; i++) {
if (list.indexOf(FILES[flag][i]) < 0) {
list.push(FILES[flag][i]);
}
}
}
}
return list;
};
var fileList = getFileList();
var output = [];
for (var i = 0; i < fileList.length; i++) {
sys.print("Importing: " + fileList[i] + "\n");
output.push(fs.readFileSync(fileList[i]));
}
var productionBuild = true;
var distDir = "api/" + (productionBuild ? "latest" : "dev");
var distPluginDir = distDir + "/plugins";
var distExtrasDir = distDir + "/extras";
// Create sub directory for build version
fs.mkdir(distDir,
function () {
fs.mkdir(distPluginDir,
function () {
fs.mkdir(distExtrasDir,
function () {
// Deep-copy an existing directory
sys.print("Distributing plugins to: " + distPluginDir + "\n");
ncp("src/plugins", distPluginDir, function (err) {
});
sys.print("Distributing extras to: " + distExtrasDir + "\n");
ncp("src/extras", distExtrasDir, function (err) {
});
fs.writeFileSync(distExtrasDir + "/gui.js", fs.readFileSync("src/extras/gui/dat.gui.min.js") + fs.readFileSync("src/extras/gui/gui.js"));
if (fileList.length > 0) {
sys.print("Writing core library to: " + distDir + "/scenejs.js\n");
output.push('SceneJS.configure({ pluginPath: "http://xeolabs.github.com/scenejs/' + distDir + '/plugins" });');
output = output.join("");
fs.writeFileSync(distDir + "/scenejs.js", output);
}
var files = getFileList([], true);
if (FLAGS.documents) {
if (files.length) {
var spawn = require('child_process').spawn;
var cmdStr = ["external/jsdoc-toolkit/app/run.js", "-a", "-d=docs",
//"-p",
"-t=external/jsdoc-toolkit/templates/jsdoc"].concat(files);
sys.print("cmdStr + " + cmdStr);
var cmd = spawn('node', cmdStr);
sys.print("Generating Documents\n");
cmd.stdout.on('data', function (data) {
sys.print(data);
});
// check exit-code
cmd.on('exit', function (code) {
if (code == 0) sys.print("Build Complete!\n");
else sys.print("Build Complete! Exit with code: " + code + "\n");
});
// check for errors
cmd.stderr.on('data', function (error) {
if (/^execvp\(\)/.test(error.asciiSlice(0, error.length))) {
console.log('Failed to start child process.');
}
});
} else {
sys.print("Build Complete!\n");
}
} else {
sys.print("Build Complete!\n");
}
});
});
});
})();