forked from AtomicGameEngine/AtomicGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildCommon.js
More file actions
353 lines (250 loc) · 10.5 KB
/
BuildCommon.js
File metadata and controls
353 lines (250 loc) · 10.5 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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
var fs = require('fs-extra');
var os = require('os');
var path = require("path");
var glob = require('glob');
var Tslint = require("tslint");
var fso = require('fs');
var spawnSync = require('child_process').spawnSync;
var host = require("./Host");
var config = require('./BuildConfig');
var atomicRoot = config.atomicRoot;
var jsDocFolder = config.artifactsRoot + "Build/JSDoc/";
var cppDocFolder = config.artifactsRoot + "Build/CPPDocs/";
var csharpDocFolder = config.artifactsRoot + "Build/CSharpDocs/";
namespace('build', function() {
// Linting task
task('lint_typescript', {
async: true
}, function(fileMask, failOnError) {
console.log("TSLINT: Linting files in " + fileMask);
var lintConfig = JSON.parse(fs.readFileSync("./Script/tslint.json"));
var tslintConfig = {
configuration: lintConfig,
formatter: "prose"
};
// lint
// Since TSLint does not yet support recursively searching for files, then we need to
// create a command per file. The main issue with this is that it will abort on the first error instead
// of listing out all lint errors
glob(fileMask, function(err, results) {
var lintErrors = [];
results.forEach(function(filename) {
var contents = fs.readFileSync(filename, "utf8");
var ll = new Tslint(filename, contents, tslintConfig);
var result = ll.lint();
if (result.failureCount > 0) {
lintErrors.push(result.output);
}
});
if (lintErrors.length > 0) {
console.warn("TSLINT: WARNING - Lint errors detected");
console.warn(lintErrors.join(''));
if (failOnError) {
fail("TSLint errors detected");
}
}
complete();
});
});
// precreate script bindgs so they can be picked up by CMake
task('precreateScriptBindings', {
async: true
}, function(clean) {
if (clean === undefined) {
clean = true;
}
console.log("Precreating script bindings");
if (clean) {
common.cleanCreateDir(common.getGenScriptRootDir())
}
common.createGenScriptFiles();
complete();
});
function fileExists(filePath)
{
try
{
return fs.statSync(filePath).isFile();
}
catch (err)
{
return false;
}
}
task('genAtomicNET', {
async:true
}, function(platform, configuration) {
if (configuration != "Debug" && configuration != "Release")
configuration = "Release";
// Compile AtomicNET assemblies
var cmds = [];
cmds.push(host.atomicTool + " net compile " + atomicRoot + "Script/AtomicNET/AtomicNETProject.json -platform " + platform + " -config " + configuration);
jake.exec(cmds, function() {
complete();
}, {
printStdout: true
});
})
task('genscripts', {
async: true
}, function(force) {
// default to true
if (force != "true" && force != "false") {
force = "true";
}
var anyZero = false;
if (force != "true") {
var filenames = common.getGenScriptFilenames();
for (var i in filenames) {
if (!fileExists(filenames[i]))
{
console.log("genscripts: file missing, regenerating script bindings: " + filenames[i]);
anyZero = true;
break;
}
var stats = fs.statSync(filenames[i]);
if (stats["size"] == 0) {
console.log("genscripts: file zero size, regenerating script bindings: " + filenames[i]);
anyZero = true;
break;
}
}
if (!anyZero)
return;
}
process.chdir(atomicRoot);
var modules = host.getScriptModules();
var bindCmd = host.atomicTool + " bind \"" + atomicRoot + "\" ";
var node = host.node;
var tsc = "./Build/node_modules/typescript/lib/tsc";
var tslint = "./Build/node_modules/tslint/lib/tslint-cli";
var dtsGenerator = "./Build/node_modules/dts-generator/bin/dts-generator";
var cmds = [];
for (var pkgName in modules) {
cmds.push(bindCmd + "Script/Packages/" + pkgName + "/");
}
if (node) {
// compile
cmds.push(node + " " + tsc + " -p ./Script");
cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
// generate combined atomic.d.ts
cmds.push(node + " " + dtsGenerator + " --name Atomic --project ./Script/TypeScript --out ./Script/TypeScript/dist/Atomic.d.ts");
var lintTask = jake.Task['build:lint_typescript'];
lintTask.addListener('complete', function () {
console.log("\n\nLint: Typescript linting complete.\n\n");
jake.exec(cmds, { printStdout : true, printStderr: true }, function() {
// copy some external dependencies into the editor modules directory
var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
var nodeModulesDir = "./Build/node_modules";
fs.mkdirsSync(editorModulesDir);
// TypeScript
fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
// copy lib.core.d.ts into the tool data directory
fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
fs.copySync("./Build/node_modules/typescript/lib/lib.es5.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.es5.d.ts");
// copy the combined Atomic.d.ts to the tool data directory
fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
complete();
}, {
printStdout: true
});
});
lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
} else {
throw new Error("Node not configured for this platform: " + os.platform());
}
});
task('gendocs', {
async: true
}, function() {
console.log( "Generating Docs..." );
fs.copySync(atomicRoot + "Build/Docs/Readme.md", jsDocFolder + "Readme.md");
fs.copySync(atomicRoot + "Build/Docs/atomic-theme", jsDocFolder + "atomic-theme");
var typeDoc;
if (os.platform() == "win32") {
// uses system node for typedoc, which should have as require npm
typeDoc = "node_modules\\.bin\\typedoc.cmd";
}
else
typeDoc = host.node + " ./node_modules/.bin/typedoc";
// tsdoc is having problems when name has spaces on Windows and Linux, tried quoting/escaping
// what should happen here is instead of command line use a json config file (or maybe new version of tsdoc fixes this)
var name = "Atomic-Game-Engine";
cmds = [
"cd " + jsDocFolder + " && echo {} > package.json", // newer versions of npm require package.json to be in the folder or else it searches up the heirarchy
"cd " + jsDocFolder + " && npm install typedoc",
"cd " + jsDocFolder + " && " + typeDoc + " --out out " + config.atomicRoot +
"Script/TypeScript/dist/Atomic.d.ts --module commonjs --includeDeclarations --mode file --theme atomic-theme --name " +
name + " --readme ./Readme.md"
];
jake.exec(cmds, function() {
common.cleanCreateDir( config.toolDataFolder + "Docs");
fs.copySync(jsDocFolder + "out", config.toolDataFolder + "Docs/JSDocs");
complete();
console.log( "completed installing API documentation" );
}, {
printStdout: true
});
});
task('gendoxygen', {
async: true
}, function() {
console.log( "Generating C++ API Documentation..." );
var cppDoc;
if (os.platform() == "win32") {
cppDoc = "doxygen"; // I dont know what to do here...
}
else {
// use doxygen on path
cppDoc = "doxygen";
}
cmds = [
"cd " + atomicRoot + "Source && " + cppDoc + " " + atomicRoot + "Build/Docs/CPlusPlus/Doxyfile"
];
jake.exec(cmds, function() {
common.cleanCreateDir( config.toolDataFolder + "Docs/CPPDocs"); // clear destination
fs.copySync(cppDocFolder, config.toolDataFolder + "Docs/CPPDocs"); // copy into release same place as JSDocs
complete();
console.log( "completed installing CPP API documentation" );
}, {
printStdout: true
});
});
task('genmdoc', {
async: true
}, function() {
console.log( "Generating C# API Documentation..." );
// mdoc must be on path
var mdoc = "mdoc";
// clear destination
common.cleanCreateDir( csharpDocFolder );
cmds = [
"cd " + csharpDocFolder + " && " + mdoc + " update -o docgen -i ../../AtomicNET/Release/Desktop/AtomicNET.xml ../../AtomicNET/Release/Desktop/AtomicNET.dll",
"cd " + csharpDocFolder + " && " + mdoc + " export-html -o html docgen --template=../../../Build/Docs/CSharp/atomictemplate.xlst"
];
jake.exec(cmds, function() {
// clear destination
common.cleanCreateDir( config.toolDataFolder + "Docs/CSharpDocs");
// copy into release same place as JSDocs
fs.copySync(csharpDocFolder, config.toolDataFolder + "Docs/CSharpDocs");
complete();
console.log( "completed installing C# API documentation" );
}, {
printStdout: true
});
});
task('genexamples', {
async: true
}, function() {
console.log( "Generating Examples..." );
// TODO: support pulling examples from a specific branch/commit/etc
var exampleSrc = atomicRoot + "Submodules/AtomicExamples/";
var exampleDst = config.toolDataFolder + "AtomicExamples/";
common.testRemoveDir( exampleDst);
fs.copySync(exampleSrc, exampleDst);
// remove the .git file/folder and save some space
fs.removeSync( exampleDst + ".git" );
complete();
});
}); // end of build namespace