lincd-cli 1.1.0 → 1.1.2

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 (103) hide show
  1. package/defaults/app-static/.env-cmdrc.json +17 -0
  2. package/defaults/app-static/package.json +8 -0
  3. package/defaults/app-static/src/index-static.tsx +6 -9
  4. package/defaults/app-with-backend/.env-cmdrc.json +1 -4
  5. package/defaults/app-with-backend/gitignore.template +1 -1
  6. package/defaults/app-with-backend/package.json +11 -15
  7. package/defaults/app-with-backend/scripts/storage-config.js +12 -0
  8. package/defaults/app-with-backend/src/config-frontend.ts +17 -0
  9. package/defaults/app-with-backend/src/index.tsx +3 -6
  10. package/defaults/app-with-backend/src/package.ts +1 -2
  11. package/defaults/component.tsx +1 -3
  12. package/defaults/package/package.json +2 -2
  13. package/defaults/package/src/index.ts +1 -0
  14. package/defaults/package/src/ontologies/example-ontology.ts +10 -3
  15. package/defaults/package/src/package.ts +11 -3
  16. package/defaults/package/src/types.d.ts +9 -0
  17. package/defaults/package/tsconfig-cjs.json +8 -0
  18. package/defaults/package/tsconfig-esm.json +9 -0
  19. package/defaults/set-component.tsx +2 -5
  20. package/defaults/shape.ts +2 -2
  21. package/lib/{cli-methods.js → cjs/cli-methods.js} +645 -264
  22. package/lib/cjs/cli-methods.js.map +1 -0
  23. package/lib/cjs/cli.js +202 -0
  24. package/lib/cjs/cli.js.map +1 -0
  25. package/lib/{config-grunt.js → cjs/config-grunt.cjs} +15 -13
  26. package/lib/cjs/config-grunt.cjs.map +1 -0
  27. package/lib/cjs/config-webpack-app.js +353 -0
  28. package/lib/cjs/config-webpack-app.js.map +1 -0
  29. package/lib/cjs/config-webpack.js +436 -0
  30. package/lib/cjs/config-webpack.js.map +1 -0
  31. package/lib/{index.js → cjs/index.js} +3 -5
  32. package/lib/cjs/index.js.map +1 -0
  33. package/lib/{interfaces.js.map → cjs/interfaces.js.map} +1 -1
  34. package/lib/cjs/loaders/css-loader.mjs +82 -0
  35. package/lib/cjs/loaders/css-loader.mjs.map +1 -0
  36. package/lib/cjs/loaders/register.js +6 -0
  37. package/lib/cjs/loaders/register.js.map +1 -0
  38. package/lib/cjs/metadata.js +155 -0
  39. package/lib/cjs/metadata.js.map +1 -0
  40. package/lib/cjs/package.json +139 -0
  41. package/lib/cjs/plugins/check-imports.js.map +1 -0
  42. package/lib/cjs/plugins/declaration-plugin.js +275 -0
  43. package/lib/cjs/plugins/declaration-plugin.js.map +1 -0
  44. package/lib/cjs/plugins/externalise-modules.js +190 -0
  45. package/lib/cjs/plugins/externalise-modules.js.map +1 -0
  46. package/lib/cjs/plugins/watch-run.js.map +1 -0
  47. package/lib/{utils.js → cjs/utils.js} +22 -18
  48. package/lib/cjs/utils.js.map +1 -0
  49. package/lib/esm/cli-methods.js +1965 -0
  50. package/lib/esm/cli-methods.js.map +1 -0
  51. package/lib/{cli.js → esm/cli.js} +59 -44
  52. package/lib/esm/cli.js.map +1 -0
  53. package/lib/esm/config-grunt.cjs +270 -0
  54. package/lib/esm/config-grunt.cjs.map +1 -0
  55. package/lib/esm/config-webpack-app.js +326 -0
  56. package/lib/esm/config-webpack-app.js.map +1 -0
  57. package/lib/{config-webpack.js → esm/config-webpack.js} +27 -39
  58. package/lib/esm/config-webpack.js.map +1 -0
  59. package/lib/esm/index.js +9 -0
  60. package/lib/esm/index.js.map +1 -0
  61. package/lib/esm/interfaces.js +2 -0
  62. package/lib/esm/interfaces.js.map +1 -0
  63. package/lib/esm/loaders/css-loader.mjs +75 -0
  64. package/lib/esm/loaders/css-loader.mjs.map +1 -0
  65. package/lib/esm/loaders/register.js +4 -0
  66. package/lib/esm/loaders/register.js.map +1 -0
  67. package/lib/esm/metadata.js +155 -0
  68. package/lib/esm/metadata.js.map +1 -0
  69. package/lib/esm/package.json +139 -0
  70. package/lib/esm/plugins/check-imports.js +65 -0
  71. package/lib/esm/plugins/check-imports.js.map +1 -0
  72. package/lib/{plugins → esm/plugins}/declaration-plugin.js +9 -8
  73. package/lib/esm/plugins/declaration-plugin.js.map +1 -0
  74. package/lib/{plugins → esm/plugins}/externalise-modules.js +5 -6
  75. package/lib/esm/plugins/externalise-modules.js.map +1 -0
  76. package/lib/esm/plugins/watch-run.js +44 -0
  77. package/lib/esm/plugins/watch-run.js.map +1 -0
  78. package/lib/esm/utils.js +478 -0
  79. package/lib/esm/utils.js.map +1 -0
  80. package/package.json +52 -15
  81. package/tsconfig-cjs.json +9 -0
  82. package/tsconfig-esm.json +10 -0
  83. package/defaults/app-with-backend/scripts/build.js +0 -41
  84. package/defaults/app-with-backend/scripts/setup_storage.js +0 -6
  85. package/defaults/app-with-backend/scripts/start-server.js +0 -11
  86. package/lib/cli-methods.js.map +0 -1
  87. package/lib/cli.js.map +0 -1
  88. package/lib/config-grunt.js.map +0 -1
  89. package/lib/config-webpack-app.js +0 -367
  90. package/lib/config-webpack-app.js.map +0 -1
  91. package/lib/config-webpack.js.map +0 -1
  92. package/lib/index.js.map +0 -1
  93. package/lib/metadata.js +0 -149
  94. package/lib/metadata.js.map +0 -1
  95. package/lib/plugins/check-imports.js.map +0 -1
  96. package/lib/plugins/declaration-plugin.js.map +0 -1
  97. package/lib/plugins/externalise-modules.js.map +0 -1
  98. package/lib/plugins/watch-run.js.map +0 -1
  99. package/lib/utils.js.map +0 -1
  100. /package/{expose-grunt.js → expose-grunt.cjs} +0 -0
  101. /package/lib/{interfaces.js → cjs/interfaces.js} +0 -0
  102. /package/lib/{plugins → cjs/plugins}/check-imports.js +0 -0
  103. /package/lib/{plugins → cjs/plugins}/watch-run.js +0 -0
@@ -1,25 +1,50 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.register = exports.createPackage = exports.buildApp = exports.startServer = exports.ensureEnvironmentLoaded = exports.depCheck = exports.depCheckStaged = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
29
+ exports.removeOldFiles = exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.compilePackage = exports.buildPackage = exports.register = exports.createPackage = exports.upgradePackages = exports.buildApp = exports.startServer = exports.ensureEnvironmentLoaded = exports.depCheck = exports.depCheckStaged = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.getScriptDir = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
7
30
  const chalk_1 = __importDefault(require("chalk"));
8
31
  const child_process_1 = require("child_process");
9
32
  const depcheck_1 = __importDefault(require("depcheck"));
10
- const get_env_vars_1 = require("env-cmd/dist/get-env-vars");
33
+ const get_env_vars_js_1 = require("env-cmd/dist/get-env-vars.js");
11
34
  const fs_extra_1 = __importDefault(require("fs-extra"));
12
- const path_1 = __importDefault(require("path"));
13
- const utils_1 = require("./utils");
35
+ const path_1 = __importStar(require("path"));
36
+ const utils_js_1 = require("./utils.js");
14
37
  const fs_1 = require("fs");
15
38
  const find_nearest_package_json_1 = require("find-nearest-package-json");
16
- const LinkedFileStorage_1 = require("lincd/lib/utils/LinkedFileStorage");
39
+ const LinkedFileStorage_1 = require("lincd/utils/LinkedFileStorage");
40
+ // import pkg from 'lincd/utils/LinkedFileStorage';
41
+ // const { LinkedFileStorage } = pkg;
17
42
  // const config = require('lincd-server/site.webpack.config');
18
- var glob = require('glob');
43
+ const glob_1 = require("glob");
44
+ const webpack_1 = __importDefault(require("webpack"));
45
+ const staged_git_files_1 = __importDefault(require("staged-git-files"));
46
+ const ora_1 = __importDefault(require("ora"));
19
47
  var variables = {};
20
- var open = require('open');
21
- var stagedGitFiles = require('staged-git-files');
22
- const webpack = require('webpack');
23
48
  const createApp = async (name, basePath = process.cwd()) => {
24
49
  if (!name) {
25
50
  console.warn('Please provide a name as the first argument');
@@ -38,21 +63,21 @@ const createApp = async (name, basePath = process.cwd()) => {
38
63
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'gitignore.template'), path_1.default.join(targetFolder, '.gitignore'));
39
64
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'yarnrc.yml.template'), path_1.default.join(targetFolder, '.yarnrc.yml'));
40
65
  // fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
