lincd-cli 0.1.6 → 0.1.9
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.
- package/{src/cli.js → cli.js} +2 -2
- package/config-generator.js +568 -0
- package/defaults/app/Gruntfile.js +13 -0
- package/defaults/app/index.html +12 -0
- package/defaults/{package.json → app/package.json} +4 -2
- package/defaults/app/tsconfig-es5.json +18 -0
- package/defaults/module/.npmignore +6 -0
- package/defaults/module/package.json +14 -6
- package/defaults/shape.ts +8 -0
- package/{src/index.js → index.js} +9 -5
- package/lib/cli.js +362 -107
- package/lib/config-grunt.js +34 -30
- package/lib/config-webpack.js +9 -7
- package/lib/index.js +5 -1
- package/lib/plugins/declaration-plugin.js +9 -9
- package/lib/plugins/externalise-modules.js +13 -13
- package/lib/plugins/watch-run.js +1 -1
- package/lib/utils.js +5 -1
- package/package.json +12 -10
- package/{src/plugins → plugins}/declaration-plugin.js +0 -0
- package/{src/plugins → plugins}/externalise-modules.js +0 -0
- package/{src/plugins → plugins}/watch-run.js +0 -0
- package/utils.js +39 -0
- package/defaults/create_migration.js +0 -155
- package/defaults/create_migration.ts +0 -7
- package/defaults/defaultModule/Index.js +0 -30
- package/defaults/defaultModule/Index.scss +0 -19
- package/defaults/defaultModule/Index.tsx +0 -25
- package/defaults/defaultModule/data.json +0 -56
- package/defaults/defaultModule/defaultOntology.json +0 -23
- package/defaults/defaultModule/index.ts +0 -12
- package/defaults/defaultModule/ontology.js +0 -21
- package/defaults/defaultModule/ontology.ts +0 -16
- package/defaults/gitignorefile +0 -4
- package/defaults/index.ts +0 -13
- package/defaults/module/src/components/ExampleComponent.tsx +0 -22
- package/defaults/module/src/data/example-ontology.json +0 -20
- package/defaults/module/src/data/example-ontology.json.d.ts +0 -1
- package/defaults/module/src/index.ts +0 -7
- package/defaults/module/src/module.ts +0 -9
- package/defaults/module/src/ontologies/example-ontology.ts +0 -33
- package/defaults/module/src/shapes/ExampleShapeClass.ts +0 -30
- package/defaults/ontology.ts +0 -16
- package/defaults/providers.ts +0 -1
- package/defaults/site/package.json +0 -40
- package/defaults/site/storage/filestores/settings-production-template.jsonld +0 -129
- package/defaults/site/web/.htaccess +0 -19
- package/defaults/site/web/favicon.png +0 -0
- package/defaults/site/web/img/placeholder.jpg +0 -0
- package/src/config-grunt.js +0 -263
- package/src/config-webpack.js +0 -281
- package/src/interfaces.js +0 -2
- package/src/plugins/shapes-plugin.js +0 -69
- 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++) {
|
|
@@ -129,7 +139,7 @@ function getLincdModules(rootPath) {
|
|
|
129
139
|
//TODO: read from package.json what the workspaces are. for each, follow up all the folders inside that path
|
|
130
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
|
|
131
141
|
//TODO: this way it will work with websites as well, instead of just from the main LINCD repository
|
|
132
|
-
var pack = utils_1.getPackageJSON();
|
|
142
|
+
var pack = (0, utils_1.getPackageJSON)();
|
|
133
143
|
var res = [];
|
|
134
144
|
if (!pack.workspaces) {
|
|
135
145
|
warn(chalk.red('Could not find package workspaces. Make sure you run this command from a yarn workspace.'));
|
|
@@ -254,58 +264,291 @@ var replaceCurlyVariables = function (string) {
|
|
|
254
264
|
};
|
|
255
265
|
var capitalize = function (str) { return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1); };
|
|
256
266
|
var camelCase = function (str) {
|
|
267
|
+
//this version does not replace any capitals already used by the user
|
|
257
268
|
var string = str
|
|
258
|
-
.toLowerCase()
|
|
259
269
|
.replace(/[^A-Za-z0-9]/g, ' ')
|
|
260
270
|
.split(' ')
|
|
261
|
-
.reduce(function (result, word) { return result + capitalize(word
|
|
262
|
-
|
|
271
|
+
.reduce(function (result, word) { return result + capitalize(word); });
|
|
272
|
+
//it also leave the first capital intact
|
|
273
|
+
return string;
|
|
274
|
+
// let string = str
|
|
275
|
+
// .toLowerCase()
|
|
276
|
+
// .replace(/[^A-Za-z0-9]/g, ' ')
|
|
277
|
+
// .split(' ')
|
|
278
|
+
// .reduce((result, word) => result + capitalize(word.toLowerCase()));
|
|
279
|
+
// return string.charAt(0).toLowerCase() + string.slice(1);
|
|
263
280
|
};
|
|
264
|
-
program.command('
|
|
265
|
-
return
|
|
281
|
+
program.command('create-app [name] [uribase]').action(function (name, uriBase) {
|
|
282
|
+
return createApp(name, uriBase);
|
|
283
|
+
});
|
|
284
|
+
program.command('create-module [name] [uribase]').action(function (name, uriBase) {
|
|
285
|
+
return createModule(name, uriBase);
|
|
266
286
|
});
|
|
267
|
-
|
|
287
|
+
program.command('create-shape [name]').action(function (name, uriBase) {
|
|
288
|
+
return createShape(name);
|
|
289
|
+
});
|
|
290
|
+
program.command('create-ontology [suggested-prefix] [uribase]').action(function (prefix, uriBase) {
|
|
291
|
+
return createOntology(prefix, uriBase);
|
|
292
|
+
});
|
|
293
|
+
var createOntology = function (prefix, uriBase, basePath) {
|
|
268
294
|
if (basePath === void 0) { basePath = process.cwd(); }
|
|
269
|
-
|
|
270
|
-
|
|
295
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
296
|
+
var targetFolder, _a, hyphenName, camelCaseName, underscoreName, targetFile, targetDataFile, targetDataFile2, indexPath;
|
|
297
|
+
return __generator(this, function (_b) {
|
|
298
|
+
switch (_b.label) {
|
|
299
|
+
case 0:
|
|
300
|
+
if (!prefix) {
|
|
301
|
+
console.warn('Please provide a suggested prefix as the first argument');
|
|
302
|
+
return [2 /*return*/];
|
|
303
|
+
}
|
|
304
|
+
targetFolder = ensureFolderExists(basePath, 'src', 'ontologies');
|
|
305
|
+
if (!uriBase) {
|
|
306
|
+
uriBase = 'http://lincd.org/ont/' + prefix;
|
|
307
|
+
}
|
|
308
|
+
setVariable('uri_base', uriBase);
|
|
309
|
+
_a = setNameVariables(prefix), hyphenName = _a.hyphenName, camelCaseName = _a.camelCaseName, underscoreName = _a.underscoreName;
|
|
310
|
+
//copy ontology accessor file
|
|
311
|
+
log("Creating files for ontology '" + prefix + "'");
|
|
312
|
+
targetFile = path.join(targetFolder, hyphenName + '.ts');
|
|
313
|
+
fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
|
|
314
|
+
targetDataFile = path.join(targetFolder, '..', 'data', hyphenName + '.json');
|
|
315
|
+
targetDataFile2 = path.join(targetFolder, '..', 'data', hyphenName + '.json.d.ts');
|
|
316
|
+
fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'data', 'example-ontology.json'), targetDataFile);
|
|
317
|
+
fs.copySync(path.join(__dirname, '..', 'defaults', 'module', 'src', 'data', 'example-ontology.json.d.ts'), targetDataFile2);
|
|
318
|
+
return [4 /*yield*/, replaceVariablesInFiles(targetFile, targetDataFile, targetDataFile2)];
|
|
319
|
+
case 1:
|
|
320
|
+
_b.sent();
|
|
321
|
+
indexPath = addLineToIndex("import './ontologies/".concat(hyphenName, "';"), 'ontologies');
|
|
322
|
+
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)));
|
|
323
|
+
return [2 /*return*/];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
var addLineToIndex = function (line, insertMatchString) {
|
|
329
|
+
//import ontology in index
|
|
330
|
+
var indexPath = ['index.ts', 'index.tsx']
|
|
331
|
+
.map(function (f) { return path.join('src', f); })
|
|
332
|
+
.find(function (indexFileName) {
|
|
333
|
+
return fs.existsSync(indexFileName);
|
|
334
|
+
});
|
|
335
|
+
if (indexPath) {
|
|
336
|
+
var indexContents = fs.readFileSync(indexPath, 'utf-8');
|
|
337
|
+
var lines = indexContents.split(/\n/g);
|
|
338
|
+
var newContents = void 0;
|
|
339
|
+
for (var key in lines) {
|
|
340
|
+
if (lines[key].indexOf(insertMatchString) !== -1) {
|
|
341
|
+
//remove lines after this line and insert new line in its place
|
|
342
|
+
lines[key] += "\n".concat(line);
|
|
343
|
+
newContents = lines.join('\n');
|
|
344
|
+
// log("Found at "+key,lines,newContents);
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (!newContents) {
|
|
349
|
+
newContents = indexContents + "\n".concat(line);
|
|
350
|
+
// log("Added at end",newContents);
|
|
351
|
+
}
|
|
352
|
+
fs.writeFileSync(indexPath, newContents);
|
|
353
|
+
}
|
|
354
|
+
return indexPath;
|
|
355
|
+
};
|
|
356
|
+
var replaceVariablesInFiles = function () {
|
|
357
|
+
var files = [];
|
|
358
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
359
|
+
files[_i] = arguments[_i];
|
|
360
|
+
}
|
|
361
|
+
return Promise.all(files.map(function (file) {
|
|
362
|
+
return replaceVariablesInFile(file);
|
|
363
|
+
}));
|
|
364
|
+
};
|
|
365
|
+
var ensureFolderExists = function () {
|
|
366
|
+
var folders = [];
|
|
367
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
368
|
+
folders[_i] = arguments[_i];
|
|
271
369
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
// --> match[0] = @dacore/some-mod
|
|
278
|
-
// --> match[1] = @dacore
|
|
279
|
-
// --> match[2] = some-mod
|
|
280
|
-
var _a = pack.name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
|
|
281
|
-
name = cleanPackageName;
|
|
370
|
+
var targetFolder = path.join.apply(path, folders);
|
|
371
|
+
var parentDirectory = folders.slice(0, folders.length - 1);
|
|
372
|
+
if (!fs.existsSync(targetFolder)) {
|
|
373
|
+
if (fs.existsSync(path.join.apply(path, parentDirectory))) {
|
|
374
|
+
fs.mkdirSync(targetFolder);
|
|
282
375
|
}
|
|
283
376
|
else {
|
|
284
|
-
|
|
377
|
+
warn("Please run this command from the root of your module. This command expects ".concat(parentDirectory.toString(), " to exists from that folder"));
|
|
285
378
|
}
|
|
286
379
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), basePath);
|
|
294
|
-
var camelCaseModuleName = camelCase(name); //some-module --> someModule
|
|
295
|
-
var underscoreModuleName = name.replace(/[-\s]+/g, '_');
|
|
296
|
-
setVariable('uri_base', uriBase);
|
|
380
|
+
return targetFolder;
|
|
381
|
+
};
|
|
382
|
+
var setNameVariables = function (name) {
|
|
383
|
+
var hyphenName = name.replace(/[-_\s]+/g, '-');
|
|
384
|
+
var camelCaseName = camelCase(name); //some-module --> someModule
|
|
385
|
+
var underscoreName = name.replace(/[-\s]+/g, '_');
|
|
297
386
|
//longer similar variables names should come before the shorter ones
|
|
298
|
-
setVariable('
|
|
299
|
-
setVariable('
|
|
300
|
-
setVariable('
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
387
|
+
setVariable('underscore_name', underscoreName);
|
|
388
|
+
setVariable('hyphen_name', hyphenName);
|
|
389
|
+
setVariable('camel_name', camelCaseName);
|
|
390
|
+
setVariable('name', name);
|
|
391
|
+
return { hyphenName: hyphenName, camelCaseName: camelCaseName, underscoreName: underscoreName };
|
|
392
|
+
};
|
|
393
|
+
var createShape = function (name, basePath) {
|
|
394
|
+
if (basePath === void 0) { basePath = process.cwd(); }
|
|
395
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
396
|
+
var targetFolder, _a, hyphenName, camelCaseName, underscoreName, targetFile, indexPath;
|
|
397
|
+
return __generator(this, function (_b) {
|
|
398
|
+
switch (_b.label) {
|
|
399
|
+
case 0:
|
|
400
|
+
targetFolder = ensureFolderExists(basePath, 'src', 'shapes');
|
|
401
|
+
_a = setNameVariables(name), hyphenName = _a.hyphenName, camelCaseName = _a.camelCaseName, underscoreName = _a.underscoreName;
|
|
402
|
+
//copy default shape file
|
|
403
|
+
log("Creating files for shape '" + name + "'");
|
|
404
|
+
targetFile = path.join(targetFolder, hyphenName + '.ts');
|
|
405
|
+
fs.copySync(path.join(__dirname, '..', 'defaults', 'shape.ts'), targetFile);
|
|
406
|
+
//replace variables in some of the copied files
|
|
407
|
+
return [4 /*yield*/, replaceVariablesInFiles(targetFile)];
|
|
408
|
+
case 1:
|
|
409
|
+
//replace variables in some of the copied files
|
|
410
|
+
_b.sent();
|
|
411
|
+
indexPath = addLineToIndex("import './shapes/".concat(hyphenName, "';"), 'shapes');
|
|
412
|
+
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)));
|
|
413
|
+
return [2 /*return*/];
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
var createModule = function (name, uriBase, basePath) {
|
|
419
|
+
if (basePath === void 0) { basePath = process.cwd(); }
|
|
420
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
421
|
+
var _a, packageName, scope, cleanPackageName, targetFolder, _b, hyphenName, camelCaseName, underscoreName, version, installCommand;
|
|
422
|
+
return __generator(this, function (_c) {
|
|
423
|
+
switch (_c.label) {
|
|
424
|
+
case 0:
|
|
425
|
+
//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)
|
|
426
|
+
//so we manually find a modules folder, if it exists we go into that.
|
|
427
|
+
if (fs.existsSync(path.join(basePath, 'modules'))) {
|
|
428
|
+
basePath = path.join(basePath, 'modules');
|
|
429
|
+
}
|
|
430
|
+
if (!name) {
|
|
431
|
+
console.warn('Please provide a name as the first argument');
|
|
432
|
+
return [2 /*return*/];
|
|
433
|
+
}
|
|
434
|
+
_a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
|
|
435
|
+
targetFolder = ensureFolderExists(basePath, cleanPackageName);
|
|
436
|
+
if (!uriBase) {
|
|
437
|
+
uriBase = 'http://lincd.org/ont/' + name;
|
|
438
|
+
}
|
|
439
|
+
setVariable('uri_base', uriBase);
|
|
440
|
+
//find @scope and the next part between 2 slashes after
|
|
441
|
+
//so @dacore/some-mod/lib/file.js
|
|
442
|
+
// --> match[0] = @dacore/some-mod
|
|
443
|
+
// --> match[1] = @dacore
|
|
444
|
+
// --> match[2] = some-mod
|
|
445
|
+
//but save full scoped module name under ${module_name}
|
|
446
|
+
setVariable('module_name', name);
|
|
447
|
+
//extra variable for clarity (will be same as 'name')
|
|
448
|
+
setVariable('output_file_name', name);
|
|
449
|
+
_b = setNameVariables(cleanPackageName), hyphenName = _b.hyphenName, camelCaseName = _b.camelCaseName, underscoreName = _b.underscoreName;
|
|
450
|
+
log("Creating new LINCD module '" + name + "'");
|
|
451
|
+
fs.copySync(path.join(__dirname, '..', 'defaults', 'module'), targetFolder);
|
|
452
|
+
//replace variables in some of the copied files
|
|
453
|
+
return [4 /*yield*/, Promise.all([
|
|
454
|
+
'src/index.ts',
|
|
455
|
+
'package.json',
|
|
456
|
+
'Gruntfile.js',
|
|
457
|
+
'src/module.ts',
|
|
458
|
+
'src/shapes/ExampleShapeClass.ts',
|
|
459
|
+
'src/ontologies/example-ontology.ts',
|
|
460
|
+
'src/data/example-ontology.json',
|
|
461
|
+
]
|
|
462
|
+
.map(function (f) { return path.join(targetFolder, f); })
|
|
463
|
+
.map(function (file) {
|
|
464
|
+
return replaceVariablesInFile(file);
|
|
465
|
+
}))];
|
|
466
|
+
case 1:
|
|
467
|
+
//replace variables in some of the copied files
|
|
468
|
+
_c.sent();
|
|
469
|
+
//rename these to a file name similar to the module name
|
|
470
|
+
[
|
|
471
|
+
'src/ontologies/example-ontology.ts',
|
|
472
|
+
'src/data/example-ontology.json',
|
|
473
|
+
'src/data/example-ontology.json.d.ts',
|
|
474
|
+
].forEach(function (f) {
|
|
475
|
+
var parts = f.split('/');
|
|
476
|
+
var newParts = __spreadArray([], parts, true);
|
|
477
|
+
var _a = newParts.pop().split('.'), name = _a[0], extensions = _a.slice(1);
|
|
478
|
+
var newName = hyphenName + '.' + extensions.join('.');
|
|
479
|
+
console.log('rename ', path.join(targetFolder, f), path.join.apply(path, __spreadArray(__spreadArray([targetFolder], newParts, false), [newName], false)));
|
|
480
|
+
fs.renameSync(path.join(targetFolder, f), path.join.apply(path, __spreadArray(__spreadArray([targetFolder], newParts, false), [newName], false)));
|
|
481
|
+
});
|
|
482
|
+
return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
|
|
483
|
+
console.log('yarn probably not working');
|
|
484
|
+
return '';
|
|
485
|
+
})];
|
|
486
|
+
case 2:
|
|
487
|
+
version = (_c.sent());
|
|
488
|
+
installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
|
|
489
|
+
return [4 /*yield*/, execp("cd ".concat(targetFolder, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
|
|
490
|
+
console.warn('Could not install dependencies');
|
|
491
|
+
})];
|
|
492
|
+
case 3:
|
|
493
|
+
_c.sent();
|
|
494
|
+
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"));
|
|
495
|
+
return [2 /*return*/];
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
var createApp = function (name, uriBase, basePath) {
|
|
501
|
+
if (basePath === void 0) { basePath = process.cwd(); }
|
|
502
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
503
|
+
var _a, packageName, scope, cleanPackageName, targetFolder, codeName, cameCaseName, underscoreName, version, installCommand;
|
|
504
|
+
return __generator(this, function (_b) {
|
|
505
|
+
switch (_b.label) {
|
|
506
|
+
case 0:
|
|
507
|
+
if (!name) {
|
|
508
|
+
console.warn('Please provide a name as the first argument');
|
|
509
|
+
}
|
|
510
|
+
_a = name.match(/(@[\w\-]+\/)?([\w\-]+)/), packageName = _a[0], scope = _a[1], cleanPackageName = _a[2];
|
|
511
|
+
if (!uriBase) {
|
|
512
|
+
uriBase = 'http://lincd.org/ont/' + name;
|
|
513
|
+
}
|
|
514
|
+
targetFolder = path.join(basePath, name);
|
|
515
|
+
if (!fs.existsSync(targetFolder)) {
|
|
516
|
+
fs.mkdirSync(targetFolder);
|
|
517
|
+
}
|
|
518
|
+
fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
|
|
519
|
+
codeName = cleanPackageName.replace(/\-/g, '_');
|
|
520
|
+
cameCaseName = camelCase(name);
|
|
521
|
+
underscoreName = name.replace(/[-\s]+/g, '_');
|
|
522
|
+
setVariable('uri_base', uriBase);
|
|
523
|
+
//longer similar variables names should come before the shorter ones
|
|
524
|
+
setVariable('camelcase_name', cameCaseName);
|
|
525
|
+
setVariable('underscore_name', underscoreName);
|
|
526
|
+
setVariable('app_name', name);
|
|
527
|
+
log("Creating new LINCD application '" + name + "'");
|
|
528
|
+
//replace variables in some of the copied files
|
|
529
|
+
['package.json', 'index.html', 'Gruntfile.js', 'src/index.tsx', 'src/App.tsx']
|
|
530
|
+
.map(function (f) { return path.join(targetFolder, f); })
|
|
531
|
+
.forEach(function (file) {
|
|
532
|
+
replaceVariablesInFile(file);
|
|
533
|
+
});
|
|
534
|
+
return [4 /*yield*/, execPromise('yarn --version')["catch"](function (err) {
|
|
535
|
+
console.log('yarn probably not working');
|
|
536
|
+
return '';
|
|
537
|
+
})];
|
|
538
|
+
case 1:
|
|
539
|
+
version = (_b.sent());
|
|
540
|
+
installCommand = version.toString().match(/[0-9]+/) ? 'yarn install' : 'npm install';
|
|
541
|
+
return [4 /*yield*/, execp("cd ".concat(name, " && ").concat(installCommand, " && npm exec lincd build"), true)["catch"](function (err) {
|
|
542
|
+
console.warn('Could not install dependencies');
|
|
543
|
+
})];
|
|
544
|
+
case 2:
|
|
545
|
+
_b.sent();
|
|
546
|
+
open(path.join(targetFolder, 'index.html'));
|
|
547
|
+
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"));
|
|
548
|
+
return [2 /*return*/];
|
|
549
|
+
}
|
|
550
|
+
});
|
|
307
551
|
});
|
|
308
|
-
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");
|
|
309
552
|
};
|
|
310
553
|
var getNextVersion = function (version) {
|
|
311
554
|
var parts = version.split('.');
|
|
@@ -389,56 +632,56 @@ program.command('register [version]').action(function (newVersion) {
|
|
|
389
632
|
});
|
|
390
633
|
/*console.log(chalk.cyan('building production bundles'));
|
|
391
634
|
return execPromise('yarn lincd build production', false, true)
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
635
|
+
.then((output: string) => {
|
|
636
|
+
if (buildFailed(output)) {
|
|
637
|
+
// console.warn("Build failed:");
|
|
638
|
+
console.log(output);
|
|
639
|
+
throw new Error('build failed');
|
|
640
|
+
}
|
|
641
|
+
pack.version = newVersion;
|
|
642
|
+
//save package.json
|
|
643
|
+
return fs.writeFileSync(
|
|
644
|
+
path.join(process.cwd(), 'package.json'),
|
|
645
|
+
JSON.stringify(pack, null, 2),
|
|
646
|
+
);
|
|
647
|
+
})
|
|
648
|
+
.then((version) => {
|
|
649
|
+
console.log(chalk.cyan('Committing to git'));
|
|
650
|
+
//we have just changed package.json, so there will be things "uncommitted"
|
|
651
|
+
//to make sure this module does not automatically come up as "needing to be published" we need to commit this change here straight away
|
|
652
|
+
//so: add all files not added yet in the folder of this module
|
|
653
|
+
//then commit all changes (including new version number in package.json)
|
|
654
|
+
//then add a version commit git flag
|
|
655
|
+
return execPromise(
|
|
656
|
+
`git add -- ./ & git commit -m "publishing ${moduleName} ${newVersion}" -- ./ & git tag ${moduleName}@${newVersion}"`,
|
|
657
|
+
);
|
|
658
|
+
})
|
|
659
|
+
.then((version) => {
|
|
660
|
+
console.log(chalk.cyan('Publishing ' + moduleName + ' ' + newVersion));
|
|
661
|
+
|
|
662
|
+
// let tag = moduleName+'@'+version;
|
|
663
|
+
return execPromise('yarn publish --new-version ' + newVersion, true);
|
|
664
|
+
})
|
|
665
|
+
.then((res) => {
|
|
666
|
+
if (
|
|
667
|
+
res.indexOf('Aborted due to warnings') !== -1 ||
|
|
668
|
+
res.indexOf('Could not publish') !== -1 ||
|
|
669
|
+
res.indexOf("Couldn't publish") !== -1
|
|
670
|
+
) {
|
|
671
|
+
console.log(chalk.red('Failed to publish'));
|
|
672
|
+
return false;
|
|
673
|
+
} else {
|
|
674
|
+
var pack = JSON.parse(
|
|
675
|
+
fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
|
|
676
|
+
);
|
|
677
|
+
version = pack.version;
|
|
678
|
+
console.log(chalk.green('Published ' + version));
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
})
|
|
682
|
+
.catch((err) => {
|
|
683
|
+
console.warn(chalk.red('Could not publish: ' + err));
|
|
684
|
+
});*/
|
|
442
685
|
}
|
|
443
686
|
else {
|
|
444
687
|
console.warn('not found: ' + process.cwd() + '/package.json');
|
|
@@ -497,7 +740,7 @@ var buildModule = function (target, target2, modulePath, logResults) {
|
|
|
497
740
|
if (logResults === void 0) { logResults = true; }
|
|
498
741
|
if (target == 'production' || target == 'es5' || target == 'es6' || !target) {
|
|
499
742
|
if (!fs.existsSync(path.join(modulePath, 'Gruntfile.js'))) {
|
|
500
|
-
console.warn("No Gruntfile found at "
|
|
743
|
+
console.warn("No Gruntfile found at ".concat(modulePath, "\\Gruntfile.js. Cannot build."));
|
|
501
744
|
return;
|
|
502
745
|
}
|
|
503
746
|
var nodeEnv = '';
|
|
@@ -547,7 +790,7 @@ var getLastModifiedSourceTime = function (modulePath) {
|
|
|
547
790
|
var getLastCommitTime = function (modulePath) {
|
|
548
791
|
// console.log(`git log -1 --format=%ci -- ${modulePath}`);
|
|
549
792
|
// process.exit();
|
|
550
|
-
return execPromise("git log -1 --format=%ci -- "
|
|
793
|
+
return execPromise("git log -1 --format=%ci -- ".concat(modulePath)).then(function (result) {
|
|
551
794
|
var lastCommit = new Date(result);
|
|
552
795
|
// console.log(modulePath,result,lastCommit);
|
|
553
796
|
return lastCommit;
|
|
@@ -759,6 +1002,9 @@ var buildUpdated = function (back, target, target2, test) {
|
|
|
759
1002
|
});
|
|
760
1003
|
// });
|
|
761
1004
|
};
|
|
1005
|
+
var printFailedModules = function (modules) {
|
|
1006
|
+
log('These modules failed to build:\n\t' + chalk.red(modules.join('\n\t')) + '\n');
|
|
1007
|
+
};
|
|
762
1008
|
program.command('build-all [target] [target2]').action(function (target, target2) {
|
|
763
1009
|
var dependencies = new Map();
|
|
764
1010
|
console.log('Building all modules of this repository in order of dependencies');
|
|
@@ -766,7 +1012,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
|
|
|
766
1012
|
//get dependencies of each module
|
|
767
1013
|
var leastDependentModule;
|
|
768
1014
|
modules.forEach(function (module) {
|
|
769
|
-
var pack = utils_1.getPackageJSON(module.path);
|
|
1015
|
+
var pack = (0, utils_1.getPackageJSON)(module.path);
|
|
770
1016
|
if (pack) {
|
|
771
1017
|
//get lincd related dependencies and get the actual module details from the module map by removing '@dacore/' from the package name
|
|
772
1018
|
var moduleDependencies = Object.keys(pack.dependencies)
|
|
@@ -802,7 +1048,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
|
|
|
802
1048
|
var done = new Set();
|
|
803
1049
|
var p = Promise.resolve();
|
|
804
1050
|
var runStack = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
805
|
-
var modulesLeft, stackPromise, first_1;
|
|
1051
|
+
var modulesLeft, failedModules, stackPromise, first_1;
|
|
806
1052
|
return __generator(this, function (_a) {
|
|
807
1053
|
switch (_a.label) {
|
|
808
1054
|
case 0:
|
|
@@ -812,6 +1058,7 @@ program.command('build-all [target] [target2]').action(function (target, target2
|
|
|
812
1058
|
console.log(chalk.magenta(stack.map(function (i) { return i.moduleName; })));
|
|
813
1059
|
// log(stack);
|
|
814
1060
|
}
|
|
1061
|
+
failedModules = [];
|
|
815
1062
|
stackPromise = Promise.all(stack.map(function (module) {
|
|
816
1063
|
// p = p.then(() => {
|
|
817
1064
|
var command;
|
|
@@ -844,6 +1091,8 @@ program.command('build-all [target] [target2]').action(function (target, target2
|
|
|
844
1091
|
}
|
|
845
1092
|
});
|
|
846
1093
|
if (dependentModules.length > 0) {
|
|
1094
|
+
failedModules.push(module.moduleName);
|
|
1095
|
+
printFailedModules(failedModules);
|
|
847
1096
|
console.log(chalk.magenta('Stopping build process because an error occurred whilst building ' +
|
|
848
1097
|
module.moduleName +
|
|
849
1098
|
', which ' +
|
|
@@ -851,15 +1100,21 @@ program.command('build-all [target] [target2]').action(function (target, target2
|
|
|
851
1100
|
' other modules depend on.')); //"+dependentModules.map(d => d.moduleName).join(", ")));
|
|
852
1101
|
console.log(chalk.cyanBright('tip ') +
|
|
853
1102
|
'Run ' +
|
|
854
|
-
chalk.green("lincd build-all from "
|
|
1103
|
+
chalk.green("lincd build-all from ".concat(module.moduleName)) +
|
|
855
1104
|
' to build only the remaining modules'); //"+dependentModules.map(d => d.moduleName).join(", ")));
|
|
856
1105
|
process.exit(1);
|
|
857
1106
|
}
|
|
1107
|
+
else {
|
|
1108
|
+
failedModules.push(module.moduleName);
|
|
1109
|
+
}
|
|
858
1110
|
})
|
|
859
1111
|
.then(function (res) {
|
|
860
1112
|
done.add(module);
|
|
861
1113
|
modulesLeft--;
|
|
862
1114
|
log(chalk.magenta(modulesLeft + ' modules left'));
|
|
1115
|
+
if (modulesLeft == 0 && failedModules.length > 0) {
|
|
1116
|
+
printFailedModules(failedModules);
|
|
1117
|
+
}
|
|
863
1118
|
return res;
|
|
864
1119
|
});
|
|
865
1120
|
// });
|
|
@@ -1044,24 +1299,24 @@ function logHelp() {
|
|
|
1044
1299
|
chalk.cyan('- build only those modules that have updated their source since their last local built'));
|
|
1045
1300
|
/*
|
|
1046
1301
|
console.log(
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1302
|
+
chalk.blue('- build-updated [n] ') +
|
|
1303
|
+
chalk.cyan(
|
|
1304
|
+
'- build only those modules that have updated their source since the last local commit (or optionally n commits back',
|
|
1305
|
+
),
|
|
1051
1306
|
);
|
|
1052
1307
|
console.log(
|
|
1053
|
-
|
|
1054
|
-
|
|
1308
|
+
chalk.blue('- modules [action]') +
|
|
1309
|
+
chalk.cyan('- execute a command for all modules'),
|
|
1055
1310
|
);
|
|
1056
1311
|
console.log(
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1312
|
+
chalk.blue('- publish-updated [message] ') +
|
|
1313
|
+
chalk.cyan(
|
|
1314
|
+
"- publish all modules who's source changes have been committed to git since the last published version.",
|
|
1315
|
+
),
|
|
1061
1316
|
);
|
|
1062
1317
|
console.log(
|
|
1063
|
-
|
|
1064
|
-
|
|
1318
|
+
chalk.blue('- status') +
|
|
1319
|
+
chalk.cyan('- see which modules need to be published or build'),
|
|
1065
1320
|
);*/
|
|
1066
1321
|
console.log(chalk.green('\nOther commands:'));
|
|
1067
1322
|
console.log(chalk.blue('- info ') + chalk.cyan('- print the version of this tool and where it runs from'));
|