@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.
Files changed (27) hide show
  1. package/build/bin.mjs +1 -1
  2. package/build/{cli-4b4eb819.mjs → cli-91fabb36.mjs} +22 -8
  3. package/build/cli-91fabb36.mjs.map +1 -0
  4. package/build/{dependencies-7b889e67.mjs → dependencies-7711a9db.mjs} +2 -2
  5. package/build/{dependencies-7b889e67.mjs.map → dependencies-7711a9db.mjs.map} +1 -1
  6. package/build/{generateIndex-1c76f3b7.mjs → generateIndex-47c082d0.mjs} +2 -2
  7. package/build/{generateIndex-1c76f3b7.mjs.map → generateIndex-47c082d0.mjs.map} +1 -1
  8. package/build/{generateParameterType-ecd8f4b2.mjs → generateParameterType-10d124a6.mjs} +2 -2
  9. package/build/{generateParameterType-ecd8f4b2.mjs.map → generateParameterType-10d124a6.mjs.map} +1 -1
  10. package/build/{index-4dd728d6.mjs → index-ca04836f.mjs} +25 -6
  11. package/build/index-ca04836f.mjs.map +1 -0
  12. package/build/index-e6ead55c.mjs +1120 -0
  13. package/build/index-e6ead55c.mjs.map +1 -0
  14. package/build/{postinstall-dce685cf.mjs → postinstall-0ea76778.mjs} +3 -3
  15. package/build/{postinstall-dce685cf.mjs.map → postinstall-0ea76778.mjs.map} +1 -1
  16. package/build/{publishNpm-0bfe5bda.mjs → publishNpm-aadd7dc2.mjs} +33 -5
  17. package/build/publishNpm-aadd7dc2.mjs.map +1 -0
  18. package/build/{versionFile-041c0e79.mjs → versionFile-ad981e93.mjs} +2 -2
  19. package/build/{versionFile-041c0e79.mjs.map → versionFile-ad981e93.mjs.map} +1 -1
  20. package/lib/lib.mjs +576 -146
  21. package/package.json +3 -2
  22. package/readme.md +9 -0
  23. package/build/cli-4b4eb819.mjs.map +0 -1
  24. package/build/index-14f27618.mjs +0 -706
  25. package/build/index-14f27618.mjs.map +0 -1
  26. package/build/index-4dd728d6.mjs.map +0 -1
  27. package/build/publishNpm-0bfe5bda.mjs.map +0 -1
