lincd-cli 0.1.7 → 0.1.10

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 (51) hide show
  1. package/{src/cli.js → cli.js} +2 -2
  2. package/config-generator.js +568 -0
  3. package/defaults/app/Gruntfile.js +13 -0
  4. package/defaults/app/tsconfig-es5.json +18 -0
  5. package/defaults/app/tsconfig.json +18 -0
  6. package/defaults/module/.npmignore +6 -0
  7. package/defaults/module/Gruntfile.js +16 -0
  8. package/defaults/module/package.json +14 -6
  9. package/defaults/module/src/components/ExampleComponent.tsx +12 -10
  10. package/defaults/module/src/data/example-ontology.json +3 -3
  11. package/defaults/module/src/index.ts +1 -1
  12. package/defaults/module/src/module.ts +1 -1
  13. package/defaults/module/src/ontologies/example-ontology.ts +19 -14
  14. package/defaults/module/src/shapes/ExampleShapeClass.ts +5 -5
  15. package/defaults/module/tsconfig-es5.json +18 -0
  16. package/defaults/module/tsconfig.json +18 -0
  17. package/defaults/shape.ts +8 -0
  18. package/{src/index.js → index.js} +9 -5
  19. package/lib/cli.js +537 -472
  20. package/lib/config-webpack.js +3 -2
  21. package/lib/utils.js +6 -3
  22. package/package.json +9 -9
  23. package/{src/plugins → plugins}/declaration-plugin.js +0 -0
  24. package/{src/plugins → plugins}/externalise-modules.js +0 -0
  25. package/{src/plugins → plugins}/watch-run.js +0 -0
  26. package/utils.js +39 -0
  27. package/defaults/create_migration.js +0 -155
  28. package/defaults/create_migration.ts +0 -7
  29. package/defaults/defaultModule/Index.js +0 -30
  30. package/defaults/defaultModule/Index.scss +0 -19
  31. package/defaults/defaultModule/Index.tsx +0 -32
  32. package/defaults/defaultModule/data.json +0 -56
  33. package/defaults/defaultModule/defaultOntology.json +0 -23
  34. package/defaults/defaultModule/index.ts +0 -16
  35. package/defaults/defaultModule/ontology.js +0 -21
  36. package/defaults/defaultModule/ontology.ts +0 -19
  37. package/defaults/gitignorefile +0 -4
  38. package/defaults/index.ts +0 -17
  39. package/defaults/ontology.ts +0 -19
  40. package/defaults/package.json +0 -28
  41. package/defaults/providers.ts +0 -1
  42. package/defaults/site/package.json +0 -40
  43. package/defaults/site/storage/filestores/settings-production-template.jsonld +0 -129
  44. package/defaults/site/web/.htaccess +0 -19
  45. package/defaults/site/web/favicon.png +0 -0
  46. package/defaults/site/web/img/placeholder.jpg +0 -0
  47. package/src/config-grunt.js +0 -263
  48. package/src/config-webpack.js +0 -281
  49. package/src/interfaces.js +0 -2
  50. package/src/plugins/shapes-plugin.js +0 -69
  51. 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,7 +55,105 @@ var fs = require('fs-extra');
46
55
  var path = require('path');
47
56
  var glob = require('glob');
48
57
  var variables = {};
49
- var open = require("open");
58
+ var open = require('open');
59
+ program
60
+ .command('create-app')
61
+ .action(function (name) {
62
+ return createApp(name);
63
+ })
64
+ .description('Creates a new folder with all the required files for a LINCD app')
65
+ .argument('<name>', 'the name of your LINCD app');
66
+ program
67
+ .command('create-module')
68
+ .action(function (name, uriBase) {
69
+ return createModule(name, uriBase);
70
+ })
71
+ .description('Create a new folder with all the required files for a new LINCD module')
72
+ .argument('<name>', 'The name of the module. Will be used as package name in package.json')
73
+ .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');
74
+ program
75
+ .command('create-shape')
76
+ .action(function (name, uriBase) {
77
+ return createShape(name);
78
+ })
79
+ .description('Creates a new ShapeClass file for your module. Execute this from your module folder.')
80
+ .argument('<name>', 'The name of the shape. Will be used for the file name and the class name');
81
+ program
82
+ .command('create-ontology')
83
+ .action(function (prefix, uriBase) {
84
+ return createOntology(prefix, uriBase);
85
+ })
86
+ .description('Creates a new ontology file for your module. Execute this from your module folder.')
87
+ .argument('<suggested-prefix>', 'The suggested prefix for your ontology. Also the shorthand code used for the file name and the exported ontology object')
88
+ .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");
89
+ program.command('register-local', { hidden: true }).action(function () {
90
+ register('http://localhost:4001');
91
+ });
92
+ program.command('register-dev', { hidden: true }).action(function () {
93
+ register('https://dev-registry.lincd.org');
94
+ });
95
+ program
96
+ .command('register')
97
+ .action(function () {
98
+ register('https://registry.lincd.org');
99
+ })
100
+ .description('Register (a new version of) this module to the LINCD registry. If successful your module will appear on www.lincd.org');
101
+ program
102
+ .command('info')
103
+ .action(function () {
104
+ var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
105
+ console.log(ownPackage.version);
106
+ console.log('Running from: ' + __dirname);
107
+ })
108
+ .description("Log the version of this tool and the path that it's running from");
109
+ program.command('build [target] [target2]', { isDefault: true }).action(function (target, target2) {
110
+ buildModule(target, target2);
111
+ });
112
+ program.command('publish-updated').action(function () {
113
+ return publishUpdated();
114
+ });
115
+ program.command('status').action(function () {
116
+ return publishUpdated(true).then(function () {
117
+ return buildUpdated(undefined, '', '', true);
118
+ });
119
+ });
120
+ program.command('build-updated [target] [target2]').action(function (target, target2) {
121
+ return buildUpdated(1, target, target2);
122
+ });
123
+ program.command('build-updated-since [num-commits-back] [target] [target2]').action(function (back, target, target2) {
124
+ return buildUpdated(back, target, target2);
125
+ });
126
+ program.command('build-all [target] [target2]').action(function (target, target2) {
127
+ buildAll(target, target2);
128
+ });
129
+ program.command('modules [action] [includedSpaces]').action(function (command, includedSpaces) {
130
+ executeCommandForEachModule(getLincdModules(), command, includedSpaces);
131
+ });
132
+ program.command('modules-except [excludedSpaces] [action]').action(function (excludedSpaces, command) {
133
+ executeCommandForEachModule(getLincdModules(), command, null, excludedSpaces);
134
+ });
135
+ program.command('dev [target] [mode]').action(function (target, mode) {
136
+ developModule(target, mode);
137
+ });
138
+ program
139
+ .command('module|m')
140
+ .action(function (name, command, args) {
141
+ var fullCommand = (command ? command + ' ' +
142
+ ' ' +
143
+ args
144
+ .slice(0, 3)
145
+ .filter(function (a) { return a && true; })
146
+ .join(' ') : null);
147
+ executeCommandForModule(name, fullCommand);
148
+ })
149
+ .alias('m')
150
+ .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)")
151
+ .argument('<name>', 'the name of the module. Can be a part of the name.')
152
+ .argument('[command]', 'the lincd command you want to execute. Like dev or build')
153
+ .argument('[args...]', 'the additional arguments of that command');
154
+ function logHelp() {
155
+ execp('yarn lincd help');
156
+ }
50
157
  function log() {
51
158
  var messages = [];
52
159
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -66,6 +173,25 @@ function warn() {
66
173
  // console.log(chalk.red(message));
67
174
  });
