lincd-cli 0.2.24 → 0.2.26

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.
@@ -1,4 +1,4 @@
1
- import {initFrontend} from 'lincd-server/lib/utils/Frontend';
1
+ import {initFrontend} from 'lincd-server-utils/lib/utils/Frontend';
2
2
 
3
3
  window['$RefreshReg$'] = () => {};
4
4
  window['$RefreshSig$'] = () => () => {};
@@ -45,6 +45,7 @@
45
45
  "lincd": "^0.5",
46
46
  "lincd-jsonld": "^0.1.5",
47
47
  "lincd-server": "^0.1.19",
48
+ "lincd-server-utils": "^0.1",
48
49
  "react": "^18.2",
49
50
  "react-dom": "^18.2",
50
51
  "react-error-boundary": "^3.1.3",
@@ -56,6 +57,7 @@
56
57
  "@types/react-dom": "^18.0.6",
57
58
  "env-cmd": "^10.1.0",
58
59
  "lincd-cli": "^0.2",
59
- "nodemon": "^2.0.6"
60
+ "nodemon": "^2.0.6",
61
+ "pm2": "^5.3.0"
60
62
  }
61
63
  }
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ apps: [
3
+ {
4
+ name: '${hyphen_name}',
5
+ script: 'yarn run server:prod',
6
+ time: true,
7
+ log_date_format: 'DD-MM-YYYY HH:mm Z',
8
+ out_file: "./data/out.log",
9
+ error_file: "./data/error.log",
10
+ }
11
+ ],
12
+ };
@@ -134,7 +134,7 @@ var createApp = function (name, basePath) {
134
134
  // fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
135
135
  log("Creating new LINCD application '" + name + "'");
136
136
  //replace variables in some copied files
137
- replaceVariablesInFilesWithRoot(targetFolder, 'package.json', 'frontend/src/App.tsx', 'frontend/src/package.ts', 'frontend/src/App.scss.json', '.vscode/launch.json', 'frontend/src/components/Spinner.scss.json');
137
+ replaceVariablesInFilesWithRoot(targetFolder, 'package.json', 'pm2.config.js', 'frontend/src/App.tsx', 'frontend/src/package.ts', 'frontend/src/App.scss.json', '.vscode/launch.json', 'frontend/src/components/Spinner.scss.json');
138
138
  return [4 /*yield*/, hasYarnInstalled()];
139
139
  case 1:
140
140
  hasYarn = _b.sent();
@@ -183,11 +183,11 @@ function debugInfo() {
183
183
  // console.log(gruntConfig);
184
184
  // process.exit();
185
185
  // }
186
- if (gruntConfig && gruntConfig.analyse === true) {
187
- messages.forEach(function (message) {
188
- console.log(chalk_1["default"].cyan('Info: ') + message);
189
- });
190
- }
186
+ // if (gruntConfig && gruntConfig.analyse === true) {
187
+ messages.forEach(function (message) {
188
+ console.log(chalk_1["default"].cyan('Info: ') + message);
189
+ });
190
+ // }
191
191
  }
192
192
  function warn() {
193
193
  var messages = [];
@@ -323,12 +323,44 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
323
323
  })) {
324
324
  stack.push(pkg);
325
325
  }
326
- // else if(!done.has(package))
327
- // {
328
- // console.log(chalk.red(package+' not yet'))
329
- // console.log('UNMET DEPS: '+deps.filter(dependency => !done.has(dependency)).join(" "))
330
- // }
331
326
  });
