lincd-cli 0.1.4 → 0.1.7

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 (47) hide show
  1. package/LICENSE +373 -373
  2. package/README.md +24 -24
  3. package/defaults/app/index.html +12 -0
  4. package/defaults/app/package.json +30 -0
  5. package/defaults/app/src/App.tsx +5 -0
  6. package/defaults/app/src/index.tsx +10 -0
  7. package/defaults/create_migration.ts +3 -3
  8. package/defaults/defaultModule/Index.scss +16 -16
  9. package/defaults/defaultModule/Index.tsx +31 -24
  10. package/defaults/defaultModule/data.json +54 -54
  11. package/defaults/defaultModule/defaultOntology.json +21 -21
  12. package/defaults/defaultModule/index.ts +16 -12
  13. package/defaults/defaultModule/ontology.ts +18 -15
  14. package/defaults/gitignorefile +3 -3
  15. package/defaults/index.ts +17 -13
  16. package/defaults/module/package.json +30 -29
  17. package/defaults/module/src/components/ExampleComponent.tsx +10 -14
  18. package/defaults/module/src/data/example-ontology.json +18 -18
  19. package/defaults/module/src/module.ts +3 -8
  20. package/defaults/module/src/ontologies/example-ontology.ts +8 -10
  21. package/defaults/module/src/shapes/ExampleShapeClass.ts +20 -21
  22. package/defaults/ontology.ts +18 -15
  23. package/defaults/package.json +28 -28
  24. package/defaults/site/package.json +38 -38
  25. package/defaults/site/storage/filestores/settings-production-template.jsonld +128 -128
  26. package/defaults/site/web/.htaccess +19 -19
  27. package/lib/cli.js +332 -258
  28. package/lib/config-grunt.js +39 -45
  29. package/lib/config-webpack.js +34 -39
  30. package/lib/index.js +5 -1
  31. package/lib/plugins/declaration-plugin.js +22 -64
  32. package/lib/plugins/externalise-modules.js +23 -13
  33. package/lib/plugins/watch-run.js +1 -1
  34. package/lib/utils.js +7 -3
  35. package/package.json +76 -72
  36. package/defaults/.npmignore +0 -11
  37. package/defaults/Gruntfile.js +0 -16
  38. package/defaults/module/Gruntfile.js +0 -16
  39. package/defaults/module/tsconfig-es5.json +0 -19
  40. package/defaults/module/tsconfig.json +0 -19
  41. package/defaults/site/.gitignore +0 -8
  42. package/defaults/site/.npmignore +0 -10
  43. package/defaults/site/lib/start-server.js +0 -22
  44. package/defaults/site/lib/test-server.js +0 -10
  45. package/defaults/site/storage/filestores/settings-development.jsonld +0 -117
  46. package/defaults/tsconfig-es5.json +0 -18
  47. package/defaults/tsconfig.json +0 -20
package/lib/cli.js CHANGED
@@ -46,6 +46,7 @@ var fs = require('fs-extra');
46
46
  var path = require('path');
47
47
  var glob = require('glob');
48
48
  var variables = {};
49
+ var open = require("open");
49
50
  function log() {
50
51
  var messages = [];
51
52
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -65,11 +66,36 @@ function warn() {
65
66
  // console.log(chalk.red(message));
66
67
  });
67
68
  }
