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