@@ -0,0 +1,1120 @@
1
+ import * as path from 'path';
2
+ import * as fs$1 from 'fs/promises';
3
+ import * as terser from 'terser';
4
+ import * as fs from 'fs';
5
+ import 'resolve';
6
+ import 'write-pkg';
7
+ import { c as readPackageAnimationList, r as readPackageCreatorManifest, i as isErrorENOENT, q as readPackageNpmManifest } from './cli-91fabb36.mjs';
8
+ import glob from 'glob';
9
+ import 'node:path';
10
+ import 'node:fs';
11
+ import 'axios';
12
+ import ts from 'typescript';
13
+ import { g as getPackageTypescriptFiles } from './scripts-7ed8dff6.mjs';
14
+ import typedoc from 'typedoc';
15
+ import require$$2 from 'events';
16
+ import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
17
+ import Ajv from 'ajv';
18
+
19
+ const logPackageMessage = (name, step, index, total, maxNameLength = 15)=>{
20
+ const numLength = total === undefined ? undefined : total.toString().length;
21
+ const indexString = total === undefined || total < 2 ? "" : `${index.toString().padStart(numLength, "0")}/${total} `;
22
+ const identifierString = `${indexString}${name.padEnd(maxNameLength)}`;
23
+ console.log(`${identifierString} >> ${step}`);
24
+ };
25
+
26
+ const tryReadTsConfig = (location)=>{
27
+ const { config } = ts.readConfigFile(path.join(location.scriptsDir, "tsconfig.json"), (path)=>{
28
+ try {
29
+ return fs.readFileSync(path, "utf8");
30
+ } catch {
31
+ return undefined;
32
+ }
33
+ });
34
+ return config;
35
+ };
36
+ const createTSCBuildParticipant = (location, outputDir)=>(env)=>{
37
+ const files = getPackageTypescriptFiles(location);
38
+ if (files.length === 0) {
39
+ env.onBuildStart();
40
+ env.onBuildEnd({
41
+ type: "success",
42
+ artefacts: {
43
+ js: "",
44
+ definitions: ""
45
+ }
46
+ });
47
+ return {
48
+ destroy: ()=>{}
49
+ };
50
+ }
51
+ try {
52
+ env.onBuildStart();
53
+ const compilerOptions = getCompilerOptions(location, outputDir);
54
+ const host = ts.createCompilerHost(compilerOptions);
55
+ host.getCurrentDirectory = ()=>location.scriptsDir;
56
+ let js;
57
+ let definitions;
58
+ let sourceMap;
59
+ host.writeFile = (fileName, data, writeByteOrderMark)=>{
60
+ if (fileName.endsWith(".js")) {
61
+ js = data;
62
+ } else if (fileName.endsWith(".d.ts")) {
63
+ definitions = data;
64
+ } else if (fileName.endsWith(".js.map")) {
65
+ sourceMap = data;
66
+ }
67
+ };
68
+ const programOptions = {
69
+ rootNames: files,
70
+ options: compilerOptions,
71
+ host
72
+ };
73
+ const program = ts.createProgram(programOptions);
74
+ const emitResult = program.emit();
75
+ const allDiagnostics = ts.getPreEmitDiagnostics(program);
76
+ if (!emitResult.emitSkipped) {
77
+ if (allDiagnostics.length > 0) {
78
+ console.log(allDiagnostics.map(createErrorMessage).join("\n"));
79
+ }
80
+ if (js === undefined || definitions === undefined) {
81
+ throw new Error(`Unexpected: no js or definitions were created`);
82
+ }
83
+ env.onBuildEnd({
84
+ type: "success",
85
+ artefacts: {
86
+ js: js.replace(`//# sourceMappingURL=out.js.map`, ""),
87
+ definitions,
88
+ sourceMap
89
+ }
90
+ });
91
+ } else {
92
+ const error = allDiagnostics.map(createErrorMessage).join("\n");
93
+ throw new Error(error);
94
+ }
95
+ } catch (err) {
96
+ env.onBuildEnd({
97
+ type: "error",
98
+ error: err.message
99
+ });
100
+ }
101
+ return {
102
+ destroy: ()=>{}
103
+ };
104
+ };
105
+ const createTSCWatchBuildParticipant = (location, outputDir)=>{
106
+ return ({ onBuildStart , onBuildEnd })=>{
107
+ let state = {
108
+ diagnostics: [],
109
+ js: undefined,
110
+ definitions: undefined,
111
+ sourceMap: undefined
112
+ };
113
+ const customSys = {
114
+ ...ts.sys,
115
+ writeFile: (fileName, data, writeByteOrderMark)=>{
116
+ if (fileName.endsWith(".js")) {
117
+ state.js = data;
118
+ } else if (fileName.endsWith(".d.ts")) {
119
+ state.definitions = data;
120
+ } else if (fileName.endsWith(".js.map")) {
121
+ state.sourceMap = data;
122
+ }
123
+ }
124
+ };
125
+ const reportDiagnostic = (diagnostic)=>{
126
+ switch(diagnostic.code){
127
+ // file not found - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4640
128
+ // probably deleted -> ignore
129
+ case 6053:
130
+ return;
131
+ // no inputs were found - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L6838
132
+ // we don't care about this error. a user might have temporarily deleted the last ts file and will readd one later.
133
+ case 18003:
134
+ return;
135
+ }
136
+ state.diagnostics.push(diagnostic);
137
+ };
138
+ const reportWatchStatusChanged = (diagnostic)=>{
139
+ switch(diagnostic.code){
140
+ // regular watch mode - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4567
141
+ case 6031:
142
+ // incremental watch mode - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4571
143
+ case 6032:
144
+ // build start
145
+ onBuildStart();
146
+ break;
147
+ // found one error - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L5119
148
+ case 6193:
149
+ // found n or 0 errors - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L5123
150
+ case 6194:
151
+ // build end
152
+ const emitState = state;
153
+ state = {
154
+ diagnostics: [],
155
+ js: undefined,
156
+ definitions: undefined,
157
+ sourceMap: undefined
158
+ };
159
+ if (emitState.diagnostics.length > 0) {
160
+ const message = emitState.diagnostics.map(createErrorMessage).join("\n");
161
+ onBuildEnd({
162
+ type: "error",
163
+ error: message
164
+ });
165
+ return;
166
+ }
167
+ if (emitState.js === undefined || emitState.definitions === undefined) {
168
+ onBuildEnd({
169
+ type: "success",
170
+ artefacts: {
171
+ js: ""
172
+ }
173
+ });
174
+ return;
175
+ }
176
+ onBuildEnd({
177
+ type: "success",
178
+ artefacts: {
179
+ js: emitState.js.replace(`//# sourceMappingURL=out.js.map`, ""),
180
+ definitions: emitState.definitions,
181
+ sourceMap: emitState.sourceMap
182
+ }
183
+ });
184
+ break;
185
+ }
186
+ };
187
+ const host = ts.createWatchCompilerHost(path.join(location.scriptsDir, "tsconfig.json"), getCompilerOptions(location, outputDir), customSys, ts.createSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportWatchStatusChanged);
188
+ const watchProgram = ts.createWatchProgram(host);
189
+ const files = getPackageTypescriptFiles(location);
190
+ if (files.length === 0) {
191
+ onBuildStart();
192
+ onBuildEnd({
193
+ type: "success",
194
+ artefacts: {
195
+ js: "",
196
+ definitions: ""
197
+ }
198
+ });
199
+ }
200
+ return {
201
+ destroy: ()=>{
202
+ watchProgram.close();
203
+ }
204
+ };
205
+ };
206
+ };
207
+ const createErrorMessage = (diagnostic)=>{
208
+ if (!diagnostic.file) {
209
+ return `${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`;
210
+ }
211
+ const { line , character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
212
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
213
+ return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`;
214
+ };
215
+ const getCompilerOptions = (location, outputDir)=>{
216
+ const config = tryReadTsConfig(location);
217
+ config.compilerOptions.lib = [
218
+ "es5",
219
+ "dom"
220
+ ];
221
+ const result = ts.convertCompilerOptionsFromJson(config.compilerOptions, location.scriptsDir);
222
+ const compilerOptions = {
223
+ ...result.options,
224
+ removeComments: false,
225
+ declaration: true,
226
+ sourceMap: true,
227
+ inlineSources: false,
228
+ // We don't use tsc to actually emit the files, but we still need to set the correct
229
+ // output directory so the compiler can rewrite the `reference path` directives.
230
+ outFile: path.join(outputDir, "out.js"),
231
+ target: ts.ScriptTarget.ES5,
232
+ noEmitOnError: true
233
+ };
234
+ return compilerOptions;
235
+ };
236
+
237
+ const generateDocs = async (location, declarationFile, outFolder, name)=>{
238
+ const app = new typedoc.Application();
239
+ const mediaDir = path.join(location.manifestDir, "Media");
240
+ app.bootstrap({
241
+ entryPoints: [
242
+ declarationFile
243
+ ],
244
+ media: mediaDir,
245
+ out: outFolder,
246
+ tsconfig: path.join(location.scriptsDir, "tsconfig.json"),
247
+ skipErrorChecking: true
248
+ });
249
+ app.options.setCompilerOptions([
250
+ declarationFile
251
+ ], {
252
+ target: ts.ScriptTarget.ES5
253
+ }, undefined);
254
+ app.options.setValue("name", name);
255
+ const [readmePath] = glob.sync("**/readme.md", {
256
+ absolute: true,
257
+ cwd: location.manifestDir
258
+ });
259
+ if (readmePath) {
260
+ app.options.setValue("readme", readmePath);
261
+ }
262
+ const project = app.convert();
263
+ if (project) {
264
+ await app.generateDocs(project, outFolder);
265
+ }
266
+ };
267
+
268
+ // Stolen from ig.tools.core
269
+ const toposort = (packages)=>{
270
+ const queue = Object.getOwnPropertyNames(packages);
271
+ const result = [];
272
+ let index = 0;
273
+ while(queue.length > 0){
274
+ if (index >= queue.length) {
275
+ throw new Error("Packages can not have cyclic dependencies");
276
+ }
277
+ const queueEntry = queue[index];
278
+ const dependencies = packages[queueEntry];
279
+ const dependencyQueued = dependencies.some((dependency)=>queue.includes(dependency));
280
+ if (dependencyQueued) {
281
+ index++;
282
+ continue;
283
+ }
284
+ queue.splice(index, 1);
285
+ index = 0;
286
+ result.push(queueEntry);
287
+ }
288
+ return result;
289
+ };
290
+
291
+ class BuildManager extends require$$2 {
292
+ constructor(manifest, writer, logStep){
293
+ super();
294
+ this.manifest = manifest;
295
+ this.writer = writer;
296
+ this.logStep = logStep;
297
+ this.participants = new Map();
298
+ this.states = new Map();
299
+ }
300
+ addParticipant(name, participant) {
301
+ this.participants.set(name, participant);
302
+ }
303
+ run() {
304
+ for (const [name] of this.participants){
305
+ this.states.set(name, {
306
+ type: "busy"
307
+ });
308
+ }
309
+ this.emit("start");
310
+ for (const [name, participant] of this.participants){
311
+ participant({
312
+ onBuildStart: ()=>{
313
+ let alreadyBusy = false;
314
+ for (const [name, state] of this.states){
315
+ if (state.type === "busy") {
316
+ alreadyBusy = true;
317
+ continue;
318
+ }
319
+ }
320
+ this.states.set(name, {
321
+ type: "busy"
322
+ });
323
+ if (!alreadyBusy) {
324
+ this.emit("start");
325
+ }
326
+ },
327
+ onBuildEnd: (result)=>{
328
+ this.states.set(name, result);
329
+ this.maybeEmit();
330
+ },
331
+ log: this.logStep
332
+ });
333
+ }
334
+ }
335
+ maybeEmit() {
336
+ const errors = [];
337
+ const results = [];
338
+ for (const [_, state] of this.states){
339
+ if (state.type === "busy") {
340
+ return;
341
+ }
342
+ if (state.type === "success") {
343
+ results.push(state);
344
+ } else if (state.type === "error") {
345
+ errors.push(state.error);
346
+ }
347
+ }
348
+ if (errors.length > 0) {
349
+ this.emit("error", errors.join("\n"));
350
+ return;
351
+ }
352
+ const completeResult = {
353
+ js: ""
354
+ };
355
+ const sourceMapGenerator = new SourceMapGenerator();
356
+ for (const result of results){
357
+ if (result.artefacts.js) {
358
+ if (completeResult.js) {
359
+ completeResult.js += "\n";
360
+ }
361
+ if (result.artefacts.sourceMap) {
362
+ const lines = completeResult.js.split("\n").length - 1;
363
+ const sourceMap = new SourceMapConsumer(JSON.parse(result.artefacts.sourceMap));
364
+ const sources = new Set();
365
+ sourceMap.eachMapping((mapping)=>{
366
+ sourceMapGenerator.addMapping({
367
+ generated: {
368
+ line: lines + mapping.generatedLine,
369
+ column: mapping.generatedColumn
370
+ },
371
+ original: {
372
+ line: mapping.originalLine,
373
+ column: mapping.originalColumn
374
+ },
375
+ source: mapping.source,
376
+ name: mapping.name
377
+ });
378
+ sources.add(mapping.source);
379
+ });
380
+ for (const source of sources){
381
+ const content = sourceMap.sourceContentFor(source);
382
+ if (content !== null) {
383
+ sourceMapGenerator.setSourceContent(source, content);
384
+ }
385
+ }
386
+ }
387
+ completeResult.js += result.artefacts.js;
388
+ }
389
+ if (result.artefacts.definitions) {
390
+ if (completeResult.definitions) {
391
+ completeResult.definitions += "\n";
392
+ } else {
393
+ completeResult.definitions = "";
394
+ }
395
+ completeResult.definitions += result.artefacts.definitions;
396
+ }
397
+ }
398
+ completeResult.sourceMap = sourceMapGenerator.toString();
399
+ this.writer(completeResult).then(()=>{
400
+ this.emit("build");
401
+ });
402
+ }
403
+ }
404
+
405
+ var animationSchema = {
406
+ $schema: "http://json-schema.org/draft-07/schema",
407
+ $id: "https://archive.intelligentgraphics.biz/schemas/gfx/animation.json",
408
+ $comment: "Version 2023-02-17, Source: ig.data.gfx/Specs/animation.json",
409
+ title: "Animation description format",
410
+ additionalProperties: false,
411
+ type: "object",
412
+ properties: {
413
+ $schema: {
414
+ type: "string"
415
+ },
416
+ Id: {
417
+ type: "string",
418
+ description: "Animation id, to be unique in the project scope. Needs to be a valid JavaScript identifier."
419
+ },
420
+ Animations: {
421
+ type: "array",
422
+ description: "Declaration of animation states for gfx objects",
423
+ items: {
424
+ type: "object",
425
+ additionalProperties: false,
426
+ properties: {
427
+ _: {
428
+ type: "string",
429
+ description: "Comment"
430
+ },
431
+ Path: {
432
+ $ref: "#/definitions/igxcPath"
433
+ },
434
+ States: {
435
+ type: "object",
436
+ additionalProperties: {
437
+ type: "object",
438
+ additionalProperties: false,
439
+ properties: {
440
+ Position: {
441
+ $ref: "#/definitions/vec3"
442
+ },
443
+ Rotation: {
444
+ $ref: "#/definitions/rotation"
445
+ },
446
+ Scaling: {
447
+ $ref: "#/definitions/vec3"
448
+ },
449
+ Visibility: {
450
+ type: "boolean"
451
+ },
452
+ Deformation: {
453
+ anyOf: [
454
+ {
455
+ type: "number"
456
+ },
457
+ {
458
+ type: "string"
459
+ }
460
+ ]
461
+ }
462
+ }
463
+ }
464
+ }
465
+ }
466
+ }
467
+ },
468
+ Kinematics: {
469
+ oneOf: [
470
+ {
471
+ $ref: "#/definitions/kinematicChain"
472
+ },
473
+ {
474
+ type: "array",
475
+ items: {
476
+ $ref: "#/definitions/kinematicChain"
477
+ }
478
+ }
479
+ ]
480
+ },
481
+ LinkedPoints: {
482
+ type: "object",
483
+ additionalProperties: {
484
+ type: "array",
485
+ items: {
486
+ type: "string"
487
+ }
488
+ }
489
+ },
490
+ _: {
491
+ type: "string",
492
+ description: "Comment"
493
+ }
494
+ },
495
+ definitions: {
496
+ vec3: {
497
+ type: "object",
498
+ additionalProperties: false,
499
+ properties: {
500
+ X: {
501
+ anyOf: [
502
+ {
503
+ type: "number"
504
+ },
505
+ {
506
+ type: "string"
507
+ }
508
+ ]
509
+ },
510
+ Y: {
511
+ anyOf: [
512
+ {
513
+ type: "number"
514
+ },
515
+ {
516
+ type: "string"
517
+ }
518
+ ]
519
+ },
520
+ Z: {
521
+ anyOf: [
522
+ {
523
+ type: "number"
524
+ },
525
+ {
526
+ type: "string"
527
+ }
528
+ ]
529
+ },
530
+ _: {
531
+ type: "string",
532
+ description: "Comment"
533
+ }
534
+ }
535
+ },
536
+ rotation: {
537
+ type: "object",
538
+ additionalProperties: false,
539
+ properties: {
540
+ Q: {
541
+ description: "If true, the rotation is considered to be a Quaternion. Otherwise, it's interpreted as Euler arcs and W will be ignored.",
542
+ type: "boolean"
543
+ },
544
+ X: {
545
+ anyOf: [
546
+ {
547
+ type: "number"
548
+ },
549
+ {
550
+ type: "string"
551
+ }
552
+ ]
553
+ },
554
+ Y: {
555
+ anyOf: [
556
+ {
557
+ type: "number"
558
+ },
559
+ {
560
+ type: "string"
561
+ }
562
+ ]
563
+ },
564
+ Z: {
565
+ anyOf: [
566
+ {
567
+ type: "number"
568
+ },
569
+ {
570
+ type: "string"
571
+ }
572
+ ]
573
+ },
574
+ W: {
575
+ anyOf: [
576
+ {
577
+ type: "number"
578
+ },
579
+ {
580
+ type: "string"
581
+ }
582
+ ]
583
+ },
584
+ _: {
585
+ type: "string",
586
+ description: "Comment"
587
+ }
588
+ }
589
+ },
590
+ igxcPath: {
591
+ type: "string",
592
+ description: "Relative path of the target object",
593
+ pattern: "^((o|e)\\d+(\\.(o|e)\\d+)*|\\.)$"
594
+ },
595
+ param: {
596
+ type: "string",
597
+ pattern: "^Param\\d+$"
598
+ },
599
+ kinematicChain: {
600
+ type: "object",
601
+ additionalProperties: false,
602
+ properties: {
603
+ GeometryBase: {
604
+ type: "string"
605
+ },
606
+ Joints: {
607
+ type: "array",
608
+ items: {
609
+ type: "object",
610
+ additionalProperties: false,
611
+ properties: {
612
+ Name: {
613
+ oneOf: [
614
+ {
615
+ $ref: "#/definitions/param"
616
+ },
617
+ {
618
+ type: "string"
619
+ }
620
+ ]
621
+ },
622
+ HeadX: {
623
+ oneOf: [
624
+ {
625
+ $ref: "#/definitions/param"
626
+ },
627
+ {
628
+ $ref: "#/definitions/igxcPath"
629
+ }
630
+ ]
631
+ },
632
+ HeadY: {
633
+ oneOf: [
634
+ {
635
+ $ref: "#/definitions/param"
636
+ },
637
+ {
638
+ $ref: "#/definitions/igxcPath"
639
+ }
640
+ ]
641
+ },
642
+ HeadZ: {
643
+ oneOf: [
644
+ {
645
+ $ref: "#/definitions/param"
646
+ },
647
+ {
648
+ $ref: "#/definitions/igxcPath"
649
+ }
650
+ ]
651
+ },
652
+ Tail: {
653
+ oneOf: [
654
+ {
655
+ $ref: "#/definitions/param"
656
+ },
657
+ {
658
+ $ref: "#/definitions/igxcPath"
659
+ }
660
+ ]
661
+ },
662
+ LimitLeft: {
663
+ type: "number"
664
+ },
665
+ LimitRight: {
666
+ type: "number"
667
+ },
668
+ LimitUp: {
669
+ type: "number"
670
+ },
671
+ LimitDown: {
672
+ type: "number"
673
+ },
674
+ FollowJointNode: {
675
+ $ref: "#/definitions/igxcPath"
676
+ },
677
+ _TargetNodeForFollow: {
678
+ type: "string"
679
+ }
680
+ }
681
+ }
682
+ },
683
+ Target: {
684
+ oneOf: [
685
+ {
686
+ $ref: "#/definitions/igxcPath"
687
+ },
688
+ {
689
+ $ref: "#/definitions/param"
690
+ },
691
+ {
692
+ type: "string",
693
+ enum: [
694
+ "subbase"
695
+ ]
696
+ }
697
+ ]
698
+ },
699
+ Parent: {
700
+ oneOf: [
701
+ {
702
+ $ref: "#/definitions/igxcPath"
703
+ },
704
+ {
705
+ type: "string",
706
+ enum: [
707
+ "root"
708
+ ]
709
+ }
710
+ ]
711
+ },
712
+ Tolerance: {
713
+ type: "number"
714
+ },
715
+ MaxIterations: {
716
+ type: "integer"
717
+ },
718
+ _: {
719
+ type: "string",
720
+ description: "Comment"
721
+ },
722
+ __: {
723
+ type: "string",
724
+ description: "Super Comment"
725
+ }
726
+ }
727
+ }
728
+ }
729
+ };
730
+
731
+ const createAnimationBuildParticipant = (location, manifest)=>{
732
+ return (env)=>{
733
+ env.onBuildStart();
734
+ bundleAnimations(location, manifest, env.log).then((result)=>{
735
+ env.onBuildEnd({
736
+ type: "success",
737
+ artefacts: {
738
+ js: (result == null ? void 0 : result.js) ?? ""
739
+ }
740
+ });
741
+ }).catch((err)=>{
742
+ env.onBuildEnd({
743
+ type: "error",
744
+ error: err.message
745
+ });
746
+ });
747
+ return {
748
+ destroy: ()=>{}
749
+ };
750
+ };
751
+ };
752
+ const createAnimationWatchBuildParticipant = (location, manifest)=>{
753
+ return (env)=>{
754
+ env.onBuildStart();
755
+ bundleAnimations(location, manifest, env.log).then((result)=>{
756
+ env.onBuildEnd({
757
+ type: "success",
758
+ artefacts: {
759
+ js: (result == null ? void 0 : result.js) ?? ""
760
+ }
761
+ });
762
+ }).catch((err)=>{
763
+ env.onBuildEnd({
764
+ type: "error",
765
+ error: err.message
766
+ });
767
+ });
768
+ (async ()=>{
769
+ for await (const event of fs$1.watch(location.scriptsDir)){
770
+ if (event.filename.endsWith(".animation.json")) {
771
+ env.onBuildStart();
772
+ try {
773
+ const result = await bundleAnimations(location, manifest, env.log);
774
+ env.onBuildEnd({
775
+ type: "success",
776
+ artefacts: {
777
+ js: (result == null ? void 0 : result.js) ?? ""
778
+ }
779
+ });
780
+ } catch (err) {
781
+ env.onBuildEnd({
782
+ type: "error",
783
+ error: err.message
784
+ });
785
+ }
786
+ }
787
+ }
788
+ })();
789
+ return {
790
+ destroy: ()=>{}
791
+ };
792
+ };
793
+ };
794
+ const bundleAnimations = async (location, manifest, logStep)=>{
795
+ const animations = new Map();
796
+ for (const scriptFilePath of readPackageAnimationList(location)){
797
+ const content = await fs$1.readFile(scriptFilePath, {
798
+ encoding: "utf8"
799
+ });
800
+ let data;
801
+ try {
802
+ data = JSON.parse(content);
803
+ } catch (err) {
804
+ const relativePath = path.relative(location.path, scriptFilePath);
805
+ if (err instanceof SyntaxError) {
806
+ throw new Error(`Encountered invalid syntax in file "${relativePath}": ${String(err)}`);
807
+ }
808
+ throw new Error(`Encountered an unexpected error while parsing animation json file at path "${relativePath}"`, {
809
+ cause: err
810
+ });
811
+ }
812
+ if (!data.Id) {
813
+ const fileName = path.basename(scriptFilePath, ".animation.json");
814
+ data.Id = fileName;
815
+ }
816
+ (await getAnimationJsonValidation())(data);
817
+ delete data.$schema;
818
+ animations.set(data.Id, JSON.stringify(data));
819
+ }
820
+ if (animations.size > 0) {
821
+ const scope = manifest.Scope ?? manifest.Package;
822
+ const scopeParts = scope.split(".");
823
+ let js = createNamespace(scopeParts);
824
+ for (const [name, content] of animations){
825
+ js += `${scope}["${name}"] = ` + content + ";";
826
+ logStep(`Adding animation ${scope}.${name}`);
827
+ }
828
+ return {
829
+ js
830
+ };
831
+ }
832
+ return undefined;
833
+ };
834
+ const createNamespace = (parts)=>{
835
+ let code = `var ${parts[0]};`;
836
+ for(let index = 0; index < parts.length; index++){
837
+ const path = parts.slice(0, index + 1).join(".");
838
+ code += `\n(${path} = ${path} || {});`;
839
+ }
840
+ return code;
841
+ };
842
+ let validateAnimationJson;
843
+ const getAnimationJsonValidation = async ()=>{
844
+ if (validateAnimationJson === undefined) {
845
+ validateAnimationJson = new Ajv({
846
+ coerceTypes: true,
847
+ allErrors: true,
848
+ removeAdditional: true,
849
+ useDefaults: "empty",
850
+ validateSchema: "log"
851
+ }).compile(animationSchema);
852
+ }
853
+ return validateAnimationJson;
854
+ };
855
+
856
+ const buildFolders = async (options)=>{
857
+ if (options.outDir !== undefined && options.clean) {
858
+ await fs$1.rm(options.outDir, {
859
+ recursive: true
860
+ });
861
+ }
862
+ const workspace = options.workspace;
863
+ const folders = options.packages;
864
+ let sortedPackages = sortPackagesByBuildOrder(folders);
865
+ let index = 1;
866
+ const manifests = new Map(sortedPackages.map((location)=>[
867
+ location,
868
+ readPackageCreatorManifest(location)
869
+ ]));
870
+ const maxNameLength = Array.from(manifests.values(), (manifest)=>manifest.Package.length).reduce((acc, length)=>Math.max(acc, length), 0);
871
+ for (const location of sortedPackages){
872
+ await ensureTsConfig(location);
873
+ const data = manifests.get(location);
874
+ const logStep = (step)=>logPackageMessage(data.Package, step, index, folders.length, maxNameLength);
875
+ const outputDirectory = options.outDir || location.scriptsDir;
876
+ await fs$1.mkdir(outputDirectory, {
877
+ recursive: true
878
+ });
879
+ const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
880
+ if (options.banner) {
881
+ manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
882
+ }
883
+ manager.addParticipant("tsc", createTSCBuildParticipant(location, outputDirectory));
884
+ manager.addParticipant("animation", createAnimationBuildParticipant(location, data));
885
+ await new Promise((resolve, reject)=>{
886
+ manager.addListener("start", ()=>{
887
+ logStep(`Build started`);
888
+ });
889
+ manager.addListener("error", (error)=>{
890
+ reject(new Error(error));
891
+ });
892
+ manager.addListener("build", ()=>{
893
+ logStep(`Build complete`);
894
+ resolve();
895
+ });
896
+ manager.run();
897
+ });
898
+ if (options.docs) {
899
+ logStep("Generating typedoc documentation");
900
+ await generateDocs(location, path.join(outputDirectory, `${data.Package}.d.ts`), path.join(workspace.path, "docs", data.Package), data.Package);
901
+ }
902
+ index++;
903
+ }
904
+ };
905
+ const buildFoldersWatch = async (options)=>{
906
+ if (options.outDir !== undefined && options.clean) {
907
+ await fs$1.rm(options.outDir, {
908
+ recursive: true
909
+ });
910
+ }
911
+ const workspace = options.workspace;
912
+ const folders = options.packages;
913
+ let sortedPackages = sortPackagesByBuildOrder(folders);
914
+ let index = 1;
915
+ const manifests = new Map(sortedPackages.map((location)=>[
916
+ location,
917
+ readPackageCreatorManifest(location)
918
+ ]));
919
+ const maxNameLength = Array.from(manifests.values(), (manifest)=>manifest.Package.length).reduce((acc, length)=>Math.max(acc, length), 0);
920
+ for (const location of sortedPackages){
921
+ await ensureTsConfig(location);
922
+ const data = manifests.get(location);
923
+ const currentIndex = index;
924
+ const logStep = (step)=>logPackageMessage(data.Package, step, currentIndex, folders.length, maxNameLength);
925
+ const outputDirectory = options.outDir || location.scriptsDir;
926
+ await fs$1.mkdir(outputDirectory, {
927
+ recursive: true
928
+ });
929
+ const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
930
+ if (options.banner) {
931
+ manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
932
+ }
933
+ manager.addParticipant("tsc", createTSCWatchBuildParticipant(location, outputDirectory));
934
+ manager.addParticipant("animation", createAnimationWatchBuildParticipant(location, data));
935
+ await new Promise((resolve, reject)=>{
936
+ manager.addListener("start", ()=>{
937
+ logStep(`Build started`);
938
+ });
939
+ manager.addListener("error", (error)=>{
940
+ logStep(`Build failed: ${error}`);
941
+ resolve();
942
+ });
943
+ manager.addListener("build", ()=>{
944
+ logStep(`Build complete`);
945
+ resolve();
946
+ });
947
+ manager.run();
948
+ });
949
+ index++;
950
+ }
951
+ await new Promise(()=>{});
952
+ };
953
+ const writeBuildResult = async (buildResult, manifest, location, workspace, outputDirectory, minimize, logStep)=>{
954
+ let js = buildResult.js;
955
+ if (buildResult.sourceMap) {
956
+ js += `\n//# sourceMappingURL=${manifest.Package}.js.map`;
957
+ }
958
+ await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.js`), js, {
959
+ encoding: "utf8"
960
+ });
961
+ if (buildResult.definitions !== undefined) {
962
+ await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.d.ts`), buildResult.definitions, {
963
+ encoding: "utf8"
964
+ });
965
+ }
966
+ if (buildResult.sourceMap !== undefined) {
967
+ await fs$1.writeFile(path.join(outputDirectory, `${manifest.Package}.js.map`), buildResult.sourceMap, {
968
+ encoding: "utf8"
969
+ });
970
+ }
971
+ if (minimize) {
972
+ const minifyResult = await terser.minify(js, {
973
+ ecma: 5,
974
+ sourceMap: {
975
+ content: buildResult.sourceMap,
976
+ includeSources: false
977
+ }
978
+ });
979
+ const minifiedPath = path.join(outputDirectory, `${manifest.Package}.min.js`);
980
+ await fs$1.writeFile(minifiedPath, minifyResult.code, {
981
+ encoding: "utf8"
982
+ });
983
+ if (minifyResult.map !== undefined) {
984
+ await fs$1.writeFile(minifiedPath + ".map", typeof minifyResult.map === "string" ? minifyResult.map : JSON.stringify(minifyResult.map), {
985
+ encoding: "utf8"
986
+ });
987
+ }
988
+ }
989
+ if (location.path.includes("Basics") && buildResult.definitions !== undefined) {
990
+ await fs$1.mkdir(path.join(workspace.path, "lib"), {
991
+ recursive: true
992
+ });
993
+ logStep("Copying basics definition file to the lib folder");
994
+ await fs$1.writeFile(path.join(workspace.path, "lib", `${manifest.Package}.d.ts`), buildResult.definitions, {
995
+ encoding: "utf8"
996
+ });
997
+ }
998
+ };
999
+ const createBannerCommentBuildParticipant = (options)=>(env)=>{
1000
+ env.onBuildStart();
1001
+ const banner = createBannerComment(options);
1002
+ env.onBuildEnd({
1003
+ type: "success",
1004
+ artefacts: {
1005
+ js: banner ?? "",
1006
+ definitions: banner ?? ""
1007
+ }
1008
+ });
1009
+ return {
1010
+ destroy: ()=>{}
1011
+ };
1012
+ };
1013
+ const ensureTsConfig = async (location)=>{
1014
+ const tsconfigPath = path.join(location.scriptsDir, "tsconfig.json");
1015
+ try {
1016
+ const content = JSON.parse(await fs$1.readFile(tsconfigPath, "utf8"));
1017
+ applyTsConfigOption(content);
1018
+ await fs$1.writeFile(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
1019
+ } catch (err) {
1020
+ if (!isErrorENOENT(err)) {
1021
+ throw err;
1022
+ }
1023
+ const content = {};
1024
+ applyTsConfigOption(content);
1025
+ await fs$1.writeFile(tsconfigPath, JSON.stringify(content, undefined, "\t"), "utf8");
1026
+ }
1027
+ };
1028
+ const applyTsConfigOption = (data)=>{
1029
+ data.compilerOptions = data.compilerOptions ?? {};
1030
+ data.compilerOptions.target = "es5";
1031
+ data.compilerOptions.lib = [
1032
+ "es5",
1033
+ "dom"
1034
+ ];
1035
+ };
1036
+ const sortPackagesByBuildOrder = (folders)=>{
1037
+ const packages = Array.from(folders).reduce((acc, location)=>{
1038
+ const data = readPackageNpmManifest(location);
1039
+ if (data !== undefined) {
1040
+ acc[data.name] = {
1041
+ data,
1042
+ location
1043
+ };
1044
+ } else {
1045
+ acc[location.path] = {
1046
+ data: undefined,
1047
+ location
1048
+ };
1049
+ }
1050
+ return acc;
1051
+ }, {});
1052
+ const packageDependencies = Object.getOwnPropertyNames(packages).reduce((acc, packageName)=>{
1053
+ const packageData = packages[packageName];
1054
+ if (packageData.data === undefined) {
1055
+ acc[packageName] = [];
1056
+ } else {
1057
+ acc[packageName] = Object.getOwnPropertyNames({
1058
+ ...packageData.data.devDependencies,
1059
+ ...packageData.data.dependencies,
1060
+ ...packageData.data.peerDependencies
1061
+ }).filter((packageName)=>packages[packageName] !== undefined);
1062
+ }
1063
+ return acc;
1064
+ }, {});
1065
+ const sortedPackages = toposort(packageDependencies);
1066
+ const result = [];
1067
+ for (const packageName of sortedPackages){
1068
+ const location = packages[packageName].location;
1069
+ if (readPackageCreatorManifest(location).Package.endsWith(".Basics")) {
1070
+ result.unshift(location);
1071
+ } else {
1072
+ result.push(location);
1073
+ }
1074
+ }
1075
+ return result;
1076
+ };
1077
+ const createBannerComment = (banner)=>{
1078
+ const bannerParts = [];
1079
+ if (banner.text) {
1080
+ bannerParts.push(" * " + banner.text);
1081
+ }
1082
+ {
1083
+ const details = [];
1084
+ if (banner.version) {
1085
+ details.push(`Version: ${banner.version}`);
1086
+ }
1087
+ if (banner.commit) {
1088
+ if (banner.commitDirty) {
1089
+ details.push(`Commit: ${banner.commit} (dirty)`);
1090
+ } else {
1091
+ details.push(`Commit: ${banner.commit}`);
1092
+ }
1093
+ }
1094
+ if (banner.date) {
1095
+ details.push(`Date: ${banner.date.toISOString()}`);
1096
+ }
1097
+ const detailsText = details.map((line)=>` * ${line}`).join("\n");
1098
+ if (detailsText) {
1099
+ bannerParts.push(detailsText);
1100
+ }
1101
+ }
1102
+ const bannerText = bannerParts.join("\n\n");
1103
+ if (bannerText) {
1104
+ return `/*
1105
+ ${bannerText}
1106
+ *
1107
+ * @preserve
1108
+ */`;
1109
+ }
1110
+ return undefined;
1111
+ };
1112
+
1113
+ var index = /*#__PURE__*/Object.freeze({
1114
+ __proto__: null,
1115
+ buildFolders: buildFolders,
1116
+ buildFoldersWatch: buildFoldersWatch
1117
+ });
1118
+
1119
+ export { buildFolders as b, index as i, logPackageMessage as l };
1120
+ //# sourceMappingURL=index-e6ead55c.mjs.map