forked from philc/vimium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.js
More file actions
executable file
·189 lines (163 loc) · 5.63 KB
/
make.js
File metadata and controls
executable file
·189 lines (163 loc) · 5.63 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
#!/usr/bin/env node
// Usage: ./make.js command. Use -h for help.
// This is a set of tasks for building and testing Vimium in development.
fs = require("fs");
child_process = require("child_process");
// Spawns a new process and returns it.
function spawn(procName, optArray, silent = false, sync = false) {
if (process.platform == "win32") {
// if win32, prefix arguments with "/c {original command}"
// e.g. "coffee -c c:\git\vimium" becomes "cmd.exe /c coffee -c c:\git\vimium"
optArray.unshift("/c", procName)
procName = "cmd.exe"
}
proc = null
if (sync) {
proc = child_process.spawnSync(procName, optArray, {
stdio: [undefined, process.stdout, process.stderr]
});
} else {
proc = child_process.spawn(procName, optArray)
if (!silent) {
proc.stdout.on('data', (data) => process.stdout.write(data));
proc.stderr.on('data', (data) => process.stderr.write(data));
}
}
return proc;
}
// Compile coffeescript into javascript.
function build() {
coffee = spawn("coffee", ["-c", __dirname], false, true)
if (coffee.status != 0) {
console.log("Build failed. Coffee exited with status", coffee.status);
process.exit(coffee.status);
}
}
// Builds a zip file for submission to the Chrome store. The output is in dist/.
function buildStorePackage() {
const vimiumVersion = JSON.parse(fs.readFileSync("manifest.json").toString())["version"]
build();
spawn("rm", ["-rf", "dist/vimium"], false, true);
spawn("mkdir", ["-p", "dist/vimium"], false, true);
const blacklist = [".*", "*.coffee", "*.md", "reference", "test_harnesses", "tests", "dist", "git_hooks",
"CREDITS", "node_modules", "MIT-LICENSE.txt", "Cakefile"];
const rsyncOptions = [].concat.apply(
["-r", ".", "dist/vimium"],
blacklist.map((item) => ["--exclude", item]));
spawn("rsync", rsyncOptions, false, true);
const distManifest = "dist/vimium/manifest.json";
const manifest = JSON.parse(fs.readFileSync(distManifest).toString());
// Build the Chrome Store package; this does not require the clipboardWrite permission.
manifest.permissions = manifest.permissions.filter((p) => p != "clipboardWrite");
fs.writeFileSync(distManifest, JSON.stringify(manifest, null, 2));
spawn("zip", ["-r", `dist/vimium-chrome-store-${vimiumVersion}.zip`, "dist/vimium"], false, true);
// Build the Chrome Store dev package.
manifest.name = "Vimium Canary";
manifest.description = "This is the development branch of Vimium (it is beta software).";
fs.writeFileSync(distManifest, JSON.stringify(manifest, null, 2));
spawn("zip", ["-r", `dist/vimium-canary-${vimiumVersion}.zip`, "dist/vimium"], false, true);
// Build Firefox release.
const args = "-r -FS dist/vimium-ff-${vimium_version}.zip background_scripts Cakefile " +
"content_scripts CONTRIBUTING.md CREDITS icons lib manifest.json MIT-LICENSE.txt pages README.md" +
"-x *.coffee -x Cakefile -x CREDITS -x *.md";
spawn("zip", args.split(/\s+/), false, true);
}
// Returns how many tests failed.
function runUnitTests() {
console.log("Running unit tests...")
projectDir = "."
basedir = __dirname + "/tests/unit_tests/";
test_files = fs.readdirSync(basedir).filter((filename) => filename.indexOf("_test.js") > 0)
test_files = test_files.map((filename) => basedir + filename)
test_files.forEach((file) => {
path = (file[0] == '/' ? '' : './') + file;
require(path);
});
return Tests.run();
}
// Returns how many tests fail.
function runDomTests() {
const puppeteer = require("puppeteer");
const testFile = __dirname + "/tests/dom_tests/dom_tests.html";
(async () => {
const browser = await puppeteer.launch({
// NOTE(philc): "Disabling web security" is required for vomnibar_test.js, because we have a file://
// page accessing an iframe, and Chrome prevents this because it's a cross-origin request.
args: ['--disable-web-security']
});
const page = await browser.newPage();
page.on("console", msg => console.log(msg.text()));
await page.goto("file://" + testFile);
const testsFailed = await page.evaluate(() => {
Tests.run();
return Tests.testsFailed;
});
await browser.close();
return testsFailed;
})();
}
// Prints the list of valid commands.
function printHelpString() {
console.log("Usage: ./make.js command\n\nValid commands:");
const keys = Object.keys(commands).sort();
for (let k of keys)
console.log(k, ":", commands[k].help);
}
const commands = []
// Defines a new command.
function command(name, helpString, fn) {
commands[name] = { help: helpString, fn: fn };
}
command(
"build",
"compile all coffeescript files to javascript",
build);
command(
"test",
"Run all tests",
() => {
build();
let failed = runUnitTests();
failed += runDomTests();
if (failed > 0)
Process.exit(1);
});
command(
"test-unit",
"Run unit tests",
() => {
build();
const failed = runUnitTests() > 0;
if (failed > 0)
Process.exit(1);
});
command(
"test-dom",
"Run DOM tests",
() => {
build();
const failed = runDomTests();
if (failed > 0)
Process.exit(1);
});
command(
"autobuild",
"continually rebuild coffeescript files using coffee --watch",
() => {
spawn("coffee", ["-cw", __dirname]);
});
command(
"package",
"Builds a zip file for submission to the Chrome store. The output is in dist/",
buildStorePackage);
if (process.argv.includes("-h") || process.argv.includes("--help") || process.argv.length == 2) {
printHelpString();
return;
}
commandArg = process.argv[2]
if (commands[commandArg]) {
commands[commandArg].fn();
} else {
printHelpString();
process.exit(1);
}