41
- log("Creating new LINCD application '" + name + "'");
66
+ log('Creating new LINCD application \'' + name + '\'');
42
67
  //replace variables in some copied files
43
68
  await replaceVariablesInFolder(targetFolder);
44
69
  let hasYarn = await hasYarnInstalled();
45
70
  let installCommand = hasYarn
46
71
  ? 'export NODE_OPTIONS="--no-network-family-autoselection" && yarn install'
47
72
  : 'npm install';
48
- await (0, utils_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
73
+ await (0, utils_js_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
49
74
  console.warn('Could not install dependencies or start application');
50
75
  });
51
76
  log(`Your LINCD App is ready at ${chalk_1.default.blueBright(targetFolder)}`, `To start, run\n${chalk_1.default.blueBright(`cd ${hyphenName}`)} and then ${chalk_1.default.blueBright((hasYarn ? 'yarn' : 'npm') + ' start')}`);
52
77
  };
53
78
  exports.createApp = createApp;
54
79
  function logHelp() {
55
- (0, utils_1.execp)('yarn exec lincd help');
80
+ (0, utils_js_1.execp)('yarn exec lincd help');
56
81
  }
57
82
  function log(...messages) {
58
83
  messages.forEach((message) => {
@@ -65,7 +90,7 @@ function progressUpdate(message) {
65
90
  }
66
91
  function warn(...messages) {
67
92
  messages.forEach((message) => {
68
- console.log(chalk_1.default.magenta('Warning: ') + message);
93
+ console.log(chalk_1.default.redBright('Warning: ') + message);
69
94
  // console.log(chalk.red(message));
70
95
  });
71
96
  }
@@ -141,7 +166,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
141
166
  //get dependencies of each package
142
167
  let leastDependentPackage;
143
168
  lincdPackages.forEach((pkg) => {
144
- var pack = (0, utils_1.getPackageJSON)(pkg.path);
169
+ var pack = (0, utils_js_1.getPackageJSON)(pkg.path);
145
170
  if (pack) {
146
171
  //get lincd related dependencies and get the actual package details from the package map by removing '@dacore/' from the package name
147
172
  let packageDependencies = Object.keys(pack.dependencies)
@@ -166,9 +191,17 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
166
191
  let startStack = [leastDependentPackage];
167
192
  const runPackage = (runFunction, pck) => {
168
193
  return runFunction(pck)
169
- .catch(({ error, stdout, stderr }) => {
170
- warn('Uncaught exception whilst running parallel function on ' +
171
- pck.packageName, error.message);
194
+ .catch((errorObj) => {
195
+ if (errorObj.error) {
196
+ let { error, stdout, stderr } = errorObj;
197
+ warn('Uncaught exception whilst running parallel function on ' +
198
+ pck.packageName, (error === null || error === void 0 ? void 0 : error.message) ? error.message : error === null || error === void 0 ? void 0 : error.toString());
199
+ }
200
+ else {
201
+ warn('Uncaught exception whilst running parallel function on ' +
202
+ pck.packageName, errorObj === null || errorObj === void 0 ? void 0 : errorObj.toString());
203
+ process.exit();
204
+ }
172
205
  // warn(chalk.red(pck.packageName+' failed:'));
173
206
  // console.log(stdout);
174
207
  })
@@ -337,10 +370,10 @@ function buildAll(options) {
337
370
  // let packagesLeft = lincdPackages.size - done.size;
338
371
  runOnPackagesGroupedByDependencies(lincdPackages, (packageGroup, dependencies) => {
339
372
  if (done.size > 0) {
340
- (0, utils_1.debugInfo)(chalk_1.default.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
373
+ (0, utils_js_1.debugInfo)(chalk_1.default.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
341
374
  // log(stack);
342
375
  }
343
- (0, utils_1.debugInfo)('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
376
+ (0, utils_js_1.debugInfo)('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
344
377
  return async (pkg) => {
345
378
  let command;
346
379
  let skipping = false;
@@ -359,50 +392,119 @@ function buildAll(options) {
359
392
  }
360
393
  //unless told otherwise, build the package
361
394
  if (!command) {
362
- command = (0, utils_1.execPromise)('cd ' + pkg.path + ' && yarn exec lincd build',
363
- // (target ? ' ' + target : '') +
364
- // (target2 ? ' ' + target2 : ''),
365
- false, false, {}, false);
395
+ command = (0, exports.buildPackage)(null, null, path_1.default.join(process.cwd(), pkg.path), false);
396
+ // command = execPromise(
397
+ // 'cd ' + pkg.path + ' && yarn exec lincd build',
398
+ // // (target ? ' ' + target : '') +
399
+ // // (target2 ? ' ' + target2 : ''),
400
+ // false,
401
+ // false,
402
+ // {},
403
+ // false,
404
+ // );
366
405
  log(chalk_1.default.cyan('Building ' + pkg.packageName));
367
406
  process.stdout.write(packagesLeft + ' packages left\r');
368
407
  }
369
- return command
370
- .catch(({ error, stdout, stderr }) => {
371
- //this prints out the webpack output, including the build errors
372
- warn('Failed to build ' + pkg.packageName);
373
- console.log(stdout);
374
- failedModules.push(pkg.packageName);
375
- let dependentModules = getDependentPackages(dependencies, pkg);
376
- if (dependentModules.length > 0) {
377
- printBuildResults(failedModules, done);
378
- console.log(chalk_1.default.magenta('Stopping build process because an error occurred whilst building ' +
379
- pkg.packageName +
380
- ', which ' +
381
- dependentModules.length +
382
- ' other packages depend on.')); //"+dependentModules.map(d => d.packageName).join(", ")));
383
- console.log(chalk_1.default.cyanBright('tip ') +
384
- 'Run ' +
385
- chalk_1.default.green(`lincd build-all --from=${pkg.packageName}`) +
386
- ' to build only the remaining packages'); //"+dependentModules.map(d => d.packageName).join(", ")));
387
- process.exit(1);
388
- }
389
- })
390
- .then((res) => {
391
- if (!skipping) {
392
- log(chalk_1.default.green('Built ' + pkg.packageName));
393
- }
394
- done.add(pkg);
395
- packagesLeft--;
396
- // log(chalk.magenta(packagesLeft + ' packages left'));
397
- process.stdout.write(packagesLeft + ' packages left\r');
398
- if (packagesLeft == 0) {
399
- printBuildResults(failedModules, done);
400
- if (failedModules.length > 0) {
408
+ return command.then(res => {
409
+ //empty string or true is success
410
+ //false is success with warnings
411
+ //any other string is the build error text
412
+ //undefined result means it failed
413
+ // if (res !== '' && res !== true && res !== false) {
414
+ if (typeof res === 'undefined') {
415
+ failedModules.push(pkg.packageName);
416
+ let dependentModules = getDependentPackages(dependencies, pkg);
417
+ if (dependentModules.length > 0) {
418
+ printBuildResults(failedModules, done);
419
+ console.log('Stopping build process because an error occurred whilst building ' +
420
+ pkg.packageName +
421
+ ', which ' +
422
+ dependentModules.length +
423
+ ' other packages depend on.'); //"+dependentModules.map(d => d.packageName).join(", ")));
424
+ log('Run ' +
425
+ chalk_1.default.greenBright(`lincd build-all --from=${pkg.packageName}`) +
426
+ ' to build only the remaining packages'); //"+dependentModules.map(d => d.packageName).join(", ")));
401
427
  process.exit(1);
402
428
  }
403
429
  }
404
- return res;
430
+ else {
431
+ if (!skipping) {
432
+ log(chalk_1.default.green('Built ' + pkg.packageName) + (res === false ? chalk_1.default.redBright(' (with warnings)') : ''));
433
+ }
434
+ done.add(pkg);
435
+ packagesLeft--;
436
+ // log(chalk.magenta(packagesLeft + ' packages left'));
437
+ process.stdout.write(packagesLeft + ' packages left\r');
438
+ if (packagesLeft == 0) {
439
+ printBuildResults(failedModules, done);
440
+ if (failedModules.length > 0) {
441
+ process.exit(1);
442
+ }
443
+ }
444
+ return res;
445
+ }
446
+ })
447
+ .catch(({ error, stdout, stderr }) => {
448
+ warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
449
+ console.log(stdout);
450
+ process.exit(1);
451
+ // let dependentModules = getDependentP
405
452
  });
453
+ //undefined result means it failed
454
+ /*if (typeof res === 'undefined')
455
+ {
456
+ // .catch(({ error,stdout,stderr }) => {
457
+ //this prints out the webpack output, including the build errors
458
+ // warn('Failed to build ' + pkg.packageName);
459
+ // console.log(stdout);
460
+ failedModules.push(pkg.packageName);
461
+ let dependentModules = getDependentPackages(dependencies,pkg);
462
+ if (dependentModules.length > 0)
463
+ {
464
+ printBuildResults(failedModules,done);
465
+ console.log(
466
+ 'Stopping build process because an error occurred whilst building ' +
467
+ pkg.packageName +
468
+ ', which ' +
469
+ dependentModules.length +
470
+ ' other packages depend on.',
471
+ ); //"+dependentModules.map(d => d.packageName).join(", ")));
472
+ log(
473
+ 'Run ' +
474
+ chalk.greenBright(`lincd build-all --from=${pkg.packageName}`) +
475
+ ' to build only the remaining packages',
476
+ ); //"+dependentModules.map(d => d.packageName).join(", ")));
477
+ process.exit(1);
478
+ }
479
+ }
480
+ else //true is successful build, false is successful but with warnings
481
+ {
482
+ //successful build
483
+ // })
484
+ // .then((res) => {
485
+ if (!skipping)
486
+ {
487
+ log(chalk.green('Built ' + pkg.packageName)+(res === false ? chalk.redBright(' (with warnings)') : ''));
488
+ }
489
+ done.add(pkg);
490
+
491
+ packagesLeft--;
492
+ // log(chalk.magenta(packagesLeft + ' packages left'));
493
+ process.stdout.write(packagesLeft + ' packages left\r');
494
+ if (packagesLeft == 0)
495
+ {
496
+ printBuildResults(failedModules,done);
497
+ if (failedModules.length > 0)
498
+ {
499
+ process.exit(1);
500
+ }
501
+ }
502
+
503
+ return res;
504
+ }*/
505
+ // }).catch(err => {
506
+ // console.log(err);
507
+ // })
406
508
  };
407
509
  }, (dependencies) => {
408
510
  //if no more packages to build but we never started building...
@@ -474,11 +576,11 @@ function getLocalLincdModules(rootPath = './') {
474
576
  });
475
577
  }
476
578
  function getLincdPackages(rootPath = process.cwd()) {
477
- let pack = (0, utils_1.getPackageJSON)();
579
+ let pack = (0, utils_js_1.getPackageJSON)();
478
580
  if (!pack || !pack.workspaces) {
479
581
  for (let i = 0; i <= 3; i++) {
480
582
  rootPath = path_1.default.join(process.cwd(), ...Array(i).fill('..'));
481
- pack = (0, utils_1.getPackageJSON)(rootPath);
583
+ pack = (0, utils_js_1.getPackageJSON)(rootPath);
482
584
  if (pack && pack.workspaces) {
483
585
  // log('Found workspace at '+packagePath);
484
586
  break;
@@ -541,7 +643,7 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
541
643
  setVariable('uri_base', uriBase);
542
644
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(prefix);
543
645
  //copy ontology accessor file
544
- log("Creating files for ontology '" + prefix + "'");
646
+ log('Creating files for ontology \'' + prefix + '\'');
545
647
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
546
648
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
547
649
  //copy data files
@@ -559,10 +661,10 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
559
661
  }
560
662
  };
561
663
  exports.createOntology = createOntology;
562
- const addLineToIndex = function (line, insertMatchString) {
664
+ const addLineToIndex = function (line, insertMatchString, root = process.cwd(), insertAtStart = false) {
563
665
  //import ontology in index
564
666
  let indexPath = ['index.ts', 'index.tsx']
565
- .map((f) => path_1.default.join('src', f))
667
+ .map((f) => path_1.default.join(root, 'src', f))
566
668
  .find((indexFileName) => {
567
669
  return fs_extra_1.default.existsSync(indexFileName);
568
670
  });
@@ -571,8 +673,9 @@ const addLineToIndex = function (line, insertMatchString) {
571
673
  let lines = indexContents.split(/\n/g);
572
674
  let newContents;
573
675
  for (var key in lines) {
676
+ //if the match string is found
574
677
  if (lines[key].indexOf(insertMatchString) !== -1) {
575
- //remove lines after this line and insert new line in its place
678
+ //add the new line after this line
576
679
  lines[key] += `\n${line}`;
577
680
  newContents = lines.join('\n');
578
681
  // log("Found at "+key,lines,newContents);
@@ -580,7 +683,12 @@ const addLineToIndex = function (line, insertMatchString) {
580
683
  }
581
684
  }
582
685
  if (!newContents) {
583
- newContents = indexContents + `\n${line}`;
686
+ if (insertAtStart) {
687
+ newContents = `${line}\n${indexContents}`;
688
+ }
689
+ else {
690
+ newContents = `${indexContents}\n${line}`;
691
+ }
584
692
  // log("Added at end",newContents);
585
693
  }
586
694
  fs_extra_1.default.writeFileSync(indexPath, newContents);
@@ -594,13 +702,13 @@ const replaceVariablesInFiles = function (...files) {
594
702
  };
595
703
  const replaceVariablesInFolder = function (folder) {
596
704
  //get all files in folder, including files that start with a dot
597
- glob(folder + '/**/*', { dot: true, nodir: true }, function (err, files) {
705
+ glob_1.glob(folder + '/**/*', { dot: true, nodir: true }, async function (err, files) {
598
706
  if (err) {
599
707
  console.log('Error', err);
600
708
  }
601
709
  else {
602
710
  // console.log(files);
603
- return Promise.all(files.map((file) => {
711
+ await Promise.all(files.map((file) => {
604
712
  return replaceVariablesInFile(file);
605
713
  }));
606
714
  }
@@ -610,7 +718,7 @@ const replaceVariablesInFilesWithRoot = function (root, ...files) {
610
718
  return replaceVariablesInFiles(...files.map((f) => path_1.default.join(root, f)));
611
719
  };
612
720
  const hasYarnInstalled = async function () {
613
- let version = (await (0, utils_1.execPromise)('yarn --version').catch((err) => {
721
+ let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
614
722
  console.log('yarn probably not working');
615
723
  return '';
616
724
  }));
@@ -666,6 +774,21 @@ function getSourceFolder(basePath = process.cwd()) {
666
774
  return path_1.default.join(basePath, 'src');
667
775
  }
668
776
  }
777
+ /**
778
+ * get __dirname for either ESM/CJS
779
+ */
780
+ const getScriptDir = () => {
781
+ // @ts-ignore
782
+ if (typeof __dirname !== 'undefined') {
783
+ // @ts-ignore
784
+ return __dirname;
785
+ }
786
+ else {
787
+ // @ts-ignore
788
+ return (0, path_1.dirname)(import.meta.url).replace('file:/', '');
789
+ }
790
+ };
791
+ exports.getScriptDir = getScriptDir;
669
792
  const createShape = async (name, basePath = process.cwd()) => {
670
793
  let sourceFolder = getSourceFolder(basePath);
671
794
  let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
@@ -673,7 +796,7 @@ const createShape = async (name, basePath = process.cwd()) => {
673
796
  //copy default shape file
674
797
  // log("Creating files for shape '" + name + "'");
675
798
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
676
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'shape.ts'), targetFile);
799
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'shape.ts'), targetFile);
677
800
  //replace variables in some of the copied files
678
801
  await replaceVariablesInFiles(targetFile);
679
802
  log(`Created a new shape class template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
@@ -689,11 +812,11 @@ const createSetComponent = async (name, basePath = process.cwd()) => {
689
812
  let targetFolder = ensureFolderExists(basePath, 'src', 'components');
690
813
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
691
814
  //copy default shape file
692
- log("Creating files for set component '" + name + "'");
815
+ log('Creating files for set component \'' + name + '\'');
693
816
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
694
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'set-component.tsx'), targetFile);
817
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
695
818
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
696
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
819
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'component.scss'), targetFile2);
697
820
  //replace variables in some of the copied files
698
821
  await replaceVariablesInFiles(targetFile, targetFile2);
699
822
  let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
@@ -705,11 +828,11 @@ const createComponent = async (name, basePath = process.cwd()) => {
705
828
  let targetFolder = ensureFolderExists(sourceFolder, 'components');
706
829
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
707
830
  //copy default shape file
708
- log("Creating files for component '" + name + "'");
831
+ log('Creating files for component \'' + name + '\'');
709
832
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
710
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.tsx'), targetFile);
833
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.tsx'), targetFile);
711
834
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
712
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
835
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.scss'), targetFile2);
713
836
  //replace variables in some of the copied files
714
837
  await replaceVariablesInFiles(targetFile, targetFile2);
715
838
  log(`Created a new component template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`, `Created component stylesheet template in ${chalk_1.default.magenta(targetFile2.replace(basePath, ''))}`);
@@ -742,10 +865,10 @@ invalidImports = new Map()) => {
742
865
  // - .tsx
743
866
  continue;
744
867
  }
745
- const allImports = await (0, utils_1.getFileImports)(filename);
868
+ const allImports = await (0, utils_js_1.getFileImports)(filename);
746
869
  const lincdImports = allImports.filter((i) => i.includes('lincd') || i.includes('..'));
747
870
  lincdImports.forEach((i) => {
748
- if (!(0, utils_1.isValidLINCDImport)(i, depth)) {
871
+ if (!(0, utils_js_1.isValidLINCDImport)(i, depth)) {
749
872
  if (!invalidImports.has(filename)) {
750
873
  invalidImports.set(filename, []);
751
874
  }
@@ -753,26 +876,36 @@ invalidImports = new Map()) => {
753
876
  }
754
877
  });
755
878
  }
879
+ let res = '';
756
880
  // All recursion must have finished, display any errors
757
881
  if (depth === 0 && invalidImports.size > 0) {
758
- console.warn(chalk_1.default.red('\n' + 'Invalid imports found. See fixes below:'));
759
- console.warn(chalk_1.default.red(" - For relative imports, ensure you don't import outside of the /src/ folder"));
760
- console.warn(chalk_1.default.red(' - For lincd imports, access the /lib/ folder instead of /src/'));
882
+ res += chalk_1.default.red('Invalid imports found.\n');
761
883
  invalidImports.forEach((value, key) => {
762
- console.info(chalk_1.default.red('\nFound in file ') + chalk_1.default.blue(key) + chalk_1.default.red(':'));
763
- value.forEach((i) => console.warn(chalk_1.default.red("- '" + i + "'")));
884
+ // res += '- '+chalk.blueBright(key.split('/').pop()) + ':\n';
885
+ value.forEach((i) => {
886
+ res += chalk_1.default.red(key.split('/').pop() + ' imports from \'' + i + '\'\n');
887
+ if (i.indexOf('../../') === 0) {
888
+ res +=
889
+ 'To fix: import from the NPM package directly.\n';
890
+ }
891
+ else if ('/src/') {
892
+ res += 'To fix: you likely need to replace /src with /lib\n';
893
+ }
894
+ });
764
895
  });
765
- process.exit(1);
896
+ throw res;
897
+ // process.exit(1);
766
898
  }
767
899
  else if (depth === 0 && invalidImports.size === 0) {
768
- console.info('All imports OK');
769
- process.exit(0);
900
+ // console.info('All imports OK');
901
+ // process.exit(0);
902
+ return true;
770
903
  }
771
904
  };
772
905
  exports.checkImports = checkImports;
773
906
  const depCheckStaged = async () => {
774
907
  console.log('Checking dependencies of staged files');
775
- stagedGitFiles(async function (err, results) {
908
+ (0, staged_git_files_1.default)(async function (err, results) {
776
909
  const packages = new Set();
777
910
  await Promise.all(results.map(async (file) => {
778
911
  // console.log('STAGED: ', file.filename);
@@ -792,50 +925,54 @@ const depCheckStaged = async () => {
792
925
  });
793
926
  };
794
927
  exports.depCheckStaged = depCheckStaged;
795
- const depCheck = async (path = process.cwd()) => {
796
- (0, depcheck_1.default)(path, {}, (results) => {
797
- if (results.missing) {
798
- let lincdPackages = getLocalLincdModules();
799
- let missing = Object.keys(results.missing);
800
- //filter out missing types, if it builds we're not too concerned about that at the moment?
801
- //especially things like @types/react, @types/react-dom, @types/node (they are added elsewhere?)
802
- // missing = missing.filter(m => m.indexOf('@types/') === 0);
803
- //currently react is not an explicit dependency, but we should add it as a peer dependency
804
- missing.splice(missing.indexOf('react'), 1);
805
- let missingLincdPackages = missing.filter((missingDep) => {
806
- return lincdPackages.some((lincdPackage) => {
807
- return lincdPackage.packageName === missingDep;
928
+ const depCheck = async (packagePath = process.cwd()) => {
929
+ return new Promise((resolve, reject) => {
930
+ (0, depcheck_1.default)(packagePath, {}, (results) => {
931
+ if (results.missing) {
932
+ let lincdPackages = getLocalLincdModules();
933
+ let missing = Object.keys(results.missing);
934
+ //filter out missing types, if it builds we're not too concerned about that at the moment?
935
+ //especially things like @types/react, @types/react-dom, @types/node (they are added elsewhere?)
936
+ // missing = missing.filter(m => m.indexOf('@types/') === 0);
937
+ //currently react is not an explicit dependency, but we should add it as a peer dependency
938
+ missing.splice(missing.indexOf('react'), 1);
939
+ let missingLincdPackages = missing.filter((missingDep) => {
940
+ return lincdPackages.some((lincdPackage) => {
941
+ return lincdPackage.packageName === missingDep;
942
+ });
808
943
  });
809
- });
810
- //currently just missing LINCD packages cause a hard failure exit code
811
- if (missingLincdPackages.length > 0) {
812
- console.warn(chalk_1.default.red(path +
813
- '\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
814
- missingLincdPackages.join(',\n- ')));
815
- process.exit(1);
816
- }
817
- else if (missing.length > 0) {
818
- console.warn(chalk_1.default.magenta(path +
819
- '\nMissing dependencies (for now a warning, soon an error):\n\t' +
820
- missing.join(',\n\t')));
944
+ //currently just missing LINCD packages cause a hard failure exit code
945
+ if (missingLincdPackages.length > 0) {
946
+ reject(chalk_1.default.red(packagePath.split('/').pop() +
947
+ '\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
948
+ missingLincdPackages.join(',\n- ')));
949
+ }
950
+ else if (missing.length > 0) {
951
+ resolve(chalk_1.default.redBright('warning: ' + packagePath.split('/').pop() +
952
+ ' is missing dependencies:\n - ' +
953
+ missing.join('\n - ')));
954
+ }
955
+ else {
956
+ resolve(true);
957
+ }
821
958
  }
822
- }
823
- // if(Object.keys(results.invalidFiles).length > 0) {
824
- // console.warn(chalk.red("Invalid files:\n")+Object.keys(results.invalidFiles).join(",\n"));
825
- // }
826
- // if(Object.keys(results.invalidDirs).length > 0) {
827
- // console.warn(chalk.red("Invalid dirs:\n")+results.invalidDirs.toString());
828
- // }
829
- // if(results.unused) {
830
- // console.warn("Unused dependencies: "+results.missing.join(", "));
831
- // }
959
+ // if(Object.keys(results.invalidFiles).length > 0) {
960
+ // console.warn(chalk.red("Invalid files:\n")+Object.keys(results.invalidFiles).join(",\n"));
961
+ // }
962
+ // if(Object.keys(results.invalidDirs).length > 0) {
963
+ // console.warn(chalk.red("Invalid dirs:\n")+results.invalidDirs.toString());
964
+ // }
965
+ // if(results.unused) {
966
+ // console.warn("Unused dependencies: "+results.missing.join(", "));
967
+ // }
968
+ });
832
969
  });
833
970
  };
834
971
  exports.depCheck = depCheck;
835
972
  const ensureEnvironmentLoaded = async () => {
836
973
  if (!process.env.NODE_ENV) {
837
974
  //load env-cmd for development environment
838
- let { GetEnvVars } = require('env-cmd');
975
+ let { GetEnvVars } = await Promise.resolve().then(() => __importStar(require('env-cmd')));
839
976
  let envCmdrcPath = path_1.default.join(process.cwd(), '.env-cmdrc.json');
840
977
  if (!fs_extra_1.default.existsSync(envCmdrcPath)) {
841
978
  console.warn('No .env-cmdrc.json found in this folder. Are you running this command from the root of a LINCD app?');
@@ -856,16 +993,18 @@ const ensureEnvironmentLoaded = async () => {
856
993
  if (args.includes('--env')) {
857
994
  let envIndex = args.indexOf('--env');
858
995
  let env = args[envIndex + 1];
859
- if (environments.includes(env)) {
860
- console.log('Environment: ' + env);
861
- process.env = { ...process.env, ...vars[env] };
862
- }
863
- else {
864
- console.warn('Environment ' +
865
- env +
866
- ' not found in .env-cmdrc.json. Available environments: ' +
867
- environments.join(', '));
868
- }
996
+ env.split(',').forEach((singleEnvironment) => {
997
+ if (environments.includes(singleEnvironment)) {
998
+ console.log('Environment: ' + singleEnvironment);
999
+ process.env = { ...process.env, ...vars[singleEnvironment] };
1000
+ }
1001
+ else {
1002
+ console.warn('Environment ' +
1003
+ singleEnvironment +
1004
+ ' not found in .env-cmdrc.json. Available environments: ' +
1005
+ environments.join(', '));
1006
+ }
1007
+ });
869
1008
  }
870
1009
  else {
871
1010
  //chose development by default
@@ -876,14 +1015,25 @@ const ensureEnvironmentLoaded = async () => {
876
1015
  };
877
1016
  exports.ensureEnvironmentLoaded = ensureEnvironmentLoaded;
878
1017
  const startServer = async (initOnly = false, ServerClass = null) => {
1018
+ var _a, _b;
879
1019
  await (0, exports.ensureEnvironmentLoaded)();
880
- let lincdConfig = require(path_1.default.join(process.cwd(), 'lincd.config'));
1020
+ let lincdConfig = await (_a = path_1.default.join(process.cwd(), 'lincd.config.js'), Promise.resolve().then(() => __importStar(require(_a))));
1021
+ // function scssLoadcall(source, filename) {
1022
+ // return 'console.log("SCSS CALL: ' + filename + '");\n' + source;
1023
+ // process.exit();
1024
+ // }
1025
+ // hook.hook('.scss', scssLoadcall);
1026
+ // hook.hook('.css', scssLoadcall);
1027
+ // import.meta.
1028
+ // // hook.hook('*.css', scssLoadcall);
1029
+ // // hook.hook('Body.module.css', scssLoadcall);
1030
+ // hook.hook('.module.css', scssLoadcall);
881
1031
  if (!ServerClass) {
882
- ServerClass = require('lincd-server/lib/shapes/LincdServer').LincdServer;
1032
+ ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer')))).LincdServer;
883
1033
  }
884
- require(path_1.default.join(process.cwd(), 'scripts', 'storage-config'));
1034
+ await (_b = path_1.default.join(process.cwd(), 'scripts', 'storage-config.js'), Promise.resolve().then(() => __importStar(require(_b))));
885
1035
  let server = new ServerClass({
886
- loadAppComponent: () => require(path_1.default.join(process.cwd(), 'src', 'App')).default,
1036
+ loadAppComponent: async () => { var _a; return (await (_a = path_1.default.join(process.cwd(), 'src', 'App'), Promise.resolve().then(() => __importStar(require(_a))))).default; },
887
1037
  ...lincdConfig,
888
1038
  });
889
1039
  //Important to use slice, because when using clusers, child processes need to be able to read the same arguments
@@ -899,15 +1049,12 @@ const startServer = async (initOnly = false, ServerClass = null) => {
899
1049
  exports.startServer = startServer;
900
1050
  const buildApp = async () => {
901
1051
  await (0, exports.ensureEnvironmentLoaded)();
902
- const webpackAppConfig = require('./config-webpack-app').webpackAppConfig;
1052
+ const webpackAppConfig = await (await Promise.resolve().then(() => __importStar(require('./config-webpack-app.js')))).getWebpackAppConfig();
903
1053
  console.log(chalk_1.default.magenta(`Building ${process.env.NODE_ENV} app bundles`));
904
1054
  return new Promise((resolve, reject) => {
905
- webpack(webpackAppConfig, async (err, stats) => {
1055
+ (0, webpack_1.default)(webpackAppConfig, async (err, stats) => {
906
1056
  if (err) {
907
1057
  console.error(err.stack || err);
908
- if (err.details) {
909
- console.error(err.details);
910
- }
911
1058
  process.exit(1);
912
1059
  }
913
1060
  const info = stats.toJson();
@@ -921,10 +1068,9 @@ const buildApp = async () => {
921
1068
  console.log(stats.toString({
922
1069
  chunks: false,
923
1070
  assets: true,
924
- entryPoints: false,
1071
+ entrypoints: false,
925
1072
  modules: false,
926
1073
  moduleAssets: false,
927
- moduleChunks: false,
928
1074
  colors: true,
929
1075
  }));
930
1076
  console.log('App build process finished');
@@ -939,13 +1085,18 @@ const buildApp = async () => {
939
1085
  // process.exit();
940
1086
  });
941
1087
  }).then(async () => {
1088
+ var _a;
942
1089
  // make sure environment is not development for storage config
943
1090
  if (process.env.NODE_ENV === 'development') {
944
1091
  console.warn('Upload build to storage skip in development environment');
945
1092
  process.exit();
946
1093
  }
1094
+ if (process.env.APP_ENV) {
1095
+ console.warn('Not uploading to CDN for app builds');
1096
+ process.exit();
1097
+ }
947
1098
  // load the storage config
948
- const storageConfig = require(path_1.default.join(process.cwd(), 'scripts', 'storage-config'));
1099
+ const storageConfig = await (_a = path_1.default.join(process.cwd(), 'scripts', 'storage-config.js'), Promise.resolve().then(() => __importStar(require(_a))));
949
1100
  // check if LincdFileStorage has a default FileStore
950
1101
  // if yes: copy all the files in the build folder over with LincdFileStorage
951
1102
  if (LinkedFileStorage_1.LinkedFileStorage.getDefaultStore()) {
@@ -957,7 +1108,7 @@ const buildApp = async () => {
957
1108
  return;
958
1109
  }
959
1110
  // get all files in the web directory and then upload them to the storage
960
- const files = await (0, utils_1.getFiles)(pathDir);
1111
+ const files = await (0, utils_js_1.getFiles)(pathDir);
961
1112
  const uploads = files.map(async (filePath) => {
962
1113
  // read file content
963
1114
  const fileContent = await fs_extra_1.default.promises.readFile(filePath);
@@ -974,6 +1125,149 @@ const buildApp = async () => {
974
1125
  });
975
1126
  };
976
1127
  exports.buildApp = buildApp;
1128
+ const upgradePackages = async () => {
1129
+ await (0, exports.ensureEnvironmentLoaded)();
1130
+ // let packages = getLincdPackages();
1131
+ // let packages = getLocalLincdModules();
1132
+ let packages = getLocalLincdPackageMap();
1133
+ let dirname = (0, exports.getScriptDir)();
1134
+ const tsConfigCJS = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-cjs.json');
1135
+ const tsConfigESM = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-esm.json');
1136
+ const typesFile = path_1.default.join(dirname, '../../defaults/package/src', 'types.d.ts');
1137
+ const tsConfigTemplate = await fs_extra_1.default.readJson(path_1.default.join(dirname, '../../defaults/package', 'tsconfig.json')).catch(err => {
1138
+ console.log(err);
1139
+ });
1140
+ runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
1141
+ // packageGroup.forEach((pkg) => {
1142
+ // console.log(' Upgrading ' + pkg.packageName);
1143
+ console.log('-----');
1144
+ return async (pkg) => {
1145
+ if (pkg.packageName === 'lincd')
1146
+ return;
1147
+ // await execPromise(`cd ${pkg.path} && yarn upgrade`);
1148
+ console.log('Upgrading ' + pkg.packageName);
1149
+ //
1150
+ // //create a new file src/tsconfig-cjs.json
1151
+ // //copy the contents of tsconfig.json into it
1152
+ // if (!fs.existsSync(path.join(pkg.path,'tsconfig-cjs.json')))
1153
+ // {
1154
+ // await fs.copy(tsConfigCJS,path.join(pkg.path,'tsconfig-cjs.json'));
1155
+ // await fs.copy(tsConfigESM,path.join(pkg.path,'tsconfig-esm.json'));
1156
+ // console.log('Copied new tsconfig to ' + pkg.packageName);
1157
+ // }
1158
+ //
1159
+ // //read tsconfig
1160
+ // await fs.readJson(path.join(pkg.path,'tsconfig.json')).then((tsconfig) => {
1161
+ // let oldCompilerOpts = tsconfig.compilerOptions;
1162
+ // tsconfig.compilerOptions = tsConfigTemplate.compilerOptions;
1163
+ // tsconfig.compilerOptions.types = oldCompilerOpts.types;
1164
+ // tsconfig.compilerOptions.plugins = [{"name": "typescript-plugin-css-modules"}];
1165
+ //
1166
+ // console.log('Upgraded tsconfig for ' + pkg.packageName);
1167
+ // return fs.writeJson(path.join(pkg.path,'tsconfig.json'),tsconfig,{spaces: 2});
1168
+ // });
1169
+ // //import types at the beginning of index.ts
1170
+ // addLineToIndex(`import './types';`,null,pkg.path,true);
1171
+ // //copy over the types file
1172
+ // await fs.copy(typesFile,path.join(pkg.path,'src','types.d.ts'));
1173
+ // await fs.readJson(path.join(pkg.path,'package.json')).then((packageJson) => {
1174
+ // let version = packageJson.version;
1175
+ // let nextVersion;
1176
+ // if (version.split('.').shift() === '0')
1177
+ // {
1178
+ // nextVersion = getNextMajorVersion(version);
1179
+ // }
1180
+ // else
1181
+ // {
1182
+ // nextVersion = getNextMinorVersion(version);
1183
+ // }
1184
+ // console.log('Upgraded version for ' + pkg.packageName + ' to ' + nextVersion);
1185
+ //
1186
+ // packageJson.version = nextVersion;
1187
+ // packageJson.devDependencies['tsconfig-to-dual-package'] = '^1.2.0';
1188
+ // packageJson.devDependencies['typescript-plugin-css-modules'] = '^5.1.0';
1189
+ //
1190
+ // packageJson.main = 'lib/cjs/index.js';
1191
+ // packageJson.module = 'lib/esm/index.js';
1192
+ // packageJson.exports = {
1193
+ // '.': {
1194
+ // 'types': './lib/esm/index.d.ts',
1195
+ // 'import': './lib/esm/index.js',
1196
+ // 'require': './lib/cjs/index.js',
1197
+ // },
1198
+ // './*': {
1199
+ // 'types': './lib/esm/*.d.ts',
1200
+ // 'import': './lib/esm/*.js',
1201
+ // 'require': './lib/cjs/*.js',
1202
+ // },
1203
+ // };
1204
+ // packageJson.typesVersions = {
1205
+ // '*': {
1206
+ // '*': [
1207
+ // 'lib/esm/*',
1208
+ // ],
1209
+ // },
1210
+ // };
1211
+ //
1212
+ // return fs.writeJson(path.join(pkg.path,'package.json'),packageJson,{ spaces: 2 });
1213
+ // });
1214
+ //change .css files and .scss files to .module.css and .module.scss
1215
+ let files = await (0, utils_js_1.getFiles)(path_1.default.join(pkg.path, 'src'));
1216
+ // let tsFiles = files.filter(f => f.match(/\.(ts|tsx)$/));
1217
+ // let cssFiles = files.filter(f => f.match(/\.(css|scss)$/)).filter(f => !f.match(/\.module\.(css|scss)$/));
1218
+ // cssFiles.forEach(cssFile => {
1219
+ // let cssFileName = path.basename(cssFile);
1220
+ // let newFile = cssFileName.replace(/\.s?css$/,'.module$&');
1221
+ // let newFilePath = cssFile.replace(/\.s?css$/,'.module$&');
1222
+ // let jsonFile = cssFileName.replace(/\.s?css$/,'$&.json');
1223
+ // fs.renameSync(cssFile,newFilePath);
1224
+ // console.log('Renaming ' + cssFileName + ' to ' + newFilePath);
1225
+ // //find other files that import this file and update them
1226
+ // tsFiles.forEach(tsFile => {
1227
+ // //read contents of f2
1228
+ // let contents = fs.readFileSync(tsFile,'utf8');
1229
+ // //if it imports f
1230
+ // if (contents.indexOf(cssFileName) !== -1)
1231
+ // {
1232
+ // //find the whole line that imports f
1233
+ // let line = contents.split('\n').find(l => l.indexOf(cssFileName) !== -1);
1234
+ // // console.log("OLD: "+line);
1235
+ // let jsonLine = contents.split('\n').find(l => l.indexOf(jsonFile) !== -1);
1236
+ // // console.log("JSON: "+jsonLine);
1237
+ // //if not commented out
1238
+ // if(line.indexOf('//') === -1) {
1239
+ // let previousImportPath = line.match(/['"](.*)['"]/)[1];
1240
+ // let newImportPath = previousImportPath.replace(cssFileName,newFile);
1241
+ // let newContents = contents.replace(line,`import style from '${newImportPath}';`)
1242
+ // .replace(jsonLine+'\n','');
1243
+ // // console.log("\n");
1244
+ // fs.writeFileSync(tsFile,newContents);
1245
+ // console.log('Updated imports in ' + tsFile);
1246
+ // // fs.writeFileSync
1247
+ // // fs.writeFileSync(i,fs.readFileSync(i,'utf8').replace(f,newFile));
1248
+ // }
1249
+ // }
1250
+ // })
1251
+ // });
1252
+ files.filter(f => f.match(/\.(scss\.json|css\.json)$/)).forEach(cssJsonFile => {
1253
+ console.log('Removing ' + cssJsonFile);
1254
+ fs_extra_1.default.unlinkSync(cssJsonFile);
1255
+ });
1256
+ };
1257
+ // });
1258
+ }, () => {
1259
+ console.log('Finished upgrading packages');
1260
+ });
1261
+ // packages.forEach((pkg,key) => {
1262
+ // console.log(key+' Upgrading ' + pkg.packageName);
1263
+ // execPromise(`cd ${pkg.path} && yarn upgrade`).then(() => {
1264
+ // console.log('Upgraded ' + pkg.packageName);
1265
+ // }).catch(err => {
1266
+ // console.warn(err);
1267
+ // })
1268
+ // });
1269
+ };
1270
+ exports.upgradePackages = upgradePackages;
977
1271
  const createPackage = async (name, uriBase, basePath = process.cwd()) => {
978
1272
  if (!name) {
979
1273
  console.warn('Please provide a name as the first argument');
@@ -1005,8 +1299,8 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
1005
1299
  //extra variable for clarity (will be same as 'name')
1006
1300
  setVariable('output_file_name', name);
1007
1301
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(cleanPackageName);
1008
- log("Creating new LINCD package '" + name + "'");
1009
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package'), targetFolder);
1302
+ log('Creating new LINCD package \'' + name + '\'');
1303
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'package'), targetFolder);
1010
1304
  //replace variables in some of the copied files
1011
1305
  await Promise.all([
1012
1306
  'src/index.ts',
@@ -1033,14 +1327,14 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
1033
1327
  console.log('rename ', path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
1034
1328
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
1035
1329
  });
1036
- let version = (await (0, utils_1.execPromise)('yarn --version').catch((err) => {
1330
+ let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
1037
1331
  console.log('yarn probably not working');
1038
1332
  return '';
1039
1333
  }));
1040
1334
  let installCommand = version.toString().match(/[0-9]+/)
1041
1335
  ? 'yarn install'
1042
1336
  : 'npm install';
1043
- await (0, utils_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
1337
+ await (0, utils_js_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
1044
1338
  console.warn('Could not install dependencies');
1045
1339
  });
1046
1340
  log(`Prepared a new LINCD package in ${chalk_1.default.magenta(targetFolder)}`, `Run ${chalk_1.default.blueBright('yarn build')} from this directory to build once`, `Or ${chalk_1.default.blueBright('yarn dev')} to continuously rebuild on file changes`);
@@ -1062,43 +1356,6 @@ var buildFailed = function (output) {
1062
1356
  return (output.indexOf('Aborted due to warnings') !== -1 &&
1063
1357
  output.indexOf('Command failed') !== -1);
1064
1358
  };
1065
- /*program.command('shapes').action(async () => {
1066
- //we've imported require-extensions from npm so that we can use this
1067
- //we want to avoid nodejs tripping up over @import commands in css files
1068
- require.extensions['.scss'] = function (sourcecode, filename) {
1069
- return {};
1070
- };
1071
- require.extensions['.css'] = function (sourcecode, filename) {
1072
- return {};
1073
- };
1074
-
1075
- if (fs.existsSync(process.cwd() + '/package.json')) {
1076
- var pack = JSON.parse(
1077
- fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
1078
- );
1079
- let packageName = pack.name;
1080
-
1081
- //just making sure the library is loaded in correct order because circular references are currently happening when importing BlankNode before NamedNode for example
1082
- // require('lincd');
1083
- //TODO: replace with actual index file from package.json, or tsconfig
1084
- let indexExports = require(process.cwd() + '/lib/index.js');
1085
- if(indexExports.packageExports)
1086
- {
1087
- let shapeJSONLD = await getShapesJSONLD(indexExports.packageExports);
1088
- console.log(indexExports.packageExports);
1089
- console.log(shapeJSONLD);
1090
- console.log(chalk.bold(chalk.green(packageName+'/dist/shapes.json')));
1091
- return fs.writeFile(path.join('dist', 'shapes.json'), shapeJSONLD);
1092
- }
1093
- else
1094
- {
1095
- console.warn("Invalid LINCD package. Index file should export a packageExports object. See examples.")
1096
- }
1097
-
1098
- } else {
1099
- console.warn('Not a project');
1100
- }
1101
- });*/
1102
1359
  const register = function (registryURL) {
1103
1360
  if (fs_extra_1.default.existsSync(process.cwd() + '/package.json')) {
1104
1361
  var pack = JSON.parse(fs_extra_1.default.readFileSync(process.cwd() + '/package.json', 'utf8'));
@@ -1146,58 +1403,139 @@ const register = function (registryURL) {
1146
1403
  }
1147
1404
  };
1148
1405
  exports.register = register;
1149
- const buildPackage = (target, target2, packagePath = process.cwd(), logResults = true) => {
1150
- if (target == 'production' || target == 'es5' || target == 'es6' || !target) {
1151
- if (!fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'Gruntfile.js'))) {
1152
- console.warn(`No Gruntfile found at ${packagePath}\\Gruntfile.js. Cannot build.`);
1153
- return;
1154
- }
1155
- var nodeEnv = '';
1156
- if (target == 'production') {
1157
- if (!(target2 == 'es5' || target2 == 'es6' || typeof target2 == 'undefined')) {
1158
- console.warn('unknown second build target. Use es5 or es6', target2);
1159
- return;
1160
- }
1161
- var isWindows = /^win/.test(process.platform);
1162
- if (isWindows) {
1163
- nodeEnv = 'SET NODE_ENV=production&& ';
1164
- }
1165
- else {
1166
- nodeEnv = "NODE_ENV='production' ";
1406
+ const buildPackage = async (target, target2, packagePath = process.cwd(), logResults = true) => {
1407
+ let spinner;
1408
+ if (logResults) {
1409
+ //TODO: replace with listr so we can show multiple processes at once
1410
+ spinner = (0, ora_1.default)({
1411
+ discardStdin: true,
1412
+ text: 'Compiling code',
1413
+ }).start();
1414
+ }
1415
+ let buildProcess = Promise.resolve(true);
1416
+ let buildStep = (step) => {
1417
+ buildProcess = buildProcess.then((previousResult) => {
1418
+ if (logResults) {
1419
+ spinner.text = step.name;
1420
+ spinner.start();
1167
1421
  }
1422
+ return step.apply().then(stepResult => {
1423
+ if (typeof stepResult === 'string') {
1424
+ // spinner.text = step.name + ' - ' + stepResult;
1425
+ if (logResults) {
1426
+ spinner.warn(step.name + ' - ' + stepResult);
1427
+ spinner.stop();
1428
+ }
1429
+ //warning is shown, but build is still succesful with warnings
1430
+ return false;
1431
+ }
1432
+ else if (stepResult === true || typeof stepResult === 'undefined') {
1433
+ if (logResults) {
1434
+ spinner.succeed();
1435
+ }
1436
+ return previousResult && true;
1437
+ }
1438
+ });
1439
+ });
1440
+ };
1441
+ buildStep({
1442
+ name: 'Compiling code',
1443
+ apply: async () => {
1444
+ return (0, exports.compilePackage)(packagePath);
1445
+ },
1446
+ });
1447
+ buildStep({
1448
+ name: 'Copying files to lib folder',
1449
+ apply: async () => {
1450
+ const files = await (0, glob_1.glob)(packagePath + '/src/**/*.{json,d.ts,css,scss}');
1451
+ return Promise.all(files.map((async (file) => {
1452
+ try {
1453
+ await fs_extra_1.default.copy(file, packagePath + '/lib/esm/' + file.replace(packagePath + '/src/', ''));
1454
+ await fs_extra_1.default.copy(file, packagePath + '/lib/cjs/' + file.replace(packagePath + '/src/', ''));
1455
+ return true;
1456
+ }
1457
+ catch (err) {
1458
+ console.warn(err);
1459
+ return false;
1460
+ }
1461
+ ;
1462
+ }))).then((allResults) => {
1463
+ return allResults.every(r => r === true);
1464
+ });
1465
+ },
1466
+ });
1467
+ buildStep({
1468
+ name: 'Dual package support',
1469
+ apply: () => {
1470
+ return (0, utils_js_1.execPromise)('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then(res => {
1471
+ return res === '';
1472
+ });
1473
+ },
1474
+ });
1475
+ buildStep({
1476
+ name: 'Removing old files from lib folder',
1477
+ apply: async () => {
1478
+ return (0, exports.removeOldFiles)(packagePath);
1479
+ },
1480
+ });
1481
+ buildStep({
1482
+ name: 'Checking imports',
1483
+ apply: () => (0, exports.checkImports)(packagePath),
1484
+ });
1485
+ buildStep({
1486
+ name: 'Checking dependencies',
1487
+ apply: () => (0, exports.depCheck)(packagePath),
1488
+ });
1489
+ let success = await buildProcess.catch(err => {
1490
+ //err.error + ':\n' +
1491
+ let msg = (err && err.stdout && err.error) ? err.stdout : err.toString();
1492
+ if (logResults) {
1493
+ spinner.stopAndPersist({
1494
+ symbol: chalk_1.default.red('✖'),
1495
+ text: 'Build failed',
1496
+ });
1168
1497
  }
1169
- if (!target) {
1170
- target = 'es6';
1498
+ else {
1499
+ console.log(chalk_1.default.red(packagePath.split('/').pop(), ' - Build failed:'));
1500
+ }
1501
+ console.log(msg);
1502
+ });
1503
+ //will be undefined if there was an error
1504
+ if (typeof success !== 'undefined') {
1505
+ if (logResults) {
1506
+ spinner.stopAndPersist({
1507
+ symbol: chalk_1.default.greenBright('✔'),
1508
+ text: success === true ? 'Build successful' : 'Build successful with warnings',
1509
+ });
1171
1510
  }
1172
- log('building once: ' +
1173
- nodeEnv +
1174
- 'grunt build' +
1175
- (target ? '-' + target : '') +
1176
- (target2 ? '-' + target2 : '') +
1177
- ' --color');
1178
- let method = logResults ? utils_1.execp : utils_1.execPromise;
1179
- //NOTE: we moved SCSS:JSON out of webpack and grunt, into this file
1180
- //this is the beginning of a transition away from grunt
1181
- //but for the time being it's perhaps a bit strange that we
1182
- // let x = postcss([
1183
- // postcssModules({
1184
- // generateScopedName,
1185
- // }),
1186
- // ]);
1187
- //execute the command to build the method, and provide the current work directory as option
1188
- return method(nodeEnv +
1189
- 'grunt build' +
1190
- (target ? '-' + target : '') +
1191
- (target2 ? '-' + target2 : '') +
1192
- ' --color', false, false, { cwd: packagePath }).catch((err) => {
1193
- process.exit(1);
1194
- });
1511
+ }
1512
+ return success;
1513
+ };
1514
+ exports.buildPackage = buildPackage;
1515
+ const compilePackage = async (packagePath = process.cwd()) => {
1516
+ //echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
1517
+ let cjsConfig = fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'tsconfig-cjs.json'));
1518
+ let esmConfig = fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'tsconfig-esm.json'));
1519
+ let compileCJS = `yarn exec tsc -p tsconfig-cjs.json`;
1520
+ let compileESM = `yarn exec tsc -p tsconfig-esm.json`;
1521
+ let compileCommand;
1522
+ if (cjsConfig && esmConfig) {
1523
+ compileCommand = `${compileCJS} && ${compileESM}`;
1524
+ }
1525
+ else if (cjsConfig) {
1526
+ compileCommand = compileCJS;
1527
+ }
1528
+ else if (esmConfig) {
1529
+ compileCommand = compileESM;
1195
1530
  }
1196
1531
  else {
1197
- console.warn('unknown build target. Use es5, es6 or production.');
1532
+ compileCommand = `yarn exec tsc`;
1198
1533
  }
1534
+ return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
1535
+ return res === '';
1536
+ });
1199
1537
  };
1200
- exports.buildPackage = buildPackage;
1538
+ exports.compilePackage = compilePackage;
1201
1539
  var publishUpdated = function (test = false) {
1202
1540
  let packages = getLocalLincdModules();
1203
1541
  var p = Promise.resolve('');
@@ -1215,22 +1553,22 @@ var publishUpdated = function (test = false) {
1215
1553
  // console.log("Will be requesting npm view from this current working directory:\n"+process.cwd());
1216
1554
  // return execPromise('npm view '+pkg.packageName+' --json').then((output:string) => {
1217
1555
  let shouldPublish;
1218
- var pack = (0, utils_1.getPackageJSON)(pckg.path);
1556
+ var pack = (0, utils_js_1.getPackageJSON)(pckg.path);
1219
1557
  let version = getNextVersion(pack.version);
1220
1558
  if (pack.private) {
1221
1559
  shouldPublish = false;
1222
- (0, utils_1.debugInfo)(chalk_1.default.blue('--> is private, skipping'));
1560
+ (0, utils_js_1.debugInfo)(chalk_1.default.blue('--> is private, skipping'));
1223
1561
  return chalk_1.default.gray(pckg.packageName + ' is private');
1224
1562
  // return previousResult + ' ' + chalk.gray(pckg.packageName + ' is private\n');
1225
1563
  }
1226
1564
  console.log('testing npm');
1227
- return (0, utils_1.execPromise)('npm info ' + pckg.packageName + ' --json')
1565
+ return (0, utils_js_1.execPromise)('npm info ' + pckg.packageName + ' --json')
1228
1566
  .then(async (output) => {
1229
1567
  console.log('testing npm done');
1230
1568
  var info;
1231
1569
  try {
1232
1570
  if (output == '' || output.includes('E404')) {
1233
- (0, utils_1.debugInfo)('Empty or 404 response from `npm info`. This package was probably not published before');
1571
+ (0, utils_js_1.debugInfo)('Empty or 404 response from `npm info`. This package was probably not published before');
1234
1572
  // throw new Error('Empty response from `yarn info`. This pkg was probably not published before');
1235
1573
  // return;
1236
1574
  shouldPublish = true;
@@ -1253,10 +1591,10 @@ var publishUpdated = function (test = false) {
1253
1591
  // }
1254
1592
  let lastPublishDate = new Date(lastPublish);
1255
1593
  // let {lastModifiedTime, lastModifiedName, lastModified} = getLastModifiedSourceTime(pkg.path);
1256
- let lastCommitInfo = await (0, utils_1.getLastCommitTime)(pckg.path);
1594
+ let lastCommitInfo = await (0, utils_js_1.getLastCommitTime)(pckg.path);
1257
1595
  if (!lastCommitInfo) {
1258
1596
  shouldPublish = false;
1259
- (0, utils_1.debugInfo)('Could not determine last git commit');
1597
+ (0, utils_js_1.debugInfo)('Could not determine last git commit');
1260
1598
  // return previousResult + ' ' + chalk.red(pckg.packageName + ' - could not determine last commit\n');
1261
1599
  return chalk_1.default.red(pckg.packageName + ' - could not determine last commit');
1262
1600
  }
@@ -1350,7 +1688,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
1350
1688
  }
1351
1689
  // let path = './';
1352
1690
  for (let i = 0; i <= 10; i++) {
1353
- let envFile = await (0, get_env_vars_1.getEnvFile)({
1691
+ let envFile = await (0, get_env_vars_js_1.getEnvFile)({
1354
1692
  filePath: relativeToPath + path + '.env.json',
1355
1693
  }).catch((err) => {
1356
1694
  return null;
@@ -1364,7 +1702,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
1364
1702
  }
1365
1703
  var publishPackage = async function (pkg, test, info, publishVersion) {
1366
1704
  if (!pkg) {
1367
- let localPackageJson = (0, utils_1.getPackageJSON)();
1705
+ let localPackageJson = (0, utils_js_1.getPackageJSON)();
1368
1706
  pkg = {
1369
1707
  path: process.cwd(),
1370
1708
  packageName: localPackageJson.name,
@@ -1374,18 +1712,18 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
1374
1712
  publishVersion = info ? getNextVersion(info.version) : 'patch';
1375
1713
  }
1376
1714
  if (test) {
1377
- (0, utils_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
1715
+ (0, utils_js_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
1378
1716
  //when testing what needs to be published
1379
1717
  return chalk_1.default.blue(pkg.packageName + ' should publish');
1380
1718
  }
1381
1719
  console.log(chalk_1.default.blue('publishing ' + pkg.packageName + ' ' + publishVersion));
1382
1720
  //looking for an .env.json file in our workspace, which may store our NPM AUTH key
1383
1721
  let envJsonPath = await getEnvJsonPath(pkg.path);
1384
- return (0, utils_1.execPromise)(`cd ${pkg.path} && ${envJsonPath ? `env-cmd -f ${envJsonPath} --use-shell "` : ''}yarn version ${publishVersion} && yarn npm publish${envJsonPath ? `"` : ''}`, true, false, {}, true)
1722
+ return (0, utils_js_1.execPromise)(`cd ${pkg.path} && ${envJsonPath ? `env-cmd -f ${envJsonPath} --use-shell "` : ''}yarn version ${publishVersion} && yarn npm publish${envJsonPath ? `"` : ''}`, true, false, {}, true)
1385
1723
  .then((res) => {
1386
1724
  if (res.indexOf('Aborted due to warnings') !== -1 ||
1387
1725
  res.indexOf('Could not publish') !== -1 ||
1388
- res.indexOf("Couldn't publish") !== -1) {
1726
+ res.indexOf('Couldn\'t publish') !== -1) {
1389
1727
  console.log(res);
1390
1728
  return chalk_1.default.red(pkg.packageName + ' failed\n');
1391
1729
  }
@@ -1414,12 +1752,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1414
1752
  // let packages = getLocalLincdModules();
1415
1753
  let packages = getLocalLincdPackageMap();
1416
1754
  // console.log(packages);
1417
- let jsonldPkgUpdated = await (0, utils_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
1755
+ let jsonldPkgUpdated = await (0, utils_js_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
1418
1756
  // let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
1419
1757
  //if either cli or jsonldPkg needs to be rebuilt
1420
1758
  // if (jsonldPkgUpdated || cliPkgUpdated) {
1421
1759
  if (jsonldPkgUpdated) {
1422
- await (0, utils_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
1760
+ await (0, utils_js_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
1423
1761
  cwd: packages.get('lincd-jsonld').path,
1424
1762
  }, true);
1425
1763
  // await execPromise('yarn build-core', false, false, {}, true);
@@ -1431,12 +1769,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1431
1769
  // }
1432
1770
  let packagesLeft = packages.size;
1433
1771
  runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
1434
- (0, utils_1.debugInfo)('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
1435
- (0, utils_1.debugInfo)(packagesLeft + ' packages left.');
1772
+ (0, utils_js_1.debugInfo)('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
1773
+ (0, utils_js_1.debugInfo)(packagesLeft + ' packages left.');
1436
1774
  packagesLeft = packagesLeft - packageGroup.length;
1437
1775
  return async (pkg) => {
1438
1776
  // debugInfo('# Checking package ' + pkg.packageName);
1439
- let needRebuild = await (0, utils_1.needsRebuilding)(pkg, useGitForLastModified);
1777
+ let needRebuild = await (0, utils_js_1.needsRebuilding)(pkg, useGitForLastModified);
1440
1778
  if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
1441
1779
  needRebuild = true;
1442
1780
  }
@@ -1444,18 +1782,26 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1444
1782
  //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1445
1783
  // log(packageName+' modified since last commit on '+now.toString());
1446
1784
  if (test) {
1447
- (0, utils_1.debugInfo)('Need to build ' + pkg.packageName);
1785
+ (0, utils_js_1.debugInfo)('Need to build ' + pkg.packageName);
1448
1786
  return chalk_1.default.blue(pkg.packageName + ' should be build');
1449
1787
  }
1450
1788
  log('Building ' + pkg.packageName);
1451
- return (0, utils_1.execPromise)('cd ' +
1789
+ // return buildPackage(null,null,pkg.path)
1790
+ return (0, utils_js_1.execPromise)('cd ' +
1452
1791
  pkg.path +
1453
1792
  ' && yarn build' +
1454
1793
  (target ? ' ' + target : '') +
1455
1794
  (target2 ? ' ' + target2 : ''))
1456
1795
  .then((res) => {
1457
- (0, utils_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
1458
- return chalk_1.default.green(pkg.packageName + ' built');
1796
+ if (res === '') {
1797
+ (0, utils_js_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
1798
+ return chalk_1.default.green(pkg.packageName + ' built');
1799
+ }
1800
+ else if (typeof res === 'string') {
1801
+ warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
1802
+ console.log(res);
1803
+ process.exit(1);
1804
+ }
1459
1805
  })
1460
1806
  .catch(({ error, stdout, stderr }) => {
1461
1807
  warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
@@ -1487,9 +1833,11 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1487
1833
  };
1488
1834
  exports.buildUpdated = buildUpdated;
1489
1835
  const printBuildResults = function (failed, done) {
1490
- log('Successfully built: ' +
1491
- chalk_1.default.green([...done].map((m) => m.packageName).join(', ')) +
1492
- '\n');
1836
+ if (done.size > 0 || done.length > 0) {
1837
+ log('Successfully built: ' +
1838
+ chalk_1.default.green([...done].map((m) => m.packageName).join(', ')) +
1839
+ '\n');
1840
+ }
1493
1841
  if (failed.length > 0) {
1494
1842
  warn('Failed to build: ' + chalk_1.default.red(failed.join(', ')) + '\n');
1495
1843
  }
@@ -1520,15 +1868,15 @@ var executeCommandForEachPackage = function (packages, command, filterMethod, fi
1520
1868
  return seen;
1521
1869
  });
1522
1870
  }
1523
- log("Executing '" +
1871
+ log('Executing \'' +
1524
1872
  chalk_1.default.blueBright(command) +
1525
- "' on packages " +
1873
+ '\' on packages ' +
1526
1874
  chalk_1.default.magenta(packages.map((m) => m.packageName).join(', ')));
1527
1875
  var p = Promise.resolve(true);
1528
1876
  packages.forEach((pkg) => {
1529
1877
  p = p.then(() => {
1530
1878
  log('# Package ' + chalk_1.default.magenta(pkg.packageName));
1531
- return (0, utils_1.execp)('cd ' + pkg.path + ' && ' + command);
1879
+ return (0, utils_js_1.execp)('cd ' + pkg.path + ' && ' + command);
1532
1880
  });
1533
1881
  });
1534
1882
  return p;
@@ -1550,8 +1898,8 @@ exports.addLinesToFile = addLinesToFile;
1550
1898
  var addCapacitor = async function (basePath = process.cwd()) {
1551
1899
  let targetFolder = ensureFolderExists(basePath);
1552
1900
  log('Adding capacitor');
1553
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'app-static'), targetFolder);
1554
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'capacitor', 'scripts'), path_1.default.join(targetFolder, 'scripts'));
1901
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'app-static'), targetFolder);
1902
+ fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'capacitor', 'scripts'), path_1.default.join(targetFolder, 'scripts'));
1555
1903
  //update .env-cmdrc.json file
1556
1904
  let envCmdPath = path_1.default.resolve(basePath, '.env-cmdrc.json');
1557
1905
  let envCmd = JSON.parse(fs_extra_1.default.readFileSync(envCmdPath, { encoding: 'utf8' }));
@@ -1573,7 +1921,7 @@ var addCapacitor = async function (basePath = process.cwd()) {
1573
1921
  log('Edited .env-cmdrc.json');
1574
1922
  gitIgnore('android/app/build', 'android/**/capacitor.build.gradle', 'ios/App/App/public');
1575
1923
  //update package.json scripts
1576
- let pack = (0, utils_1.getPackageJSON)(basePath);
1924
+ let pack = (0, utils_js_1.getPackageJSON)(basePath);
1577
1925
  pack.scripts['build-staging'] =
1578
1926
  'env-cmd -e _main, staging node scripts/build.js';
1579
1927
  pack.scripts['fix-app'] = 'node scripts/fix-namespace.js';
@@ -1588,8 +1936,8 @@ var addCapacitor = async function (basePath = process.cwd()) {
1588
1936
  pack.scripts['cap:sync'] = 'yarn cap sync';
1589
1937
  fs_extra_1.default.writeFile(path_1.default.resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
1590
1938
  log('Added new run script to package.json');
1591
- await (0, utils_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
1592
- await (0, utils_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/app @capacitor/ios`, false, false, null, true);
1939
+ await (0, utils_js_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
1940
+ await (0, utils_js_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/app @capacitor/ios`, false, false, null, true);
1593
1941
  // TODO: Do we need to add `npx cap init`? If yes, we should not copy capacitor config.ts yet
1594
1942
  // await execPromise(`npx cap init`, true, false, null, true);
1595
1943
  // got error:
@@ -1606,20 +1954,53 @@ var executeCommandForPackage = function (packageName, command) {
1606
1954
  let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
1607
1955
  modDetails.packageName.indexOf(packageName) !== -1);
1608
1956
  if (packageDetails) {
1609
- log("Executing 'cd " +
1957
+ log('Executing \'cd ' +
1610
1958
  packageDetails.path +
1611
1959
  ' && yarn exec lincd' +
1612
1960
  (command ? ' ' + command : '') +
1613
- "'");
1614
- return (0, utils_1.execp)('cd ' +
1961
+ '\'');
1962
+ return (0, utils_js_1.execp)('cd ' +
1615
1963
  packageDetails.path +
1616
1964
  ' && yarn exec lincd' +
1617
1965
  (command ? ' ' + command : ''));
1618
1966
  }
1619
1967
  else {
1620
- warn("Could not find a pkg who's name (partially) matched " +
1968
+ warn('Could not find a pkg who\'s name (partially) matched ' +
1621
1969
  chalk_1.default.cyan(packageName));
1622
1970
  }
1623
1971
  };
1624
1972
  exports.executeCommandForPackage = executeCommandForPackage;
1973
+ /**
1974
+ * Function to remove files older than 10 seconds from the 'lib' folder.
1975
+ * @param {string} packagePath - The path to the package directory.
1976
+ */
1977
+ const removeOldFiles = async (packagePath) => {
1978
+ const libPath = path_1.default.join(packagePath, 'lib');
1979
+ try {
1980
+ // Read all files in the 'lib' folder asynchronously
1981
+ const files = await (0, glob_1.glob)(packagePath + '/lib/**/*.*');
1982
+ // Iterate through each file
1983
+ for (const file of files) {
1984
+ // const filePath = path.join(libPath, file);
1985
+ // Check if the file exists before attempting to delete it
1986
+ // if (await fs.pathExists(filePath)) {
1987
+ const stats = await fs_extra_1.default.stat(file);
1988
+ const currentTime = new Date().getTime();
1989
+ const lastModifiedTime = stats.mtime.getTime();
1990
+ // Check if the difference between the current time and last modified time is greater than 10 seconds
1991
+ if (currentTime - lastModifiedTime > 10000) {
1992
+ // Attempt to delete the file
1993
+ await fs_extra_1.default.unlink(file);
1994
+ // console.log(`Removed: ${file}`);
1995
+ }
1996
+ // }
1997
+ }
1998
+ return true;
1999
+ }
2000
+ catch (error) {
2001
+ console.error(`Error removing files: ${error.message}`);
2002
+ return false;
2003
+ }
2004
+ };
2005
+ exports.removeOldFiles = removeOldFiles;
1625
2006
  //# sourceMappingURL=cli-methods.js.map