@intelligentgraphics/ig.gfx.packager 3.0.21 → 3.0.23

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 (28) hide show
  1. package/build/bin.mjs +1 -1
  2. package/build/{cli-91fabb36.mjs → cli-t3HbtHpD.mjs} +40 -70
  3. package/build/cli-t3HbtHpD.mjs.map +1 -0
  4. package/build/{dependencies-7711a9db.mjs → dependencies-DevWjwri.mjs} +2 -2
  5. package/build/{dependencies-7711a9db.mjs.map → dependencies-DevWjwri.mjs.map} +1 -1
  6. package/build/{generateIndex-47c082d0.mjs → generateIndex-BtHP1bP3.mjs} +4 -4
  7. package/build/{generateIndex-47c082d0.mjs.map → generateIndex-BtHP1bP3.mjs.map} +1 -1
  8. package/build/{generateParameterType-10d124a6.mjs → generateParameterType-DyylDiF2.mjs} +3 -3
  9. package/build/{generateParameterType-10d124a6.mjs.map → generateParameterType-DyylDiF2.mjs.map} +1 -1
  10. package/build/{index-e6ead55c.mjs → index-C3Hd8xoM.mjs} +57 -42
  11. package/build/index-C3Hd8xoM.mjs.map +1 -0
  12. package/build/{index-ca04836f.mjs → index-CNupsFSp.mjs} +187 -182
  13. package/build/index-CNupsFSp.mjs.map +1 -0
  14. package/build/{postinstall-0ea76778.mjs → postinstall-D2hLZlaK.mjs} +3 -3
  15. package/build/{postinstall-0ea76778.mjs.map → postinstall-D2hLZlaK.mjs.map} +1 -1
  16. package/build/{publishNpm-aadd7dc2.mjs → publishNpm-h9T6BVws.mjs} +13 -7
  17. package/build/publishNpm-h9T6BVws.mjs.map +1 -0
  18. package/build/{scripts-7ed8dff6.mjs → scripts-EvIjiH6G.mjs} +1 -1
  19. package/build/{scripts-7ed8dff6.mjs.map → scripts-EvIjiH6G.mjs.map} +1 -1
  20. package/build/{versionFile-ad981e93.mjs → versionFile-7rrD5z3c.mjs} +7 -11
  21. package/build/{versionFile-ad981e93.mjs.map → versionFile-7rrD5z3c.mjs.map} +1 -1
  22. package/lib/lib.mjs +243 -228
  23. package/package.json +12 -12
  24. package/readme.md +28 -0
  25. package/build/cli-91fabb36.mjs.map +0 -1
  26. package/build/index-ca04836f.mjs.map +0 -1
  27. package/build/index-e6ead55c.mjs.map +0 -1
  28. package/build/publishNpm-aadd7dc2.mjs.map +0 -1
package/lib/lib.mjs CHANGED
@@ -13,6 +13,7 @@ import typedoc from 'typedoc';
13
13
  import EventEmitter from 'events';
14
14
  import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
15
15
  import Ajv from 'ajv';
16
+ import { EOL } from 'os';
16
17
  import { pipeline } from 'stream/promises';
17
18
  import { exec } from 'child_process';
18
19
  import { promisify } from 'util';
@@ -265,11 +266,26 @@ const readStringFromFileOrUndefined = (filePath)=>{
265
266
  }
266
267
  };
267
268
 
