-
Notifications
You must be signed in to change notification settings - Fork 133
/
Jakefile.js
370 lines (289 loc) · 11.4 KB
/
Jakefile.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
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Copyright (c) 2012-2016 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
/*global desc, task, file, jake, rule, fail, complete, directory*/
(function() {
"use strict";
var startTime = Date.now();
// We've put most of our require statements in functions (or tasks) so we don't have the overhead of
// loading modules we don't need. At the time this refactoring was done, module loading took about half a
// second, which was 10% of our desired maximum of five seconds for a quick build.
// The require statements here are just the ones that are used to set up the tasks.
var paths = require("./build/config/paths.js");
var strict = !process.env.loose;
if (strict) console.log("For more forgiving test settings, use 'loose=true'");
//*** DIRECTORIES
directory(paths.tempTestfileDir);
directory(paths.buildDir);
directory(paths.buildServerDir);
directory(paths.buildSharedDir);
directory(paths.buildClientDir);
directory(paths.incrementalDir);
//*** GENERAL
jake.addListener('complete', function () {
var elapsedSeconds = (Date.now() - startTime) / 1000;
console.log("\n\nBUILD OK (" + elapsedSeconds.toFixed(2) + "s)");
});
desc("Delete all generated files");
task("clean", [], function() {
jake.rmRf(paths.generatedDir);
});
desc("Lint and test everything");
task("default", [ "clean", "quick", "smoketest" ]);
desc("Incrementally lint and test fast targets");
task("quick", [ "versions", "lint", "test" ]);
desc("Start Karma server for testing");
task("karma", [ "versions" ], function() {
karmaRunner().start({
configFile: paths.karmaConfig
}, complete, fail);
}, { async: true });
desc("Start localhost server for manual testing");
task("run", [ "nodeVersion", "build" ], function() {
var runServer = require("./src/_run_server.js");
console.log("Running server. Press Ctrl-C to stop.");
runServer.runInteractively();
// We never call complete() because we want the task to hang until the user presses 'Ctrl-C'.
}, { async: true });
//*** LINT
desc("Lint everything");
task("lint", [ "lintLog", "incrementalLint" ], function() {
console.log();
});
task("lintLog", function() { process.stdout.write("Linting JavaScript: "); });
task("incrementalLint", paths.lintDirectories());
task("incrementalLint", paths.lintOutput());
createDirectoryDependencies(paths.lintDirectories());
rule(".lint", determineLintDependency, function() {
/*eslint no-invalid-this:off */
var lint = require("./build/util/lint_runner.js");
var lintConfig = require("./build/config/eslint.conf.js");
var passed = lint.validateFile(this.source, lintConfig.options);
if (passed) fs().writeFileSync(this.name, "lint ok");
else fail("Lint failed");
});
//*** TEST
desc("Test everything (except smoke tests)");
task("test", [ "testShared", "testServer", "testClient" ]);
desc("Test client code");
task("testClient", [ "testClientUi", "testClientNetwork", "testClientCss" ]);
desc("Test shared code");
task("testShared", [ "testSharedOnServer", "testSharedOnClient" ]);
desc("Test server code");
incrementalTask("testServer", [ paths.tempTestfileDir ], paths.serverTestDependencies(), function(complete, fail) {
console.log("Testing server JavaScript: ");
mochaRunner().runTests({
files: paths.serverTestFiles(),
options: mochaConfig()
}, complete, fail);
});
incrementalTask("testSharedOnServer", [], paths.sharedJsTestDependencies(), function(complete, fail) {
console.log("Testing shared JavaScript on server: ");
mochaRunner().runTests({
files: paths.sharedTestFiles(),
options: mochaConfig()
}, complete, fail);
});
incrementalTask("testSharedOnClient", [], paths.sharedJsTestDependencies(), function(complete, fail) {
console.log("Testing shared JavaScript on client: ");
runKarmaOnTaggedSubsetOfTests("SHARED", complete, fail);
});
incrementalTask("testClientUi", [], paths.clientJsTestDependencies(), function(complete, fail) {
console.log("Testing browser UI code: ");
runKarmaOnTaggedSubsetOfTests("UI", complete, fail);
});
incrementalTask("testClientCss", [], paths.cssTestDependencies(), function(complete, fail) {
console.log("Testing CSS:");
runKarmaOnTaggedSubsetOfTests("CSS", complete, fail);
});
incrementalTask("testClientNetwork", [], paths.clientNetworkTestDependencies(), function(complete, fail) {
console.log("Testing browser networking code: ");
var networkHarness = require("./src/client/network/__test_harness_server.js");
var networkStopFn = networkHarness.start();
runKarmaOnTaggedSubsetOfTests("NET", networkStopFn(complete), fail);
});
function runKarmaOnTaggedSubsetOfTests(tag, complete, fail) {
karmaRunner().run({
configFile: paths.karmaConfig,
expectedBrowsers: testedBrowsers(),
strict: strict,
clientArgs: [ "--grep=" + tag + ":" ]
}, complete, fail);
}
desc("End-to-end smoke tests");
task("smoketest", [ "build" ], function(why) {
console.log("Smoke testing app: ");
mochaRunner().runTests({
files: paths.smokeTestFiles(),
options: mochaConfig()
}, complete, fail);
}, { async: true });
//*** BUILD DISTRIBUTION DIRECTORY
desc("Bundle and build code");
task("build", [ "server", "client" ]);
task("server", [ paths.buildServerDir, paths.buildSharedDir ], function() {
console.log("Collating server files: .");
shell().rm("-rf", paths.buildDir + "/server/*");
shell().rm("-rf", paths.buildDir + "/shared/*");
shell().rm("-rf", paths.buildDir + "/node_modules/*");
shell().cp(
"-R",
"src/server",
"src/shared",
"src/node_modules",
paths.buildDir
);
});
task("client", [ "cacheBust" ]);
task("cacheBust", [ "collateClientFiles", "bundleClientJs" ], function() {
process.stdout.write("Cache-busting CSS and JavaScript: ");
var hashCatRunner = require("./build/util/hashcat_runner.js");
hashCatRunner.go({
files: [ paths.buildClientIndexHtml, paths.buildClient404Html ]
}, removeUnwantedFiles, fail);
function removeUnwantedFiles() {
shell().rm(paths.buildIntermediateFilesToErase());
complete();
}
}, { async: true });
task("collateClientFiles", [ paths.buildClientDir ], function() {
console.log("Collating client files: .");
shell().rm("-rf", paths.buildClientDir + "/*");
shell().cp(
"-R",
"src/client/content/*", "src/client/ui/vendor", "src/client/network/vendor",
paths.buildClientDir
);
});
task("bundleClientJs", [ paths.buildClientDir ], function() {
process.stdout.write("Bundling client files with Browserify: ");
var browserifyRunner = require("./build/util/browserify_runner.js");
browserifyRunner.bundle({
requires: [
{ path: "./src/client/ui/client.js", expose: "./client.js" },
{ path: "./src/client/ui/html_element.js", expose: "./html_element.js" },
{ path: "./src/client/network/real_time_connection.js", expose: "./real_time_connection.js" }
],
outfile: paths.buildClientDir + "/bundle.js",
options: { debug: true }
}, complete, fail);
}, { async: true });
//*** CHECK VERSIONS
desc("Check dependency versions");
task("versions", [ "nodeVersion", "socketIoVersion" ]);
task("nodeVersion", [], function() {
console.log("Checking Node.js version: .");
var version = require("./build/util/version_checker.js");
version.check({
name: "Node",
expected: require("./package.json").engines.node,
actual: process.version,
strict: strict
}, complete, fail);
}, { async: true });
task("socketIoVersion", [], function() {
console.log("Checking Socket.IO versions: .");
var nodeServerVersion = require("socket.io/package").version;
var nodeClientVersion = require("socket.io-client/package").version;
if (nodeServerVersion !== nodeClientVersion) {
console.log("Socket.IO versions did not match!\n" +
" socket.io: " + nodeServerVersion + "\n" +
" socket.io-client: " + nodeClientVersion
);
fail("Socket.IO version mismatch");
}
var vendorClientFilename = "./src/client/network/vendor/socket.io-" + nodeServerVersion + ".js";
try {
var stat = fs().statSync(vendorClientFilename);
// file exists, we're all good
}
catch (err) {
console.log("Socket.IO vendor file version did not match or was missing!\n" +
" Expected version " + nodeServerVersion + "\n" +
" at location " + vendorClientFilename + "\n" +
" To get correct version, `jake run` and go to:\n" +
" http://localhost:5000/socket.io/socket.io.js\n" +
" (" + err + ")"
);
fail("Socket.IO version mismatch");
}
});
//*** CHECKLISTS
desc("Integration checklist");
task("integrate", function() {
console.log("1. Make sure 'git status' is clean.");
console.log("2. Build on the integration box.");
console.log(" a. Walk over to integration box.");
console.log(" b. 'git pull'");
console.log(" c. 'npm rebuild'");
console.log(" d. Check status for files that need to be .gitignore'd");
console.log(" e. 'jake'");
console.log(" f. If jake fails, stop! Try again after fixing the issue.");
console.log("3. 'git checkout integration'");
console.log("4. 'git merge master --no-ff --log=100 -m \"INTEGRATE: \" -e'");
console.log("5. 'git checkout master'");
});
desc("Deploy checklist");
task("deploy", function() {
console.log("To deploy to production:");
console.log("1. Make sure `git status` is clean");
console.log("2. Run full build (`jake`) and make sure it builds okay");
console.log("3. Check in release code: `git add generated/dist -f && git commit`");
console.log("4. Integrate");
console.log("5. Deploy integrated code to staging: `git push staging integration:master`");
console.log("6. Verify by visiting http://wwp-staging.herokuapp.com");
console.log("7. Deploy integrated to production: `git push heroku integration:master`");
console.log("8. Remove `generated/dist` from git");
});
desc("End-of-episode checklist");
task("episode", [], function() {
console.log("1. Save recording.");
console.log("2. Double-check sound and framing.");
console.log("3. Commit source code.");
console.log("4. Check Windows compatibility");
console.log(" a. Switch to Windows VM");
console.log(" b. 'git pull'");
console.log(" c. 'npm rebuild'");
console.log(" d. Check status for files that need to be .gitignore'd");
console.log(" e. 'jake'");
console.log("5. Tag episode: 'git tag -a episodeXX -m \"End of episode XX\"'");
});
//*** UTILITY FUNCTIONS
function determineLintDependency(name) {
var result = name.replace(/^generated\/incremental\/lint\//, "");
return result.replace(/\.lint$/, "");
}
function incrementalTask(taskName, taskDependencies, fileDependencies, action) {
var incrementalFile = paths.incrementalDir + "/" + taskName + ".task";
task(taskName, taskDependencies.concat(paths.incrementalDir, incrementalFile));
file(incrementalFile, fileDependencies, function() {
action(succeed, fail);
}, {async: true});
function succeed() {
fs().writeFileSync(incrementalFile, "ok");
complete();
}
}
function createDirectoryDependencies(directories) {
directories.forEach(function(lintDirectory) {
directory(lintDirectory);
});
}
//*** LAZY-LOADED MODULES
function fs() {
return require("fs");
}
function karmaRunner() {
return require("simplebuild-karma");
}
function mochaRunner() {
return require("./build/util/mocha_runner.js");
}
function mochaConfig() {
return require("./build/config/mocha.conf.js");
}
function shell() {
return require("shelljs");
}
function testedBrowsers() {
return require("./build/config/tested_browsers.js");
}
}());