forked from dead-claudia/thallium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.js
227 lines (188 loc) · 5.9 KB
/
make.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
"use strict"
/* eslint-env node, shelljs */
require("shelljs/make")
var path = require("path")
var chokidar = require("chokidar")
var semver = require("semver")
var pkg = require("./package")
function c(cmd) {
return path.resolve(__dirname, "node_modules/.bin", cmd)
}
function exec(str, cb) {
if (Array.isArray(str)) str = str.join(" ")
echo("exec: " + str)
return global.exec(str, {stdio: "inherit"}, cb)
}
function task(name, callback) {
target[name] = function (arg) {
if (callback.length) {
echo("=== Task `" + name + "`, args: " + arg.join(" ") + " ===")
} else {
echo("=== Task `" + name + "` ===")
}
return callback(arg)
}
}
config.fatal = true
task("all", function () {
target.lint()
target.test()
})
task("lint", function () {
exec(c("eslint") + " . --cache --color")
exec(c("coffeelint") + " . --cache --color=always")
})
task("test", function () {
target["test:chrome"]()
target["test:firefox"]()
target["test:phantomjs"]()
target["test:node"]()
})
task("test:chrome", function () {
exec(c("karma") + " start --colors --single-run --browsers Chrome")
})
task("test:firefox", function () {
exec(c("karma") + " start --colors --single-run --browsers Firefox")
})
task("test:phantomjs", function () {
exec(c("karma") + " start --colors --single-run --browsers PhantomJS")
})
task("test:node", function () {
exec(c("mocha") + " --colors")
})
var dirs = [
"bin", "fixtures", "helpers", "lib", "r", "test", "test-util", "migrate",
"assert",
].join(",")
var patterns = ["{" + dirs + "}/**/{.,}*.{js,coffee}", "{.,}*.{js,coffee}"]
// This creates a closure with `onchange` to not use the memoized versions
// ShellJS replaces them with after the initial tick.
function watch(task) {
config.fatal = false
var active = false
var queue = []
var timeout
function execute() {
queue.forEach(function (event) {
echo(event.name + " " + event.path)
})
queue = []
active = true
exec("node make " + task, function () {
active = false
if (queue.length) execute()
})
}
chokidar.watch(patterns, {
cwd: __dirname,
ignored: ["./thallium{,-migrate}.js"],
})
.on("all", function (name, path) {
// Give time for the file changes to settle by delaying and debouncing
// the `onchange` task.
if (timeout != null) clearTimeout(timeout)
queue.push({name: name, path: path})
timeout = setTimeout(function () {
timeout = undefined
if (!active) execute()
}, 500)
})
.on("error", function (err) {
console.error(err.stack)
})
.once("ready", function () {
console.error('Watching "' + patterns.join('", "') + '"...')
})
}
task("watch", function () { watch("test") })
task("watch:chrome", function () { watch("test:chrome") })
task("watch:phantomjs", function () { watch("test:phantomjs") })
task("watch:node", function () { watch("test:node") })
task("bundle", function () {
exec([
c("browserify"),
"-dr ./lib/browser-bundle.js:thallium -o thallium.js",
])
exec([
c("browserify"),
"-dr ./migrate/bundle.js:thallium -o thallium-migrate.js",
])
})
task("update", function (args) {
var pkgs = args.filter(function (arg) { return arg[0] !== "-" })
var saveFlag = "--save-dev"
args
.filter(function (arg) { return arg[0] === "-" })
.forEach(function (arg) {
switch (arg) {
case "--release": saveFlag = "--save"; break
case "--raw": saveFlag = ""; break
default: // ignore
}
})
exec("npm install " + pkgs.join(" ") + saveFlag)
if (pkgs.indexOf("clean-assert") >= 0) {
exec("node ./scripts/update-clean-assert.js")
}
})
task("release", function (args) {
var force = false
var increment
args.forEach(function (arg) {
switch (arg) {
case "major": case "minor": case "patch":
case "premajor": case "preminor": case "prepatch": case "prerelease":
if (increment != null) {
console.error("Unexpected additional increment: " + arg)
exit(1)
}
increment = arg
break
case "--force": case "-f": force = true; break
case "--no-force": force = false; break
default: // ignore
}
})
if (increment == null) {
console.error([
"Increment parameter required. Use this target like so:",
"",
"node make release -- <semver-compatible increment> [ -f ]",
].join("\n"))
exit(1)
}
if (!force) {
var changelogUpdated = false
var treeDirty = false
exec("/usr/bin/env bash scripts/test.sh")
exec("git status --porcelain", {silent: true}).stdout
.split(/\r?\n/g)
.filter(function (line) { return line !== "" })
.forEach(function (line) {
if (/^( M|M |MM) CHANGELOG\.md$/.test(line)) {
changelogUpdated = true
} else {
treeDirty = true
}
})
if (!changelogUpdated || treeDirty) {
if (!changelogUpdated) {
console.error("Error: Changelog must be updated!")
}
if (treeDirty) {
console.error("Error: Tree must not be dirty!")
}
exit(1)
}
}
target.bundle()
// Increment the package version and get the printed version
pkg.version = semver.inc(pkg.version, increment)
JSON.stringify(pkg, null, 2).to(path.resolve(__dirname, "package.json"))
// Add everything
exec("git add thallium.js thallium-migrate.js package.json CHANGELOG.md")
exec("git commit --message=v" + pkg.version)
exec("git tag v" + pkg.version)
exec("git push")
exec("git push --tags")
})