lincd-cli 1.1.2 → 1.1.4

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 (97) hide show
  1. package/defaults/app-static/src/index-static.tsx +3 -3
  2. package/defaults/app-with-backend/.env-cmdrc.json +4 -1
  3. package/defaults/app-with-backend/package.json +9 -8
  4. package/defaults/app-with-backend/scripts/storage-config.js +2 -2
  5. package/defaults/app-with-backend/src/package.ts +2 -1
  6. package/defaults/component.tsx +3 -1
  7. package/defaults/package/package.json +2 -2
  8. package/defaults/package/src/index.ts +0 -1
  9. package/defaults/package/src/ontologies/example-ontology.ts +3 -10
  10. package/defaults/package/src/package.ts +3 -11
  11. package/defaults/set-component.tsx +5 -2
  12. package/defaults/shape.ts +2 -2
  13. package/lib/{cjs/cli-methods.js → cli-methods.js} +293 -663
  14. package/lib/cli-methods.js.map +1 -0
  15. package/lib/{esm/cli.js → cli.js} +44 -59
  16. package/lib/cli.js.map +1 -0
  17. package/lib/{cjs/config-grunt.cjs → config-grunt.js} +13 -15
  18. package/lib/config-grunt.js.map +1 -0
  19. package/lib/config-webpack-app.js +367 -0
  20. package/lib/config-webpack-app.js.map +1 -0
  21. package/lib/{esm/config-webpack.js → config-webpack.js} +39 -27
  22. package/lib/config-webpack.js.map +1 -0
  23. package/lib/{cjs/index.js → index.js} +5 -3
  24. package/lib/index.js.map +1 -0
  25. package/lib/{cjs/interfaces.js.map → interfaces.js.map} +1 -1
  26. package/lib/metadata.js +149 -0
  27. package/lib/metadata.js.map +1 -0
  28. package/lib/plugins/check-imports.js.map +1 -0
  29. package/lib/{esm/plugins → plugins}/declaration-plugin.js +8 -9
  30. package/lib/plugins/declaration-plugin.js.map +1 -0
  31. package/lib/{esm/plugins → plugins}/externalise-modules.js +6 -5
  32. package/lib/plugins/externalise-modules.js.map +1 -0
  33. package/lib/plugins/watch-run.js.map +1 -0
  34. package/lib/{cjs/utils.js → utils.js} +18 -22
  35. package/lib/utils.js.map +1 -0
  36. package/package.json +15 -53
  37. package/defaults/app-static/.env-cmdrc.json +0 -17
  38. package/defaults/app-static/package.json +0 -8
  39. package/defaults/package/src/types.d.ts +0 -9
  40. package/defaults/package/tsconfig-cjs.json +0 -8
  41. package/defaults/package/tsconfig-esm.json +0 -9
  42. package/lib/cjs/cli-methods.js.map +0 -1
  43. package/lib/cjs/cli.js +0 -202
  44. package/lib/cjs/cli.js.map +0 -1
  45. package/lib/cjs/config-grunt.cjs.map +0 -1
  46. package/lib/cjs/config-webpack-app.js +0 -353
  47. package/lib/cjs/config-webpack-app.js.map +0 -1
  48. package/lib/cjs/config-webpack.js +0 -436
  49. package/lib/cjs/config-webpack.js.map +0 -1
  50. package/lib/cjs/index.js.map +0 -1
  51. package/lib/cjs/loaders/css-loader.mjs +0 -82
  52. package/lib/cjs/loaders/css-loader.mjs.map +0 -1
  53. package/lib/cjs/loaders/register.js +0 -6
  54. package/lib/cjs/loaders/register.js.map +0 -1
  55. package/lib/cjs/metadata.js +0 -155
  56. package/lib/cjs/metadata.js.map +0 -1
  57. package/lib/cjs/package.json +0 -139
  58. package/lib/cjs/plugins/check-imports.js.map +0 -1
  59. package/lib/cjs/plugins/declaration-plugin.js +0 -275
  60. package/lib/cjs/plugins/declaration-plugin.js.map +0 -1
  61. package/lib/cjs/plugins/externalise-modules.js +0 -190
  62. package/lib/cjs/plugins/externalise-modules.js.map +0 -1
  63. package/lib/cjs/plugins/watch-run.js.map +0 -1
  64. package/lib/cjs/utils.js.map +0 -1
  65. package/lib/esm/cli-methods.js +0 -1965
  66. package/lib/esm/cli-methods.js.map +0 -1
  67. package/lib/esm/cli.js.map +0 -1
  68. package/lib/esm/config-grunt.cjs +0 -270
  69. package/lib/esm/config-grunt.cjs.map +0 -1
  70. package/lib/esm/config-webpack-app.js +0 -326
  71. package/lib/esm/config-webpack-app.js.map +0 -1
  72. package/lib/esm/config-webpack.js.map +0 -1
  73. package/lib/esm/index.js +0 -9
  74. package/lib/esm/index.js.map +0 -1
  75. package/lib/esm/interfaces.js +0 -2
  76. package/lib/esm/interfaces.js.map +0 -1
  77. package/lib/esm/loaders/css-loader.mjs +0 -75
  78. package/lib/esm/loaders/css-loader.mjs.map +0 -1
  79. package/lib/esm/loaders/register.js +0 -4
  80. package/lib/esm/loaders/register.js.map +0 -1
  81. package/lib/esm/metadata.js +0 -155
  82. package/lib/esm/metadata.js.map +0 -1
  83. package/lib/esm/package.json +0 -139
  84. package/lib/esm/plugins/check-imports.js +0 -65
  85. package/lib/esm/plugins/check-imports.js.map +0 -1
  86. package/lib/esm/plugins/declaration-plugin.js.map +0 -1
  87. package/lib/esm/plugins/externalise-modules.js.map +0 -1
  88. package/lib/esm/plugins/watch-run.js +0 -44
  89. package/lib/esm/plugins/watch-run.js.map +0 -1
  90. package/lib/esm/utils.js +0 -478
  91. package/lib/esm/utils.js.map +0 -1
  92. package/tsconfig-cjs.json +0 -9
  93. package/tsconfig-esm.json +0 -10
  94. /package/{expose-grunt.cjs → expose-grunt.js} +0 -0
  95. /package/lib/{cjs/interfaces.js → interfaces.js} +0 -0
  96. /package/lib/{cjs/plugins → plugins}/check-imports.js +0 -0
  97. /package/lib/{cjs/plugins → plugins}/watch-run.js +0 -0
