forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJakefile.js
More file actions
305 lines (249 loc) · 8.44 KB
/
Jakefile.js
File metadata and controls
305 lines (249 loc) · 8.44 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
// Copyright (c) 2012 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();
if (!process.env.loose) console.log("For more forgiving test settings, use 'loose=true'");
var REQUIRED_BROWSERS = [
"IE 8.0.0 (Windows 7)",
"IE 9.0.0 (Windows 7)",
"Firefox 35.0.0 (Mac OS X 10.10)",
"Chrome 40.0.2214 (Mac OS X 10.10.2)",
"Safari 8.0.3 (Mac OS X 10.10.2)",
"Mobile Safari 7.0.0 (iOS 7.1)"
];
var GENERATED_DIR = "generated";
var TEMP_TESTFILE_DIR = GENERATED_DIR + "/test";
var BUILD_DIR = GENERATED_DIR + "/build";
var BUILD_CLIENT_DIR = BUILD_DIR + "/client";
directory(TEMP_TESTFILE_DIR);
directory(BUILD_DIR);
directory(BUILD_CLIENT_DIR);
desc("Delete all generated files");
task("clean", [], function() {
jake.rmRf(GENERATED_DIR);
});
desc("Build and test");
task("default", [ "lint", "test" ], function() {
buildOk();
});
desc("Build and test fast targets only");
task("quick", [ "lint", "testFast" ], function() {
buildOk();
});
desc("Start Karma server for testing");
task("karma", function() {
karma().serve("build/karma.conf.js", complete, fail);
}, {async: true});
desc("Start WeeWikiPaint server for manual testing");
task("run", [ "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});
desc("Lint everything");
task("lint", [ "nodeVersion", "lintNode", "lintClient" ]);
task("lintClient", function() {
var passed = lint().validateFileList(clientLintFiles(), clientLintOptions(), clientGlobals());
if (!passed) fail("Lint failed");
});
var path = require("path");
var lintRunner = lint();
var glob = require("glob");
task("lintNode");
nodeLintDirectories().forEach(function(lintDirectory) {
task("lintNode", [ lintDirectory ]);
directory(lintDirectory);
});
task("lintNode", nodeLintDependencies());
function lintSourceFile(name) {
var result = name.replace(/^generated\/lint\//, "");
return result.replace(/\.lint$/, ".js");
}
rule(".lint", lintSourceFile, function() {
var fs = require("fs");
var passed = lintRunner.validateFile(this.source, nodeLintOptions(), {});
if (passed) fs.writeFileSync(this.name, "lint ok");
else fail("Lint failed");
});
desc("Test everything");
task("test", [ "testFast", "testSlow" ]);
task("testFast", [ "testServer", "testClient" ]);
task("testSlow", [ "testSmoke" ]);
desc("Test server code");
task("testServer", [ "nodeVersion", TEMP_TESTFILE_DIR ], function() {
nodeunit().runTests(serverTestFiles(), complete, fail);
}, {async: true});
desc("Test client code");
task("testClient", [], function() {
karma().runTests(REQUIRED_BROWSERS, complete, fail);
}, {async: true});
desc("End-to-end smoke tests");
task("testSmoke", [ "build" ], function() {
nodeunit().runTests(smokeTestFiles(), complete, fail);
}, {async: true});
desc("Bundle and build code");
task("build", [ BUILD_CLIENT_DIR ], function() {
var fs = require("fs");
var shell = require("shelljs");
var browserify = require("browserify");
shell.rm("-rf", BUILD_CLIENT_DIR + "/*");
shell.cp(
"-R",
"src/client/*.html", "src/client/*.css", "src/client/images", "src/client/vendor",
BUILD_CLIENT_DIR
);
console.log("Bundling client files with Browserify...");
var b = browserify({ debug: true });
b.require("./src/client/client.js", {expose: "./client.js"} );
b.require("./src/client/html_element.js", {expose: "./html_element.js"} );
b.bundle(function(err, bundle) {
if (err) fail(err);
fs.writeFileSync(BUILD_CLIENT_DIR + "/bundle.js", bundle);
complete();
});
}, {async: true});
desc("Deploy to Heroku");
task("deploy", function() {
console.log("To deploy to production:");
console.log("1. Integrate ('jake integrate')");
// Correction: Use "git push heroku integration:master" to deploy from integration branch.
// Thanks to Jüri A, http://www.letscodejavascript.com/v3/comments/live/32#comment-798947003 .
console.log("2. 'git push heroku integration:master' (or 'git push staging integration:master')");
console.log("3. 'jake test'");
console.log();
console.log("To deploy latest code to staging server:");
console.log("1. Make sure 'git status' is clean.");
console.log("2. 'git push staging master");
console.log("3. Visit http://wwp-staging.herokuapp.com/");
});
// desc("Ensure correct version of Node is present.");
task("nodeVersion", [], function() {
var versionChecker = require("./build/util/version_checker.js");
var deployedVersion = "v" + require("./package.json").engines.node;
versionChecker.check("Node", !process.env.loose, deployedVersion, process.version, fail);
});
desc("Integration checklist");
task("integrate", [ "default" ], 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'");
console.log("5. 'git checkout master'");
});
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\"'");
});
function serverTestFiles() {
var testFiles = new jake.FileList();
testFiles.include("src/server/**/_*_test.js");
testFiles = testFiles.toArray();
return testFiles;
}
function smokeTestFiles() {
var testFiles = new jake.FileList();
testFiles.include("src/_*_test.js");
testFiles = testFiles.toArray();
return testFiles;
}
function clientLintFiles() {
var javascriptFiles = new jake.FileList();
javascriptFiles.include("src/client/*.js");
return javascriptFiles.toArray();
}
function nodeLintFiles() {
return glob.sync("{*.js,build/util/*.js,src/server/**/*.js,src/*.js}");
}
function nodeLintDirectories() {
var result = [];
nodeLintDependencies().forEach(function(lintDependency) {
result.push(path.dirname(lintDependency));
});
return result;
}
function nodeLintDependencies() {
return nodeLintFiles().map(function(pathname) {
return "generated/lint/" + pathname.replace(/\.js$/, ".lint");
});
}
function nodeLintOptions() {
var options = sharedLintOptions();
options.node = true;
return options;
}
function clientLintOptions() {
var options = sharedLintOptions();
options.browser = true;
return options;
}
function sharedLintOptions() {
return {
bitwise: true,
curly: false,
eqeqeq: true,
forin: true,
immed: true,
latedef: false,
newcap: true,
noarg: true,
noempty: true,
nonew: true,
regexp: true,
undef: true,
strict: true,
trailing: true
};
}
function clientGlobals() {
return {
// Browserify
require: false,
module: false,
exports: false,
// Mocha / expect.js
describe: false,
it: false,
expect: false,
dump: false,
beforeEach: false,
afterEach: false,
before: false,
after: false,
// Browser
console: false
};
}
function buildOk() {
var elapsedSeconds = (Date.now() - startTime) / 1000;
console.log("\n\nBUILD OK (" + elapsedSeconds.toFixed(2) + "s)");
}
// We've factored our require statements into functions 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.
function lint() {
return require("./build/util/lint_runner.js");
}
function nodeunit() {
return require("./build/util/nodeunit_runner.js");
}
function karma() {
return require("./build/util/karma_runner.js");
}
}());