lincd-cli 1.1.1 → 1.1.3
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/defaults/app-static/.env-cmdrc.json +17 -0
- package/defaults/app-static/package.json +8 -0
- package/defaults/app-static/src/index-static.tsx +3 -3
- package/defaults/app-with-backend/.env-cmdrc.json +1 -4
- package/defaults/app-with-backend/package.json +8 -9
- package/defaults/app-with-backend/scripts/storage-config.js +2 -2
- package/defaults/app-with-backend/src/package.ts +1 -2
- package/defaults/component.tsx +1 -3
- package/defaults/package/package.json +2 -2
- package/defaults/package/src/index.ts +1 -0
- package/defaults/package/src/ontologies/example-ontology.ts +10 -3
- package/defaults/package/src/package.ts +11 -3
- package/defaults/package/src/types.d.ts +9 -0
- package/defaults/package/tsconfig-cjs.json +8 -0
- package/defaults/package/tsconfig-esm.json +9 -0
- package/defaults/set-component.tsx +2 -5
- package/defaults/shape.ts +2 -2
- package/lib/{cli-methods.js → cjs/cli-methods.js} +629 -254
- package/lib/cjs/cli-methods.js.map +1 -0
- package/lib/cjs/cli.js +202 -0
- package/lib/cjs/cli.js.map +1 -0
- package/lib/{config-grunt.js → cjs/config-grunt.cjs} +15 -13
- package/lib/cjs/config-grunt.cjs.map +1 -0
- package/lib/cjs/config-webpack-app.js +353 -0
- package/lib/cjs/config-webpack-app.js.map +1 -0
- package/lib/cjs/config-webpack.js +436 -0
- package/lib/cjs/config-webpack.js.map +1 -0
- package/lib/{index.js → cjs/index.js} +3 -5
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces.js.map → cjs/interfaces.js.map} +1 -1
- package/lib/cjs/loaders/css-loader.mjs +82 -0
- package/lib/cjs/loaders/css-loader.mjs.map +1 -0
- package/lib/cjs/loaders/register.js +6 -0
- package/lib/cjs/loaders/register.js.map +1 -0
- package/lib/cjs/metadata.js +155 -0
- package/lib/cjs/metadata.js.map +1 -0
- package/lib/cjs/package.json +139 -0
- package/lib/cjs/plugins/check-imports.js.map +1 -0
- package/lib/cjs/plugins/declaration-plugin.js +275 -0
- package/lib/cjs/plugins/declaration-plugin.js.map +1 -0
- package/lib/cjs/plugins/externalise-modules.js +190 -0
- package/lib/cjs/plugins/externalise-modules.js.map +1 -0
- package/lib/cjs/plugins/watch-run.js.map +1 -0
- package/lib/{utils.js → cjs/utils.js} +22 -18
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/cli-methods.js +1965 -0
- package/lib/esm/cli-methods.js.map +1 -0
- package/lib/{cli.js → esm/cli.js} +59 -44
- package/lib/esm/cli.js.map +1 -0
- package/lib/esm/config-grunt.cjs +270 -0
- package/lib/esm/config-grunt.cjs.map +1 -0
- package/lib/esm/config-webpack-app.js +326 -0
- package/lib/esm/config-webpack-app.js.map +1 -0
- package/lib/{config-webpack.js → esm/config-webpack.js} +27 -39
- package/lib/esm/config-webpack.js.map +1 -0
- package/lib/esm/index.js +9 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces.js +2 -0
- package/lib/esm/interfaces.js.map +1 -0
- package/lib/esm/loaders/css-loader.mjs +75 -0
- package/lib/esm/loaders/css-loader.mjs.map +1 -0
- package/lib/esm/loaders/register.js +4 -0
- package/lib/esm/loaders/register.js.map +1 -0
- package/lib/esm/metadata.js +155 -0
- package/lib/esm/metadata.js.map +1 -0
- package/lib/esm/package.json +139 -0
- package/lib/esm/plugins/check-imports.js +65 -0
- package/lib/esm/plugins/check-imports.js.map +1 -0
- package/lib/{plugins → esm/plugins}/declaration-plugin.js +9 -8
- package/lib/esm/plugins/declaration-plugin.js.map +1 -0
- package/lib/{plugins → esm/plugins}/externalise-modules.js +5 -6
- package/lib/esm/plugins/externalise-modules.js.map +1 -0
- package/lib/esm/plugins/watch-run.js +44 -0
- package/lib/esm/plugins/watch-run.js.map +1 -0
- package/lib/esm/utils.js +478 -0
- package/lib/esm/utils.js.map +1 -0
- package/package.json +53 -16
- package/tsconfig-cjs.json +9 -0
- package/tsconfig-esm.json +10 -0
- package/lib/cli-methods.js.map +0 -1
- package/lib/cli.js.map +0 -1
- package/lib/config-grunt.js.map +0 -1
- package/lib/config-webpack-app.js +0 -367
- package/lib/config-webpack-app.js.map +0 -1
- package/lib/config-webpack.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/metadata.js +0 -149
- package/lib/metadata.js.map +0 -1
- package/lib/plugins/check-imports.js.map +0 -1
- package/lib/plugins/declaration-plugin.js.map +0 -1
- package/lib/plugins/externalise-modules.js.map +0 -1
- package/lib/plugins/watch-run.js.map +0 -1
- package/lib/utils.js.map +0 -1
- /package/{expose-grunt.js → expose-grunt.cjs} +0 -0
- /package/lib/{interfaces.js → cjs/interfaces.js} +0 -0
- /package/lib/{plugins → cjs/plugins}/check-imports.js +0 -0
- /package/lib/{plugins → cjs/plugins}/watch-run.js +0 -0
|
@@ -1,25 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.register = exports.createPackage = exports.buildApp = exports.startServer = exports.ensureEnvironmentLoaded = exports.depCheck = exports.depCheckStaged = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
|
|
29
|
+
exports.removeOldFiles = exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.compilePackage = exports.buildPackage = exports.register = exports.createPackage = exports.upgradePackages = exports.buildApp = exports.startServer = exports.ensureEnvironmentLoaded = exports.depCheck = exports.depCheckStaged = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.getScriptDir = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
|
|
7
30
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
31
|
const child_process_1 = require("child_process");
|
|
9
32
|
const depcheck_1 = __importDefault(require("depcheck"));
|
|
10
|
-
const
|
|
33
|
+
const get_env_vars_js_1 = require("env-cmd/dist/get-env-vars.js");
|
|
11
34
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
|
-
const path_1 =
|
|
13
|
-
const
|
|
35
|
+
const path_1 = __importStar(require("path"));
|
|
36
|
+
const utils_js_1 = require("./utils.js");
|
|
14
37
|
const fs_1 = require("fs");
|
|
15
38
|
const find_nearest_package_json_1 = require("find-nearest-package-json");
|
|
16
|
-
const LinkedFileStorage_1 = require("lincd/
|
|
39
|
+
const LinkedFileStorage_1 = require("lincd/utils/LinkedFileStorage");
|
|
40
|
+
// import pkg from 'lincd/utils/LinkedFileStorage';
|
|
41
|
+
// const { LinkedFileStorage } = pkg;
|
|
17
42
|
// const config = require('lincd-server/site.webpack.config');
|
|
18
|
-
|
|
43
|
+
const glob_1 = require("glob");
|
|
44
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
45
|
+
const staged_git_files_1 = __importDefault(require("staged-git-files"));
|
|
46
|
+
const ora_1 = __importDefault(require("ora"));
|
|
19
47
|
var variables = {};
|
|
20
|
-
var open = require('open');
|
|
21
|
-
var stagedGitFiles = require('staged-git-files');
|
|
22
|
-
const webpack = require('webpack');
|
|
23
48
|
const createApp = async (name, basePath = process.cwd()) => {
|
|
24
49
|
if (!name) {
|
|
25
50
|
console.warn('Please provide a name as the first argument');
|
|
@@ -38,21 +63,21 @@ const createApp = async (name, basePath = process.cwd()) => {
|
|
|
38
63
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'gitignore.template'), path_1.default.join(targetFolder, '.gitignore'));
|
|
39
64
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'yarnrc.yml.template'), path_1.default.join(targetFolder, '.yarnrc.yml'));
|
|
40
65
|
// fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
|
|
41
|
-
log(
|
|
66
|
+
log('Creating new LINCD application \'' + name + '\'');
|
|
42
67
|
//replace variables in some copied files
|
|
43
68
|
await replaceVariablesInFolder(targetFolder);
|
|
44
69
|
let hasYarn = await hasYarnInstalled();
|
|
45
70
|
let installCommand = hasYarn
|
|
46
71
|
? 'export NODE_OPTIONS="--no-network-family-autoselection" && yarn install'
|
|
47
72
|
: 'npm install';
|
|
48
|
-
await (0,
|
|
73
|
+
await (0, utils_js_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
|
|
49
74
|
console.warn('Could not install dependencies or start application');
|
|
50
75
|
});
|
|
51
76
|
log(`Your LINCD App is ready at ${chalk_1.default.blueBright(targetFolder)}`, `To start, run\n${chalk_1.default.blueBright(`cd ${hyphenName}`)} and then ${chalk_1.default.blueBright((hasYarn ? 'yarn' : 'npm') + ' start')}`);
|
|
52
77
|
};
|
|
53
78
|
exports.createApp = createApp;
|
|
54
79
|
function logHelp() {
|
|
55
|
-
(0,
|
|
80
|
+
(0, utils_js_1.execp)('yarn exec lincd help');
|
|
56
81
|
}
|
|
57
82
|
function log(...messages) {
|
|
58
83
|
messages.forEach((message) => {
|
|
@@ -65,7 +90,7 @@ function progressUpdate(message) {
|
|
|
65
90
|
}
|
|
66
91
|
function warn(...messages) {
|
|
67
92
|
messages.forEach((message) => {
|
|
68
|
-
console.log(chalk_1.default.
|
|
93
|
+
console.log(chalk_1.default.redBright('Warning: ') + message);
|
|
69
94
|
// console.log(chalk.red(message));
|
|
70
95
|
});
|
|
71
96
|
}
|
|
@@ -141,7 +166,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
|
|
|
141
166
|
//get dependencies of each package
|
|
142
167
|
let leastDependentPackage;
|
|
143
168
|
lincdPackages.forEach((pkg) => {
|
|
144
|
-
var pack = (0,
|
|
169
|
+
var pack = (0, utils_js_1.getPackageJSON)(pkg.path);
|
|
145
170
|
if (pack) {
|
|
146
171
|
//get lincd related dependencies and get the actual package details from the package map by removing '@dacore/' from the package name
|
|
147
172
|
let packageDependencies = Object.keys(pack.dependencies)
|
|
@@ -166,9 +191,17 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
|
|
|
166
191
|
let startStack = [leastDependentPackage];
|
|
167
192
|
const runPackage = (runFunction, pck) => {
|
|
168
193
|
return runFunction(pck)
|
|
169
|
-
.catch((
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
.catch((errorObj) => {
|
|
195
|
+
if (errorObj.error) {
|
|
196
|
+
let { error, stdout, stderr } = errorObj;
|
|
197
|
+
warn('Uncaught exception whilst running parallel function on ' +
|
|
198
|
+
pck.packageName, (error === null || error === void 0 ? void 0 : error.message) ? error.message : error === null || error === void 0 ? void 0 : error.toString());
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
warn('Uncaught exception whilst running parallel function on ' +
|
|
202
|
+
pck.packageName, errorObj === null || errorObj === void 0 ? void 0 : errorObj.toString());
|
|
203
|
+
process.exit();
|
|
204
|
+
}
|
|
172
205
|
// warn(chalk.red(pck.packageName+' failed:'));
|
|
173
206
|
// console.log(stdout);
|
|
174
207
|
})
|
|
@@ -337,10 +370,10 @@ function buildAll(options) {
|
|
|
337
370
|
// let packagesLeft = lincdPackages.size - done.size;
|
|
338
371
|
runOnPackagesGroupedByDependencies(lincdPackages, (packageGroup, dependencies) => {
|
|
339
372
|
if (done.size > 0) {
|
|
340
|
-
(0,
|
|
373
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
|
|
341
374
|
// log(stack);
|
|
342
375
|
}
|
|
343
|
-
(0,
|
|
376
|
+
(0, utils_js_1.debugInfo)('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
|
|
344
377
|
return async (pkg) => {
|
|
345
378
|
let command;
|
|
346
379
|
let skipping = false;
|
|
@@ -359,50 +392,119 @@ function buildAll(options) {
|
|
|
359
392
|
}
|
|
360
393
|
//unless told otherwise, build the package
|
|
361
394
|
if (!command) {
|
|
362
|
-
command = (0,
|
|
363
|
-
//
|
|
364
|
-
//
|
|
365
|
-
|
|
395
|
+
command = (0, exports.buildPackage)(null, null, path_1.default.join(process.cwd(), pkg.path), false);
|
|
396
|
+
// command = execPromise(
|
|
397
|
+
// 'cd ' + pkg.path + ' && yarn exec lincd build',
|
|
398
|
+
// // (target ? ' ' + target : '') +
|
|
399
|
+
// // (target2 ? ' ' + target2 : ''),
|
|
400
|
+
// false,
|
|
401
|
+
// false,
|
|
402
|
+
// {},
|
|
403
|
+
// false,
|
|
404
|
+
// );
|
|
366
405
|
log(chalk_1.default.cyan('Building ' + pkg.packageName));
|
|
367
406
|
process.stdout.write(packagesLeft + ' packages left\r');
|
|
368
407
|
}
|
|
369
|
-
return command
|
|
370
|
-
|
|
371
|
-
//
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
'
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
})
|
|
390
|
-
.then((res) => {
|
|
391
|
-
if (!skipping) {
|
|
392
|
-
log(chalk_1.default.green('Built ' + pkg.packageName));
|
|
393
|
-
}
|
|
394
|
-
done.add(pkg);
|
|
395
|
-
packagesLeft--;
|
|
396
|
-
// log(chalk.magenta(packagesLeft + ' packages left'));
|
|
397
|
-
process.stdout.write(packagesLeft + ' packages left\r');
|
|
398
|
-
if (packagesLeft == 0) {
|
|
399
|
-
printBuildResults(failedModules, done);
|
|
400
|
-
if (failedModules.length > 0) {
|
|
408
|
+
return command.then(res => {
|
|
409
|
+
//empty string or true is success
|
|
410
|
+
//false is success with warnings
|
|
411
|
+
//any other string is the build error text
|
|
412
|
+
//undefined result means it failed
|
|
413
|
+
// if (res !== '' && res !== true && res !== false) {
|
|
414
|
+
if (typeof res === 'undefined') {
|
|
415
|
+
failedModules.push(pkg.packageName);
|
|
416
|
+
let dependentModules = getDependentPackages(dependencies, pkg);
|
|
417
|
+
if (dependentModules.length > 0) {
|
|
418
|
+
printBuildResults(failedModules, done);
|
|
419
|
+
console.log('Stopping build process because an error occurred whilst building ' +
|
|
420
|
+
pkg.packageName +
|
|
421
|
+
', which ' +
|
|
422
|
+
dependentModules.length +
|
|
423
|
+
' other packages depend on.'); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
424
|
+
log('Run ' +
|
|
425
|
+
chalk_1.default.greenBright(`lincd build-all --from=${pkg.packageName}`) +
|
|
426
|
+
' to build only the remaining packages'); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
401
427
|
process.exit(1);
|
|
402
428
|
}
|
|
403
429
|
}
|
|
404
|
-
|
|
430
|
+
else {
|
|
431
|
+
if (!skipping) {
|
|
432
|
+
log(chalk_1.default.green('Built ' + pkg.packageName) + (res === false ? chalk_1.default.redBright(' (with warnings)') : ''));
|
|
433
|
+
}
|
|
434
|
+
done.add(pkg);
|
|
435
|
+
packagesLeft--;
|
|
436
|
+
// log(chalk.magenta(packagesLeft + ' packages left'));
|
|
437
|
+
process.stdout.write(packagesLeft + ' packages left\r');
|
|
438
|
+
if (packagesLeft == 0) {
|
|
439
|
+
printBuildResults(failedModules, done);
|
|
440
|
+
if (failedModules.length > 0) {
|
|
441
|
+
process.exit(1);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return res;
|
|
445
|
+
}
|
|
446
|
+
})
|
|
447
|
+
.catch(({ error, stdout, stderr }) => {
|
|
448
|
+
warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
|
|
449
|
+
console.log(stdout);
|
|
450
|
+
process.exit(1);
|
|
451
|
+
// let dependentModules = getDependentP
|
|
405
452
|
});
|
|
453
|
+
//undefined result means it failed
|
|
454
|
+
/*if (typeof res === 'undefined')
|
|
455
|
+
{
|
|
456
|
+
// .catch(({ error,stdout,stderr }) => {
|
|
457
|
+
//this prints out the webpack output, including the build errors
|
|
458
|
+
// warn('Failed to build ' + pkg.packageName);
|
|
459
|
+
// console.log(stdout);
|
|
460
|
+
failedModules.push(pkg.packageName);
|
|
461
|
+
let dependentModules = getDependentPackages(dependencies,pkg);
|
|
462
|
+
if (dependentModules.length > 0)
|
|
463
|
+
{
|
|
464
|
+
printBuildResults(failedModules,done);
|
|
465
|
+
console.log(
|
|
466
|
+
'Stopping build process because an error occurred whilst building ' +
|
|
467
|
+
pkg.packageName +
|
|
468
|
+
', which ' +
|
|
469
|
+
dependentModules.length +
|
|
470
|
+
' other packages depend on.',
|
|
471
|
+
); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
472
|
+
log(
|
|
473
|
+
'Run ' +
|
|
474
|
+
chalk.greenBright(`lincd build-all --from=${pkg.packageName}`) +
|
|
475
|
+
' to build only the remaining packages',
|
|
476
|
+
); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
477
|
+
process.exit(1);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
else //true is successful build, false is successful but with warnings
|
|
481
|
+
{
|
|
482
|
+
//successful build
|
|
483
|
+
// })
|
|
484
|
+
// .then((res) => {
|
|
485
|
+
if (!skipping)
|
|
486
|
+
{
|
|
487
|
+
log(chalk.green('Built ' + pkg.packageName)+(res === false ? chalk.redBright(' (with warnings)') : ''));
|
|
488
|
+
}
|
|
489
|
+
done.add(pkg);
|
|
490
|
+
|
|
491
|
+
packagesLeft--;
|
|
492
|
+
// log(chalk.magenta(packagesLeft + ' packages left'));
|
|
493
|
+
process.stdout.write(packagesLeft + ' packages left\r');
|
|
494
|
+
if (packagesLeft == 0)
|
|
495
|
+
{
|
|
496
|
+
printBuildResults(failedModules,done);
|
|
497
|
+
if (failedModules.length > 0)
|
|
498
|
+
{
|
|
499
|
+
process.exit(1);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return res;
|
|
504
|
+
}*/
|
|
505
|
+
// }).catch(err => {
|
|
506
|
+
// console.log(err);
|
|
507
|
+
// })
|
|
406
508
|
};
|
|
407
509
|
}, (dependencies) => {
|
|
408
510
|
//if no more packages to build but we never started building...
|
|
@@ -474,11 +576,11 @@ function getLocalLincdModules(rootPath = './') {
|
|
|
474
576
|
});
|
|
475
577
|
}
|
|
476
578
|
function getLincdPackages(rootPath = process.cwd()) {
|
|
477
|
-
let pack = (0,
|
|
579
|
+
let pack = (0, utils_js_1.getPackageJSON)();
|
|
478
580
|
if (!pack || !pack.workspaces) {
|
|
479
581
|
for (let i = 0; i <= 3; i++) {
|
|
480
582
|
rootPath = path_1.default.join(process.cwd(), ...Array(i).fill('..'));
|
|
481
|
-
pack = (0,
|
|
583
|
+
pack = (0, utils_js_1.getPackageJSON)(rootPath);
|
|
482
584
|
if (pack && pack.workspaces) {
|
|
483
585
|
// log('Found workspace at '+packagePath);
|
|
484
586
|
break;
|
|
@@ -541,7 +643,7 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
|
|
|
541
643
|
setVariable('uri_base', uriBase);
|
|
542
644
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(prefix);
|
|
543
645
|
//copy ontology accessor file
|
|
544
|
-
log(
|
|
646
|
+
log('Creating files for ontology \'' + prefix + '\'');
|
|
545
647
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
|
|
546
648
|
fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
|
|
547
649
|
//copy data files
|
|
@@ -559,10 +661,10 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
|
|
|
559
661
|
}
|
|
560
662
|
};
|
|
561
663
|
exports.createOntology = createOntology;
|
|
562
|
-
const addLineToIndex = function (line, insertMatchString) {
|
|
664
|
+
const addLineToIndex = function (line, insertMatchString, root = process.cwd(), insertAtStart = false) {
|
|
563
665
|
//import ontology in index
|
|
564
666
|
let indexPath = ['index.ts', 'index.tsx']
|
|
565
|
-
.map((f) => path_1.default.join('src', f))
|
|
667
|
+
.map((f) => path_1.default.join(root, 'src', f))
|
|
566
668
|
.find((indexFileName) => {
|
|
567
669
|
return fs_extra_1.default.existsSync(indexFileName);
|
|
568
670
|
});
|
|
@@ -571,8 +673,9 @@ const addLineToIndex = function (line, insertMatchString) {
|
|
|
571
673
|
let lines = indexContents.split(/\n/g);
|
|
572
674
|
let newContents;
|
|
573
675
|
for (var key in lines) {
|
|
676
|
+
//if the match string is found
|
|
574
677
|
if (lines[key].indexOf(insertMatchString) !== -1) {
|
|
575
|
-
//
|
|
678
|
+
//add the new line after this line
|
|
576
679
|
lines[key] += `\n${line}`;
|
|
577
680
|
newContents = lines.join('\n');
|
|
578
681
|
// log("Found at "+key,lines,newContents);
|
|
@@ -580,7 +683,12 @@ const addLineToIndex = function (line, insertMatchString) {
|
|
|
580
683
|
}
|
|
581
684
|
}
|
|
582
685
|
if (!newContents) {
|
|
583
|
-
|
|
686
|
+
if (insertAtStart) {
|
|
687
|
+
newContents = `${line}\n${indexContents}`;
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
newContents = `${indexContents}\n${line}`;
|
|
691
|
+
}
|
|
584
692
|
// log("Added at end",newContents);
|
|
585
693
|
}
|
|
586
694
|
fs_extra_1.default.writeFileSync(indexPath, newContents);
|
|
@@ -594,13 +702,13 @@ const replaceVariablesInFiles = function (...files) {
|
|
|
594
702
|
};
|
|
595
703
|
const replaceVariablesInFolder = function (folder) {
|
|
596
704
|
//get all files in folder, including files that start with a dot
|
|
597
|
-
glob(folder + '/**/*', { dot: true, nodir: true }, function (err, files) {
|
|
705
|
+
glob_1.glob(folder + '/**/*', { dot: true, nodir: true }, async function (err, files) {
|
|
598
706
|
if (err) {
|
|
599
707
|
console.log('Error', err);
|
|
600
708
|
}
|
|
601
709
|
else {
|
|
602
710
|
// console.log(files);
|
|
603
|
-
|
|
711
|
+
await Promise.all(files.map((file) => {
|
|
604
712
|
return replaceVariablesInFile(file);
|
|
605
713
|
}));
|
|
606
714
|
}
|
|
@@ -610,7 +718,7 @@ const replaceVariablesInFilesWithRoot = function (root, ...files) {
|
|
|
610
718
|
return replaceVariablesInFiles(...files.map((f) => path_1.default.join(root, f)));
|
|
611
719
|
};
|
|
612
720
|
const hasYarnInstalled = async function () {
|
|
613
|
-
let version = (await (0,
|
|
721
|
+
let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
|
|
614
722
|
console.log('yarn probably not working');
|
|
615
723
|
return '';
|
|
616
724
|
}));
|
|
@@ -666,6 +774,21 @@ function getSourceFolder(basePath = process.cwd()) {
|
|
|
666
774
|
return path_1.default.join(basePath, 'src');
|
|
667
775
|
}
|
|
668
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* get __dirname for either ESM/CJS
|
|
779
|
+
*/
|
|
780
|
+
const getScriptDir = () => {
|
|
781
|
+
// @ts-ignore
|
|
782
|
+
if (typeof __dirname !== 'undefined') {
|
|
783
|
+
// @ts-ignore
|
|
784
|
+
return __dirname;
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
// @ts-ignore
|
|
788
|
+
return (0, path_1.dirname)(import.meta.url).replace('file:/', '');
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
exports.getScriptDir = getScriptDir;
|
|
669
792
|
const createShape = async (name, basePath = process.cwd()) => {
|
|
670
793
|
let sourceFolder = getSourceFolder(basePath);
|
|
671
794
|
let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
|
|
@@ -673,7 +796,7 @@ const createShape = async (name, basePath = process.cwd()) => {
|
|
|
673
796
|
//copy default shape file
|
|
674
797
|
// log("Creating files for shape '" + name + "'");
|
|
675
798
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
|
|
676
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
799
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'shape.ts'), targetFile);
|
|
677
800
|
//replace variables in some of the copied files
|
|
678
801
|
await replaceVariablesInFiles(targetFile);
|
|
679
802
|
log(`Created a new shape class template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
|
|
@@ -689,11 +812,11 @@ const createSetComponent = async (name, basePath = process.cwd()) => {
|
|
|
689
812
|
let targetFolder = ensureFolderExists(basePath, 'src', 'components');
|
|
690
813
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
|
|
691
814
|
//copy default shape file
|
|
692
|
-
log(
|
|
815
|
+
log('Creating files for set component \'' + name + '\'');
|
|
693
816
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
694
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
817
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
|
|
695
818
|
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
696
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
819
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'component.scss'), targetFile2);
|
|
697
820
|
//replace variables in some of the copied files
|
|
698
821
|
await replaceVariablesInFiles(targetFile, targetFile2);
|
|
699
822
|
let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
|
|
@@ -705,11 +828,11 @@ const createComponent = async (name, basePath = process.cwd()) => {
|
|
|
705
828
|
let targetFolder = ensureFolderExists(sourceFolder, 'components');
|
|
706
829
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
|
|
707
830
|
//copy default shape file
|
|
708
|
-
log(
|
|
831
|
+
log('Creating files for component \'' + name + '\'');
|
|
709
832
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
710
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
833
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.tsx'), targetFile);
|
|
711
834
|
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
712
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
835
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.scss'), targetFile2);
|
|
713
836
|
//replace variables in some of the copied files
|
|
714
837
|
await replaceVariablesInFiles(targetFile, targetFile2);
|
|
715
838
|
log(`Created a new component template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`, `Created component stylesheet template in ${chalk_1.default.magenta(targetFile2.replace(basePath, ''))}`);
|
|
@@ -742,10 +865,10 @@ invalidImports = new Map()) => {
|
|
|
742
865
|
// - .tsx
|
|
743
866
|
continue;
|
|
744
867
|
}
|
|
745
|
-
const allImports = await (0,
|
|
868
|
+
const allImports = await (0, utils_js_1.getFileImports)(filename);
|
|
746
869
|
const lincdImports = allImports.filter((i) => i.includes('lincd') || i.includes('..'));
|
|
747
870
|
lincdImports.forEach((i) => {
|
|
748
|
-
if (!(0,
|
|
871
|
+
if (!(0, utils_js_1.isValidLINCDImport)(i, depth)) {
|
|
749
872
|
if (!invalidImports.has(filename)) {
|
|
750
873
|
invalidImports.set(filename, []);
|
|
751
874
|
}
|
|
@@ -753,26 +876,36 @@ invalidImports = new Map()) => {
|
|
|
753
876
|
}
|
|
754
877
|
});
|
|
755
878
|
}
|
|
879
|
+
let res = '';
|
|
756
880
|
// All recursion must have finished, display any errors
|
|
757
881
|
if (depth === 0 && invalidImports.size > 0) {
|
|
758
|
-
|
|
759
|
-
console.warn(chalk_1.default.red(" - For relative imports, ensure you don't import outside of the /src/ folder"));
|
|
760
|
-
console.warn(chalk_1.default.red(' - For lincd imports, access the /lib/ folder instead of /src/'));
|
|
882
|
+
res += chalk_1.default.red('Invalid imports found.\n');
|
|
761
883
|
invalidImports.forEach((value, key) => {
|
|
762
|
-
|
|
763
|
-
value.forEach((i) =>
|
|
884
|
+
// res += '- '+chalk.blueBright(key.split('/').pop()) + ':\n';
|
|
885
|
+
value.forEach((i) => {
|
|
886
|
+
res += chalk_1.default.red(key.split('/').pop() + ' imports from \'' + i + '\'\n');
|
|
887
|
+
if (i.indexOf('../../') === 0) {
|
|
888
|
+
res +=
|
|
889
|
+
'To fix: import from the NPM package directly.\n';
|
|
890
|
+
}
|
|
891
|
+
else if ('/src/') {
|
|
892
|
+
res += 'To fix: you likely need to replace /src with /lib\n';
|
|
893
|
+
}
|
|
894
|
+
});
|
|
764
895
|
});
|
|
765
|
-
|
|
896
|
+
throw res;
|
|
897
|
+
// process.exit(1);
|
|
766
898
|
}
|
|
767
899
|
else if (depth === 0 && invalidImports.size === 0) {
|
|
768
|
-
console.info('All imports OK');
|
|
769
|
-
process.exit(0);
|
|
900
|
+
// console.info('All imports OK');
|
|
901
|
+
// process.exit(0);
|
|
902
|
+
return true;
|
|
770
903
|
}
|
|
771
904
|
};
|
|
772
905
|
exports.checkImports = checkImports;
|
|
773
906
|
const depCheckStaged = async () => {
|
|
774
907
|
console.log('Checking dependencies of staged files');
|
|
775
|
-
|
|
908
|
+
(0, staged_git_files_1.default)(async function (err, results) {
|
|
776
909
|
const packages = new Set();
|
|
777
910
|
await Promise.all(results.map(async (file) => {
|
|
778
911
|
// console.log('STAGED: ', file.filename);
|
|
@@ -792,50 +925,54 @@ const depCheckStaged = async () => {
|
|
|
792
925
|
});
|
|
793
926
|
};
|
|
794
927
|
exports.depCheckStaged = depCheckStaged;
|
|
795
|
-
const depCheck = async (
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
return lincdPackage
|
|
928
|
+
const depCheck = async (packagePath = process.cwd()) => {
|
|
929
|
+
return new Promise((resolve, reject) => {
|
|
930
|
+
(0, depcheck_1.default)(packagePath, {}, (results) => {
|
|
931
|
+
if (results.missing) {
|
|
932
|
+
let lincdPackages = getLocalLincdModules();
|
|
933
|
+
let missing = Object.keys(results.missing);
|
|
934
|
+
//filter out missing types, if it builds we're not too concerned about that at the moment?
|
|
935
|
+
//especially things like @types/react, @types/react-dom, @types/node (they are added elsewhere?)
|
|
936
|
+
// missing = missing.filter(m => m.indexOf('@types/') === 0);
|
|
937
|
+
//currently react is not an explicit dependency, but we should add it as a peer dependency
|
|
938
|
+
missing.splice(missing.indexOf('react'), 1);
|
|
939
|
+
let missingLincdPackages = missing.filter((missingDep) => {
|
|
940
|
+
return lincdPackages.some((lincdPackage) => {
|
|
941
|
+
return lincdPackage.packageName === missingDep;
|
|
942
|
+
});
|
|
808
943
|
});
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
944
|
+
//currently just missing LINCD packages cause a hard failure exit code
|
|
945
|
+
if (missingLincdPackages.length > 0) {
|
|
946
|
+
reject(chalk_1.default.red(packagePath.split('/').pop() +
|
|
947
|
+
'\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
|
|
948
|
+
missingLincdPackages.join(',\n- ')));
|
|
949
|
+
}
|
|
950
|
+
else if (missing.length > 0) {
|
|
951
|
+
resolve(chalk_1.default.redBright('warning: ' + packagePath.split('/').pop() +
|
|
952
|
+
' is missing dependencies:\n - ' +
|
|
953
|
+
missing.join('\n - ')));
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
resolve(true);
|
|
957
|
+
}
|
|
821
958
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
959
|
+
// if(Object.keys(results.invalidFiles).length > 0) {
|
|
960
|
+
// console.warn(chalk.red("Invalid files:\n")+Object.keys(results.invalidFiles).join(",\n"));
|
|
961
|
+
// }
|
|
962
|
+
// if(Object.keys(results.invalidDirs).length > 0) {
|
|
963
|
+
// console.warn(chalk.red("Invalid dirs:\n")+results.invalidDirs.toString());
|
|
964
|
+
// }
|
|
965
|
+
// if(results.unused) {
|
|
966
|
+
// console.warn("Unused dependencies: "+results.missing.join(", "));
|
|
967
|
+
// }
|
|
968
|
+
});
|
|
832
969
|
});
|
|
833
970
|
};
|
|
834
971
|
exports.depCheck = depCheck;
|
|
835
972
|
const ensureEnvironmentLoaded = async () => {
|
|
836
973
|
if (!process.env.NODE_ENV) {
|
|
837
974
|
//load env-cmd for development environment
|
|
838
|
-
let { GetEnvVars } = require('env-cmd');
|
|
975
|
+
let { GetEnvVars } = await Promise.resolve().then(() => __importStar(require('env-cmd')));
|
|
839
976
|
let envCmdrcPath = path_1.default.join(process.cwd(), '.env-cmdrc.json');
|
|
840
977
|
if (!fs_extra_1.default.existsSync(envCmdrcPath)) {
|
|
841
978
|
console.warn('No .env-cmdrc.json found in this folder. Are you running this command from the root of a LINCD app?');
|
|
@@ -878,14 +1015,25 @@ const ensureEnvironmentLoaded = async () => {
|
|
|
878
1015
|
};
|
|
879
1016
|
exports.ensureEnvironmentLoaded = ensureEnvironmentLoaded;
|
|
880
1017
|
const startServer = async (initOnly = false, ServerClass = null) => {
|
|
1018
|
+
var _a, _b;
|
|
881
1019
|
await (0, exports.ensureEnvironmentLoaded)();
|
|
882
|
-
let lincdConfig =
|
|
1020
|
+
let lincdConfig = await (_a = path_1.default.join(process.cwd(), 'lincd.config.js'), Promise.resolve().then(() => __importStar(require(_a))));
|
|
1021
|
+
// function scssLoadcall(source, filename) {
|
|
1022
|
+
// return 'console.log("SCSS CALL: ' + filename + '");\n' + source;
|
|
1023
|
+
// process.exit();
|
|
1024
|
+
// }
|
|
1025
|
+
// hook.hook('.scss', scssLoadcall);
|
|
1026
|
+
// hook.hook('.css', scssLoadcall);
|
|
1027
|
+
// import.meta.
|
|
1028
|
+
// // hook.hook('*.css', scssLoadcall);
|
|
1029
|
+
// // hook.hook('Body.module.css', scssLoadcall);
|
|
1030
|
+
// hook.hook('.module.css', scssLoadcall);
|
|
883
1031
|
if (!ServerClass) {
|
|
884
|
-
ServerClass = require('lincd-server/
|
|
1032
|
+
ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer')))).LincdServer;
|
|
885
1033
|
}
|
|
886
|
-
|
|
1034
|
+
await (_b = path_1.default.join(process.cwd(), 'scripts', 'storage-config.js'), Promise.resolve().then(() => __importStar(require(_b))));
|
|
887
1035
|
let server = new ServerClass({
|
|
888
|
-
loadAppComponent: () =>
|
|
1036
|
+
loadAppComponent: async () => { var _a; return (await (_a = path_1.default.join(process.cwd(), 'src', 'App'), Promise.resolve().then(() => __importStar(require(_a))))).default; },
|
|
889
1037
|
...lincdConfig,
|
|
890
1038
|
});
|
|
891
1039
|
//Important to use slice, because when using clusers, child processes need to be able to read the same arguments
|
|
@@ -901,15 +1049,12 @@ const startServer = async (initOnly = false, ServerClass = null) => {
|
|
|
901
1049
|
exports.startServer = startServer;
|
|
902
1050
|
const buildApp = async () => {
|
|
903
1051
|
await (0, exports.ensureEnvironmentLoaded)();
|
|
904
|
-
const webpackAppConfig = require('./config-webpack-app').
|
|
1052
|
+
const webpackAppConfig = await (await Promise.resolve().then(() => __importStar(require('./config-webpack-app.js')))).getWebpackAppConfig();
|
|
905
1053
|
console.log(chalk_1.default.magenta(`Building ${process.env.NODE_ENV} app bundles`));
|
|
906
1054
|
return new Promise((resolve, reject) => {
|
|
907
|
-
|
|
1055
|
+
(0, webpack_1.default)(webpackAppConfig, async (err, stats) => {
|
|
908
1056
|
if (err) {
|
|
909
1057
|
console.error(err.stack || err);
|
|
910
|
-
if (err.details) {
|
|
911
|
-
console.error(err.details);
|
|
912
|
-
}
|
|
913
1058
|
process.exit(1);
|
|
914
1059
|
}
|
|
915
1060
|
const info = stats.toJson();
|
|
@@ -923,10 +1068,9 @@ const buildApp = async () => {
|
|
|
923
1068
|
console.log(stats.toString({
|
|
924
1069
|
chunks: false,
|
|
925
1070
|
assets: true,
|
|
926
|
-
|
|
1071
|
+
entrypoints: false,
|
|
927
1072
|
modules: false,
|
|
928
1073
|
moduleAssets: false,
|
|
929
|
-
moduleChunks: false,
|
|
930
1074
|
colors: true,
|
|
931
1075
|
}));
|
|
932
1076
|
console.log('App build process finished');
|
|
@@ -941,6 +1085,7 @@ const buildApp = async () => {
|
|
|
941
1085
|
// process.exit();
|
|
942
1086
|
});
|
|
943
1087
|
}).then(async () => {
|
|
1088
|
+
var _a;
|
|
944
1089
|
// make sure environment is not development for storage config
|
|
945
1090
|
if (process.env.NODE_ENV === 'development') {
|
|
946
1091
|
console.warn('Upload build to storage skip in development environment');
|
|
@@ -951,7 +1096,7 @@ const buildApp = async () => {
|
|
|
951
1096
|
process.exit();
|
|
952
1097
|
}
|
|
953
1098
|
// load the storage config
|
|
954
|
-
const storageConfig =
|
|
1099
|
+
const storageConfig = await (_a = path_1.default.join(process.cwd(), 'scripts', 'storage-config.js'), Promise.resolve().then(() => __importStar(require(_a))));
|
|
955
1100
|
// check if LincdFileStorage has a default FileStore
|
|
956
1101
|
// if yes: copy all the files in the build folder over with LincdFileStorage
|
|
957
1102
|
if (LinkedFileStorage_1.LinkedFileStorage.getDefaultStore()) {
|
|
@@ -963,7 +1108,7 @@ const buildApp = async () => {
|
|
|
963
1108
|
return;
|
|
964
1109
|
}
|
|
965
1110
|
// get all files in the web directory and then upload them to the storage
|
|
966
|
-
const files = await (0,
|
|
1111
|
+
const files = await (0, utils_js_1.getFiles)(pathDir);
|
|
967
1112
|
const uploads = files.map(async (filePath) => {
|
|
968
1113
|
// read file content
|
|
969
1114
|
const fileContent = await fs_extra_1.default.promises.readFile(filePath);
|
|
@@ -980,6 +1125,149 @@ const buildApp = async () => {
|
|
|
980
1125
|
});
|
|
981
1126
|
};
|
|
982
1127
|
exports.buildApp = buildApp;
|
|
1128
|
+
const upgradePackages = async () => {
|
|
1129
|
+
await (0, exports.ensureEnvironmentLoaded)();
|
|
1130
|
+
// let packages = getLincdPackages();
|
|
1131
|
+
// let packages = getLocalLincdModules();
|
|
1132
|
+
let packages = getLocalLincdPackageMap();
|
|
1133
|
+
let dirname = (0, exports.getScriptDir)();
|
|
1134
|
+
const tsConfigCJS = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-cjs.json');
|
|
1135
|
+
const tsConfigESM = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-esm.json');
|
|
1136
|
+
const typesFile = path_1.default.join(dirname, '../../defaults/package/src', 'types.d.ts');
|
|
1137
|
+
const tsConfigTemplate = await fs_extra_1.default.readJson(path_1.default.join(dirname, '../../defaults/package', 'tsconfig.json')).catch(err => {
|
|
1138
|
+
console.log(err);
|
|
1139
|
+
});
|
|
1140
|
+
runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
|
|
1141
|
+
// packageGroup.forEach((pkg) => {
|
|
1142
|
+
// console.log(' Upgrading ' + pkg.packageName);
|
|
1143
|
+
console.log('-----');
|
|
1144
|
+
return async (pkg) => {
|
|
1145
|
+
if (pkg.packageName === 'lincd')
|
|
1146
|
+
return;
|
|
1147
|
+
// await execPromise(`cd ${pkg.path} && yarn upgrade`);
|
|
1148
|
+
console.log('Upgrading ' + pkg.packageName);
|
|
1149
|
+
//
|
|
1150
|
+
// //create a new file src/tsconfig-cjs.json
|
|
1151
|
+
// //copy the contents of tsconfig.json into it
|
|
1152
|
+
// if (!fs.existsSync(path.join(pkg.path,'tsconfig-cjs.json')))
|
|
1153
|
+
// {
|
|
1154
|
+
// await fs.copy(tsConfigCJS,path.join(pkg.path,'tsconfig-cjs.json'));
|
|
1155
|
+
// await fs.copy(tsConfigESM,path.join(pkg.path,'tsconfig-esm.json'));
|
|
1156
|
+
// console.log('Copied new tsconfig to ' + pkg.packageName);
|
|
1157
|
+
// }
|
|
1158
|
+
//
|
|
1159
|
+
// //read tsconfig
|
|
1160
|
+
// await fs.readJson(path.join(pkg.path,'tsconfig.json')).then((tsconfig) => {
|
|
1161
|
+
// let oldCompilerOpts = tsconfig.compilerOptions;
|
|
1162
|
+
// tsconfig.compilerOptions = tsConfigTemplate.compilerOptions;
|
|
1163
|
+
// tsconfig.compilerOptions.types = oldCompilerOpts.types;
|
|
1164
|
+
// tsconfig.compilerOptions.plugins = [{"name": "typescript-plugin-css-modules"}];
|
|
1165
|
+
//
|
|
1166
|
+
// console.log('Upgraded tsconfig for ' + pkg.packageName);
|
|
1167
|
+
// return fs.writeJson(path.join(pkg.path,'tsconfig.json'),tsconfig,{spaces: 2});
|
|
1168
|
+
// });
|
|
1169
|
+
// //import types at the beginning of index.ts
|
|
1170
|
+
// addLineToIndex(`import './types';`,null,pkg.path,true);
|
|
1171
|
+
// //copy over the types file
|
|
1172
|
+
// await fs.copy(typesFile,path.join(pkg.path,'src','types.d.ts'));
|
|
1173
|
+
// await fs.readJson(path.join(pkg.path,'package.json')).then((packageJson) => {
|
|
1174
|
+
// let version = packageJson.version;
|
|
1175
|
+
// let nextVersion;
|
|
1176
|
+
// if (version.split('.').shift() === '0')
|
|
1177
|
+
// {
|
|
1178
|
+
// nextVersion = getNextMajorVersion(version);
|
|
1179
|
+
// }
|
|
1180
|
+
// else
|
|
1181
|
+
// {
|
|
1182
|
+
// nextVersion = getNextMinorVersion(version);
|
|
1183
|
+
// }
|
|
1184
|
+
// console.log('Upgraded version for ' + pkg.packageName + ' to ' + nextVersion);
|
|
1185
|
+
//
|
|
1186
|
+
// packageJson.version = nextVersion;
|
|
1187
|
+
// packageJson.devDependencies['tsconfig-to-dual-package'] = '^1.2.0';
|
|
1188
|
+
// packageJson.devDependencies['typescript-plugin-css-modules'] = '^5.1.0';
|
|
1189
|
+
//
|
|
1190
|
+
// packageJson.main = 'lib/cjs/index.js';
|
|
1191
|
+
// packageJson.module = 'lib/esm/index.js';
|
|
1192
|
+
// packageJson.exports = {
|
|
1193
|
+
// '.': {
|
|
1194
|
+
// 'types': './lib/esm/index.d.ts',
|
|
1195
|
+
// 'import': './lib/esm/index.js',
|
|
1196
|
+
// 'require': './lib/cjs/index.js',
|
|
1197
|
+
// },
|
|
1198
|
+
// './*': {
|
|
1199
|
+
// 'types': './lib/esm/*.d.ts',
|
|
1200
|
+
// 'import': './lib/esm/*.js',
|
|
1201
|
+
// 'require': './lib/cjs/*.js',
|
|
1202
|
+
// },
|
|
1203
|
+
// };
|
|
1204
|
+
// packageJson.typesVersions = {
|
|
1205
|
+
// '*': {
|
|
1206
|
+
// '*': [
|
|
1207
|
+
// 'lib/esm/*',
|
|
1208
|
+
// ],
|
|
1209
|
+
// },
|
|
1210
|
+
// };
|
|
1211
|
+
//
|
|
1212
|
+
// return fs.writeJson(path.join(pkg.path,'package.json'),packageJson,{ spaces: 2 });
|
|
1213
|
+
// });
|
|
1214
|
+
//change .css files and .scss files to .module.css and .module.scss
|
|
1215
|
+
let files = await (0, utils_js_1.getFiles)(path_1.default.join(pkg.path, 'src'));
|
|
1216
|
+
// let tsFiles = files.filter(f => f.match(/\.(ts|tsx)$/));
|
|
1217
|
+
// let cssFiles = files.filter(f => f.match(/\.(css|scss)$/)).filter(f => !f.match(/\.module\.(css|scss)$/));
|
|
1218
|
+
// cssFiles.forEach(cssFile => {
|
|
1219
|
+
// let cssFileName = path.basename(cssFile);
|
|
1220
|
+
// let newFile = cssFileName.replace(/\.s?css$/,'.module$&');
|
|
1221
|
+
// let newFilePath = cssFile.replace(/\.s?css$/,'.module$&');
|
|
1222
|
+
// let jsonFile = cssFileName.replace(/\.s?css$/,'$&.json');
|
|
1223
|
+
// fs.renameSync(cssFile,newFilePath);
|
|
1224
|
+
// console.log('Renaming ' + cssFileName + ' to ' + newFilePath);
|
|
1225
|
+
// //find other files that import this file and update them
|
|
1226
|
+
// tsFiles.forEach(tsFile => {
|
|
1227
|
+
// //read contents of f2
|
|
1228
|
+
// let contents = fs.readFileSync(tsFile,'utf8');
|
|
1229
|
+
// //if it imports f
|
|
1230
|
+
// if (contents.indexOf(cssFileName) !== -1)
|
|
1231
|
+
// {
|
|
1232
|
+
// //find the whole line that imports f
|
|
1233
|
+
// let line = contents.split('\n').find(l => l.indexOf(cssFileName) !== -1);
|
|
1234
|
+
// // console.log("OLD: "+line);
|
|
1235
|
+
// let jsonLine = contents.split('\n').find(l => l.indexOf(jsonFile) !== -1);
|
|
1236
|
+
// // console.log("JSON: "+jsonLine);
|
|
1237
|
+
// //if not commented out
|
|
1238
|
+
// if(line.indexOf('//') === -1) {
|
|
1239
|
+
// let previousImportPath = line.match(/['"](.*)['"]/)[1];
|
|
1240
|
+
// let newImportPath = previousImportPath.replace(cssFileName,newFile);
|
|
1241
|
+
// let newContents = contents.replace(line,`import style from '${newImportPath}';`)
|
|
1242
|
+
// .replace(jsonLine+'\n','');
|
|
1243
|
+
// // console.log("\n");
|
|
1244
|
+
// fs.writeFileSync(tsFile,newContents);
|
|
1245
|
+
// console.log('Updated imports in ' + tsFile);
|
|
1246
|
+
// // fs.writeFileSync
|
|
1247
|
+
// // fs.writeFileSync(i,fs.readFileSync(i,'utf8').replace(f,newFile));
|
|
1248
|
+
// }
|
|
1249
|
+
// }
|
|
1250
|
+
// })
|
|
1251
|
+
// });
|
|
1252
|
+
files.filter(f => f.match(/\.(scss\.json|css\.json)$/)).forEach(cssJsonFile => {
|
|
1253
|
+
console.log('Removing ' + cssJsonFile);
|
|
1254
|
+
fs_extra_1.default.unlinkSync(cssJsonFile);
|
|
1255
|
+
});
|
|
1256
|
+
};
|
|
1257
|
+
// });
|
|
1258
|
+
}, () => {
|
|
1259
|
+
console.log('Finished upgrading packages');
|
|
1260
|
+
});
|
|
1261
|
+
// packages.forEach((pkg,key) => {
|
|
1262
|
+
// console.log(key+' Upgrading ' + pkg.packageName);
|
|
1263
|
+
// execPromise(`cd ${pkg.path} && yarn upgrade`).then(() => {
|
|
1264
|
+
// console.log('Upgraded ' + pkg.packageName);
|
|
1265
|
+
// }).catch(err => {
|
|
1266
|
+
// console.warn(err);
|
|
1267
|
+
// })
|
|
1268
|
+
// });
|
|
1269
|
+
};
|
|
1270
|
+
exports.upgradePackages = upgradePackages;
|
|
983
1271
|
const createPackage = async (name, uriBase, basePath = process.cwd()) => {
|
|
984
1272
|
if (!name) {
|
|
985
1273
|
console.warn('Please provide a name as the first argument');
|
|
@@ -1011,8 +1299,8 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
|
|
|
1011
1299
|
//extra variable for clarity (will be same as 'name')
|
|
1012
1300
|
setVariable('output_file_name', name);
|
|
1013
1301
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(cleanPackageName);
|
|
1014
|
-
log(
|
|
1015
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
1302
|
+
log('Creating new LINCD package \'' + name + '\'');
|
|
1303
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'package'), targetFolder);
|
|
1016
1304
|
//replace variables in some of the copied files
|
|
1017
1305
|
await Promise.all([
|
|
1018
1306
|
'src/index.ts',
|
|
@@ -1039,14 +1327,14 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
|
|
|
1039
1327
|
console.log('rename ', path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
|
|
1040
1328
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
|
|
1041
1329
|
});
|
|
1042
|
-
let version = (await (0,
|
|
1330
|
+
let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
|
|
1043
1331
|
console.log('yarn probably not working');
|
|
1044
1332
|
return '';
|
|
1045
1333
|
}));
|
|
1046
1334
|
let installCommand = version.toString().match(/[0-9]+/)
|
|
1047
1335
|
? 'yarn install'
|
|
1048
1336
|
: 'npm install';
|
|
1049
|
-
await (0,
|
|
1337
|
+
await (0, utils_js_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
|
|
1050
1338
|
console.warn('Could not install dependencies');
|
|
1051
1339
|
});
|
|
1052
1340
|
log(`Prepared a new LINCD package in ${chalk_1.default.magenta(targetFolder)}`, `Run ${chalk_1.default.blueBright('yarn build')} from this directory to build once`, `Or ${chalk_1.default.blueBright('yarn dev')} to continuously rebuild on file changes`);
|
|
@@ -1068,43 +1356,6 @@ var buildFailed = function (output) {
|
|
|
1068
1356
|
return (output.indexOf('Aborted due to warnings') !== -1 &&
|
|
1069
1357
|
output.indexOf('Command failed') !== -1);
|
|
1070
1358
|
};
|
|
1071
|
-
/*program.command('shapes').action(async () => {
|
|
1072
|
-
//we've imported require-extensions from npm so that we can use this
|
|
1073
|
-
//we want to avoid nodejs tripping up over @import commands in css files
|
|
1074
|
-
require.extensions['.scss'] = function (sourcecode, filename) {
|
|
1075
|
-
return {};
|
|
1076
|
-
};
|
|
1077
|
-
require.extensions['.css'] = function (sourcecode, filename) {
|
|
1078
|
-
return {};
|
|
1079
|
-
};
|
|
1080
|
-
|
|
1081
|
-
if (fs.existsSync(process.cwd() + '/package.json')) {
|
|
1082
|
-
var pack = JSON.parse(
|
|
1083
|
-
fs.readFileSync(process.cwd() + '/package.json', 'utf8'),
|
|
1084
|
-
);
|
|
1085
|
-
let packageName = pack.name;
|
|
1086
|
-
|
|
1087
|
-
//just making sure the library is loaded in correct order because circular references are currently happening when importing BlankNode before NamedNode for example
|
|
1088
|
-
// require('lincd');
|
|
1089
|
-
//TODO: replace with actual index file from package.json, or tsconfig
|
|
1090
|
-
let indexExports = require(process.cwd() + '/lib/index.js');
|
|
1091
|
-
if(indexExports.packageExports)
|
|
1092
|
-
{
|
|
1093
|
-
let shapeJSONLD = await getShapesJSONLD(indexExports.packageExports);
|
|
1094
|
-
console.log(indexExports.packageExports);
|
|
1095
|
-
console.log(shapeJSONLD);
|
|
1096
|
-
console.log(chalk.bold(chalk.green(packageName+'/dist/shapes.json')));
|
|
1097
|
-
return fs.writeFile(path.join('dist', 'shapes.json'), shapeJSONLD);
|
|
1098
|
-
}
|
|
1099
|
-
else
|
|
1100
|
-
{
|
|
1101
|
-
console.warn("Invalid LINCD package. Index file should export a packageExports object. See examples.")
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
} else {
|
|
1105
|
-
console.warn('Not a project');
|
|
1106
|
-
}
|
|
1107
|
-
});*/
|
|
1108
1359
|
const register = function (registryURL) {
|
|
1109
1360
|
if (fs_extra_1.default.existsSync(process.cwd() + '/package.json')) {
|
|
1110
1361
|
var pack = JSON.parse(fs_extra_1.default.readFileSync(process.cwd() + '/package.json', 'utf8'));
|
|
@@ -1152,58 +1403,139 @@ const register = function (registryURL) {
|
|
|
1152
1403
|
}
|
|
1153
1404
|
};
|
|
1154
1405
|
exports.register = register;
|
|
1155
|
-
const buildPackage = (target, target2, packagePath = process.cwd(), logResults = true) => {
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
}
|
|
1171
|
-
else {
|
|
1172
|
-
nodeEnv = "NODE_ENV='production' ";
|
|
1406
|
+
const buildPackage = async (target, target2, packagePath = process.cwd(), logResults = true) => {
|
|
1407
|
+
let spinner;
|
|
1408
|
+
if (logResults) {
|
|
1409
|
+
//TODO: replace with listr so we can show multiple processes at once
|
|
1410
|
+
spinner = (0, ora_1.default)({
|
|
1411
|
+
discardStdin: true,
|
|
1412
|
+
text: 'Compiling code',
|
|
1413
|
+
}).start();
|
|
1414
|
+
}
|
|
1415
|
+
let buildProcess = Promise.resolve(true);
|
|
1416
|
+
let buildStep = (step) => {
|
|
1417
|
+
buildProcess = buildProcess.then((previousResult) => {
|
|
1418
|
+
if (logResults) {
|
|
1419
|
+
spinner.text = step.name;
|
|
1420
|
+
spinner.start();
|
|
1173
1421
|
}
|
|
1422
|
+
return step.apply().then(stepResult => {
|
|
1423
|
+
if (typeof stepResult === 'string') {
|
|
1424
|
+
// spinner.text = step.name + ' - ' + stepResult;
|
|
1425
|
+
if (logResults) {
|
|
1426
|
+
spinner.warn(step.name + ' - ' + stepResult);
|
|
1427
|
+
spinner.stop();
|
|
1428
|
+
}
|
|
1429
|
+
//warning is shown, but build is still succesful with warnings
|
|
1430
|
+
return false;
|
|
1431
|
+
}
|
|
1432
|
+
else if (stepResult === true || typeof stepResult === 'undefined') {
|
|
1433
|
+
if (logResults) {
|
|
1434
|
+
spinner.succeed();
|
|
1435
|
+
}
|
|
1436
|
+
return previousResult && true;
|
|
1437
|
+
}
|
|
1438
|
+
});
|
|
1439
|
+
});
|
|
1440
|
+
};
|
|
1441
|
+
buildStep({
|
|
1442
|
+
name: 'Compiling code',
|
|
1443
|
+
apply: async () => {
|
|
1444
|
+
return (0, exports.compilePackage)(packagePath);
|
|
1445
|
+
},
|
|
1446
|
+
});
|
|
1447
|
+
buildStep({
|
|
1448
|
+
name: 'Copying files to lib folder',
|
|
1449
|
+
apply: async () => {
|
|
1450
|
+
const files = await (0, glob_1.glob)(packagePath + '/src/**/*.{json,d.ts,css,scss}');
|
|
1451
|
+
return Promise.all(files.map((async (file) => {
|
|
1452
|
+
try {
|
|
1453
|
+
await fs_extra_1.default.copy(file, packagePath + '/lib/esm/' + file.replace(packagePath + '/src/', ''));
|
|
1454
|
+
await fs_extra_1.default.copy(file, packagePath + '/lib/cjs/' + file.replace(packagePath + '/src/', ''));
|
|
1455
|
+
return true;
|
|
1456
|
+
}
|
|
1457
|
+
catch (err) {
|
|
1458
|
+
console.warn(err);
|
|
1459
|
+
return false;
|
|
1460
|
+
}
|
|
1461
|
+
;
|
|
1462
|
+
}))).then((allResults) => {
|
|
1463
|
+
return allResults.every(r => r === true);
|
|
1464
|
+
});
|
|
1465
|
+
},
|
|
1466
|
+
});
|
|
1467
|
+
buildStep({
|
|
1468
|
+
name: 'Dual package support',
|
|
1469
|
+
apply: () => {
|
|
1470
|
+
return (0, utils_js_1.execPromise)('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then(res => {
|
|
1471
|
+
return res === '';
|
|
1472
|
+
});
|
|
1473
|
+
},
|
|
1474
|
+
});
|
|
1475
|
+
buildStep({
|
|
1476
|
+
name: 'Removing old files from lib folder',
|
|
1477
|
+
apply: async () => {
|
|
1478
|
+
return (0, exports.removeOldFiles)(packagePath);
|
|
1479
|
+
},
|
|
1480
|
+
});
|
|
1481
|
+
buildStep({
|
|
1482
|
+
name: 'Checking imports',
|
|
1483
|
+
apply: () => (0, exports.checkImports)(packagePath),
|
|
1484
|
+
});
|
|
1485
|
+
buildStep({
|
|
1486
|
+
name: 'Checking dependencies',
|
|
1487
|
+
apply: () => (0, exports.depCheck)(packagePath),
|
|
1488
|
+
});
|
|
1489
|
+
let success = await buildProcess.catch(err => {
|
|
1490
|
+
//err.error + ':\n' +
|
|
1491
|
+
let msg = (err && err.stdout && err.error) ? err.stdout : err.toString();
|
|
1492
|
+
if (logResults) {
|
|
1493
|
+
spinner.stopAndPersist({
|
|
1494
|
+
symbol: chalk_1.default.red('✖'),
|
|
1495
|
+
text: 'Build failed',
|
|
1496
|
+
});
|
|
1174
1497
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1498
|
+
else {
|
|
1499
|
+
console.log(chalk_1.default.red(packagePath.split('/').pop(), ' - Build failed:'));
|
|
1177
1500
|
}
|
|
1178
|
-
log(
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
}
|
|
1501
|
+
console.log(msg);
|
|
1502
|
+
});
|
|
1503
|
+
//will be undefined if there was an error
|
|
1504
|
+
if (typeof success !== 'undefined') {
|
|
1505
|
+
if (logResults) {
|
|
1506
|
+
spinner.stopAndPersist({
|
|
1507
|
+
symbol: chalk_1.default.greenBright('✔'),
|
|
1508
|
+
text: success === true ? 'Build successful' : 'Build successful with warnings',
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
return success;
|
|
1513
|
+
};
|
|
1514
|
+
exports.buildPackage = buildPackage;
|
|
1515
|
+
const compilePackage = async (packagePath = process.cwd()) => {
|
|
1516
|
+
//echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
|
|
1517
|
+
let cjsConfig = fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'tsconfig-cjs.json'));
|
|
1518
|
+
let esmConfig = fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'tsconfig-esm.json'));
|
|
1519
|
+
let compileCJS = `yarn exec tsc -p tsconfig-cjs.json`;
|
|
1520
|
+
let compileESM = `yarn exec tsc -p tsconfig-esm.json`;
|
|
1521
|
+
let compileCommand;
|
|
1522
|
+
if (cjsConfig && esmConfig) {
|
|
1523
|
+
compileCommand = `${compileCJS} && ${compileESM}`;
|
|
1524
|
+
}
|
|
1525
|
+
else if (cjsConfig) {
|
|
1526
|
+
compileCommand = compileCJS;
|
|
1527
|
+
}
|
|
1528
|
+
else if (esmConfig) {
|
|
1529
|
+
compileCommand = compileESM;
|
|
1201
1530
|
}
|
|
1202
1531
|
else {
|
|
1203
|
-
|
|
1532
|
+
compileCommand = `yarn exec tsc`;
|
|
1204
1533
|
}
|
|
1534
|
+
return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
|
|
1535
|
+
return res === '';
|
|
1536
|
+
});
|
|
1205
1537
|
};
|
|
1206
|
-
exports.
|
|
1538
|
+
exports.compilePackage = compilePackage;
|
|
1207
1539
|
var publishUpdated = function (test = false) {
|
|
1208
1540
|
let packages = getLocalLincdModules();
|
|
1209
1541
|
var p = Promise.resolve('');
|
|
@@ -1221,22 +1553,22 @@ var publishUpdated = function (test = false) {
|
|
|
1221
1553
|
// console.log("Will be requesting npm view from this current working directory:\n"+process.cwd());
|
|
1222
1554
|
// return execPromise('npm view '+pkg.packageName+' --json').then((output:string) => {
|
|
1223
1555
|
let shouldPublish;
|
|
1224
|
-
var pack = (0,
|
|
1556
|
+
var pack = (0, utils_js_1.getPackageJSON)(pckg.path);
|
|
1225
1557
|
let version = getNextVersion(pack.version);
|
|
1226
1558
|
if (pack.private) {
|
|
1227
1559
|
shouldPublish = false;
|
|
1228
|
-
(0,
|
|
1560
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.blue('--> is private, skipping'));
|
|
1229
1561
|
return chalk_1.default.gray(pckg.packageName + ' is private');
|
|
1230
1562
|
// return previousResult + ' ' + chalk.gray(pckg.packageName + ' is private\n');
|
|
1231
1563
|
}
|
|
1232
1564
|
console.log('testing npm');
|
|
1233
|
-
return (0,
|
|
1565
|
+
return (0, utils_js_1.execPromise)('npm info ' + pckg.packageName + ' --json')
|
|
1234
1566
|
.then(async (output) => {
|
|
1235
1567
|
console.log('testing npm done');
|
|
1236
1568
|
var info;
|
|
1237
1569
|
try {
|
|
1238
1570
|
if (output == '' || output.includes('E404')) {
|
|
1239
|
-
(0,
|
|
1571
|
+
(0, utils_js_1.debugInfo)('Empty or 404 response from `npm info`. This package was probably not published before');
|
|
1240
1572
|
// throw new Error('Empty response from `yarn info`. This pkg was probably not published before');
|
|
1241
1573
|
// return;
|
|
1242
1574
|
shouldPublish = true;
|
|
@@ -1259,10 +1591,10 @@ var publishUpdated = function (test = false) {
|
|
|
1259
1591
|
// }
|
|
1260
1592
|
let lastPublishDate = new Date(lastPublish);
|
|
1261
1593
|
// let {lastModifiedTime, lastModifiedName, lastModified} = getLastModifiedSourceTime(pkg.path);
|
|
1262
|
-
let lastCommitInfo = await (0,
|
|
1594
|
+
let lastCommitInfo = await (0, utils_js_1.getLastCommitTime)(pckg.path);
|
|
1263
1595
|
if (!lastCommitInfo) {
|
|
1264
1596
|
shouldPublish = false;
|
|
1265
|
-
(0,
|
|
1597
|
+
(0, utils_js_1.debugInfo)('Could not determine last git commit');
|
|
1266
1598
|
// return previousResult + ' ' + chalk.red(pckg.packageName + ' - could not determine last commit\n');
|
|
1267
1599
|
return chalk_1.default.red(pckg.packageName + ' - could not determine last commit');
|
|
1268
1600
|
}
|
|
@@ -1356,7 +1688,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
|
|
|
1356
1688
|
}
|
|
1357
1689
|
// let path = './';
|
|
1358
1690
|
for (let i = 0; i <= 10; i++) {
|
|
1359
|
-
let envFile = await (0,
|
|
1691
|
+
let envFile = await (0, get_env_vars_js_1.getEnvFile)({
|
|
1360
1692
|
filePath: relativeToPath + path + '.env.json',
|
|
1361
1693
|
}).catch((err) => {
|
|
1362
1694
|
return null;
|
|
@@ -1370,7 +1702,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
|
|
|
1370
1702
|
}
|
|
1371
1703
|
var publishPackage = async function (pkg, test, info, publishVersion) {
|
|
1372
1704
|
if (!pkg) {
|
|
1373
|
-
let localPackageJson = (0,
|
|
1705
|
+
let localPackageJson = (0, utils_js_1.getPackageJSON)();
|
|
1374
1706
|
pkg = {
|
|
1375
1707
|
path: process.cwd(),
|
|
1376
1708
|
packageName: localPackageJson.name,
|
|
@@ -1380,18 +1712,18 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
|
|
|
1380
1712
|
publishVersion = info ? getNextVersion(info.version) : 'patch';
|
|
1381
1713
|
}
|
|
1382
1714
|
if (test) {
|
|
1383
|
-
(0,
|
|
1715
|
+
(0, utils_js_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
|
|
1384
1716
|
//when testing what needs to be published
|
|
1385
1717
|
return chalk_1.default.blue(pkg.packageName + ' should publish');
|
|
1386
1718
|
}
|
|
1387
1719
|
console.log(chalk_1.default.blue('publishing ' + pkg.packageName + ' ' + publishVersion));
|
|
1388
1720
|
//looking for an .env.json file in our workspace, which may store our NPM AUTH key
|
|
1389
1721
|
let envJsonPath = await getEnvJsonPath(pkg.path);
|
|
1390
|
-
return (0,
|
|
1722
|
+
return (0, utils_js_1.execPromise)(`cd ${pkg.path} && ${envJsonPath ? `env-cmd -f ${envJsonPath} --use-shell "` : ''}yarn version ${publishVersion} && yarn npm publish${envJsonPath ? `"` : ''}`, true, false, {}, true)
|
|
1391
1723
|
.then((res) => {
|
|
1392
1724
|
if (res.indexOf('Aborted due to warnings') !== -1 ||
|
|
1393
1725
|
res.indexOf('Could not publish') !== -1 ||
|
|
1394
|
-
res.indexOf(
|
|
1726
|
+
res.indexOf('Couldn\'t publish') !== -1) {
|
|
1395
1727
|
console.log(res);
|
|
1396
1728
|
return chalk_1.default.red(pkg.packageName + ' failed\n');
|
|
1397
1729
|
}
|
|
@@ -1420,12 +1752,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1420
1752
|
// let packages = getLocalLincdModules();
|
|
1421
1753
|
let packages = getLocalLincdPackageMap();
|
|
1422
1754
|
// console.log(packages);
|
|
1423
|
-
let jsonldPkgUpdated = await (0,
|
|
1755
|
+
let jsonldPkgUpdated = await (0, utils_js_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
|
|
1424
1756
|
// let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
|
|
1425
1757
|
//if either cli or jsonldPkg needs to be rebuilt
|
|
1426
1758
|
// if (jsonldPkgUpdated || cliPkgUpdated) {
|
|
1427
1759
|
if (jsonldPkgUpdated) {
|
|
1428
|
-
await (0,
|
|
1760
|
+
await (0, utils_js_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
|
|
1429
1761
|
cwd: packages.get('lincd-jsonld').path,
|
|
1430
1762
|
}, true);
|
|
1431
1763
|
// await execPromise('yarn build-core', false, false, {}, true);
|
|
@@ -1437,12 +1769,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1437
1769
|
// }
|
|
1438
1770
|
let packagesLeft = packages.size;
|
|
1439
1771
|
runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
|
|
1440
|
-
(0,
|
|
1441
|
-
(0,
|
|
1772
|
+
(0, utils_js_1.debugInfo)('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
|
|
1773
|
+
(0, utils_js_1.debugInfo)(packagesLeft + ' packages left.');
|
|
1442
1774
|
packagesLeft = packagesLeft - packageGroup.length;
|
|
1443
1775
|
return async (pkg) => {
|
|
1444
1776
|
// debugInfo('# Checking package ' + pkg.packageName);
|
|
1445
|
-
let needRebuild = await (0,
|
|
1777
|
+
let needRebuild = await (0, utils_js_1.needsRebuilding)(pkg, useGitForLastModified);
|
|
1446
1778
|
if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
|
|
1447
1779
|
needRebuild = true;
|
|
1448
1780
|
}
|
|
@@ -1450,18 +1782,26 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1450
1782
|
//TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
|
|
1451
1783
|
// log(packageName+' modified since last commit on '+now.toString());
|
|
1452
1784
|
if (test) {
|
|
1453
|
-
(0,
|
|
1785
|
+
(0, utils_js_1.debugInfo)('Need to build ' + pkg.packageName);
|
|
1454
1786
|
return chalk_1.default.blue(pkg.packageName + ' should be build');
|
|
1455
1787
|
}
|
|
1456
1788
|
log('Building ' + pkg.packageName);
|
|
1457
|
-
return (
|
|
1789
|
+
// return buildPackage(null,null,pkg.path)
|
|
1790
|
+
return (0, utils_js_1.execPromise)('cd ' +
|
|
1458
1791
|
pkg.path +
|
|
1459
1792
|
' && yarn build' +
|
|
1460
1793
|
(target ? ' ' + target : '') +
|
|
1461
1794
|
(target2 ? ' ' + target2 : ''))
|
|
1462
1795
|
.then((res) => {
|
|
1463
|
-
|
|
1464
|
-
|
|
1796
|
+
if (res === '') {
|
|
1797
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
|
|
1798
|
+
return chalk_1.default.green(pkg.packageName + ' built');
|
|
1799
|
+
}
|
|
1800
|
+
else if (typeof res === 'string') {
|
|
1801
|
+
warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
|
|
1802
|
+
console.log(res);
|
|
1803
|
+
process.exit(1);
|
|
1804
|
+
}
|
|
1465
1805
|
})
|
|
1466
1806
|
.catch(({ error, stdout, stderr }) => {
|
|
1467
1807
|
warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
|
|
@@ -1493,9 +1833,11 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1493
1833
|
};
|
|
1494
1834
|
exports.buildUpdated = buildUpdated;
|
|
1495
1835
|
const printBuildResults = function (failed, done) {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1836
|
+
if (done.size > 0 || done.length > 0) {
|
|
1837
|
+
log('Successfully built: ' +
|
|
1838
|
+
chalk_1.default.green([...done].map((m) => m.packageName).join(', ')) +
|
|
1839
|
+
'\n');
|
|
1840
|
+
}
|
|
1499
1841
|
if (failed.length > 0) {
|
|
1500
1842
|
warn('Failed to build: ' + chalk_1.default.red(failed.join(', ')) + '\n');
|
|
1501
1843
|
}
|
|
@@ -1526,15 +1868,15 @@ var executeCommandForEachPackage = function (packages, command, filterMethod, fi
|
|
|
1526
1868
|
return seen;
|
|
1527
1869
|
});
|
|
1528
1870
|
}
|
|
1529
|
-
log(
|
|
1871
|
+
log('Executing \'' +
|
|
1530
1872
|
chalk_1.default.blueBright(command) +
|
|
1531
|
-
|
|
1873
|
+
'\' on packages ' +
|
|
1532
1874
|
chalk_1.default.magenta(packages.map((m) => m.packageName).join(', ')));
|
|
1533
1875
|
var p = Promise.resolve(true);
|
|
1534
1876
|
packages.forEach((pkg) => {
|
|
1535
1877
|
p = p.then(() => {
|
|
1536
1878
|
log('# Package ' + chalk_1.default.magenta(pkg.packageName));
|
|
1537
|
-
return (0,
|
|
1879
|
+
return (0, utils_js_1.execp)('cd ' + pkg.path + ' && ' + command);
|
|
1538
1880
|
});
|
|
1539
1881
|
});
|
|
1540
1882
|
return p;
|
|
@@ -1556,8 +1898,8 @@ exports.addLinesToFile = addLinesToFile;
|
|
|
1556
1898
|
var addCapacitor = async function (basePath = process.cwd()) {
|
|
1557
1899
|
let targetFolder = ensureFolderExists(basePath);
|
|
1558
1900
|
log('Adding capacitor');
|
|
1559
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
1560
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
1901
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'app-static'), targetFolder);
|
|
1902
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'capacitor', 'scripts'), path_1.default.join(targetFolder, 'scripts'));
|
|
1561
1903
|
//update .env-cmdrc.json file
|
|
1562
1904
|
let envCmdPath = path_1.default.resolve(basePath, '.env-cmdrc.json');
|
|
1563
1905
|
let envCmd = JSON.parse(fs_extra_1.default.readFileSync(envCmdPath, { encoding: 'utf8' }));
|
|
@@ -1579,7 +1921,7 @@ var addCapacitor = async function (basePath = process.cwd()) {
|
|
|
1579
1921
|
log('Edited .env-cmdrc.json');
|
|
1580
1922
|
gitIgnore('android/app/build', 'android/**/capacitor.build.gradle', 'ios/App/App/public');
|
|
1581
1923
|
//update package.json scripts
|
|
1582
|
-
let pack = (0,
|
|
1924
|
+
let pack = (0, utils_js_1.getPackageJSON)(basePath);
|
|
1583
1925
|
pack.scripts['build-staging'] =
|
|
1584
1926
|
'env-cmd -e _main, staging node scripts/build.js';
|
|
1585
1927
|
pack.scripts['fix-app'] = 'node scripts/fix-namespace.js';
|
|
@@ -1594,8 +1936,8 @@ var addCapacitor = async function (basePath = process.cwd()) {
|
|
|
1594
1936
|
pack.scripts['cap:sync'] = 'yarn cap sync';
|
|
1595
1937
|
fs_extra_1.default.writeFile(path_1.default.resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
|
|
1596
1938
|
log('Added new run script to package.json');
|
|
1597
|
-
await (0,
|
|
1598
|
-
await (0,
|
|
1939
|
+
await (0, utils_js_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
|
|
1940
|
+
await (0, utils_js_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/app @capacitor/ios`, false, false, null, true);
|
|
1599
1941
|
// TODO: Do we need to add `npx cap init`? If yes, we should not copy capacitor config.ts yet
|
|
1600
1942
|
// await execPromise(`npx cap init`, true, false, null, true);
|
|
1601
1943
|
// got error:
|
|
@@ -1612,20 +1954,53 @@ var executeCommandForPackage = function (packageName, command) {
|
|
|
1612
1954
|
let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
|
|
1613
1955
|
modDetails.packageName.indexOf(packageName) !== -1);
|
|
1614
1956
|
if (packageDetails) {
|
|
1615
|
-
log(
|
|
1957
|
+
log('Executing \'cd ' +
|
|
1616
1958
|
packageDetails.path +
|
|
1617
1959
|
' && yarn exec lincd' +
|
|
1618
1960
|
(command ? ' ' + command : '') +
|
|
1619
|
-
|
|
1620
|
-
return (0,
|
|
1961
|
+
'\'');
|
|
1962
|
+
return (0, utils_js_1.execp)('cd ' +
|
|
1621
1963
|
packageDetails.path +
|
|
1622
1964
|
' && yarn exec lincd' +
|
|
1623
1965
|
(command ? ' ' + command : ''));
|
|
1624
1966
|
}
|
|
1625
1967
|
else {
|
|
1626
|
-
warn(
|
|
1968
|
+
warn('Could not find a pkg who\'s name (partially) matched ' +
|
|
1627
1969
|
chalk_1.default.cyan(packageName));
|
|
1628
1970
|
}
|
|
1629
1971
|
};
|
|
1630
1972
|
exports.executeCommandForPackage = executeCommandForPackage;
|
|
1973
|
+
/**
|
|
1974
|
+
* Function to remove files older than 10 seconds from the 'lib' folder.
|
|
1975
|
+
* @param {string} packagePath - The path to the package directory.
|
|
1976
|
+
*/
|
|
1977
|
+
const removeOldFiles = async (packagePath) => {
|
|
1978
|
+
const libPath = path_1.default.join(packagePath, 'lib');
|
|
1979
|
+
try {
|
|
1980
|
+
// Read all files in the 'lib' folder asynchronously
|
|
1981
|
+
const files = await (0, glob_1.glob)(packagePath + '/lib/**/*.*');
|
|
1982
|
+
// Iterate through each file
|
|
1983
|
+
for (const file of files) {
|
|
1984
|
+
// const filePath = path.join(libPath, file);
|
|
1985
|
+
// Check if the file exists before attempting to delete it
|
|
1986
|
+
// if (await fs.pathExists(filePath)) {
|
|
1987
|
+
const stats = await fs_extra_1.default.stat(file);
|
|
1988
|
+
const currentTime = new Date().getTime();
|
|
1989
|
+
const lastModifiedTime = stats.mtime.getTime();
|
|
1990
|
+
// Check if the difference between the current time and last modified time is greater than 10 seconds
|
|
1991
|
+
if (currentTime - lastModifiedTime > 10000) {
|
|
1992
|
+
// Attempt to delete the file
|
|
1993
|
+
await fs_extra_1.default.unlink(file);
|
|
1994
|
+
// console.log(`Removed: ${file}`);
|
|
1995
|
+
}
|
|
1996
|
+
// }
|
|
1997
|
+
}
|
|
1998
|
+
return true;
|
|
1999
|
+
}
|
|
2000
|
+
catch (error) {
|
|
2001
|
+
console.error(`Error removing files: ${error.message}`);
|
|
2002
|
+
return false;
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
exports.removeOldFiles = removeOldFiles;
|
|
1631
2006
|
//# sourceMappingURL=cli-methods.js.map
|