lincd-cli 0.1.23 → 0.1.24

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.
@@ -4,9 +4,9 @@
4
4
  "description": "",
5
5
  "version": "0.1.0",
6
6
  "private": true,
7
- "author":{
8
- "name" : "",
9
- "url" : "",
7
+ "author": {
8
+ "name": "",
9
+ "url": "",
10
10
  "email": ""
11
11
  },
12
12
  "engines": {
@@ -50,6 +50,7 @@
50
50
  "@types/react-dom": "^18.0.6",
51
51
  "env-cmd": "^10.1.0",
52
52
  "lincd-cli": "^0.1",
53
- "nodemon": "^2.0.6"
53
+ "nodemon": "^2.0.6",
54
+ "ts-loader": "^9.4.1"
54
55
  }
55
56
  }
@@ -16,8 +16,8 @@
16
16
  "types": "dist/${output_file_name}.d.ts",
17
17
  "license": "ISC",
18
18
  "scripts": {
19
+ "start": "npm exec lincd dev",
19
20
  "build": "npm exec lincd build",
20
- "dev": "npm exec lincd dev",
21
21
  "prepublishOnly": "npm exec lincd build production",
22
22
  "postpublish": "npm exec lincd register"
23
23
  },
package/lib/cli.js CHANGED
@@ -72,6 +72,7 @@ var path = require('path');
72
72
  var glob = require('glob');
73
73
  var variables = {};
74
74
  var open = require('open');
75
+ var gruntConfig;
75
76
  program
76
77
  .command('create-app')