68
- function checkModulePath(modulePath, res) {
69
+ function checkWorkspaces(rootPath, workspaces, res) {
70
+ // console.log('checking workspaces at '+rootPath+": "+workspaces.toString());
71
+ workspaces.forEach(function (workspace) {
72
+ var workspacePath = path.join(rootPath, workspace.replace('/*', ''));
73
+ if (workspace.indexOf('/*') !== -1) {
74
+ // console.log(workspacePath);
75
+ if (fs.existsSync(workspacePath)) {
76
+ var folders = fs.readdirSync(workspacePath);
77
+ folders.forEach(function (folder) {
78
+ if (folder !== './' && folder !== '../') {
79
+ checkModulePath(rootPath, path.join(workspacePath, folder), res);
80
+ }
81
+ });
82
+ }
83
+ }
84
+ else {
85
+ checkModulePath(rootPath, workspacePath, res);
86
+ }
87
+ });
88
+ }
89
+ function checkModulePath(rootPath, modulePath, res) {
69
90
  var packagePath = path.join(modulePath, 'package.json');
91
+ // console.log('checking '+packagePath);
70
92
  if (fs.existsSync(packagePath)) {
71
93
  var pack = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
72
- if (pack && pack.lincd === true) {
94
+ //some packages are not true lincd modules, but we still want them to be re-built automatically. This is what lincd_util is for
95
+ if (pack && pack.workspaces) {
96
+ checkWorkspaces(modulePath, pack.workspaces, res);
97
+ }
98
+ else if ((pack && pack.lincd === true) || pack.lincd_util === true) {
73
99
  res.push({
74
100
  path: modulePath,
75
101
  moduleName: pack.name,
@@ -86,8 +112,7 @@ function getLocalLincdModuleMap(rootPath) {
86
112
  if (rootPath === void 0) { rootPath = './'; }
87
113
  var map = new Map();
88
114
  getLincdModules(rootPath).forEach(function (module) {
89
- if (module.path.indexOf('../') === -1 &&
90
- module.path.indexOf('..\\') === -1) {
115
+ if (module.path.indexOf('../') === -1 && module.path.indexOf('..\\') === -1) {
91
116
  // console.log(module.path);
92
117
  map.set(module.moduleName, module);
93
118
  }
@@ -105,7 +130,7 @@ function getLincdModules(rootPath) {
105
130
  //TODO: read from package.json what the workspaces are. for each, follow up all the folders inside that path
106
131
  //TODO: then return an array with objects that have both the module name + the path. And then use that path across this whenever this function is called
107
132
  //TODO: this way it will work with websites as well, instead of just from the main LINCD repository
108
- var pack = utils_1.getPackageJSON();
133
+ var pack = (0, utils_1.getPackageJSON)();
109
134
  var res = [];
110
135
  if (!pack.workspaces) {
111
136
  warn(chalk.red('Could not find package workspaces. Make sure you run this command from a yarn workspace.'));
@@ -113,23 +138,7 @@ function getLincdModules(rootPath) {
113
138
  process.exit();
114
139
  }
115
140
  //TODO: filter with package.lincd = true?
116
- pack.workspaces.forEach(function (workspace) {
117
- var workspacePath = path.join(rootPath, workspace.replace('/*', ''));
118
- if (workspace.indexOf('/*') !== -1) {
119
- // console.log(workspacePath);
120
- if (fs.existsSync(workspacePath)) {
121
- var folders = fs.readdirSync(workspacePath);
122
- folders.forEach(function (folder) {
123
- if (folder !== './' && folder !== '../') {
124
- checkModulePath(path.join(workspacePath, folder), res);
125
- }
126
- });
127
- }
128
- }
129
- else {
130
- checkModulePath(workspacePath, res);
131
- }
132
- });
141
+ checkWorkspaces(rootPath, pack.workspaces, res);
133
142
  // console.log(res);
134
143
  return res;
135
144
  }
@@ -244,9 +253,7 @@ var replaceCurlyVariables = function (string) {
244
253
  }
245
254
  return string;
246
255
  };
247
- var capitalize = function (str) {
248
- return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1);
249
- };
256
+ var capitalize = function (str) { return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1); };
250
257
  var camelCase = function (str) {
251
258
  var string = str
252
259
  .toLowerCase()
@@ -255,51 +262,128 @@ var camelCase = function (str) {
255
262
  .reduce(function (result, word) { return result + capitalize(word.toLowerCase()); });
256
263
  return string.charAt(0).toLowerCase() + string.slice(1);
257
264
  };
258
- program.command('init [name] [uribase]').action(function (name, uriBase) {
259
- return initModule(name, uriBase);
265
+ program.command('create-app [name] [uribase]').action(function (name, uriBase) {
266
+ return createApp(name, uriBase);
260
267
  });
261
- var initModule = function (name, uriBase, basePath) {
268
+ program.command('create-module [name] [uribase]').action(function (name, uriBase) {
269
+ return createModule(name, uriBase);
270
+ });
271
+ var createModule = function (name, uriBase, basePath) {
262
272
  if (basePath === void 0) { basePath = process.cwd(); }
263
- if (!uriBase) {
264
- uriBase = '[INSERT_URI_BASE]';
265
- }
266
- if (!name) {
267
- if (fs.existsSync(path.join(basePath, 'package.json'))) {
268
- var pack = require(path.join(basePath, 'package.json'));
269
- //find @scope and the next part between 2 slashes after
270
- //so @dacore/some-mod/lib/file.js
271
- // --> match[0] = @dacore/some-mod
272
- // --> match[1] = @dacore
273
- // --> match[2] = some-mod
274
- var _a = pack.name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
275
- name = cleanPackageName;
276
- }
277
- else {
278
- name = path.basename(process.cwd());
279
- }
280
- }
281
- // console.log(
282
- // 'Copying ' +
283
- // path.join(__dirname, '..', 'defaults', 'module') +
284
- // '\nto ' +
285
- // basePath,
286
- // );
287
- fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), basePath);
288
- var camelCaseModuleName = camelCase(name); //some-module --> someModule
289
- var underscoreModuleName = name.replace(/[-\s]+/g, '_');
290
- setVariable('uri_base', uriBase);
291
- //longer similar variables names should come before the shorter ones
292
- setVariable('camel_module_name', camelCaseModuleName);
293
- setVariable('underscore_module_name', underscoreModuleName);
294
- setVariable('module_name', name);
295
- log("Creating new lincd module '" + name + "'");
296
- //replace variables in some of the copied files
297
- ['package.json', 'Gruntfile.js', 'src/module.ts']
298
- .map(function (f) { return path.join(basePath, f); })
299
- .forEach(function (file) {
300
- replaceVariablesInFile(file);
273
+ return __awaiter(void 0, void 0, void 0, function () {
274
+ var targetFolder, _a, packageName, scope, cleanPackageName, codeName, cameCaseName, underscoreName, version, installCommand;
275
+ return __generator(this, function (_b) {
276
+ switch (_b.label) {
277
+ case 0:
278
+ //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)
279
+ //so we manually find a modules folder, if it exists we go into that.
280
+ if (fs.existsSync(path.join(basePath, 'modules'))) {
281
+ basePath = path.join(basePath, 'modules');
282
+ }
283
+ targetFolder = path.join(basePath, name);
284
+ console.log(targetFolder, basePath, name);
285
+ if (!fs.existsSync(targetFolder)) {
286
+ fs.mkdirSync(targetFolder);
287
+ }
288
+ if (!uriBase) {
289
+ uriBase = 'http://lincd.org/ont/' + name;
290
+ }
291
+ if (!name) {
292
+ console.warn("Please provide a name as the first argument");
293
+ }
294
+ _a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
295
+ // console.log(
296
+ // 'Copying ' +
297
+ // path.join(__dirname, '..', 'defaults', 'module') +
298
+ // '\nto ' +
299
+ // basePath,
300
+ // );
301
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), targetFolder);
302
+ codeName = cleanPackageName.replace(/\-/g, '_');
303
+ cameCaseName = camelCase(name);
304
+ underscoreName = name.replace(/[-\s]+/g, '_');
305
+ setVariable('uri_base', uriBase);
306
+ //longer similar variables names should come before the shorter ones
307
+ setVariable('camel_module_name', cameCaseName);
308
+ setVariable('underscore_module_name', underscoreName);
309
+ setVariable('module_name', name);
310
+ log("Creating new LINCD module '" + name + "'");
311
+ //replace variables in some of the copied files
312
+ ['package.json', 'Gruntfile.js', 'src/module.ts']
313
+ .map(function (f) { return path.join(targetFolder, f); })
314
+ .forEach(function (file) {
315
+ replaceVariablesInFile(file);
316
+ });
317
+ return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
318
+ console.log("yarn probably not working");
319
+ return '';
320
+ })];
321
+ case 1:
322
+ version = _b.sent();
323
+ installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
324
+ return [4 /*yield*/, execp("cd ".concat(targetFolder, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
325
+ console.warn("Could not install dependencies");
326
+ })];
327
+ case 2:
328
+ _b.sent();
329
+ 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"));
330
+ return [2 /*return*/];
331
+ }
332
+ });
333
+ });
334
+ };
335
+ var createApp = function (name, uriBase, basePath) {
336
+ if (basePath === void 0) { basePath = process.cwd(); }
337
+ return __awaiter(void 0, void 0, void 0, function () {
338
+ var _a, packageName, scope, cleanPackageName, targetFolder, codeName, cameCaseName, underscoreName, version, installCommand;
339
+ return __generator(this, function (_b) {
340
+ switch (_b.label) {
341
+ case 0:
342
+ if (!name) {
343
+ console.warn("Please provide a name as the first argument");
344
+ }
345
+ _a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
346
+ if (!uriBase) {
347
+ uriBase = 'http://lincd.org/ont/' + name;
348
+ }
349
+ targetFolder = path.join(basePath, name);
350
+ if (!fs.existsSync(targetFolder)) {
351
+ fs.mkdirSync(targetFolder);
352
+ }
353
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
354
+ codeName = cleanPackageName.replace(/\-/g, '_');
355
+ cameCaseName = camelCase(name);
356
+ underscoreName = name.replace(/[-\s]+/g, '_');
357
+ setVariable('uri_base', uriBase);
358
+ //longer similar variables names should come before the shorter ones
359
+ setVariable('camelcase_name', cameCaseName);
360
+ setVariable('underscore_name', underscoreName);
361
+ setVariable('app_name', name);
362
+ log("Creating new LINCD application '" + name + "'");
363
+ //replace variables in some of the copied files
364
+ ['package.json', 'index.html', 'Gruntfile.js', 'src/index.tsx', 'src/App.tsx']
365
+ .map(function (f) { return path.join(targetFolder, f); })
366
+ .forEach(function (file) {
367
+ replaceVariablesInFile(file);
368
+ });
369
+ return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
370
+ console.log("yarn probably not working");
371
+ return '';
372
+ })];
373
+ case 1:
374
+ version = _b.sent();
375
+ installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
376
+ return [4 /*yield*/, execp("cd ".concat(name, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
377
+ console.warn("Could not install dependencies");
378
+ })];
379
+ case 2:
380
+ _b.sent();
381
+ open(path.join(targetFolder, 'index.html'));
382
+ log("Your LINCD App starting setup is ready.", "Run ".concat(chalk.blueBright('cd ' + name), " and then run \n the ").concat(chalk.blueBright('build'), " script to build once or \n the ").concat(chalk.blueBright('dev'), " script to continuously rebuild on file changes"));
383
+ return [2 /*return*/];
384
+ }
385
+ });
301
386
  });
302
- log("Prepared all files.", "Run " + chalk.blueBright('yarn') + " or " + chalk.blueBright('npm install') + " to install the dependencies.", "Then run " + chalk.blueBright('yarn build') + " to build once or " + chalk.blueBright('yarn dev') + " to continuously rebuild on file changes");
303
387
  };
304
388
  var getNextVersion = function (version) {
305
389
  var parts = version.split('.');
@@ -314,8 +398,7 @@ var getNextMinorVersion = function (version) {
314
398
  return parts[0] + '.' + (parseInt(parts[1]) + 1).toString() + '.0';
315
399
  };
316
400
  var buildFailed = function (output) {
317
- return (output.indexOf('Aborted due to warnings') !== -1 &&
318
- output.indexOf('Command failed') !== -1);
401
+ return output.indexOf('Aborted due to warnings') !== -1 && output.indexOf('Command failed') !== -1;
319
402
  };
320
403
  /*program.command('shapes').action(async () => {
321
404
  //we've imported require-extensions from npm so that we can use this
@@ -359,9 +442,11 @@ program.command('register [version]').action(function (newVersion) {
359
442
  var pack = JSON.parse(fs.readFileSync(process.cwd() + '/package.json', 'utf8'));
360
443
  var version = pack.version;
361
444
  var moduleName = pack.name;
362
- console.log(chalk.cyan('registering ' + moduleName + ' ' + version + ' in the LINCD registry'));
445
+ var author = pack.author;
446
+ // let displayName = pack.displayName;
447
+ console.log(chalk.cyan('registering ' + author + "'s module, " + moduleName + ' ' + version + ' in the LINCD registry'));
363
448
  //temporary test code
364
- return fetch('http://localhost:3000/register', {
449
+ return fetch('http://localhost:4001/register', {
365
450
  method: 'POST',
366
451
  headers: {
367
452
  Accept: 'application/json, text/plain, */*',
@@ -369,64 +454,69 @@ program.command('register [version]').action(function (newVersion) {
369
454
  },
370
455
  body: JSON.stringify({ package: moduleName, version: version })
371
456
  })
372
- .then(function (res) { return res.text(); })
373
- .then(function (text) {
374
- console.log(chalk.cyan('Response: ') + chalk.italic(text));
457
+ .then(function (res) { return res.json(); })
458
+ .then(function (json) {
459
+ if (json.error) {
460
+ console.log(chalk.red('Response: ' + json.error));
461
+ }
462
+ else if (json.result) {
463
+ console.log(chalk.cyan('Response: ') + json.result);
464
+ }
375
465
  })["catch"](function (err) {
376
466
  console.warn('Could not connect to LINCD registry');
377
467
  });
378
468
  /*console.log(chalk.cyan('building production bundles'));
379
469
  return execPromise('yarn lincd build production', false, true)
380
- .then((output: string) => {
381
- if (buildFailed(output)) {
382
- // console.warn("Build failed:");
383
- console.log(output);
384
- throw new Error('build failed');
385
- }
386
- pack.version = newVersion;
387
- //save package.json
388
- return fs.writeFileSync(
389
- path.join(process.cwd(), 'package.json'),
390
- JSON.stringify(pack, null, 2),
391
- );
392
- })
393
- .then((version) => {
394
- console.log(chalk.cyan('Committing to git'));
395
- //we have just changed package.json, so there will be things "uncommitted"
396
- //to make sure this module does not automatically come up as "needing to be published" we need to commit this change here straight away
397
- //so: add all files not added yet in the folder of this module
398
- //then commit all changes (including new version number in package.json)
399
- //then add a version commit git flag
400
- return execPromise(
401
- `git add -- ./ & git commit -m "publishing ${moduleName} ${newVersion}" -- ./ & git tag ${moduleName}@${newVersion}"`,
402
- );
403
- })
404
- .then((version) => {
405
- console.log(chalk.cyan('Publishing ' + moduleName + ' ' + newVersion));
406
-
407
- // let tag = moduleName+'@'+version;
408
- return execPromise('yarn publish --new-version ' + newVersion, true);
409
- })
410
- .then((res) => {
411
- if (
412
- res.indexOf('Aborted due to warnings') !== -1 ||
413
- res.indexOf('Could not publish') !== -1 ||
414
- res.indexOf("Couldn't publish") !== -1
415
- ) {
416
- console.log(chalk.red('Failed to publish'));
417
- return false;
418
- } else {
419
- var pack = JSON.parse(
420
- fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
421
- );
422
- version = pack.version;
423
- console.log(chalk.green('Published ' + version));
424
- return true;
425
- }
426
- })
427
- .catch((err) => {
428
- console.warn(chalk.red('Could not publish: ' + err));
429
- });*/
470
+ .then((output: string) => {
471
+ if (buildFailed(output)) {
472
+ // console.warn("Build failed:");
473
+ console.log(output);
474
+ throw new Error('build failed');
475
+ }
476
+ pack.version = newVersion;
477
+ //save package.json
478
+ return fs.writeFileSync(
479
+ path.join(process.cwd(), 'package.json'),
480
+ JSON.stringify(pack, null, 2),
481
+ );
482
+ })
483
+ .then((version) => {
484
+ console.log(chalk.cyan('Committing to git'));
485
+ //we have just changed package.json, so there will be things "uncommitted"
486
+ //to make sure this module does not automatically come up as "needing to be published" we need to commit this change here straight away
487
+ //so: add all files not added yet in the folder of this module
488
+ //then commit all changes (including new version number in package.json)
489
+ //then add a version commit git flag
490
+ return execPromise(
491
+ `git add -- ./ & git commit -m "publishing ${moduleName} ${newVersion}" -- ./ & git tag ${moduleName}@${newVersion}"`,
492
+ );
493
+ })
494
+ .then((version) => {
495
+ console.log(chalk.cyan('Publishing ' + moduleName + ' ' + newVersion));
496
+
497
+ // let tag = moduleName+'@'+version;
498
+ return execPromise('yarn publish --new-version ' + newVersion, true);
499
+ })
500
+ .then((res) => {
501
+ if (
502
+ res.indexOf('Aborted due to warnings') !== -1 ||
503
+ res.indexOf('Could not publish') !== -1 ||
504
+ res.indexOf("Couldn't publish") !== -1
505
+ ) {
506
+ console.log(chalk.red('Failed to publish'));
507
+ return false;
508
+ } else {
509
+ var pack = JSON.parse(
510
+ fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
511
+ );
512
+ version = pack.version;
513
+ console.log(chalk.green('Published ' + version));
514
+ return true;
515
+ }
516
+ })
517
+ .catch((err) => {
518
+ console.warn(chalk.red('Could not publish: ' + err));
519
+ });*/
430
520
  }
431
521
  else {
432
522
  console.warn('not found: ' + process.cwd() + '/package.json');
@@ -485,7 +575,7 @@ var buildModule = function (target, target2, modulePath, logResults) {
485
575
  if (logResults === void 0) { logResults = true; }
486
576
  if (target == 'production' || target == 'es5' || target == 'es6' || !target) {
487
577
  if (!fs.existsSync(path.join(modulePath, 'Gruntfile.js'))) {
488
- console.warn("No Gruntfile found at " + modulePath + "\\Gruntfile.js. Cannot build.");
578
+ console.warn("No Gruntfile found at ".concat(modulePath, "\\Gruntfile.js. Cannot build."));
489
579
  return;
490
580
  }
491
581
  var nodeEnv = '';
@@ -513,11 +603,7 @@ var buildModule = function (target, target2, modulePath, logResults) {
513
603
  ' --color');
514
604
  var method = logResults ? execp : execPromise;
515
605
  //execute the command to build the method, and provide the current work directory as option
516
- return method(nodeEnv +
517
- 'grunt build' +
518
- (target ? '-' + target : '') +
519
- (target2 ? '-' + target2 : '') +
520
- ' --color', false, false, { cwd: modulePath })["catch"](function (err) {
606
+ return method(nodeEnv + 'grunt build' + (target ? '-' + target : '') + (target2 ? '-' + target2 : '') + ' --color', false, false, { cwd: modulePath })["catch"](function (err) {
521
607
  process.exit(1);
522
608
  });
523
609
  }
@@ -539,7 +625,7 @@ var getLastModifiedSourceTime = function (modulePath) {
539
625
  var getLastCommitTime = function (modulePath) {
540
626
  // console.log(`git log -1 --format=%ci -- ${modulePath}`);
541
627
  // process.exit();
542
- return execPromise("git log -1 --format=%ci -- " + modulePath).then(function (result) {
628
+ return execPromise("git log -1 --format=%ci -- ".concat(modulePath)).then(function (result) {
543
629
  var lastCommit = new Date(result);
544
630
  // console.log(modulePath,result,lastCommit);
545
631
  return lastCommit;
@@ -614,9 +700,7 @@ var publishUpdated = function (test) {
614
700
  catch (err) {
615
701
  chalk.red(module.moduleName + ' failed: ' + err.message + '\n');
616
702
  console.warn('Returned JSON from npm: ' + output);
617
- return [2 /*return*/, (previousResult +
618
- ' ' +
619
- chalk.red(module.moduleName + ' failed: ' + err.message + '\n'))];
703
+ return [2 /*return*/, previousResult + ' ' + chalk.red(module.moduleName + ' failed: ' + err.message + '\n')];
620
704
  }
621
705
  lastPublish = info.data.time[info.data.version];
622
706
  lastPublishDate = new Date(lastPublish);
@@ -624,15 +708,8 @@ var publishUpdated = function (test) {
624
708
  return [4 /*yield*/, getLastCommitTime(module.path)];
625
709
  case 1:
626
710
  lastCommit = _b.sent();
627
- console.log(lastPublishDate.toDateString() +
628
- ' ' +
629
- lastPublishDate.toTimeString() +
630
- ' published ' +
631
- info.data.version);
632
- console.log(lastCommit.toDateString() +
633
- ' ' +
634
- new Date(lastCommit).toTimeString() +
635
- ' source last committed');
711
+ console.log(lastPublishDate.toDateString() + ' ' + lastPublishDate.toTimeString() + ' published ' + info.data.version);
712
+ console.log(lastCommit.toDateString() + ' ' + new Date(lastCommit).toTimeString() + ' source last committed');
636
713
  // console.log(lastModified.toDateString() + ' ' + new Date(lastModified).toTimeString() + ' source ' + lastModifiedName + ' last edited');
637
714
  //NOTE: removed lastModified, because switching branches will say that the file was modified and cause everything to publish
638
715
  //SO: now you NEED TO commit before it picks up that you should publish
@@ -657,7 +734,7 @@ var publishUpdated = function (test) {
657
734
  });
658
735
  }); })["catch"](function (err) {
659
736
  console.log(err);
660
- return (previousResult + ' ' + chalk.red(module.moduleName + ' failed\n'));
737
+ return previousResult + ' ' + chalk.red(module.moduleName + ' failed\n');
661
738
  });
662
739
  });
663
740
  });
@@ -672,12 +749,7 @@ var publishUpdated = function (test) {
672
749
  };
673
750
  var executeSingleBuild = function (module, previousResult, test, info) {
674
751
  var nextVersion = info ? getNextVersion(info.data.version) : '';
675
- console.log(chalk.blue('--> ' +
676
- (test ? 'should publish' : 'publishing') +
677
- ' ' +
678
- module.moduleName +
679
- ' ' +
680
- nextVersion));
752
+ console.log(chalk.blue('--> ' + (test ? 'should publish' : 'publishing') + ' ' + module.moduleName + ' ' + nextVersion));
681
753
  if (!test) {
682
754
  return execPromise('cd ' + module.path + ' && yarn lincd register', true)
683
755
  .then(function (res) {
@@ -685,12 +757,10 @@ var executeSingleBuild = function (module, previousResult, test, info) {
685
757
  res.indexOf('Could not publish') !== -1 ||
686
758
  res.indexOf("Couldn't publish") !== -1) {
687
759
  console.log(res);
688
- return (previousResult + ' ' + chalk.red(module.moduleName + ' failed\n'));
760
+ return previousResult + ' ' + chalk.red(module.moduleName + ' failed\n');
689
761
  }
690
762
  console.log(chalk.green('Successfully published ' + nextVersion));
691
- return (previousResult +
692
- ' ' +
693
- chalk.green(module.moduleName + ' published ' + nextVersion + '\n'));
763
+ return previousResult + ' ' + chalk.green(module.moduleName + ' published ' + nextVersion + '\n');
694
764
  })["catch"](function (err) {
695
765
  console.log(chalk.red('Failed to publish: ' + err));
696
766
  return chalk.red('Failed to publish: ' + err);
@@ -698,82 +768,74 @@ var executeSingleBuild = function (module, previousResult, test, info) {
698
768
  }
699
769
  else {
700
770
  //when testing what needs to be published
701
- return (previousResult + ' ' + chalk.blue(module.moduleName + ' should publish\n'));
771
+ return previousResult + ' ' + chalk.blue(module.moduleName + ' should publish\n');
702
772
  }
703
773
  };
704
- program
705
- .command('build-updated [target] [target2]')
706
- .action(function (target, target2) {
774
+ program.command('build-updated [target] [target2]').action(function (target, target2) {
707
775
  return buildUpdated(1, target, target2);
708
776
  });
709
- program
710
- .command('build-updated-since [num-commits-back] [target] [target2]')
711
- .action(function (back, target, target2) {
777
+ program.command('build-updated-since [num-commits-back] [target] [target2]').action(function (back, target, target2) {
712
778
  return buildUpdated(back, target, target2);
713
779
  });
714
780
  var buildUpdated = function (back, target, target2, test) {
715
781
  if (test === void 0) { test = false; }
716
- back = back || 1;
717
- return execPromise("git log -" + back + " --format=%ci").then(function (result) {
718
- var lastCommit = new Date(result);
719
- var previousResult = '';
720
- log((test ? 'Checking which modules' : 'Building all modules that') +
721
- ' have been changed since last commit on ' +
722
- lastCommit.toString());
723
- var modules = getLocalLincdModules();
724
- var p = Promise.resolve('');
725
- modules.forEach(function (module) {
726
- var moduleName = module.moduleName;
727
- p = p
728
- .then(function (previousResult) {
729
- var lastModifiedSource = getLastModifiedSourceTime(module.path);
730
- var lastModifiedBundle = getLastBuildTime(module.path);
731
- // console.log(module.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
732
- // console.log(module.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
733
- console.log('# Checking module ' + moduleName);
734
- if (lastModifiedSource.lastModifiedTime >
735
- lastModifiedBundle.lastModifiedTime) {
736
- // log(moduleName+' modified since last commit on '+lastCommit.toString());
737
- console.log(chalk.cyan('Last modified source: ' +
738
- lastModifiedSource.lastModifiedName +
739
- ' on ' +
740
- lastModifiedSource.lastModified.toString()));
741
- console.log(chalk.cyan('Last build: ' + lastModifiedBundle.lastModified.toString()));
742
- log('--> ' + (test ? 'need to build ' : 'building ') + moduleName);
743
- if (!test) {
744
- return execPromise('cd ' +
745
- module.path +
746
- ' && yarn lincd build' +
747
- (target ? ' ' + target : '') +
748
- (target2 ? ' ' + target2 : '')).then(function (res) {
749
- if (res.indexOf('Aborted due to warnings') !== -1 ||
750
- res.indexOf('Fatal error') !== -1) {
751
- console.log(res);
752
- return (previousResult + ' ' + chalk.red(moduleName + ' failed\n'));
753
- }
754
- console.log(chalk.green(moduleName + ' bundles successfully built'));
755
- return (previousResult + ' ' + chalk.green(moduleName + ' built\n'));
756
- });
757
- }
758
- return (previousResult +
759
- ' ' +
760
- chalk.blue(moduleName + ' should be build\n'));
782
+ // back = back || 1;
783
+ // return execPromise(`git log -${back} --format=%ci`).then((result) => {
784
+ // let now = new Date();
785
+ var previousResult = '';
786
+ log((test ? 'Checking which modules' : 'Building all modules that') + ' have been changed since their last built ');
787
+ var modules = getLocalLincdModules();
788
+ //TODO: sort all these modules in the order of their dependencies.
789
+ // To do so, see build-all command and put some of the functionality (like getting modules that depend on a module) in reusable functions
790
+ var p = Promise.resolve('');
791
+ modules.forEach(function (module) {
792
+ var moduleName = module.moduleName;
793
+ p = p
794
+ .then(function (previousResult) {
795
+ var lastModifiedSource = getLastModifiedSourceTime(module.path);
796
+ var lastModifiedBundle = getLastBuildTime(module.path);
797
+ // console.log(module.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
798
+ // console.log(module.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
799
+ console.log('# Checking module ' + moduleName);
800
+ if (lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime) {
801
+ //TODO: when building a module, also rebuild all modules that depend on this module.. and iteratively build modules that depend on those modules..
802
+ // log(moduleName+' modified since last commit on '+now.toString());
803
+ console.log(chalk.cyan('Last modified source: ' +
804
+ lastModifiedSource.lastModifiedName +
805
+ ' on ' +
806
+ lastModifiedSource.lastModified.toString()));
807
+ console.log(chalk.cyan('Last build: ' +
808
+ (lastModifiedBundle && typeof lastModifiedBundle.lastModified !== 'undefined'
809
+ ? lastModifiedBundle.lastModified.toString()
810
+ : 'never')));
811
+ log('--> ' + (test ? 'need to build ' : 'building ') + moduleName);
812
+ if (!test) {
813
+ return execPromise('cd ' + module.path + ' && yarn build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : '')).then(function (res) {
814
+ if (res.indexOf('Aborted due to warnings') !== -1 || res.indexOf('Fatal error') !== -1) {
815
+ console.log(res);
816
+ return previousResult + ' ' + chalk.red(moduleName + ' failed\n');
817
+ }
818
+ console.log(chalk.green(moduleName + ' bundles successfully built'));
819
+ return previousResult + ' ' + chalk.green(moduleName + ' built\n');
820
+ });
761
821
  }
762
- return previousResult;
763
- })["catch"](function (err) {
764
- console.log(err);
765
- return previousResult + ' ' + chalk.red(moduleName + ' failed\n');
766
- });
767
- });
768
- return p.then(function (messages) {
769
- if (messages == '') {
770
- console.log(chalk.green('Nothing to rebuild.'));
771
- }
772
- else {
773
- console.log('Summary: \n' + messages);
822
+ return previousResult + ' ' + chalk.blue(moduleName + ' should be build\n');
774
823
  }
824
+ return previousResult;
825
+ })["catch"](function (err) {
826
+ console.log(err);
827
+ return previousResult + ' ' + chalk.red(moduleName + ' failed\n');
775
828
  });
776
829
  });
830
+ return p.then(function (messages) {
831
+ if (messages == '') {
832
+ console.log(chalk.green('Nothing to rebuild.'));
833
+ }
834
+ else {
835
+ console.log('Summary: \n' + messages);
836
+ }
837
+ });
838
+ // });
777
839
  };
778
840
  program.command('build-all [target] [target2]').action(function (target, target2) {
779
841
  var dependencies = new Map();
@@ -782,7 +844,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
782
844
  //get dependencies of each module
783
845
  var leastDependentModule;
784
846
  modules.forEach(function (module) {
785
- var pack = utils_1.getPackageJSON(module.path);
847
+ var pack = (0, utils_1.getPackageJSON)(module.path);
786
848
  if (pack) {
787
849
  //get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
788
850
  var moduleDependencies = Object.keys(pack.dependencies)
@@ -796,7 +858,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
796
858
  });
797
859
  dependencies.forEach(function (moduleDependencies, module) {
798
860
  if (!moduleDependencies.some(function (dependency) {
799
- return (typeof dependency !== 'string' && modules.has(dependency.moduleName));
861
+ return typeof dependency !== 'string' && modules.has(dependency.moduleName);
800
862
  })) {
801
863
  leastDependentModule = module;
802
864
  }
@@ -834,8 +896,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
834
896
  //if we're skipping builds until a certain module
835
897
  if (!building) {
836
898
  //if the module name matches the module we're supposed to start from then start building modules
837
- if (module.moduleName == startFrom ||
838
- module.packageName == startFrom) {
899
+ if (module.moduleName == startFrom || module.packageName == startFrom) {
839
900
  building = true;
840
901
  }
841
902
  //else still waiting for the module
@@ -868,7 +929,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
868
929
  ' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
869
930
  console.log(chalk.cyanBright('tip ') +
870
931
  'Run ' +
871
- chalk.green("yarn build-all from " + module.moduleName) +
932
+ chalk.green("lincd build-all from ".concat(module.moduleName)) +
872
933
  ' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
873
934
  process.exit(1);
874
935
  }
@@ -897,8 +958,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
897
958
  //but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
898
959
  if (!done.has(module) &&
899
960
  deps.every(function (dependency) {
900
- return (typeof dependency !== 'string' &&
901
- (done.has(dependency) || !modules.has(dependency.moduleName)));
961
+ return typeof dependency !== 'string' && (done.has(dependency) || !modules.has(dependency.moduleName));
902
962
  })) {
903
963
  stack.push(module);
904
964
  }
@@ -955,16 +1015,27 @@ program.command('build-all [target] [target2]').action(function (target, target2
955
1015
  //starts the process
956
1016
  runStack();
957
1017
  });
958
- program
959
- .command('modules [action] [includedSpaces]')
960
- .action(function (command, includedSpaces) {
1018
+ program.command('modules [action] [includedSpaces]').action(function (command, includedSpaces) {
961
1019
  executeCommandForEachModule(getLincdModules(), command, includedSpaces);
962
1020
  });
963
- program
964
- .command('modules-except [excludedSpaces] [action]')
965
- .action(function (excludedSpaces, command) {
1021
+ program.command('modules-except [excludedSpaces] [action]').action(function (excludedSpaces, command) {
966
1022
  executeCommandForEachModule(getLincdModules(), command, null, excludedSpaces);
967
1023
  });
1024
+ program
1025
+ .command('module|mod [module] [a1] [a2] [a3] [a4]')
1026
+ .action(function (module) {
1027
+ var args = [];
1028
+ for (var _i = 1; _i < arguments.length; _i++) {
1029
+ args[_i - 1] = arguments[_i];
1030
+ }
1031
+ var command = args
1032
+ .slice(0, 3)
1033
+ .filter(function (a) { return a && true; })
1034
+ .join(' ');
1035
+ executeCommandForModule(module, command);
1036
+ })
1037
+ .alias('mod')
1038
+ .alias('m');
968
1039
  var executeCommandForEachModule = function (modules, command, includedSpaces, excludedSpaces) {
969
1040
  //if a specific set of modules is given
970
1041
  if (includedSpaces) {
@@ -980,10 +1051,7 @@ var executeCommandForEachModule = function (modules, command, includedSpaces, ex
980
1051
  modules = modules.filter(function (module) { return excludedSpaces.indexOf(module.moduleName) === -1; });
981
1052
  log('Filtering excluded spaces');
982
1053
  }
983
- log("Executing '" +
984
- command +
985
- "' on modules " +
986
- modules.map(function (m) { return m.moduleName; }).join(', '));
1054
+ log("Executing '" + command + "' on modules " + modules.map(function (m) { return m.moduleName; }).join(', '));
987
1055
  var p = Promise.resolve(true);
988
1056
  modules.forEach(function (module) {
989
1057
  p = p.then(function () {
@@ -993,6 +1061,15 @@ var executeCommandForEachModule = function (modules, command, includedSpaces, ex
993
1061
  });
994
1062
  return p;
995
1063
  };
1064
+ var executeCommandForModule = function (module, command) {
1065
+ var moduleDetails = getLincdModules().find(function (modDetails) {
1066
+ return modDetails.packageName.indexOf(module) !== -1 || modDetails.moduleName.indexOf(module) !== -1;
1067
+ });
1068
+ if (moduleDetails) {
1069
+ log("Executing 'cd " + moduleDetails.path + ' && lincd ' + command + "'");
1070
+ return execp('cd ' + moduleDetails.path + ' && lincd ' + command);
1071
+ }
1072
+ };
996
1073
  program.command('dev [target] [mode]').action(function (target, mode) {
997
1074
  if (!target)
998
1075
  target = 'es6';
@@ -1003,14 +1080,8 @@ program.command('dev [target] [mode]').action(function (target, mode) {
1003
1080
  if (target == 'es5' || target == 'es6') {
1004
1081
  // log('> Starting continuous development build for '+target+' target')
1005
1082
  log('starting continuous development build');
1006
- log('grunt dev' +
1007
- (target ? '-' + target : '') +
1008
- (mode ? '-' + mode : '') +
1009
- ' --color');
1010
- var command = exec('grunt dev' +
1011
- (target ? '-' + target : '') +
1012
- (mode ? '-' + mode : '') +
1013
- ' --color');
1083
+ log('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
1084
+ var command = exec('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
1014
1085
  command.stdout.pipe(process.stdout);
1015
1086
  command.stderr.pipe(process.stderr);
1016
1087
  }
@@ -1026,7 +1097,7 @@ program.command('*').action(function (command) {
1026
1097
  logHelp();
1027
1098
  });
1028
1099
  function logHelp() {
1029
- var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
1100
+ var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
1030
1101
  console.log('lincd-cli ' + ownPackage.version);
1031
1102
  console.log(chalk.green('\nAvailable commands from a module:'));
1032
1103
  console.log(chalk.blue('- build [es5|es6|production] [es5|es6] ') +
@@ -1043,32 +1114,35 @@ function logHelp() {
1043
1114
  chalk.cyan('- publish new version to the npm registry AND to the LINCD.org registry'));
1044
1115
  //TODO: these all need to be tested to see if they work with the new LINCD setup
1045
1116
  console.log(chalk.green('\nAvailable commands from a yarn workspace:'));
1117
+ console.log(chalk.blue('- modules|mod|m module-name ...command') +
1118
+ chalk.cyan('- execute a lincd command for a specific module in this workspace. Use can use partial packageNames. So `lincd m xsd build` will trigger `lincd build` for the module lincd-xsd'));
1046
1119
  console.log(chalk.blue('- build-all [from] [module-name]') +
1047
1120
  chalk.cyan('- build all modules in order of dependencies. To continue later from a specific module, add `from {modulename}`'));
1121
+ console.log(chalk.blue('- build-updated') +
1122
+ chalk.cyan('- build only those modules that have updated their source since their last local built'));
1048
1123
  /*
1049
1124
  console.log(
1050
- chalk.blue('- build-updated [n] ') +
1051
- chalk.cyan(
1052
- '- build only those modules that have updated their source since the last local commit (or optionally n commits back',
1053
- ),
1125
+ chalk.blue('- build-updated [n] ') +
1126
+ chalk.cyan(
1127
+ '- build only those modules that have updated their source since the last local commit (or optionally n commits back',
1128
+ ),
1054
1129
  );
1055
1130
  console.log(
1056
- chalk.blue('- modules [action]') +
1057
- chalk.cyan('- execute a command for all modules'),
1131
+ chalk.blue('- modules [action]') +
1132
+ chalk.cyan('- execute a command for all modules'),
1058
1133
  );
1059
1134
  console.log(
1060
- chalk.blue('- publish-updated [message] ') +
1061
- chalk.cyan(
1062
- "- publish all modules who's source changes have been committed to git since the last published version.",
1063
- ),
1135
+ chalk.blue('- publish-updated [message] ') +
1136
+ chalk.cyan(
1137
+ "- publish all modules who's source changes have been committed to git since the last published version.",
1138
+ ),
1064
1139
  );
1065
1140
  console.log(
1066
- chalk.blue('- status') +
1067
- chalk.cyan('- see which modules need to be published or build'),
1141
+ chalk.blue('- status') +
1142
+ chalk.cyan('- see which modules need to be published or build'),
1068
1143
  );*/
1069
1144
  console.log(chalk.green('\nOther commands:'));
1070
- console.log(chalk.blue('- info ') +
1071
- chalk.cyan('- print the version of this tool and where it runs from'));
1145
+ console.log(chalk.blue('- info ') + chalk.cyan('- print the version of this tool and where it runs from'));
1072
1146
  console.log(chalk.blue('- help ') + chalk.cyan('- print this message'));
1073
1147
  }
1074
1148
  program.parse(process.argv);