lincd-cli 0.1.5 → 0.1.8

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 (61) 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.js +30 -30
  9. package/defaults/defaultModule/Index.scss +16 -16
  10. package/defaults/defaultModule/Index.tsx +31 -24
  11. package/defaults/defaultModule/data.json +54 -54
  12. package/defaults/defaultModule/defaultOntology.json +21 -21
  13. package/defaults/defaultModule/index.ts +16 -12
  14. package/defaults/defaultModule/ontology.js +21 -21
  15. package/defaults/defaultModule/ontology.ts +18 -15
  16. package/defaults/gitignorefile +3 -3
  17. package/defaults/index.ts +17 -13
  18. package/defaults/module/package.json +30 -30
  19. package/defaults/module/src/components/ExampleComponent.tsx +18 -22
  20. package/defaults/module/src/data/example-ontology.json +20 -20
  21. package/defaults/module/src/data/example-ontology.json.d.ts +1 -1
  22. package/defaults/module/src/index.ts +7 -7
  23. package/defaults/module/src/module.ts +4 -9
  24. package/defaults/module/src/ontologies/example-ontology.ts +30 -33
  25. package/defaults/module/src/shapes/ExampleShapeClass.ts +29 -30
  26. package/defaults/ontology.ts +18 -15
  27. package/defaults/package.json +28 -28
  28. package/defaults/site/package.json +40 -40
  29. package/defaults/site/storage/filestores/settings-production-template.jsonld +128 -128
  30. package/defaults/site/web/.htaccess +19 -19
  31. package/lib/cli.js +359 -224
  32. package/lib/config-grunt.js +37 -43
  33. package/lib/config-webpack.js +30 -29
  34. package/lib/index.js +5 -1
  35. package/lib/plugins/declaration-plugin.js +22 -64
  36. package/lib/plugins/externalise-modules.js +17 -23
  37. package/lib/plugins/watch-run.js +1 -1
  38. package/lib/utils.js +5 -1
  39. package/package.json +77 -73
  40. package/defaults/.npmignore +0 -11
  41. package/defaults/Gruntfile.js +0 -16
  42. package/defaults/module/Gruntfile.js +0 -16
  43. package/defaults/module/tsconfig-es5.json +0 -21
  44. package/defaults/module/tsconfig.json +0 -21
  45. package/defaults/site/.gitignore +0 -8
  46. package/defaults/site/.npmignore +0 -10
  47. package/defaults/site/lib/start-server.js +0 -22
  48. package/defaults/site/lib/test-server.js +0 -10
  49. package/defaults/site/storage/filestores/settings-development.jsonld +0 -117
  50. package/defaults/tsconfig-es5.json +0 -18
  51. package/defaults/tsconfig.json +0 -20
  52. package/src/cli.js +0 -1209
  53. package/src/config-grunt.js +0 -263
  54. package/src/config-webpack.js +0 -281
  55. package/src/index.js +0 -22
  56. package/src/interfaces.js +0 -2
  57. package/src/plugins/declaration-plugin.js +0 -248
  58. package/src/plugins/externalise-modules.js +0 -161
  59. package/src/plugins/shapes-plugin.js +0 -69
  60. package/src/plugins/watch-run.js +0 -47
  61. package/src/utils.js +0 -127
package/lib/cli.js CHANGED
@@ -36,6 +36,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
37
  }
38
38
  };
39
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
40
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
41
+ if (ar || !(i in from)) {
42
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
43
+ ar[i] = from[i];
44
+ }
45
+ }
46
+ return to.concat(ar || Array.prototype.slice.call(from));
47
+ };
39
48
  exports.__esModule = true;
40
49
  var utils_1 = require("./utils");
41
50
  require('require-extensions');
@@ -46,6 +55,7 @@ var fs = require('fs-extra');
46
55
  var path = require('path');
47
56
  var glob = require('glob');
48
57
  var variables = {};
58
+ var open = require("open");
49
59
  function log() {
50
60
  var messages = [];
51
61
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -65,12 +75,36 @@ function warn() {
65
75
  // console.log(chalk.red(message));
66
76
  });
67
77
  }