77
78
  .action(function (name) {
@@ -84,15 +85,15 @@ program
84
85
  .action(function (name, uriBase) {
85
86
  return createModule(name, uriBase);
86
87
  })
87
- .description('Create a new folder with all the required files for a new LINCD module')
88
- .argument('<name>', 'The name of the module. Will be used as package name in package.json')
89
- .argument('[uri_base]', 'The base URL used for data of this module. Leave blank to use the URL of your module on lincd.org after you register it');
88
+ .description('Create a new folder with all the required files for a new LINCD package')
89
+ .argument('<name>', 'The name of the package. Will be used as package name in package.json')
90
+ .argument('[uri_base]', 'The base URL used for data of this package. Leave blank to use the URL of your package on lincd.org after you register it');
90
91
  program
91
92
  .command('create-shape')
92
93
  .action(function (name, uriBase) {
93
94
  return createShape(name);
94
95
  })
95
- .description('Creates a new ShapeClass file for your module. Execute this from your module folder.')
96
+ .description('Creates a new ShapeClass file for your package. Execute this from your package folder.')
96
97
  .argument('<name>', 'The name of the shape. Will be used for the file name and the class name');
97
98
  program
98
99
  .command('create-component')
@@ -106,9 +107,9 @@ program
106
107
  .action(function (prefix, uriBase) {
107
108
  return createOntology(prefix, uriBase);
108
109
  })
109
- .description('Creates a new ontology file for your module. Execute this from your module folder.')
110
+ .description('Creates a new ontology file for your package. Execute this from your package folder.')
110
111
  .argument('<suggested-prefix>', 'The suggested prefix for your ontology. Also the shorthand code used for the file name and the exported ontology object')
111
- .argument('[uribase]', "Optional argument to set the URI base for the URI's of all entities in your ontology. Leave blank to use the URI's provided by lincd.org once you register this module");
112
+ .argument('[uribase]', "Optional argument to set the URI base for the URI's of all entities in your ontology. Leave blank to use the URI's provided by lincd.org once you register this package");
112
113
  program.command('register-local', { hidden: true }).action(function () {
113
114
  register('http://localhost:4101');
114
115
  });
@@ -120,7 +121,7 @@ program
120
121
  .action(function () {
121
122
  register('https://registry.lincd.org');
122
123
  })
123
- .description('Register (a new version of) this module to the LINCD registry. If successful your module will appear on www.lincd.org');
124
+ .description('Register (a new version of) this package to the LINCD registry. If successful your package will appear on www.lincd.org');
124
125
  program
125
126
  .command('info')
126
127
  .action(function () {
@@ -136,7 +137,9 @@ program.command('publish-updated').action(function () {
136
137
  return publishUpdated();
137
138
  });
138
139
  program.command('status').action(function () {
140
+ //log which packages need to be published
139
141
  return publishUpdated(true).then(function () {
142
+ //log which packages need to be build
140
143
  return buildUpdated(undefined, '', '', true);
141
144
  });
142
145
  });
@@ -149,17 +152,17 @@ program.command('build-updated-since [num-commits-back] [target] [target2]').act
149
152
  program.command('build-all [target] [target2]').action(function (target, target2) {
150
153
  buildAll(target, target2);
151
154
  });
152
- program.command('modules [action] [filter] [filter-value]').action(function (command, filter, filterValue) {
155
+ program.command('all [action] [filter] [filter-value]').action(function (command, filter, filterValue) {
153
156
  executeCommandForEachModule(getLincdModules(), command, filter, filterValue);
154
157
  });
155
- // program.command('modules-except [excludedSpaces] [action]').action((excludedSpaces, command) => {
158
+ // program.command('all-except [excludedSpaces] [action]').action((excludedSpaces, command) => {
156
159
  // executeCommandForEachModule(getLincdModules(), command, null, excludedSpaces);
157
160
  // });
158
161
  program.command('dev [target] [mode]').action(function (target, mode) {
159
162
  developModule(target, mode);
160
163
  });
161
164
  program
162
- .command('module|m')
165
+ .command('module|m|package|p')
163
166
  .action(function (name, command, args) {
164
167
  var fullCommand = command
165
168
  ? command +
@@ -173,8 +176,8 @@ program
173
176
  executeCommandForModule(name, fullCommand);
174
177
  })
175
178
  .alias('m')
176
- .description("Searches for a module in this workspace with a partially matching name and executes a command for that module (without needing to execute it from that modules' folder)")
177
- .argument('<name>', 'the name of the module. Can be a part of the name.')
179
+ .description('Searches for a package in this workspace with a partially matching name and executes a command for that package (without needing to execute it from the folder of the package)')
180
+ .argument('<name>', 'the name of the package. Can be a part of the name.')
178
181
  .argument('[command]', 'the lincd command you want to execute. Like dev or build')
179
182
  .argument('[args...]', 'the additional arguments of that command');
180
183
  function logHelp() {
@@ -189,6 +192,33 @@ function log() {
189
192
  console.log(chalk.cyan('Info: ') + message);
190
193
  });
191
194
  }
195
+ function progressUpdate(message) {
196
+ process.stdout.write(' \r');
197
+ process.stdout.write(message + '\r');
198
+ }
199
+ function debugInfo() {
200
+ var messages = [];
201
+ for (var _i = 0; _i < arguments.length; _i++) {
202
+ messages[_i] = arguments[_i];
203
+ }
204
+ // messages.forEach((message) => {
205
+ // console.log(chalk.cyan('Info: ') + message);
206
+ // });
207
+ //@TODO: let packages also use lincd.config.json? instead of gruntfile...
208
+ // that way we can read "analyse" here and see if we need to log debug info
209
+ // if(!gruntConfig)
210
+ // {
211
+ // gruntConfig = getGruntConfig();
212
+ // console.log(gruntConfig);
213
+ // process.exit();
214
+ // }
215
+ // if(gruntConfig.analyse === true)
216
+ // {
217
+ // messages.forEach((message) => {
218
+ // console.log(chalk.cyan('Info: ') + message);
219
+ // });
220
+ // }
221
+ }
192
222
  function warn() {
193
223
  var messages = [];
194
224
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -246,7 +276,7 @@ function checkModulePath(rootPath, modulePath, res) {
246
276
  // console.log('checking '+packagePath);
247
277
  if (fs.existsSync(packagePath)) {
248
278
  var pack = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
249
- //some packages are not true lincd modules, but we still want them to be re-built automatically. This is what lincd_util is for
279
+ //some packages are not true lincd packages, but we still want them to be re-built automatically. This is what lincd_util is for
250
280
  if (pack && pack.workspaces) {
251
281
  checkWorkspaces(modulePath, pack.workspaces, res);
252
282
  }
@@ -259,221 +289,240 @@ function checkModulePath(rootPath, modulePath, res) {
259
289
  }
260
290
  }
261
291
  }
262
- function buildAll(target, target2) {
292
+ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStackEnd) {
263
293
  var _this = this;
264
294
  var dependencies = new Map();
265
- console.log('Building all modules of this repository in order of dependencies');
266
- var modules = getLocalLincdModuleMap();
267
- //get dependencies of each module
295
+ //get dependencies of each package
268
296
  var leastDependentModule;
269
- modules.forEach(function (module) {
270
- var pack = (0, utils_1.getPackageJSON)(module.path);
297
+ lincdPackages.forEach(function (pkg) {
298
+ var pack = (0, utils_1.getPackageJSON)(pkg.path);
271
299
  if (pack) {
272
- //get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
300
+ //get lincd related dependencies and get the actual package details from the package map by removing '@dacore/' from the package name
273
301
  var moduleDependencies = Object.keys(pack.dependencies)
274
- .filter(function (dependency) { return modules.has(dependency); })
302
+ .filter(function (dependency) { return lincdPackages.has(dependency); })
275
303
  .map(function (dependency) {
276
- return modules.has(dependency) ? modules.get(dependency) : dependency;
304
+ return lincdPackages.has(dependency) ? lincdPackages.get(dependency) : dependency;
277
305
  });
278
- // console.log(module.moduleName,moduleDependencies.map())
279
- dependencies.set(module, moduleDependencies);
306
+ // console.log(package.moduleName,moduleDependencies.map())
307
+ dependencies.set(pkg, moduleDependencies);
280
308
  }
281
309
  });
282
- dependencies.forEach(function (moduleDependencies, module) {
310
+ dependencies.forEach(function (moduleDependencies, pkg) {
283
311
  if (!moduleDependencies.some(function (dependency) {
284
- return typeof dependency !== 'string' && modules.has(dependency.moduleName);
312
+ return typeof dependency !== 'string' && lincdPackages.has(dependency.moduleName);
285
313
  })) {
286
- leastDependentModule = module;
314
+ leastDependentModule = pkg;
287
315
  }
288
316
  });
289
- var startFrom;
290
- //by default start building
291
- var building = true;
292
- //option to start from a specific module in the stack
293
- if (target == 'from') {
294
- startFrom = target2;
295
- //if we have a startFrom, then we havnt started the build process yet
296
- building = startFrom ? false : true;
297
- //clear targets
298
- target = '';
299
- target2 = '';
300
- console.log(chalk.blue('Will skip builds until ' + startFrom));
301
- }
302
- var stack = [leastDependentModule];
317
+ var startStack = [leastDependentModule];
303
318
  var done = new Set();
304
- var p = Promise.resolve();
305
- var runStack = function () { return __awaiter(_this, void 0, void 0, function () {
306
- var modulesLeft, failedModules, stackPromise, first_1;
319
+ var results = [];
320
+ var runStack = function (stack) { return __awaiter(_this, void 0, void 0, function () {
321
+ var runFunction, stackPromise, stackResults;
307
322
  return __generator(this, function (_a) {
308
323
  switch (_a.label) {
309
324
  case 0:
310
- modulesLeft = modules.size - done.size;
311
- if (done.size > 0) {
312
- console.log(chalk.magenta('\n-------\nThese modules are next, since all their dependencies have now been build:'));
313
- console.log(chalk.magenta(stack.map(function (i) { return i.moduleName; })));
314
- // log(stack);
315
- }
316
- failedModules = [];
317
- stackPromise = Promise.all(stack.map(function (module) {
325
+ runFunction = onBuildStack(stack, dependencies);
326
+ stackPromise = Promise.all(stack.map(function (pck) {
318
327
  // p = p.then(() => {
319
- var command;
320
- //if we're skipping builds until a certain module
321
- if (!building) {
322
- //if the module name matches the module we're supposed to start from then start building modules
323
- if (module.moduleName == startFrom || module.packageName == startFrom) {
324
- building = true;
325
- }
326
- //else still waiting for the module
327
- else {
328
- log(chalk.blue('skipping ' + module.moduleName));
329
- command = Promise.resolve(true);
330
- }
331
- }
332
- //unless told otherwise, build the module
333
- if (!command) {
334
- command = execp('cd ' +
335
- module.path +
336
- ' && yarn lincd build' +
337
- (target ? ' ' + target : '') +
338
- (target2 ? ' ' + target2 : ''));
339
- log(chalk.cyan('Building ' + module.moduleName));
340
- }
341
- return command["catch"](function (err) {
342
- var dependentModules = [];
343
- dependencies.forEach(function (dModuleDependencies, dModule) {
344
- if (dModuleDependencies.indexOf(module) !== -1) {
345
- dependentModules.push(dModule);
346
- }
347
- });
348
- if (dependentModules.length > 0) {
349
- failedModules.push(module.moduleName);
350
- printBuildResults(failedModules, done);
351
- console.log(chalk.magenta('Stopping build process because an error occurred whilst building ' +
352
- module.moduleName +
353
- ', which ' +
354
- dependentModules.length +
355
- ' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
356
- console.log(chalk.cyanBright('tip ') +
357
- 'Run ' +
358
- chalk.green("lincd build-all from ".concat(module.moduleName)) +
359
- ' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
360
- process.exit(1);
361
- }
362
- else {
363
- failedModules.push(module.moduleName);
364
- }
328
+ return runFunction(pck)["catch"](function (_a) {
329
+ var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
330
+ warn('Uncaught exception whilst running parallel function on ' + pck.moduleName, error.message);
331
+ // warn(chalk.red(pck.moduleName+' failed:'));
332
+ // console.log(stdout);
365
333
  })
366
334
  .then(function (res) {
367
- // console.log("RESULT: ",res);
368
- // if(res && res.includes("Aborted due to warnings"))
369
- // {
370
- // failedModules.push(module.moduleName);
371
- // }
372
- // else
373
- // {
374
- done.add(module);
375
- // }
376
- modulesLeft--;
377
- log(chalk.magenta(modulesLeft + ' modules left'));
378
- if (modulesLeft == 0) {
379
- printBuildResults(failedModules, done);
380
- }
335
+ done.add(pck);
381
336
  return res;
382
337
  });
383
- // });
384
- // done.add(module);
385
338
  }));
386
- //wait till stack is completed
387
339
  return [4 /*yield*/, stackPromise];
388
340
  case 1:
389
- //wait till stack is completed
390
- _a.sent();
391
- // await p;
341
+ stackResults = _a.sent();
342
+ results = results.concat(stackResults);
392
343
  //clear stack for next round
393
344
  stack = [];
394
- //find those modules who have all their dependencies already built and add them to the stack
395
- modules.forEach(function (module) {
396
- var deps = dependencies.get(module);
397
- //if the module is not done yet
345
+ //find those packages who have all their dependencies already built and add them to the stack
346
+ lincdPackages.forEach(function (pkg) {
347
+ var deps = dependencies.get(pkg);
348
+ //if the package is not done yet
398
349
  //but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
399
- if (!done.has(module) &&
350
+ if (!done.has(pkg) &&
400
351
  deps.every(function (dependency) {
401
- return typeof dependency !== 'string' && (done.has(dependency) || !modules.has(dependency.moduleName));
352
+ return typeof dependency !== 'string' && (done.has(dependency) || !lincdPackages.has(dependency.moduleName));
402
353
  })) {
403
- stack.push(module);
354
+ stack.push(pkg);
404
355
  }
405
- // else if(!done.has(module))
356
+ // else if(!done.has(package))
406
357
  // {
407
- // console.log(chalk.red(module+' not yet'))
358
+ // console.log(chalk.red(package+' not yet'))
408
359
  // console.log('UNMET DEPS: '+deps.filter(dependency => !done.has(dependency)).join(" "))
409
360
  // }
410
361
  });
411
362
  //if more to be built, iterate
412
363
  if (stack.length > 0) {
413
- return [2 /*return*/, runStack()];
364
+ return [2 /*return*/, runStack(stack)];
414
365
  }
415
366
  else {
416
- //if no more modules to build but we never started building...
417
- if (!building) {
418
- console.log(chalk.red('Could not find the module to start from. Please provide a correct package name or module name to build from'));
419
- }
420
- else {
421
- first_1 = true;
422
- modules.forEach(function (module) {
423
- if (!done.has(module)) {
424
- var deps = dependencies.get(module);
425
- if (first_1) {
426
- console.log(chalk.red('CYCLICAL DEPENDENCIES? - could not build some modules because they depend on each other.'));
427
- first_1 = false;
428
- }
429
- //print the cyclical dependencies
430
- console.log(chalk.red(module.moduleName) +
431
- ' depends on ' +
432
- deps
433
- .filter(function (dependency) {
434
- return typeof dependency !== 'string';
435
- })
436
- .map(function (d) {
437
- return done.has(d) ? d.moduleName : chalk.red(d.moduleName);
438
- })
439
- .join(', '));
440
- //also print some information why these modules have not been moved into the stack
441
- var stringDependencies = deps.filter(function (d) { return typeof d === 'string'; });
442
- if (stringDependencies.length > 0) {
443
- console.log(chalk.red('And it depends on these module(s) - which seem not to be proper modules :' +
444
- stringDependencies.join(', ')));
445
- console.log(chalk.red('Could you remove this from dependencies? Should it be a devDependency?'));
446
- }
447
- }
448
- });
449
- }
367
+ onStackEnd(results.filter(Boolean));
450
368
  }
451
369
  return [2 /*return*/];
452
370
  }
453
371
  });
454
372
  }); };
455
373
  //starts the process
456
- runStack();
374
+ runStack(startStack);
375
+ }
376
+ function buildAll(target, target2) {
377
+ var _this = this;
378
+ console.log('Building all LINCD packages of this repository in order of dependencies');
379
+ var lincdPackages = getLocalLincdModuleMap();
380
+ var startFrom;
381
+ //by default start building
382
+ var building = true;
383
+ //option to start from a specific package in the stack
384
+ if (target == 'from') {
385
+ startFrom = target2;
386
+ //if we have a startFrom, then we havnt started the build process yet
387
+ building = startFrom ? false : true;
388
+ //clear targets
389
+ target = '';
390
+ target2 = '';
391
+ console.log(chalk.blue('Will skip builds until ' + startFrom));
392
+ return function (pkg) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
393
+ return [2 /*return*/];
394
+ }); }); };
395
+ }
396
+ var done = new Set();
397
+ var failedModules = [];
398
+ progressUpdate(lincdPackages.size + ' packages left');
399
+ var modulesLeft = lincdPackages.size;
400
+ // let modulesLeft = lincdPackages.size - done.size;
401
+ runOnPackagesGroupedByDependencies(lincdPackages, function (packageGroup, dependencies) {
402
+ if (done.size > 0) {
403
+ debugInfo(chalk.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
404
+ // log(stack);
405
+ }
406
+ debugInfo('Now building: ' + chalk.blue(packageGroup.map(function (i) { return i.moduleName; })));
407
+ return function (pkg) { return __awaiter(_this, void 0, void 0, function () {
408
+ var command;
409
+ return __generator(this, function (_a) {
410
+ //if we're skipping builds until a certain package
411
+ if (!building) {
412
+ //if the package name matches the package we're supposed to start from then start building packages
413
+ if (pkg.moduleName == startFrom || pkg.packageName == startFrom) {
414
+ building = true;
415
+ }
416
+ //else still waiting for the package
417
+ else {
418
+ log(chalk.blue('skipping ' + pkg.moduleName));
419
+ command = Promise.resolve(true);
420
+ }
421
+ }
422
+ //unless told otherwise, build the package
423
+ if (!command) {
424
+ command = execPromise('cd ' + pkg.path + ' && yarn lincd build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : ''), false, false, {}, false);
425
+ debugInfo(chalk.cyan('Building ' + pkg.moduleName));
426
+ }
427
+ return [2 /*return*/, command["catch"](function (_a) {
428
+ var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
429
+ //this prints out the webpack output, including the build errors
430
+ warn('Failed to build ' + pkg.moduleName);
431
+ console.log(stdout);
432
+ failedModules.push(pkg.moduleName);
433
+ var dependentModules = getDependentPackages(dependencies, pkg);
434
+ if (dependentModules.length > 0) {
435
+ printBuildResults(failedModules, done);
436
+ console.log(chalk.magenta('Stopping build process because an error occurred whilst building ' +
437
+ pkg.moduleName +
438
+ ', which ' +
439
+ dependentModules.length +
440
+ ' other packages depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
441
+ console.log(chalk.cyanBright('tip ') +
442
+ 'Run ' +
443
+ chalk.green("lincd build-all from ".concat(pkg.moduleName)) +
444
+ ' to build only the remaining packages'); //"+dependentModules.map(d => d.moduleName).join(", ")));
445
+ process.exit(1);
446
+ }
447
+ })
448
+ .then(function (res) {
449
+ done.add(pkg);
450
+ modulesLeft--;
451
+ // log(chalk.magenta(modulesLeft + ' packages left'));
452
+ process.stdout.write(modulesLeft + ' packages left\r');
453
+ if (modulesLeft == 0) {
454
+ printBuildResults(failedModules, done);
455
+ }
456
+ return res;
457
+ })];
458
+ });
459
+ }); };
460
+ }, function (dependencies) {
461
+ //if no more packages to build but we never started building...
462
+ if (!building) {
463
+ console.log(chalk.red('Could not find the package to start from. Please provide a correct package name or package name to build from'));
464
+ }
465
+ else {
466
+ //Detecting cyclical dependencies that caused some packages not to be build
467
+ var first_1 = true;
468
+ lincdPackages.forEach(function (pkg) {
469
+ if (!done.has(pkg)) {
470
+ var deps = dependencies.get(pkg);
471
+ if (first_1) {
472
+ console.log(chalk.red('CYCLICAL DEPENDENCIES? - could not build some packages because they depend on each other.'));
473
+ first_1 = false;
474
+ }
475
+ //print the cyclical dependencies
476
+ console.log(chalk.red(pkg.moduleName) +
477
+ ' depends on ' +
478
+ deps
479
+ .filter(function (dependency) {
480
+ return typeof dependency !== 'string';
481
+ })
482
+ .map(function (d) {
483
+ return done.has(d) ? d.moduleName : chalk.red(d.moduleName);
484
+ })
485
+ .join(', '));
486
+ //also print some information why these packages have not been moved into the stack
487
+ var stringDependencies = deps.filter(function (d) { return typeof d === 'string'; });
488
+ if (stringDependencies.length > 0) {
489
+ console.log(chalk.red('And it depends on these package(s) - which seem not to be proper packages :' +
490
+ stringDependencies.join(', ')));
491
+ console.log(chalk.red('Could you remove this from dependencies? Should it be a devDependency?'));
492
+ }
493
+ }
494
+ });
495
+ }
496
+ });
497
+ }
498
+ function getDependentPackages(dependencies, pkg) {
499
+ var dependentModules = [];
500
+ dependencies.forEach(function (dModuleDependencies, dModule) {
501
+ if (dModuleDependencies.indexOf(pkg) !== -1) {
502
+ dependentModules.push(dModule);
503
+ }
504
+ });
505
+ return dependentModules;
457
506
  }
458
507
  /**
459
- * Returns a map of the modules that this repository manages (so no modules found through the workspaces who's path contains ../ )
508
+ * Returns a map of the packages that this repository manages (so no packages found through the workspaces who's path contains ../ )
460
509
  * @param rootPath
461
510
  */
462
511
  function getLocalLincdModuleMap(rootPath) {
463
512
  if (rootPath === void 0) { rootPath = './'; }
464
513
  var map = new Map();
465
- getLincdModules(rootPath).forEach(function (module) {
466
- if (module.path.indexOf('../') === -1 && module.path.indexOf('..\\') === -1) {
467
- // console.log(module.path);
468
- map.set(module.moduleName, module);
514
+ getLincdModules(rootPath).forEach(function (pkg) {
515
+ if (pkg.path.indexOf('../') === -1 && pkg.path.indexOf('..\\') === -1) {
516
+ // console.log(package.path);
517
+ map.set(pkg.moduleName, pkg);
469
518
  }
470
519
  });
471
520
  return map;
472
521
  }
473
522
  function getLocalLincdModules(rootPath) {
474
523
  if (rootPath === void 0) { rootPath = './'; }
475
- return getLincdModules(rootPath).filter(function (module) {
476
- return module.path.indexOf('..\\') === -1;
524
+ return getLincdModules(rootPath).filter(function (pkg) {
525
+ return pkg.path.indexOf('..\\') === -1;
477
526
  });
478
527
  }
479
528
  function getLincdModules(rootPath) {
@@ -558,16 +607,17 @@ function execp(cmd, log, allowError, options) {
558
607
  });
559
608
  });
560
609
  }
561
- function execPromise(command, log, allowError, options) {
610
+ function execPromise(command, log, allowError, options, pipeOutput) {
562
611
  if (log === void 0) { log = false; }
563
612
  if (allowError === void 0) { allowError = false; }
613
+ if (pipeOutput === void 0) { pipeOutput = false; }
564
614
  return new Promise(function (resolve, reject) {
565
615
  if (log)
566
616
  console.log(chalk.cyan(command));
567
- exec(command, options, function (error, stdout, stderr) {
617
+ var child = exec(command, options, function (error, stdout, stderr) {
568
618
  if (error) {
569
619
  if (!allowError) {
570
- reject(error.message);
620
+ reject({ error: error, stdout: stdout, stderr: stderr });
571
621
  return;
572
622
  }
573
623
  else if (log) {
@@ -583,6 +633,10 @@ function execPromise(command, log, allowError, options) {
583
633
  }
584
634
  resolve(result);
585
635
  });
636
+ if (pipeOutput) {
637
+ child.stdout.pipe(process.stdout);
638
+ child.stderr.pipe(process.stderr);
639
+ }
586
640
  });
587
641
  }
588
642
  var replaceVariablesInFile = function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
@@ -606,9 +660,7 @@ var replaceCurlyVariables = function (string) {
606
660
  };
607
661
  var capitalize = function (str) { return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1); };
608
662
  var camelCase = function (str) {
609
- var string = str
610
- .replace(/[^A-Za-z0-9]/g, ' ')
611
- .split(' ');
663
+ var string = str.replace(/[^A-Za-z0-9]/g, ' ').split(' ');
612
664
  if (string.length > 1) {
613
665
  return string.reduce(function (result, word) { return result + capitalize(word); });
614
666
  }
@@ -806,7 +858,7 @@ var createModule = function (name, uriBase, basePath) {
806
858
  switch (_c.label) {
807
859
  case 0:
808
860
  //if ran with npx, basePath will be the root directory of the repository, even if we're executing from a sub folder (the root directory is where node_modules lives and package.json with workspaces)
809
- //so we manually find a modules folder, if it exists we go into that.
861
+ //so we manually find a packages folder, if it exists we go into that.
810
862
  if (fs.existsSync(path.join(basePath, 'modules'))) {
811
863
  basePath = path.join(basePath, 'modules');
812
864
  }
@@ -825,12 +877,12 @@ var createModule = function (name, uriBase, basePath) {
825
877
  // --> match[0] = @dacore/some-mod
826
878
  // --> match[1] = @dacore
827
879
  // --> match[2] = some-mod
828
- //but save full scoped module name under ${module_name}
880
+ //but save full scoped package name under ${module_name}
829
881
  setVariable('module_name', name);
830
882
  //extra variable for clarity (will be same as 'name')
831
883
  setVariable('output_file_name', name);
832
884
  _b = setNameVariables(cleanPackageName), hyphenName = _b.hyphenName, camelCaseName = _b.camelCaseName, underscoreName = _b.underscoreName;
833
- log("Creating new LINCD module '" + name + "'");
885
+ log("Creating new LINCD package '" + name + "'");
834
886
  fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), targetFolder);
835
887
  //replace variables in some of the copied files
836
888
  return [4 /*yield*/, Promise.all([
@@ -849,7 +901,7 @@ var createModule = function (name, uriBase, basePath) {
849
901
  case 1:
850
902
  //replace variables in some of the copied files
851
903
  _c.sent();
852
- //rename these to a file name similar to the module name
904
+ //rename these to a file name similar to the pkg name
853
905
  [
854
906
  'src/ontologies/example-ontology.ts',
855
907
  'src/data/example-ontology.json',
@@ -874,7 +926,7 @@ var createModule = function (name, uriBase, basePath) {
874
926
  })];
875
927
  case 3:
876
928
  _c.sent();
877
- log("Prepared a new LINCD module in ".concat(chalk.magenta(targetFolder)), "Run ".concat(chalk.blueBright('yarn build'), " from this directory to build once"), "Or ".concat(chalk.blueBright('yarn dev'), " to continuously rebuild on file changes"));
929
+ log("Prepared a new LINCD package in ".concat(chalk.magenta(targetFolder)), "Run ".concat(chalk.blueBright('yarn build'), " from this directory to build once"), "Or ".concat(chalk.blueBright('yarn dev'), " to continuously rebuild on file changes"));
878
930
  return [2 /*return*/];
879
931
  }
880
932
  });
@@ -961,7 +1013,7 @@ var buildFailed = function (output) {
961
1013
  }
962
1014
  else
963
1015
  {
964
- console.warn("Invalid LINCD module. Index file should export a packageExports object. See examples.")
1016
+ console.warn("Invalid LINCD package. Index file should export a packageExports object. See examples.")
965
1017
  }
966
1018
 
967
1019
  } else {
@@ -1050,7 +1102,7 @@ var buildModule = function (target, target2, modulePath, logResults) {
1050
1102
  }
1051
1103
  };
1052
1104
  var getLastBuildTime = function (modulePath) {
1053
- return getLastModifiedFile(modulePath + '/@(builds|lib)/**/*.js');
1105
+ return getLastModifiedFile(modulePath + '/@(builds|lib|dist)/**/*.js');
1054
1106
  };
1055
1107
  var getLastModifiedSourceTime = function (modulePath) {
1056
1108
  return getLastModifiedFile(modulePath + '/@(src|data|scss)/**/*', {
@@ -1060,10 +1112,15 @@ var getLastModifiedSourceTime = function (modulePath) {
1060
1112
  var getLastCommitTime = function (modulePath) {
1061
1113
  // console.log(`git log -1 --format=%ci -- ${modulePath}`);
1062
1114
  // process.exit();
1063
- return execPromise("git log -1 --format=%ci -- ".concat(modulePath)).then(function (result) {
1115
+ return execPromise("git log -1 --format=%ci -- ".concat(modulePath))
1116
+ .then(function (result) {
1064
1117
  var lastCommit = new Date(result);
1065
1118
  // console.log(modulePath,result,lastCommit);
1066
1119
  return lastCommit;
1120
+ })["catch"](function (_a) {
1121
+ var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
1122
+ debugInfo(chalk.red('Git error: ') + error.message.toString());
1123
+ return null;
1067
1124
  });
1068
1125
  };
1069
1126
  var getLastModifiedFile = function (filePath, config) {
@@ -1092,60 +1149,90 @@ var getLastModifiedFile = function (filePath, config) {
1092
1149
  var publishUpdated = function (test) {
1093
1150
  var _this = this;
1094
1151
  if (test === void 0) { test = false; }
1095
- var modules = getLocalLincdModules();
1152
+ var packages = getLocalLincdModules();
1096
1153
  var browserCoreBuilt = false;
1097
1154
  var p = Promise.resolve('');
1098
- modules.forEach(function (module) {
1155
+ var packagesLeft = packages.length;
1156
+ console.log('Checking which packages need to be published by comparing last published date with last git commit');
1157
+ packages.forEach(function (pckg) {
1099
1158
  p = p.then(function (previousResult) {
1100
- log('# Checking module ' + module.moduleName);
1101
- // log('# Requesting ' + 'yarn info '+module.packageName+' --json');
1102
- // return execPromise('yarn info '+module.packageName+' --json').then((output:string) => {
1159
+ progressUpdate(packagesLeft-- + ' packages left. Now checking ' + pckg.moduleName);
1160
+ debugInfo('# Checking package ' + pckg.moduleName);
1161
+ // log('# Requesting ' + 'yarn info '+pkg.packageName+' --json');
1162
+ // return execPromise('yarn info '+pkg.packageName+' --json').then((output:string) => {
1103
1163
  // console.log("Will be requesting npm view from this current working directory:\n"+process.cwd());
1104
- // return execPromise('npm view '+module.packageName+' --json').then((output:string) => {
1105
- return execPromise('yarn info ' + module.packageName + ' --json')
1164
+ // return execPromise('npm view '+pkg.packageName+' --json').then((output:string) => {
1165
+ var shouldPublish;
1166
+ var pack = (0, utils_1.getPackageJSON)(pckg.path);
1167
+ var version = getNextVersion(pack.version);
1168
+ if (pack.private) {
1169
+ shouldPublish = false;
1170
+ debugInfo(chalk.blue('--> is private, skipping'));
1171
+ return previousResult + ' ' + chalk.gray(pckg.moduleName + ' is private\n');
1172
+ }
1173
+ return execPromise('yarn info ' + pckg.packageName + ' --json')
1106
1174
  .then(function (output) { return __awaiter(_this, void 0, void 0, function () {
1107
- var info, lastPublish, lastPublishDate, _a, lastModifiedTime, lastModifiedName, lastModified, lastCommit, res, browserModule;
1108
- return __generator(this, function (_b) {
1109
- switch (_b.label) {
1175
+ var info, lastPublish, lastPublishDate, lastCommit, res, browserModule;
1176
+ return __generator(this, function (_a) {
1177
+ switch (_a.label) {
1110
1178
  case 0:
1111
1179
  try {
1112
1180
  if (output == '') {
1113
- // console.warn("No response (empty) from `yarn info`");
1114
- throw new Error('Empty response from `npm view`');
1115
- return [2 /*return*/];
1181
+ debugInfo('No response (empty) from `yarn info`. This package was probably not published before');
1182
+ // throw new Error('Empty response from `yarn info`. This pkg was probably not published before');
1183
+ // return;
1184
+ shouldPublish = true;
1185
+ //don't patch the version number (default, see above), use the current version
1186
+ version = pack.version;
1187
+ }
1188
+ else {
1189
+ info = JSON.parse(output);
1116
1190
  }
1117
- info = JSON.parse(output);
1118
1191
  // var stats = fs.statSync(path.join(moduleDirectory));
1119
1192
  // var files = fs.readdirSync(path.join(moduleDirectory,'src'));
1120
1193
  }
1121
1194
  catch (err) {
1122
- chalk.red(module.moduleName + ' failed: ' + err.message + '\n');
1195
+ chalk.red(pckg.moduleName + ' failed: ' + err.message + '\n');
1123
1196
  console.warn('Returned JSON from npm: ' + output);
1124
- return [2 /*return*/, previousResult + ' ' + chalk.red(module.moduleName + ' failed: ' + err.message + '\n')];
1197
+ return [2 /*return*/, previousResult + ' ' + chalk.red(pckg.moduleName + ' failed: ' + err.message + '\n')];
1125
1198
  }
1199
+ if (!info) return [3 /*break*/, 2];
1126
1200
  lastPublish = info.data.time[info.data.version];
1127
1201
  lastPublishDate = new Date(lastPublish);
1128
- _a = getLastModifiedSourceTime(module.path), lastModifiedTime = _a.lastModifiedTime, lastModifiedName = _a.lastModifiedName, lastModified = _a.lastModified;
1129
- return [4 /*yield*/, getLastCommitTime(module.path)];
1202
+ return [4 /*yield*/, getLastCommitTime(pckg.path)];
1130
1203
  case 1:
1131
- lastCommit = _b.sent();
1132
- console.log(lastPublishDate.toDateString() + ' ' + lastPublishDate.toTimeString() + ' published ' + info.data.version);
1133
- console.log(lastCommit.toDateString() + ' ' + new Date(lastCommit).toTimeString() + ' source last committed');
1134
- // console.log(lastModified.toDateString() + ' ' + new Date(lastModified).toTimeString() + ' source ' + lastModifiedName + ' last edited');
1135
- //NOTE: removed lastModified, because switching branches will say that the file was modified and cause everything to publish
1136
- //SO: now you NEED TO commit before it picks up that you should publish
1137
- //|| lastPublishDate.getTime() < lastModified.getTime()
1138
- if (lastPublishDate.getTime() < lastCommit.getTime()) {
1139
- res = executeSingleBuild(module, previousResult, test, info);
1140
- if (module.moduleName == 'browser-core') {
1204
+ lastCommit = _a.sent();
1205
+ if (!lastCommit) {
1206
+ shouldPublish = false;
1207
+ debugInfo('Could not determine last git commit');
1208
+ return [2 /*return*/, previousResult + ' ' + chalk.red(pckg.moduleName + ' - could not determine last commit\n')];
1209
+ }
1210
+ else {
1211
+ //NOTE: removed lastModified, because switching branches will say that the file was modified and cause everything to publish
1212
+ //SO: now you NEED TO commit before it picks up that you should publish
1213
+ shouldPublish = lastPublishDate.getTime() < lastCommit.getTime();
1214
+ if (shouldPublish) {
1215
+ debugInfo(lastPublishDate.toDateString() +
1216
+ ' ' +
1217
+ lastPublishDate.toTimeString() +
1218
+ ' published ' +
1219
+ info.data.version);
1220
+ debugInfo(lastCommit.toDateString() + ' ' + new Date(lastCommit).toTimeString() + ' source last committed');
1221
+ }
1222
+ }
1223
+ _a.label = 2;
1224
+ case 2:
1225
+ if (shouldPublish) {
1226
+ res = publishPackage(pckg, previousResult, test, info, version);
1227
+ if (pckg.moduleName == 'browser-core') {
1141
1228
  browserCoreBuilt = true;
1142
1229
  }
1143
1230
  //when publishing core, also make sure to publish browser-core
1144
- if (module.moduleName == 'core' && !browserCoreBuilt) {
1145
- browserModule = modules.find(function (m) { return m.moduleName == 'browser-core'; });
1231
+ if (pckg.moduleName == 'core' && !browserCoreBuilt) {
1232
+ browserModule = packages.find(function (m) { return m.moduleName == 'browser-core'; });
1146
1233
  return [2 /*return*/, Promise.resolve(res).then(function (previousResult) {
1147
- log('# Automatically also publishing module browser-core');
1148
- return executeSingleBuild(browserModule, previousResult, test);
1234
+ log('# Automatically also publishing package browser-core');
1235
+ return publishPackage(browserModule, previousResult, test);
1149
1236
  })];
1150
1237
  }
1151
1238
  return [2 /*return*/, res];
@@ -1153,142 +1240,194 @@ var publishUpdated = function (test) {
1153
1240
  return [2 /*return*/, previousResult];
1154
1241
  }
1155
1242
  });
1156
- }); })["catch"](function (err) {
1157
- console.log(err);
1158
- return previousResult + ' ' + chalk.red(module.moduleName + ' failed\n');
1243
+ }); })["catch"](function (_a) {
1244
+ var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
1245
+ console.log(error.message);
1246
+ return previousResult + ' ' + chalk.red(pckg.moduleName + ' failed\n');
1159
1247
  });
1160
1248
  });
1161
1249
  });
1162
1250
  return p.then(function (messages) {
1163
1251
  if (messages == '') {
1164
- console.log('All published modules are already up-to-date.');
1252
+ console.log('All published packages are already up-to-date.');
1165
1253
  }
1166
1254
  else {
1167
1255
  console.log('Summary: \n' + messages);
1168
1256
  }
1169
1257
  });
1170
1258
  };
1171
- var executeSingleBuild = function (module, previousResult, test, info) {
1172
- var nextVersion = info ? getNextVersion(info.data.version) : '';
1173
- console.log(chalk.blue('--> ' + (test ? 'should publish' : 'publishing') + ' ' + module.moduleName + ' ' + nextVersion));
1259
+ var publishPackage = function (pkg, previousResult, test, info, publishVersion) {
1260
+ if (!publishVersion) {
1261
+ publishVersion = info ? getNextVersion(info.data.version) : '';
1262
+ }
1263
+ if (test) {
1264
+ debugInfo('should publish ' + pkg.moduleName + ' ' + publishVersion);
1265
+ }
1266
+ else {
1267
+ console.log(chalk.blue('publishing ' + pkg.moduleName + ' ' + publishVersion));
1268
+ }
1174
1269
  if (!test) {
1175
- return execPromise('cd ' + module.path + ' && yarn lincd register', true)
1270
+ return execPromise("cd ".concat(pkg.path, " && yarn publish").concat(publishVersion ? ' --new-version ' + publishVersion : ''), true, false, {}, true)
1176
1271
  .then(function (res) {
1177
1272
  if (res.indexOf('Aborted due to warnings') !== -1 ||
1178
1273
  res.indexOf('Could not publish') !== -1 ||
1179
1274
  res.indexOf("Couldn't publish") !== -1) {
1180
1275
  console.log(res);
1181
- return previousResult + ' ' + chalk.red(module.moduleName + ' failed\n');
1276
+ return previousResult + ' ' + chalk.red(pkg.moduleName + ' failed\n');
1182
1277
  }
1183
- console.log(chalk.green('Successfully published ' + nextVersion));
1184
- return previousResult + ' ' + chalk.green(module.moduleName + ' published ' + nextVersion + '\n');
1185
- })["catch"](function (err) {
1186
- console.log(chalk.red('Failed to publish: ' + err));
1187
- return chalk.red('Failed to publish: ' + err);
1278
+ console.log(chalk.green('Successfully published ' + pkg.path + ' ' + publishVersion));
1279
+ return previousResult + ' ' + chalk.green(pkg.moduleName + ' published ' + publishVersion + '\n');
1280
+ })["catch"](function (_a) {
1281
+ var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
1282
+ console.log(chalk.red('Failed to publish: ' + error.message));
1283
+ return previousResult + ' ' + chalk.red(pkg.moduleName + ' failed to publish\n');
1188
1284
  });
1189
1285
  }
1190
1286
  else {
1191
1287
  //when testing what needs to be published
1192
- return previousResult + ' ' + chalk.blue(module.moduleName + ' should publish\n');
1288
+ return previousResult + ' ' + chalk.blue(pkg.moduleName + ' should publish\n');
1193
1289
  }
1194
1290
  };
1195
1291
  var buildUpdated = function (back, target, target2, test) {
1196
1292
  if (test === void 0) { test = false; }
1197
- // back = back || 1;
1198
- // return execPromise(`git log -${back} --format=%ci`).then((result) => {
1199
- // let now = new Date();
1200
- var previousResult = '';
1201
- log((test ? 'Checking which modules' : 'Building all modules that') + ' have been changed since their last built ');
1202
- var modules = getLocalLincdModules();
1203
- //TODO: sort all these modules in the order of their dependencies.
1204
- // To do so, see build-all command and put some of the functionality (like getting modules that depend on a module) in reusable functions
1205
- var p = Promise.resolve('');
1206
- modules.forEach(function (module) {
1207
- var moduleName = module.moduleName;
1208
- p = p
1209
- .then(function (previousResult) {
1210
- var lastModifiedSource = getLastModifiedSourceTime(module.path);
1211
- var lastModifiedBundle = getLastBuildTime(module.path);
1212
- // console.log(module.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
1213
- // console.log(module.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
1214
- console.log('# Checking module ' + moduleName);
1215
- if (lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime) {
1216
- //TODO: when building a module, also rebuild all modules that depend on this module.. and iteratively build modules that depend on those modules..
1217
- // log(moduleName+' modified since last commit on '+now.toString());
1218
- console.log(chalk.cyan('Last modified source: ' +
1219
- lastModifiedSource.lastModifiedName +
1220
- ' on ' +
1221
- lastModifiedSource.lastModified.toString()));
1222
- console.log(chalk.cyan('Last build: ' +
1223
- (lastModifiedBundle && typeof lastModifiedBundle.lastModified !== 'undefined'
1224
- ? lastModifiedBundle.lastModified.toString()
1225
- : 'never')));
1226
- log('--> ' + (test ? 'need to build ' : 'building ') + moduleName);
1227
- if (!test) {
1228
- return execPromise('cd ' + module.path + ' && yarn build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : '')).then(function (res) {
1229
- if (res.indexOf('Aborted due to warnings') !== -1 || res.indexOf('Fatal error') !== -1) {
1230
- console.log(res);
1231
- return previousResult + ' ' + chalk.red(moduleName + ' failed\n');
1293
+ return __awaiter(this, void 0, void 0, function () {
1294
+ var previousResult, packages, jsonldPkgUpdated, cliPkgUpdated, rebuildAllModules, packagesLeft, p;
1295
+ var _this = this;
1296
+ return __generator(this, function (_a) {
1297
+ switch (_a.label) {
1298
+ case 0:
1299
+ previousResult = '';
1300
+ log(test ? 'Checking which packages need to be rebuild' : 'Building updated packages');
1301
+ packages = getLocalLincdModuleMap();
1302
+ jsonldPkgUpdated = needsRebuilding(packages.get('lincd-jsonld'));
1303
+ cliPkgUpdated = needsRebuilding(packages.get('lincd-cli'));
1304
+ if (!(jsonldPkgUpdated || cliPkgUpdated)) return [3 /*break*/, 2];
1305
+ return [4 /*yield*/, execPromise('yarn build-core', false, false, {}, true)];
1306
+ case 1:
1307
+ _a.sent();
1308
+ _a.label = 2;
1309
+ case 2:
1310
+ rebuildAllModules = false;
1311
+ if (cliPkgUpdated) {
1312
+ rebuildAllModules = true;
1313
+ log(chalk.magenta('Rebuilding all modules because the build tools (lincd-cli) got updated'));
1314
+ }
1315
+ packagesLeft = packages.size;
1316
+ runOnPackagesGroupedByDependencies(packages, function (packageGroup, dependencies) {
1317
+ // console.log('Now checking: ' + chalk.blue(packageGroup.map((i) => i.moduleName)));
1318
+ // console.log((packagesLeft) + " packages left.");
1319
+ packagesLeft = packagesLeft - packageGroup.length;
1320
+ return function (pkg) { return __awaiter(_this, void 0, void 0, function () {
1321
+ var needRebuild;
1322
+ return __generator(this, function (_a) {
1323
+ debugInfo('# Checking package ' + pkg.moduleName);
1324
+ needRebuild = needsRebuilding(pkg, true);
1325
+ if (pkg.moduleName === 'lincd-jsonld' && jsonldPkgUpdated) {
1326
+ needRebuild = true;
1327
+ }
1328
+ // console.log(pkg.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
1329
+ // console.log(pkg.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
1330
+ if (needRebuild || rebuildAllModules) {
1331
+ //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1332
+ // log(moduleName+' modified since last commit on '+now.toString());
1333
+ if (test) {
1334
+ debugInfo('Need to build ' + pkg.moduleName);
1335
+ return [2 /*return*/, chalk.blue(pkg.moduleName + ' should be build')];
1336
+ }
1337
+ log('Building ' + pkg.moduleName);
1338
+ return [2 /*return*/, execPromise('cd ' + pkg.path + ' && yarn build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : ''))
1339
+ .then(function (res) {
1340
+ debugInfo(chalk.green(pkg.moduleName + ' successfully built'));
1341
+ return chalk.green(pkg.moduleName + ' built');
1342
+ })["catch"](function (_a) {
1343
+ var error = _a.error, stdout = _a.stdout, stderr = _a.stderr;
1344
+ warn('Failed to build ' + pkg.moduleName);
1345
+ console.log(stdout);
1346
+ var dependentModules = getDependentPackages(dependencies, pkg);
1347
+ if (dependentModules.length > 0) {
1348
+ // printBuildResults(failedModules, done);
1349
+ warn(chalk.red(pkg.moduleName + ' build failed'));
1350
+ warn('Stopping build-updated process because ' +
1351
+ dependentModules.length +
1352
+ ' other packages depend on this module.\n'); //"+dependentModules.map(d => d.moduleName).join(", ")));
1353
+ process.exit(1);
1354
+ }
1355
+ })];
1356
+ }
1357
+ return [2 /*return*/];
1358
+ });
1359
+ }); };
1360
+ }, function (results) {
1361
+ if (results.length) {
1362
+ log('Summary:');
1363
+ log(results.join('\n'));
1364
+ }
1365
+ else {
1366
+ log(chalk.green('Nothing to rebuild'));
1232
1367
  }
1233
- console.log(chalk.green(moduleName + ' bundles successfully built'));
1234
- return previousResult + ' ' + chalk.green(moduleName + ' built\n');
1235
1368
  });
1236
- }
1237
- return previousResult + ' ' + chalk.blue(moduleName + ' should be build\n');
1369
+ return [2 /*return*/];
1238
1370
  }
1239
- return previousResult;
1240
- })["catch"](function (err) {
1241
- console.log(err);
1242
- return previousResult + ' ' + chalk.red(moduleName + ' failed\n');
1243
1371
  });
1244
1372
  });
1245
- return p.then(function (messages) {
1246
- if (messages == '') {
1247
- console.log(chalk.green('Nothing to rebuild.'));
1248
- }
1249
- else {
1250
- console.log('Summary: \n' + messages);
1251
- }
1252
- });
1253
- // });
1373
+ };
1374
+ var needsRebuilding = function (pkg, logDetailsIfTrue) {
1375
+ if (logDetailsIfTrue === void 0) { logDetailsIfTrue = false; }
1376
+ var lastModifiedSource = getLastModifiedSourceTime(pkg.path);
1377
+ var lastModifiedBundle = getLastBuildTime(pkg.path);
1378
+ var result = lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime;
1379
+ if (logDetailsIfTrue) {
1380
+ debugInfo(chalk.cyan('Last modified source: ' +
1381
+ lastModifiedSource.lastModifiedName +
1382
+ ' on ' +
1383
+ lastModifiedSource.lastModified.toString()));
1384
+ debugInfo(chalk.cyan('Last build: ' +
1385
+ (lastModifiedBundle && typeof lastModifiedBundle.lastModified !== 'undefined'
1386
+ ? lastModifiedBundle.lastModified.toString()
1387
+ : 'never')));
1388
+ }
1389
+ return result;
1254
1390
  };
1255
1391
  var printBuildResults = function (failed, done) {
1256
- log('Build results: ' +
1257
- chalk.green(__spreadArray([], __read(done), false).map(function (m) { return m.moduleName; }).join(', ')) +
1258
- (failed.length > 0 ? ', ' + chalk.red(failed.join(', ')) : '') +
1259
- '\n');
1392
+ log('Successfully built: ' + chalk.green(__spreadArray([], __read(done), false).map(function (m) { return m.moduleName; }).join(', ')) + '\n');
1393
+ if (failed.length > 0) {
1394
+ warn('Failed to build: ' + chalk.red(failed.join(', ')) + '\n');
1395
+ }
1260
1396
  };
1261
- var executeCommandForEachModule = function (modules, command, filterMethod, filterValue) {
1262
- //if a specific set of modules is given
1397
+ var executeCommandForEachModule = function (packages, command, filterMethod, filterValue) {
1398
+ //if a specific set of packages is given
1263
1399
  if (filterMethod == 'exclude') {
1264
- //filter modules, so that we only execute on the modules as provided in the command
1400
+ //filter packages, so that we only execute on the packages as provided in the command
1265
1401
  log('Excluding ' + filterValue);
1266
1402
  filterValue = filterValue.split(',');
1267
- modules = modules.filter(function (module) { return filterValue.indexOf(module.moduleName) === -1; });
1403
+ packages = packages.filter(function (pkg) { return filterValue.indexOf(pkg.moduleName) === -1; });
1268
1404
  }
1269
1405
  var startFrom;
1270
1406
  //by default start executing, unless 'from' is given
1271
1407
  var executing = true;
1272
- //option to start from a specific module in the stack
1408
+ //option to start from a specific pkg in the stack
1273
1409
  if (filterMethod == 'from') {
1274
1410
  startFrom = filterValue;
1275
1411
  if (startFrom) {
1276
1412
  console.log(chalk.blue('Will skip ahead to ' + startFrom));
1277
1413
  }
1278
1414
  var seen_1 = false;
1279
- modules = modules.filter(function (module) {
1280
- if (!seen_1 && (module.moduleName == startFrom || module.packageName == startFrom)) {
1415
+ packages = packages.filter(function (pkg) {
1416
+ if (!seen_1 && (pkg.moduleName == startFrom || pkg.packageName == startFrom)) {
1281
1417
  seen_1 = true;
1282
1418
  }
1283
1419
  return seen_1;
1284
1420
  });
1285
1421
  }
1286
- log("Executing '" + chalk.blueBright(command) + "' on modules " + chalk.magenta(modules.map(function (m) { return m.moduleName; }).join(', ')));
1422
+ log("Executing '" +
1423
+ chalk.blueBright(command) +
1424
+ "' on packages " +
1425
+ chalk.magenta(packages.map(function (m) { return m.moduleName; }).join(', ')));
1287
1426
  var p = Promise.resolve(true);
1288
- modules.forEach(function (module) {
1427
+ packages.forEach(function (pkg) {
1289
1428
  p = p.then(function () {
1290
- log('# Package ' + chalk.magenta(module.moduleName));
1291
- return execp('cd ' + module.path + ' && ' + command);
1429
+ log('# Package ' + chalk.magenta(pkg.moduleName));
1430
+ return execp('cd ' + pkg.path + ' && ' + command);
1292
1431
  });
1293
1432
  });
1294
1433
  return p;
@@ -1302,7 +1441,7 @@ var executeCommandForModule = function (moduleName, command) {
1302
1441
  return execp('cd ' + moduleDetails.path + ' && yarn lincd' + (command ? ' ' + command : ''));
1303
1442
  }
1304
1443
  else {
1305
- warn("Could not find a module who's name (partially) matched " + chalk.cyan(moduleName));
1444
+ warn("Could not find a pkg who's name (partially) matched " + chalk.cyan(moduleName));
1306
1445
  }
1307
1446
  };
1308
1447
  program.parse(process.argv);
@@ -32,7 +32,7 @@ var path = require('path');
32
32
  var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
33
33
  var TerserPlugin = require('terser-webpack-plugin');
34
34
  var exec = require('child_process').exec;
35
- var CopyPlugin = require("copy-webpack-plugin");
35
+ var CopyPlugin = require('copy-webpack-plugin');
36
36
  var NODE_ENV = process.env.NODE_ENV;
37
37
  var nodeProduction = NODE_ENV == 'production';
38
38
  // const libraryName = 'lincd';
@@ -83,7 +83,7 @@ function generateWebpackConfig(buildName, moduleName, config) {
83
83
  new CopyPlugin({
84
84
  patterns: [
85
85
  {
86
- from: "src/**/*.scss",
86
+ from: 'src/**/*.scss',
87
87
  to: function (_a) {
88
88
  var context = _a.context, absoluteFilename = _a.absoluteFilename;
89
89
  // console.log(chalk.magenta(context),chalk.magenta(absoluteFilename),process.cwd());
@@ -165,6 +165,7 @@ function generateWebpackConfig(buildName, moduleName, config) {
165
165
  // "postcss-scss": {}, //<-- only add this back if the build gets stuck on //comments in scss files, but I dont think that will be the case anymore
166
166
  'postcss-modules': {
167
167
  // //by default postcss-modules will put out a json file right next to the original css / scss file, this method defines what classnames to use
168
+ // generateScopedName:generateScopedName.bind(null,moduleName),
168
169
  generateScopedName: utils_1.generateScopedName.bind(null, moduleName),
169
170
  globalModulePaths: [/tailwind/]
170
171
  },
@@ -327,7 +328,7 @@ function generateWebpackConfig(buildName, moduleName, config) {
327
328
  //stats:{chunks:!watch,version:!watch}//hide some info from output when in watch mode to keep it succinct
328
329
  cache: {
329
330
  // https://webpack.js.org/configuration/other-options/#cache
330
- type: "filesystem"
331
+ type: 'filesystem'
331
332
  }
332
333
  };
333
334
  }
package/lib/utils.js CHANGED
@@ -51,11 +51,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
51
51
  return (mod && mod.__esModule) ? mod : { "default": mod };
52
52
  };
53
53
  exports.__esModule = true;
54
- exports.flatten = exports.warn = exports.debug = exports.log = exports.generateScopedName = exports.getPackageJSON = void 0;
54
+ exports.flatten = exports.warn = exports.debug = exports.log = exports.generateScopedName = exports.getGruntConfig = exports.getPackageJSON = void 0;
55
55
  var fs = __importStar(require("fs"));
56
56
  var path = __importStar(require("path"));
57
57
  var chalk_1 = __importDefault(require("chalk"));
58
- // const {findNearestPackageJson, findNearestPackageJsonSync} = require('find-nearest-package-json');
58
+ var _a = require('find-nearest-package-json'), findNearestPackageJson = _a.findNearestPackageJson, findNearestPackageJsonSync = _a.findNearestPackageJsonSync;
59
59
  var getPackageJSON = function (root, error) {
60
60
  if (root === void 0) { root = process.cwd(); }
61
61
  if (error === void 0) { error = true; }
@@ -71,6 +71,21 @@ var getPackageJSON = function (root, error) {
71
71
  }
72
72
  };
73
73
  exports.getPackageJSON = getPackageJSON;
74
+ var getGruntConfig = function (root, error) {
75
+ if (root === void 0) { root = process.cwd(); }
76
+ if (error === void 0) { error = true; }
77
+ var gruntFile = path.join(root, 'Gruntfile.js');
78
+ if (fs.existsSync(gruntFile)) {
79
+ return require(gruntFile)();
80
+ }
81
+ else if (root === process.cwd()) {
82
+ if (error) {
83
+ console.warn('Could not find Gruntfile.js. Make sure you run this command from the root of a lincd module or a lincd yarn workspace');
84
+ process.exit();
85
+ }
86
+ }
87
+ };
88
+ exports.getGruntConfig = getGruntConfig;
74
89
  /*export function getShapesJSONLD(packageExports): Promise<string> {
75
90
  // return JSONLDWriter.stringify(getShapes(packageExports));
76
91
  }
@@ -89,14 +104,15 @@ export function getShapes(packageExports): CoreSet<SHACL_Shape> {
89
104
  }
90
105
  return shapes;
91
106
  }*/
107
+ // export function generateScopedName(moduleName,name, filename, css) {
92
108
  function generateScopedName(moduleName, name, filename, css) {
93
109
  // console.log(moduleName,name,filename,css);
94
- // var file = path.basename(filename, '.scss');
95
- // let nearestPackageJson = findNearestPackageJsonSync(filename);
96
- // let packageName = nearestPackageJson ? nearestPackageJson.data.name : packageJson.name;
97
- // return packageName.replace(/[^a-zA-Z0-9_]+/g, '_') + '_' + file + '_' + name;
110
+ var file = path.basename(filename, '.scss');
111
+ var nearestPackageJson = findNearestPackageJsonSync(filename);
112
+ var packageName = nearestPackageJson ? nearestPackageJson.data.name : moduleName;
113
+ return packageName.replace(/[^a-zA-Z0-9_]+/g, '_') + '_' + file + '_' + name;
98
114
  // process.exit();
99
- var path = require('path');
115
+ // var path = require('path');
100
116
  var file = path.basename(filename, '.scss');
101
117
  var module = filename.match(/[\\\/]modules[\\\/]([\w\-_]+)/);
102
118
  var moduleName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lincd-cli",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Command line tools for the lincd.js library",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "build": "npm exec tsc",
9
9
  "dev": "npm exec tsc -w"
10
10
  },
11
- "lincd_util": true,
11
+ "lincd": true,
12
12
  "keywords": [
13
13
  "lincd",
14
14
  "cli",
@@ -43,6 +43,7 @@
43
43
  "commander": "^9.4.0",
44
44
  "copy-webpack-plugin": "^11.0.0",
45
45
  "css-loader": "^6.7.1",
46
+ "find-nearest-package-json": "^2.0.1",
46
47
  "fs-extra": "^10.1.0",
47
48
  "glob": "^7.1.6",
48
49
  "grunt": "^1.3.0",