lincd-cli 1.2.1 → 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.
Files changed (48) hide show
  1. package/defaults/app-with-backend/lincd.config.js +3 -3
  2. package/defaults/app-with-backend/package.json +2 -1
  3. package/defaults/app-with-backend/src/index.tsx +3 -3
  4. package/defaults/app-with-backend/src/pages/Home.tsx +1 -0
  5. package/defaults/app-with-backend/src/pages/PageNotFound.tsx +2 -1
  6. package/defaults/app-with-backend/src/theme.css +61 -66
  7. package/defaults/app-with-backend/src/types.ts +14 -0
  8. package/defaults/app-with-backend/tsconfig.json +1 -1
  9. package/defaults/package/package.json +30 -3
  10. package/defaults/package/src/backend.ts +2 -1
  11. package/defaults/package/src/index.ts +1 -1
  12. package/defaults/package/src/ontologies/example-ontology.ts +4 -4
  13. package/defaults/package/src/package.ts +2 -1
  14. package/defaults/shape.ts +1 -1
  15. package/lib/cjs/cli-methods.js +442 -132
  16. package/lib/cjs/cli-methods.js.map +1 -1
  17. package/lib/cjs/cli.js +9 -1
  18. package/lib/cjs/cli.js.map +1 -1
  19. package/lib/cjs/config-grunt.cjs +1 -1
  20. package/lib/cjs/config-grunt.cjs.map +1 -1
  21. package/lib/cjs/config-webpack-app.js +42 -50
  22. package/lib/cjs/config-webpack-app.js.map +1 -1
  23. package/lib/cjs/config-webpack.js +10 -19
  24. package/lib/cjs/config-webpack.js.map +1 -1
  25. package/lib/cjs/loaders/css-loader.mjs +12 -5
  26. package/lib/cjs/loaders/css-loader.mjs.map +1 -1
  27. package/lib/cjs/package.json +2 -1
  28. package/lib/cjs/plugins/check-imports.js +1 -1
  29. package/lib/cjs/plugins/check-imports.js.map +1 -1
  30. package/lib/cjs/plugins/declaration-plugin.js +7 -17
  31. package/lib/cjs/plugins/declaration-plugin.js.map +1 -1
  32. package/lib/cjs/utils.js +44 -38
  33. package/lib/cjs/utils.js.map +1 -1
  34. package/lib/esm/cli-methods.js +434 -122
  35. package/lib/esm/cli-methods.js.map +1 -1
  36. package/lib/esm/cli.js +10 -2
  37. package/lib/esm/cli.js.map +1 -1
  38. package/lib/esm/config-grunt.cjs +24 -27
  39. package/lib/esm/config-grunt.cjs.map +1 -1
  40. package/lib/esm/config-webpack-app.js +36 -34
  41. package/lib/esm/config-webpack-app.js.map +1 -1
  42. package/lib/esm/config-webpack.js +1 -1
  43. package/lib/esm/config-webpack.js.map +1 -1
  44. package/lib/esm/package.json +2 -1
  45. package/lib/esm/utils.js +24 -9
  46. package/lib/esm/utils.js.map +1 -1
  47. package/package.json +7 -1
  48. /package/defaults/package/src/{types.d.ts → types.ts} +0 -0
@@ -14,18 +14,21 @@ import { getEnvFile } from 'env-cmd/dist/get-env-vars.js';
14
14
  import fs from 'fs-extra';
15
15
  import path, { dirname } from 'path';
16
16
  import { debugInfo, execp, execPromise, getFileImports, getFiles, getLastCommitTime, getPackageJSON, isImportOutsideOfPackage, isImportWithMissingExtension, isInvalidLINCDImport, needsRebuilding, } from './utils.js';
17
- import { statSync } from 'fs';
17
+ import { spawn as spawnChild } from 'child_process';
18
18
  import { findNearestPackageJson } from 'find-nearest-package-json';
19
+ import { statSync } from 'fs';
19
20
  import { LinkedFileStorage } from 'lincd/utils/LinkedFileStorage';
20
21
  // import pkg from 'lincd/utils/LinkedFileStorage';
21
22
  // const { LinkedFileStorage } = pkg;
22
23
  // const config = require('lincd-server/site.webpack.config');
23
24
  import { glob } from 'glob';
24
25
  import webpack from 'webpack';
25
- import stagedGitFiles from 'staged-git-files';
26
26
  import ora from 'ora';
27
- //@ts-ignore
28
- let dirname__ = typeof __dirname !== 'undefined' ? __dirname : dirname(import.meta.url).replace('file:/', '');
27
+ import stagedGitFiles from 'staged-git-files';
28
+ let dirname__ = typeof __dirname !== 'undefined'
29
+ ? __dirname
30
+ : //@ts-ignore
31
+ dirname(import.meta.url).replace('file:/', '');
29
32
  var variables = {};
30
33
  export const createApp = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
31
34
  if (!name) {
@@ -45,7 +48,7 @@ export const createApp = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...ar
45
48
  fs.renameSync(path.join(targetFolder, 'gitignore.template'), path.join(targetFolder, '.gitignore'));
46
49
  fs.renameSync(path.join(targetFolder, 'yarnrc.yml.template'), path.join(targetFolder, '.yarnrc.yml'));
47
50
  // fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
48
- log('Creating new LINCD application \'' + name + '\'');
51
+ log("Creating new LINCD application '" + name + "'");
49
52
  //replace variables in some copied files
50
53
  yield replaceVariablesInFolder(targetFolder);
51
54
  let hasYarn = yield hasYarnInstalled();
@@ -71,10 +74,15 @@ function progressUpdate(message) {
71
74
  }
72
75
  export function warn(...messages) {
73
76
  messages.forEach((message) => {
74
- console.log(chalk.redBright('Warning: ') + message);
77
+ console.warn(chalk.redBright('Warning: ') + message);
75
78
  // console.log(chalk.red(message));
76
79
  });
77
80
  }
81
+ export function logError(...messages) {
82
+ messages.forEach((message) => {
83
+ console.error(chalk.redBright('Error: ') + message);
84
+ });
85
+ }
78
86
  export function developPackage(target, mode) {
79
87
  if (!target)
80
88
  target = 'es6';
@@ -140,7 +148,7 @@ function checkPackagePath(rootPath, packagePath, res) {
140
148
  }
141
149
  }
142
150
  }
