lincd-cli 1.2.2 → 1.2.3

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.
@@ -15,33 +15,18 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
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
+ };
35
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
27
  };
38
28
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.removeOldFiles = exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.compilePackageCJS = exports.compilePackageESM = exports.compilePackage = exports.buildPackage = exports.register = exports.createPackage = exports.upgradePackages = exports.buildBackend = exports.buildFrontend = exports.buildApp = exports.startServer = exports.runMethod = exports.ensureEnvironmentLoaded = exports.depCheck = exports.depCheckStaged = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.getScriptDir = exports.setNameVariables = exports.createOntology = exports.createApp = void 0;
40
- exports.warn = warn;
41
- exports.developPackage = developPackage;
42
- exports.runOnPackagesGroupedByDependencies = runOnPackagesGroupedByDependencies;
43
- exports.buildAll = buildAll;
44
- exports.getLincdPackages = getLincdPackages;
29
+ exports.removeOldFiles = exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.compilePackageCJS = exports.compilePackageESM = exports.compilePackage = exports.buildPackage = exports.register = exports.createPackage = exports.upgradePackages = exports.buildBackend = exports.buildFrontend = exports.buildApp = exports.startServer = exports.runMethod = 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.runOnPackagesGroupedByDependencies = exports.developPackage = exports.logError = exports.warn = exports.createApp = void 0;
45
30
  const chalk_1 = __importDefault(require("chalk"));
46
31
  const child_process_1 = require("child_process");
47
32
  const depcheck_1 = __importDefault(require("depcheck"));
@@ -49,19 +34,21 @@ const get_env_vars_js_1 = require("env-cmd/dist/get-env-vars.js");
49
34
  const fs_extra_1 = __importDefault(require("fs-extra"));
50
35
  const path_1 = __importStar(require("path"));
51
36
  const utils_js_1 = require("./utils.js");
52
- const fs_1 = require("fs");
37
+ const child_process_2 = require("child_process");
53
38
  const find_nearest_package_json_1 = require("find-nearest-package-json");
39
+ const fs_1 = require("fs");
54
40
  const LinkedFileStorage_1 = require("lincd/utils/LinkedFileStorage");
55
- const child_process_2 = require("child_process");
56
41
  // import pkg from 'lincd/utils/LinkedFileStorage';
57
42
  // const { LinkedFileStorage } = pkg;
58
43
  // const config = require('lincd-server/site.webpack.config');
59
44
  const glob_1 = require("glob");
60
45
  const webpack_1 = __importDefault(require("webpack"));
61
- const staged_git_files_1 = __importDefault(require("staged-git-files"));
62
46
  const ora_1 = __importDefault(require("ora"));
63
- //@ts-ignore
64
- let dirname__ = typeof __dirname !== 'undefined' ? __dirname : (0, path_1.dirname)(import.meta.url).replace('file:/', '');
47
+ const staged_git_files_1 = __importDefault(require("staged-git-files"));
48
+ let dirname__ = typeof __dirname !== 'undefined'
49
+ ? __dirname
50
+ : //@ts-ignore
51
+ (0, path_1.dirname)(import.meta.url).replace('file:/', '');
65
52
  var variables = {};
66
53
  const createApp = async (name, basePath = process.cwd()) => {
67
54
  if (!name) {
@@ -81,7 +68,7 @@ const createApp = async (name, basePath = process.cwd()) => {
81
68
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'gitignore.template'), path_1.default.join(targetFolder, '.gitignore'));
82
69
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'yarnrc.yml.template'), path_1.default.join(targetFolder, '.yarnrc.yml'));
83
70
  // fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
84
- log('Creating new LINCD application \'' + name + '\'');
71
+ log("Creating new LINCD application '" + name + "'");
85
72
  //replace variables in some copied files
86
73
  await replaceVariablesInFolder(targetFolder);
87
74
  let hasYarn = await hasYarnInstalled();
@@ -108,10 +95,17 @@ function progressUpdate(message) {
108
95
  }
109
96
  function warn(...messages) {
110
97
  messages.forEach((message) => {
111
- console.log(chalk_1.default.redBright('Warning: ') + message);
98
+ console.warn(chalk_1.default.redBright('Warning: ') + message);
112
99
  // console.log(chalk.red(message));
113
100
  });
114
101
  }