68
- function checkModulePath(modulePath, res) {
78
+ function checkWorkspaces(rootPath, workspaces, res) {
79
+ // console.log('checking workspaces at '+rootPath+": "+workspaces.toString());
80
+ workspaces.forEach(function (workspace) {
81
+ var workspacePath = path.join(rootPath, workspace.replace('/*', ''));
82
+ if (workspace.indexOf('/*') !== -1) {
83
+ // console.log(workspacePath);
84
+ if (fs.existsSync(workspacePath)) {
85
+ var folders = fs.readdirSync(workspacePath);
86
+ folders.forEach(function (folder) {
87
+ if (folder !== './' && folder !== '../') {
88
+ checkModulePath(rootPath, path.join(workspacePath, folder), res);
89
+ }
90
+ });
91
+ }
92
+ }
93
+ else {
94
+ checkModulePath(rootPath, workspacePath, res);
95
+ }
96
+ });
97
+ }
98
+ function checkModulePath(rootPath, modulePath, res) {
69
99
  var packagePath = path.join(modulePath, 'package.json');
100
+ // console.log('checking '+packagePath);
70
101
  if (fs.existsSync(packagePath)) {
71
102
  var pack = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
72
103
  //some packages are not true lincd modules, but we still want them to be re-built automatically. This is what lincd_util is for
73
- if ((pack && pack.lincd === true) || pack.lincd_util === true) {
104
+ if (pack && pack.workspaces) {
105
+ checkWorkspaces(modulePath, pack.workspaces, res);
106
+ }
107
+ else if ((pack && pack.lincd === true) || pack.lincd_util === true) {
74
108
  res.push({
75
109
  path: modulePath,
76
110
  moduleName: pack.name,
@@ -87,8 +121,7 @@ function getLocalLincdModuleMap(rootPath) {
87
121
  if (rootPath === void 0) { rootPath = './'; }
88
122
  var map = new Map();
89
123
  getLincdModules(rootPath).forEach(function (module) {
90
- if (module.path.indexOf('../') === -1 &&
91
- module.path.indexOf('..\\') === -1) {
124
+ if (module.path.indexOf('../') === -1 && module.path.indexOf('..\\') === -1) {
92
125
  // console.log(module.path);
93
126
  map.set(module.moduleName, module);
94
127
  }
@@ -106,7 +139,7 @@ function getLincdModules(rootPath) {
106
139
  //TODO: read from package.json what the workspaces are. for each, follow up all the folders inside that path
107
140
  //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
108
141
  //TODO: this way it will work with websites as well, instead of just from the main LINCD repository
109
- var pack = utils_1.getPackageJSON();
142
+ var pack = (0, utils_1.getPackageJSON)();
110
143
  var res = [];
111
144
  if (!pack.workspaces) {
112
145
  warn(chalk.red('Could not find package workspaces. Make sure you run this command from a yarn workspace.'));
@@ -114,23 +147,7 @@ function getLincdModules(rootPath) {
114
147
  process.exit();
115
148
  }
116
149
  //TODO: filter with package.lincd = true?
117
- pack.workspaces.forEach(function (workspace) {
118
- var workspacePath = path.join(rootPath, workspace.replace('/*', ''));
119
- if (workspace.indexOf('/*') !== -1) {
120
- // console.log(workspacePath);
121
- if (fs.existsSync(workspacePath)) {
122
- var folders = fs.readdirSync(workspacePath);
123
- folders.forEach(function (folder) {
124
- if (folder !== './' && folder !== '../') {
125
- checkModulePath(path.join(workspacePath, folder), res);
126
- }
127
- });
128
- }
129
- }
130
- else {
131
- checkModulePath(workspacePath, res);
132
- }
133
- });
150
+ checkWorkspaces(rootPath, pack.workspaces, res);
134
151
  // console.log(res);
135
152
  return res;
136
153
  }
@@ -245,9 +262,7 @@ var replaceCurlyVariables = function (string) {
245
262
  }
246
263
  return string;
247
264
  };
248
- var capitalize = function (str) {
249
- return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1);
250
- };
265
+ var capitalize = function (str) { return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1); };
251
266
  var camelCase = function (str) {
252
267
  var string = str
253
268
  .toLowerCase()
@@ -256,51 +271,222 @@ var camelCase = function (str) {
256
271
  .reduce(function (result, word) { return result + capitalize(word.toLowerCase()); });
257
272
  return string.charAt(0).toLowerCase() + string.slice(1);
258
273
  };
259
- program.command('init [name] [uribase]').action(function (name, uriBase) {
260
- return initModule(name, uriBase);
274
+ program.command('create-app [name] [uribase]').action(function (name, uriBase) {
275
+ return createApp(name, uriBase);
261
276
  });
262
- var initModule = function (name, uriBase, basePath) {
277
+ program.command('create-module [name] [uribase]').action(function (name, uriBase) {
278
+ return createModule(name, uriBase);
279
+ });
280
+ program.command('create-ontology [suggested-prefix] [uribase]').action(function (prefix, uriBase) {
281
+ return createOntology(prefix, uriBase);
282
+ });
283
+ var createOntology = function (prefix, uriBase, basePath) {
263
284
  if (basePath === void 0) { basePath = process.cwd(); }
264
- if (!uriBase) {
265
- uriBase = '[INSERT_URI_BASE]';
266
- }
267
- if (!name) {
268
- if (fs.existsSync(path.join(basePath, 'package.json'))) {
269
- var pack = require(path.join(basePath, 'package.json'));
270
- //find @scope and the next part between 2 slashes after
271
- //so @dacore/some-mod/lib/file.js
272
- // --> match[0] = @dacore/some-mod
273
- // --> match[1] = @dacore
274
- // --> match[2] = some-mod
275
- var _a = pack.name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
276
- name = cleanPackageName;
277
- }
278
- else {
279
- name = path.basename(process.cwd());
280
- }
281
- }
282
- // console.log(
283
- // 'Copying ' +
284
- // path.join(__dirname, '..', 'defaults', 'module') +
285
- // '\nto ' +
286
- // basePath,
287
- // );
288
- fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), basePath);
289
- var camelCaseModuleName = camelCase(name); //some-module --> someModule
290
- var underscoreModuleName = name.replace(/[-\s]+/g, '_');
291
- setVariable('uri_base', uriBase);
292
- //longer similar variables names should come before the shorter ones
293
- setVariable('camel_module_name', camelCaseModuleName);
294
- setVariable('underscore_module_name', underscoreModuleName);
295
- setVariable('module_name', name);
296
- log("Creating new lincd module '" + name + "'");
297
- //replace variables in some of the copied files
298
- ['package.json', 'Gruntfile.js', 'src/module.ts']
299
- .map(function (f) { return path.join(basePath, f); })
300
- .forEach(function (file) {
301
- replaceVariablesInFile(file);
285
+ return __awaiter(void 0, void 0, void 0, function () {
286
+ var targetFolder, codeName, hyphenName, cameCaseName, underscoreName, targetFile, targetDataFile, targetDataFile2, indexPath, indexContents, lines, newContents, key;
287
+ return __generator(this, function (_a) {
288
+ switch (_a.label) {
289
+ case 0:
290
+ if (!prefix) {
291
+ console.warn("Please provide a suggested prefix as the first argument");
292
+ return [2 /*return*/];
293
+ }
294
+ targetFolder = path.join(basePath, 'src', 'ontologies');
295
+ if (!fs.existsSync(targetFolder)) {
296
+ if (fs.existsSync(path.join(basePath, 'src'))) {
297
+ fs.mkdirSync(targetFolder);
298
+ }
299
+ else {
300
+ warn("Please run this command from the root of your module. This command expects [modules]/src/ontologies to exists from that folder");
301
+ }
302
+ }
303
+ if (!uriBase) {
304
+ uriBase = 'http://lincd.org/ont/' + prefix;
305
+ }
306
+ codeName = prefix.replace(/\-/g, '_');
307
+ hyphenName = prefix.replace(/[-_\s]+/g, '-');
308
+ cameCaseName = camelCase(prefix);
309
+ underscoreName = prefix.replace(/[-\s]+/g, '_');
310
+ targetFile = path.join(targetFolder, hyphenName + '.ts');
311
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
312
+ targetDataFile = path.join(targetFolder, '..', 'data', hyphenName + '.json');
313
+ targetDataFile2 = path.join(targetFolder, '..', 'data', hyphenName + '.json.d.ts');
314
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'data', 'example-ontology.json'), targetDataFile);
315
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'data', 'example-ontology.json.d.ts'), targetDataFile2);
316
+ setVariable('uri_base', uriBase);
317
+ setVariable('camel_module_name', cameCaseName);
318
+ setVariable('underscore_module_name', underscoreName);
319
+ setVariable('hyphen_name', hyphenName);
320
+ setVariable('module_name', prefix);
321
+ log("Creating files for ontology '" + prefix + "'");
322
+ //replace variables in some of the copied files
323
+ return [4 /*yield*/, Promise.all([targetFile, targetDataFile, targetDataFile2]
324
+ .map(function (file) {
325
+ return replaceVariablesInFile(file);
326
+ }))];
327
+ case 1:
328
+ //replace variables in some of the copied files
329
+ _a.sent();
330
+ indexPath = ['index.ts', 'index.tsx'].map(function (f) {
331
+ return path.join('src', f);
332
+ }).find(function (indexFileName) {
333
+ return fs.existsSync(indexFileName);
334
+ });
335
+ if (indexPath) {
336
+ indexContents = fs.readFileSync(indexPath, 'utf-8');
337
+ lines = indexContents.split(/\n/g);
338
+ newContents = void 0;
339
+ for (key in lines) {
340
+ if (lines[key].indexOf('ontologies') !== -1) {
341
+ //remove lines after this line and insert new line in its place
342
+ lines[key] += "\nimport './ontologies/".concat(hyphenName, "';");
343
+ newContents = lines.join("\n");
344
+ // log("Found at "+key,lines,newContents);
345
+ break;
346
+ }
347
+ }
348
+ if (!newContents) {
349
+ newContents = indexContents + "\nimport './ontologies/".concat(hyphenName, "';");
350
+ // log("Added at end",newContents);
351
+ }
352
+ fs.writeFileSync(indexPath, newContents);
353
+ }
354
+ log("Prepared a new ontology data files in ".concat(chalk.magenta(targetDataFile.replace(basePath, ''))), "And an ontology accessor file in ".concat(chalk.magenta(targetFile.replace(basePath, ''))), "Added an import of this file from ".concat(chalk.magenta(indexPath)));
355
+ return [2 /*return*/];
356
+ }
357
+ });
358
+ });
359
+ };
360
+ var createModule = function (name, uriBase, basePath) {
361
+ if (basePath === void 0) { basePath = process.cwd(); }
362
+ return __awaiter(void 0, void 0, void 0, function () {
363
+ var targetFolder, _a, packageName, scope, cleanPackageName, codeName, cameCaseName, underscoreName, hyphenName, version, installCommand;
364
+ return __generator(this, function (_b) {
365
+ switch (_b.label) {
366
+ case 0:
367
+ //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)
368
+ //so we manually find a modules folder, if it exists we go into that.
369
+ if (fs.existsSync(path.join(basePath, 'modules'))) {
370
+ basePath = path.join(basePath, 'modules');
371
+ }
372
+ targetFolder = path.join(basePath, name);
373
+ console.log(targetFolder, basePath, name);
374
+ if (!fs.existsSync(targetFolder)) {
375
+ fs.mkdirSync(targetFolder);
376
+ }
377
+ if (!uriBase) {
378
+ uriBase = 'http://lincd.org/ont/' + name;
379
+ }
380
+ if (!name) {
381
+ console.warn("Please provide a name as the first argument");
382
+ }
383
+ _a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
384
+ // console.log(
385
+ // 'Copying ' +
386
+ // path.join(__dirname, '..', 'defaults', 'module') +
387
+ // '\nto ' +
388
+ // basePath,
389
+ // );
390
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), targetFolder);
391
+ codeName = cleanPackageName.replace(/\-/g, '_');
392
+ cameCaseName = camelCase(name);
393
+ underscoreName = name.replace(/[-\s]+/g, '_');
394
+ hyphenName = name.replace(/[-_\s]+/g, '-');
395
+ setVariable('uri_base', uriBase);
396
+ //longer similar variables names should come before the shorter ones
397
+ setVariable('camel_module_name', cameCaseName);
398
+ setVariable('underscore_module_name', underscoreName);
399
+ setVariable('module_name', name);
400
+ setVariable('hyphen_name', hyphenName);
401
+ log("Creating new LINCD module '" + name + "'");
402
+ //replace variables in some of the copied files
403
+ return [4 /*yield*/, Promise.all(['src/index.ts', 'package.json', 'Gruntfile.js', 'src/module.ts', 'src/shapes/ExampleShapeClass.ts', 'src/ontologies/example-ontology.ts', 'src/data/example-ontology.json']
404
+ .map(function (f) { return path.join(targetFolder, f); })
405
+ .map(function (file) {
406
+ return replaceVariablesInFile(file);
407
+ }))];
408
+ case 1:
409
+ //replace variables in some of the copied files
410
+ _b.sent();
411
+ //rename these to a file name similar to the module name
412
+ ['src/ontologies/example-ontology.ts', 'src/data/example-ontology.json', 'src/data/example-ontology.json.d.ts'].forEach(function (f) {
413
+ var parts = f.split('/');
414
+ var newParts = __spreadArray([], parts, true);
415
+ var _a = newParts.pop().split('.'), name = _a[0], extensions = _a.slice(1);
416
+ var newName = hyphenName + '.' + extensions.join(".");
417
+ console.log('rename ', path.join(targetFolder, f), path.join.apply(path, __spreadArray(__spreadArray([targetFolder], newParts, false), [newName], false)));
418
+ fs.renameSync(path.join(targetFolder, f), path.join.apply(path, __spreadArray(__spreadArray([targetFolder], newParts, false), [newName], false)));
419
+ });
420
+ return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
421
+ console.log("yarn probably not working");
422
+ return '';
423
+ })];
424
+ case 2:
425
+ version = _b.sent();
426
+ installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
427
+ return [4 /*yield*/, execp("cd ".concat(targetFolder, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
428
+ console.warn("Could not install dependencies");
429
+ })];
430
+ case 3:
431
+ _b.sent();
432
+ 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"));
433
+ return [2 /*return*/];
434
+ }
435
+ });
436
+ });
437
+ };
438
+ var createApp = function (name, uriBase, basePath) {
439
+ if (basePath === void 0) { basePath = process.cwd(); }
440
+ return __awaiter(void 0, void 0, void 0, function () {
441
+ var _a, packageName, scope, cleanPackageName, targetFolder, codeName, cameCaseName, underscoreName, version, installCommand;
442
+ return __generator(this, function (_b) {
443
+ switch (_b.label) {
444
+ case 0:
445
+ if (!name) {
446
+ console.warn("Please provide a name as the first argument");
447
+ }
448
+ _a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
449
+ if (!uriBase) {
450
+ uriBase = 'http://lincd.org/ont/' + name;
451
+ }
452
+ targetFolder = path.join(basePath, name);
453
+ if (!fs.existsSync(targetFolder)) {
454
+ fs.mkdirSync(targetFolder);
455
+ }
456
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
457
+ codeName = cleanPackageName.replace(/\-/g, '_');
458
+ cameCaseName = camelCase(name);
459
+ underscoreName = name.replace(/[-\s]+/g, '_');
460
+ setVariable('uri_base', uriBase);
461
+ //longer similar variables names should come before the shorter ones
462
+ setVariable('camelcase_name', cameCaseName);
463
+ setVariable('underscore_name', underscoreName);
464
+ setVariable('app_name', name);
465
+ log("Creating new LINCD application '" + name + "'");
466
+ //replace variables in some of the copied files
467
+ ['package.json', 'index.html', 'Gruntfile.js', 'src/index.tsx', 'src/App.tsx']
468
+ .map(function (f) { return path.join(targetFolder, f); })
469
+ .forEach(function (file) {
470
+ replaceVariablesInFile(file);
471
+ });
472
+ return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
473
+ console.log("yarn probably not working");
474
+ return '';
475
+ })];
476
+ case 1:
477
+ version = _b.sent();
478
+ installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
479
+ return [4 /*yield*/, execp("cd ".concat(name, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
480
+ console.warn("Could not install dependencies");
481
+ })];
482
+ case 2:
483
+ _b.sent();
484
+ open(path.join(targetFolder, 'index.html'));
485
+ 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"));
486
+ return [2 /*return*/];
487
+ }
488
+ });
302
489
  });
303
- 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");
304
490
  };
305
491
  var getNextVersion = function (version) {
306
492
  var parts = version.split('.');
@@ -315,8 +501,7 @@ var getNextMinorVersion = function (version) {
315
501
  return parts[0] + '.' + (parseInt(parts[1]) + 1).toString() + '.0';
316
502
  };
317
503
  var buildFailed = function (output) {
318
- return (output.indexOf('Aborted due to warnings') !== -1 &&
319
- output.indexOf('Command failed') !== -1);
504
+ return output.indexOf('Aborted due to warnings') !== -1 && output.indexOf('Command failed') !== -1;
320
505
  };
321
506
  /*program.command('shapes').action(async () => {
322
507
  //we've imported require-extensions from npm so that we can use this
@@ -362,15 +547,9 @@ program.command('register [version]').action(function (newVersion) {
362
547
  var moduleName = pack.name;
363
548
  var author = pack.author;
364
549
  // let displayName = pack.displayName;
365
- console.log(chalk.cyan('registering ' +
366
- author +
367
- "'s module, " +
368
- moduleName +
369
- ' ' +
370
- version +
371
- ' in the LINCD registry'));
550
+ console.log(chalk.cyan('registering ' + author + "'s module, " + moduleName + ' ' + version + ' in the LINCD registry'));
372
551
  //temporary test code
373
- return fetch('http://localhost:3000/register', {
552
+ return fetch('http://localhost:4001/register', {
374
553
  method: 'POST',
375
554
  headers: {
376
555
  Accept: 'application/json, text/plain, */*',
@@ -378,64 +557,69 @@ program.command('register [version]').action(function (newVersion) {
378
557
  },
379
558
  body: JSON.stringify({ package: moduleName, version: version })
380
559
  })
381
- .then(function (res) { return res.text(); })
382
- .then(function (text) {
383
- console.log(chalk.cyan('Response: ') + chalk.italic(text));
560
+ .then(function (res) { return res.json(); })
561
+ .then(function (json) {
562
+ if (json.error) {
563
+ console.log(chalk.red('Response: ' + json.error));
564
+ }
565
+ else if (json.result) {
566
+ console.log(chalk.cyan('Response: ') + json.result);
567
+ }
384
568
  })["catch"](function (err) {
385
569
  console.warn('Could not connect to LINCD registry');
386
570
  });
387
571
  /*console.log(chalk.cyan('building production bundles'));
388
572
  return execPromise('yarn lincd build production', false, true)
389
- .then((output: string) => {
390
- if (buildFailed(output)) {
391
- // console.warn("Build failed:");
392
- console.log(output);
393
- throw new Error('build failed');
394
- }
395
- pack.version = newVersion;
396
- //save package.json
397
- return fs.writeFileSync(
398
- path.join(process.cwd(), 'package.json'),
399
- JSON.stringify(pack, null, 2),
400
- );
401
- })
402
- .then((version) => {
403
- console.log(chalk.cyan('Committing to git'));
404
- //we have just changed package.json, so there will be things "uncommitted"
405
- //to make sure this module does not automatically come up as "needing to be published" we need to commit this change here straight away
406
- //so: add all files not added yet in the folder of this module
407
- //then commit all changes (including new version number in package.json)
408
- //then add a version commit git flag
409
- return execPromise(
410
- `git add -- ./ & git commit -m "publishing ${moduleName} ${newVersion}" -- ./ & git tag ${moduleName}@${newVersion}"`,
411
- );
412
- })
413
- .then((version) => {
414
- console.log(chalk.cyan('Publishing ' + moduleName + ' ' + newVersion));
415
-
416
- // let tag = moduleName+'@'+version;
417
- return execPromise('yarn publish --new-version ' + newVersion, true);
418
- })
419
- .then((res) => {
420
- if (
421
- res.indexOf('Aborted due to warnings') !== -1 ||
422
- res.indexOf('Could not publish') !== -1 ||
423
- res.indexOf("Couldn't publish") !== -1
424
- ) {
425
- console.log(chalk.red('Failed to publish'));
426
- return false;
427
- } else {
428
- var pack = JSON.parse(
429
- fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
430
- );
431
- version = pack.version;
432
- console.log(chalk.green('Published ' + version));
433
- return true;
434
- }
435
- })
436
- .catch((err) => {
437
- console.warn(chalk.red('Could not publish: ' + err));
438
- });*/
573
+ .then((output: string) => {
574
+ if (buildFailed(output)) {
575
+ // console.warn("Build failed:");
576
+ console.log(output);
577
+ throw new Error('build failed');
578
+ }
579
+ pack.version = newVersion;
580
+ //save package.json
581
+ return fs.writeFileSync(
582
+ path.join(process.cwd(), 'package.json'),
583
+ JSON.stringify(pack, null, 2),
584
+ );
585
+ })
586
+ .then((version) => {
587
+ console.log(chalk.cyan('Committing to git'));
588
+ //we have just changed package.json, so there will be things "uncommitted"
589
+ //to make sure this module does not automatically come up as "needing to be published" we need to commit this change here straight away
590
+ //so: add all files not added yet in the folder of this module
591
+ //then commit all changes (including new version number in package.json)
592
+ //then add a version commit git flag
593
+ return execPromise(
594
+ `git add -- ./ & git commit -m "publishing ${moduleName} ${newVersion}" -- ./ & git tag ${moduleName}@${newVersion}"`,
595
+ );
596
+ })
597
+ .then((version) => {
598
+ console.log(chalk.cyan('Publishing ' + moduleName + ' ' + newVersion));
599
+
600
+ // let tag = moduleName+'@'+version;
601
+ return execPromise('yarn publish --new-version ' + newVersion, true);
602
+ })
603
+ .then((res) => {
604
+ if (
605
+ res.indexOf('Aborted due to warnings') !== -1 ||
606
+ res.indexOf('Could not publish') !== -1 ||
607
+ res.indexOf("Couldn't publish") !== -1
608
+ ) {
609
+ console.log(chalk.red('Failed to publish'));
610
+ return false;
611
+ } else {
612
+ var pack = JSON.parse(
613
+ fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
614
+ );
615
+ version = pack.version;
616
+ console.log(chalk.green('Published ' + version));
617
+ return true;
618
+ }
619
+ })
620
+ .catch((err) => {
621
+ console.warn(chalk.red('Could not publish: ' + err));
622
+ });*/
439
623
  }
440
624
  else {
441
625
  console.warn('not found: ' + process.cwd() + '/package.json');
@@ -494,7 +678,7 @@ var buildModule = function (target, target2, modulePath, logResults) {
494
678
  if (logResults === void 0) { logResults = true; }
495
679
  if (target == 'production' || target == 'es5' || target == 'es6' || !target) {
496
680
  if (!fs.existsSync(path.join(modulePath, 'Gruntfile.js'))) {
497
- console.warn("No Gruntfile found at " + modulePath + "\\Gruntfile.js. Cannot build.");
681
+ console.warn("No Gruntfile found at ".concat(modulePath, "\\Gruntfile.js. Cannot build."));
498
682
  return;
499
683
  }
500
684
  var nodeEnv = '';
@@ -522,11 +706,7 @@ var buildModule = function (target, target2, modulePath, logResults) {
522
706
  ' --color');
523
707
  var method = logResults ? execp : execPromise;
524
708
  //execute the command to build the method, and provide the current work directory as option
525
- return method(nodeEnv +
526
- 'grunt build' +
527
- (target ? '-' + target : '') +
528
- (target2 ? '-' + target2 : '') +
529
- ' --color', false, false, { cwd: modulePath })["catch"](function (err) {
709
+ return method(nodeEnv + 'grunt build' + (target ? '-' + target : '') + (target2 ? '-' + target2 : '') + ' --color', false, false, { cwd: modulePath })["catch"](function (err) {
530
710
  process.exit(1);
531
711
  });
532
712
  }
@@ -548,7 +728,7 @@ var getLastModifiedSourceTime = function (modulePath) {
548
728
  var getLastCommitTime = function (modulePath) {
549
729
  // console.log(`git log -1 --format=%ci -- ${modulePath}`);
550
730
  // process.exit();
551
- return execPromise("git log -1 --format=%ci -- " + modulePath).then(function (result) {
731
+ return execPromise("git log -1 --format=%ci -- ".concat(modulePath)).then(function (result) {
552
732
  var lastCommit = new Date(result);
553
733
  // console.log(modulePath,result,lastCommit);
554
734
  return lastCommit;
@@ -623,9 +803,7 @@ var publishUpdated = function (test) {
623
803
  catch (err) {
624
804
  chalk.red(module.moduleName + ' failed: ' + err.message + '\n');
625
805
  console.warn('Returned JSON from npm: ' + output);
626
- return [2 /*return*/, (previousResult +
627
- ' ' +
628
- chalk.red(module.moduleName + ' failed: ' + err.message + '\n'))];
806
+ return [2 /*return*/, previousResult + ' ' + chalk.red(module.moduleName + ' failed: ' + err.message + '\n')];
629
807
  }
630
808
  lastPublish = info.data.time[info.data.version];
631
809
  lastPublishDate = new Date(lastPublish);
@@ -633,15 +811,8 @@ var publishUpdated = function (test) {
633
811
  return [4 /*yield*/, getLastCommitTime(module.path)];
634
812
  case 1:
635
813
  lastCommit = _b.sent();
636
- console.log(lastPublishDate.toDateString() +
637
- ' ' +
638
- lastPublishDate.toTimeString() +
639
- ' published ' +
640
- info.data.version);
641
- console.log(lastCommit.toDateString() +
642
- ' ' +
643
- new Date(lastCommit).toTimeString() +
644
- ' source last committed');
814
+ console.log(lastPublishDate.toDateString() + ' ' + lastPublishDate.toTimeString() + ' published ' + info.data.version);
815
+ console.log(lastCommit.toDateString() + ' ' + new Date(lastCommit).toTimeString() + ' source last committed');
645
816
  // console.log(lastModified.toDateString() + ' ' + new Date(lastModified).toTimeString() + ' source ' + lastModifiedName + ' last edited');
646
817
  //NOTE: removed lastModified, because switching branches will say that the file was modified and cause everything to publish
647
818
  //SO: now you NEED TO commit before it picks up that you should publish
@@ -666,7 +837,7 @@ var publishUpdated = function (test) {
666
837
  });
667
838
  }); })["catch"](function (err) {
668
839
  console.log(err);
669
- return (previousResult + ' ' + chalk.red(module.moduleName + ' failed\n'));
840
+ return previousResult + ' ' + chalk.red(module.moduleName + ' failed\n');
670
841
  });
671
842
  });
672
843
  });
@@ -681,12 +852,7 @@ var publishUpdated = function (test) {
681
852
  };
682
853
  var executeSingleBuild = function (module, previousResult, test, info) {
683
854
  var nextVersion = info ? getNextVersion(info.data.version) : '';
684
- console.log(chalk.blue('--> ' +
685
- (test ? 'should publish' : 'publishing') +
686
- ' ' +
687
- module.moduleName +
688
- ' ' +
689
- nextVersion));
855
+ console.log(chalk.blue('--> ' + (test ? 'should publish' : 'publishing') + ' ' + module.moduleName + ' ' + nextVersion));
690
856
  if (!test) {
691
857
  return execPromise('cd ' + module.path + ' && yarn lincd register', true)
692
858
  .then(function (res) {
@@ -694,12 +860,10 @@ var executeSingleBuild = function (module, previousResult, test, info) {
694
860
  res.indexOf('Could not publish') !== -1 ||
695
861
  res.indexOf("Couldn't publish") !== -1) {
696
862
  console.log(res);
697
- return (previousResult + ' ' + chalk.red(module.moduleName + ' failed\n'));
863
+ return previousResult + ' ' + chalk.red(module.moduleName + ' failed\n');
698
864
  }
699
865
  console.log(chalk.green('Successfully published ' + nextVersion));
700
- return (previousResult +
701
- ' ' +
702
- chalk.green(module.moduleName + ' published ' + nextVersion + '\n'));
866
+ return previousResult + ' ' + chalk.green(module.moduleName + ' published ' + nextVersion + '\n');
703
867
  })["catch"](function (err) {
704
868
  console.log(chalk.red('Failed to publish: ' + err));
705
869
  return chalk.red('Failed to publish: ' + err);
@@ -707,17 +871,13 @@ var executeSingleBuild = function (module, previousResult, test, info) {
707
871
  }
708
872
  else {
709
873
  //when testing what needs to be published
710
- return (previousResult + ' ' + chalk.blue(module.moduleName + ' should publish\n'));
874
+ return previousResult + ' ' + chalk.blue(module.moduleName + ' should publish\n');
711
875
  }
712
876
  };
713
- program
714
- .command('build-updated [target] [target2]')
715
- .action(function (target, target2) {
877
+ program.command('build-updated [target] [target2]').action(function (target, target2) {
716
878
  return buildUpdated(1, target, target2);
717
879
  });
718
- program
719
- .command('build-updated-since [num-commits-back] [target] [target2]')
720
- .action(function (back, target, target2) {
880
+ program.command('build-updated-since [num-commits-back] [target] [target2]').action(function (back, target, target2) {
721
881
  return buildUpdated(back, target, target2);
722
882
  });
723
883
  var buildUpdated = function (back, target, target2, test) {
@@ -726,8 +886,7 @@ var buildUpdated = function (back, target, target2, test) {
726
886
  // return execPromise(`git log -${back} --format=%ci`).then((result) => {
727
887
  // let now = new Date();
728
888
  var previousResult = '';
729
- log((test ? 'Checking which modules' : 'Building all modules that') +
730
- ' have been changed since their last built ');
889
+ log((test ? 'Checking which modules' : 'Building all modules that') + ' have been changed since their last built ');
731
890
  var modules = getLocalLincdModules();
732
891
  //TODO: sort all these modules in the order of their dependencies.
733
892
  // To do so, see build-all command and put some of the functionality (like getting modules that depend on a module) in reusable functions
@@ -741,8 +900,7 @@ var buildUpdated = function (back, target, target2, test) {
741
900
  // console.log(module.path,lastModifiedSource.lastModifiedTime,lastModifiedBundle.lastModifiedTime);
742
901
  // console.log(module.path,new Date(lastModifiedSource.lastModified).toString(),new Date(lastModifiedBundle.lastModified).toString());
743
902
  console.log('# Checking module ' + moduleName);
744
- if (lastModifiedSource.lastModifiedTime >
745
- lastModifiedBundle.lastModifiedTime) {
903
+ if (lastModifiedSource.lastModifiedTime > lastModifiedBundle.lastModifiedTime) {
746
904
  //TODO: when building a module, also rebuild all modules that depend on this module.. and iteratively build modules that depend on those modules..
747
905
  // log(moduleName+' modified since last commit on '+now.toString());
748
906
  console.log(chalk.cyan('Last modified source: ' +
@@ -750,27 +908,21 @@ var buildUpdated = function (back, target, target2, test) {
750
908
  ' on ' +
751
909
  lastModifiedSource.lastModified.toString()));
752
910
  console.log(chalk.cyan('Last build: ' +
753
- (lastModifiedBundle &&
754
- typeof lastModifiedBundle.lastModified !== 'undefined'
911
+ (lastModifiedBundle && typeof lastModifiedBundle.lastModified !== 'undefined'
755
912
  ? lastModifiedBundle.lastModified.toString()
756
913
  : 'never')));
757
914
  log('--> ' + (test ? 'need to build ' : 'building ') + moduleName);
758
915
  if (!test) {
759
- return execPromise('cd ' +
760
- module.path +
761
- ' && yarn build' +
762
- (target ? ' ' + target : '') +
763
- (target2 ? ' ' + target2 : '')).then(function (res) {
764
- if (res.indexOf('Aborted due to warnings') !== -1 ||
765
- res.indexOf('Fatal error') !== -1) {
916
+ return execPromise('cd ' + module.path + ' && yarn build' + (target ? ' ' + target : '') + (target2 ? ' ' + target2 : '')).then(function (res) {
917
+ if (res.indexOf('Aborted due to warnings') !== -1 || res.indexOf('Fatal error') !== -1) {
766
918
  console.log(res);
767
- return (previousResult + ' ' + chalk.red(moduleName + ' failed\n'));
919
+ return previousResult + ' ' + chalk.red(moduleName + ' failed\n');
768
920
  }
769
921
  console.log(chalk.green(moduleName + ' bundles successfully built'));
770
- return (previousResult + ' ' + chalk.green(moduleName + ' built\n'));
922
+ return previousResult + ' ' + chalk.green(moduleName + ' built\n');
771
923
  });
772
924
  }
773
- return (previousResult + ' ' + chalk.blue(moduleName + ' should be build\n'));
925
+ return previousResult + ' ' + chalk.blue(moduleName + ' should be build\n');
774
926
  }
775
927
  return previousResult;
776
928
  })["catch"](function (err) {
@@ -795,7 +947,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
795
947
  //get dependencies of each module
796
948
  var leastDependentModule;
797
949
  modules.forEach(function (module) {
798
- var pack = utils_1.getPackageJSON(module.path);
950
+ var pack = (0, utils_1.getPackageJSON)(module.path);
799
951
  if (pack) {
800
952
  //get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
801
953
  var moduleDependencies = Object.keys(pack.dependencies)
@@ -809,7 +961,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
809
961
  });
810
962
  dependencies.forEach(function (moduleDependencies, module) {
811
963
  if (!moduleDependencies.some(function (dependency) {
812
- return (typeof dependency !== 'string' && modules.has(dependency.moduleName));
964
+ return typeof dependency !== 'string' && modules.has(dependency.moduleName);
813
965
  })) {
814
966
  leastDependentModule = module;
815
967
  }
@@ -847,8 +999,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
847
999
  //if we're skipping builds until a certain module
848
1000
  if (!building) {
849
1001
  //if the module name matches the module we're supposed to start from then start building modules
850
- if (module.moduleName == startFrom ||
851
- module.packageName == startFrom) {
1002
+ if (module.moduleName == startFrom || module.packageName == startFrom) {
852
1003
  building = true;
853
1004
  }
854
1005
  //else still waiting for the module
@@ -881,7 +1032,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
881
1032
  ' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
882
1033
  console.log(chalk.cyanBright('tip ') +
883
1034
  'Run ' +
884
- chalk.green("yarn build-all from " + module.moduleName) +
1035
+ chalk.green("lincd build-all from ".concat(module.moduleName)) +
885
1036
  ' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
886
1037
  process.exit(1);
887
1038
  }
@@ -910,8 +1061,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
910
1061
  //but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
911
1062
  if (!done.has(module) &&
912
1063
  deps.every(function (dependency) {
913
- return (typeof dependency !== 'string' &&
914
- (done.has(dependency) || !modules.has(dependency.moduleName)));
1064
+ return typeof dependency !== 'string' && (done.has(dependency) || !modules.has(dependency.moduleName));
915
1065
  })) {
916
1066
  stack.push(module);
917
1067
  }
@@ -968,14 +1118,10 @@ program.command('build-all [target] [target2]').action(function (target, target2
968
1118
  //starts the process
969
1119
  runStack();
970
1120
  });
971
- program
972
- .command('modules [action] [includedSpaces]')
973
- .action(function (command, includedSpaces) {
1121
+ program.command('modules [action] [includedSpaces]').action(function (command, includedSpaces) {
974
1122
  executeCommandForEachModule(getLincdModules(), command, includedSpaces);
975
1123
  });
976
- program
977
- .command('modules-except [excludedSpaces] [action]')
978
- .action(function (excludedSpaces, command) {
1124
+ program.command('modules-except [excludedSpaces] [action]').action(function (excludedSpaces, command) {
979
1125
  executeCommandForEachModule(getLincdModules(), command, null, excludedSpaces);
980
1126
  });
981
1127
  program
@@ -1008,10 +1154,7 @@ var executeCommandForEachModule = function (modules, command, includedSpaces, ex
1008
1154
  modules = modules.filter(function (module) { return excludedSpaces.indexOf(module.moduleName) === -1; });
1009
1155
  log('Filtering excluded spaces');
1010
1156
  }
1011
- log("Executing '" +
1012
- command +
1013
- "' on modules " +
1014
- modules.map(function (m) { return m.moduleName; }).join(', '));
1157
+ log("Executing '" + command + "' on modules " + modules.map(function (m) { return m.moduleName; }).join(', '));
1015
1158
  var p = Promise.resolve(true);
1016
1159
  modules.forEach(function (module) {
1017
1160
  p = p.then(function () {
@@ -1023,8 +1166,7 @@ var executeCommandForEachModule = function (modules, command, includedSpaces, ex
1023
1166
  };
1024
1167
  var executeCommandForModule = function (module, command) {
1025
1168
  var moduleDetails = getLincdModules().find(function (modDetails) {
1026
- return modDetails.packageName.indexOf(module) !== -1 ||
1027
- modDetails.moduleName.indexOf(module) !== -1;
1169
+ return modDetails.packageName.indexOf(module) !== -1 || modDetails.moduleName.indexOf(module) !== -1;
1028
1170
  });
1029
1171
  if (moduleDetails) {
1030
1172
  log("Executing 'cd " + moduleDetails.path + ' && lincd ' + command + "'");
@@ -1041,14 +1183,8 @@ program.command('dev [target] [mode]').action(function (target, mode) {
1041
1183
  if (target == 'es5' || target == 'es6') {
1042
1184
  // log('> Starting continuous development build for '+target+' target')
1043
1185
  log('starting continuous development build');
1044
- log('grunt dev' +
1045
- (target ? '-' + target : '') +
1046
- (mode ? '-' + mode : '') +
1047
- ' --color');
1048
- var command = exec('grunt dev' +
1049
- (target ? '-' + target : '') +
1050
- (mode ? '-' + mode : '') +
1051
- ' --color');
1186
+ log('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
1187
+ var command = exec('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
1052
1188
  command.stdout.pipe(process.stdout);
1053
1189
  command.stderr.pipe(process.stderr);
1054
1190
  }
@@ -1089,28 +1225,27 @@ function logHelp() {
1089
1225
  chalk.cyan('- build only those modules that have updated their source since their last local built'));
1090
1226
  /*
1091
1227
  console.log(
1092
- chalk.blue('- build-updated [n] ') +
1093
- chalk.cyan(
1094
- '- build only those modules that have updated their source since the last local commit (or optionally n commits back',
1095
- ),
1228
+ chalk.blue('- build-updated [n] ') +
1229
+ chalk.cyan(
1230
+ '- build only those modules that have updated their source since the last local commit (or optionally n commits back',
1231
+ ),
1096
1232
  );
1097
1233
  console.log(
1098
- chalk.blue('- modules [action]') +
1099
- chalk.cyan('- execute a command for all modules'),
1234
+ chalk.blue('- modules [action]') +
1235
+ chalk.cyan('- execute a command for all modules'),
1100
1236
  );
1101
1237
  console.log(
1102
- chalk.blue('- publish-updated [message] ') +
1103
- chalk.cyan(
1104
- "- publish all modules who's source changes have been committed to git since the last published version.",
1105
- ),
1238
+ chalk.blue('- publish-updated [message] ') +
1239
+ chalk.cyan(
1240
+ "- publish all modules who's source changes have been committed to git since the last published version.",
1241
+ ),
1106
1242
  );
1107
1243
  console.log(
1108
- chalk.blue('- status') +
1109
- chalk.cyan('- see which modules need to be published or build'),
1244
+ chalk.blue('- status') +
1245
+ chalk.cyan('- see which modules need to be published or build'),
1110
1246
  );*/
1111
1247
  console.log(chalk.green('\nOther commands:'));
1112
- console.log(chalk.blue('- info ') +
1113
- chalk.cyan('- print the version of this tool and where it runs from'));
1248
+ console.log(chalk.blue('- info ') + chalk.cyan('- print the version of this tool and where it runs from'));
1114
1249
  console.log(chalk.blue('- help ') + chalk.cyan('- print this message'));
1115
1250
  }
1116
1251
  program.parse(process.argv);