-
Notifications
You must be signed in to change notification settings - Fork 578
/
gulpfile.js
814 lines (672 loc) · 29 KB
/
gulpfile.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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
const fs = require("fs");
const os = require("os");
const path = require("path");
const gulp = require("gulp");
const ts = require("gulp-typescript");
const merge = require("merge-stream");
const concat = require("gulp-concat");
const header = require("gulp-header");
const replace = require("gulp-replace");
const ju = require("./jakeutil");
const exec = ju.exec;
const rimraf = ju.rimraf;
const isWin32 = os.platform() === "win32";
const clean = () => rimraf("built").then(() => rimraf("temp"));
const update = () => exec("git pull", true).then(() => exec("npm install", true))
const noop = () => Promise.resolve();
const SUB_WEBAPPS = require("./cli/webapps-config.json").webapps;
/** onlineline */
const onlinelearning = () => {
const tasks = ["schedule", "projects"].map(fn =>
() => exec(`node node_modules/typescript/bin/tsc ./docs/static/online-learning/${fn}.ts`)
);
gulp.watch("./docs/static/online-learning/*.ts", gulp.series(...tasks));
};
/********************************************************
TypeScript build
*********************************************************/
const copyTypescriptServices = () => gulp.src("pxtcompiler/ext-typescript/lib/typescriptServices.d.ts")
.pipe(gulp.dest("built"));
const pxtlib = () => compileTsProject("pxtlib");
const pxtcompiler = () => compileTsProject("pxtcompiler");
const pxtpy = () => compileTsProject("pxtpy");
const pxtsim = () => compileTsProject("pxtsim");
const pxtrunner = () => compileTsProject("pxtrunner", "built", true);
const pxteditor = () => compileTsProject("pxteditor", "built", true);
const pxtweb = () => compileTsProject("docfiles/pxtweb", "built/web");
const backendutils = () => compileTsProject("backendutils")
const cli = () => compileTsProject("cli", "built", true);
const webapp = () => compileTsProject("webapp", "built", true);
const reactCommon = () => compileTsProject("react-common", "built/react-common", true);
const pxtblocks = () => compileTsProject("pxtblocks", "built/pxtblocks", true);
const pxtservices = () => compileTsProject("pxtservices", "built/pxtservices", true);
const pxtapp = () => gulp.src([
"node_modules/lzma/src/lzma_worker-min.js",
"node_modules/dompurify/dist/purify.min.js",
"built/pxtlib.js",
"built/pxtsim.js"
])
.pipe(concat("pxtapp.js"))
.pipe(gulp.dest("built/web"));
const pxtworker = () => gulp.src([
"pxtcompiler/ext-typescript/lib/typescript.js",
"node_modules/fuse.js/dist/fuse.min.js",
"node_modules/lzma/src/lzma_worker-min.js",
"node_modules/dompurify/dist/purify.min.js",
"built/pxtlib.js",
"built/pxtcompiler.js",
"built/pxtpy.js"
])
.pipe(concat("pxtworker.js"))
.pipe(header(`"use strict";\n`))
.pipe(gulp.dest("built/web"));
const pxtembed = () => gulp.src([
"pxtcompiler/ext-typescript/lib/typescript.js",
"node_modules/lzma/src/lzma_worker-min.js",
"node_modules/dompurify/dist/purify.min.js",
"built/pxtlib.js",
"built/pxtcompiler.js",
"built/pxtpy.js",
"built/pxtsim.js",
"built/web/runnerembed.js"
])
.pipe(concat("pxtembed.js"))
.pipe(gulp.dest("built/web"));
const buildpxtjs = () => gulp.src([
"pxtcompiler/ext-typescript/lib/typescript.js",
"built/pxtlib.js",
"built/pxtcompiler.js",
"built/pxtpy.js",
"built/pxtsim.js",
"built/cli.js"
])
.pipe(concat("pxt.js"))
.pipe(header(`
"use strict";
// make sure TypeScript doesn't overwrite our module.exports
global.savedModuleExports = module.exports;
module.exports = null;
`))
.pipe(gulp.dest("built"));
const copySubappsConfig = () => gulp.src("cli/webapps-config.json")
.pipe(gulp.dest("built"));
const pxtjs = gulp.parallel(buildpxtjs, copySubappsConfig);
const pxtdts = () => gulp.src("built/cli.d.ts")
.pipe(concat("pxt.d.ts"))
.pipe(gulp.dest("built"));
function initWatch() {
gulp.watch("./docfiles/pxtweb/**/*", pxtweb);
const tasks = [
pxtlib,
gulp.parallel(pxtcompiler, pxtsim, backendutils),
pxtpy,
gulp.parallel(pxtblocks, pxteditor, pxtservices),
gulp.parallel(pxtrunner, cli, pxtcommon),
gulp.parallel(updatestrings, browserifyEmbed),
gulp.parallel(pxtjs, pxtdts, pxtapp, pxtworker, pxtembed),
targetjs,
reactCommon,
webapp,
browserifyWebapp,
browserifyAssetEditor,
gulp.parallel(semanticjs, copyJquery, copyWebapp, copySemanticFonts, copyMonaco),
notifyBuildComplete
];
gulp.watch("./pxtlib/**/*", gulp.series(...tasks));
gulp.watch("./pxtcompiler/**/*", gulp.series(pxtcompiler, ...tasks.slice(2)));
gulp.watch("./pxtsim/**/*", gulp.series(pxtsim, ...tasks.slice(2)));
gulp.watch("./backendutils/**/*", gulp.series(backendutils, ...tasks.slice(2)));
gulp.watch("./pxtpy/**/*", gulp.series(pxtpy, ...tasks.slice(3)));
gulp.watch("./pxtblocks/**/*", gulp.series(pxtblocks, ...tasks.slice(4)));
gulp.watch("./pxtservices/**/*", gulp.series(pxtservices, ...tasks.slice(4)));
gulp.watch("./pxteditor/**/*", gulp.series(pxteditor, ...tasks.slice(4)));
gulp.watch("./pxtrunner/**/*", gulp.series(pxtrunner, ...tasks.slice(5)));
gulp.watch("./cli/**/*", gulp.series(cli, ...tasks.slice(5)));
gulp.watch("./react-common/styles/**/*.css", gulp.series(buildcss, ...tasks.slice(9)))
gulp.watch("./react-common/**/*", gulp.series(reactCommon, ...tasks.slice(10)))
gulp.watch("./webapp/src/**/*", gulp.series(updatestrings, webapp, browserifyWebapp, browserifyAssetEditor, notifyBuildComplete));
gulp.watch(["./theme/**/*.less", "./theme/**/*.overrides", "./theme/**/*.variables", "./svgicons/**/*.svg"], gulp.series(gulp.parallel(buildcss, buildSVGIcons), notifyBuildComplete))
gulp.series(buildAll, notifyBuildComplete)();
}
function initWatchCli() {
const tasks = [
pxtlib,
gulp.parallel(pxtcompiler),
pxtpy,
cli,
notifyBuildComplete
]
gulp.watch("./pxtlib/**/*", gulp.series(...tasks));
gulp.watch("./pxtcompiler/**/*", gulp.series(pxtcompiler, ...tasks.slice(2)));
gulp.watch("./pxtpy/**/*", gulp.series(pxtpy, ...tasks.slice(3)));
gulp.watch("./cli/**/*", gulp.series(cli, ...tasks.slice(5)));
}
const targetjs = () => exec("node built/pxt.js buildtarget", true);
const buildcss = () => exec("node built/pxt.js buildcss", true);
const pxtTravis = () => exec("node built/pxt.js travis", true);
function compileTsProject(dirname, destination, useOutdir, filename) {
if (!destination) destination = "built";
let opts = useOutdir ? {
outDir: path.resolve(destination)
} : {
outFile: path.resolve(destination, path.basename(filename || dirname) + ".js")
};
let configPath = path.join(dirname, "tsconfig.json");
let tsProject = ts.createProject(configPath, opts);
let tsResult = tsProject.src()
.pipe(tsProject());
return merge(
tsResult.js.pipe(gulp.dest(destination)),
tsResult.dts.pipe(gulp.dest(destination))
);
}
// TODO: Copied from Jakefile; should be async
function pxtcommon() {
const std = {}
const files = ju.expand(['libs/pxt-common', 'libs/pxt-python'], ".ts")
for (let f of files) {
std[path.basename(f)] = fs.readFileSync(f, "utf8")
}
fs.writeFileSync("built/pxt-common.json", JSON.stringify(std, null, 4))
return Promise.resolve();
}
function notifyBuildComplete() {
console.log("-- Build Complete --");
return Promise.resolve();
}
// TODO: Copied from Jakefile; should be async
function updatestrings() {
return buildStrings("built/strings.json", [
"cli",
"pxtblocks",
"pxtservices",
"pxtcompiler",
"pxteditor",
"pxtlib",
"pxtpy",
"pxtsim",
"webapp/src",
], true);
}
function updateWebappStrings(name) {
return buildStrings(`built/${name}-strings.json`, [`${name}/src`], true);
}
// TODO: Copied from Jakefile; should be async
function buildStrings(out, rootPaths, recursive) {
let errCnt = 0;
const translationStrings = {}
const translationHelpStrings = {}
function processLf(filename) {
if (!/\.(ts|tsx|html)$/.test(filename)) return
if (/\.d\.ts$/.test(filename)) return
// console.log(`extracting strings from ${filename}`);
fs.readFileSync(filename, "utf8").split('\n').forEach((line, idx) => {
function err(msg) {
console.log("%s(%d): %s", filename, idx + 1, msg);
errCnt++;
}
if (/@ignorelf@/.test(line))
return;
while (true) {
let newLine = line.replace(/\blf(_va)?\s*\(\s*(.*)/, (all, a, args) => {
let m = /^("([^"]|(\\"))+")\s*[\),]/.exec(args)
if (m) {
try {
let str = JSON.parse(m[1])
translationStrings[str] = 1
} catch (e) {
err("cannot JSON-parse " + m[1])
}
} else {
err("invalid format of lf() argument: " + args) // @ignorelf@
}
return "BLAH " + args
})
if (newLine == line) return;
line = newLine
}
})
}
let fileCnt = 0;
const paths = recursive ? ju.expand(rootPaths) : ju.expand1(rootPaths);
paths.forEach(pth => {
fileCnt++;
processLf(pth);
});
Object.keys(translationHelpStrings).forEach(k => translationStrings[k] = k)
let tr = Object.keys(translationStrings)
tr.sort()
if (!fs.existsSync("built")) fs.mkdirSync("built");
fs.writeFileSync("built/localization.json", JSON.stringify({ strings: tr }, null, 1))
let strings = {};
tr.forEach((k) => { strings[k] = k; });
fs.writeFileSync(out, JSON.stringify(strings, null, 2));
console.log("Localization extraction: " + fileCnt + " files; " + tr.length + " strings; " + out);
if (errCnt > 0) {
console.log("%d errors", errCnt);
if (process.env.PXT_ENV == 'production') {
throw "Broken lfs";
}
}
return Promise.resolve();
}
function runUglify() {
if (process.env.PXT_ENV == 'production') {
console.log("Minifying built/web...")
const terser = require("terser");
const files = ju.expand("built/web", ".js");
return Promise.all(files.map(fn => {
console.log(`Minifying ${fn}`)
return Promise.resolve()
.then(() => fs.readFileSync(fn, "utf-8"))
.then(content => terser.minify(content))
.then(
res => {
fs.writeFileSync(fn, res.code, { encoding: "utf8" })
console.log(`Finished minifying ${fn}`);
},
err => {
console.log(`Could not minify ${fn}: ${err}`);
throw err;
}
);
}))
}
else {
console.log("Skipping minification for non-production build")
}
return Promise.resolve();
}
/********************************************************
Webapp dependencies
*********************************************************/
const semanticjs = () => gulp.src(ju.expand([
"node_modules/semantic-ui-less/definitions/globals",
"node_modules/semantic-ui-less/definitions/modules/accordion.js",
"node_modules/semantic-ui-less/definitions/modules/checkbox.js",
"node_modules/semantic-ui-less/definitions/modules/dimmer.js",
"node_modules/semantic-ui-less/definitions/modules/dropdown.js",
"node_modules/semantic-ui-less/definitions/modules/embed.js",
"node_modules/semantic-ui-less/definitions/modules/modal.js",
"node_modules/semantic-ui-less/definitions/modules/popup.js",
"node_modules/semantic-ui-less/definitions/modules/search.js",
"node_modules/semantic-ui-less/definitions/modules/sidebar.js",
"node_modules/semantic-ui-less/definitions/modules/transition.js",
"node_modules/semantic-ui-less/definitions/behaviors"],
".js"))
.pipe(concat("semantic.js"))
.pipe(gulp.dest("built/web"));
const copyJquery = () => gulp.src("node_modules/jquery/dist/jquery.min.js")
.pipe(concat("jquery.js"))
.pipe(gulp.dest("built/web"));
const copyWebapp = () =>
gulp.src([
"node_modules/@microsoft/applicationinsights-web/browser/ai.2.min.js",
"pxtcompiler/ext-typescript/lib/typescript.js",
"built/pxtlib.js",
"built/pxtcompiler.js",
"built/pxtpy.js",
"built/pxtsim.js",
"built/webapp/src/worker.js",
"built/webapp/src/serviceworker.js",
"built/webapp/src/simulatorserviceworker.js",
"built/webapp/src/tsworker.js",
])
.pipe(gulp.dest("built/web"));
const copySemanticFonts = () => gulp.src("node_modules/semantic-ui-less/themes/default/assets/fonts/*")
.pipe(gulp.dest("built/web/fonts"))
const execBrowserify = (entryPoint, outfile) => process.env.PXT_ENV == 'production' ?
exec(`node node_modules/browserify/bin/cmd ${entryPoint} -g [ envify --NODE_ENV production ] -g [ uglifyify --ignore '**/node_modules/@blockly/**' ] -o ${outfile}`) :
exec(`node node_modules/browserify/bin/cmd ${entryPoint} -o ${outfile} --debug`);
const browserifyWebapp = () => execBrowserify("./built/webapp/src/app.js", "./built/web/main.js");
const browserifyAssetEditor = () => execBrowserify("./built/webapp/src/assetEditor.js", "./built/web/pxtasseteditor.js");
const browserifyEmbed = () => execBrowserify("./built/pxtrunner/embed.js", "./built/web/runnerembed.js");
const buildSVGIcons = () => {
let webfontsGenerator = require('@vusion/webfonts-generator')
let name = "xicon"
return new Promise((resolve, reject) => {
webfontsGenerator({
fontName: name,
files: ju.expand(["svgicons"], ".svg"),
dest: "built/fonts/", // fake
templateOptions: {
classPrefix: name + ".",
baseClass: name
},
// The following icons have fixed code points because they are referenced in the code
codepoints: {
function: 0xf109,
bucket: 0xf102,
undo: 0xf118,
redo: 0xf111,
rectangularselection: 0xf113
},
writeFiles: false,
}, function (error, res) {
if (error) {
reject(error)
} else {
let css = res.generateCss()
let data = res["woff"].toString("base64")
css = css.replace(/^\s*src:[^;]+;/m,
" src: url(data:application/x-font-woff;charset=utf-8;base64," + data + ") format(\"woff\");")
css = css.replace(/line-height:\s*1;/, "")
// SUI css file would override our icons without !important;
// our icons have xicon class so it never happens the other way around
css = css.replace(/(content:.*);/g, (f, m) => m + " !important;")
console.log("Generated icons.css -", css.length, "bytes")
let html = "<!doctype html>\n<html><body style='font-size: 30px'><style>@import './icons.css';</style>\n"
css.replace(/\.(\w+):before /g, (f, n) => {
html += `<div style="margin:20px;"> <i class="${name} ${n}"></i> <span style='padding-left:1em; font-size:0.8em; opacity:0.5;'>${n}</span> </div>\n`
})
html += "</body></html>\n"
fs.writeFileSync("built/web/icons.html", html)
fs.writeFileSync("built/web/icons.css", css)
resolve();
}
})
})
}
const copyBlocklyMedia = () =>
gulp.src("node_modules/blockly/media/*")
.pipe(gulp.dest("webapp/public/blockly/media"))
/********************************************************
Monaco editor
*********************************************************/
const copyMonacoBase = () => gulp.src([
"node_modules/monaco-editor/min/vs/base/**/*",
"!**/codicon.ttf" // We use a different version of this font that's checked into pxt (see inlineCodiconFont)
])
.pipe(gulp.dest("webapp/public/vs/base"));
const copyMonacoEditor = () => gulp.src([
"node_modules/monaco-editor/min/vs/editor/**/*",
"!**/editor.main.js"
])
.pipe(gulp.dest("webapp/public/vs/editor"));
const copyMonacoLoader = () => gulp.src("node_modules/monaco-editor/min/vs/loader.js")
.pipe(gulp.dest("webapp/public/vs"));
const basicLanguages = ["bat", "cpp", "markdown", "python", "typescript", "javascript"];
const allLanguages = ["json", ...basicLanguages]
const copyMonacoEditorMain = () => gulp.src("node_modules/monaco-editor/min/vs/editor/editor.main.js")
.pipe(replace(/"\.\/([\w-]+)\/\1\.contribution"(?:,)?\s*/gi, (match, lang) => {
if (allLanguages.indexOf(lang) === -1) {
return ""
}
return match;
}))
.pipe(gulp.dest("built/web/vs/editor/"));
const copyMonacoBasicLanguages = gulp.parallel(basicLanguages.map(lang => {
return () => gulp.src(`node_modules/monaco-editor/min/vs/basic-languages/${lang}/${lang}.js`)
.pipe(gulp.dest(`webapp/public/vs/basic-languages/${lang}`))
}));
const copyMonacoJSON = () => gulp.src("node_modules/monaco-editor/min/vs/language/json/**/*")
.pipe(gulp.dest("webapp/public/vs/language/json"));
const copyMonacoTypescript = () => gulp.src("node_modules/monaco-editor/min/vs/language/typescript/**/*")
.pipe(gulp.dest("webapp/public/vs/language/typescript"));
const inlineCodiconFont = () => {
// For whatever reason the codicon.ttf font that comes with the monaco-editor is invalid.
// We need to inline the font anyways so fetch a good version of the font from the source
// This good version comes from: https://github.com/microsoft/vscode-codicons/blob/main/dist/codicon.ttf
let font = fs.readFileSync("theme/external-font/codicon.ttf").toString("base64");
return gulp.src("node_modules/monaco-editor/min/vs/editor/editor.main.css")
.pipe(replace(`../base/browser/ui/codicons/codicon/codicon.ttf`, `data:application/x-font-ttf;charset=utf-8;base64,${font}`))
.pipe(gulp.dest("webapp/public/vs/editor/"))
}
const stripMonacoSourceMaps = () => {
ju.stripSrcMapSync("webapp/public/vs/")
return Promise.resolve();
}
const copyMonaco = gulp.series(
gulp.parallel(
copyMonacoBase,
copyMonacoEditor,
copyMonacoLoader,
copyMonacoEditorMain,
copyMonacoJSON,
copyMonacoBasicLanguages,
copyMonacoTypescript,
),
inlineCodiconFont,
stripMonacoSourceMaps
);
function createWebappTasks(root, outname) {
outname = outname || root;
const outdir = `built/web/${outname}`;
const cleanWebapp = () => rimraf(outdir);
const npmBuildWebapp = () => exec("npm run build", true, { cwd: root });
const buildWebapp = async () => await npmBuildWebapp();
const copyWebappCss = () => gulp.src(`${root}/build/static/css/*`)
.pipe(gulp.dest(`${outdir}/css`));
const copyWebappJs = () => gulp.src(`${root}/build/static/js/*`)
.pipe(gulp.dest(`${outdir}/js`));
const copyWebappHtml = () => rimraf(`webapp/public/${outname}.html`)
.then(() => gulp.src(`${root}/build/index.html`)
.pipe(replace(/="\/static\//g, `="/blb/${outname}/`))
.pipe(concat(`${outname}.html`))
.pipe(gulp.dest("webapp/public")));
const result = gulp.series(cleanWebapp, buildWebapp, gulp.series(copyWebappCss, copyWebappJs, copyWebappHtml));
exports[outname] = result;
return result;
}
/********************************************************
Skillmap
*********************************************************/
const skillmap = createWebappTasks("skillmap");
const buildSkillmapTests = () => compileTsProject("skillmap/tests", "built/tests");
const copySkillmapTests = () => gulp.src([
"./built/pxtlib.js",
"./built/tests/tests/skillmapParser.spec.js"])
.pipe(concat("skillmapParserTests.js"))
.pipe(gulp.dest("built/tests/tests"));
const runSkillmapTests = () => {
let command;
if(isWin32) {
command = path.resolve("node_modules/.bin/mocha.cmd") + " ./built/tests/tests/skillmapParserTests.js";
} else {
command = "./node_modules/.bin/mocha ./built/tests/tests/skillmapParserTests.js";
}
return exec(command, true);
}
const testSkillmap = gulp.series(buildSkillmapTests, copySkillmapTests, runSkillmapTests);
/********************************************************
Authcode
*********************************************************/
const authcode = createWebappTasks("authcode");
/********************************************************
Multiplayer
*********************************************************/
const multiplayer = createWebappTasks("multiplayer");
/********************************************************
Kiosk
*********************************************************/
const kiosk = createWebappTasks("kiosk");
/********************************************************
Teacher Tool
*********************************************************/
const teacherTool = createWebappTasks("teachertool");
/********************************************************
Tutorial Tool
*********************************************************/
const tutorialTool = createWebappTasks("tutorialtool");
/********************************************************
Webapp build wrappers
*********************************************************/
const shouldBuildWebapps = () => (process.argv.indexOf("--no-webapps") === -1 && process.argv.indexOf("-n") === -1);
const maybeUpdateWebappStrings = () => {
if (!shouldBuildWebapps()) return noop;
return gulp.parallel(...SUB_WEBAPPS.map(app => () => updateWebappStrings(app.name)));
};
const maybeBuildWebapps = () => {
if (!shouldBuildWebapps()) return noop;
return gulp.parallel(skillmap, authcode, multiplayer, kiosk, teacherTool, tutorialTool);
}
/********************************************************
Tests and Linting
*********************************************************/
const lintWithEslint = () => Promise.all(
["cli", "pxtblocks", "pxteditor", "pxtlib", "pxtcompiler",
"pxtpy", "pxtrunner", "pxtsim", "webapp", "pxtservices",
"docfiles/pxtweb", "skillmap", "authcode",
"multiplayer"/*, "kiosk"*/, "teachertool", "docs/static/streamer"].map(dirname =>
exec(`node node_modules/eslint/bin/eslint.js -c .eslintrc.js --ext .ts,.tsx ./${dirname}/`, true)))
.then(() => console.log("linted"))
const lint = lintWithEslint
const testdecompiler = testTask("decompile-test", "decompilerunner.js");
const testlang = testTask("compile-test", "compilerunner.js");
const testhelpers = testTask("helpers-test", "helperrunner.js");
const testerr = testTask("errors-test", "errorrunner.js");
const testfmt = testTask("format-test", "formatrunner.js");
const testpydecomp = testTask("pydecompile-test", "pydecompilerunner.js");
const testpycomp = testTask("pyconverter-test", "pyconvertrunner.js");
const testpytraces = testTask("runtime-trace-tests", "tracerunner.js");
const testtutorials = testTask("tutorial-test", "tutorialrunner.js");
const testlanguageservice = testTask("language-service", "languageservicerunner.js");
const testpxteditor = pxtEditorTestTask();
const buildKarmaRunner = () => compileTsProject("tests/blocklycompiler-test", "built/", true);
const browserifyKarma = () =>
exec('node node_modules/browserify/bin/cmd built/tests/blocklycompiler-test/test.spec.js -o built/tests/karma-test-runner.js --debug');
const runKarma = () => {
let command;
if (isWin32) {
command = path.resolve("node_modules/.bin/karma.cmd") + " start karma.conf.js" ;
}
else {
command = "./node_modules/.bin/karma start karma.conf.js ";
if (process.env.GITHUB_ACTIONS)
command = "xvfb-run --auto-servernum " + command;
}
return exec(command, true);
}
const karma = gulp.series(buildKarmaRunner, browserifyKarma, runKarma);
const buildBlocksTestRunner = () => compileTsProject("tests/blocks-test", "built/", true);
const browserifyBlocksTestRunner = () =>
exec('node node_modules/browserify/bin/cmd built/tests/blocks-test/blocksrunner.js -o built/tests/blocksrunner.js --debug');
const browserifyBlocksPrep = () =>
exec('node node_modules/browserify/bin/cmd built/tests/blocks-test/blockssetup.js -o built/tests/blockssetup.js --debug');
const testAll = gulp.series(
testdecompiler,
testlang,
testhelpers,
testerr,
testfmt,
testpydecomp,
testpycomp,
testpytraces,
testtutorials,
testlanguageservice,
karma,
testSkillmap,
testpxteditor
)
function testTask(testFolder, testFile, additionalFiles) {
const buildTs = () => compileTsProject("tests/" + testFolder, "built/tests", true);
const src = [
"pxtcompiler/ext-typescript/lib/typescript.js",
"built/pxtlib.js",
"built/pxtcompiler.js",
"built/pxtpy.js",
"built/pxtsim.js",
]
if (additionalFiles) {
src.push(...additionalFiles);
}
src.push("built/tests/" + testFolder + "/" + testFile,)
const buildTestRunner = () => gulp.src(src)
.pipe(concat("runner.js"))
.pipe(header(`
"use strict";
// make sure TypeScript doesn't overwrite our module.exports
global.savedModuleExports = module.exports;
module.exports = null;
`))
.pipe(gulp.dest('built/tests/' + testFolder));
const testArgs = " built/tests/" + testFolder + "/runner.js --reporter dot";
const runTest = () => exec(getMochaExecutable() + testArgs, true);
return gulp.series(buildTs, buildTestRunner, runTest);
}
function pxtEditorTestTask() {
const buildTs = () => compileTsProject("tests/pxt-editor-test", "built", true);
const browserifyTs = () => exec('node node_modules/browserify/bin/cmd built/tests/pxt-editor-test/editorrunner.js -o built/tests/pxt-editor-test/bundled.js --debug');
const buildRunner = () => gulp.src(["built/pxtlib.js", "built/tests/pxt-editor-test/bundled.js"]).pipe(concat("runner.js")).pipe(gulp.dest("built/tests/pxt-editor-test/"));
const runTests = () => exec(`${getMochaExecutable()} built/tests/pxt-editor-test/runner.js --reporter dot`, true)
return gulp.series([buildTs, browserifyTs, buildRunner, runTests]);
}
function getMochaExecutable() {
return isWin32 ? path.resolve("node_modules/.bin/mocha.cmd") : "./node_modules/.bin/mocha";
}
const buildAll = gulp.series(
updatestrings,
maybeUpdateWebappStrings(),
gulp.parallel(copyTypescriptServices, copyBlocklyMedia),
gulp.parallel(pxtlib, pxtweb),
gulp.parallel(pxtcompiler, pxtsim, backendutils),
pxtpy,
gulp.parallel(pxteditor, pxtblocks, pxtservices),
gulp.parallel(pxtrunner, cli, pxtcommon),
browserifyEmbed,
gulp.parallel(pxtjs, pxtdts, pxtapp, pxtworker, pxtembed),
targetjs,
reactCommon,
gulp.parallel(buildcss, buildSVGIcons),
maybeBuildWebapps(),
webapp,
browserifyWebapp,
browserifyAssetEditor,
gulp.parallel(semanticjs, copyJquery, copyWebapp, copySemanticFonts, copyMonaco),
buildBlocksTestRunner,
gulp.parallel(browserifyBlocksTestRunner, browserifyBlocksPrep),
runUglify
);
const travis = gulp.series(lint, buildAll, testAll, targetjs, pxtTravis);
exports.default = buildAll;
exports.clean = clean;
exports.build = buildAll;
exports.webapp = gulp.series(
gulp.parallel(reactCommon, pxtblocks, pxteditor, pxtservices),
webapp,
browserifyWebapp,
browserifyAssetEditor
)
exports.pxtrunner = gulp.series(
gulp.parallel(reactCommon, pxtblocks, pxteditor, pxtservices),
pxtrunner,
browserifyEmbed,
pxtembed,
);
exports.skillmapTest = testSkillmap;
exports.updatestrings = updatestrings;
exports.lint = lint
exports.testdecompiler = testdecompiler;
exports.testlang = testlang;
exports.testerr = testerr;
exports.testfmt = testfmt;
exports.testpydecomp = testpydecomp;
exports.testpycomp = testpycomp;
exports.testpytraces = testpytraces;
exports.testtutorials = testtutorials;
exports.test = testAll;
exports.travis = travis;
exports.karma = karma;
exports.update = update;
exports.uglify = runUglify;
exports.watch = initWatch;
exports.watchCli = initWatchCli;
exports.testlanguageservice = testlanguageservice;
exports.onlinelearning = onlinelearning;
exports.tt = teacherTool;
exports.icons = buildSVGIcons;
exports.testhelpers = testhelpers;
exports.testpxteditor = testpxteditor;
exports.reactCommon = reactCommon;
exports.cli = gulp.series(
gulp.parallel(pxtlib, pxtweb),
gulp.parallel(pxtcompiler, pxtsim, backendutils),
pxtpy,
pxteditor,
gulp.parallel(pxtrunner, cli, pxtcommon),
pxtjs
);
console.log(`pxt build how to:`)
console.log(`run "gulp watch" in pxt folder`)
console.log(`run "pxt serve" in target folder in new command prompt`)
console.log();