327
+ if (stack.length <= 0 && done.size < lincdPackages.size) {
328
+ console.log(chalk_1["default"].red('Only ' + done.size + ' out of ' + lincdPackages.size + ' packages have been built'));
329
+ console.log('ALL remaining packages have dependencies that have not been met. This may point to ' + chalk_1["default"].red('circular dependencies.'));
330
+ console.log('Already built: ' + Array.from(done).map(function (p) { return chalk_1["default"].green(p.packageName); }).join(', '));
331
+ console.log(chalk_1["default"].blue('\nTo solve this issue') + ': find the circular dependencies below and fix the dependencies:\n\n');
332
+ //TODO: actually find and name the packages that have circular dependencies
333
+ // let circular = [];
334
+ // lincdPackages.forEach((pkg) => {
335
+ // if (!done.has(pkg))
336
+ // {
337
+ // let deps = dependencies.get(pkg);
338
+ // if (deps.some(dependency => {
339
+ // //return true if this dependency (indirectly) depends on the package whos' dependency it is
340
+ // return hasDependency(dependency,pkg,dependencies)
341
+ // }))
342
+ // {
343
+ // circular.push(pkg);
344
+ // }
345
+ // process.exit();
346
+ // }
347
+ // });
348
+ lincdPackages.forEach(function (pkg) {
349
+ var deps = dependencies.get(pkg);
350
+ if (!done.has(pkg)) {
351
+ console.log(chalk_1["default"].red(pkg.packageName) + ' has not been built yet. Unbuilt dependencies:\n' + deps.filter(function (dependency) {
352
+ return !Array.from(done).some(function (p) {
353
+ // console.log(p.packageName,dependency.packageName,p===dependency)
354
+ return p === dependency;
355
+ });
356
+ }).map(function (p) { return chalk_1["default"].red('\t- ' + ((p === null || p === void 0 ? void 0 : p.packageName) ? p.packageName : p.toString()) + '\n'); }).join(" "));
357
+ // console.log(chalk.red(pkg.packageName)+' has not been built yet. Built dependencies:\n' + deps.filter(dependency => {
358
+ // return Array.from(done).some(p => p.packageName === pkg.packageName)
359
+ // }).map(p => chalk.green('\t- '+p.packageName+'\n')).join(" "))
360
+ // console.log(chalk.red(pkg.packageName)+' has not been built yet. Built dependencies:\n' + deps.filter(dependency => done.has(pkg)).map(p => chalk.green('\t- '+p.packageName+'\n')).join(" "))
361
+ }
362
+ });
363
+ }
332
364
  //if more to be built, iterate
333
365
  if (stack.length > 0) {
334
366
  return [2 /*return*/, runStack(stack)];
@@ -343,6 +375,23 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
343
375
  //starts the process
344
376
  runStack(startStack);
345
377
  }
