-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-scripts.js
230 lines (221 loc) · 8.14 KB
/
package-scripts.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
const { concurrent, copy, crossEnv, rimraf, series } = require("nps-utils");
function config(name) {
return `configs/tsconfig-${name}.json`;
}
function rollup(mod, minify) {
return package(`rollup --c --environment mod:${mod},${minify ? "minify" : ""}`);
}
function tsc(tsconfig) {
return package(`tsc --project ${config(tsconfig)}`);
}
function setTsNodeProject() {
return `TS_NODE_PROJECT=\"${config("tsnode")}\"`;
}
function webpack(tool, arg) {
return crossEnv(`${setTsNodeProject()} ${package(tool)} --config webpack.config.ts ${arg}`);
}
function package(script) {
return crossEnv(`./node_modules/.bin/${script}`);
}
function karma(single, watch, browsers, transpileOnly, noInfo, coverage, tsconfig, logLevel, devtool) {
return package(
`${setTsNodeProject()} ${package("karma")} start`
.concat(single !== null ? ` --single-run=${single}` : "")
.concat(watch !== null ? ` --auto-watch=${watch}` : "")
.concat(browsers !== null ? ` --browsers=${browsers}` : "")
.concat(transpileOnly !== null ? ` --transpile-only=${transpileOnly}` : "")
.concat(noInfo !== null ? ` --no-info=${noInfo}` : "")
.concat(coverage !== null ? ` --coverage=${coverage}` : "")
.concat(tsconfig !== null ? ` --tsconfig=${tsconfig}` : "")
.concat(logLevel !== null ? ` --log-level=${logLevel}` : "")
.concat(devtool !== null ? ` --devtool=${devtool}` : "")
);
}
function release(version, dry) {
/**
* Dry prevents anything irreversible from happening.
* It will do pretty much do the same thing except it won't push to git or publish to npm.
* Just remember to "unbump" the version in package.json after a dry run (see explanation below)
*/
const variant = dry ? "dry" : "default";
return {
default: series.nps(
`release.${version}.${variant}.before`,
`release.${version}.${variant}.version`,
`release.${version}.${variant}.after`
),
before: series.nps(
`release.${version}.${variant}.build`,
`release.${version}.${variant}.bump`,
`release.${version}.${variant}.git.stage`
),
after: series.nps(`release.${version}.${variant}.git.push`, `release.${version}.${variant}.npm.publish`),
bump: crossEnv(`npm --no-git-tag-version version ${version}`),
/**
* Normally, standard-version looks for certain keywords in the commit log and automatically assigns
* major/minor/patch based on the contents of those logs.
*
* --first-release disables that behavior and does not change the version, which allows us to manually
* decide the version and bump it with npm version (see right above) instead.
*
* The downside is that we have to bump the version in package.json even in a dry run, because
* standard-version wouldn't report what it would do otherwise.
*
* Therefore, always remember to manually "unbump" the version number in package.json after doing a dry run!
* If you forget this, you'll end up bumping the version twice which gives you one release without changes.
*/
version: `${package("standard-version")} --first-release --commit-all${dry ? " --dry-run" : ""}`,
build: series.nps("test", "build.dist"),
git: {
stage: "git add package.json dist",
push: `git push --follow-tags origin master${dry ? " -n" : ""}`
},
npm: {
publish: `npm ${dry ? "pack" : "publish"}`
}
};
}
module.exports = {
scripts: {
lint: package(`tslint --project ${config("build")}`),
test: {
default: package("nps test.single"),
single: karma(true, false, "ChromeHeadless", true, true, true, config("test"), null, null),
watch: {
default: package("nps test.watch.dev"),
dev: karma(false, true, "ChromeHeadless", true, true, true, config("test"), null, null),
debug: karma(false, true, "ChromeDebugging", true, false, null, config("test"), "debug", null)
}
},
build: {
demo: {
default: "nps build.demo.development",
development: {
default: webpack("webpack-dev-server", "--hot --env.server")
},
production: {
default: webpack("webpack", "--env.production")
}
},
dist: {
default: "nps build.dist.rollup",
before: series.nps("lint", "build.dist.clean"),
clean: rimraf("dist"),
rollup: {
default: series.nps("build.dist.before", "build.dist.rollup.all.default"),
minify: series.nps("build.dist.rollup.all.minify"),
all: {
default: concurrent.nps(
"build.dist.rollup.es2015.default",
"build.dist.rollup.amd.default",
"build.dist.rollup.commonjs.default",
// "build.dist.rollup.es2017.default",
// "build.dist.rollup.esnext.default",
"build.dist.rollup.nativeModules.default",
// "build.dist.rollup.system.default",
// "build.dist.rollup.umd.default"
),
minify: concurrent.nps(
"build.dist.rollup.es2015.minify",
"build.dist.rollup.amd.minify",
"build.dist.rollup.commonjs.minify",
// "build.dist.rollup.es2017.minify",
// "build.dist.rollup.esnext.default",
"build.dist.rollup.nativeModules.minify",
// "build.dist.rollup.system.minify",
// "build.dist.rollup.umd.minify"
)
},
amd: {
default: rollup("amd"),
minify: rollup("amd", true)
},
commonjs: {
default: rollup("commonjs"),
minify: rollup("commonjs", true)
},
es2015: {
default: rollup("es2015"),
minify: rollup("es2015", true)
},
es2017: {
default: rollup("es2017"),
minify: rollup("es2017", true)
},
esnext: {
default: rollup("esnext"),
minify: rollup("esnext", true)
},
nativeModules: {
default: rollup("native-modules"),
minify: rollup("native-modules", true)
},
system: {
default: rollup("system"),
minify: rollup("system", true)
},
umd: {
default: rollup("umd"),
minify: rollup("umd", true)
}
},
tsc: {
default: series.nps("build.dist.before", "build.dist.tsc.all"),
all: concurrent.nps(
"build.dist.tsc.amd",
"build.dist.tsc.commonjs",
"build.dist.tsc.es2015",
"build.dist.tsc.es2017",
"build.dist.tsc.esnext",
"build.dist.tsc.nativeModules",
"build.dist.tsc.system",
"build.dist.tsc.umd"
),
amd: tsc("build-amd"),
commonjs: tsc("build-commonjs"),
es2015: tsc("build-es2015"),
es2017: tsc("build-es2017"),
esnext: tsc("build-esnext"),
nativeModules: tsc("build-native-modules"),
system: tsc("build-system"),
umd: tsc("build-umd")
}
}
},
release: {
patch: {
default: release("patch"),
dry: release("patch", true)
},
minor: {
default: release("minor"),
dry: release("minor", true)
},
major: {
default: release("major"),
dry: release("major", true)
}
},
/**
* Make sure to run "npm run ghpages-setup" before "npm run ghpages" the very first time,
* or manually create the gh-pages branch and set the remote.
*
* There is no dry run variant for this because it's not really that harmful if the demo page goes bad
* and it doesn't affect the master branch.
*/
ghpages: {
default: series(
"git checkout gh-pages",
"git merge master --no-edit",
rimraf("*.bundle.js"),
rimraf("*.bundle.map"),
package("nps build.demo.production"),
"git add index.html *.bundle.js *.bundle.map",
'git commit -m "doc(demo): build demo"',
"git push",
"git checkout master"
),
setup: series("git checkout -b gh-pages", "git push -u origin gh-pages", "git checkout master")
}
}
};