68
175
  }
176
+ function developModule(target, mode) {
177
+ if (!target)
178
+ target = 'es6';
179
+ if (mode !== 'production')
180
+ mode = '';
181
+ else if (target !== 'es6')
182
+ log('target must be es6 when developing for production');
183
+ if (target == 'es5' || target == 'es6') {
184
+ // log('> Starting continuous development build for '+target+' target')
185
+ log('starting continuous development build');
186
+ log('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
187
+ var command = exec('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
188
+ command.stdout.pipe(process.stdout);
189
+ command.stderr.pipe(process.stderr);
190
+ }
191
+ else {
192
+ console.warn('unknown build target. Use es5 or es6');
193
+ }
194
+ }
69
195
  function checkWorkspaces(rootPath, workspaces, res) {
70
196
  // console.log('checking workspaces at '+rootPath+": "+workspaces.toString());
71
197
  workspaces.forEach(function (workspace) {
@@ -104,6 +230,194 @@ function checkModulePath(rootPath, modulePath, res) {
104
230
  }
105
231
  }
106
232
  }
233
+ function buildAll(target, target2) {
234
+ var _this = this;
235
+ var dependencies = new Map();
236
+ console.log('Building all modules of this repository in order of dependencies');
237
+ var modules = getLocalLincdModuleMap();
238
+ //get dependencies of each module
239
+ var leastDependentModule;
240
+ modules.forEach(function (module) {
241
+ var pack = (0, utils_1.getPackageJSON)(module.path);
242
+ if (pack) {
243
+ //get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
244
+ var moduleDependencies = Object.keys(pack.dependencies)
245
+ .filter(function (dependency) { return modules.has(dependency); })
246
+ .map(function (dependency) {
247
+ return modules.has(dependency) ? modules.get(dependency) : dependency;
248
+ });
249
+ // console.log(module.moduleName,moduleDependencies.map())
250
+ dependencies.set(module, moduleDependencies);
251
+ }
252
+ });
253
+ dependencies.forEach(function (moduleDependencies, module) {
254
+ if (!moduleDependencies.some(function (dependency) {
255
+ return typeof dependency !== 'string' && modules.has(dependency.moduleName);
256
+ })) {
257
+ leastDependentModule = module;
258
+ }
259
+ });
260
+ var startFrom;
261
+ //by default start building
262
+ var building = true;
263
+ //option to start from a specific module in the stack
264
+ if (target == 'from') {
265
+ startFrom = target2;
266
+ //if we have a startFrom, then we havnt started the build process yet
267
+ building = startFrom ? false : true;
268
+ //clear targets
269
+ target = '';
270
+ target2 = '';
271
+ console.log(chalk.blue('Will skip builds until ' + startFrom));
272
+ }
273
+ var stack = [leastDependentModule];
274
+ var done = new Set();
275
+ var p = Promise.resolve();
276
+ var runStack = function () { return __awaiter(_this, void 0, void 0, function () {
277
+ var modulesLeft, failedModules, stackPromise, first_1;
278
+ return __generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0:
281
+ modulesLeft = modules.size - done.size;
282
+ if (done.size > 0) {
283
+ console.log(chalk.magenta('\n-------\nThese modules are next, since all their dependencies have now been build:'));
284
+ console.log(chalk.magenta(stack.map(function (i) { return i.moduleName; })));
285
+ // log(stack);
286
+ }
287
+ failedModules = [];
288
+ stackPromise = Promise.all(stack.map(function (module) {
289
+ // p = p.then(() => {
290
+ var command;
291
+ //if we're skipping builds until a certain module
292
+ if (!building) {
293
+ //if the module name matches the module we're supposed to start from then start building modules
294
+ if (module.moduleName == startFrom || module.packageName == startFrom) {
295
+ building = true;
296
+ }
297
+ //else still waiting for the module
298
+ else {
299
+ log(chalk.blue('skipping ' + module.moduleName));
300
+ command = Promise.resolve(true);
301
+ }
302
+ }
303
+ //unless told otherwise, build the module
304
+ if (!command) {
305
+ command = execp('cd ' +
306
+ module.path +
307
+ ' && yarn lincd build' +
308
+ (target ? ' ' + target : '') +
309
+ (target2 ? ' ' + target2 : ''));
310
+ log(chalk.cyan('Building ' + module.moduleName));
311
+ }
312
+ return command["catch"](function (err) {
313
+ var dependentModules = [];
314
+ dependencies.forEach(function (dModuleDependencies, dModule) {
315
+ if (dModuleDependencies.indexOf(module) !== -1) {
316
+ dependentModules.push(dModule);
317
+ }
318
+ });
319
+ if (dependentModules.length > 0) {
320
+ failedModules.push(module.moduleName);
321
+ printFailedModules(failedModules);
322
+ console.log(chalk.magenta('Stopping build process because an error occurred whilst building ' +
323
+ module.moduleName +
324
+ ', which ' +
325
+ dependentModules.length +
326
+ ' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
327
+ console.log(chalk.cyanBright('tip ') +
328
+ 'Run ' +
329
+ chalk.green("lincd build-all from ".concat(module.moduleName)) +
330
+ ' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
331
+ process.exit(1);
332
+ }
333
+ else {
334
+ failedModules.push(module.moduleName);
335
+ }
336
+ })
337
+ .then(function (res) {
338
+ done.add(module);
339
+ modulesLeft--;
340
+ log(chalk.magenta(modulesLeft + ' modules left'));
341
+ if (modulesLeft == 0 && failedModules.length > 0) {
342
+ printFailedModules(failedModules);
343
+ }
344
+ return res;
345
+ });
346
+ // });
347
+ // done.add(module);
348
+ }));
349
+ //wait till stack is completed
350
+ return [4 /*yield*/, stackPromise];
351
+ case 1:
352
+ //wait till stack is completed
353
+ _a.sent();
354
+ // await p;
355
+ //clear stack for next round
356
+ stack = [];
357
+ //find those modules who have all their dependencies already built and add them to the stack
358
+ modules.forEach(function (module) {
359
+ var deps = dependencies.get(module);
360
+ //if the module is not done yet
361
+ //but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
362
+ if (!done.has(module) &&
363
+ deps.every(function (dependency) {
364
+ return typeof dependency !== 'string' && (done.has(dependency) || !modules.has(dependency.moduleName));
365
+ })) {
366
+ stack.push(module);
367
+ }
368
+ // else if(!done.has(module))
369
+ // {
370
+ // console.log(chalk.red(module+' not yet'))
371
+ // console.log('UNMET DEPS: '+deps.filter(dependency => !done.has(dependency)).join(" "))
372
+ // }
373
+ });
374
+ //if more to be built, iterate
375
+ if (stack.length > 0) {
376
+ return [2 /*return*/, runStack()];
377
+ }
378
+ else {
379
+ //if no more modules to build but we never started building...
380
+ if (!building) {
381
+ console.log(chalk.red('Could not find the module to start from. Please provide a correct package name or module name to build from'));
382
+ }
383
+ else {
384
+ first_1 = true;
385
+ modules.forEach(function (module) {
386
+ if (!done.has(module)) {
387
+ var deps = dependencies.get(module);
388
+ if (first_1) {
389
+ console.log(chalk.red('CYCLICAL DEPENDENCIES? - could not build some modules because they depend on each other.'));
390
+ first_1 = false;
391
+ }
392
+ //print the cyclical dependencies
393
+ console.log(chalk.red(module.moduleName) +
394
+ ' depends on ' +
395
+ deps
396
+ .filter(function (dependency) {
397
+ return typeof dependency !== 'string';
398
+ })
399
+ .map(function (d) {
400
+ return done.has(d) ? d.moduleName : chalk.red(d.moduleName);
401
+ })
402
+ .join(', '));
403
+ //also print some information why these modules have not been moved into the stack
404
+ var stringDependencies = deps.filter(function (d) { return typeof d === 'string'; });
405
+ if (stringDependencies.length > 0) {
406
+ console.log(chalk.red('And it depends on these module(s) - which seem not to be proper modules :' +
407
+ stringDependencies.join(', ')));
408
+ console.log(chalk.red('Could you remove this from dependencies? Should it be a devDependency?'));
409
+ }
410
+ }
411
+ });
412
+ }
413
+ }
414
+ return [2 /*return*/];
415
+ }
416
+ });
417
+ }); };
418
+ //starts the process
419
+ runStack();
420
+ }
107
421
  /**
108
422
  * Returns a map of the modules that this repository manages (so no modules found through the workspaces who's path contains ../ )
109
423
  * @param rootPath
@@ -126,20 +440,26 @@ function getLocalLincdModules(rootPath) {
126
440
  });
127
441
  }
128
442
  function getLincdModules(rootPath) {
129
- if (rootPath === void 0) { rootPath = './'; }
130
- //TODO: read from package.json what the workspaces are. for each, follow up all the folders inside that path
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
132
- //TODO: this way it will work with websites as well, instead of just from the main LINCD repository
443
+ if (rootPath === void 0) { rootPath = process.cwd(); }
133
444
  var pack = (0, utils_1.getPackageJSON)();
134
- var res = [];
135
- if (!pack.workspaces) {
445
+ if (!pack || !pack.workspaces) {
446
+ for (var i = 0; i <= 3; i++) {
447
+ rootPath = path.join.apply(path, __spreadArray([process.cwd()], Array(i).fill('..'), false));
448
+ pack = (0, utils_1.getPackageJSON)(rootPath);
449
+ if (pack && pack.workspaces) {
450
+ // log('Found workspace at '+packagePath);
451
+ break;
452
+ }
453
+ }
454
+ }
455
+ if (!pack || !pack.workspaces) {
136
456
  warn(chalk.red('Could not find package workspaces. Make sure you run this command from a yarn workspace.'));
137
457
  logHelp();
138
458
  process.exit();
139
459
  }
140
- //TODO: filter with package.lincd = true?
460
+ // console.log(pack.workspaces);
461
+ var res = [];
141
462
  checkWorkspaces(rootPath, pack.workspaces, res);
142
- // console.log(res);
143
463
  return res;
144
464
  }
145
465
  function setVariable(name, replacement) {
@@ -201,12 +521,6 @@ function execp(cmd, log, allowError, options) {
201
521
  });
202
522
  });
203
523
  }
204
- function replaceVariables(string) {
205
- for (var key in variables) {
206
- string = string.replace(new RegExp(key, 'g'), variables[key]);
207
- }
208
- return string;
209
- }
210
524
  function execPromise(command, log, allowError, options) {
211
525
  if (log === void 0) { log = false; }
212
526
  if (allowError === void 0) { allowError = false; }
@@ -255,84 +569,231 @@ var replaceCurlyVariables = function (string) {
255
569
  };
256
570
  var capitalize = function (str) { return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1); };
257
571
  var camelCase = function (str) {
572
+ //this version does not replace any capitals already used by the user
258
573
  var string = str
259
- .toLowerCase()
260
574
  .replace(/[^A-Za-z0-9]/g, ' ')
261
575
  .split(' ')
262
- .reduce(function (result, word) { return result + capitalize(word.toLowerCase()); });
263
- return string.charAt(0).toLowerCase() + string.slice(1);
576
+ .reduce(function (result, word) { return result + capitalize(word); });
577
+ //it also leave the first capital intact
578
+ return string;
264
579
  };
265
- program.command('create-app [name] [uribase]').action(function (name, uriBase) {
266
- return createApp(name, uriBase);
267
- });
268
- program.command('create-module [name] [uribase]').action(function (name, uriBase) {
269
- return createModule(name, uriBase);
270
- });
271
- var createModule = function (name, uriBase, basePath) {
580
+ var createOntology = function (prefix, uriBase, basePath) {
272
581
  if (basePath === void 0) { basePath = process.cwd(); }
273
582
  return __awaiter(void 0, void 0, void 0, function () {
274
- var targetFolder, _a, packageName, scope, cleanPackageName, codeName, cameCaseName, underscoreName, version, installCommand;
583
+ var targetFolder, _a, hyphenName, camelCaseName, underscoreName, targetFile, targetDataFile, targetDataFile2, indexPath;
275
584
  return __generator(this, function (_b) {
276
585
  switch (_b.label) {
586
+ case 0:
587
+ if (!prefix) {
588
+ console.warn('Please provide a suggested prefix as the first argument');
589
+ return [2 /*return*/];
590
+ }
591
+ targetFolder = ensureFolderExists(basePath, 'src', 'ontologies');
592
+ if (!uriBase) {
593
+ uriBase = 'http://lincd.org/ont/' + prefix;
594
+ }
595
+ setVariable('uri_base', uriBase);
596
+ _a = setNameVariables(prefix), hyphenName = _a.hyphenName, camelCaseName = _a.camelCaseName, underscoreName = _a.underscoreName;
597
+ //copy ontology accessor file
598
+ log("Creating files for ontology '" + prefix + "'");
599
+ targetFile = path.join(targetFolder, hyphenName + '.ts');
600
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
601
+ targetDataFile = path.join(targetFolder, '..', 'data', hyphenName + '.json');
602
+ targetDataFile2 = path.join(targetFolder, '..', 'data', hyphenName + '.json.d.ts');
603
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'data', 'example-ontology.json'), targetDataFile);
604
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'data', 'example-ontology.json.d.ts'), targetDataFile2);
605
+ return [4 /*yield*/, replaceVariablesInFiles(targetFile, targetDataFile, targetDataFile2)];
606
+ case 1:
607
+ _b.sent();
608
+ indexPath = addLineToIndex("import './ontologies/".concat(hyphenName, "';"), 'ontologies');
609
+ 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)));
610
+ return [2 /*return*/];
611
+ }
612
+ });
613
+ });
614
+ };
615
+ var addLineToIndex = function (line, insertMatchString) {
616
+ //import ontology in index
617
+ var indexPath = ['index.ts', 'index.tsx']
618
+ .map(function (f) { return path.join('src', f); })
619
+ .find(function (indexFileName) {
620
+ return fs.existsSync(indexFileName);
621
+ });
622
+ if (indexPath) {
623
+ var indexContents = fs.readFileSync(indexPath, 'utf-8');
624
+ var lines = indexContents.split(/\n/g);
625
+ var newContents = void 0;
626
+ for (var key in lines) {
627
+ if (lines[key].indexOf(insertMatchString) !== -1) {
628
+ //remove lines after this line and insert new line in its place
629
+ lines[key] += "\n".concat(line);
630
+ newContents = lines.join('\n');
631
+ // log("Found at "+key,lines,newContents);
632
+ break;
633
+ }
634
+ }
635
+ if (!newContents) {
636
+ newContents = indexContents + "\n".concat(line);
637
+ // log("Added at end",newContents);
638
+ }
639
+ fs.writeFileSync(indexPath, newContents);
640
+ }
641
+ return indexPath;
642
+ };
643
+ var replaceVariablesInFiles = function () {
644
+ var files = [];
645
+ for (var _i = 0; _i < arguments.length; _i++) {
646
+ files[_i] = arguments[_i];
647
+ }
648
+ return Promise.all(files.map(function (file) {
649
+ return replaceVariablesInFile(file);
650
+ }));
651
+ };
652
+ var ensureFolderExists = function () {
653
+ var folders = [];
654
+ for (var _i = 0; _i < arguments.length; _i++) {
655
+ folders[_i] = arguments[_i];
656
+ }
657
+ var target;
658
+ folders.forEach(function (folder) {
659
+ target = target ? path.join(target, folder) : path.join(folder);
660
+ if (!fs.existsSync(target)) {
661
+ fs.mkdirSync(target);
662
+ }
663
+ });
664
+ return target;
665
+ /*let targetFolder = path.join(...folders);
666
+ let parentDirectory = folders.slice(0, folders.length - 1);
667
+ if (!fs.existsSync(targetFolder)) {
668
+ if (fs.existsSync(path.join(...parentDirectory))) {
669
+ fs.mkdirSync(targetFolder);
670
+ } else {
671
+ warn(
672
+ `Please run this command from the root of your module. This command expects ${parentDirectory.toString()} to exists from that folder`,
673
+ );
674
+ }
675
+ }
676
+ return targetFolder;*/
677
+ };
678
+ var setNameVariables = function (name) {
679
+ var hyphenName = name.replace(/[-_\s]+/g, '-');
680
+ var camelCaseName = camelCase(name); //some-module --> someModule
681
+ var underscoreName = name.replace(/[-\s]+/g, '_');
682
+ //longer similar variables names should come before the shorter ones
683
+ setVariable('underscore_name', underscoreName);
684
+ setVariable('hyphen_name', hyphenName);
685
+ setVariable('camel_name', camelCaseName);
686
+ setVariable('name', name);
687
+ return { hyphenName: hyphenName, camelCaseName: camelCaseName, underscoreName: underscoreName };
688
+ };
689
+ var createShape = function (name, basePath) {
690
+ if (basePath === void 0) { basePath = process.cwd(); }
691
+ return __awaiter(void 0, void 0, void 0, function () {
692
+ var targetFolder, _a, hyphenName, camelCaseName, underscoreName, targetFile, indexPath;
693
+ return __generator(this, function (_b) {
694
+ switch (_b.label) {
695
+ case 0:
696
+ targetFolder = ensureFolderExists(basePath, 'src', 'shapes');
697
+ _a = setNameVariables(name), hyphenName = _a.hyphenName, camelCaseName = _a.camelCaseName, underscoreName = _a.underscoreName;
698
+ //copy default shape file
699
+ log("Creating files for shape '" + name + "'");
700
+ targetFile = path.join(targetFolder, hyphenName + '.ts');
701
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'shape.ts'), targetFile);
702
+ //replace variables in some of the copied files
703
+ return [4 /*yield*/, replaceVariablesInFiles(targetFile)];
704
+ case 1:
705
+ //replace variables in some of the copied files
706
+ _b.sent();
707
+ indexPath = addLineToIndex("import './shapes/".concat(hyphenName, "';"), 'shapes');
708
+ log("Created a new shape class template in ".concat(chalk.magenta(targetFile.replace(basePath, ''))), "Added an import of this file from ".concat(chalk.magenta(indexPath)));
709
+ return [2 /*return*/];
710
+ }
711
+ });
712
+ });
713
+ };
714
+ var createModule = function (name, uriBase, basePath) {
715
+ if (basePath === void 0) { basePath = process.cwd(); }
716
+ return __awaiter(void 0, void 0, void 0, function () {
717
+ var _a, packageName, scope, cleanPackageName, targetFolder, _b, hyphenName, camelCaseName, underscoreName, version, installCommand;
718
+ return __generator(this, function (_c) {
719
+ switch (_c.label) {
277
720
  case 0:
278
721
  //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
722
  //so we manually find a modules folder, if it exists we go into that.
280
723
  if (fs.existsSync(path.join(basePath, 'modules'))) {
281
724
  basePath = path.join(basePath, 'modules');
282
725
  }
283
- targetFolder = path.join(basePath, name);
284
- console.log(targetFolder, basePath, name);
285
- if (!fs.existsSync(targetFolder)) {
286
- fs.mkdirSync(targetFolder);
726
+ if (!name) {
727
+ console.warn('Please provide a name as the first argument');
728
+ return [2 /*return*/];
287
729
  }
730
+ _a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
731
+ targetFolder = ensureFolderExists(basePath, cleanPackageName);
288
732
  if (!uriBase) {
289
733
  uriBase = 'http://lincd.org/ont/' + name;
290
734
  }
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
735
  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);
736
+ //find @scope and the next part between 2 slashes after
737
+ //so @dacore/some-mod/lib/file.js
738
+ // --> match[0] = @dacore/some-mod
739
+ // --> match[1] = @dacore
740
+ // --> match[2] = some-mod
741
+ //but save full scoped module name under ${module_name}
309
742
  setVariable('module_name', name);
743
+ //extra variable for clarity (will be same as 'name')
744
+ setVariable('output_file_name', name);
745
+ _b = setNameVariables(cleanPackageName), hyphenName = _b.hyphenName, camelCaseName = _b.camelCaseName, underscoreName = _b.underscoreName;
310
746
  log("Creating new LINCD module '" + name + "'");
747
+ fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), targetFolder);
311
748
  //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);
749
+ return [4 /*yield*/, Promise.all([
750
+ 'src/index.ts',
751
+ 'package.json',
752
+ 'Gruntfile.js',
753
+ 'src/module.ts',
754
+ 'src/shapes/ExampleShapeClass.ts',
755
+ 'src/ontologies/example-ontology.ts',
756
+ 'src/data/example-ontology.json',
757
+ ]
758
+ .map(function (f) { return path.join(targetFolder, f); })
759
+ .map(function (file) {
760
+ return replaceVariablesInFile(file);
761
+ }))];
762
+ case 1:
763
+ //replace variables in some of the copied files
764
+ _c.sent();
765
+ //rename these to a file name similar to the module name
766
+ [
767
+ 'src/ontologies/example-ontology.ts',
768
+ 'src/data/example-ontology.json',
769
+ 'src/data/example-ontology.json.d.ts',
770
+ ].forEach(function (f) {
771
+ var parts = f.split('/');
772
+ var newParts = __spreadArray([], parts, true);
773
+ var _a = newParts.pop().split('.'), name = _a[0], extensions = _a.slice(1);
774
+ var newName = hyphenName + '.' + extensions.join('.');
775
+ console.log('rename ', path.join(targetFolder, f), path.join.apply(path, __spreadArray(__spreadArray([targetFolder], newParts, false), [newName], false)));
776
+ fs.renameSync(path.join(targetFolder, f), path.join.apply(path, __spreadArray(__spreadArray([targetFolder], newParts, false), [newName], false)));
316
777
  });
317
778
  return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
318
- console.log("yarn probably not working");
779
+ console.log('yarn probably not working');
319
780
  return '';
320
781
  })];
321
- case 1:
322
- version = _b.sent();
782
+ case 2:
783
+ version = (_c.sent());
323
784
  installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
324
785
  return [4 /*yield*/, execp("cd ".concat(targetFolder, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
325
- console.warn("Could not install dependencies");
786
+ console.warn('Could not install dependencies');
326
787
  })];
327
- case 2:
328
- _b.sent();
788
+ case 3:
789
+ _c.sent();
329
790
  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
791
  return [2 /*return*/];
331
792
  }