143
- function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStackEnd, sync = false) {
151
+ export function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStackEnd, sync = false) {
144
152
  let dependencies = new Map();
145
153
  //get dependencies of each package
146
154
  let leastDependentPackage;
@@ -308,9 +316,121 @@ function hasDependency(pkg, childPkg, dependencies, depth = 1) {
308
316
  console.log('going up');
309
317
  return false;
310
318
  }
319
+ /**
320
+ * Finds the topmost package.json that could be an APP_ROOT
321
+ * Returns null if no app root is found (standalone repo case)
322
+ */
323
+ function findAppRoot(startPath = process.cwd()) {
324
+ let currentPath = startPath;
325
+ let candidateRoots = [];
326
+ // Walk up the directory tree
327
+ for (let i = 0; i < 10; i++) {
328
+ const packageJsonPath = path.join(currentPath, 'package.json');
329
+ if (fs.existsSync(packageJsonPath)) {
330
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
331
+ candidateRoots.push({
332
+ path: currentPath,
333
+ hasWorkspaces: !!packageJson.workspaces,
334
+ isLincd: packageJson.lincd === true,
335
+ });
336
+ }
337
+ const parentPath = path.join(currentPath, '..');
338
+ // If we've reached the root or haven't moved up
339
+ if (parentPath === currentPath) {
340
+ break;
341
+ }
342
+ currentPath = parentPath;
343
+ }
344
+ // Find the topmost package.json that has workspaces
345
+ // Prefer non-lincd packages (app roots) over lincd packages
346
+ let appRoot = null;
347
+ for (let i = candidateRoots.length - 1; i >= 0; i--) {
348
+ const candidate = candidateRoots[i];
349
+ if (candidate.hasWorkspaces && !candidate.isLincd) {
350
+ appRoot = candidate.path;
351
+ break;
352
+ }
353
+ }
354
+ // If no non-lincd workspace found, use the topmost workspace
355
+ if (!appRoot) {
356
+ for (let i = candidateRoots.length - 1; i >= 0; i--) {
357
+ if (candidateRoots[i].hasWorkspaces) {
358
+ appRoot = candidateRoots[i].path;
359
+ break;
360
+ }
361
+ }
362
+ }
363
+ return appRoot;
364
+ }
365
+ /**
366
+ * Filters packages to only include those in the dependency tree of the app root
367
+ */
368
+ function filterPackagesByDependencyTree(allPackages, appRootPath) {
369
+ const appPackageJson = getPackageJSON(appRootPath);
370
+ if (!appPackageJson) {
371
+ return allPackages;
372
+ }
373
+ const relevantPackages = new Map();
374
+ const packagesToCheck = new Set();
375
+ // Start with direct dependencies from app root
376
+ if (appPackageJson.dependencies) {
377
+ Object.keys(appPackageJson.dependencies).forEach((dep) => {
378
+ if (allPackages.has(dep)) {
379
+ packagesToCheck.add(dep);
380
+ }
381
+ });
382
+ }
383
+ // Recursively add dependencies
384
+ const processedPackages = new Set();
385
+ while (packagesToCheck.size > 0) {
386
+ const packageName = Array.from(packagesToCheck)[0];
387
+ packagesToCheck.delete(packageName);
388
+ if (processedPackages.has(packageName)) {
389
+ continue;
390
+ }
391
+ processedPackages.add(packageName);
392
+ const packageDetails = allPackages.get(packageName);
393
+ if (packageDetails) {
394
+ relevantPackages.set(packageName, packageDetails);
395
+ // Get this package's dependencies
396
+ const packageJson = getPackageJSON(packageDetails.path);
397
+ if (packageJson && packageJson.dependencies) {
398
+ Object.keys(packageJson.dependencies).forEach((dep) => {
399
+ if (allPackages.has(dep) && !processedPackages.has(dep)) {
400
+ packagesToCheck.add(dep);
401
+ }
402
+ });
403
+ }
404
+ }
405
+ }
406
+ return relevantPackages;
407
+ }
311
408
  export function buildAll(options) {
312
409
  console.log('Building all LINCD packages of this repository in order of dependencies');
313
410
  let lincdPackages = getLocalLincdPackageMap();
411
+ const originalPackageCount = lincdPackages.size;
412
+ // Check if we're in an app context and filter packages accordingly
413
+ const appRoot = findAppRoot();
414
+ if (appRoot) {
415
+ const appPackageJson = getPackageJSON(appRoot);
416
+ // Check if this is an app (not a lincd package itself) with lincd dependencies
417
+ const isAppWithLincdDeps = appPackageJson &&
418
+ appPackageJson.lincd !== true &&
419
+ appPackageJson.dependencies &&
420
+ Object.keys(appPackageJson.dependencies).some((dep) => lincdPackages.has(dep));
421
+ if (isAppWithLincdDeps) {
422
+ debugInfo(chalk.blue(`Found app root at: ${appRoot}`));
423
+ const filteredPackages = filterPackagesByDependencyTree(lincdPackages, appRoot);
424
+ console.log(chalk.magenta(`Found ${originalPackageCount} total LINCD packages, building only ${filteredPackages.size} that are relevant to this app`));
425
+ lincdPackages = filteredPackages;
426
+ }
427
+ else {
428
+ debugInfo(chalk.blue(`Building all ${originalPackageCount} packages from workspace`));
429
+ }
430
+ }
431
+ else {
432
+ debugInfo(chalk.blue(`No workspace root found, building all ${originalPackageCount} packages`));
433
+ }
314
434
  let startFrom;
315
435
  //by default start building
316
436
  let building = true;
@@ -384,7 +504,8 @@ export function buildAll(options) {
384
504
  log(chalk.cyan('Building ' + pkg.packageName));
385
505
  process.stdout.write(packagesLeft + ' packages left\r');
386
506
  }
387
- return command.then(res => {
507
+ return command
508
+ .then((res) => {
388
509
  //empty string or true is success
389
510
  //false is success with warnings
390
511
  //any other string is the build error text
@@ -408,7 +529,8 @@ export function buildAll(options) {
408
529
  }
409
530
  else {
410
531
  if (!skipping) {
411
- log(chalk.green('Built ' + pkg.packageName) + (res === false ? chalk.redBright(' (with warnings)') : ''));
532
+ log(chalk.green('Built ' + pkg.packageName) +
533
+ (res === false ? chalk.redBright(' (with warnings)') : ''));
412
534
  }
413
535
  done.add(pkg);
414
536
  packagesLeft--;
@@ -424,7 +546,7 @@ export function buildAll(options) {
424
546
  }
425
547
  })
426
548
  .catch(({ error, stdout, stderr }) => {
427
- warn(chalk.red('Failed to build ' + pkg.packageName));
549
+ logError(chalk.red('Failed to build ' + pkg.packageName));
428
550
  console.log(stdout);
429
551
  process.exit(1);
430
552
  // let dependentModules = getDependentP
@@ -607,7 +729,7 @@ const camelCase = (str) => {
607
729
  }
608
730
  return str;
609
731
  };
610
- export const createOntology = (prefix_1, uriBase_1, ...args_1) => __awaiter(void 0, [prefix_1, uriBase_1, ...args_1], void 0, function* (prefix, uriBase, basePath = process.cwd()) {
732
+ export const createOntology = (prefix_1, uriBase_1, ...args_2) => __awaiter(void 0, [prefix_1, uriBase_1, ...args_2], void 0, function* (prefix, uriBase, basePath = process.cwd()) {
611
733
  if (!prefix) {
612
734
  console.warn('Please provide a suggested prefix as the first argument');
613
735
  return;
@@ -620,7 +742,7 @@ export const createOntology = (prefix_1, uriBase_1, ...args_1) => __awaiter(void
620
742
  setVariable('uri_base', uriBase);
621
743
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(prefix);
622
744
  //copy ontology accessor file
623
- log('Creating files for ontology \'' + prefix + '\'');
745
+ log("Creating files for ontology '" + prefix + "'");
624
746
  let targetFile = path.join(targetFolder, hyphenName + '.ts');
625
747
  fs.copySync(path.join(dirname__, '..', '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
626
748
  //copy data files
@@ -770,7 +892,7 @@ export const getScriptDir = () => {
770
892
  // return dirname(import.meta.url).replace('file:/','');
771
893
  // }
772
894
  };
773
- export const createShape = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
895
+ export const createShape = (name_2, ...args_3) => __awaiter(void 0, [name_2, ...args_3], void 0, function* (name, basePath = process.cwd()) {
774
896
  let sourceFolder = getSourceFolder(basePath);
775
897
  let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
776
898
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
@@ -788,11 +910,11 @@ export const createShape = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...
788
910
  log(`Added an import of this file from ${chalk.magenta(indexPath)}`);
789
911
  }
790
912
  });
791
- export const createSetComponent = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
913
+ export const createSetComponent = (name_3, ...args_4) => __awaiter(void 0, [name_3, ...args_4], void 0, function* (name, basePath = process.cwd()) {
792
914
  let targetFolder = ensureFolderExists(basePath, 'src', 'components');
793
915
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
794
916
  //copy default shape file
795
- log('Creating files for set component \'' + name + '\'');
917
+ log("Creating files for set component '" + name + "'");
796
918
  let targetFile = path.join(targetFolder, hyphenName + '.tsx');
797
919
  fs.copySync(path.join(getScriptDir(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
798
920
  let targetFile2 = path.join(targetFolder, hyphenName + '.scss');
@@ -802,12 +924,12 @@ export const createSetComponent = (name_1, ...args_1) => __awaiter(void 0, [name
802
924
  let indexPath = addLineToIndex(`import './components/${hyphenName}.js';`, 'components');
803
925
  log(`Created a new set component in ${chalk.magenta(targetFile.replace(basePath, ''))}`, `Created a new stylesheet in ${chalk.magenta(targetFile2.replace(basePath, ''))}`, `Added an import of this file from ${chalk.magenta(indexPath)}`);
804
926
  });
805
- export const createComponent = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
927
+ export const createComponent = (name_4, ...args_5) => __awaiter(void 0, [name_4, ...args_5], void 0, function* (name, basePath = process.cwd()) {
806
928
  let sourceFolder = getSourceFolder(basePath);
807
929
  let targetFolder = ensureFolderExists(sourceFolder, 'components');
808
930
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
809
931
  //copy default shape file
810
- log('Creating files for component \'' + name + '\'');
932
+ log("Creating files for component '" + name + "'");
811
933
  let targetFile = path.join(targetFolder, hyphenName + '.tsx');
812
934
  fs.copySync(path.join(getScriptDir(), '..', 'defaults', 'component.tsx'), targetFile);
813
935
  let targetFile2 = path.join(targetFolder, hyphenName + '.scss');
@@ -825,7 +947,7 @@ export const createComponent = (name_1, ...args_1) => __awaiter(void 0, [name_1,
825
947
  //read the source of all ts/tsx files in the src folder
826
948
  //if there is an import that imports a lincd package with /src/ in it, then warn
827
949
  //if there is an import that imports something from outside the src folder, then warn
828
- export const checkImports = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside the src folder
950
+ export const checkImports = (...args_6) => __awaiter(void 0, [...args_6], void 0, function* (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside the src folder
829
951
  invalidImports = new Map()) {
830
952
  const dir = fs.readdirSync(sourceFolder);
831
953
  // Start checking each file in the source folder
@@ -858,19 +980,19 @@ invalidImports = new Map()) {
858
980
  if (isImportOutsideOfPackage(i, depth)) {
859
981
  invalidImports.get(filename).push({
860
982
  type: 'outside_package',
861
- importPath: i
983
+ importPath: i,
862
984
  });
863
985
  }
864
986
  if (isInvalidLINCDImport(i, depth)) {
865
987
  invalidImports.get(filename).push({
866
988
  type: 'lincd',
867
- importPath: i
989
+ importPath: i,
868
990
  });
869
991
  }
870
992
  if (isImportWithMissingExtension(i)) {
871
993
  invalidImports.get(filename).push({
872
994
  type: 'missing_extension',
873
- importPath: i
995
+ importPath: i,
874
996
  });
875
997
  }
876
998
  });
@@ -884,15 +1006,17 @@ invalidImports = new Map()) {
884
1006
  invalidImports.forEach((value, key) => {
885
1007
  // res += '- '+chalk.blueBright(key.split('/').pop()) + ':\n';
886
1008
  value.forEach(({ type, importPath }) => {
887
- let message = key.split('/').pop() + ' imports from \'' + importPath + '\'';
1009
+ let message = key.split('/').pop() + " imports from '" + importPath + "'";
888
1010
  if (type === 'outside_package') {
889
1011
  message += ' which is outside the package source root';
890
1012
  }
891
1013
  if (type === 'lincd') {
892
- message += ' which should not contain /src/ or /lib/ in the import path';
1014
+ message +=
1015
+ ' which should not contain /src/ or /lib/ in the import path';
893
1016
  }
894
1017
  if (type === 'missing_extension') {
895
- message += ' which should end with a file extension. Like .js or .scss';
1018
+ message +=
1019
+ ' which should end with a file extension. Like .js or .scss';
896
1020
  }
897
1021
  res += chalk.red(message + '\n');
898
1022
  });
@@ -929,7 +1053,7 @@ export const depCheckStaged = () => __awaiter(void 0, void 0, void 0, function*
929
1053
  });
930
1054
  });
931
1055
  });
932
- export const depCheck = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
1056
+ export const depCheck = (...args_7) => __awaiter(void 0, [...args_7], void 0, function* (packagePath = process.cwd()) {
933
1057
  return new Promise((resolve, reject) => {
934
1058
  depcheck(packagePath, {}, (results) => {
935
1059
  if (results.missing) {
@@ -949,10 +1073,16 @@ export const depCheck = (...args_1) => __awaiter(void 0, [...args_1], void 0, fu
949
1073
  if (missingLincdPackages.length > 0) {
950
1074
  reject(chalk.red(packagePath.split('/').pop() +
951
1075
  '\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
952
- missingLincdPackages.join(',\n- ')));
1076
+ missingLincdPackages
1077
+ .map((missedKey) => {
1078
+ const files = results.missing[missedKey];
1079
+ return `${missedKey} (${files.length} files: ${files.join(', ')})`;
1080
+ })
1081
+ .join(',\n- ')));
953
1082
  }
954
1083
  else if (missing.length > 0) {
955
- resolve(chalk.redBright('warning: ' + packagePath.split('/').pop() +
1084
+ resolve(chalk.redBright('warning: ' +
1085
+ packagePath.split('/').pop() +
956
1086
  ' is missing dependencies:\n - ' +
957
1087
  missing.join('\n - ')));
958
1088
  }
@@ -1016,9 +1146,88 @@ export const ensureEnvironmentLoaded = () => __awaiter(void 0, void 0, void 0, f
1016
1146
  }
1017
1147
  }
1018
1148
  });
1019
- export const startServer = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (initOnly = false, ServerClass = null) {
1149
+ export const runMethod = (packageName, method, options) => __awaiter(void 0, void 0, void 0, function* () {
1150
+ yield ensureEnvironmentLoaded();
1151
+ if (options.spawn) {
1152
+ let lincdConfig = (yield import(path.join(process.cwd(), 'lincd.config.js'))).default;
1153
+ //@ts-ignore
1154
+ const ServerClass = (yield import('lincd-server/shapes/LincdServer'))
1155
+ .LincdServer;
1156
+ yield import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
1157
+ let server = new ServerClass(Object.assign({ loadAppComponent: () => __awaiter(void 0, void 0, void 0, function* () { return (yield import(path.join(process.cwd(), 'src', 'App'))).default; }) }, lincdConfig));
1158
+ //init the server
1159
+ console.log('Initializing server...');
1160
+ server.initOnly().then(() => {
1161
+ //process the backend method call
1162
+ console.log('Running method ' + method);
1163
+ //mock the request and response objects
1164
+ let request = {
1165
+ body: {},
1166
+ query: {},
1167
+ params: {},
1168
+ headers: {},
1169
+ method: 'POST',
1170
+ url: '/' + packageName + '/' + method,
1171
+ };
1172
+ let response = {
1173
+ status: (statusCode) => {
1174
+ console.log('Response status code:', statusCode);
1175
+ return response;
1176
+ },
1177
+ json: (data) => {
1178
+ console.log('Response data:', data);
1179
+ },
1180
+ send: (data) => {
1181
+ console.log('Response data:', data);
1182
+ },
1183
+ };
1184
+ //TODO; allow sending args
1185
+ server
1186
+ .callBackendMethod(packageName, method, [], request, response)
1187
+ .then(() => {
1188
+ console.log('Done');
1189
+ process.exit();
1190
+ });
1191
+ });
1192
+ }
1193
+ else {
1194
+ //reuse the existing running LincdServer instance.
1195
+ //make a HTTP call
1196
+ //'/call/:pkg/:method',
1197
+ fetch(process.env.SITE_ROOT + '/call/' + packageName + '/' + method, {
1198
+ method: 'POST',
1199
+ headers: {
1200
+ 'Content-Type': 'application/json',
1201
+ },
1202
+ })
1203
+ .then((response) => {
1204
+ if (!response.ok) {
1205
+ throw new Error('Network response was not ok');
1206
+ }
1207
+ return response.json();
1208
+ })
1209
+ .then((data) => {
1210
+ console.log('Response data:', data);
1211
+ process.exit();
1212
+ })
1213
+ .catch((error) => {
1214
+ var _a;
1215
+ if (error.code === 'ECONNREFUSED' ||
1216
+ ((_a = error.cause) === null || _a === void 0 ? void 0 : _a.code) === 'ECONNREFUSED') {
1217
+ console.error(chalk.red('Could not connect to the backend server. Is it running?'));
1218
+ console.error(`Make sure you ${chalk.magenta('run "yarn start" in a separate process')} before calling this method.`);
1219
+ }
1220
+ else {
1221
+ console.error('Error during backend call:', error);
1222
+ }
1223
+ process.exit(1);
1224
+ });
1225
+ }
1226
+ });
1227
+ export const startServer = (...args_8) => __awaiter(void 0, [...args_8], void 0, function* (initOnly = false, ServerClass = null) {
1020
1228
  yield ensureEnvironmentLoaded();
1021
- let lincdConfig = (yield import(path.join(process.cwd(), 'lincd.config.js'))).default;
1229
+ let lincdConfig = (yield import(path.join(process.cwd(), 'lincd.config.js')))
1230
+ .default;
1022
1231
  // function scssLoadcall(source, filename) {
1023
1232
  // return 'console.log("SCSS CALL: ' + filename + '");\n' + source;
1024
1233
  // process.exit();
@@ -1034,7 +1243,18 @@ export const startServer = (...args_1) => __awaiter(void 0, [...args_1], void 0,
1034
1243
  ServerClass = (yield import('lincd-server/shapes/LincdServer')).LincdServer;
1035
1244
  }
1036
1245
  yield import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
1037
- let server = new ServerClass(Object.assign({ loadAppComponent: () => __awaiter(void 0, void 0, void 0, function* () { return (yield import(path.join(process.cwd(), 'src', 'App'))).default; }) }, lincdConfig));
1246
+ let appPromise;
1247
+ if (process.env.NODE_ENV !== 'development') {
1248
+ appPromise = (yield import(path.join(process.cwd(), 'lib', 'App.js')))
1249
+ .default;
1250
+ }
1251
+ else {
1252
+ appPromise = (yield import(path.join(process.cwd(), 'src', 'App.tsx')))
1253
+ .default;
1254
+ }
1255
+ let server = new ServerClass(Object.assign({ loadAppComponent: () => __awaiter(void 0, void 0, void 0, function* () {
1256
+ return appPromise;
1257
+ }) }, lincdConfig));
1038
1258
  //Important to use slice, because when using clusers, child processes need to be able to read the same arguments
1039
1259
  let args = process.argv.slice(2);
1040
1260
  //if --initOnly is passed, only initialize the server and don't start it
@@ -1046,10 +1266,15 @@ export const startServer = (...args_1) => __awaiter(void 0, [...args_1], void 0,
1046
1266
  }
1047
1267
  });
1048
1268
  export const buildApp = () => __awaiter(void 0, void 0, void 0, function* () {
1269
+ yield buildFrontend();
1270
+ yield buildBackend();
1271
+ console.log(chalk.magenta(`✅ ${process.env.NODE_ENV} app build finished`));
1272
+ });
1273
+ export const buildFrontend = () => __awaiter(void 0, void 0, void 0, function* () {
1049
1274
  yield ensureEnvironmentLoaded();
1050
1275
  const webpackAppConfig = yield (yield import('./config-webpack-app.js')).getWebpackAppConfig();
1051
- console.log(chalk.magenta(`Building ${process.env.NODE_ENV} app bundles`));
1052
- return new Promise((resolve, reject) => {
1276
+ console.log(chalk.magenta(`🛠 Building ${process.env.NODE_ENV} frontend bundles`));
1277
+ yield new Promise((resolve, reject) => {
1053
1278
  webpack(webpackAppConfig, (err, stats) => __awaiter(void 0, void 0, void 0, function* () {
1054
1279
  if (err) {
1055
1280
  console.error(err.stack || err);
@@ -1085,13 +1310,16 @@ export const buildApp = () => __awaiter(void 0, void 0, void 0, function* () {
1085
1310
  }).then(() => __awaiter(void 0, void 0, void 0, function* () {
1086
1311
  // make sure environment is not development for storage config
1087
1312
  // and if we want to upload to storage, we need set S3_BUCKET_ENDPOINT
1088
- if (process.env.NODE_ENV === 'development' || !process.env.S3_BUCKET_ENDPOINT) {
1313
+ if (process.env.NODE_ENV === 'development' ||
1314
+ !process.env.S3_BUCKET_ENDPOINT) {
1089
1315
  console.warn('Upload build to storage skip in development environment or S3_BUCKET_ENDPOINT is not set');
1090
- process.exit();
1316
+ return;
1317
+ // process.exit();
1091
1318
  }
1092
1319
  if (process.env.APP_ENV) {
1093
1320
  console.warn('Not uploading to CDN for app builds');
1094
- process.exit();
1321
+ return;
1322
+ // process.exit();
1095
1323
  }
1096
1324
  // load the storage config
1097
1325
  const storageConfig = yield import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
@@ -1107,6 +1335,12 @@ export const buildApp = () => __awaiter(void 0, void 0, void 0, function* () {
1107
1335
  }
1108
1336
  // get all files in the web directory and then upload them to the storage
1109
1337
  const files = yield getFiles(pathDir);
1338
+ console.log(chalk.magenta(`🕊 Publishing ${files.length} public files to linked file storage`));
1339
+ const clearSpinner = ora({
1340
+ discardStdin: true,
1341
+ text: `Publishing ${files.length} public files`,
1342
+ }).start();
1343
+ let counter = 0;
1110
1344
  const uploads = files.map((filePath) => __awaiter(void 0, void 0, void 0, function* () {
1111
1345
  // read file content
1112
1346
  const fileContent = yield fs.promises.readFile(filePath);
@@ -1114,14 +1348,77 @@ export const buildApp = () => __awaiter(void 0, void 0, void 0, function* () {
1114
1348
  // example: /Users/username/project/www/index.html -> /project/www/index.html
1115
1349
  const pathname = filePath.replace(pathDir, `/${rootDirectory}`);
1116
1350
  // upload file to storage
1117
- return yield LinkedFileStorage.saveFile(pathname, fileContent);
1351
+ yield LinkedFileStorage.saveFile(pathname, fileContent)
1352
+ .then(() => {
1353
+ clearSpinner.text = `${counter++}/${files.length}: - Published ${pathname} `;
1354
+ })
1355
+ .catch(console.error);
1118
1356
  }));
1119
1357
  const urls = yield Promise.all(uploads);
1120
- console.log(`${urls.length} files uploaded to storage`);
1121
- process.exit();
1358
+ clearSpinner.succeed(`${urls.length} files uploaded to storage`);
1122
1359
  }
1123
1360
  }));
1124
1361
  });
1362
+ export const buildBackend = () => __awaiter(void 0, void 0, void 0, function* () {
1363
+ console.log(chalk.magenta(`🛠 Preparing ${process.env.NODE_ENV} backend`));
1364
+ //run tsc in the backend folder
1365
+ yield ensureEnvironmentLoaded();
1366
+ const sourceFolder = path.join(process.cwd(), 'src');
1367
+ const targetFolder = path.join(process.cwd(), 'lib');
1368
+ // Step 1: Clear lib folder
1369
+ const clearSpinner = ora({
1370
+ discardStdin: true,
1371
+ text: 'Clearing lib folder',
1372
+ }).start();
1373
+ try {
1374
+ if (fs.existsSync(targetFolder)) {
1375
+ yield fs.remove(targetFolder);
1376
+ }
1377
+ clearSpinner.succeed('Lib folder cleared');
1378
+ }
1379
+ catch (e) {
1380
+ console.error(e);
1381
+ clearSpinner.fail('Failed to clear lib folder');
1382
+ return;
1383
+ }
1384
+ // Step 2: Compile TS files
1385
+ const compileSpinner = ora({
1386
+ discardStdin: true,
1387
+ text: 'Compiling backend TS files',
1388
+ }).start();
1389
+ try {
1390
+ yield execPromise(`yarn exec tsc`);
1391
+ compileSpinner.succeed('Backend TS files compiled');
1392
+ }
1393
+ catch (e) {
1394
+ console.error(e);
1395
+ compileSpinner.fail('Failed to compile backend TS files');
1396
+ return;
1397
+ }
1398
+ // Step 3: Copy CSS files
1399
+ const copySpinner = ora({
1400
+ discardStdin: true,
1401
+ text: 'Copying CSS files',
1402
+ }).start();
1403
+ try {
1404
+ const cssFiles = yield getFiles(sourceFolder, '.css');
1405
+ yield Promise.all(cssFiles.map((file) => {
1406
+ const targetFile = file.replace(sourceFolder, targetFolder);
1407
+ //ensure the target folder exists
1408
+ const targetDir = path.dirname(targetFile);
1409
+ if (!fs.existsSync(targetDir)) {
1410
+ fs.mkdirSync(targetDir, { recursive: true });
1411
+ }
1412
+ return fs.copyFile(file, targetFile);
1413
+ }));
1414
+ copySpinner.succeed(`${cssFiles.length} CSS files copied`);
1415
+ }
1416
+ catch (e) {
1417
+ console.error(e);
1418
+ copySpinner.fail('Failed to copy CSS files');
1419
+ }
1420
+ return true;
1421
+ });
1125
1422
  export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function* () {
1126
1423
  yield ensureEnvironmentLoaded();
1127
1424
  // let packages = getLincdPackages();
@@ -1131,7 +1428,9 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
1131
1428
  const tsConfigCJS = path.join(dirname, '../../defaults/package', 'tsconfig-cjs.json');
1132
1429
  const tsConfigESM = path.join(dirname, '../../defaults/package', 'tsconfig-esm.json');
1133
1430
  const typesFile = path.join(dirname, '../../defaults/package/src', 'types.d.ts');
1134
- const tsConfigTemplate = yield fs.readJson(path.join(dirname, '../../defaults/package', 'tsconfig.json')).catch(err => {
1431
+ const tsConfigTemplate = yield fs
1432
+ .readJson(path.join(dirname, '../../defaults/package', 'tsconfig.json'))
1433
+ .catch((err) => {
1135
1434
  console.log(err);
1136
1435
  });
1137
1436
  runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
@@ -1246,7 +1545,9 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
1246
1545
  // }
1247
1546
  // })
1248
1547
  // });
1249
- files.filter(f => f.match(/\.(scss\.json|css\.json)$/)).forEach(cssJsonFile => {
1548
+ files
1549
+ .filter((f) => f.match(/\.(scss\.json|css\.json)$/))
1550
+ .forEach((cssJsonFile) => {
1250
1551
  console.log('Removing ' + cssJsonFile);
1251
1552
  fs.unlinkSync(cssJsonFile);
1252
1553
  });
@@ -1264,7 +1565,7 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
1264
1565
  // })
1265
1566
  // });
1266
1567
  });
1267
- export const createPackage = (name_1, uriBase_1, ...args_1) => __awaiter(void 0, [name_1, uriBase_1, ...args_1], void 0, function* (name, uriBase, basePath = process.cwd()) {
1568
+ export const createPackage = (name_5, uriBase_2, ...args_9) => __awaiter(void 0, [name_5, uriBase_2, ...args_9], void 0, function* (name, uriBase, basePath = process.cwd()) {
1268
1569
  if (!name) {
1269
1570
  console.warn('Please provide a name as the first argument');
1270
1571
  return;
@@ -1295,7 +1596,7 @@ export const createPackage = (name_1, uriBase_1, ...args_1) => __awaiter(void 0,
1295
1596
  //extra variable for clarity (will be same as 'name')
1296
1597
  setVariable('output_file_name', name);
1297
1598
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(cleanPackageName);
1298
- log('Creating new LINCD package \'' + name + '\'');
1599
+ log("Creating new LINCD package '" + name + "'");
1299
1600
  fs.copySync(path.join(getScriptDir(), '..', '..', 'defaults', 'package'), targetFolder);
1300
1601
  //replace variables in some of the copied files
1301
1602
  yield Promise.all([
@@ -1397,7 +1698,7 @@ export const register = function (registryURL) {
1397
1698
  console.warn(chalk.red('Warning:') + ' not found: ' + process.cwd() + '/package.json');
1398
1699
  }
1399
1700
  };
1400
- export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0, [target_1, target2_1, ...args_1], void 0, function* (target, target2, packagePath = process.cwd(), logResults = true) {
1701
+ export const buildPackage = (target_1, target2_1, ...args_10) => __awaiter(void 0, [target_1, target2_1, ...args_10], void 0, function* (target, target2, packagePath = process.cwd(), logResults = true) {
1401
1702
  let spinner;
1402
1703
  if (logResults) {
1403
1704
  //TODO: replace with listr so we can show multiple processes at once
@@ -1416,7 +1717,7 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
1416
1717
  spinner.text = step.name;
1417
1718
  spinner.start();
1418
1719
  }
1419
- return step.apply().then(stepResult => {
1720
+ return step.apply().then((stepResult) => {
1420
1721
  //if a build step returns a string,
1421
1722
  //a warning is shown but the build is still successful with warnings
1422
1723
  if (typeof stepResult === 'string') {
@@ -1445,6 +1746,10 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
1445
1746
  });
1446
1747
  });
1447
1748
  };
1749
+ buildStep({
1750
+ name: 'Checking imports',
1751
+ apply: () => checkImports(packagePath + '/src'),
1752
+ });
1448
1753
  buildStep({
1449
1754
  name: 'Compiling ESM',
1450
1755
  apply: () => __awaiter(void 0, void 0, void 0, function* () {
@@ -1461,26 +1766,29 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
1461
1766
  name: 'Copying files to lib folder',
1462
1767
  apply: () => __awaiter(void 0, void 0, void 0, function* () {
1463
1768
  const files = yield glob(packagePath + '/src/**/*.{json,d.ts,css,scss}');
1464
- return Promise.all(files.map(((file) => __awaiter(void 0, void 0, void 0, function* () {
1769
+ return Promise.all(files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
1465
1770
  try {
1466
- yield fs.copy(file, packagePath + '/lib/esm/' + file.replace(packagePath + '/src/', ''));
1467
- yield fs.copy(file, packagePath + '/lib/cjs/' + file.replace(packagePath + '/src/', ''));
1771
+ yield fs.copy(file, packagePath +
1772
+ '/lib/esm/' +
1773
+ file.replace(packagePath + '/src/', ''));
1774
+ yield fs.copy(file, packagePath +
1775
+ '/lib/cjs/' +
1776
+ file.replace(packagePath + '/src/', ''));
1468
1777
  return true;
1469
1778
  }
1470
1779
  catch (err) {
1471
1780
  console.warn(err);
1472
1781
  return false;
1473
1782
  }
1474
- ;
1475
- })))).then((allResults) => {
1476
- return allResults.every(r => r === true);
1783
+ }))).then((allResults) => {
1784
+ return allResults.every((r) => r === true);
1477
1785
  });
1478
1786
  }),
1479
1787
  });
1480
1788
  buildStep({
1481
1789
  name: 'Dual package support',
1482
1790
  apply: () => {
1483
- return execPromise('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then(res => {
1791
+ return execPromise('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
1484
1792
  return res === '';
1485
1793
  });
1486
1794
  },
@@ -1491,16 +1799,16 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
1491
1799
  return removeOldFiles(packagePath);
1492
1800
  }),
1493
1801
  });
1494
- buildStep({
1495
- name: 'Checking imports',
1496
- apply: () => checkImports(packagePath),
1497
- });
1498
1802
  buildStep({
1499
1803
  name: 'Checking dependencies',
1500
1804
  apply: () => depCheck(packagePath),
1501
1805
  });
1502
- let success = yield buildProcess.catch(err => {
1503
- 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);
1806
+ let success = yield buildProcess.catch((err) => {
1807
+ let msg = typeof err === 'string' || err instanceof Error
1808
+ ? err.toString()
1809
+ : err.error && !err.error.toString().includes('Command failed:')
1810
+ ? err.error
1811
+ : err.stdout + '\n' + err.stderr;
1504
1812
  if (logResults) {
1505
1813
  spinner.stopAndPersist({
1506
1814
  symbol: chalk.red('✖'),
@@ -1518,19 +1826,23 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
1518
1826
  if (logResults) {
1519
1827
  spinner.stopAndPersist({
1520
1828
  symbol: chalk.greenBright('✔'),
1521
- text: success === true ? 'Build successful' : 'Build successful with warnings',
1829
+ text: success === true
1830
+ ? 'Build successful'
1831
+ : 'Build successful with warnings',
1522
1832
  });
1523
1833
  }
1524
1834
  }
1525
1835
  else {
1526
- spinner.stopAndPersist({
1527
- symbol: chalk.red('✖'),
1528
- text: 'Build failed',
1529
- });
1836
+ if (logResults) {
1837
+ spinner.stopAndPersist({
1838
+ symbol: chalk.red(''),
1839
+ text: 'Build failed',
1840
+ });
1841
+ }
1530
1842
  }
1531
1843
  return success;
1532
1844
  });
1533
- export const compilePackage = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
1845
+ export const compilePackage = (...args_11) => __awaiter(void 0, [...args_11], void 0, function* (packagePath = process.cwd()) {
1534
1846
  //echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
1535
1847
  // let cjsConfig = fs.existsSync(path.join(packagePath,'tsconfig-cjs.json'));
1536
1848
  // let esmConfig = fs.existsSync(path.join(packagePath,'tsconfig-esm.json'));
@@ -1556,20 +1868,22 @@ export const compilePackage = (...args_1) => __awaiter(void 0, [...args_1], void
1556
1868
  yield compilePackageESM(packagePath);
1557
1869
  yield compilePackageCJS(packagePath);
1558
1870
  });
1559
- export const compilePackageESM = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
1871
+ export const compilePackageESM = (...args_12) => __awaiter(void 0, [...args_12], void 0, function* (packagePath = process.cwd()) {
1560
1872
  //echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
1561
1873
  let compileCommand = `yarn exec tsc -p tsconfig-esm.json`;
1562
- return execPromise(compileCommand, false, false, { cwd: packagePath }).then(res => {
1874
+ return execPromise(compileCommand, false, false, { cwd: packagePath }).then((res) => {
1563
1875
  return res === '';
1564
1876
  });
1565
1877
  });
1566
- export const compilePackageCJS = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
1878
+ export const compilePackageCJS = (...args_13) => __awaiter(void 0, [...args_13], void 0, function* (packagePath = process.cwd()) {
1567
1879
  let compileCommand = `yarn exec tsc -p tsconfig-cjs.json`;
1568
- return execPromise(compileCommand, false, false, { cwd: packagePath }).then(res => {
1880
+ return execPromise(compileCommand, false, false, { cwd: packagePath })
1881
+ .then((res) => {
1569
1882
  return res === '';
1570
- }).catch(err => {
1883
+ })
1884
+ .catch((err) => {
1571
1885
  return {
1572
- error: err.stdout
1886
+ error: err.stdout,
1573
1887
  };
1574
1888
  });
1575
1889
  });
@@ -1684,7 +1998,7 @@ export var publishUpdated = function (test = false) {
1684
1998
  }))
1685
1999
  .catch(({ error, stdout, stderr }) => {
1686
2000
  if (error) {
1687
- console.log(error.message);
2001
+ console.error(error.message);
1688
2002
  }
1689
2003
  if (stdout) {
1690
2004
  console.log(stderr);
@@ -1762,7 +2076,7 @@ export var publishPackage = function (pkg, test, info, publishVersion) {
1762
2076
  .then((res) => {
1763
2077
  if (res.indexOf('Aborted due to warnings') !== -1 ||
1764
2078
  res.indexOf('Could not publish') !== -1 ||
1765
- res.indexOf('Couldn\'t publish') !== -1) {
2079
+ res.indexOf("Couldn't publish") !== -1) {
1766
2080
  console.log(res);
1767
2081
  return chalk.red(pkg.packageName + ' failed\n');
1768
2082
  }
@@ -1775,7 +2089,7 @@ export var publishPackage = function (pkg, test, info, publishVersion) {
1775
2089
  chalk.magenta(publishVersion));
1776
2090
  })
1777
2091
  .catch(({ error, stdout, stderr }) => {
1778
- console.log(chalk.red('Failed to publish: ' + error.message));
2092
+ logError('Failed to publish: ' + error.message);
1779
2093
  return chalk.red(pkg.packageName + ' failed to publish');
1780
2094
  });
1781
2095
  });
@@ -1792,16 +2106,26 @@ export var buildUpdated = function (back_1, target_1, target2_1) {
1792
2106
  // let packages = getLocalLincdModules();
1793
2107
  let packages = getLocalLincdPackageMap();
1794
2108
  // console.log(packages);
1795
- let jsonldPkgUpdated = yield needsRebuilding(packages.get('lincd-jsonld'), useGitForLastModified);
2109
+ // let jsonldPkgUpdated = await needsRebuilding(
2110
+ // packages.get('lincd-jsonld'),
2111
+ // useGitForLastModified,
2112
+ // );
1796
2113
  // let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
1797
2114
  //if either cli or jsonldPkg needs to be rebuilt
1798
2115
  // if (jsonldPkgUpdated || cliPkgUpdated) {
1799
- if (jsonldPkgUpdated) {
1800
- yield execPromise('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
1801
- cwd: packages.get('lincd-jsonld').path,
1802
- }, true);
1803
- // await execPromise('yarn build-core', false, false, {}, true);
1804
- }
2116
+ // if (jsonldPkgUpdated)
2117
+ // {
2118
+ // await execPromise(
2119
+ // 'yarn exec tsc && echo "compiled lincd-jsonld"',
2120
+ // false,
2121
+ // false,
2122
+ // {
2123
+ // cwd: packages.get('lincd-jsonld').path,
2124
+ // },
2125
+ // true,
2126
+ // );
2127
+ // // await execPromise('yarn build-core', false, false, {}, true);
2128
+ // }
1805
2129
  let rebuildAllModules = false;
1806
2130
  // if (cliPkgUpdated) {
1807
2131
  // rebuildAllModules = true;
@@ -1815,9 +2139,10 @@ export var buildUpdated = function (back_1, target_1, target2_1) {
1815
2139
  return (pkg) => __awaiter(this, void 0, void 0, function* () {
1816
2140
  // debugInfo('# Checking package ' + pkg.packageName);
1817
2141
  let needRebuild = yield needsRebuilding(pkg, useGitForLastModified);
1818
- if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
1819
- needRebuild = true;
1820
- }
2142
+ // if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated)
2143
+ // {
2144
+ // needRebuild = true;
2145
+ // }
1821
2146
  if (needRebuild || rebuildAllModules) {
1822
2147
  //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1823
2148
  // log(packageName+' modified since last commit on '+now.toString());
@@ -1826,42 +2151,31 @@ export var buildUpdated = function (back_1, target_1, target2_1) {
1826
2151
  return chalk.blue(pkg.packageName + ' should be build');
1827
2152
  }
1828
2153
  log('Building ' + pkg.packageName);
1829
- // return buildPackage(null,null,pkg.path)
1830
- return execPromise('cd ' +
1831
- pkg.path +
1832
- ' && yarn build' +
1833
- (target ? ' ' + target : '') +
1834
- (target2 ? ' ' + target2 : ''))
2154
+ return buildPackage(null, null, path.join(process.cwd(), pkg.path), false)
1835
2155
  .then((res) => {
1836
- if (res === '') {
2156
+ //empty string or true is success
2157
+ //false is success with warnings
2158
+ //any other string is the build error text
2159
+ //undefined result means it failed
2160
+ if (typeof res === 'undefined') {
2161
+ logError('Failed to build ' + pkg.packageName);
2162
+ process.exit(1);
2163
+ }
2164
+ else {
1837
2165
  debugInfo(chalk.green(pkg.packageName + ' successfully built'));
1838
2166
  return chalk.green(pkg.packageName + ' built');
1839
2167
  }
1840
- else if (typeof res === 'string') {
1841
- warn(chalk.red('Failed to build ' + pkg.packageName));
1842
- // console.log(res);
1843
- process.exit(1);
1844
- }
1845
2168
  })
1846
- .catch(({ error, stdout, stderr }) => {
1847
- warn(chalk.red('Failed to build ' + pkg.packageName));
1848
- console.log(stdout);
2169
+ .catch((err) => {
2170
+ logError('Failed to build ' + pkg.packageName);
2171
+ console.error(err);
1849
2172
  process.exit(1);
1850
- // let dependentModules = getDependentPackages(dependencies, pkg);
1851
- // if (dependentModules.length > 0) {
1852
- // // printBuildResults(failedModules, done);
1853
- // warn(chalk.red(pkg.packageName + ' build failed'));
1854
- // warn(
1855
- // 'Stopping build-updated process because ' +
1856
- // dependentModules.length +
1857
- // ' other packages depend on this package.\n',
1858
- // ); //"+dependentModules.map(d => d.packageName).join(", ")));
1859
- // }
1860
2173
  });
1861
2174
  }
1862
2175
  });
1863
- }, (results) => {
2176
+ }, (dependencies, results) => {
1864
2177
  if (results.length) {
2178
+ log(chalk.green('Changed packages have been rebuilt'));
1865
2179
  log('Summary:');
1866
2180
  log(results.join('\n'));
1867
2181
  }
@@ -1901,16 +2215,15 @@ export var executeCommandForEachPackage = function (packages, command, filterMet
1901
2215
  }
1902
2216
  let seen = false;
1903
2217
  packages = packages.filter((pkg) => {
1904
- if (!seen &&
1905
- pkg.packageName.includes(startFrom)) {
2218
+ if (!seen && pkg.packageName.includes(startFrom)) {
1906
2219
  seen = true;
1907
2220
  }
1908
2221
  return seen;
1909
2222
  });
1910
2223
  }
1911
- log('Executing \'' +
2224
+ log("Executing '" +
1912
2225
  chalk.blueBright(command) +
1913
- '\' on packages ' +
2226
+ "' on packages " +
1914
2227
  chalk.magenta(packages.map((m) => m.packageName).join(', ')));
1915
2228
  var p = Promise.resolve(true);
1916
2229
  packages.forEach((pkg) => {
@@ -1993,20 +2306,19 @@ export var executeCommandForPackage = function (packageName, command) {
1993
2306
  let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
1994
2307
  modDetails.packageName.indexOf(packageName) !== -1);
1995
2308
  if (packageDetails) {
1996
- log('Executing \'cd ' +
2309
+ log("Executing 'cd " +
1997
2310
  packageDetails.path +
1998
- ' && yarn exec lincd' +
2311
+ ' && yarn lincd' +
1999
2312
  (command ? ' ' + command : '') +
2000
- '\'');
2001
- //TODO : replace with spawn("path to executable", ["params"], {stdio: "inherit"});
2002
- // maybe make spawnPromise that returns a promise
2003
- return execp('cd ' +
2004
- packageDetails.path +
2005
- ' && yarn exec lincd' +
2006
- (command ? ' ' + command : ''));
2313
+ "'");
2314
+ spawnChild(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', // Windows quirk
2315
+ ['lincd', command || null], {
2316
+ cwd: packageDetails.path,
2317
+ stdio: 'inherit',
2318
+ });
2007
2319
  }
2008
2320
  else {
2009
- warn('Could not find a pkg who\'s name (partially) matched ' +
2321
+ warn("Could not find a pkg who's name (partially) matched " +
2010
2322
  chalk.cyan(packageName));
2011
2323
  }
2012
2324
  };