@intelligentgraphics/ig.gfx.packager 3.0.19 → 3.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bin.mjs +1 -1
- package/build/{cli-4b4eb819.mjs → cli-91fabb36.mjs} +22 -8
- package/build/cli-91fabb36.mjs.map +1 -0
- package/build/{dependencies-7b889e67.mjs → dependencies-7711a9db.mjs} +2 -2
- package/build/{dependencies-7b889e67.mjs.map → dependencies-7711a9db.mjs.map} +1 -1
- package/build/{generateIndex-1c76f3b7.mjs → generateIndex-47c082d0.mjs} +2 -2
- package/build/{generateIndex-1c76f3b7.mjs.map → generateIndex-47c082d0.mjs.map} +1 -1
- package/build/{generateParameterType-ecd8f4b2.mjs → generateParameterType-10d124a6.mjs} +2 -2
- package/build/{generateParameterType-ecd8f4b2.mjs.map → generateParameterType-10d124a6.mjs.map} +1 -1
- package/build/{index-4dd728d6.mjs → index-ca04836f.mjs} +25 -6
- package/build/index-ca04836f.mjs.map +1 -0
- package/build/index-e6ead55c.mjs +1120 -0
- package/build/index-e6ead55c.mjs.map +1 -0
- package/build/{postinstall-dce685cf.mjs → postinstall-0ea76778.mjs} +3 -3
- package/build/{postinstall-dce685cf.mjs.map → postinstall-0ea76778.mjs.map} +1 -1
- package/build/{publishNpm-0bfe5bda.mjs → publishNpm-aadd7dc2.mjs} +33 -5
- package/build/publishNpm-aadd7dc2.mjs.map +1 -0
- package/build/{versionFile-041c0e79.mjs → versionFile-ad981e93.mjs} +2 -2
- package/build/{versionFile-041c0e79.mjs.map → versionFile-ad981e93.mjs.map} +1 -1
- package/lib/lib.mjs +576 -146
- package/package.json +3 -2
- package/readme.md +9 -0
- package/build/cli-4b4eb819.mjs.map +0 -1
- package/build/index-14f27618.mjs +0 -706
- package/build/index-14f27618.mjs.map +0 -1
- package/build/index-4dd728d6.mjs.map +0 -1
- package/build/publishNpm-0bfe5bda.mjs.map +0 -1
package/lib/lib.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
|
+
import * as fs$1 from 'fs/promises';
|
|
3
|
+
import * as terser from 'terser';
|
|
2
4
|
import * as fs from 'fs';
|
|
3
5
|
import { createWriteStream, createReadStream } from 'fs';
|
|
4
|
-
import * as terser from 'terser';
|
|
5
6
|
import resolve from 'resolve';
|
|
6
7
|
import 'write-pkg';
|
|
7
8
|
import glob from 'glob';
|
|
@@ -9,8 +10,9 @@ import 'write-json-file';
|
|
|
9
10
|
import axios from 'axios';
|
|
10
11
|
import ts from 'typescript';
|
|
11
12
|
import typedoc from 'typedoc';
|
|
13
|
+
import EventEmitter from 'events';
|
|
14
|
+
import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
|
|
12
15
|
import Ajv from 'ajv';
|
|
13
|
-
import * as fs$1 from 'fs/promises';
|
|
14
16
|
import { pipeline } from 'stream/promises';
|
|
15
17
|
import { exec } from 'child_process';
|
|
16
18
|
import { promisify } from 'util';
|
|
@@ -263,10 +265,10 @@ const readStringFromFileOrUndefined = (filePath)=>{
|
|
|
263
265
|
}
|
|
264
266
|
};
|
|
265
267
|
|
|
266
|
-
const logPackageMessage = (name, step, index, total)=>{
|
|
268
|
+
const logPackageMessage = (name, step, index, total, maxNameLength = 15)=>{
|
|
267
269
|
const numLength = total === undefined ? undefined : total.toString().length;
|
|
268
270
|
const indexString = total === undefined || total < 2 ? "" : `${index.toString().padStart(numLength, "0")}/${total} `;
|
|
269
|
-
const identifierString = `${indexString}${name.padEnd(
|
|
271
|
+
const identifierString = `${indexString}${name.padEnd(maxNameLength)}`;
|
|
270
272
|
console.log(`${identifierString} >> ${step}`);
|
|
271
273
|
};
|
|
272
274
|
|
|
@@ -377,7 +379,186 @@ const tryReadTsConfig = (location)=>{
|
|
|
377
379
|
});
|
|
378
380
|
return config;
|
|
379
381
|
};
|
|
380
|
-
const
|
|
382
|
+
const createTSCBuildParticipant = (location, outputDir)=>(env)=>{
|
|
383
|
+
const files = getPackageTypescriptFiles(location);
|
|
384
|
+
if (files.length === 0) {
|
|
385
|
+
env.onBuildStart();
|
|
386
|
+
env.onBuildEnd({
|
|
387
|
+
type: "success",
|
|
388
|
+
artefacts: {
|
|
389
|
+
js: "",
|
|
390
|
+
definitions: ""
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
return {
|
|
394
|
+
destroy: ()=>{}
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
try {
|
|
398
|
+
env.onBuildStart();
|
|
399
|
+
const compilerOptions = getCompilerOptions(location, outputDir);
|
|
400
|
+
const host = ts.createCompilerHost(compilerOptions);
|
|
401
|
+
host.getCurrentDirectory = ()=>location.scriptsDir;
|
|
402
|
+
let js;
|
|
403
|
+
let definitions;
|
|
404
|
+
let sourceMap;
|
|
405
|
+
host.writeFile = (fileName, data, writeByteOrderMark)=>{
|
|
406
|
+
if (fileName.endsWith(".js")) {
|
|
407
|
+
js = data;
|
|
408
|
+
} else if (fileName.endsWith(".d.ts")) {
|
|
409
|
+
definitions = data;
|
|
410
|
+
} else if (fileName.endsWith(".js.map")) {
|
|
411
|
+
sourceMap = data;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
const programOptions = {
|
|
415
|
+
rootNames: files,
|
|
416
|
+
options: compilerOptions,
|
|
417
|
+
host
|
|
418
|
+
};
|
|
419
|
+
const program = ts.createProgram(programOptions);
|
|
420
|
+
const emitResult = program.emit();
|
|
421
|
+
const allDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
422
|
+
if (!emitResult.emitSkipped) {
|
|
423
|
+
if (allDiagnostics.length > 0) {
|
|
424
|
+
console.log(allDiagnostics.map(createErrorMessage).join("\n"));
|
|
425
|
+
}
|
|
426
|
+
if (js === undefined || definitions === undefined) {
|
|
427
|
+
throw new Error(`Unexpected: no js or definitions were created`);
|
|
428
|
+
}
|
|
429
|
+
env.onBuildEnd({
|
|
430
|
+
type: "success",
|
|
431
|
+
artefacts: {
|
|
432
|
+
js: js.replace(`//# sourceMappingURL=out.js.map`, ""),
|
|
433
|
+
definitions,
|
|
434
|
+
sourceMap
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
} else {
|
|
438
|
+
const error = allDiagnostics.map(createErrorMessage).join("\n");
|
|
439
|
+
throw new Error(error);
|
|
440
|
+
}
|
|
441
|
+
} catch (err) {
|
|
442
|
+
env.onBuildEnd({
|
|
443
|
+
type: "error",
|
|
444
|
+
error: err.message
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
destroy: ()=>{}
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
const createTSCWatchBuildParticipant = (location, outputDir)=>{
|
|
452
|
+
return ({ onBuildStart , onBuildEnd })=>{
|
|
453
|
+
let state = {
|
|
454
|
+
diagnostics: [],
|
|
455
|
+
js: undefined,
|
|
456
|
+
definitions: undefined,
|
|
457
|
+
sourceMap: undefined
|
|
458
|
+
};
|
|
459
|
+
const customSys = {
|
|
460
|
+
...ts.sys,
|
|
461
|
+
writeFile: (fileName, data, writeByteOrderMark)=>{
|
|
462
|
+
if (fileName.endsWith(".js")) {
|
|
463
|
+
state.js = data;
|
|
464
|
+
} else if (fileName.endsWith(".d.ts")) {
|
|
465
|
+
state.definitions = data;
|
|
466
|
+
} else if (fileName.endsWith(".js.map")) {
|
|
467
|
+
state.sourceMap = data;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
const reportDiagnostic = (diagnostic)=>{
|
|
472
|
+
switch(diagnostic.code){
|
|
473
|
+
// file not found - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4640
|
|
474
|
+
// probably deleted -> ignore
|
|
475
|
+
case 6053:
|
|
476
|
+
return;
|
|
477
|
+
// no inputs were found - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L6838
|
|
478
|
+
// we don't care about this error. a user might have temporarily deleted the last ts file and will readd one later.
|
|
479
|
+
case 18003:
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
state.diagnostics.push(diagnostic);
|
|
483
|
+
};
|
|
484
|
+
const reportWatchStatusChanged = (diagnostic)=>{
|
|
485
|
+
switch(diagnostic.code){
|
|
486
|
+
// regular watch mode - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4567
|
|
487
|
+
case 6031:
|
|
488
|
+
// incremental watch mode - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4571
|
|
489
|
+
case 6032:
|
|
490
|
+
// build start
|
|
491
|
+
onBuildStart();
|
|
492
|
+
break;
|
|
493
|
+
// found one error - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L5119
|
|
494
|
+
case 6193:
|
|
495
|
+
// found n or 0 errors - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L5123
|
|
496
|
+
case 6194:
|
|
497
|
+
// build end
|
|
498
|
+
const emitState = state;
|
|
499
|
+
state = {
|
|
500
|
+
diagnostics: [],
|
|
501
|
+
js: undefined,
|
|
502
|
+
definitions: undefined,
|
|
503
|
+
sourceMap: undefined
|
|
504
|
+
};
|
|
505
|
+
if (emitState.diagnostics.length > 0) {
|
|
506
|
+
const message = emitState.diagnostics.map(createErrorMessage).join("\n");
|
|
507
|
+
onBuildEnd({
|
|
508
|
+
type: "error",
|
|
509
|
+
error: message
|
|
510
|
+
});
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (emitState.js === undefined || emitState.definitions === undefined) {
|
|
514
|
+
onBuildEnd({
|
|
515
|
+
type: "success",
|
|
516
|
+
artefacts: {
|
|
517
|
+
js: ""
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
onBuildEnd({
|
|
523
|
+
type: "success",
|
|
524
|
+
artefacts: {
|
|
525
|
+
js: emitState.js.replace(`//# sourceMappingURL=out.js.map`, ""),
|
|
526
|
+
definitions: emitState.definitions,
|
|
527
|
+
sourceMap: emitState.sourceMap
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
break;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
const host = ts.createWatchCompilerHost(path.join(location.scriptsDir, "tsconfig.json"), getCompilerOptions(location, outputDir), customSys, ts.createSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportWatchStatusChanged);
|
|
534
|
+
const watchProgram = ts.createWatchProgram(host);
|
|
535
|
+
const files = getPackageTypescriptFiles(location);
|
|
536
|
+
if (files.length === 0) {
|
|
537
|
+
onBuildStart();
|
|
538
|
+
onBuildEnd({
|
|
539
|
+
type: "success",
|
|
540
|
+
artefacts: {
|
|
541
|
+
js: "",
|
|
542
|
+
definitions: ""
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
return {
|
|
547
|
+
destroy: ()=>{
|
|
548
|
+
watchProgram.close();
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
const createErrorMessage = (diagnostic)=>{
|
|
554
|
+
if (!diagnostic.file) {
|
|
555
|
+
return `${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`;
|
|
556
|
+
}
|
|
557
|
+
const { line , character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
558
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
559
|
+
return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`;
|
|
560
|
+
};
|
|
561
|
+
const getCompilerOptions = (location, outputDir)=>{
|
|
381
562
|
const config = tryReadTsConfig(location);
|
|
382
563
|
config.compilerOptions.lib = [
|
|
383
564
|
"es5",
|
|
@@ -388,58 +569,15 @@ const build = async (location, outputDir)=>{
|
|
|
388
569
|
...result.options,
|
|
389
570
|
removeComments: false,
|
|
390
571
|
declaration: true,
|
|
391
|
-
sourceMap:
|
|
572
|
+
sourceMap: true,
|
|
573
|
+
inlineSources: false,
|
|
392
574
|
// We don't use tsc to actually emit the files, but we still need to set the correct
|
|
393
575
|
// output directory so the compiler can rewrite the `reference path` directives.
|
|
394
576
|
outFile: path.join(outputDir, "out.js"),
|
|
395
577
|
target: ts.ScriptTarget.ES5,
|
|
396
578
|
noEmitOnError: true
|
|
397
579
|
};
|
|
398
|
-
|
|
399
|
-
host.getCurrentDirectory = ()=>location.scriptsDir;
|
|
400
|
-
let js;
|
|
401
|
-
let definitions;
|
|
402
|
-
host.writeFile = (fileName, data, writeByteOrderMark)=>{
|
|
403
|
-
if (fileName.endsWith(".js")) {
|
|
404
|
-
js = data;
|
|
405
|
-
} else if (fileName.endsWith(".d.ts")) {
|
|
406
|
-
definitions = data;
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
const files = getPackageTypescriptFiles(location);
|
|
410
|
-
if (files.length === 0) {
|
|
411
|
-
throw new Error(`Expected typescript files to exist when building a package. Packages only consisting of animation jsons do not need to be built.`);
|
|
412
|
-
}
|
|
413
|
-
const programOptions = {
|
|
414
|
-
rootNames: files,
|
|
415
|
-
options: compilerOptions,
|
|
416
|
-
host
|
|
417
|
-
};
|
|
418
|
-
const program = ts.createProgram(programOptions);
|
|
419
|
-
const emitResult = program.emit();
|
|
420
|
-
const allDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
421
|
-
if (!emitResult.emitSkipped) {
|
|
422
|
-
if (allDiagnostics.length > 0) {
|
|
423
|
-
console.log(allDiagnostics.map(createErrorMessage).join("\n"));
|
|
424
|
-
}
|
|
425
|
-
if (js === undefined || definitions === undefined) {
|
|
426
|
-
throw new Error(`Unexpected: no js or definitions were created`);
|
|
427
|
-
}
|
|
428
|
-
return {
|
|
429
|
-
js,
|
|
430
|
-
definitions
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
const error = allDiagnostics.map(createErrorMessage).join("\n");
|
|
434
|
-
throw new Error(error);
|
|
435
|
-
};
|
|
436
|
-
const createErrorMessage = (diagnostic)=>{
|
|
437
|
-
if (!diagnostic.file) {
|
|
438
|
-
return `${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`;
|
|
439
|
-
}
|
|
440
|
-
const { line , character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
441
|
-
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
442
|
-
return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`;
|
|
580
|
+
return compilerOptions;
|
|
443
581
|
};
|
|
444
582
|
|
|
445
583
|
const generateDocs = async (location, declarationFile, outFolder, name)=>{
|
|
@@ -496,6 +634,120 @@ const toposort = (packages)=>{
|
|
|
496
634
|
return result;
|
|
497
635
|
};
|
|
498
636
|
|
|
637
|
+
class BuildManager extends EventEmitter {
|
|
638
|
+
constructor(manifest, writer, logStep){
|
|
639
|
+
super();
|
|
640
|
+
this.manifest = manifest;
|
|
641
|
+
this.writer = writer;
|
|
642
|
+
this.logStep = logStep;
|
|
643
|
+
this.participants = new Map();
|
|
644
|
+
this.states = new Map();
|
|
645
|
+
}
|
|
646
|
+
addParticipant(name, participant) {
|
|
647
|
+
this.participants.set(name, participant);
|
|
648
|
+
}
|
|
649
|
+
run() {
|
|
650
|
+
for (const [name] of this.participants){
|
|
651
|
+
this.states.set(name, {
|
|
652
|
+
type: "busy"
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
this.emit("start");
|
|
656
|
+
for (const [name, participant] of this.participants){
|
|
657
|
+
participant({
|
|
658
|
+
onBuildStart: ()=>{
|
|
659
|
+
let alreadyBusy = false;
|
|
660
|
+
for (const [name, state] of this.states){
|
|
661
|
+
if (state.type === "busy") {
|
|
662
|
+
alreadyBusy = true;
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
this.states.set(name, {
|
|
667
|
+
type: "busy"
|
|
668
|
+
});
|
|
669
|
+
if (!alreadyBusy) {
|
|
670
|
+
this.emit("start");
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
onBuildEnd: (result)=>{
|
|
674
|
+
this.states.set(name, result);
|
|
675
|
+
this.maybeEmit();
|
|
676
|
+
},
|
|
677
|
+
log: this.logStep
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
maybeEmit() {
|
|
682
|
+
const errors = [];
|
|
683
|
+
const results = [];
|
|
684
|
+
for (const [_, state] of this.states){
|
|
685
|
+
if (state.type === "busy") {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (state.type === "success") {
|
|
689
|
+
results.push(state);
|
|
690
|
+
} else if (state.type === "error") {
|
|
691
|
+
errors.push(state.error);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (errors.length > 0) {
|
|
695
|
+
this.emit("error", errors.join("\n"));
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
const completeResult = {
|
|
699
|
+
js: ""
|
|
700
|
+
};
|
|
701
|
+
const sourceMapGenerator = new SourceMapGenerator();
|
|
702
|
+
for (const result of results){
|
|
703
|
+
if (result.artefacts.js) {
|
|
704
|
+
if (completeResult.js) {
|
|
705
|
+
completeResult.js += "\n";
|
|
706
|
+
}
|
|
707
|
+
if (result.artefacts.sourceMap) {
|
|
708
|
+
const lines = completeResult.js.split("\n").length - 1;
|
|
709
|
+
const sourceMap = new SourceMapConsumer(JSON.parse(result.artefacts.sourceMap));
|
|
710
|
+
const sources = new Set();
|
|
711
|
+
sourceMap.eachMapping((mapping)=>{
|
|
712
|
+
sourceMapGenerator.addMapping({
|
|
713
|
+
generated: {
|
|
714
|
+
line: lines + mapping.generatedLine,
|
|
715
|
+
column: mapping.generatedColumn
|
|
716
|
+
},
|
|
717
|
+
original: {
|
|
718
|
+
line: mapping.originalLine,
|
|
719
|
+
column: mapping.originalColumn
|
|
720
|
+
},
|
|
721
|
+
source: mapping.source,
|
|
722
|
+
name: mapping.name
|
|
723
|
+
});
|
|
724
|
+
sources.add(mapping.source);
|
|
725
|
+
});
|
|
726
|
+
for (const source of sources){
|
|
727
|
+
const content = sourceMap.sourceContentFor(source);
|
|
728
|
+
if (content !== null) {
|
|
729
|
+
sourceMapGenerator.setSourceContent(source, content);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
completeResult.js += result.artefacts.js;
|
|
734
|
+
}
|
|
735
|
+
if (result.artefacts.definitions) {
|
|
736
|
+
if (completeResult.definitions) {
|
|
737
|
+
completeResult.definitions += "\n";
|
|
738
|
+
} else {
|
|
739
|
+
completeResult.definitions = "";
|
|
740
|
+
}
|
|
741
|
+
completeResult.definitions += result.artefacts.definitions;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
completeResult.sourceMap = sourceMapGenerator.toString();
|
|
745
|
+
this.writer(completeResult).then(()=>{
|
|
746
|
+
this.emit("build");
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
499
751
|
var animationSchema = {
|
|
500
752
|
$schema: "http://json-schema.org/draft-07/schema",
|
|
501
753
|
$id: "https://archive.intelligentgraphics.biz/schemas/gfx/animation.json",
|
|
@@ -822,6 +1074,117 @@ var animationSchema = {
|
|
|
822
1074
|
}
|
|
823
1075
|
};
|
|
824
1076
|
|
|
1077
|
+
const createAnimationBuildParticipant = (location, manifest)=>{
|
|
1078
|
+
return (env)=>{
|
|
1079
|
+
env.onBuildStart();
|
|
1080
|
+
bundleAnimations(location, manifest, env.log).then((result)=>{
|
|
1081
|
+
env.onBuildEnd({
|
|
1082
|
+
type: "success",
|
|
1083
|
+
artefacts: {
|
|
1084
|
+
js: (result == null ? void 0 : result.js) ?? ""
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
}).catch((err)=>{
|
|
1088
|
+
env.onBuildEnd({
|
|
1089
|
+
type: "error",
|
|
1090
|
+
error: err.message
|
|
1091
|
+
});
|
|
1092
|
+
});
|
|
1093
|
+
return {
|
|
1094
|
+
destroy: ()=>{}
|
|
1095
|
+
};
|
|
1096
|
+
};
|
|
1097
|
+
};
|
|
1098
|
+
const createAnimationWatchBuildParticipant = (location, manifest)=>{
|
|
1099
|
+
return (env)=>{
|
|
1100
|
+
env.onBuildStart();
|
|
1101
|
+
bundleAnimations(location, manifest, env.log).then((result)=>{
|
|
1102
|
+
env.onBuildEnd({
|
|
1103
|
+
type: "success",
|
|
1104
|
+
artefacts: {
|
|
1105
|
+
js: (result == null ? void 0 : result.js) ?? ""
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
}).catch((err)=>{
|
|
1109
|
+
env.onBuildEnd({
|
|
1110
|
+
type: "error",
|
|
1111
|
+
error: err.message
|
|
1112
|
+
});
|
|
1113
|
+
});
|
|
1114
|
+
(async ()=>{
|
|
1115
|
+
for await (const event of fs$1.watch(location.scriptsDir)){
|
|
1116
|
+
if (event.filename.endsWith(".animation.json")) {
|
|
1117
|
+
env.onBuildStart();
|
|
1118
|
+
try {
|
|
1119
|
+
const result = await bundleAnimations(location, manifest, env.log);
|
|
1120
|
+
env.onBuildEnd({
|
|
1121
|
+
type: "success",
|
|
1122
|
+
artefacts: {
|
|
1123
|
+
js: (result == null ? void 0 : result.js) ?? ""
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
} catch (err) {
|
|
1127
|
+
env.onBuildEnd({
|
|
1128
|
+
type: "error",
|
|
1129
|
+
error: err.message
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
})();
|
|
1135
|
+
return {
|
|
1136
|
+
destroy: ()=>{}
|
|
1137
|
+
};
|
|
1138
|
+
};
|
|
1139
|
+
};
|
|
1140
|
+
const bundleAnimations = async (location, manifest, logStep)=>{
|
|
1141
|
+
const animations = new Map();
|
|
1142
|
+
for (const scriptFilePath of readPackageAnimationList(location)){
|
|
1143
|
+
const content = await fs$1.readFile(scriptFilePath, {
|
|
1144
|
+
encoding: "utf8"
|
|
1145
|
+
});
|
|
1146
|
+
let data;
|
|
1147
|
+
try {
|
|
1148
|
+
data = JSON.parse(content);
|
|
1149
|
+
} catch (err) {
|
|
1150
|
+
const relativePath = path.relative(location.path, scriptFilePath);
|
|
1151
|
+
if (err instanceof SyntaxError) {
|
|
1152
|
+
throw new Error(`Encountered invalid syntax in file "${relativePath}": ${String(err)}`);
|
|
1153
|
+
}
|
|
1154
|
+
throw new Error(`Encountered an unexpected error while parsing animation json file at path "${relativePath}"`, {
|
|
1155
|
+
cause: err
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
if (!data.Id) {
|
|
1159
|
+
const fileName = path.basename(scriptFilePath, ".animation.json");
|
|
1160
|
+
data.Id = fileName;
|
|
1161
|
+
}
|
|
1162
|
+
(await getAnimationJsonValidation())(data);
|
|
1163
|
+
delete data.$schema;
|
|
1164
|
+
animations.set(data.Id, JSON.stringify(data));
|
|
1165
|
+
}
|
|
1166
|
+
if (animations.size > 0) {
|
|
1167
|
+
const scope = manifest.Scope ?? manifest.Package;
|
|
1168
|
+
const scopeParts = scope.split(".");
|
|
1169
|
+
let js = createNamespace(scopeParts);
|
|
1170
|
+
for (const [name, content] of animations){
|
|
1171
|
+
js += `${scope}["${name}"] = ` + content + ";";
|
|
1172
|
+
logStep(`Adding animation ${scope}.${name}`);
|
|
1173
|
+
}
|
|
1174
|
+
return {
|
|
1175
|
+
js
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
return undefined;
|
|
1179
|
+
};
|
|
1180
|
+
const createNamespace = (parts)=>{
|
|
1181
|
+
let code = `var ${parts[0]};`;
|
|
1182
|
+
for(let index = 0; index < parts.length; index++){
|
|
1183
|
+
const path = parts.slice(0, index + 1).join(".");
|
|
1184
|
+
code += `\n(${path} = ${path} || {});`;
|
|
1185
|
+
}
|
|
1186
|
+
return code;
|
|
1187
|
+
};
|
|
825
1188
|
let validateAnimationJson;
|
|
826
1189
|
const getAnimationJsonValidation = async ()=>{
|
|
827
1190
|
if (validateAnimationJson === undefined) {
|
|
@@ -835,9 +1198,10 @@ const getAnimationJsonValidation = async ()=>{
|
|
|
835
1198
|
}
|
|
836
1199
|
return validateAnimationJson;
|
|
837
1200
|
};
|
|
1201
|
+
|
|
838
1202
|
const buildFolders = async (options)=>{
|
|
839
1203
|
if (options.outDir !== undefined && options.clean) {
|
|
840
|
-
fs.
|
|
1204
|
+
await fs$1.rm(options.outDir, {
|
|
841
1205
|
recursive: true
|
|
842
1206
|
});
|
|
843
1207
|
}
|
|
@@ -845,93 +1209,38 @@ const buildFolders = async (options)=>{
|
|
|
845
1209
|
const folders = options.packages;
|
|
846
1210
|
let sortedPackages = sortPackagesByBuildOrder(folders);
|
|
847
1211
|
let index = 1;
|
|
1212
|
+
const manifests = new Map(sortedPackages.map((location)=>[
|
|
1213
|
+
location,
|
|
1214
|
+
readPackageCreatorManifest(location)
|
|
1215
|
+
]));
|
|
1216
|
+
const maxNameLength = Array.from(manifests.values(), (manifest)=>manifest.Package.length).reduce((acc, length)=>Math.max(acc, length), 0);
|
|
848
1217
|
for (const location of sortedPackages){
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
const
|
|
852
|
-
const logStep = (step)=>logPackageMessage(data.Package, step, index, folders.length);
|
|
1218
|
+
await ensureTsConfig(location);
|
|
1219
|
+
const data = manifests.get(location);
|
|
1220
|
+
const logStep = (step)=>logPackageMessage(data.Package, step, index, folders.length, maxNameLength);
|
|
853
1221
|
const outputDirectory = options.outDir || location.scriptsDir;
|
|
854
|
-
fs.
|
|
1222
|
+
await fs$1.mkdir(outputDirectory, {
|
|
855
1223
|
recursive: true
|
|
856
1224
|
});
|
|
857
|
-
|
|
858
|
-
if (
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
const banner = options.banner ? createBannerComment(options.banner) : undefined;
|
|
867
|
-
if (banner) {
|
|
868
|
-
buildResult.js = banner + "\n" + buildResult.js;
|
|
869
|
-
if (buildResult.definitions !== undefined) {
|
|
870
|
-
buildResult.definitions = banner + "\n" + buildResult.definitions;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
const animations = new Map();
|
|
874
|
-
for (const scriptFilePath of readPackageAnimationList(location)){
|
|
875
|
-
const content = fs.readFileSync(scriptFilePath, {
|
|
876
|
-
encoding: "utf8"
|
|
877
|
-
});
|
|
878
|
-
let data;
|
|
879
|
-
try {
|
|
880
|
-
data = JSON.parse(content);
|
|
881
|
-
} catch (err) {
|
|
882
|
-
const relativePath = path.relative(options.workspace.path, scriptFilePath);
|
|
883
|
-
if (err instanceof SyntaxError) {
|
|
884
|
-
throw new Error(`Encountered invalid syntax in file "${relativePath}": ${String(err)}`);
|
|
885
|
-
}
|
|
886
|
-
throw new Error(`Encountered an unexpected error while parsing animation json file at path "${relativePath}"`, {
|
|
887
|
-
cause: err
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
if (!data.Id) {
|
|
891
|
-
const fileName = path.basename(scriptFilePath, ".animation.json");
|
|
892
|
-
data.Id = fileName;
|
|
893
|
-
}
|
|
894
|
-
(await getAnimationJsonValidation())(data);
|
|
895
|
-
delete data.$schema;
|
|
896
|
-
animations.set(data.Id, JSON.stringify(data));
|
|
897
|
-
}
|
|
898
|
-
if (animations.size > 0) {
|
|
899
|
-
const scope = data.Scope ?? data.Package;
|
|
900
|
-
const scopeParts = scope.split(".");
|
|
901
|
-
buildResult.js += createNamespace(scopeParts);
|
|
902
|
-
for (const [name, content] of animations){
|
|
903
|
-
buildResult.js += `${scope}["${name}"] = ` + content + ";";
|
|
904
|
-
logPackageMessage(data.Package, `Adding animation ${scope}.${name}`);
|
|
905
|
-
}
|
|
906
|
-
} else if (!hasTypescript) {
|
|
907
|
-
throw new Error(`Expected package to have a least one ts file or one animation.json file`);
|
|
908
|
-
}
|
|
909
|
-
fs.writeFileSync(path.join(outputDirectory, `${data.Package}.js`), buildResult.js, {
|
|
910
|
-
encoding: "utf8"
|
|
911
|
-
});
|
|
912
|
-
if (buildResult.definitions !== undefined) {
|
|
913
|
-
fs.writeFileSync(path.join(outputDirectory, `${data.Package}.d.ts`), buildResult.definitions, {
|
|
914
|
-
encoding: "utf8"
|
|
1225
|
+
const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
|
|
1226
|
+
if (options.banner) {
|
|
1227
|
+
manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
|
|
1228
|
+
}
|
|
1229
|
+
manager.addParticipant("tsc", createTSCBuildParticipant(location, outputDirectory));
|
|
1230
|
+
manager.addParticipant("animation", createAnimationBuildParticipant(location, data));
|
|
1231
|
+
await new Promise((resolve, reject)=>{
|
|
1232
|
+
manager.addListener("start", ()=>{
|
|
1233
|
+
logStep(`Build started`);
|
|
915
1234
|
});
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
const minifyResult = await terser.minify(buildResult.js, {
|
|
919
|
-
ecma: 5
|
|
920
|
-
});
|
|
921
|
-
const minifiedPath = path.join(outputDirectory, `${data.Package}.min.js`);
|
|
922
|
-
fs.writeFileSync(minifiedPath, minifyResult.code, {
|
|
923
|
-
encoding: "utf8"
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
if (location.path.includes("Basics") && buildResult.definitions !== undefined) {
|
|
927
|
-
fs.mkdirSync(path.join(workspace.path, "lib"), {
|
|
928
|
-
recursive: true
|
|
1235
|
+
manager.addListener("error", (error)=>{
|
|
1236
|
+
reject(new Error(error));
|
|
929
1237
|
});
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1238
|
+
manager.addListener("build", ()=>{
|
|
1239
|
+
logStep(`Build complete`);
|
|
1240
|
+
resolve();
|
|
933
1241
|
});
|
|
934
|
-
|
|
1242
|
+
manager.run();
|
|
1243
|
+
});
|
|
935
1244
|
if (options.docs) {
|
|
936
1245
|
logStep("Generating typedoc documentation");
|
|
937
1246
|
await generateDocs(location, path.join(outputDirectory, `${data.Package}.d.ts`), path.join(workspace.path, "docs", data.Package), data.Package);
|
|
@@ -939,24 +1248,127 @@ const buildFolders = async (options)=>{
|
|
|
939
1248
|
index++;
|
|
940
1249
|
}
|
|
941
1250
|
};
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1251
|
+
const buildFoldersWatch = async (options)=>{
|
|
1252
|
+
if (options.outDir !== undefined && options.clean) {
|
|
1253
|
+
await fs$1.rm(options.outDir, {
|
|
1254
|
+
recursive: true
|
|
1255
|
+
});
|
|
947
1256
|
}
|
|
948
|
-
|
|
1257
|
+
const workspace = options.workspace;
|
|
1258
|
+
const folders = options.packages;
|
|
1259
|
+
let sortedPackages = sortPackagesByBuildOrder(folders);
|
|
1260
|
+
let index = 1;
|
|
1261
|
+
const manifests = new Map(sortedPackages.map((location)=>[
|
|
1262
|
+
location,
|
|
1263
|
+
readPackageCreatorManifest(location)
|
|
1264
|
+
]));
|
|
1265
|
+
const maxNameLength = Array.from(manifests.values(), (manifest)=>manifest.Package.length).reduce((acc, length)=>Math.max(acc, length), 0);
|
|
1266
|
+
for (const location of sortedPackages){
|
|
1267
|
+
await ensureTsConfig(location);
|
|
1268
|
+
const data = manifests.get(location);
|
|
1269
|
+
const currentIndex = index;
|
|
1270
|
+
const logStep = (step)=>logPackageMessage(data.Package, step, currentIndex, folders.length, maxNameLength);
|
|
1271
|
+
const outputDirectory = options.outDir || location.scriptsDir;
|
|
1272
|
+
await fs$1.mkdir(outputDirectory, {
|
|
1273
|
+
recursive: true
|
|
1274
|
+
});
|
|
1275
|
+
const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
|
|
1276
|
+
if (options.banner) {
|
|
1277
|
+
manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
|
|
1278
|
+
}
|
|
1279
|
+
manager.addParticipant("tsc", createTSCWatchBuildParticipant(location, outputDirectory));
|
|
1280
|
+
manager.addParticipant("animation", createAnimationWatchBuildParticipant(location, data));
|
|
1281
|
+
await new Promise((resolve, reject)=>{
|
|
1282
|
+
manager.addListener("start", ()=>{
|
|
1283
|
+
logStep(`Build started`);
|
|
1284
|
+
});
|
|
1285
|
+
manager.addListener("error", (error)=>{
|
|
1286
|
+
logStep(`Build failed: ${error}`);
|
|
1287
|
+
resolve();
|
|
1288
|
+
});
|
|
1289
|
+
manager.addListener("build", ()=>{
|
|
1290
|
+
logStep(`Build complete`);
|
|
1291
|
+
resolve();
|
|
1292
|
+
});
|
|
1293
|
+
manager.run();
|
|
1294
|
+
});
|
|
1295
|
+
index++;
|
|
1296
|
+
}
|
|
1297
|
+
await new Promise(()=>{});
|
|
949
1298
|
};
|
|
950
|
-
const
|
|
1299
|
+
const writeBuildResult = async (buildResult, manifest, location, workspace, outputDirectory, minimize, logStep)=>{
|
|
1300
|
+
let js = buildResult.js;
|
|
1301
|
+
if (buildResult.sourceMap) {
|
|
1302
|
+
js += `\n//# sourceMappingURL=${manifest.Package}.js.map`;
|
|
1303
|
+
}
|
|
1304
|
+
await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.js`), js, {
|
|
1305
|
+
encoding: "utf8"
|
|
1306
|
+
});
|
|
1307
|
+
if (buildResult.definitions !== undefined) {
|
|
1308
|
+
await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.d.ts`), buildResult.definitions, {
|
|
1309
|
+
encoding: "utf8"
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
if (buildResult.sourceMap !== undefined) {
|
|
1313
|
+
await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.js.map`), buildResult.sourceMap, {
|
|
1314
|
+
encoding: "utf8"
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
if (minimize) {
|
|
1318
|
+
const minifyResult = await terser.minify(js, {
|
|
1319
|
+
ecma: 5,
|
|
1320
|
+
sourceMap: {
|
|
1321
|
+
content: buildResult.sourceMap,
|
|
1322
|
+
includeSources: false
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
const minifiedPath = path.join(outputDirectory, `${manifest.Package}.min.js`);
|
|
1326
|
+
await fs$1.writeFile(minifiedPath, minifyResult.code, {
|
|
1327
|
+
encoding: "utf8"
|
|
1328
|
+
});
|
|
1329
|
+
if (minifyResult.map !== undefined) {
|
|
1330
|
+
await fs$1.writeFile(minifiedPath + ".map", typeof minifyResult.map === "string" ? minifyResult.map : JSON.stringify(minifyResult.map), {
|
|
1331
|
+
encoding: "utf8"
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
if (location.path.includes("Basics") && buildResult.definitions !== undefined) {
|
|
1336
|
+
await fs$1.mkdir(path.join(workspace.path, "lib"), {
|
|
1337
|
+
recursive: true
|
|
1338
|
+
});
|
|
1339
|
+
logStep("Copying basics definition file to the lib folder");
|
|
1340
|
+
await fs$1.writeFile(path.join(workspace.path, "lib", `${manifest.Package}.d.ts`), buildResult.definitions, {
|
|
1341
|
+
encoding: "utf8"
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
const createBannerCommentBuildParticipant = (options)=>(env)=>{
|
|
1346
|
+
env.onBuildStart();
|
|
1347
|
+
const banner = createBannerComment(options);
|
|
1348
|
+
env.onBuildEnd({
|
|
1349
|
+
type: "success",
|
|
1350
|
+
artefacts: {
|
|
1351
|
+
js: banner ?? "",
|
|
1352
|
+
definitions: banner ?? ""
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
return {
|
|
1356
|
+
destroy: ()=>{}
|
|
1357
|
+
};
|
|
1358
|
+
};
|
|
1359
|
+
const ensureTsConfig = async (location)=>{
|
|
951
1360
|
const tsconfigPath = path.join(location.scriptsDir, "tsconfig.json");
|
|
952
|
-
|
|
953
|
-
const content =
|
|
1361
|
+
try {
|
|
1362
|
+
const content = JSON.parse(await fs$1.readFile(tsconfigPath, "utf8"));
|
|
954
1363
|
applyTsConfigOption(content);
|
|
955
|
-
fs.
|
|
956
|
-
}
|
|
957
|
-
|
|
1364
|
+
await fs$1.writeFile(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
|
|
1365
|
+
} catch (err) {
|
|
1366
|
+
if (!isErrorENOENT(err)) {
|
|
1367
|
+
throw err;
|
|
1368
|
+
}
|
|
1369
|
+
const content = {};
|
|
958
1370
|
applyTsConfigOption(content);
|
|
959
|
-
fs.
|
|
1371
|
+
await fs$1.writeFile(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
|
|
960
1372
|
}
|
|
961
1373
|
};
|
|
962
1374
|
const applyTsConfigOption = (data)=>{
|
|
@@ -1409,6 +1821,24 @@ const buildArchiveFromPublishedPackage = (location, manifest, creatorPackage)=>{
|
|
|
1409
1821
|
archive.file(INDEX_FILE, JSON.stringify(index, null, 2));
|
|
1410
1822
|
}
|
|
1411
1823
|
archive.file(manifest.main, fs.createReadStream(path.join(location.path, manifest.main)));
|
|
1824
|
+
if (creatorPackage.Package === "IG.GFX.Standard") {
|
|
1825
|
+
const source = path.join(location.path, "Images");
|
|
1826
|
+
if (fs.existsSync(source)) {
|
|
1827
|
+
const images = fs.readdirSync(source);
|
|
1828
|
+
for (const file of images){
|
|
1829
|
+
const { ext } = path.parse(file);
|
|
1830
|
+
switch(ext){
|
|
1831
|
+
case ".png":
|
|
1832
|
+
case ".jpeg":
|
|
1833
|
+
case ".jpg":
|
|
1834
|
+
break;
|
|
1835
|
+
default:
|
|
1836
|
+
continue;
|
|
1837
|
+
}
|
|
1838
|
+
archive.file(file, fs.createReadStream(path.join(source, file)));
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1412
1842
|
return archive;
|
|
1413
1843
|
};
|
|
1414
1844
|
const runtimeScripts = [
|
|
@@ -2089,5 +2519,5 @@ const detectScriptingClass = (node)=>{
|
|
|
2089
2519
|
}
|
|
2090
2520
|
};
|
|
2091
2521
|
|
|
2092
|
-
export { buildFolders, generateIndex, releaseFolder };
|
|
2522
|
+
export { buildFolders, buildFoldersWatch, generateIndex, releaseFolder };
|
|
2093
2523
|
//# sourceMappingURL=lib.mjs.map
|