@@ -1,50 +1,24 @@
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
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
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;
6
+ exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.removeOldFiles = 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;
30
7
  const chalk_1 = __importDefault(require("chalk"));
31
8
  const child_process_1 = require("child_process");
32
9
  const depcheck_1 = __importDefault(require("depcheck"));
33
- const get_env_vars_js_1 = require("env-cmd/dist/get-env-vars.js");
10
+ const get_env_vars_1 = require("env-cmd/dist/get-env-vars");
34
11
  const fs_extra_1 = __importDefault(require("fs-extra"));
35
- const path_1 = __importStar(require("path"));
36
- const utils_js_1 = require("./utils.js");
12
+ const path_1 = __importDefault(require("path"));
13
+ const utils_1 = require("./utils");
37
14
  const fs_1 = require("fs");
38
15
  const find_nearest_package_json_1 = require("find-nearest-package-json");
39
- const LinkedFileStorage_1 = require("lincd/utils/LinkedFileStorage");
40
- // import pkg from 'lincd/utils/LinkedFileStorage';
41
- // const { LinkedFileStorage } = pkg;
42
16
  // const config = require('lincd-server/site.webpack.config');
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"));
17
+ var glob = require('glob');
47
18
  var variables = {};
19
+ var open = require('open');
20
+ var stagedGitFiles = require('staged-git-files');
21
+ const webpack = require('webpack');
48
22
  const createApp = async (name, basePath = process.cwd()) => {
49
23
  if (!name) {
50
24
  console.warn('Please provide a name as the first argument');
@@ -63,21 +37,21 @@ const createApp = async (name, basePath = process.cwd()) => {
63
37
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'gitignore.template'), path_1.default.join(targetFolder, '.gitignore'));
64
38
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'yarnrc.yml.template'), path_1.default.join(targetFolder, '.yarnrc.yml'));
65
39
  // fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
66
- log('Creating new LINCD application \'' + name + '\'');
40
+ log("Creating new LINCD application '" + name + "'");
67
41
  //replace variables in some copied files
68
42
  await replaceVariablesInFolder(targetFolder);
69
43
  let hasYarn = await hasYarnInstalled();
70
44
  let installCommand = hasYarn
71
45
  ? 'export NODE_OPTIONS="--no-network-family-autoselection" && yarn install'
72
46
  : 'npm install';
73
- await (0, utils_js_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
47
+ await (0, utils_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
74
48
  console.warn('Could not install dependencies or start application');
75
49
  });
76
50
  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')}`);
77
51
  };
78
52
  exports.createApp = createApp;
79
53
  function logHelp() {
80
- (0, utils_js_1.execp)('yarn exec lincd help');
54
+ (0, utils_1.execp)('yarn exec lincd help');
81
55
  }