268
- const logPackageMessage = (name, step, index, total, maxNameLength = 15)=>{
269
+ const consoleReporter = {
270
+ log (message) {
271
+ console.log(message);
272
+ },
273
+ error (message, _error) {
274
+ console.error(message);
275
+ }
276
+ };
277
+ const createPackageScopedReporter = (reporter, scope, index, total, maxNameLength = 15)=>{
269
278
  const numLength = total === undefined ? undefined : total.toString().length;
270
279
  const indexString = total === undefined || total < 2 ? "" : `${index.toString().padStart(numLength, "0")}/${total} `;
271
- const identifierString = `${indexString}${name.padEnd(maxNameLength)}`;
272
- console.log(`${identifierString} >> ${step}`);
280
+ const identifierString = `${indexString}${scope.padEnd(maxNameLength)}`;
281
+ return {
282
+ log (message) {
283
+ reporter.log(`${identifierString} >> ${message}`);
284
+ },
285
+ error (message, error) {
286
+ reporter.error(`${identifierString} >> ${message}`, error);
287
+ }
288
+ };
273
289
  };
274
290
 
275
291
  const getPackageTypescriptFiles = (location)=>glob.sync("**/*.ts", {
@@ -284,7 +300,7 @@ const PLUGIN_ID = "0feba3a0-b6d1-11e6-9598-0800200c9a66";
284
300
  *
285
301
  * @param {SessionStartParams} params
286
302
  * @returns
287
- */ const startSession = async ({ url , authentication , ...params })=>{
303
+ */ const startSession = async ({ url, authentication, ...params })=>{
288
304
  const payload = {
289
305
  ...params,
290
306
  user: undefined,
@@ -298,7 +314,7 @@ const PLUGIN_ID = "0feba3a0-b6d1-11e6-9598-0800200c9a66";
298
314
  } else if (authentication.type === "license") {
299
315
  payload.license = authentication.license;
300
316
  }
301
- const { data: { session: sessionId , state , response } } = await axios.post(`Session/Start2`, JSON.stringify(payload), {
317
+ const { data: { session: sessionId, state, response } } = await axios.post(`Session/Start2`, JSON.stringify(payload), {
302
318
  baseURL: url
303
319
  });
304
320
  if (state !== "SUCCESS") {
@@ -321,11 +337,11 @@ const closeSession = async (session)=>{
321
337
  baseURL: session.url
322
338
  });
323
339
  };
324
- const uploadPackageFromStream = async (session, { name , version }, stream)=>{
325
- await uploadPackageToUrl(session.url, `UploadPackage/${session.sessionId}/${name}_${version}/`, stream);
340
+ const uploadPackageFromStream = async (session, { name, version }, stream)=>{
341
+ await uploadPackageToUrl(session.url, `UploadPackage/${session.sessionId}/${name}_${version}`, stream);
326
342
  };
327
343
  const uploadPackageToUrl = async (url, path, stream)=>{
328
- const { data , status } = await axios.post(path, stream, {
344
+ const { data, status } = await axios.post(path, stream, {
329
345
  baseURL: url
330
346
  });
331
347
  let objectBody;
@@ -360,7 +376,7 @@ const uploadPackageToUrl = async (url, path, stream)=>{
360
376
  return data;
361
377
  };
362
378
  const getExistingPackages = async (session)=>{
363
- const { data } = await axios.get(`Script/GetInformation/${session.sessionId}`, {
379
+ const { data } = await axios.get(`Script/GetInformation/${session.sessionId}`, {
364
380
  baseURL: session.url,
365
381
  validateStatus: (status)=>status === 404 || status === 200
366
382
  }).catch((err)=>{
@@ -370,7 +386,7 @@ const getExistingPackages = async (session)=>{
370
386
  };
371
387
 
372
388
  const tryReadTsConfig = (location)=>{
373
- const { config } = ts.readConfigFile(path.join(location.scriptsDir, "tsconfig.json"), (path)=>{
389
+ const { config } = ts.readConfigFile(path.join(location.scriptsDir, "tsconfig.json"), (path)=>{
374
390
  try {
375
391
  return fs.readFileSync(path, "utf8");
376
392
  } catch {
@@ -396,6 +412,7 @@ const createTSCBuildParticipant = (location, outputDir)=>(env)=>{
396
412
  }
397
413
  try {
398
414
  env.onBuildStart();
415
+ env.log("Compiling typescript files");
399
416
  const compilerOptions = getCompilerOptions(location, outputDir);
400
417
  const host = ts.createCompilerHost(compilerOptions);
401
418
  host.getCurrentDirectory = ()=>location.scriptsDir;
@@ -421,7 +438,7 @@ const createTSCBuildParticipant = (location, outputDir)=>(env)=>{
421
438
  const allDiagnostics = ts.getPreEmitDiagnostics(program);
422
439
  if (!emitResult.emitSkipped) {
423
440
  if (allDiagnostics.length > 0) {
424
- console.log(allDiagnostics.map(createErrorMessage).join("\n"));
441
+ console.log(ts.formatDiagnostics(allDiagnostics, host));
425
442
  }
426
443
  if (js === undefined || definitions === undefined) {
427
444
  throw new Error(`Unexpected: no js or definitions were created`);
@@ -435,7 +452,7 @@ const createTSCBuildParticipant = (location, outputDir)=>(env)=>{
435
452
  }
436
453
  });
437
454
  } else {
438
- const error = allDiagnostics.map(createErrorMessage).join("\n");
455
+ const error = ts.formatDiagnostics(allDiagnostics, host);
439
456
  throw new Error(error);
440
457
  }
441
458
  } catch (err) {
@@ -449,7 +466,7 @@ const createTSCBuildParticipant = (location, outputDir)=>(env)=>{
449
466
  };
450
467
  };
451
468
  const createTSCWatchBuildParticipant = (location, outputDir)=>{
452
- return ({ onBuildStart , onBuildEnd })=>{
469
+ return ({ onBuildStart, onBuildEnd })=>{
453
470
  let state = {
454
471
  diagnostics: [],
455
472
  js: undefined,
@@ -468,7 +485,7 @@ const createTSCWatchBuildParticipant = (location, outputDir)=>{
468
485
  }
469
486
  }
470
487
  };
471
- const reportDiagnostic = (diagnostic)=>{
488
+ const registerDiagnostic = (diagnostic)=>{
472
489
  switch(diagnostic.code){
473
490
  // file not found - https://github.com/microsoft/TypeScript/blob/93e6b9da0c4cb164ca90a5a1b07415e81e97f2b1/src/compiler/diagnosticMessages.json#L4640
474
491
  // probably deleted -> ignore
@@ -503,7 +520,7 @@ const createTSCWatchBuildParticipant = (location, outputDir)=>{
503
520
  sourceMap: undefined
504
521
  };
505
522
  if (emitState.diagnostics.length > 0) {
506
- const message = emitState.diagnostics.map(createErrorMessage).join("\n");
523
+ const message = ts.formatDiagnostics(emitState.diagnostics, formattingHost);
507
524
  onBuildEnd({
508
525
  type: "error",
509
526
  error: message
@@ -530,7 +547,12 @@ const createTSCWatchBuildParticipant = (location, outputDir)=>{
530
547
  break;
531
548
  }
532
549
  };
533
- const host = ts.createWatchCompilerHost(path.join(location.scriptsDir, "tsconfig.json"), getCompilerOptions(location, outputDir), customSys, ts.createSemanticDiagnosticsBuilderProgram, reportDiagnostic, reportWatchStatusChanged);
550
+ const host = ts.createWatchCompilerHost(path.join(location.scriptsDir, "tsconfig.json"), getCompilerOptions(location, outputDir), customSys, ts.createSemanticDiagnosticsBuilderProgram, registerDiagnostic, reportWatchStatusChanged);
551
+ const formattingHost = {
552
+ getCanonicalFileName: (path)=>path,
553
+ getCurrentDirectory: host.getCurrentDirectory,
554
+ getNewLine: ()=>ts.sys.newLine
555
+ };
534
556
  const watchProgram = ts.createWatchProgram(host);
535
557
  const files = getPackageTypescriptFiles(location);
536
558
  if (files.length === 0) {
@@ -550,14 +572,6 @@ const createTSCWatchBuildParticipant = (location, outputDir)=>{
550
572
  };
551
573
  };
552
574
  };
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
575
  const getCompilerOptions = (location, outputDir)=>{
562
576
  const config = tryReadTsConfig(location);
563
577
  config.compilerOptions.lib = [
@@ -635,11 +649,11 @@ const toposort = (packages)=>{
635
649
  };
636
650
 
637
651
  class BuildManager extends EventEmitter {
638
- constructor(manifest, writer, logStep){
652
+ constructor(manifest, writer, reporter){
639
653
  super();
640
654
  this.manifest = manifest;
641
655
  this.writer = writer;
642
- this.logStep = logStep;
656
+ this.reporter = reporter;
643
657
  this.participants = new Map();
644
658
  this.states = new Map();
645
659
  }
@@ -674,7 +688,7 @@ class BuildManager extends EventEmitter {
674
688
  this.states.set(name, result);
675
689
  this.maybeEmit();
676
690
  },
677
- log: this.logStep
691
+ log: (message)=>this.reporter.log(message)
678
692
  });
679
693
  }
680
694
  }
@@ -1095,8 +1109,7 @@ const createAnimationBuildParticipant = (location, manifest)=>{
1095
1109
  };
1096
1110
  };
1097
1111
  };
1098
- const createAnimationWatchBuildParticipant = (location, manifest)=>{
1099
- return (env)=>{
1112
+ const createAnimationWatchBuildParticipant = (location, manifest)=>(env)=>{
1100
1113
  env.onBuildStart();
1101
1114
  bundleAnimations(location, manifest, env.log).then((result)=>{
1102
1115
  env.onBuildEnd({
@@ -1113,7 +1126,8 @@ const createAnimationWatchBuildParticipant = (location, manifest)=>{
1113
1126
  });
1114
1127
  (async ()=>{
1115
1128
  for await (const event of fs$1.watch(location.scriptsDir)){
1116
- if (event.filename.endsWith(".animation.json")) {
1129
+ var _event_filename;
1130
+ if ((_event_filename = event.filename) == null ? void 0 : _event_filename.endsWith(".animation.json")) {
1117
1131
  env.onBuildStart();
1118
1132
  try {
1119
1133
  const result = await bundleAnimations(location, manifest, env.log);
@@ -1136,7 +1150,6 @@ const createAnimationWatchBuildParticipant = (location, manifest)=>{
1136
1150
  destroy: ()=>{}
1137
1151
  };
1138
1152
  };
1139
- };
1140
1153
  const bundleAnimations = async (location, manifest, logStep)=>{
1141
1154
  const animations = new Map();
1142
1155
  for (const scriptFilePath of readPackageAnimationList(location)){
@@ -1205,6 +1218,7 @@ const buildFolders = async (options)=>{
1205
1218
  recursive: true
1206
1219
  });
1207
1220
  }
1221
+ const baseReporter = options.reporter ?? consoleReporter;
1208
1222
  const workspace = options.workspace;
1209
1223
  const folders = options.packages;
1210
1224
  let sortedPackages = sortPackagesByBuildOrder(folders);
@@ -1217,12 +1231,12 @@ const buildFolders = async (options)=>{
1217
1231
  for (const location of sortedPackages){
1218
1232
  await ensureTsConfig(location);
1219
1233
  const data = manifests.get(location);
1220
- const logStep = (step)=>logPackageMessage(data.Package, step, index, folders.length, maxNameLength);
1234
+ const reporter = options.preparedReporter ?? createPackageScopedReporter(baseReporter, data.Package, index, folders.length, maxNameLength);
1221
1235
  const outputDirectory = options.outDir || location.scriptsDir;
1222
1236
  await fs$1.mkdir(outputDirectory, {
1223
1237
  recursive: true
1224
1238
  });
1225
- const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
1239
+ const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, reporter), reporter);
1226
1240
  if (options.banner) {
1227
1241
  manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
1228
1242
  }
@@ -1230,19 +1244,19 @@ const buildFolders = async (options)=>{
1230
1244
  manager.addParticipant("animation", createAnimationBuildParticipant(location, data));
1231
1245
  await new Promise((resolve, reject)=>{
1232
1246
  manager.addListener("start", ()=>{
1233
- logStep(`Build started`);
1247
+ reporter.log(`Build started`);
1234
1248
  });
1235
1249
  manager.addListener("error", (error)=>{
1236
1250
  reject(new Error(error));
1237
1251
  });
1238
1252
  manager.addListener("build", ()=>{
1239
- logStep(`Build complete`);
1253
+ reporter.log(`Build complete`);
1240
1254
  resolve();
1241
1255
  });
1242
1256
  manager.run();
1243
1257
  });
1244
1258
  if (options.docs) {
1245
- logStep("Generating typedoc documentation");
1259
+ reporter.log("Generating typedoc documentation");
1246
1260
  await generateDocs(location, path.join(outputDirectory, `${data.Package}.d.ts`), path.join(workspace.path, "docs", data.Package), data.Package);
1247
1261
  }
1248
1262
  index++;
@@ -1265,14 +1279,14 @@ const buildFoldersWatch = async (options)=>{
1265
1279
  const maxNameLength = Array.from(manifests.values(), (manifest)=>manifest.Package.length).reduce((acc, length)=>Math.max(acc, length), 0);
1266
1280
  for (const location of sortedPackages){
1267
1281
  await ensureTsConfig(location);
1282
+ const baseReporter = options.reporter ?? consoleReporter;
1268
1283
  const data = manifests.get(location);
1269
- const currentIndex = index;
1270
- const logStep = (step)=>logPackageMessage(data.Package, step, currentIndex, folders.length, maxNameLength);
1284
+ const reporter = createPackageScopedReporter(baseReporter, data.Package, index, folders.length, maxNameLength);
1271
1285
  const outputDirectory = options.outDir || location.scriptsDir;
1272
1286
  await fs$1.mkdir(outputDirectory, {
1273
1287
  recursive: true
1274
1288
  });
1275
- const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, logStep), logStep);
1289
+ const manager = new BuildManager(data, (result)=>writeBuildResult(result, data, location, workspace, outputDirectory, options.minimize, reporter), reporter);
1276
1290
  if (options.banner) {
1277
1291
  manager.addParticipant("banner", createBannerCommentBuildParticipant(options.banner));
1278
1292
  }
@@ -1280,14 +1294,14 @@ const buildFoldersWatch = async (options)=>{
1280
1294
  manager.addParticipant("animation", createAnimationWatchBuildParticipant(location, data));
1281
1295
  await new Promise((resolve, reject)=>{
1282
1296
  manager.addListener("start", ()=>{
1283
- logStep(`Build started`);
1297
+ reporter.log(`Build started`);
1284
1298
  });
1285
1299
  manager.addListener("error", (error)=>{
1286
- logStep(`Build failed: ${error}`);
1300
+ reporter.log(`Build failed: ${EOL}${error}`);
1287
1301
  resolve();
1288
1302
  });
1289
1303
  manager.addListener("build", ()=>{
1290
- logStep(`Build complete`);
1304
+ reporter.log(`Build complete`);
1291
1305
  resolve();
1292
1306
  });
1293
1307
  manager.run();
@@ -1296,7 +1310,7 @@ const buildFoldersWatch = async (options)=>{
1296
1310
  }
1297
1311
  await new Promise(()=>{});
1298
1312
  };
1299
- const writeBuildResult = async (buildResult, manifest, location, workspace, outputDirectory, minimize, logStep)=>{
1313
+ const writeBuildResult = async (buildResult, manifest, location, workspace, outputDirectory, minimize, reporter)=>{
1300
1314
  let js = buildResult.js;
1301
1315
  if (buildResult.sourceMap) {
1302
1316
  js += `\n//# sourceMappingURL=${manifest.Package}.js.map`;
@@ -1315,6 +1329,7 @@ const writeBuildResult = async (buildResult, manifest, location, workspace, outp
1315
1329
  });
1316
1330
  }
1317
1331
  if (minimize) {
1332
+ reporter.log("Minifying the output");
1318
1333
  const minifyResult = await terser.minify(js, {
1319
1334
  ecma: 5,
1320
1335
  sourceMap: {
@@ -1336,7 +1351,7 @@ const writeBuildResult = async (buildResult, manifest, location, workspace, outp
1336
1351
  await fs$1.mkdir(path.join(workspace.path, "lib"), {
1337
1352
  recursive: true
1338
1353
  });
1339
- logStep("Copying basics definition file to the lib folder");
1354
+ reporter.log("Copying basics definition file to the lib folder");
1340
1355
  await fs$1.writeFile(path.join(workspace.path, "lib", `${manifest.Package}.d.ts`), buildResult.definitions, {
1341
1356
  encoding: "utf8"
1342
1357
  });
@@ -1507,13 +1522,9 @@ const getWorkspaceBannerText = (manifest)=>{
1507
1522
 
1508
1523
  // Stolen from ig.tools.core
1509
1524
  class PackageVersion {
1510
- static #_ = (()=>{
1511
- // https://regex101.com/r/90PEY9/1
1512
- this.fullTextMatcher = /(\d+)(\.(\d+)(\.(\d+)(\.(\d+))?(-([^\.]+)\.(\d+))?)?)?/;
1513
- })();
1514
- static #_1 = (()=>{
1515
- this.lineMatcher = /^(\d+)(\.(\d+)(\.(\d+)(\.(\d+))?(-([^\.]+)\.(\d+))?)?)?$/;
1516
- })();
1525
+ static #_ = // https://regex101.com/r/90PEY9/1
1526
+ this.fullTextMatcher = /(\d+)(\.(\d+)(\.(\d+)(\.(\d+))?(-([^\.]+)\.(\d+))?)?)?/;
1527
+ static #_2 = this.lineMatcher = /^(\d+)(\.(\d+)(\.(\d+)(\.(\d+))?(-([^\.]+)\.(\d+))?)?)?$/;
1517
1528
  static extractFromText(input, description) {
1518
1529
  if (input === undefined) {
1519
1530
  throw new Error(`Can not parse version from undefined`);
@@ -1633,7 +1644,7 @@ class PackageVersion {
1633
1644
  this.preRelease = undefined;
1634
1645
  this.buildNumber = 100;
1635
1646
  }
1636
- toVersionString({ buildNumber } = {}) {
1647
+ toVersionString({ buildNumber } = {}) {
1637
1648
  let version = [
1638
1649
  this.major,
1639
1650
  this.minor,
@@ -1826,7 +1837,7 @@ const buildArchiveFromPublishedPackage = (location, manifest, creatorPackage)=>{
1826
1837
  if (fs.existsSync(source)) {
1827
1838
  const images = fs.readdirSync(source);
1828
1839
  for (const file of images){
1829
- const { ext } = path.parse(file);
1840
+ const { ext } = path.parse(file);
1830
1841
  switch(ext){
1831
1842
  case ".png":
1832
1843
  case ".jpeg":
@@ -1850,28 +1861,26 @@ const notRuntimeScripts = [
1850
1861
  "Context",
1851
1862
  "Evaluator"
1852
1863
  ];
1853
- const buildArchiveFromPackage = async (packageLocation, data, binDir)=>{
1854
- const { domain } = parseCreatorPackageName(data);
1855
- const logStep = (step)=>logPackageMessage(data.Package, step);
1856
- const libFilePath = path.join(binDir, `${data.Package}.min.js`);
1864
+ const buildArchiveFromPackage = async (reporter, packageLocation, data, binDir, minified = true)=>{
1865
+ const { domain } = parseCreatorPackageName(data);
1857
1866
  const scriptDirectories = [
1858
1867
  packageLocation.path,
1859
1868
  packageLocation.scriptsDir
1860
1869
  ];
1861
1870
  if (data.Package === "IG.GFX.Standard") {
1862
- logStep(`Including Images folder`);
1871
+ reporter.log(`Including Images folder`);
1863
1872
  scriptDirectories.push(path.join(packageLocation.path, "Images"));
1864
1873
  }
1865
1874
  const manifest = readPackageCreatorManifest(packageLocation);
1866
1875
  if (manifest !== undefined) {
1867
1876
  if (manifest.RunTime && notRuntimeScripts.includes(manifest.Type)) {
1868
- logStep("Setting script RunTime to false because of script type");
1877
+ reporter.log("Setting script RunTime to false because of script type");
1869
1878
  writePackageCreatorManifest(packageLocation, {
1870
1879
  ...manifest,
1871
1880
  RunTime: false
1872
1881
  });
1873
1882
  } else if (!manifest.RunTime && runtimeScripts.includes(manifest.Type)) {
1874
- logStep("Setting script RunTime to true because of script type");
1883
+ reporter.log("Setting script RunTime to true because of script type");
1875
1884
  writePackageCreatorManifest(packageLocation, {
1876
1885
  ...manifest,
1877
1886
  RunTime: true
@@ -1880,6 +1889,7 @@ const buildArchiveFromPackage = async (packageLocation, data, binDir)=>{
1880
1889
  }
1881
1890
  let libFile;
1882
1891
  try {
1892
+ const libFilePath = minified ? path.join(binDir, `${data.Package}.min.js`) : path.join(binDir, `${data.Package}.js`);
1883
1893
  libFile = fs.readFileSync(libFilePath, {
1884
1894
  encoding: "utf8"
1885
1895
  });
@@ -1898,10 +1908,7 @@ const buildArchiveFromPackage = async (packageLocation, data, binDir)=>{
1898
1908
  library = `/* This file is part of the ${domain} Data Packages.
1899
1909
  * Copyright (C) ${date.getFullYear()} intelligentgraphics. All Rights Reserved. */`;
1900
1910
  }
1901
- const minifyResult = await terser.minify(library, {
1902
- ecma: 5
1903
- });
1904
- archive.file(`${data.Package}.js`, minifyResult.code);
1911
+ archive.file(`${data.Package}.js`, library);
1905
1912
  archive.file(PACKAGE_FILE, JSON.stringify(data, null, 2));
1906
1913
  const creatorIndex = readPackageCreatorIndex(packageLocation);
1907
1914
  if (creatorIndex !== undefined) {
@@ -1910,7 +1917,7 @@ const buildArchiveFromPackage = async (packageLocation, data, binDir)=>{
1910
1917
  for (const directory of scriptDirectories){
1911
1918
  try {
1912
1919
  for (const file of fs.readdirSync(directory)){
1913
- const { ext } = path.parse(file);
1920
+ const { ext } = path.parse(file);
1914
1921
  switch(ext){
1915
1922
  case ".png":
1916
1923
  case ".jpeg":
@@ -1922,20 +1929,174 @@ const buildArchiveFromPackage = async (packageLocation, data, binDir)=>{
1922
1929
  archive.file(file, fs.createReadStream(path.join(directory, file)));
1923
1930
  }
1924
1931
  } catch (err) {
1925
- console.error(`Script directory "${directory}" does not exist`);
1932
+ reporter.error(`Script directory "${directory}" does not exist`);
1926
1933
  }
1927
1934
  }
1928
1935
  return archive;
1929
1936
  };
1930
1937
 
1938
+ const createAssetServiceSessionManager = async (params)=>{
1939
+ const targetSession = await startSession(params);
1940
+ let basicsSession;
1941
+ return {
1942
+ getBasicsSession: async ()=>{
1943
+ if (targetSession.subDomain === "Basics") {
1944
+ return targetSession;
1945
+ }
1946
+ if (basicsSession === undefined) {
1947
+ basicsSession = await startSession({
1948
+ ...params,
1949
+ subDomain: "Basics"
1950
+ });
1951
+ }
1952
+ return basicsSession;
1953
+ },
1954
+ getTargetSession: ()=>targetSession,
1955
+ destroy: async ()=>{
1956
+ await closeSession(targetSession);
1957
+ if (basicsSession !== undefined) {
1958
+ await closeSession(basicsSession);
1959
+ }
1960
+ }
1961
+ };
1962
+ };
1963
+
1964
+ const synchronizeDependencies = async (workspaceLocation, creatorPackage, sessionManager, prompter, reporter, logUpToDate = false)=>{
1965
+ const libraries = determineWorkspaceIGLibraries(workspaceLocation);
1966
+ // If there are no libraries, we don't need to check for required versions
1967
+ if (libraries.length === 0) {
1968
+ return true;
1969
+ }
1970
+ const targetSession = sessionManager.getTargetSession();
1971
+ const rawUploadedPackages = await getExistingPackages(targetSession);
1972
+ const uploadedPackages = rawUploadedPackages.map((entry)=>{
1973
+ let version;
1974
+ try {
1975
+ version = parseVersionFromNumericVersion(entry.numericVersion);
1976
+ } catch (err) {
1977
+ throw new Error(`Encountered invalid format for version ${entry.numericVersion}`);
1978
+ }
1979
+ if (version.buildNumber < 100) {
1980
+ version.preRelease = {
1981
+ type: "beta",
1982
+ version: version.buildNumber
1983
+ };
1984
+ } else if (version.buildNumber > 100) {
1985
+ version.preRelease = {
1986
+ type: "patch",
1987
+ version: version.buildNumber - 100
1988
+ };
1989
+ }
1990
+ return {
1991
+ ...entry,
1992
+ version
1993
+ };
1994
+ });
1995
+ for (const libraryLocation of libraries){
1996
+ const libraryManifest = readPublishedPackageNpmManifest(libraryLocation);
1997
+ const libraryCreatorPackage = readPublishedPackageCreatorManifest(libraryLocation);
1998
+ if (libraryCreatorPackage === undefined || libraryManifest.main === undefined || libraryCreatorPackage.Package === (creatorPackage == null ? void 0 : creatorPackage.Package)) {
1999
+ continue;
2000
+ }
2001
+ const libraryVersion = PackageVersion.extractFromLine(libraryManifest.version);
2002
+ if (libraryVersion.preRelease) {
2003
+ libraryVersion.buildNumber = libraryVersion.preRelease.version;
2004
+ libraryVersion.preRelease = undefined;
2005
+ } else {
2006
+ libraryVersion.buildNumber = 100;
2007
+ }
2008
+ let uploadedPackageInBasics;
2009
+ let uploadedPackageInTarget;
2010
+ for (const uploadedPackage of uploadedPackages){
2011
+ if (uploadedPackage.scope === libraryCreatorPackage.Package) {
2012
+ if (uploadedPackage.support) {
2013
+ uploadedPackageInBasics = uploadedPackage;
2014
+ } else {
2015
+ uploadedPackageInTarget = uploadedPackage;
2016
+ }
2017
+ }
2018
+ }
2019
+ const validInBasics = uploadedPackageInBasics !== undefined && !uploadedPackageInBasics.version.isLesserThan(libraryVersion);
2020
+ const validInTarget = uploadedPackageInTarget !== undefined && !uploadedPackageInTarget.version.isLesserThan(libraryVersion);
2021
+ if (validInBasics || validInTarget) {
2022
+ if (targetSession.subDomain !== "Basics" && uploadedPackageInBasics !== undefined && uploadedPackageInTarget !== undefined) {
2023
+ reporter.log(`Package ${libraryCreatorPackage.Package} is uploaded both for Basics and ${targetSession.subDomain}. The package within ${targetSession.subDomain} will be used.`);
2024
+ }
2025
+ if (logUpToDate) {
2026
+ reporter.log(`Package ${libraryCreatorPackage.Package} is already uploaded with the required version ${libraryVersion.toVersionString({})}`);
2027
+ }
2028
+ continue;
2029
+ }
2030
+ const possibleTargets = [];
2031
+ if (uploadedPackageInBasics) {
2032
+ const version = uploadedPackageInBasics.version.toVersionString({
2033
+ buildNumber: true
2034
+ });
2035
+ possibleTargets.push({
2036
+ value: "Basics",
2037
+ name: `Basics (Current: ${version})`
2038
+ });
2039
+ } else {
2040
+ possibleTargets.push({
2041
+ value: "Basics",
2042
+ name: "Basics (Current: None)"
2043
+ });
2044
+ }
2045
+ if (targetSession.subDomain !== "Basics") {
2046
+ if (uploadedPackageInTarget) {
2047
+ const version = uploadedPackageInTarget.version.toVersionString({
2048
+ buildNumber: true
2049
+ });
2050
+ possibleTargets.push({
2051
+ value: targetSession.subDomain,
2052
+ name: `${targetSession.subDomain} (Current: ${version})`
2053
+ });
2054
+ } else {
2055
+ possibleTargets.push({
2056
+ value: targetSession.subDomain,
2057
+ name: `${targetSession.subDomain} (Current: None)`
2058
+ });
2059
+ }
2060
+ }
2061
+ const libraryVersionString = libraryVersion.toVersionString({
2062
+ buildNumber: true
2063
+ });
2064
+ const uploadTargetScope = await prompter.ask({
2065
+ message: `Version ${libraryVersionString} of dependency ${libraryCreatorPackage.Package} is required but not available. Please select a subdomain to upload the correct dependency version to`,
2066
+ options: [
2067
+ ...possibleTargets,
2068
+ {
2069
+ name: "Skip upload",
2070
+ value: "Skip"
2071
+ }
2072
+ ],
2073
+ default: possibleTargets[0].value
2074
+ });
2075
+ if (uploadTargetScope === "Skip") {
2076
+ continue;
2077
+ }
2078
+ const archive = buildArchiveFromPublishedPackage(libraryLocation, libraryManifest, libraryCreatorPackage);
2079
+ const newVersionString = libraryVersion.toVersionString({
2080
+ buildNumber: true
2081
+ });
2082
+ const session = uploadTargetScope === "Basics" ? await sessionManager.getBasicsSession() : targetSession;
2083
+ reporter.log(`Uploading package ${libraryCreatorPackage.Package} with version ${newVersionString} to ${session.domain}.${session.subDomain}`);
2084
+ await uploadPackageFromStream(session, {
2085
+ name: libraryCreatorPackage.Package,
2086
+ version: newVersionString
2087
+ }, archive.generateNodeStream());
2088
+ }
2089
+ };
2090
+
1931
2091
  const execAsync = promisify(exec);
1932
2092
  const releaseFolder = async (options)=>{
1933
2093
  const workspace = options.workspace;
1934
2094
  const location = options.directory;
1935
- const { write: writeVersionFile , reset: resetVersionFile } = getVersionFileHandler(location);
2095
+ const { write: writeVersionFile, reset: resetVersionFile } = getVersionFileHandler(location);
1936
2096
  const packageDescription = readPackageCreatorManifest(location);
1937
2097
  const fullPackageName = packageDescription.Package;
1938
- const { domain , subdomain } = parseCreatorPackageName(packageDescription);
2098
+ const reporter = options.reporter ?? createPackageScopedReporter(consoleReporter, packageDescription.Package);
2099
+ const { domain, subdomain } = parseCreatorPackageName(packageDescription);
1939
2100
  const publishDomain = options.domain ?? domain;
1940
2101
  const publishSubdomain = options.subdomain ?? subdomain;
1941
2102
  const sharedPackageJson = readWorkspaceNpmManifest(workspace);
@@ -1961,7 +2122,7 @@ const releaseFolder = async (options)=>{
1961
2122
  };
1962
2123
  }
1963
2124
  if (sharedPackageJson !== undefined) {
1964
- logPackageMessage(packageDescription.Package, `Running npm install to make sure all dependencies are up to date`);
2125
+ reporter.log(`Running npm install to make sure all dependencies are up to date`);
1965
2126
  await execAsync(`npm install`, {
1966
2127
  encoding: "utf-8",
1967
2128
  cwd: workspace.path
@@ -2017,7 +2178,8 @@ const releaseFolder = async (options)=>{
2017
2178
  buildNumber: true
2018
2179
  }),
2019
2180
  date: new Date(Date.now())
2020
- } : undefined
2181
+ } : undefined,
2182
+ preparedReporter: reporter
2021
2183
  });
2022
2184
  newVersion.preRelease = undefined;
2023
2185
  try {
@@ -2043,13 +2205,14 @@ const releaseFolder = async (options)=>{
2043
2205
  }
2044
2206
  }
2045
2207
  }
2046
- const archive = await buildArchiveFromPackage(location, packageDescription, binDir);
2208
+ reporter.log(`Creating zip file`);
2209
+ const archive = await buildArchiveFromPackage(reporter, location, packageDescription, binDir, options.minimize);
2047
2210
  try {
2048
2211
  const zipOutputStream = createWriteStream(zipFilePath);
2049
2212
  await pipeline(archive.generateNodeStream(), zipOutputStream);
2050
2213
  } catch (err) {
2051
2214
  if (isErrorEACCES(err) || isErrorEPERM(err)) {
2052
- logPackageMessage(packageDescription.Package, `Could not create zip file in the bin directory because of a permissions error. Only using it in-memory`);
2215
+ reporter.log(`Could not create zip file in the bin directory because of a permissions error. Only using it in-memory`);
2053
2216
  uploadable = {
2054
2217
  getStream: ()=>archive.generateNodeStream()
2055
2218
  };
@@ -2062,8 +2225,8 @@ const releaseFolder = async (options)=>{
2062
2225
  if (!options.authentication) {
2063
2226
  throw new Error(`Expected authentication to be available`);
2064
2227
  }
2065
- logPackageMessage(packageDescription.Package, `Opening connection to IG.Asset.Server`);
2066
- const sessionManager = await createSessionManager({
2228
+ reporter.log(`Opening connection to IG.Asset.Server`);
2229
+ const sessionManager = await createAssetServiceSessionManager({
2067
2230
  url: options.service,
2068
2231
  address: options.address,
2069
2232
  domain: publishDomain,
@@ -2072,13 +2235,13 @@ const releaseFolder = async (options)=>{
2072
2235
  });
2073
2236
  try {
2074
2237
  if (!options.skipDependencies) {
2075
- await ensureRequiredVersions(workspace, packageDescription, sessionManager, options.prompter);
2238
+ await synchronizeDependencies(workspace, packageDescription, sessionManager, options.prompter, reporter);
2076
2239
  }
2077
- logPackageMessage(packageDescription.Package, `Uploading package to ${publishDomain}.${publishSubdomain}`);
2240
+ reporter.log(`Uploading package to ${publishDomain}.${publishSubdomain}`);
2078
2241
  await uploadPackageFromStream(sessionManager.getTargetSession(), assetServerPackageDetails, uploadable.getStream());
2079
2242
  } finally{
2080
2243
  await sessionManager.destroy().catch((err)=>{
2081
- logPackageMessage(packageDescription.Package, `Failed to close IG.Asset.Server session(s): ${err}`);
2244
+ reporter.error(`Failed to close IG.Asset.Server session(s)`, err);
2082
2245
  });
2083
2246
  }
2084
2247
  }
@@ -2087,7 +2250,7 @@ const releaseFolder = async (options)=>{
2087
2250
  throw err;
2088
2251
  }
2089
2252
  if (newVersion.buildNumber >= 100 && !options.pushOnly) {
2090
- logPackageMessage(fullPackageName, "Copying zip to releases folder");
2253
+ reporter.error("Copying zip to releases folder");
2091
2254
  const zipFileName = `${packageNameWithVersion}.zip`;
2092
2255
  const releasesPath = getPackageReleasesDirectory(location);
2093
2256
  await fs$1.mkdir(releasesPath, {
@@ -2096,160 +2259,12 @@ const releaseFolder = async (options)=>{
2096
2259
  await pipeline(uploadable.getStream(), createWriteStream(path.join(releasesPath, zipFileName)));
2097
2260
  }
2098
2261
  };
2099
- const ensureRequiredVersions = async (workspaceLocation, creatorPackage, sessionManager, prompter)=>{
2100
- const libraries = determineWorkspaceIGLibraries(workspaceLocation);
2101
- // If there are no libraries, we don't need to check for required versions
2102
- if (libraries.length === 0) {
2103
- return true;
2104
- }
2105
- const targetSession = sessionManager.getTargetSession();
2106
- const rawUploadedPackages = await getExistingPackages(targetSession);
2107
- const uploadedPackages = rawUploadedPackages.map((entry)=>{
2108
- let version;
2109
- try {
2110
- version = parseVersionFromNumericVersion(entry.numericVersion);
2111
- } catch (err) {
2112
- throw new Error(`Encountered invalid format for version ${entry.numericVersion}`);
2113
- }
2114
- if (version.buildNumber < 100) {
2115
- version.preRelease = {
2116
- type: "beta",
2117
- version: version.buildNumber
2118
- };
2119
- } else if (version.buildNumber > 100) {
2120
- version.preRelease = {
2121
- type: "patch",
2122
- version: version.buildNumber - 100
2123
- };
2124
- }
2125
- return {
2126
- ...entry,
2127
- version
2128
- };
2129
- });
2130
- for (const libraryLocation of libraries){
2131
- const libraryManifest = readPublishedPackageNpmManifest(libraryLocation);
2132
- const libraryCreatorPackage = readPublishedPackageCreatorManifest(libraryLocation);
2133
- if (libraryCreatorPackage === undefined || libraryManifest.main === undefined || libraryCreatorPackage.Package === creatorPackage.Package) {
2134
- continue;
2135
- }
2136
- const libraryVersion = PackageVersion.extractFromLine(libraryManifest.version);
2137
- if (libraryVersion.preRelease) {
2138
- libraryVersion.buildNumber = libraryVersion.preRelease.version;
2139
- libraryVersion.preRelease = undefined;
2140
- } else {
2141
- libraryVersion.buildNumber = 100;
2142
- }
2143
- let uploadedPackageInBasics;
2144
- let uploadedPackageInTarget;
2145
- for (const uploadedPackage of uploadedPackages){
2146
- if (uploadedPackage.scope === libraryCreatorPackage.Package) {
2147
- if (uploadedPackage.support) {
2148
- uploadedPackageInBasics = uploadedPackage;
2149
- } else {
2150
- uploadedPackageInTarget = uploadedPackage;
2151
- }
2152
- }
2153
- }
2154
- const validInBasics = uploadedPackageInBasics !== undefined && !uploadedPackageInBasics.version.isLesserThan(libraryVersion);
2155
- const validInTarget = uploadedPackageInTarget !== undefined && !uploadedPackageInTarget.version.isLesserThan(libraryVersion);
2156
- if (validInBasics || validInTarget) {
2157
- if (targetSession.subDomain !== "Basics" && uploadedPackageInBasics !== undefined && uploadedPackageInTarget !== undefined) {
2158
- logPackageMessage(creatorPackage.Package, `Package ${libraryCreatorPackage.Package} is uploaded both for Basics and ${targetSession.subDomain}. The package within ${targetSession.subDomain} will be used.`);
2159
- }
2160
- continue;
2161
- }
2162
- const possibleTargets = [];
2163
- if (uploadedPackageInBasics) {
2164
- const version = uploadedPackageInBasics.version.toVersionString({
2165
- buildNumber: true
2166
- });
2167
- possibleTargets.push({
2168
- value: "Basics",
2169
- name: `Basics (Current: ${version})`
2170
- });
2171
- } else {
2172
- possibleTargets.push({
2173
- value: "Basics",
2174
- name: "Basics (Current: None)"
2175
- });
2176
- }
2177
- if (targetSession.subDomain !== "Basics") {
2178
- if (uploadedPackageInTarget) {
2179
- const version = uploadedPackageInTarget.version.toVersionString({
2180
- buildNumber: true
2181
- });
2182
- possibleTargets.push({
2183
- value: targetSession.subDomain,
2184
- name: `${targetSession.subDomain} (Current: ${version})`
2185
- });
2186
- } else {
2187
- possibleTargets.push({
2188
- value: targetSession.subDomain,
2189
- name: `${targetSession.subDomain} (Current: None)`
2190
- });
2191
- }
2192
- }
2193
- const libraryVersionString = libraryVersion.toVersionString({
2194
- buildNumber: true
2195
- });
2196
- const uploadTargetScope = await prompter.ask({
2197
- message: `Version ${libraryVersionString} of dependency ${libraryCreatorPackage.Package} is required but not available. Please select a subdomain to upload the correct dependency version to`,
2198
- options: [
2199
- ...possibleTargets,
2200
- {
2201
- name: "Skip upload",
2202
- value: "Skip"
2203
- }
2204
- ],
2205
- default: possibleTargets[0].value
2206
- });
2207
- if (uploadTargetScope === "Skip") {
2208
- continue;
2209
- }
2210
- const archive = buildArchiveFromPublishedPackage(libraryLocation, libraryManifest, libraryCreatorPackage);
2211
- const newVersionString = libraryVersion.toVersionString({
2212
- buildNumber: true
2213
- });
2214
- const session = uploadTargetScope === "Basics" ? await sessionManager.getBasicsSession() : targetSession;
2215
- logPackageMessage(creatorPackage.Package, `Uploading package ${libraryCreatorPackage.Package} with version ${newVersionString} to ${session.domain}.${session.subDomain}`);
2216
- await uploadPackageFromStream(session, {
2217
- name: libraryCreatorPackage.Package,
2218
- version: newVersionString
2219
- }, archive.generateNodeStream());
2220
- }
2221
- };
2222
- const createSessionManager = async (params)=>{
2223
- const targetSession = await startSession(params);
2224
- let basicsSession;
2225
- return {
2226
- getBasicsSession: async ()=>{
2227
- if (targetSession.subDomain === "Basics") {
2228
- return targetSession;
2229
- }
2230
- if (basicsSession === undefined) {
2231
- basicsSession = await startSession({
2232
- ...params,
2233
- subDomain: "Basics"
2234
- });
2235
- }
2236
- return basicsSession;
2237
- },
2238
- getTargetSession: ()=>targetSession,
2239
- destroy: async ()=>{
2240
- await closeSession(targetSession);
2241
- if (basicsSession !== undefined) {
2242
- await closeSession(basicsSession);
2243
- }
2244
- }
2245
- };
2246
- };
2247
2262
 
2248
2263
  /**
2249
2264
  * Extracts and returns script array for _Index.json from a src folder
2250
2265
  *
2251
2266
  * @param folderPath path to a src folder
2252
- */ function generateIndex({ location , ignore =[] , strictOptional =false }) {
2267
+ */ function generateIndex({ location, ignore = [], strictOptional = false }) {
2253
2268
  const files = getPackageTypescriptFiles(location);
2254
2269
  const filtered = files.filter((path)=>{
2255
2270
  return !ignore.some((suffix)=>path.endsWith(suffix));
@@ -2519,5 +2534,5 @@ const detectScriptingClass = (node)=>{
2519
2534
  }
2520
2535
  };
2521
2536
 
2522
- export { buildFolders, buildFoldersWatch, generateIndex, releaseFolder };
2537
+ export { buildFolders, buildFoldersWatch, createAssetServiceSessionManager, generateIndex, releaseFolder, synchronizeDependencies };
2523
2538
  //# sourceMappingURL=lib.mjs.map