378
+ function hasDependency(pkg, childPkg, dependencies, depth) {
379
+ if (depth === void 0) { depth = 1; }
380
+ console.log("Does " + pkg.packageName + " have dep " + childPkg.packageName + " ?");
381
+ var deps = dependencies.get(pkg);
382
+ if (deps.some(function (dependency) {
383
+ console.log(dependency.packageName, childPkg.packageName, dependency === childPkg);
384
+ if (depth === 2)
385
+ return false;
386
+ // return dependency === childPkg;
387
+ return dependency === childPkg || hasDependency(dependency, childPkg, dependencies, depth++);
388
+ })) {
389
+ console.log("##YES");
390
+ return true;
391
+ }
392
+ console.log("going up");
393
+ return false;
394
+ }
346
395
  function buildAll(target, target2, target3) {
347
396
  var _this = this;
348
397
  console.log('Building all LINCD packages of this repository in order of dependencies');
@@ -1012,6 +1061,7 @@ var buildMetadata = function () { return __awaiter(void 0, void 0, void 0, funct
1012
1061
  _c.sent(); //{recursive:true} but not needed with fs-extra
1013
1062
  _loop_1 = function (packageCodeName, packagePath, lincdPackagePath, isAppPackage) {
1014
1063
  var errors = false;
1064
+ //TODO: check if this resolves, if not, skip it (for initial setup)
1015
1065
  Promise.resolve().then(function () { return __importStar(require('lincd-modules/lib/scripts/package-metadata.js')); }).then(function (script) { return __awaiter(void 0, void 0, void 0, function () {
1016
1066
  return __generator(this, function (_a) {
1017
1067
  switch (_a.label) {
@@ -1222,7 +1272,7 @@ var publishUpdated = function (test) {
1222
1272
  p = p
1223
1273
  .then(function (previousResult) {
1224
1274
  // progressUpdate(packagesLeft-- + ' packages left. Now checking ' + pckg.packageName);
1225
- // log('# Checking package ' + pckg.packageName);
1275
+ log('# Checking package ' + pckg.packageName);
1226
1276
  // log('# Requesting ' + 'yarn info '+pkg.packageName+' --json');
1227
1277
  // return execPromise('yarn info '+pkg.packageName+' --json').then((output:string) => {
1228
1278
  // console.log("Will be requesting npm view from this current working directory:\n"+process.cwd());
@@ -1236,13 +1286,17 @@ var publishUpdated = function (test) {
1236
1286
  return chalk_1["default"].gray(pckg.packageName + ' is private');
1237
1287
  // return previousResult + ' ' + chalk.gray(pckg.packageName + ' is private\n');
1238
1288
  }
1289
+ console.log("testing npm");
1239
1290
  return (0, utils_1.execPromise)('npm info ' + pckg.packageName + ' --json')
1240
1291
  .then(function (output) { return __awaiter(_this, void 0, void 0, function () {
1241
- var info, lastPublish, lastPublishDate, lastCommitInfo, err_1;
1292
+ var info, lastPublish, lastPublishDate, lastCommitInfo, changedFiles, numberOfFilesChanges, err_1;
1242
1293
  return __generator(this, function (_a) {
1243
1294
  switch (_a.label) {
1244
1295
  case 0:
1245
- _a.trys.push([0, 3, , 4]);
1296
+ console.log("testing npm done");
1297
+ _a.label = 1;
1298
+ case 1:
1299
+ _a.trys.push([1, 4, , 5]);
1246
1300
  if (output == '' || output.includes('E404')) {
1247
1301
  debugInfo('Empty or 404 response from `npm info`. This package was probably not published before');
1248
1302
  // throw new Error('Empty response from `yarn info`. This pkg was probably not published before');
@@ -1254,14 +1308,14 @@ var publishUpdated = function (test) {
1254
1308
  else {
1255
1309
  info = JSON.parse(output);
1256
1310
  }
1257
- if (!info) return [3 /*break*/, 2];
1311
+ if (!info) return [3 /*break*/, 3];
1258
1312
  lastPublish = void 0;
1259
1313
  //yarn:
1260
1314
  // let lastPublish = info.data.time[info.data.version];
1261
1315
  lastPublish = info.time[info.version];
1262
1316
  lastPublishDate = new Date(lastPublish);
1263
1317
  return [4 /*yield*/, getLastCommitTime(pckg.path)];
1264
- case 1:
1318
+ case 2:
1265
1319
  lastCommitInfo = _a.sent();
1266
1320
  if (!lastCommitInfo) {
1267
1321
  shouldPublish = false;
@@ -1273,6 +1327,12 @@ var publishUpdated = function (test) {
1273
1327
  //NOTE: removed lastModified, because switching branches will say that the file was modified and cause everything to publish
1274
1328
  //SO: now you NEED TO commit before it picks up that you should publish
1275
1329
  shouldPublish = lastPublishDate.getTime() < lastCommitInfo.date.getTime();
1330
+ changedFiles = lastCommitInfo.changes.split("\n").filter(function (line) { return line.includes("|"); });
1331
+ numberOfFilesChanges = changedFiles.length;
1332
+ // console.log("CHECK "+lastCommitInfo.changes.includes("package.json")+" - "+numberOfFilesChanges)
1333
+ if (shouldPublish && lastCommitInfo.changes.includes("package.json") && numberOfFilesChanges === 1) {
1334
+ shouldPublish = false;
1335
+ }
1276
1336
  if (shouldPublish) {
1277
1337
  log(chalk_1["default"].magenta(pckg.packageName) + ' should be published because:');
1278
1338
  log(lastPublishDate.toDateString() +
@@ -1284,9 +1344,9 @@ var publishUpdated = function (test) {
1284
1344
  log(lastCommitInfo.changes);
1285
1345
  }
1286
1346
  }
1287
- _a.label = 2;
1288
- case 2: return [3 /*break*/, 4];
1289
- case 3:
1347
+ _a.label = 3;
1348
+ case 3: return [3 /*break*/, 5];
1349
+ case 4:
1290
1350
  err_1 = _a.sent();
1291
1351
  // var stats = fs.statSync(path.join(packageDirectory));
1292
1352
  // var files = fs.readdirSync(path.join(packageDirectory,'src'));
@@ -1294,11 +1354,11 @@ var publishUpdated = function (test) {
1294
1354
  console.warn('Returned JSON from npm: ' + output);
1295
1355
  // return previousResult + ' ' + chalk.red(pckg.packageName + ' failed: ' + err.message + '\n');
1296
1356
  return [2 /*return*/, chalk_1["default"].red(pckg.packageName + ' failed: ' + err_1.message)];
1297
- case 4:
1357
+ case 5:
1298
1358
  if (shouldPublish) {
1299
1359
  return [2 /*return*/, (0, exports.publishPackage)(pckg, test, info, version)];
1300
1360
  }
1301
- return [2 /*return*/, chalk_1["default"].green(pckg.packageName + ' latest version is up to date')];
1361
+ return [2 /*return*/, chalk_1["default"].blue(pckg.packageName) + ' latest version is up to date'];
1302
1362
  }
1303
1363
  });
1304
1364
  }); })["catch"](function (_a) {
@@ -1404,8 +1464,8 @@ var publishPackage = function (pkg, test, info, publishVersion) {
1404
1464
  console.log(res);
1405
1465
  return chalk_1["default"].red(pkg.packageName + ' failed\n');
1406
1466
  }
1407
- console.log(chalk_1["default"].green('Successfully published ' + pkg.path + ' ' + publishVersion));
1408
- return chalk_1["default"].green(pkg.packageName + ' published ' + publishVersion);
1467
+ console.log('Successfully published ' + chalk_1["default"].green(pkg.path) + ' ' + chalk_1["default"].magenta(publishVersion));
1468
+ return chalk_1["default"].green(pkg.packageName) + ' published ' + chalk_1["default"].magenta(publishVersion);
1409
1469
  })["catch"](function (_a) {
1410
1470
  var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
1411
1471
  console.log(chalk_1["default"].red('Failed to publish: ' + error.message));
@@ -1437,13 +1497,12 @@ var buildUpdated = function (back, target, target2, test) {
1437
1497
  rebuildAllModules = false;
1438
1498
  packagesLeft = packages.size;
1439
1499
  runOnPackagesGroupedByDependencies(packages, function (packageGroup, dependencies) {
1440
- // console.log('Now checking: ' + chalk.blue(packageGroup.map((i) => i.packageName)));
1441
- // console.log((packagesLeft) + " packages left.");
1500
+ debugInfo('Now checking: ' + chalk_1["default"].blue(packageGroup.map(function (i) { return i.packageName; })));
1501
+ debugInfo((packagesLeft) + " packages left.");
1442
1502
  packagesLeft = packagesLeft - packageGroup.length;
1443
1503
  return function (pkg) { return __awaiter(_this, void 0, void 0, function () {
1444
1504
  var needRebuild;
1445
1505
  return __generator(this, function (_a) {
1446
- debugInfo('# Checking package ' + pkg.packageName);
1447
1506
  needRebuild = needsRebuilding(pkg, true);
1448
1507
  if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
1449
1508
  needRebuild = true;
@@ -1495,12 +1554,12 @@ var buildUpdated = function (back, target, target2, test) {
1495
1554
  });
1496
1555
  };
1497
1556
  exports.buildUpdated = buildUpdated;
1498
- var needsRebuilding = function (pkg, logDetailsIfTrue) {
1499
- if (logDetailsIfTrue === void 0) { logDetailsIfTrue = false; }
1557
+ var needsRebuilding = function (pkg, log) {
1558
+ if (log === void 0) { log = false; }
1500
1559
  var lastModifiedSource = getLastModifiedSourceTime(pkg.path);
1501
1560
  var lastModifiedBundle = getLastBuildTime(pkg.path);
1502
1561
  var result = lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime;
1503
- if (logDetailsIfTrue) {
1562
+ if (log) {
1504
1563
  debugInfo(chalk_1["default"].cyan('Last modified source: ' +
1505
1564
  lastModifiedSource.lastModifiedName +
1506
1565
  ' on ' +
@@ -1560,23 +1619,39 @@ exports.executeCommandForEachPackage = executeCommandForEachPackage;
1560
1619
  var addCapacitor = function (basePath) {
1561
1620
  if (basePath === void 0) { basePath = process.cwd(); }
1562
1621
  return __awaiter(this, void 0, void 0, function () {
1563
- var targetFolder, pack;
1622
+ var targetFolder, envCmdPath, envCmd, pack;
1564
1623
  return __generator(this, function (_a) {
1565
1624
  switch (_a.label) {
1566
1625
  case 0:
1567
1626
  targetFolder = ensureFolderExists(basePath);
1568
1627
  log('Adding capacitor');
1569
1628
  fs_extra_1["default"].copySync(path_1["default"].join(__dirname, '..', 'defaults', 'app-static'), targetFolder);
1629
+ envCmdPath = path_1["default"].resolve(basePath, '.env-cmdrc.json');
1630
+ envCmd = JSON.parse(fs_extra_1["default"].readFileSync(envCmdPath, { encoding: 'utf8' }));
1631
+ envCmd['static-dev'] = {
1632
+ "NODE_ENV": "production",
1633
+ "SITE_ROOT": "http://localhost:4000",
1634
+ "DATA_ROOT": "http://localhost:4000/data",
1635
+ "OUTPUT_PATH": "./frontend/web/assets",
1636
+ "ASSET_PATH": "./assets/",
1637
+ "ENTRY_PATH": "./frontend/src/index-static.tsx"
1638
+ };
1639
+ fs_extra_1["default"].writeFile(envCmdPath, JSON.stringify(envCmd, null, 2));
1640
+ log('Edited .env-cmdrc.json');
1570
1641
  pack = (0, utils_1.getPackageJSON)(basePath);
1571
1642
  pack.scripts['build-static'] = 'env-cmd -e static-dev node frontend/scripts/build.js';
1572
- fs_extra_1["default"].writeFile(path_1["default"].resolve(basePath, 'package.json'), JSON.stringify(pack));
1573
- return [4 /*yield*/, (0, utils_1.execPromise)("yarn add -W -D @capacitor/cli", false, false, null, true)];
1643
+ pack.scripts['cap:android'] = 'yarn cap open android';
1644
+ pack.scripts['cap:sync'] = 'yarn cap sync';
1645
+ fs_extra_1["default"].writeFile(path_1["default"].resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
1646
+ log('Added new run script to package.json');
1647
+ return [4 /*yield*/, (0, utils_1.execPromise)("yarn add -D @capacitor/cli", true, false, null, true)];
1574
1648
  case 1:
1575
1649
  _a.sent();
1576
- return [4 /*yield*/, (0, utils_1.execPromise)("yarn add -W @capacitor/android @capacitor/core @capacitor/geolocation @capacitor/ios @capacitor/push-notifications", false, false, null, true)];
1650
+ return [4 /*yield*/, (0, utils_1.execPromise)("yarn add @capacitor/android @capacitor/core @capacitor/geolocation @capacitor/ios @capacitor/push-notifications", false, false, null, true)];
1577
1651
  case 2:
1578
1652
  _a.sent();
1579
- log('Done! Run `yarn build-static` to generate static bundles. Then `yarn cap add android` or `yarn cap add ios`');
1653
+ log("Done! Run ".concat(chalk_1["default"].magenta('yarn build-static'), " to generate static bundles. Then run ").concat(chalk_1["default"].magenta('yarn cap add android'), " and/or ").concat(chalk_1["default"].magenta('yarn cap add ios'), "')"));
1654
+ log("Also see the app icons in /frontend/web");
1580
1655
  return [2 /*return*/];
1581
1656
  }
1582
1657
  });
package/lib/cli.js CHANGED
@@ -132,7 +132,7 @@ program
132
132
  .argument('<name>', 'the name of the package. Can be a part of the name.')
133
133
  .argument('[command]', 'the lincd command you want to execute. Like dev or build')
134
134
  .argument('[args...]', 'the additional arguments of that command');
135
- program.command('add-capacitor').action(function () {
135
+ program.command('enable-capacitor').action(function () {
136
136
  (0, cli_methods_1.addCapacitor)();
137
137
  });
138
138
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lincd-cli",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "description": "Command line tools for the lincd.js library",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -59,8 +59,7 @@
59
59
  "grunt-webpack": "^5.0.0",
60
60
  "license-info-webpack-plugin": "^3.0.0",
61
61
  "lincd": "^0.5",
62
- "lincd-app": "^0.1",
63
- "lincd-jsonld": "^0.1.13",
62
+ "lincd-jsonld": "^0.1.20",
64
63
  "lincd-modules": "^0.1",
65
64
  "load-grunt-tasks": "^5.1.0",
66
65
  "mini-css-extract-plugin": "^2.7.5",
@@ -1,10 +0,0 @@
1
- {
2
- "static-dev": {
3
- "NODE_ENV": "production",
4
- "SITE_ROOT": "http://localhost:4000",
5
- "DATA_ROOT": "https://coolbock.lincd.org/data",
6
- "OUTPUT_PATH" : "./frontend/web/assets",
7
- "ASSET_PATH" : "./assets/",
8
- "ENTRY_PATH" : "./frontend/src/index-static.tsx"
9
- }
10
- }