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
144 lines (123 loc) · 4.32 KB
/
Jakefile.js
File metadata and controls
144 lines (123 loc) · 4.32 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
// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
/*global desc, task, jake, fail, complete, directory*/
(function() {
"use strict";
var NODE_VERSION = "v0.8.6";
var GENERATED_DIR = "generated";
var TEMP_TESTFILE_DIR = GENERATED_DIR + "/test";
directory(TEMP_TESTFILE_DIR);
desc("Delete all generated files");
task("clean", [], function() {
jake.rmRf(GENERATED_DIR);
});
desc("Build and test");
task("default", ["lint", "test"]);
desc("Lint everything");
task("lint", ["nodeVersion"], function() {
var lint = require("./build/lint/lint_runner.js");
var javascriptFiles = new jake.FileList();
javascriptFiles.include("**/*.js");
javascriptFiles.exclude("node_modules");
var options = nodeLintOptions();
var passed = lint.validateFileList(javascriptFiles.toArray(), options, {});
if (!passed) fail("Lint failed");
});
desc("Test everything");
task("test", ["nodeVersion", TEMP_TESTFILE_DIR], function() {
var testFiles = new jake.FileList();
testFiles.include("**/_*_test.js");
testFiles.exclude("node_modules");
var reporter = require("nodeunit").reporters["default"];
reporter.run(testFiles.toArray(), null, function(failures) {
if (failures) fail("Tests failed");
complete();
});
}, {async: true});
desc("Deploy to Heroku");
task("deploy", ["default"], function() {
console.log("1. Make sure 'git status' is clean.");
console.log("2. 'git push heroku master'");
console.log("3. 'jake test'");
});
// desc("Ensure correct version of Node is present. Use 'strict=true' to require exact match");
task("nodeVersion", [], function() {
function failWithQualifier(qualifier) {
fail("Incorrect node version. Expected " + qualifier +
" [" + expectedString + "], but was [" + actualString + "].");
}
var expectedString = NODE_VERSION;
var actualString = process.version;
var expected = parseNodeVersion("expected Node version", expectedString);
var actual = parseNodeVersion("Node version", actualString);
if (process.env.strict) {
if (actual[0] !== expected[0] || actual[1] !== expected[1] || actual[2] !== expected[2]) {
failWithQualifier("exactly");
}
}
else {
if (actual[0] < expected[0]) failWithQualifier("at least");
if (actual[0] === expected[0] && actual[1] < expected[1]) failWithQualifier("at least");
if (actual[0] === expected[0] && actual[1] === expected[1] && actual[2] < expected[2]) failWithQualifier("at least");
}
});
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. 'jake strict=true'");
console.log(" d. 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. Tag episode: 'git tag -a episodeXX -m \"End of episode XX\"'");
});
function parseNodeVersion(description, versionString) {
var versionMatcher = /^v(\d+)\.(\d+)\.(\d+)$/; // v[major].[minor].[bugfix]
var versionInfo = versionString.match(versionMatcher);
if (versionInfo === null) fail("Could not parse " + description + " (was '" + versionString + "')");
var major = parseInt(versionInfo[1], 10);
var minor = parseInt(versionInfo[2], 10);
var bugfix = parseInt(versionInfo[3], 10);
return [major, minor, bugfix];
}
function sh(command, callback) {
console.log("> " + command);
var stdout = "";
var process = jake.createExec(command, {printStdout:true, printStderr: true});
process.on("stdout", function(chunk) {
stdout += chunk;
});
process.on("cmdEnd", function() {
console.log();
callback(stdout);
});
process.run();
}
function nodeLintOptions() {
return {
bitwise:true,
curly:false,
eqeqeq:true,
forin:true,
immed:true,
latedef:true,
newcap:true,
noarg:true,
noempty:true,
nonew:true,
regexp:true,
undef:true,
strict:true,
trailing:true,
node:true
};
}
}());