332
793
  });
333
794
  });
334
795
  };
335
- var createApp = function (name, uriBase, basePath) {
796
+ var createApp = function (name, basePath) {
336
797
  if (basePath === void 0) { basePath = process.cwd(); }
337
798
  return __awaiter(void 0, void 0, void 0, function () {
338
799
  var _a, packageName, scope, cleanPackageName, targetFolder, codeName, cameCaseName, underscoreName, version, installCommand;
@@ -340,12 +801,9 @@ var createApp = function (name, uriBase, basePath) {
340
801
  switch (_b.label) {
341
802
  case 0:
342
803
  if (!name) {
343
- console.warn("Please provide a name as the first argument");
804
+ console.warn('Please provide a name as the first argument');
344
805
  }
345
806
  _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
807
  targetFolder = path.join(basePath, name);
350
808
  if (!fs.existsSync(targetFolder)) {
351
809
  fs.mkdirSync(targetFolder);
@@ -354,7 +812,7 @@ var createApp = function (name, uriBase, basePath) {
354
812
  codeName = cleanPackageName.replace(/\-/g, '_');
355
813
  cameCaseName = camelCase(name);
356
814
  underscoreName = name.replace(/[-\s]+/g, '_');
357
- setVariable('uri_base', uriBase);
815
+ // setVariable('uri_base', uriBase);
358
816
  //longer similar variables names should come before the shorter ones
359
817
  setVariable('camelcase_name', cameCaseName);
360
818
  setVariable('underscore_name', underscoreName);
@@ -367,14 +825,14 @@ var createApp = function (name, uriBase, basePath) {
367
825
  replaceVariablesInFile(file);
368
826
  });
369
827
  return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
370
- console.log("yarn probably not working");
828
+ console.log('yarn probably not working');
371
829
  return '';
372
830
  })];
373
831
  case 1:
374
- version = _b.sent();
832
+ version = (_b.sent());
375
833
  installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
376
834
  return [4 /*yield*/, execp("cd ".concat(name, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
377
- console.warn("Could not install dependencies");
835
+ console.warn('Could not install dependencies');
378
836
  })];
379
837
  case 2:
380
838
  _b.sent();
@@ -437,16 +895,14 @@ var buildFailed = function (output) {
437
895
  console.warn('Not a project');
438
896
  }
439
897
  });*/
440
- program.command('register [version]').action(function (newVersion) {
898
+ var register = function (registryURL) {
441
899
  if (fs.existsSync(process.cwd() + '/package.json')) {
442
900
  var pack = JSON.parse(fs.readFileSync(process.cwd() + '/package.json', 'utf8'));
443
901
  var version = pack.version;
444
902
  var moduleName = pack.name;
445
903
  var author = pack.author;
446
- // let displayName = pack.displayName;
447
904
  console.log(chalk.cyan('registering ' + author + "'s module, " + moduleName + ' ' + version + ' in the LINCD registry'));
448
- //temporary test code
449
- return fetch('http://localhost:4001/register', {
905
+ return fetch(registryURL + '/register', {
450
906
  method: 'POST',
451
907
  headers: {
452
908
  Accept: 'application/json, text/plain, */*',
@@ -463,113 +919,13 @@ program.command('register [version]').action(function (newVersion) {
463
919
  console.log(chalk.cyan('Response: ') + json.result);
464
920
  }
465
921
  })["catch"](function (err) {
466
- console.warn('Could not connect to LINCD registry');
922
+ console.warn(chalk.red('Warning: ') + 'Could not connect to LINCD registry');
467
923
  });
468
- /*console.log(chalk.cyan('building production bundles'));
469
- return execPromise('yarn lincd build production', false, true)
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
- });*/
520
924
  }
521
925
  else {
522
- console.warn('not found: ' + process.cwd() + '/package.json');
523
- }
524
- });
525
- // program.command('create [action] [value]').action((action, prefixedUri) => {
526
- //
527
- // let [ontology,label] = typeof prefixedUri !== 'undefined' ? prefixedUri.split(":") : [];
528
- // if(!ontology || !label)
529
- // {
530
- // return console.warn("Please provide a prefixed URI of the "+action+" to create");
531
- // }
532
- // if(action == 'viewtype')
533
- // {
534
- // //add to ontology file
535
- // let contents = fs.readFileSync(path.join('src','ontologies',ontology),'utf8');
536
- //
537
- //
538
- // //create view file
539
- // //add view file to index
540
- // }
541
- // });
542
- program.command('info').action(function () {
543
- var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
544
- console.log(ownPackage.version);
545
- console.log('Running from: ' + __dirname);
546
- });
547
- var ensurePath = function () {
548
- var folders = [];
549
- for (var _i = 0; _i < arguments.length; _i++) {
550
- folders[_i] = arguments[_i];
926
+ console.warn(chalk.red('Warning:') + ' not found: ' + process.cwd() + '/package.json');
551
927
  }
552
- // let target = path.join(folders.shift());
553
- var target;
554
- folders.forEach(function (folder) {
555
- target = target ? path.join(target, folder) : path.join(folder);
556
- if (!fs.existsSync(target)) {
557
- fs.mkdirSync(target);
558
- }
559
- });
560
- return target;
561
928
  };
562
- program.command('test-build').action(function (target, target2) {
563
- execPromise('yarn lincd build', true)
564
- .then(function (result) {
565
- console.log('success');
566
- })["catch"](function (err) {
567
- console.log('failed');
568
- });
569
- });
570
- program.command('build [target] [target2]').action(function (target, target2) {
571
- buildModule(target, target2);
572
- });
573
929
  var buildModule = function (target, target2, modulePath, logResults) {
574
930
  if (modulePath === void 0) { modulePath = process.cwd(); }
575
931
  if (logResults === void 0) { logResults = true; }
@@ -611,9 +967,6 @@ var buildModule = function (target, target2, modulePath, logResults) {
611
967
  console.warn('unknown build target. Use es5, es6 or production.');
612
968
  }
613
969
  };
614
- // program.command('css').action((message) => {
615
- // return execp('grunt babel:css-module-transforms');
616
- // });
617
970
  var getLastBuildTime = function (modulePath) {
618
971
  return getLastModifiedFile(modulePath + '/@(builds|lib)/**/*.js');
619
972
  };
@@ -643,12 +996,6 @@ var getLastModifiedFile = function (filePath, config) {
643
996
  // console.log("skipping directory "+fileName);
644
997
  return;
645
998
  }
646
- //not counting things that are generated during build process when determining last modified source-code time
647
- // if(fileName.indexOf(".d.ts") !== -1 || fileName.indexOf(".css.json") !== -1)
648
- // {
649
- // // console.log("not counting "+fileName);
650
- // return;
651
- // }
652
999
  var mtime = fs.statSync(path.join(fileName)).mtime;
653
1000
  var modifiedTime = mtime.getTime();
654
1001
  if (modifiedTime > lastModifiedTime) {
@@ -660,14 +1007,6 @@ var getLastModifiedFile = function (filePath, config) {
660
1007
  });
661
1008
  return { lastModified: lastModified, lastModifiedName: lastModifiedName, lastModifiedTime: lastModifiedTime };
662
1009
  };
663
- program.command('publish-updated').action(function () {
664
- return publishUpdated();
665
- });
666
- program.command('status').action(function () {
667
- return publishUpdated(true).then(function () {
668
- return buildUpdated(undefined, '', '', true);
669
- });
670
- });
671
1010
  var publishUpdated = function (test) {
672
1011
  var _this = this;
673
1012
  if (test === void 0) { test = false; }
@@ -771,12 +1110,6 @@ var executeSingleBuild = function (module, previousResult, test, info) {
771
1110
  return previousResult + ' ' + chalk.blue(module.moduleName + ' should publish\n');
772
1111
  }
773
1112
  };
774
- program.command('build-updated [target] [target2]').action(function (target, target2) {
775
- return buildUpdated(1, target, target2);
776
- });
777
- program.command('build-updated-since [num-commits-back] [target] [target2]').action(function (back, target, target2) {
778
- return buildUpdated(back, target, target2);
779
- });
780
1113
  var buildUpdated = function (back, target, target2, test) {
781
1114
  if (test === void 0) { test = false; }
782
1115
  // back = back || 1;
@@ -837,205 +1170,9 @@ var buildUpdated = function (back, target, target2, test) {
837
1170
  });
838
1171
  // });
839
1172
  };
840
- program.command('build-all [target] [target2]').action(function (target, target2) {
841
- var dependencies = new Map();
842
- console.log('Building all modules of this repository in order of dependencies');
843
- var modules = getLocalLincdModuleMap();
844
- //get dependencies of each module
845
- var leastDependentModule;
846
- modules.forEach(function (module) {
847
- var pack = (0, utils_1.getPackageJSON)(module.path);
848
- if (pack) {
849
- //get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
850
- var moduleDependencies = Object.keys(pack.dependencies)
851
- .filter(function (dependency) { return modules.has(dependency); })
852
- .map(function (dependency) {
853
- return modules.has(dependency) ? modules.get(dependency) : dependency;
854
- });
855
- // console.log(module.moduleName,moduleDependencies.map())
856
- dependencies.set(module, moduleDependencies);
857
- }
858
- });
859
- dependencies.forEach(function (moduleDependencies, module) {
860
- if (!moduleDependencies.some(function (dependency) {
861
- return typeof dependency !== 'string' && modules.has(dependency.moduleName);
862
- })) {
863
- leastDependentModule = module;
864
- }
865
- });
866
- var startFrom;
867
- //by default start building
868
- var building = true;
869
- //option to start from a specific module in the stack
870
- if (target == 'from') {
871
- startFrom = target2;
872
- //if we have a startFrom, then we havnt started the build process yet
873
- building = startFrom ? false : true;
874
- //clear targets
875
- target = '';
876
- target2 = '';
877
- console.log(chalk.blue('Will skip builds until ' + startFrom));
878
- }
879
- var stack = [leastDependentModule];
880
- var done = new Set();
881
- var p = Promise.resolve();
882
- var runStack = function () { return __awaiter(void 0, void 0, void 0, function () {
883
- var modulesLeft, stackPromise, first_1;
884
- return __generator(this, function (_a) {
885
- switch (_a.label) {
886
- case 0:
887
- modulesLeft = modules.size - done.size;
888
- if (done.size > 0) {
889
- console.log(chalk.magenta('\n-------\nThese modules are next, since all their dependencies have now been build:'));
890
- console.log(chalk.magenta(stack.map(function (i) { return i.moduleName; })));
891
- // log(stack);
892
- }
893
- stackPromise = Promise.all(stack.map(function (module) {
894
- // p = p.then(() => {
895
- var command;
896
- //if we're skipping builds until a certain module
897
- if (!building) {
898
- //if the module name matches the module we're supposed to start from then start building modules
899
- if (module.moduleName == startFrom || module.packageName == startFrom) {
900
- building = true;
901
- }
902
- //else still waiting for the module
903
- else {
904
- log(chalk.blue('skipping ' + module.moduleName));
905
- command = Promise.resolve(true);
906
- }
907
- }
908
- //unless told otherwise, build the module
909
- if (!command) {
910
- command = execp('cd ' +
911
- module.path +
912
- ' && yarn lincd build' +
913
- (target ? ' ' + target : '') +
914
- (target2 ? ' ' + target2 : ''));
915
- log(chalk.cyan('Building ' + module.moduleName));
916
- }
917
- return command["catch"](function (err) {
918
- var dependentModules = [];
919
- dependencies.forEach(function (dModuleDependencies, dModule) {
920
- if (dModuleDependencies.indexOf(module) !== -1) {
921
- dependentModules.push(dModule);
922
- }
923
- });
924
- if (dependentModules.length > 0) {
925
- console.log(chalk.magenta('Stopping build process because an error occurred whilst building ' +
926
- module.moduleName +
927
- ', which ' +
928
- dependentModules.length +
929
- ' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
930
- console.log(chalk.cyanBright('tip ') +
931
- 'Run ' +
932
- chalk.green("lincd build-all from ".concat(module.moduleName)) +
933
- ' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
934
- process.exit(1);
935
- }
936
- })
937
- .then(function (res) {
938
- done.add(module);
939
- modulesLeft--;
940
- log(chalk.magenta(modulesLeft + ' modules left'));
941
- return res;
942
- });
943
- // });
944
- // done.add(module);
945
- }));
946
- //wait till stack is completed
947
- return [4 /*yield*/, stackPromise];
948
- case 1:
949
- //wait till stack is completed
950
- _a.sent();
951
- // await p;
952
- //clear stack for next round
953
- stack = [];
954
- //find those modules who have all their dependencies already built and add them to the stack
955
- modules.forEach(function (module) {
956
- var deps = dependencies.get(module);
957
- //if the module is not done yet
958
- //but every dependency is now done OR was not something we can build (some @dacore dependencies may not be local)
959
- if (!done.has(module) &&
960
- deps.every(function (dependency) {
961
- return typeof dependency !== 'string' && (done.has(dependency) || !modules.has(dependency.moduleName));
962
- })) {
963
- stack.push(module);
964
- }
965
- // else if(!done.has(module))
966
- // {
967
- // console.log(chalk.red(module+' not yet'))
968
- // console.log('UNMET DEPS: '+deps.filter(dependency => !done.has(dependency)).join(" "))
969
- // }
970
- });
971
- //if more to be built, iterate
972
- if (stack.length > 0) {
973
- return [2 /*return*/, runStack()];
974
- }
975
- else {
976
- //if no more modules to build but we never started building...
977
- if (!building) {
978
- console.log(chalk.red('Could not find the module to start from. Please provide a correct package name or module name to build from'));
979
- }
980
- else {
981
- first_1 = true;
982
- modules.forEach(function (module) {
983
- if (!done.has(module)) {
984
- var deps = dependencies.get(module);
985
- if (first_1) {
986
- console.log(chalk.red('CYCLICAL DEPENDENCIES? - could not build some modules because they depend on each other.'));
987
- first_1 = false;
988
- }
989
- //print the cyclical dependencies
990
- console.log(chalk.red(module.moduleName) +
991
- ' depends on ' +
992
- deps
993
- .filter(function (dependency) {
994
- return typeof dependency !== 'string';
995
- })
996
- .map(function (d) {
997
- return done.has(d) ? d.moduleName : chalk.red(d.moduleName);
998
- })
999
- .join(', '));
1000
- //also print some information why these modules have not been moved into the stack
1001
- var stringDependencies = deps.filter(function (d) { return typeof d === 'string'; });
1002
- if (stringDependencies.length > 0) {
1003
- console.log(chalk.red('And it depends on these module(s) - which seem not to be proper modules :' +
1004
- stringDependencies.join(', ')));
1005
- console.log(chalk.red('Could you remove this from dependencies? Should it be a devDependency?'));
1006
- }
1007
- }
1008
- });
1009
- }
1010
- }
1011
- return [2 /*return*/];
1012
- }
1013
- });
1014
- }); };
1015
- //starts the process
1016
- runStack();
1017
- });
1018
- program.command('modules [action] [includedSpaces]').action(function (command, includedSpaces) {
1019
- executeCommandForEachModule(getLincdModules(), command, includedSpaces);
1020
- });
1021
- program.command('modules-except [excludedSpaces] [action]').action(function (excludedSpaces, command) {
1022
- executeCommandForEachModule(getLincdModules(), command, null, excludedSpaces);
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');
1173
+ var printFailedModules = function (modules) {
1174
+ log('These modules failed to build:\n\t' + chalk.red(modules.join('\n\t')) + '\n');
1175
+ };
1039
1176
  var executeCommandForEachModule = function (modules, command, includedSpaces, excludedSpaces) {
1040
1177
  //if a specific set of modules is given
1041
1178
  if (includedSpaces) {
@@ -1061,88 +1198,16 @@ var executeCommandForEachModule = function (modules, command, includedSpaces, ex
1061
1198
  });
1062
1199
  return p;
1063
1200
  };
1064
- var executeCommandForModule = function (module, command) {
1201
+ var executeCommandForModule = function (moduleName, command) {
1065
1202
  var moduleDetails = getLincdModules().find(function (modDetails) {
1066
- return modDetails.packageName.indexOf(module) !== -1 || modDetails.moduleName.indexOf(module) !== -1;
1203
+ return modDetails.packageName.indexOf(moduleName) !== -1 || modDetails.moduleName.indexOf(moduleName) !== -1;
1067
1204
  });
1068
1205
  if (moduleDetails) {
1069
- log("Executing 'cd " + moduleDetails.path + ' && lincd ' + command + "'");
1070
- return execp('cd ' + moduleDetails.path + ' && lincd ' + command);
1071
- }
1072
- };
1073
- program.command('dev [target] [mode]').action(function (target, mode) {
1074
- if (!target)
1075
- target = 'es6';
1076
- if (mode !== 'production')
1077
- mode = '';
1078
- else if (target !== 'es6')
1079
- log('target must be es6 when developing for production');
1080
- if (target == 'es5' || target == 'es6') {
1081
- // log('> Starting continuous development build for '+target+' target')
1082
- log('starting continuous development build');
1083
- log('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
1084
- var command = exec('grunt dev' + (target ? '-' + target : '') + (mode ? '-' + mode : '') + ' --color');
1085
- command.stdout.pipe(process.stdout);
1086
- command.stderr.pipe(process.stderr);
1206
+ log("Executing 'cd " + moduleDetails.path + ' && yarn lincd' + (command ? ' ' + command : '') + "'");
1207
+ return execp('cd ' + moduleDetails.path + ' && yarn lincd' + (command ? ' ' + command : ''));
1087
1208
  }
1088
1209
  else {
1089
- console.warn('unknown build target. Use es5 or es6');
1210
+ warn("Could not find a module who\'s name (partially) matched " + chalk.cyan(moduleName));
1090
1211
  }
1091
- });
1092
- program.command('help').action(function (command) {
1093
- logHelp();
1094
- });
1095
- program.command('*').action(function (command) {
1096
- console.warn(chalk.red('unknown command: ' + command.args.join(' ')));
1097
- logHelp();
1098
- });
1099
- function logHelp() {
1100
- var ownPackage = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
1101
- console.log('lincd-cli ' + ownPackage.version);
1102
- console.log(chalk.green('\nAvailable commands from a module:'));
1103
- console.log(chalk.blue('- build [es5|es6|production] [es5|es6] ') +
1104
- chalk.cyan('- creates bundles & compiles source files each target environment'));
1105
- console.log(chalk.blue('- dev [es5|es6] [production] ') +
1106
- chalk.cyan('- continuously build bundles & compile source on file changes'));
1107
- // console.log(
1108
- // chalk.blue('- init [name] [uribase] ') +
1109
- // chalk.cyan(
1110
- // '- sets up a new module, sets up initial files and installs dependencies',
1111
- // ),
1112
- // );
1113
- console.log(chalk.blue('- publish [version|minor|major|patch] ') +
1114
- chalk.cyan('- publish new version to the npm registry AND to the LINCD.org registry'));
1115
- //TODO: these all need to be tested to see if they work with the new LINCD setup
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'));
1119
- console.log(chalk.blue('- build-all [from] [module-name]') +
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'));
1123
- /*
1124
- console.log(
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
- ),
1129
- );
1130
- console.log(
1131
- chalk.blue('- modules [action]') +
1132
- chalk.cyan('- execute a command for all modules'),
1133
- );
1134
- console.log(
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
- ),
1139
- );
1140
- console.log(
1141
- chalk.blue('- status') +
1142
- chalk.cyan('- see which modules need to be published or build'),
1143
- );*/
1144
- console.log(chalk.green('\nOther commands:'));
1145
- console.log(chalk.blue('- info ') + chalk.cyan('- print the version of this tool and where it runs from'));
1146
- console.log(chalk.blue('- help ') + chalk.cyan('- print this message'));
1147
- }
1212
+ };
1148
1213
  program.parse(process.argv);