102
+ exports.warn = warn;
103
+ function logError(...messages) {
104
+ messages.forEach((message) => {
105
+ console.error(chalk_1.default.redBright('Error: ') + message);
106
+ });
107
+ }
108
+ exports.logError = logError;
115
109
  function developPackage(target, mode) {
116
110
  if (!target)
117
111
  target = 'es6';
@@ -137,6 +131,7 @@ function developPackage(target, mode) {
137
131
  console.warn('unknown build target. Use es5 or es6');
138
132
  }
139
133
  }
134
+ exports.developPackage = developPackage;
140
135
  function checkWorkspaces(rootPath, workspaces, res) {
141
136
  // console.log('checking workspaces at '+rootPath+": "+workspaces.toString());
142
137
  if (workspaces.packages) {
@@ -328,6 +323,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
328
323
  //starts the process
329
324
  runStack(startStack);
330
325
  }
326
+ exports.runOnPackagesGroupedByDependencies = runOnPackagesGroupedByDependencies;
331
327
  function hasDependency(pkg, childPkg, dependencies, depth = 1) {
332
328
  console.log('Does ' + pkg.packageName + ' have dep ' + childPkg.packageName + ' ?');
333
329
  let deps = dependencies.get(pkg);
@@ -345,9 +341,121 @@ function hasDependency(pkg, childPkg, dependencies, depth = 1) {
345
341
  console.log('going up');
346
342
  return false;
347
343
  }
344
+ /**
345
+ * Finds the topmost package.json that could be an APP_ROOT
346
+ * Returns null if no app root is found (standalone repo case)
347
+ */
348
+ function findAppRoot(startPath = process.cwd()) {
349
+ let currentPath = startPath;
350
+ let candidateRoots = [];
351
+ // Walk up the directory tree
352
+ for (let i = 0; i < 10; i++) {
353
+ const packageJsonPath = path_1.default.join(currentPath, 'package.json');
354
+ if (fs_extra_1.default.existsSync(packageJsonPath)) {
355
+ const packageJson = JSON.parse(fs_extra_1.default.readFileSync(packageJsonPath, 'utf8'));
356
+ candidateRoots.push({
357
+ path: currentPath,
358
+ hasWorkspaces: !!packageJson.workspaces,
359
+ isLincd: packageJson.lincd === true,
360
+ });
361
+ }
362
+ const parentPath = path_1.default.join(currentPath, '..');
363
+ // If we've reached the root or haven't moved up
364
+ if (parentPath === currentPath) {
365
+ break;
366
+ }
367
+ currentPath = parentPath;
368
+ }
369
+ // Find the topmost package.json that has workspaces
370
+ // Prefer non-lincd packages (app roots) over lincd packages
371
+ let appRoot = null;
372
+ for (let i = candidateRoots.length - 1; i >= 0; i--) {
373
+ const candidate = candidateRoots[i];
374
+ if (candidate.hasWorkspaces && !candidate.isLincd) {
375
+ appRoot = candidate.path;
376
+ break;
377
+ }
378
+ }
379
+ // If no non-lincd workspace found, use the topmost workspace
380
+ if (!appRoot) {
381
+ for (let i = candidateRoots.length - 1; i >= 0; i--) {
382
+ if (candidateRoots[i].hasWorkspaces) {
383
+ appRoot = candidateRoots[i].path;
384
+ break;
385
+ }
386
+ }
387
+ }
388
+ return appRoot;
389
+ }
390
+ /**
391
+ * Filters packages to only include those in the dependency tree of the app root
392
+ */
393
+ function filterPackagesByDependencyTree(allPackages, appRootPath) {
394
+ const appPackageJson = (0, utils_js_1.getPackageJSON)(appRootPath);
395
+ if (!appPackageJson) {
396
+ return allPackages;
397
+ }
398
+ const relevantPackages = new Map();
399
+ const packagesToCheck = new Set();
400
+ // Start with direct dependencies from app root
401
+ if (appPackageJson.dependencies) {
402
+ Object.keys(appPackageJson.dependencies).forEach((dep) => {
403
+ if (allPackages.has(dep)) {
404
+ packagesToCheck.add(dep);
405
+ }
406
+ });
407
+ }
408
+ // Recursively add dependencies
409
+ const processedPackages = new Set();
410
+ while (packagesToCheck.size > 0) {
411
+ const packageName = Array.from(packagesToCheck)[0];
412
+ packagesToCheck.delete(packageName);
413
+ if (processedPackages.has(packageName)) {
414
+ continue;
415
+ }
416
+ processedPackages.add(packageName);
417
+ const packageDetails = allPackages.get(packageName);
418
+ if (packageDetails) {
419
+ relevantPackages.set(packageName, packageDetails);
420
+ // Get this package's dependencies
421
+ const packageJson = (0, utils_js_1.getPackageJSON)(packageDetails.path);
422
+ if (packageJson && packageJson.dependencies) {
423
+ Object.keys(packageJson.dependencies).forEach((dep) => {
424
+ if (allPackages.has(dep) && !processedPackages.has(dep)) {
425
+ packagesToCheck.add(dep);
426
+ }
427
+ });
428
+ }
429
+ }
430
+ }
431
+ return relevantPackages;
432
+ }
348
433
  function buildAll(options) {
349
434
  console.log('Building all LINCD packages of this repository in order of dependencies');
350
435
  let lincdPackages = getLocalLincdPackageMap();
436
+ const originalPackageCount = lincdPackages.size;
437
+ // Check if we're in an app context and filter packages accordingly
438
+ const appRoot = findAppRoot();
439
+ if (appRoot) {
440
+ const appPackageJson = (0, utils_js_1.getPackageJSON)(appRoot);
441
+ // Check if this is an app (not a lincd package itself) with lincd dependencies
442
+ const isAppWithLincdDeps = appPackageJson &&
443
+ appPackageJson.lincd !== true &&
444
+ appPackageJson.dependencies &&
445
+ Object.keys(appPackageJson.dependencies).some((dep) => lincdPackages.has(dep));
446
+ if (isAppWithLincdDeps) {
447
+ (0, utils_js_1.debugInfo)(chalk_1.default.blue(`Found app root at: ${appRoot}`));
448
+ const filteredPackages = filterPackagesByDependencyTree(lincdPackages, appRoot);
449
+ console.log(chalk_1.default.magenta(`Found ${originalPackageCount} total LINCD packages, building only ${filteredPackages.size} that are relevant to this app`));
450
+ lincdPackages = filteredPackages;
451
+ }
452
+ else {
453
+ (0, utils_js_1.debugInfo)(chalk_1.default.blue(`Building all ${originalPackageCount} packages from workspace`));
454
+ }
455
+ }
456
+ else {
457
+ (0, utils_js_1.debugInfo)(chalk_1.default.blue(`No workspace root found, building all ${originalPackageCount} packages`));
458
+ }
351
459
  let startFrom;
352
460
  //by default start building
353
461
  let building = true;
@@ -421,7 +529,8 @@ function buildAll(options) {
421
529
  log(chalk_1.default.cyan('Building ' + pkg.packageName));
422
530
  process.stdout.write(packagesLeft + ' packages left\r');
423
531
  }
424
- return command.then(res => {
532
+ return command
533
+ .then((res) => {
425
534
  //empty string or true is success
426
535
  //false is success with warnings
427
536
  //any other string is the build error text
@@ -445,7 +554,8 @@ function buildAll(options) {
445
554
  }
446
555
  else {
447
556
  if (!skipping) {
448
- log(chalk_1.default.green('Built ' + pkg.packageName) + (res === false ? chalk_1.default.redBright(' (with warnings)') : ''));
557
+ log(chalk_1.default.green('Built ' + pkg.packageName) +
558
+ (res === false ? chalk_1.default.redBright(' (with warnings)') : ''));
449
559
  }
450
560
  done.add(pkg);
451
561
  packagesLeft--;
@@ -461,7 +571,7 @@ function buildAll(options) {
461
571
  }
462
572
  })
463
573
  .catch(({ error, stdout, stderr }) => {
464
- warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
574
+ logError(chalk_1.default.red('Failed to build ' + pkg.packageName));
465
575
  console.log(stdout);
466
576
  process.exit(1);
467
577
  // let dependentModules = getDependentP
@@ -562,6 +672,7 @@ function buildAll(options) {
562
672
  }
563
673
  }, sync);
564
674
  }
675
+ exports.buildAll = buildAll;
565
676
  function getDependentPackages(dependencies, pkg) {
566
677
  let dependentModules = [];
567
678
  dependencies.forEach((dModuleDependencies, dModule) => {
@@ -612,6 +723,7 @@ function getLincdPackages(rootPath = process.cwd()) {
612
723
  checkWorkspaces(rootPath, pack.workspaces, res);
613
724
  return res;
614
725
  }
726
+ exports.getLincdPackages = getLincdPackages;
615
727
  function setVariable(name, replacement) {
616
728
  //prepare name for regexp
617
729
  name = name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
@@ -657,7 +769,7 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
657
769
  setVariable('uri_base', uriBase);
658
770
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(prefix);
659
771
  //copy ontology accessor file
660
- log('Creating files for ontology \'' + prefix + '\'');
772
+ log("Creating files for ontology '" + prefix + "'");
661
773
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
662
774
  fs_extra_1.default.copySync(path_1.default.join(dirname__, '..', '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
663
775
  //copy data files
@@ -829,7 +941,7 @@ const createSetComponent = async (name, basePath = process.cwd()) => {
829
941
  let targetFolder = ensureFolderExists(basePath, 'src', 'components');
830
942
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
831
943
  //copy default shape file
832
- log('Creating files for set component \'' + name + '\'');
944
+ log("Creating files for set component '" + name + "'");
833
945
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
834
946
  fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
835
947
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
@@ -845,7 +957,7 @@ const createComponent = async (name, basePath = process.cwd()) => {
845
957
  let targetFolder = ensureFolderExists(sourceFolder, 'components');
846
958
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
847
959
  //copy default shape file
848
- log('Creating files for component \'' + name + '\'');
960
+ log("Creating files for component '" + name + "'");
849
961
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
850
962
  fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.tsx'), targetFile);
851
963
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
@@ -923,15 +1035,17 @@ invalidImports = new Map()) => {
923
1035
  invalidImports.forEach((value, key) => {
924
1036
  // res += '- '+chalk.blueBright(key.split('/').pop()) + ':\n';
925
1037
  value.forEach(({ type, importPath }) => {
926
- let message = key.split('/').pop() + ' imports from \'' + importPath + '\'';
1038
+ let message = key.split('/').pop() + " imports from '" + importPath + "'";
927
1039
  if (type === 'outside_package') {
928
1040
  message += ' which is outside the package source root';
929
1041
  }
930
1042
  if (type === 'lincd') {
931
- message += ' which should not contain /src/ or /lib/ in the import path';
1043
+ message +=
1044
+ ' which should not contain /src/ or /lib/ in the import path';
932
1045
  }
933
1046
  if (type === 'missing_extension') {
934
- message += ' which should end with a file extension. Like .js or .scss';
1047
+ message +=
1048
+ ' which should end with a file extension. Like .js or .scss';
935
1049
  }
936
1050
  res += chalk_1.default.red(message + '\n');
937
1051
  });
@@ -988,13 +1102,16 @@ const depCheck = async (packagePath = process.cwd()) => {
988
1102
  if (missingLincdPackages.length > 0) {
989
1103
  reject(chalk_1.default.red(packagePath.split('/').pop() +
990
1104
  '\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
991
- missingLincdPackages.map(missedKey => {
1105
+ missingLincdPackages
1106
+ .map((missedKey) => {
992
1107
  const files = results.missing[missedKey];
993
1108
  return `${missedKey} (${files.length} files: ${files.join(', ')})`;
994
- }).join(',\n- ')));
1109
+ })
1110
+ .join(',\n- ')));
995
1111
  }
996
1112
  else if (missing.length > 0) {
997
- resolve(chalk_1.default.redBright('warning: ' + packagePath.split('/').pop() +
1113
+ resolve(chalk_1.default.redBright('warning: ' +
1114
+ packagePath.split('/').pop() +
998
1115
  ' is missing dependencies:\n - ' +
999
1116
  missing.join('\n - ')));
1000
1117
  }
@@ -1065,7 +1182,8 @@ const runMethod = async (packageName, method, options) => {
1065
1182
  if (options.spawn) {
1066
1183
  let lincdConfig = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lincd.config.js')}`).then(s => __importStar(require(s)))).default;
1067
1184
  //@ts-ignore
1068
- const ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer')))).LincdServer;
1185
+ const ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer'))))
1186
+ .LincdServer;
1069
1187
  await Promise.resolve(`${path_1.default.join(process.cwd(), 'scripts', 'storage-config.js')}`).then(s => __importStar(require(s)));
1070
1188
  let server = new ServerClass({
1071
1189
  loadAppComponent: async () => (await Promise.resolve(`${path_1.default.join(process.cwd(), 'src', 'App')}`).then(s => __importStar(require(s)))).default,
@@ -1098,7 +1216,9 @@ const runMethod = async (packageName, method, options) => {
1098
1216
  },
1099
1217
  };
1100
1218
  //TODO; allow sending args
1101
- server.callBackendMethod(packageName, method, [], request, response).then(() => {
1219
+ server
1220
+ .callBackendMethod(packageName, method, [], request, response)
1221
+ .then(() => {
1102
1222
  console.log('Done');
1103
1223
  process.exit();
1104
1224
  });
@@ -1113,17 +1233,21 @@ const runMethod = async (packageName, method, options) => {
1113
1233
  headers: {
1114
1234
  'Content-Type': 'application/json',
1115
1235
  },
1116
- }).then((response) => {
1236
+ })
1237
+ .then((response) => {
1117
1238
  if (!response.ok) {
1118
1239
  throw new Error('Network response was not ok');
1119
1240
  }
1120
1241
  return response.json();
1121
- }).then((data) => {
1242
+ })
1243
+ .then((data) => {
1122
1244
  console.log('Response data:', data);
1123
1245
  process.exit();
1124
- }).catch((error) => {
1246
+ })
1247
+ .catch((error) => {
1125
1248
  var _a;
1126
- if (error.code === 'ECONNREFUSED' || ((_a = error.cause) === null || _a === void 0 ? void 0 : _a.code) === 'ECONNREFUSED') {
1249
+ if (error.code === 'ECONNREFUSED' ||
1250
+ ((_a = error.cause) === null || _a === void 0 ? void 0 : _a.code) === 'ECONNREFUSED') {
1127
1251
  console.error(chalk_1.default.red('Could not connect to the backend server. Is it running?'));
1128
1252
  console.error(`Make sure you ${chalk_1.default.magenta('run "yarn start" in a separate process')} before calling this method.`);
1129
1253
  }
@@ -1137,7 +1261,8 @@ const runMethod = async (packageName, method, options) => {
1137
1261
  exports.runMethod = runMethod;
1138
1262
  const startServer = async (initOnly = false, ServerClass = null) => {
1139
1263
  await (0, exports.ensureEnvironmentLoaded)();
1140
- let lincdConfig = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lincd.config.js')}`).then(s => __importStar(require(s)))).default;
1264
+ let lincdConfig = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lincd.config.js')}`).then(s => __importStar(require(s))))
1265
+ .default;
1141
1266
  // function scssLoadcall(source, filename) {
1142
1267
  // return 'console.log("SCSS CALL: ' + filename + '");\n' + source;
1143
1268
  // process.exit();
@@ -1155,15 +1280,18 @@ const startServer = async (initOnly = false, ServerClass = null) => {
1155
1280
  await Promise.resolve(`${path_1.default.join(process.cwd(), 'scripts', 'storage-config.js')}`).then(s => __importStar(require(s)));
1156
1281
  let appPromise;
1157
1282
  if (process.env.NODE_ENV !== 'development') {
1158
- appPromise = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lib', 'App.js')}`).then(s => __importStar(require(s)))).default;
1283
+ appPromise = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lib', 'App.js')}`).then(s => __importStar(require(s))))
1284
+ .default;
1159
1285
  }
1160
1286
  else {
1161
- appPromise = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'src', 'App.js')}`).then(s => __importStar(require(s)))).default;
1287
+ appPromise = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'src', 'App.tsx')}`).then(s => __importStar(require(s))))
1288
+ .default;
1162
1289
  }
1163
1290
  let server = new ServerClass({
1164
1291
  loadAppComponent: async () => {
1165
1292
  return appPromise;
1166
- }, ...lincdConfig,
1293
+ },
1294
+ ...lincdConfig,
1167
1295
  });
1168
1296
  //Important to use slice, because when using clusers, child processes need to be able to read the same arguments
1169
1297
  let args = process.argv.slice(2);
@@ -1222,7 +1350,8 @@ const buildFrontend = async () => {
1222
1350
  }).then(async () => {
1223
1351
  // make sure environment is not development for storage config
1224
1352
  // and if we want to upload to storage, we need set S3_BUCKET_ENDPOINT
1225
- if (process.env.NODE_ENV === 'development' || !process.env.S3_BUCKET_ENDPOINT) {
1353
+ if (process.env.NODE_ENV === 'development' ||
1354
+ !process.env.S3_BUCKET_ENDPOINT) {
1226
1355
  console.warn('Upload build to storage skip in development environment or S3_BUCKET_ENDPOINT is not set');
1227
1356
  return;
1228
1357
  // process.exit();
@@ -1259,9 +1388,11 @@ const buildFrontend = async () => {
1259
1388
  // example: /Users/username/project/www/index.html -> /project/www/index.html
1260
1389
  const pathname = filePath.replace(pathDir, `/${rootDirectory}`);
1261
1390
  // upload file to storage
1262
- await LinkedFileStorage_1.LinkedFileStorage.saveFile(pathname, fileContent).then(() => {
1391
+ await LinkedFileStorage_1.LinkedFileStorage.saveFile(pathname, fileContent)
1392
+ .then(() => {
1263
1393
  clearSpinner.text = `${counter++}/${files.length}: - Published ${pathname} `;
1264
- }).catch(console.error);
1394
+ })
1395
+ .catch(console.error);
1265
1396
  });
1266
1397
  const urls = await Promise.all(uploads);
1267
1398
  clearSpinner.succeed(`${urls.length} files uploaded to storage`);
@@ -1339,7 +1470,9 @@ const upgradePackages = async () => {
1339
1470
  const tsConfigCJS = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-cjs.json');
1340
1471
  const tsConfigESM = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-esm.json');
1341
1472
  const typesFile = path_1.default.join(dirname, '../../defaults/package/src', 'types.d.ts');
1342
- const tsConfigTemplate = await fs_extra_1.default.readJson(path_1.default.join(dirname, '../../defaults/package', 'tsconfig.json')).catch(err => {
1473
+ const tsConfigTemplate = await fs_extra_1.default
1474
+ .readJson(path_1.default.join(dirname, '../../defaults/package', 'tsconfig.json'))
1475
+ .catch((err) => {
1343
1476
  console.log(err);
1344
1477
  });
1345
1478
  runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
@@ -1454,7 +1587,9 @@ const upgradePackages = async () => {
1454
1587
  // }
1455
1588
  // })
1456
1589
  // });
1457
- files.filter(f => f.match(/\.(scss\.json|css\.json)$/)).forEach(cssJsonFile => {
1590
+ files
1591
+ .filter((f) => f.match(/\.(scss\.json|css\.json)$/))
1592
+ .forEach((cssJsonFile) => {
1458
1593
  console.log('Removing ' + cssJsonFile);
1459
1594
  fs_extra_1.default.unlinkSync(cssJsonFile);
1460
1595
  });
@@ -1504,7 +1639,7 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
1504
1639
  //extra variable for clarity (will be same as 'name')
1505
1640
  setVariable('output_file_name', name);
1506
1641
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(cleanPackageName);
1507
- log('Creating new LINCD package \'' + name + '\'');
1642
+ log("Creating new LINCD package '" + name + "'");
1508
1643
  fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'package'), targetFolder);
1509
1644
  //replace variables in some of the copied files
1510
1645
  await Promise.all([
@@ -1627,7 +1762,7 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
1627
1762
  spinner.text = step.name;
1628
1763
  spinner.start();
1629
1764
  }
1630
- return step.apply().then(stepResult => {
1765
+ return step.apply().then((stepResult) => {
1631
1766
  //if a build step returns a string,
1632
1767
  //a warning is shown but the build is still successful with warnings
1633
1768
  if (typeof stepResult === 'string') {
@@ -1676,26 +1811,29 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
1676
1811
  name: 'Copying files to lib folder',
1677
1812
  apply: async () => {
1678
1813
  const files = await (0, glob_1.glob)(packagePath + '/src/**/*.{json,d.ts,css,scss}');
1679
- return Promise.all(files.map((async (file) => {
1814
+ return Promise.all(files.map(async (file) => {
1680
1815
  try {
1681
- await fs_extra_1.default.copy(file, packagePath + '/lib/esm/' + file.replace(packagePath + '/src/', ''));
1682
- await fs_extra_1.default.copy(file, packagePath + '/lib/cjs/' + file.replace(packagePath + '/src/', ''));
1816
+ await fs_extra_1.default.copy(file, packagePath +
1817
+ '/lib/esm/' +
1818
+ file.replace(packagePath + '/src/', ''));
1819
+ await fs_extra_1.default.copy(file, packagePath +
1820
+ '/lib/cjs/' +
1821
+ file.replace(packagePath + '/src/', ''));
1683
1822
  return true;
1684
1823
  }
1685
1824
  catch (err) {
1686
1825
  console.warn(err);
1687
1826
  return false;
1688
1827
  }
1689
- ;
1690
- }))).then((allResults) => {
1691
- return allResults.every(r => r === true);
1828
+ })).then((allResults) => {
1829
+ return allResults.every((r) => r === true);
1692
1830
  });
1693
1831
  },
1694
1832
  });
1695
1833
  buildStep({
1696
1834
  name: 'Dual package support',
1697
1835
  apply: () => {
1698
- return (0, utils_js_1.execPromise)('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then(res => {
1836
+ return (0, utils_js_1.execPromise)('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
1699
1837
  return res === '';
1700
1838
  });
1701
1839
  },
@@ -1710,8 +1848,12 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
1710
1848
  name: 'Checking dependencies',
1711
1849
  apply: () => (0, exports.depCheck)(packagePath),
1712
1850
  });
1713
- let success = await buildProcess.catch(err => {
1714
- let msg = typeof err === 'string' || err instanceof Error ? err.toString() : (err.error && !err.error.toString().includes('Command failed:') ? err.error : err.stdout + '\n' + err.stderr);
1851
+ let success = await buildProcess.catch((err) => {
1852
+ let msg = typeof err === 'string' || err instanceof Error
1853
+ ? err.toString()
1854
+ : err.error && !err.error.toString().includes('Command failed:')
1855
+ ? err.error
1856
+ : err.stdout + '\n' + err.stderr;
1715
1857
  if (logResults) {
1716
1858
  spinner.stopAndPersist({
1717
1859
  symbol: chalk_1.default.red('✖'),
@@ -1729,15 +1871,19 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
1729
1871
  if (logResults) {
1730
1872
  spinner.stopAndPersist({
1731
1873
  symbol: chalk_1.default.greenBright('✔'),
1732
- text: success === true ? 'Build successful' : 'Build successful with warnings',
1874
+ text: success === true
1875
+ ? 'Build successful'
1876
+ : 'Build successful with warnings',
1733
1877
  });
1734
1878
  }
1735
1879
  }
1736
1880
  else {
1737
- spinner.stopAndPersist({
1738
- symbol: chalk_1.default.red('✖'),
1739
- text: 'Build failed',
1740
- });
1881
+ if (logResults) {
1882
+ spinner.stopAndPersist({
1883
+ symbol: chalk_1.default.red(''),
1884
+ text: 'Build failed',
1885
+ });
1886
+ }
1741
1887
  }
1742
1888
  return success;
1743
1889
  };
@@ -1772,16 +1918,18 @@ exports.compilePackage = compilePackage;
1772
1918
  const compilePackageESM = async (packagePath = process.cwd()) => {
1773
1919
  //echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
1774
1920
  let compileCommand = `yarn exec tsc -p tsconfig-esm.json`;
1775
- return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
1921
+ return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then((res) => {
1776
1922
  return res === '';
1777
1923
  });
1778
1924
  };
1779
1925
  exports.compilePackageESM = compilePackageESM;
1780
1926
  const compilePackageCJS = async (packagePath = process.cwd()) => {
1781
1927
  let compileCommand = `yarn exec tsc -p tsconfig-cjs.json`;
1782
- return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
1928
+ return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath })
1929
+ .then((res) => {
1783
1930
  return res === '';
1784
- }).catch(err => {
1931
+ })
1932
+ .catch((err) => {
1785
1933
  return {
1786
1934
  error: err.stdout,
1787
1935
  };
@@ -1899,7 +2047,7 @@ var publishUpdated = function (test = false) {
1899
2047
  })
1900
2048
  .catch(({ error, stdout, stderr }) => {
1901
2049
  if (error) {
1902
- console.log(error.message);
2050
+ console.error(error.message);
1903
2051
  }
1904
2052
  if (stdout) {
1905
2053
  console.log(stderr);
@@ -1975,7 +2123,7 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
1975
2123
  .then((res) => {
1976
2124
  if (res.indexOf('Aborted due to warnings') !== -1 ||
1977
2125
  res.indexOf('Could not publish') !== -1 ||
1978
- res.indexOf('Couldn\'t publish') !== -1) {
2126
+ res.indexOf("Couldn't publish") !== -1) {
1979
2127
  console.log(res);
1980
2128
  return chalk_1.default.red(pkg.packageName + ' failed\n');
1981
2129
  }
@@ -1988,7 +2136,7 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
1988
2136
  chalk_1.default.magenta(publishVersion));
1989
2137
  })
1990
2138
  .catch(({ error, stdout, stderr }) => {
1991
- console.log(chalk_1.default.red('Failed to publish: ' + error.message));
2139
+ logError('Failed to publish: ' + error.message);
1992
2140
  return chalk_1.default.red(pkg.packageName + ' failed to publish');
1993
2141
  });
1994
2142
  };
@@ -2049,42 +2197,31 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
2049
2197
  return chalk_1.default.blue(pkg.packageName + ' should be build');
2050
2198
  }
2051
2199
  log('Building ' + pkg.packageName);
2052
- // return buildPackage(null,null,pkg.path)
2053
- return (0, utils_js_1.execPromise)('cd ' +
2054
- pkg.path +
2055
- ' && yarn build' +
2056
- (target ? ' ' + target : '') +
2057
- (target2 ? ' ' + target2 : ''))
2200
+ return (0, exports.buildPackage)(null, null, path_1.default.join(process.cwd(), pkg.path), false)
2058
2201
  .then((res) => {
2059
- if (res === '') {
2202
+ //empty string or true is success
2203
+ //false is success with warnings
2204
+ //any other string is the build error text
2205
+ //undefined result means it failed
2206
+ if (typeof res === 'undefined') {
2207
+ logError('Failed to build ' + pkg.packageName);
2208
+ process.exit(1);
2209
+ }
2210
+ else {
2060
2211
  (0, utils_js_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
2061
2212
  return chalk_1.default.green(pkg.packageName + ' built');
2062
2213
  }
2063
- else if (typeof res === 'string') {
2064
- warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
2065
- console.log(res);
2066
- process.exit(1);
2067
- }
2068
2214
  })
2069
- .catch(({ error, stdout, stderr }) => {
2070
- warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
2071
- console.log(stdout);
2215
+ .catch((err) => {
2216
+ logError('Failed to build ' + pkg.packageName);
2217
+ console.error(err);
2072
2218
  process.exit(1);
2073
- // let dependentModules = getDependentPackages(dependencies, pkg);
2074
- // if (dependentModules.length > 0) {
2075
- // // printBuildResults(failedModules, done);
2076
- // warn(chalk.red(pkg.packageName + ' build failed'));
2077
- // warn(
2078
- // 'Stopping build-updated process because ' +
2079
- // dependentModules.length +
2080
- // ' other packages depend on this package.\n',
2081
- // ); //"+dependentModules.map(d => d.packageName).join(", ")));
2082
- // }
2083
2219
  });
2084
2220
  }
2085
2221
  };
2086
- }, (results) => {
2222
+ }, (dependencies, results) => {
2087
2223
  if (results.length) {
2224
+ log(chalk_1.default.green('Changed packages have been rebuilt'));
2088
2225
  log('Summary:');
2089
2226
  log(results.join('\n'));
2090
2227
  }
@@ -2124,16 +2261,15 @@ var executeCommandForEachPackage = function (packages, command, filterMethod, fi
2124
2261
  }
2125
2262
  let seen = false;
2126
2263
  packages = packages.filter((pkg) => {
2127
- if (!seen &&
2128
- pkg.packageName.includes(startFrom)) {
2264
+ if (!seen && pkg.packageName.includes(startFrom)) {
2129
2265
  seen = true;
2130
2266
  }
2131
2267
  return seen;
2132
2268
  });
2133
2269
  }
2134
- log('Executing \'' +
2270
+ log("Executing '" +
2135
2271
  chalk_1.default.blueBright(command) +
2136
- '\' on packages ' +
2272
+ "' on packages " +
2137
2273
  chalk_1.default.magenta(packages.map((m) => m.packageName).join(', ')));
2138
2274
  var p = Promise.resolve(true);
2139
2275
  packages.forEach((pkg) => {
@@ -2217,11 +2353,11 @@ var executeCommandForPackage = function (packageName, command) {
2217
2353
  let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
2218
2354
  modDetails.packageName.indexOf(packageName) !== -1);
2219
2355
  if (packageDetails) {
2220
- log('Executing \'cd ' +
2356
+ log("Executing 'cd " +
2221
2357
  packageDetails.path +
2222
2358
  ' && yarn lincd' +
2223
2359
  (command ? ' ' + command : '') +
2224
- '\'');
2360
+ "'");
2225
2361
  (0, child_process_2.spawn)(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', // Windows quirk
2226
2362
  ['lincd', command || null], {
2227
2363
  cwd: packageDetails.path,
@@ -2229,7 +2365,7 @@ var executeCommandForPackage = function (packageName, command) {
2229
2365
  });
2230
2366
  }
2231
2367
  else {
2232
- warn('Could not find a pkg who\'s name (partially) matched ' +
2368
+ warn("Could not find a pkg who's name (partially) matched " +
2233
2369
  chalk_1.default.cyan(packageName));
2234
2370
  }
2235
2371
  };