82
56
  function log(...messages) {
83
57
  messages.forEach((message) => {
@@ -90,7 +64,7 @@ function progressUpdate(message) {
90
64
  }
91
65
  function warn(...messages) {
92
66
  messages.forEach((message) => {
93
- console.log(chalk_1.default.redBright('Warning: ') + message);
67
+ console.log(chalk_1.default.magenta('Warning: ') + message);
94
68
  // console.log(chalk.red(message));
95
69
  });
96
70
  }
@@ -166,7 +140,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
166
140
  //get dependencies of each package
167
141
  let leastDependentPackage;
168
142
  lincdPackages.forEach((pkg) => {
169
- var pack = (0, utils_js_1.getPackageJSON)(pkg.path);
143
+ var pack = (0, utils_1.getPackageJSON)(pkg.path);
170
144
  if (pack) {
171
145
  //get lincd related dependencies and get the actual package details from the package map by removing '@dacore/' from the package name
172
146
  let packageDependencies = Object.keys(pack.dependencies)
@@ -191,17 +165,9 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
191
165
  let startStack = [leastDependentPackage];
192
166
  const runPackage = (runFunction, pck) => {
193
167
  return runFunction(pck)
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
- }
168
+ .catch(({ error, stdout, stderr }) => {
169
+ warn('Uncaught exception whilst running parallel function on ' +
170
+ pck.packageName, error.message);
205
171
  // warn(chalk.red(pck.packageName+' failed:'));
206
172
  // console.log(stdout);
207
173
  })
@@ -370,10 +336,10 @@ function buildAll(options) {
370
336
  // let packagesLeft = lincdPackages.size - done.size;
371
337
  runOnPackagesGroupedByDependencies(lincdPackages, (packageGroup, dependencies) => {
372
338
  if (done.size > 0) {
373
- (0, utils_js_1.debugInfo)(chalk_1.default.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
339
+ (0, utils_1.debugInfo)(chalk_1.default.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
374
340
  // log(stack);
375
341
  }
376
- (0, utils_js_1.debugInfo)('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
342
+ (0, utils_1.debugInfo)('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
377
343
  return async (pkg) => {
378
344
  let command;
379
345
  let skipping = false;
@@ -392,119 +358,50 @@ function buildAll(options) {
392
358
  }
393
359
  //unless told otherwise, build the package
394
360
  if (!command) {
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
- // );
361
+ command = (0, utils_1.execPromise)('cd ' + pkg.path + ' && yarn exec lincd build',
362
+ // (target ? ' ' + target : '') +
363
+ // (target2 ? ' ' + target2 : ''),
364
+ false, false, {}, false);
405
365
  log(chalk_1.default.cyan('Building ' + pkg.packageName));
406
366
  process.stdout.write(packagesLeft + ' packages left\r');
407
367
  }
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(", ")));
427
- process.exit(1);
428
- }
368
+ return command
369
+ .catch(({ error, stdout, stderr }) => {
370
+ //this prints out the webpack output, including the build errors
371
+ warn('Failed to build ' + pkg.packageName);
372
+ console.log(stdout);
373
+ failedModules.push(pkg.packageName);
374
+ let dependentModules = getDependentPackages(dependencies, pkg);
375
+ if (dependentModules.length > 0) {
376
+ printBuildResults(failedModules, done);
377
+ console.log(chalk_1.default.magenta('Stopping build process because an error occurred whilst building ' +
378
+ pkg.packageName +
379
+ ', which ' +
380
+ dependentModules.length +
381
+ ' other packages depend on.')); //"+dependentModules.map(d => d.packageName).join(", ")));
382
+ console.log(chalk_1.default.cyanBright('tip ') +
383
+ 'Run ' +
384
+ chalk_1.default.green(`lincd build-all --from=${pkg.packageName}`) +
385
+ ' to build only the remaining packages'); //"+dependentModules.map(d => d.packageName).join(", ")));
386
+ process.exit(1);
429
387
  }
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
- }
388
+ })
389
+ .then((res) => {
390
+ if (!skipping) {
391
+ log(chalk_1.default.green('Built ' + pkg.packageName));
392
+ }
393
+ done.add(pkg);
394
+ packagesLeft--;
395
+ // log(chalk.magenta(packagesLeft + ' packages left'));
396
+ process.stdout.write(packagesLeft + ' packages left\r');
397
+ if (packagesLeft == 0) {
398
+ printBuildResults(failedModules, done);
399
+ if (failedModules.length > 0) {
400
+ process.exit(1);
443
401
  }
444
- return res;
445
402
  }
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
403
+ return res;
452
404
  });
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
- // })
508
405
  };
509
406
  }, (dependencies) => {
510
407
  //if no more packages to build but we never started building...
@@ -576,11 +473,11 @@ function getLocalLincdModules(rootPath = './') {
576
473
  });
577
474
  }
578
475
  function getLincdPackages(rootPath = process.cwd()) {
579
- let pack = (0, utils_js_1.getPackageJSON)();
476
+ let pack = (0, utils_1.getPackageJSON)();
580
477
  if (!pack || !pack.workspaces) {
581
478
  for (let i = 0; i <= 3; i++) {
582
479
  rootPath = path_1.default.join(process.cwd(), ...Array(i).fill('..'));
583
- pack = (0, utils_js_1.getPackageJSON)(rootPath);
480
+ pack = (0, utils_1.getPackageJSON)(rootPath);
584
481
  if (pack && pack.workspaces) {
585
482
  // log('Found workspace at '+packagePath);
586
483
  break;
@@ -643,7 +540,7 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
643
540
  setVariable('uri_base', uriBase);
644
541
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(prefix);
645
542
  //copy ontology accessor file
646
- log('Creating files for ontology \'' + prefix + '\'');
543
+ log("Creating files for ontology '" + prefix + "'");
647
544
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
648
545
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
649
546
  //copy data files
@@ -661,10 +558,10 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
661
558
  }
662
559
  };
663
560
  exports.createOntology = createOntology;
664
- const addLineToIndex = function (line, insertMatchString, root = process.cwd(), insertAtStart = false) {
561
+ const addLineToIndex = function (line, insertMatchString) {
665
562
  //import ontology in index
666
563
  let indexPath = ['index.ts', 'index.tsx']
667
- .map((f) => path_1.default.join(root, 'src', f))
564
+ .map((f) => path_1.default.join('src', f))
668
565
  .find((indexFileName) => {
669
566
  return fs_extra_1.default.existsSync(indexFileName);
670
567
  });
@@ -673,9 +570,8 @@ const addLineToIndex = function (line, insertMatchString, root = process.cwd(),
673
570
  let lines = indexContents.split(/\n/g);
674
571
  let newContents;
675
572
  for (var key in lines) {
676
- //if the match string is found
677
573
  if (lines[key].indexOf(insertMatchString) !== -1) {
678
- //add the new line after this line
574
+ //remove lines after this line and insert new line in its place
679
575
  lines[key] += `\n${line}`;
680
576
  newContents = lines.join('\n');
681
577
  // log("Found at "+key,lines,newContents);
@@ -683,12 +579,7 @@ const addLineToIndex = function (line, insertMatchString, root = process.cwd(),
683
579
  }
684
580
  }
685
581
  if (!newContents) {
686
- if (insertAtStart) {
687
- newContents = `${line}\n${indexContents}`;
688
- }
689
- else {
690
- newContents = `${indexContents}\n${line}`;
691
- }
582
+ newContents = indexContents + `\n${line}`;
692
583
  // log("Added at end",newContents);
693
584
  }
694
585
  fs_extra_1.default.writeFileSync(indexPath, newContents);
@@ -702,13 +593,13 @@ const replaceVariablesInFiles = function (...files) {
702
593
  };
703
594
  const replaceVariablesInFolder = function (folder) {
704
595
  //get all files in folder, including files that start with a dot
705
- glob_1.glob(folder + '/**/*', { dot: true, nodir: true }, async function (err, files) {
596
+ glob(folder + '/**/*', { dot: true, nodir: true }, function (err, files) {
706
597
  if (err) {
707
598
  console.log('Error', err);
708
599
  }
709
600
  else {
710
601
  // console.log(files);
711
- await Promise.all(files.map((file) => {
602
+ return Promise.all(files.map((file) => {
712
603
  return replaceVariablesInFile(file);
713
604
  }));
714
605
  }
@@ -718,7 +609,7 @@ const replaceVariablesInFilesWithRoot = function (root, ...files) {
718
609
  return replaceVariablesInFiles(...files.map((f) => path_1.default.join(root, f)));
719
610
  };
720
611
  const hasYarnInstalled = async function () {
721
- let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
612
+ let version = (await (0, utils_1.execPromise)('yarn --version').catch((err) => {
722
613
  console.log('yarn probably not working');
723
614
  return '';
724
615
  }));
@@ -774,21 +665,6 @@ function getSourceFolder(basePath = process.cwd()) {
774
665
  return path_1.default.join(basePath, 'src');
775
666
  }
776
667
  }
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;
792
668
  const createShape = async (name, basePath = process.cwd()) => {
793
669
  let sourceFolder = getSourceFolder(basePath);
794
670
  let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
@@ -796,7 +672,7 @@ const createShape = async (name, basePath = process.cwd()) => {
796
672
  //copy default shape file
797
673
  // log("Creating files for shape '" + name + "'");
798
674
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
799
- fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'shape.ts'), targetFile);
675
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'shape.ts'), targetFile);
800
676
  //replace variables in some of the copied files
801
677
  await replaceVariablesInFiles(targetFile);
802
678
  log(`Created a new shape class template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
@@ -812,11 +688,11 @@ const createSetComponent = async (name, basePath = process.cwd()) => {
812
688
  let targetFolder = ensureFolderExists(basePath, 'src', 'components');
813
689
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
814
690
  //copy default shape file
815
- log('Creating files for set component \'' + name + '\'');
691
+ log("Creating files for set component '" + name + "'");
816
692
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
817
- fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
693
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'set-component.tsx'), targetFile);
818
694
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
819
- fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'component.scss'), targetFile2);
695
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
820
696
  //replace variables in some of the copied files
821
697
  await replaceVariablesInFiles(targetFile, targetFile2);
822
698
  let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
@@ -828,11 +704,11 @@ const createComponent = async (name, basePath = process.cwd()) => {
828
704
  let targetFolder = ensureFolderExists(sourceFolder, 'components');
829
705
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
830
706
  //copy default shape file
831
- log('Creating files for component \'' + name + '\'');
707
+ log("Creating files for component '" + name + "'");
832
708
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
833
- fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.tsx'), targetFile);
709
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.tsx'), targetFile);
834
710
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
835
- fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.scss'), targetFile2);
711
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
836
712
  //replace variables in some of the copied files
837
713
  await replaceVariablesInFiles(targetFile, targetFile2);
838
714
  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, ''))}`);
@@ -865,10 +741,10 @@ invalidImports = new Map()) => {
865
741
  // - .tsx
866
742
  continue;
867
743
  }
868
- const allImports = await (0, utils_js_1.getFileImports)(filename);
744
+ const allImports = await (0, utils_1.getFileImports)(filename);
869
745
  const lincdImports = allImports.filter((i) => i.includes('lincd') || i.includes('..'));
870
746
  lincdImports.forEach((i) => {
871
- if (!(0, utils_js_1.isValidLINCDImport)(i, depth)) {
747
+ if (!(0, utils_1.isValidLINCDImport)(i, depth)) {
872
748
  if (!invalidImports.has(filename)) {
873
749
  invalidImports.set(filename, []);
874
750
  }
@@ -876,36 +752,26 @@ invalidImports = new Map()) => {
876
752
  }
877
753
  });
878
754
  }
879
- let res = '';
880
755
  // All recursion must have finished, display any errors
881
756
  if (depth === 0 && invalidImports.size > 0) {
882
- res += chalk_1.default.red('Invalid imports found.\n');
757
+ console.warn(chalk_1.default.red('\n' + 'Invalid imports found. See fixes below:'));
758
+ console.warn(chalk_1.default.red(" - For relative imports, ensure you don't import outside of the /src/ folder"));
759
+ console.warn(chalk_1.default.red(' - For lincd imports, access the /lib/ folder instead of /src/'));
883
760
  invalidImports.forEach((value, key) => {
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
- });
761
+ console.info(chalk_1.default.red('\nFound in file ') + chalk_1.default.blue(key) + chalk_1.default.red(':'));
762
+ value.forEach((i) => console.warn(chalk_1.default.red("- '" + i + "'")));
895
763
  });
896
- throw res;
897
- // process.exit(1);
764
+ process.exit(1);
898
765
  }
899
766
  else if (depth === 0 && invalidImports.size === 0) {
900
- // console.info('All imports OK');
901
- // process.exit(0);
902
- return true;
767
+ console.info('All imports OK');
768
+ process.exit(0);
903
769
  }
904
770
  };
905
771
  exports.checkImports = checkImports;
906
772
  const depCheckStaged = async () => {
907
773
  console.log('Checking dependencies of staged files');
908
- (0, staged_git_files_1.default)(async function (err, results) {
774
+ stagedGitFiles(async function (err, results) {
909
775
  const packages = new Set();
910
776
  await Promise.all(results.map(async (file) => {
911
777
  // console.log('STAGED: ', file.filename);
@@ -925,54 +791,50 @@ const depCheckStaged = async () => {
925
791
  });
926
792
  };
927
793
  exports.depCheckStaged = depCheckStaged;
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
- });
794
+ const depCheck = async (path = process.cwd()) => {
795
+ (0, depcheck_1.default)(path, {}, (results) => {
796
+ if (results.missing) {
797
+ let lincdPackages = getLocalLincdModules();
798
+ let missing = Object.keys(results.missing);
799
+ //filter out missing types, if it builds we're not too concerned about that at the moment?
800
+ //especially things like @types/react, @types/react-dom, @types/node (they are added elsewhere?)
801
+ // missing = missing.filter(m => m.indexOf('@types/') === 0);
802
+ //currently react is not an explicit dependency, but we should add it as a peer dependency
803
+ missing.splice(missing.indexOf('react'), 1);
804
+ let missingLincdPackages = missing.filter((missingDep) => {
805
+ return lincdPackages.some((lincdPackage) => {
806
+ return lincdPackage.packageName === missingDep;
943
807
  });
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
- }
808
+ });
809
+ //currently just missing LINCD packages cause a hard failure exit code
810
+ if (missingLincdPackages.length > 0) {
811
+ console.warn(chalk_1.default.red(path +
812
+ '\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
813
+ missingLincdPackages.join(',\n- ')));
814
+ process.exit(1);
958
815
  }
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
- });
816
+ else if (missing.length > 0) {
817
+ console.warn(chalk_1.default.magenta(path +
818
+ '\nMissing dependencies (for now a warning, soon an error):\n\t' +
819
+ missing.join(',\n\t')));
820
+ }
821
+ }
822
+ // if(Object.keys(results.invalidFiles).length > 0) {
823
+ // console.warn(chalk.red("Invalid files:\n")+Object.keys(results.invalidFiles).join(",\n"));
824
+ // }
825
+ // if(Object.keys(results.invalidDirs).length > 0) {
826
+ // console.warn(chalk.red("Invalid dirs:\n")+results.invalidDirs.toString());
827
+ // }
828
+ // if(results.unused) {
829
+ // console.warn("Unused dependencies: "+results.missing.join(", "));
830
+ // }
969
831
  });
970
832
  };
971
833
  exports.depCheck = depCheck;
972
834
  const ensureEnvironmentLoaded = async () => {
973
835
  if (!process.env.NODE_ENV) {
974
836
  //load env-cmd for development environment
975
- let { GetEnvVars } = await Promise.resolve().then(() => __importStar(require('env-cmd')));
837
+ let { GetEnvVars } = require('env-cmd');
976
838
  let envCmdrcPath = path_1.default.join(process.cwd(), '.env-cmdrc.json');
977
839
  if (!fs_extra_1.default.existsSync(envCmdrcPath)) {
978
840
  console.warn('No .env-cmdrc.json found in this folder. Are you running this command from the root of a LINCD app?');
@@ -1015,25 +877,14 @@ const ensureEnvironmentLoaded = async () => {
1015
877
  };
1016
878
  exports.ensureEnvironmentLoaded = ensureEnvironmentLoaded;
1017
879
  const startServer = async (initOnly = false, ServerClass = null) => {
1018
- var _a, _b;
1019
880
  await (0, exports.ensureEnvironmentLoaded)();
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
+ let lincdConfig = require(path_1.default.join(process.cwd(), 'lincd.config'));
1031
882
  if (!ServerClass) {
1032
- ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer')))).LincdServer;
883
+ ServerClass = require('lincd-server/lib/shapes/LincdServer').LincdServer;
1033
884
  }
1034
- await (_b = path_1.default.join(process.cwd(), 'scripts', 'storage-config.js'), Promise.resolve().then(() => __importStar(require(_b))));
885
+ require(path_1.default.join(process.cwd(), 'scripts', 'storage-config'));
1035
886
  let server = new ServerClass({
1036
- loadAppComponent: async () => { var _a; return (await (_a = path_1.default.join(process.cwd(), 'src', 'App'), Promise.resolve().then(() => __importStar(require(_a))))).default; },
887
+ loadAppComponent: () => require(path_1.default.join(process.cwd(), 'src', 'App')).default,
1037
888
  ...lincdConfig,
1038
889
  });
1039
890
  //Important to use slice, because when using clusers, child processes need to be able to read the same arguments
@@ -1049,12 +900,15 @@ const startServer = async (initOnly = false, ServerClass = null) => {
1049
900
  exports.startServer = startServer;
1050
901
  const buildApp = async () => {
1051
902
  await (0, exports.ensureEnvironmentLoaded)();
1052
- const webpackAppConfig = await (await Promise.resolve().then(() => __importStar(require('./config-webpack-app.js')))).getWebpackAppConfig();
903
+ const webpackAppConfig = require('./config-webpack-app').webpackAppConfig;
1053
904
  console.log(chalk_1.default.magenta(`Building ${process.env.NODE_ENV} app bundles`));
1054
905
  return new Promise((resolve, reject) => {
1055
- (0, webpack_1.default)(webpackAppConfig, async (err, stats) => {
906
+ webpack(webpackAppConfig, async (err, stats) => {
1056
907
  if (err) {
1057
908
  console.error(err.stack || err);
909
+ if (err.details) {
910
+ console.error(err.details);
911
+ }
1058
912
  process.exit(1);
1059
913
  }
1060
914
  const info = stats.toJson();
@@ -1068,9 +922,10 @@ const buildApp = async () => {
1068
922
  console.log(stats.toString({
1069
923
  chunks: false,
1070
924
  assets: true,
1071
- entrypoints: false,
925
+ entryPoints: false,
1072
926
  modules: false,
1073
927
  moduleAssets: false,
928
+ moduleChunks: false,
1074
929
  colors: true,
1075
930
  }));
1076
931
  console.log('App build process finished');
@@ -1084,190 +939,9 @@ const buildApp = async () => {
1084
939
  }
1085
940
  // process.exit();
1086
941
  });
1087
- }).then(async () => {
1088
- var _a;
1089
- // make sure environment is not development for storage config
1090
- if (process.env.NODE_ENV === 'development') {
1091
- console.warn('Upload build to storage skip in development environment');
1092
- process.exit();
1093
- }
1094
- if (process.env.APP_ENV) {
1095
- console.warn('Not uploading to CDN for app builds');
1096
- process.exit();
1097
- }
1098
- // load the storage config
1099
- const storageConfig = await (_a = path_1.default.join(process.cwd(), 'scripts', 'storage-config.js'), Promise.resolve().then(() => __importStar(require(_a))));
1100
- // check if LincdFileStorage has a default FileStore
1101
- // if yes: copy all the files in the build folder over with LincdFileStorage
1102
- if (LinkedFileStorage_1.LinkedFileStorage.getDefaultStore()) {
1103
- // get public directory
1104
- const rootDirectory = 'public';
1105
- const pathDir = path_1.default.join(process.cwd(), rootDirectory);
1106
- if (!fs_extra_1.default.existsSync(pathDir)) {
1107
- console.warn('No public directory found. Please create a public directory in the root of your project');
1108
- return;
1109
- }
1110
- // get all files in the web directory and then upload them to the storage
1111
- const files = await (0, utils_js_1.getFiles)(pathDir);
1112
- const uploads = files.map(async (filePath) => {
1113
- // read file content
1114
- const fileContent = await fs_extra_1.default.promises.readFile(filePath);
1115
- // replace pathDir with rootDirectory in filePath to get pathname
1116
- // example: /Users/username/project/www/index.html -> /project/www/index.html
1117
- const pathname = filePath.replace(pathDir, `/${rootDirectory}`);
1118
- // upload file to storage
1119
- return await LinkedFileStorage_1.LinkedFileStorage.saveFile(pathname, fileContent);
1120
- });
1121
- const urls = await Promise.all(uploads);
1122
- console.log(`${urls.length} files uploaded to storage`);
1123
- process.exit();
1124
- }
1125
942
  });
1126
943
  };
1127
944
  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;
1271
945
  const createPackage = async (name, uriBase, basePath = process.cwd()) => {
1272
946
  if (!name) {
1273
947
  console.warn('Please provide a name as the first argument');
@@ -1299,8 +973,8 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
1299
973
  //extra variable for clarity (will be same as 'name')
1300
974
  setVariable('output_file_name', name);
1301
975
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(cleanPackageName);
1302
- log('Creating new LINCD package \'' + name + '\'');
1303
- fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'package'), targetFolder);
976
+ log("Creating new LINCD package '" + name + "'");
977
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package'), targetFolder);
1304
978
  //replace variables in some of the copied files
1305
979
  await Promise.all([
1306
980
  'src/index.ts',
@@ -1327,14 +1001,14 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
1327
1001
  console.log('rename ', path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
1328
1002
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
1329
1003
  });
1330
- let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
1004
+ let version = (await (0, utils_1.execPromise)('yarn --version').catch((err) => {
1331
1005
  console.log('yarn probably not working');
1332
1006
  return '';
1333
1007
  }));
1334
1008
  let installCommand = version.toString().match(/[0-9]+/)
1335
1009
  ? 'yarn install'
1336
1010
  : 'npm install';
1337
- await (0, utils_js_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
1011
+ await (0, utils_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
1338
1012
  console.warn('Could not install dependencies');
1339
1013
  });
1340
1014
  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`);
@@ -1356,6 +1030,43 @@ var buildFailed = function (output) {
1356
1030
  return (output.indexOf('Aborted due to warnings') !== -1 &&
1357
1031
  output.indexOf('Command failed') !== -1);
1358
1032
  };
1033
+ /*program.command('shapes').action(async () => {
1034
+ //we've imported require-extensions from npm so that we can use this
1035
+ //we want to avoid nodejs tripping up over @import commands in css files
1036
+ require.extensions['.scss'] = function (sourcecode, filename) {
1037
+ return {};
1038
+ };
1039
+ require.extensions['.css'] = function (sourcecode, filename) {
1040
+ return {};
1041
+ };
1042
+
1043
+ if (fs.existsSync(process.cwd() + '/package.json')) {
1044
+ var pack = JSON.parse(
1045
+ fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
1046
+ );
1047
+ let packageName = pack.name;
1048
+
1049
+ //just making sure the library is loaded in correct order because circular references are currently happening when importing BlankNode before NamedNode for example
1050
+ // require('lincd');
1051
+ //TODO: replace with actual index file from package.json, or tsconfig
1052
+ let indexExports = require(process.cwd() + '/lib/index.js');
1053
+ if(indexExports.packageExports)
1054
+ {
1055
+ let shapeJSONLD = await getShapesJSONLD(indexExports.packageExports);
1056
+ console.log(indexExports.packageExports);
1057
+ console.log(shapeJSONLD);
1058
+ console.log(chalk.bold(chalk.green(packageName+'/dist/shapes.json')));
1059
+ return fs.writeFile(path.join('dist', 'shapes.json'), shapeJSONLD);
1060
+ }
1061
+ else
1062
+ {
1063
+ console.warn("Invalid LINCD package. Index file should export a packageExports object. See examples.")
1064
+ }
1065
+
1066
+ } else {
1067
+ console.warn('Not a project');
1068
+ }
1069
+ });*/
1359
1070
  const register = function (registryURL) {
1360
1071
  if (fs_extra_1.default.existsSync(process.cwd() + '/package.json')) {
1361
1072
  var pack = JSON.parse(fs_extra_1.default.readFileSync(process.cwd() + '/package.json', 'utf8'));
@@ -1403,139 +1114,101 @@ const register = function (registryURL) {
1403
1114
  }
1404
1115
  };
1405
1116
  exports.register = register;
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();
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;
1117
+ /**
1118
+ * Function to remove files older than 10 seconds from the 'lib' folder.
1119
+ * @param {string} packagePath - The path to the package directory.
1120
+ */
1121
+ const removeOldFiles = async (packagePath) => {
1122
+ const libPath = path_1.default.join(packagePath, 'lib');
1123
+ try {
1124
+ // Read all files in the 'lib' folder asynchronously
1125
+ const files = await fs_extra_1.default.readdir(libPath);
1126
+ // Iterate through each file
1127
+ for (const file of files) {
1128
+ const filePath = path_1.default.join(libPath, file);
1129
+ //check if the file is a directory
1130
+ // const stats = await fs.stat(filePath);
1131
+ // let isDir = stats.isDirectory();
1132
+ // Check if the file exists before attempting to delete it
1133
+ if (await fs_extra_1.default.pathExists(filePath)) {
1134
+ const stats = await fs_extra_1.default.stat(filePath);
1135
+ const currentTime = new Date().getTime();
1136
+ const lastModifiedTime = stats.mtime.getTime();
1137
+ // Check if the difference between the current time and last modified time is greater than 10 seconds
1138
+ if (currentTime - lastModifiedTime > 120000) {
1139
+ // Attempt to delete the file
1140
+ await fs_extra_1.default.remove(filePath);
1141
+ console.log(`Removed: ${filePath}`);
1460
1142
  }
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
- });
1497
- }
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
- });
1143
+ }
1144
+ else {
1145
+ console.warn(`File ${filePath} does not exist.`);
1146
+ }
1510
1147
  }
1511
1148
  }
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;
1149
+ catch (error) {
1150
+ console.error(`Error removing files: ${error.message}`);
1527
1151
  }
1528
- else if (esmConfig) {
1529
- compileCommand = compileESM;
1152
+ };
1153
+ exports.removeOldFiles = removeOldFiles;
1154
+ const buildPackage = (target, target2, packagePath = process.cwd(), logResults = true) => {
1155
+ if (target == 'production' || target == 'es5' || target == 'es6' || !target) {
1156
+ if (!fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'Gruntfile.js'))) {
1157
+ console.warn(`No Gruntfile found at ${packagePath}\\Gruntfile.js. Cannot build.`);
1158
+ return;
1159
+ }
1160
+ var nodeEnv = '';
1161
+ if (target == 'production') {
1162
+ if (!(target2 == 'es5' || target2 == 'es6' || typeof target2 == 'undefined')) {
1163
+ console.warn('unknown second build target. Use es5 or es6', target2);
1164
+ return;
1165
+ }
1166
+ var isWindows = /^win/.test(process.platform);
1167
+ if (isWindows) {
1168
+ nodeEnv = 'SET NODE_ENV=production&& ';
1169
+ }
1170
+ else {
1171
+ nodeEnv = "NODE_ENV='production' ";
1172
+ }
1173
+ }
1174
+ if (!target) {
1175
+ target = 'es6';
1176
+ }
1177
+ log('building once: ' +
1178
+ nodeEnv +
1179
+ 'grunt build' +
1180
+ (target ? '-' + target : '') +
1181
+ (target2 ? '-' + target2 : '') +
1182
+ ' --color');
1183
+ let method = logResults ? utils_1.execp : utils_1.execPromise;
1184
+ //NOTE: we moved SCSS:JSON out of webpack and grunt, into this file
1185
+ //this is the beginning of a transition away from grunt
1186
+ //but for the time being it's perhaps a bit strange that we
1187
+ // let x = postcss([
1188
+ // postcssModules({
1189
+ // generateScopedName,
1190
+ // }),
1191
+ // ]);
1192
+ //execute the command to build the method, and provide the current work directory as option
1193
+ return method(nodeEnv +
1194
+ 'grunt build' +
1195
+ (target ? '-' + target : '') +
1196
+ (target2 ? '-' + target2 : '') +
1197
+ ' --color', false, false, { cwd: packagePath })
1198
+ .then(() => {
1199
+ // Once the build is complete, remove old files
1200
+ return (0, exports.removeOldFiles)(packagePath);
1201
+ })
1202
+ .catch((err) => {
1203
+ console.error('Error building package:', err);
1204
+ process.exit(1);
1205
+ });
1530
1206
  }
1531
1207
  else {
1532
- compileCommand = `yarn exec tsc`;
1208
+ console.warn('unknown build target. Use es5, es6, or production.');
1533
1209
  }
1534
- return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
1535
- return res === '';
1536
- });
1537
1210
  };
1538
- exports.compilePackage = compilePackage;
1211
+ exports.buildPackage = buildPackage;
1539
1212
  var publishUpdated = function (test = false) {
1540
1213
  let packages = getLocalLincdModules();
1541
1214
  var p = Promise.resolve('');
@@ -1553,22 +1226,22 @@ var publishUpdated = function (test = false) {
1553
1226
  // console.log("Will be requesting npm view from this current working directory:\n"+process.cwd());
1554
1227
  // return execPromise('npm view '+pkg.packageName+' --json').then((output:string) => {
1555
1228
  let shouldPublish;
1556
- var pack = (0, utils_js_1.getPackageJSON)(pckg.path);
1229
+ var pack = (0, utils_1.getPackageJSON)(pckg.path);
1557
1230
  let version = getNextVersion(pack.version);
1558
1231
  if (pack.private) {
1559
1232
  shouldPublish = false;
1560
- (0, utils_js_1.debugInfo)(chalk_1.default.blue('--> is private, skipping'));
1233
+ (0, utils_1.debugInfo)(chalk_1.default.blue('--> is private, skipping'));
1561
1234
  return chalk_1.default.gray(pckg.packageName + ' is private');
1562
1235
  // return previousResult + ' ' + chalk.gray(pckg.packageName + ' is private\n');
1563
1236
  }
1564
1237
  console.log('testing npm');
1565
- return (0, utils_js_1.execPromise)('npm info ' + pckg.packageName + ' --json')
1238
+ return (0, utils_1.execPromise)('npm info ' + pckg.packageName + ' --json')
1566
1239
  .then(async (output) => {
1567
1240
  console.log('testing npm done');
1568
1241
  var info;
1569
1242
  try {
1570
1243
  if (output == '' || output.includes('E404')) {
1571
- (0, utils_js_1.debugInfo)('Empty or 404 response from `npm info`. This package was probably not published before');
1244
+ (0, utils_1.debugInfo)('Empty or 404 response from `npm info`. This package was probably not published before');
1572
1245
  // throw new Error('Empty response from `yarn info`. This pkg was probably not published before');
1573
1246
  // return;
1574
1247
  shouldPublish = true;
@@ -1591,10 +1264,10 @@ var publishUpdated = function (test = false) {
1591
1264
  // }
1592
1265
  let lastPublishDate = new Date(lastPublish);
1593
1266
  // let {lastModifiedTime, lastModifiedName, lastModified} = getLastModifiedSourceTime(pkg.path);
1594
- let lastCommitInfo = await (0, utils_js_1.getLastCommitTime)(pckg.path);
1267
+ let lastCommitInfo = await (0, utils_1.getLastCommitTime)(pckg.path);
1595
1268
  if (!lastCommitInfo) {
1596
1269
  shouldPublish = false;
1597
- (0, utils_js_1.debugInfo)('Could not determine last git commit');
1270
+ (0, utils_1.debugInfo)('Could not determine last git commit');
1598
1271
  // return previousResult + ' ' + chalk.red(pckg.packageName + ' - could not determine last commit\n');
1599
1272
  return chalk_1.default.red(pckg.packageName + ' - could not determine last commit');
1600
1273
  }
@@ -1688,7 +1361,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
1688
1361
  }
1689
1362
  // let path = './';
1690
1363
  for (let i = 0; i <= 10; i++) {
1691
- let envFile = await (0, get_env_vars_js_1.getEnvFile)({
1364
+ let envFile = await (0, get_env_vars_1.getEnvFile)({
1692
1365
  filePath: relativeToPath + path + '.env.json',
1693
1366
  }).catch((err) => {
1694
1367
  return null;
@@ -1702,7 +1375,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
1702
1375
  }
1703
1376
  var publishPackage = async function (pkg, test, info, publishVersion) {
1704
1377
  if (!pkg) {
1705
- let localPackageJson = (0, utils_js_1.getPackageJSON)();
1378
+ let localPackageJson = (0, utils_1.getPackageJSON)();
1706
1379
  pkg = {
1707
1380
  path: process.cwd(),
1708
1381
  packageName: localPackageJson.name,
@@ -1712,18 +1385,18 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
1712
1385
  publishVersion = info ? getNextVersion(info.version) : 'patch';
1713
1386
  }
1714
1387
  if (test) {
1715
- (0, utils_js_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
1388
+ (0, utils_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
1716
1389
  //when testing what needs to be published
1717
1390
  return chalk_1.default.blue(pkg.packageName + ' should publish');
1718
1391
  }
1719
1392
  console.log(chalk_1.default.blue('publishing ' + pkg.packageName + ' ' + publishVersion));
1720
1393
  //looking for an .env.json file in our workspace, which may store our NPM AUTH key
1721
1394
  let envJsonPath = await getEnvJsonPath(pkg.path);
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)
1395
+ 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)
1723
1396
  .then((res) => {
1724
1397
  if (res.indexOf('Aborted due to warnings') !== -1 ||
1725
1398
  res.indexOf('Could not publish') !== -1 ||
1726
- res.indexOf('Couldn\'t publish') !== -1) {
1399
+ res.indexOf("Couldn't publish") !== -1) {
1727
1400
  console.log(res);
1728
1401
  return chalk_1.default.red(pkg.packageName + ' failed\n');
1729
1402
  }
@@ -1752,12 +1425,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1752
1425
  // let packages = getLocalLincdModules();
1753
1426
  let packages = getLocalLincdPackageMap();
1754
1427
  // console.log(packages);
1755
- let jsonldPkgUpdated = await (0, utils_js_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
1428
+ let jsonldPkgUpdated = await (0, utils_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
1756
1429
  // let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
1757
1430
  //if either cli or jsonldPkg needs to be rebuilt
1758
1431
  // if (jsonldPkgUpdated || cliPkgUpdated) {
1759
1432
  if (jsonldPkgUpdated) {
1760
- await (0, utils_js_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
1433
+ await (0, utils_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
1761
1434
  cwd: packages.get('lincd-jsonld').path,
1762
1435
  }, true);
1763
1436
  // await execPromise('yarn build-core', false, false, {}, true);
@@ -1769,12 +1442,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1769
1442
  // }
1770
1443
  let packagesLeft = packages.size;
1771
1444
  runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
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.');
1445
+ (0, utils_1.debugInfo)('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
1446
+ (0, utils_1.debugInfo)(packagesLeft + ' packages left.');
1774
1447
  packagesLeft = packagesLeft - packageGroup.length;
1775
1448
  return async (pkg) => {
1776
1449
  // debugInfo('# Checking package ' + pkg.packageName);
1777
- let needRebuild = await (0, utils_js_1.needsRebuilding)(pkg, useGitForLastModified);
1450
+ let needRebuild = await (0, utils_1.needsRebuilding)(pkg, useGitForLastModified);
1778
1451
  if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
1779
1452
  needRebuild = true;
1780
1453
  }
@@ -1782,26 +1455,18 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1782
1455
  //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1783
1456
  // log(packageName+' modified since last commit on '+now.toString());
1784
1457
  if (test) {
1785
- (0, utils_js_1.debugInfo)('Need to build ' + pkg.packageName);
1458
+ (0, utils_1.debugInfo)('Need to build ' + pkg.packageName);
1786
1459
  return chalk_1.default.blue(pkg.packageName + ' should be build');
1787
1460
  }
1788
1461
  log('Building ' + pkg.packageName);
1789
- // return buildPackage(null,null,pkg.path)
1790
- return (0, utils_js_1.execPromise)('cd ' +
1462
+ return (0, utils_1.execPromise)('cd ' +
1791
1463
  pkg.path +
1792
1464
  ' && yarn build' +
1793
1465
  (target ? ' ' + target : '') +
1794
1466
  (target2 ? ' ' + target2 : ''))
1795
1467
  .then((res) => {
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
- }
1468
+ (0, utils_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
1469
+ return chalk_1.default.green(pkg.packageName + ' built');
1805
1470
  })
1806
1471
  .catch(({ error, stdout, stderr }) => {
1807
1472
  warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
@@ -1833,11 +1498,9 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
1833
1498
  };
1834
1499
  exports.buildUpdated = buildUpdated;
1835
1500
  const printBuildResults = function (failed, done) {
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
- }
1501
+ log('Successfully built: ' +
1502
+ chalk_1.default.green([...done].map((m) => m.packageName).join(', ')) +
1503
+ '\n');
1841
1504
  if (failed.length > 0) {
1842
1505
  warn('Failed to build: ' + chalk_1.default.red(failed.join(', ')) + '\n');
1843
1506
  }
@@ -1868,15 +1531,15 @@ var executeCommandForEachPackage = function (packages, command, filterMethod, fi
1868
1531
  return seen;
1869
1532
  });
1870
1533
  }
1871
- log('Executing \'' +
1534
+ log("Executing '" +
1872
1535
  chalk_1.default.blueBright(command) +
1873
- '\' on packages ' +
1536
+ "' on packages " +
1874
1537
  chalk_1.default.magenta(packages.map((m) => m.packageName).join(', ')));
1875
1538
  var p = Promise.resolve(true);
1876
1539
  packages.forEach((pkg) => {
1877
1540
  p = p.then(() => {
1878
1541
  log('# Package ' + chalk_1.default.magenta(pkg.packageName));
1879
- return (0, utils_js_1.execp)('cd ' + pkg.path + ' && ' + command);
1542
+ return (0, utils_1.execp)('cd ' + pkg.path + ' && ' + command);
1880
1543
  });
1881
1544
  });
1882
1545
  return p;
@@ -1898,8 +1561,8 @@ exports.addLinesToFile = addLinesToFile;
1898
1561
  var addCapacitor = async function (basePath = process.cwd()) {
1899
1562
  let targetFolder = ensureFolderExists(basePath);
1900
1563
  log('Adding capacitor');
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'));
1564
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'app-static'), targetFolder);
1565
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'capacitor', 'scripts'), path_1.default.join(targetFolder, 'scripts'));
1903
1566
  //update .env-cmdrc.json file
1904
1567
  let envCmdPath = path_1.default.resolve(basePath, '.env-cmdrc.json');
1905
1568
  let envCmd = JSON.parse(fs_extra_1.default.readFileSync(envCmdPath, { encoding: 'utf8' }));
@@ -1921,7 +1584,7 @@ var addCapacitor = async function (basePath = process.cwd()) {
1921
1584
  log('Edited .env-cmdrc.json');
1922
1585
  gitIgnore('android/app/build', 'android/**/capacitor.build.gradle', 'ios/App/App/public');
1923
1586
  //update package.json scripts
1924
- let pack = (0, utils_js_1.getPackageJSON)(basePath);
1587
+ let pack = (0, utils_1.getPackageJSON)(basePath);
1925
1588
  pack.scripts['build-staging'] =
1926
1589
  'env-cmd -e _main, staging node scripts/build.js';
1927
1590
  pack.scripts['fix-app'] = 'node scripts/fix-namespace.js';
@@ -1936,8 +1599,8 @@ var addCapacitor = async function (basePath = process.cwd()) {
1936
1599
  pack.scripts['cap:sync'] = 'yarn cap sync';
1937
1600
  fs_extra_1.default.writeFile(path_1.default.resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
1938
1601
  log('Added new run script to package.json');
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);
1602
+ await (0, utils_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
1603
+ await (0, utils_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/app @capacitor/ios`, false, false, null, true);
1941
1604
  // TODO: Do we need to add `npx cap init`? If yes, we should not copy capacitor config.ts yet
1942
1605
  // await execPromise(`npx cap init`, true, false, null, true);
1943
1606
  // got error:
@@ -1954,53 +1617,20 @@ var executeCommandForPackage = function (packageName, command) {
1954
1617
  let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
1955
1618
  modDetails.packageName.indexOf(packageName) !== -1);
1956
1619
  if (packageDetails) {
1957
- log('Executing \'cd ' +
1620
+ log("Executing 'cd " +
1958
1621
  packageDetails.path +
1959
1622
  ' && yarn exec lincd' +
1960
1623
  (command ? ' ' + command : '') +
1961
- '\'');
1962
- return (0, utils_js_1.execp)('cd ' +
1624
+ "'");
1625
+ return (0, utils_1.execp)('cd ' +
1963
1626
  packageDetails.path +
1964
1627
  ' && yarn exec lincd' +
1965
1628
  (command ? ' ' + command : ''));
1966
1629
  }
1967
1630
  else {
1968
- warn('Could not find a pkg who\'s name (partially) matched ' +
1631
+ warn("Could not find a pkg who's name (partially) matched " +
1969
1632
  chalk_1.default.cyan(packageName));
1970
1633
  }
1971
1634
  };
1972
1635
  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;
2006
1636
  //# sourceMappingURL=cli-methods.js.map