-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakfyfile.ts
356 lines (344 loc) · 13.1 KB
/
makfyfile.ts
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import { cmd as _cmd, choice as _choice, flag, escape, str } from 'makfy';
import { choice, cmd } from './types/makfy-extended';
const choice = (_choice as unknown) as choice;
const cmd = (_cmd as unknown) as cmd;
cmd('clean')
.desc('Clean repo')
.run(async (exec) => {
await exec('rimraf ./.nyc_output || echo "No files to delete"');
await exec('rimraf ./build || echo "No files to delete"');
await exec('rimraf ./coverage || echo "No files to delete"');
await exec('rimraf ./instrumented || echo "No files to delete"');
await exec('rimraf ./instrumented-cjs || echo "No files to delete"');
await exec('rimraf ./examples/bundled || echo "No files to delete"');
await exec('rimraf ./examples/modules || echo "No files to delete"');
await exec('rimraf ./examples/ssr || echo "No files to delete"');
await exec('rimraf ./src/**/*.js || echo "No files to delete"');
await exec('rimraf ./src/**/*.d.ts || echo "No files to delete"');
await exec('rimraf ./src/**/*.map || echo "No files to delete"');
await exec('rimraf ./test/modules || echo "No files to delete"');
});
cmd('compile')
.desc('Compile source typescript')
.args({
dir: choice(['src', 'test', 'bin', 'examples', 'all'], 'src'),
watch: flag(),
})
.argsDesc({
dir:
'The directory to compile (or all if you want to compile them all)',
watch: 'Watch for changes',
})
.run(async (exec, { watch, dir }) => {
const watchArg = watch ? '--watch' : '';
await exec(`? compiling directory ${dir}`);
switch (dir) {
case 'src':
await exec([
`yarn tsc -p src/tsconfig.cjs.json ${watchArg}`,
`yarn tsc -p src/tsconfig.json ${watchArg}`,
]);
break;
case 'test':
await exec([
`yarn tsc -p test/tsconfig.cjs.json ${watchArg}`,
`yarn tsc -p test/tsconfig.json ${watchArg}`,
]);
break;
case 'bin':
await exec(`yarn tsc -p ./tsconfig.bin.json ${watchArg}`);
break;
case 'examples':
await exec(`yarn tsc -p examples/tsconfig.json ${watchArg}`);
break;
case 'all':
await exec(`@compile --dir src ${watchArg}`);
await exec(`@compile --dir test ${watchArg}`);
await exec(`@compile --dir bin ${watchArg}`);
await exec(`@compile --dir examples ${watchArg}`);
break;
}
});
cmd('watch')
.desc('Watch compile typescript files')
.args({
dir: choice(['es', 'cjs', 'test-es', 'test-cjs', 'all'], 'es'),
noclear: flag(),
})
.argsDesc({
dir:
'The directory to compile (or all if you want to compile them all)',
noclear: "Don't clear output on re-compile",
})
.run(async (exec, { dir, noclear }) => {
const clearArg = noclear ? '--preserveWatchOutput' : '';
await exec(`? watching directory ${dir}`);
switch (dir) {
case 'es':
await exec(`yarn tsc -p src/tsconfig.json -w ${clearArg}`);
break;
case 'cjs':
await exec(`yarn tsc -p src/tsconfig.cjs.json -w ${clearArg}`);
break;
case 'test-es':
await exec(`yarn tsc -p test/tsconfig.json -w ${clearArg}`);
break;
case 'test-cjs':
await exec(`yarn tsc -p test/tsconfig.cjs.json -w ${clearArg}`);
break;
case 'all':
await exec(
escape(
'concurrently',
`yarn tsc -p src/tsconfig.json -w --preserveWatchOutput`,
`yarn tsc -p src/tsconfig.cjs.json -w --preserveWatchOutput`,
`yarn tsc -p test/tsconfig.json -w --preserveWatchOutput`,
`yarn tsc -p test/tsconfig.cjs.json -w --preserveWatchOutput`
)
);
}
});
cmd('cypress').desc('Run cypress tests').run('node test/usage/test.js');
cmd('_set-cypress')
.desc('Set the cypress config to only run given files')
.args({
selection: choice(
[
'all',
'classes',
'lib',
'partial-classes-basic',
'partial-classes-complex-template',
'partial-classes-i18n',
'partial-classes-theming',
'properties',
'tasks',
],
'all'
),
})
.argsDesc({
selection: 'What part of the files to select for running',
})
.run(async (exec, { selection }) => {
switch (selection) {
case 'all':
await exec(`? setting selection to test/usage/integration`);
await exec('node scripts/set-specs.js test/usage/integration');
break;
case 'classes':
await exec(
`? setting selection to test/usage/integration/classes`
);
await exec(
'node scripts/set-specs.js test/usage/integration/classes'
);
break;
case 'lib':
await exec(`? setting selection to test/usage/integration/lib`);
await exec(
'node scripts/set-specs.js test/usage/integration/lib'
);
break;
case 'partial-classes-basic':
await exec(
`? setting selection to test/usage/integration/partial-classes/basic`
);
await exec(
'node scripts/set-specs.js test/usage/integration/partial-classes/basic'
);
break;
case 'partial-classes-complex-template':
await exec(
`? setting selection to test/usage/integration/partial-classes/complex-template`
);
await exec(
'node scripts/set-specs.js test/usage/integration/partial-classes/complex-template'
);
break;
case 'partial-classes-i18n':
await exec(
`? setting selection to test/usage/integration/partial-classes/i18n`
);
await exec(
'node scripts/set-specs.js test/usage/integration/partial-classes/i18n'
);
break;
case 'partial-classes-theming':
await exec(
`? setting selection to test/usage/integration/partial-classes/theming`
);
await exec(
'node scripts/set-specs.js test/usage/integration/partial-classes/theming'
);
break;
case 'properties':
await exec(
`? setting selection to test/usage/integration/properties`
);
await exec(
'node scripts/set-specs.js test/usage/integration/properties'
);
break;
case 'tasks':
await exec(
`? setting selection to test/usage/integration/tasks`
);
await exec(
'node scripts/set-specs.js test/usage/integration/tasks'
);
break;
}
});
cmd('test')
.desc('Run tests')
.args({
subtest: choice(['unit', 'cypress', 'all'], 'all'),
})
.argsDesc({
subtest: 'Which subtest to run',
})
.run(async (exec, { subtest }) => {
switch (subtest) {
case 'unit':
await exec(
'? generating CJS lit-html bundle at test/modules/lit-html.js'
);
await exec(
'rollup node_modules/lit-html/lit-html.js --file test/modules/lit-html.js --format cjs --banner "var window = {}"'
);
await exec('? testing with ava');
await exec('ava');
break;
case 'cypress':
await exec('? testing with cypress');
await exec('node test/usage/test.js');
break;
case 'all':
await exec('? compiling typescript and setting test selection');
await exec([
'@compile --dir all',
'@_set-cypress --selection all',
]);
await exec('? running tests');
await exec('@test --subtest cypress');
await exec('@test --subtest unit');
break;
}
});
cmd('serve')
.desc('Serve current directory on localhost')
.args({
port: str('1251'),
})
.argsDesc({
port: 'The port to serve it on',
})
.run(async (exec, { port }) => {
await exec(`http-server -c-1 -p ${port} .`);
});
cmd('examples')
.desc('Compile and prepare examples for serving')
.run('@compile --dir all', '@serve');
cmd('website')
.desc(
'Compile and prepare website for serving, including bundled and SSRed examples'
)
.run(async (exec) => {
await exec('? cleaning');
await exec('@clean');
await exec('? compiling build TS');
await exec('@compile --dir src');
await exec('? preparing website');
await exec('gulp prepareWebsite');
await exec('? compiling TS');
await exec('@compile --dir all');
await exec('? generating bundles');
await exec(
'node -r esm ./node_modules/gulp/bin/gulp.js --cwd examples bundle',
'node -r esm ./node_modules/gulp/bin/gulp.js --cwd examples ssr',
);
});
cmd('coverage')
.args({
subset: choice(
[
'all',
'classes',
'lib',
'partial-classes-basic',
'partial-classes-complex-template',
'partial-classes-i18n',
'partial-classes-theming',
'properties',
'tasks',
'cypress',
'unit',
],
'all'
),
})
.argsDesc({
subset: 'The subset for which to collect coverage',
})
.run(async (exec, { subset }) => {
await exec('? clearing previous coverage');
await exec('rimraf ./.nyc_output');
if (subset === 'unit' || subset == 'all') {
await exec(
'? generating CJS lit-html bundle at test/modules/lit-html.js'
);
await exec(
'rollup node_modules/lit-html/lit-html.js --file test/modules/lit-html.js --format cjs --banner "var window = {}"'
);
} else {
const cypressSubset = subset === 'cypress' ? 'all' : subset;
await exec(`? setting cypress selection to ${cypressSubset}`);
await exec(`@_set-cypress --selection ${cypressSubset}`);
}
await exec('? compiling TS');
await exec('@compile --dir all');
await exec('? copying maps and ignoring typescript for coverage');
await exec('gulp precoverage');
await exec('? instrumenting code');
await exec(
'nyc instrument build/es/ instrumented/',
'nyc instrument build/cjs/ instrumented-cjs/'
);
await exec('? rerouting imports to instrumented code');
await exec('gulp replaceTestImports');
if (subset !== 'unit') {
await exec('? running cypress test');
await exec(`nyc --no-clean --reporter=text npm run cypress`);
}
if (subset === 'unit' || subset === 'all') {
await exec('? running unit test');
await exec(`nyc --no-clean --reporter=text npm run ava`);
}
await exec('? filtering out invalid paths');
await exec('gulp filterInstrumented');
await exec('? compiling to sourcemaps');
await exec('yarn tsc -p src/tsconfig.sourcemap.json');
await exec('? joining coverages');
await exec('nyc merge .nyc_output .nyc_output/joined.json');
await exec('? mapping coverage to sourcemaps');
await exec(
'remap-istanbul -i .nyc_output/joined.json -t html -o coverage/',
'remap-istanbul -i .nyc_output/joined.json -t lcovonly -o coverage/lcov.info'
);
await exec('? Done! Coverage can be found in coverage/index.html');
});
cmd('prepack')
.desc('Command to run before packaging, builds and runs prepack commands')
.run(
'? cleaning',
'@clean',
'? compiling TS',
'@compile --dir all',
'? removing flags',
'gulp prepack',
'? creating bundle',
'rollup build/es/wc-lib.js --file build/wc-lib.bundle.js --format umd --name "wc-lib"',
'? minifiying',
'uglifyjs build/wc-lib.bundle.js -o build/wc-lib.bundle.min.js'
);