lincd-cli 1.2.1 → 1.2.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-with-backend/lincd.config.js +3 -3
- package/defaults/app-with-backend/package.json +2 -1
- package/defaults/app-with-backend/src/index.tsx +3 -3
- package/defaults/app-with-backend/src/pages/Home.tsx +1 -0
- package/defaults/app-with-backend/src/pages/PageNotFound.tsx +2 -1
- package/defaults/app-with-backend/src/theme.css +61 -66
- package/defaults/app-with-backend/src/types.ts +14 -0
- package/defaults/app-with-backend/tsconfig.json +1 -1
- package/defaults/package/package.json +30 -3
- package/defaults/package/src/backend.ts +2 -1
- package/defaults/package/src/index.ts +1 -1
- package/defaults/package/src/ontologies/example-ontology.ts +4 -4
- package/defaults/package/src/package.ts +2 -1
- package/defaults/shape.ts +1 -1
- package/lib/cjs/cli-methods.js +442 -132
- package/lib/cjs/cli-methods.js.map +1 -1
- package/lib/cjs/cli.js +9 -1
- package/lib/cjs/cli.js.map +1 -1
- package/lib/cjs/config-grunt.cjs +1 -1
- package/lib/cjs/config-grunt.cjs.map +1 -1
- package/lib/cjs/config-webpack-app.js +42 -50
- package/lib/cjs/config-webpack-app.js.map +1 -1
- package/lib/cjs/config-webpack.js +10 -19
- package/lib/cjs/config-webpack.js.map +1 -1
- package/lib/cjs/loaders/css-loader.mjs +12 -5
- package/lib/cjs/loaders/css-loader.mjs.map +1 -1
- package/lib/cjs/package.json +2 -1
- package/lib/cjs/plugins/check-imports.js +1 -1
- package/lib/cjs/plugins/check-imports.js.map +1 -1
- package/lib/cjs/plugins/declaration-plugin.js +7 -17
- package/lib/cjs/plugins/declaration-plugin.js.map +1 -1
- package/lib/cjs/utils.js +44 -38
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/cli-methods.js +434 -122
- package/lib/esm/cli-methods.js.map +1 -1
- package/lib/esm/cli.js +10 -2
- package/lib/esm/cli.js.map +1 -1
- package/lib/esm/config-grunt.cjs +24 -27
- package/lib/esm/config-grunt.cjs.map +1 -1
- package/lib/esm/config-webpack-app.js +36 -34
- package/lib/esm/config-webpack-app.js.map +1 -1
- package/lib/esm/config-webpack.js +1 -1
- package/lib/esm/config-webpack.js.map +1 -1
- package/lib/esm/package.json +2 -1
- package/lib/esm/utils.js +24 -9
- package/lib/esm/utils.js.map +1 -1
- package/package.json +7 -1
- /package/defaults/package/src/{types.d.ts → types.ts} +0 -0
package/lib/cjs/cli-methods.js
CHANGED
|
@@ -15,32 +15,18 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
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
|
+
};
|
|
35
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
27
|
};
|
|
38
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.removeOldFiles = exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.compilePackageCJS = exports.compilePackageESM = 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.createApp = void 0;
|
|
40
|
-
exports.warn = warn;
|
|
41
|
-
exports.developPackage = developPackage;
|
|
42
|
-
exports.buildAll = buildAll;
|
|
43
|
-
exports.getLincdPackages = getLincdPackages;
|
|
29
|
+
exports.removeOldFiles = exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.compilePackageCJS = exports.compilePackageESM = exports.compilePackage = exports.buildPackage = exports.register = exports.createPackage = exports.upgradePackages = exports.buildBackend = exports.buildFrontend = exports.buildApp = exports.startServer = exports.runMethod = 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.runOnPackagesGroupedByDependencies = exports.developPackage = exports.logError = exports.warn = exports.createApp = void 0;
|
|
44
30
|
const chalk_1 = __importDefault(require("chalk"));
|
|
45
31
|
const child_process_1 = require("child_process");
|
|
46
32
|
const depcheck_1 = __importDefault(require("depcheck"));
|
|
@@ -48,18 +34,21 @@ const get_env_vars_js_1 = require("env-cmd/dist/get-env-vars.js");
|
|
|
48
34
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
49
35
|
const path_1 = __importStar(require("path"));
|
|
50
36
|
const utils_js_1 = require("./utils.js");
|
|
51
|
-
const
|
|
37
|
+
const child_process_2 = require("child_process");
|
|
52
38
|
const find_nearest_package_json_1 = require("find-nearest-package-json");
|
|
39
|
+
const fs_1 = require("fs");
|
|
53
40
|
const LinkedFileStorage_1 = require("lincd/utils/LinkedFileStorage");
|
|
54
41
|
// import pkg from 'lincd/utils/LinkedFileStorage';
|
|
55
42
|
// const { LinkedFileStorage } = pkg;
|
|
56
43
|
// const config = require('lincd-server/site.webpack.config');
|
|
57
44
|
const glob_1 = require("glob");
|
|
58
45
|
const webpack_1 = __importDefault(require("webpack"));
|
|
59
|
-
const staged_git_files_1 = __importDefault(require("staged-git-files"));
|
|
60
46
|
const ora_1 = __importDefault(require("ora"));
|
|
61
|
-
|
|
62
|
-
let dirname__ = typeof __dirname !== 'undefined'
|
|
47
|
+
const staged_git_files_1 = __importDefault(require("staged-git-files"));
|
|
48
|
+
let dirname__ = typeof __dirname !== 'undefined'
|
|
49
|
+
? __dirname
|
|
50
|
+
: //@ts-ignore
|
|
51
|
+
(0, path_1.dirname)(import.meta.url).replace('file:/', '');
|
|
63
52
|
var variables = {};
|
|
64
53
|
const createApp = async (name, basePath = process.cwd()) => {
|
|
65
54
|
if (!name) {
|
|
@@ -79,7 +68,7 @@ const createApp = async (name, basePath = process.cwd()) => {
|
|
|
79
68
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'gitignore.template'), path_1.default.join(targetFolder, '.gitignore'));
|
|
80
69
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'yarnrc.yml.template'), path_1.default.join(targetFolder, '.yarnrc.yml'));
|
|
81
70
|
// fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
|
|
82
|
-
log(
|
|
71
|
+
log("Creating new LINCD application '" + name + "'");
|
|
83
72
|
//replace variables in some copied files
|
|
84
73
|
await replaceVariablesInFolder(targetFolder);
|
|
85
74
|
let hasYarn = await hasYarnInstalled();
|
|
@@ -106,10 +95,17 @@ function progressUpdate(message) {
|
|
|
106
95
|
}
|
|
107
96
|
function warn(...messages) {
|
|
108
97
|
messages.forEach((message) => {
|
|
109
|
-
console.
|
|
98
|
+
console.warn(chalk_1.default.redBright('Warning: ') + message);
|
|
110
99
|
// console.log(chalk.red(message));
|
|
111
100
|
});
|
|
112
101
|
}
|
|
102
|
+
exports.warn = warn;
|
|
103
|
+
function logError(...messages) {
|
|
104
|
+
messages.forEach((message) => {
|
|
105
|
+
console.error(chalk_1.default.redBright('Error: ') + message);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
exports.logError = logError;
|
|
113
109
|
function developPackage(target, mode) {
|
|
114
110
|
if (!target)
|
|
115
111
|
target = 'es6';
|
|
@@ -135,6 +131,7 @@ function developPackage(target, mode) {
|
|
|
135
131
|
console.warn('unknown build target. Use es5 or es6');
|
|
136
132
|
}
|
|
137
133
|
}
|
|
134
|
+
exports.developPackage = developPackage;
|
|
138
135
|
function checkWorkspaces(rootPath, workspaces, res) {
|
|
139
136
|
// console.log('checking workspaces at '+rootPath+": "+workspaces.toString());
|
|
140
137
|
if (workspaces.packages) {
|
|
@@ -326,6 +323,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
|
|
|
326
323
|
//starts the process
|
|
327
324
|
runStack(startStack);
|
|
328
325
|
}
|
|
326
|
+
exports.runOnPackagesGroupedByDependencies = runOnPackagesGroupedByDependencies;
|
|
329
327
|
function hasDependency(pkg, childPkg, dependencies, depth = 1) {
|
|
330
328
|
console.log('Does ' + pkg.packageName + ' have dep ' + childPkg.packageName + ' ?');
|
|
331
329
|
let deps = dependencies.get(pkg);
|
|
@@ -343,9 +341,121 @@ function hasDependency(pkg, childPkg, dependencies, depth = 1) {
|
|
|
343
341
|
console.log('going up');
|
|
344
342
|
return false;
|
|
345
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Finds the topmost package.json that could be an APP_ROOT
|
|
346
|
+
* Returns null if no app root is found (standalone repo case)
|
|
347
|
+
*/
|
|
348
|
+
function findAppRoot(startPath = process.cwd()) {
|
|
349
|
+
let currentPath = startPath;
|
|
350
|
+
let candidateRoots = [];
|
|
351
|
+
// Walk up the directory tree
|
|
352
|
+
for (let i = 0; i < 10; i++) {
|
|
353
|
+
const packageJsonPath = path_1.default.join(currentPath, 'package.json');
|
|
354
|
+
if (fs_extra_1.default.existsSync(packageJsonPath)) {
|
|
355
|
+
const packageJson = JSON.parse(fs_extra_1.default.readFileSync(packageJsonPath, 'utf8'));
|
|
356
|
+
candidateRoots.push({
|
|
357
|
+
path: currentPath,
|
|
358
|
+
hasWorkspaces: !!packageJson.workspaces,
|
|
359
|
+
isLincd: packageJson.lincd === true,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
const parentPath = path_1.default.join(currentPath, '..');
|
|
363
|
+
// If we've reached the root or haven't moved up
|
|
364
|
+
if (parentPath === currentPath) {
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
currentPath = parentPath;
|
|
368
|
+
}
|
|
369
|
+
// Find the topmost package.json that has workspaces
|
|
370
|
+
// Prefer non-lincd packages (app roots) over lincd packages
|
|
371
|
+
let appRoot = null;
|
|
372
|
+
for (let i = candidateRoots.length - 1; i >= 0; i--) {
|
|
373
|
+
const candidate = candidateRoots[i];
|
|
374
|
+
if (candidate.hasWorkspaces && !candidate.isLincd) {
|
|
375
|
+
appRoot = candidate.path;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
// If no non-lincd workspace found, use the topmost workspace
|
|
380
|
+
if (!appRoot) {
|
|
381
|
+
for (let i = candidateRoots.length - 1; i >= 0; i--) {
|
|
382
|
+
if (candidateRoots[i].hasWorkspaces) {
|
|
383
|
+
appRoot = candidateRoots[i].path;
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return appRoot;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Filters packages to only include those in the dependency tree of the app root
|
|
392
|
+
*/
|
|
393
|
+
function filterPackagesByDependencyTree(allPackages, appRootPath) {
|
|
394
|
+
const appPackageJson = (0, utils_js_1.getPackageJSON)(appRootPath);
|
|
395
|
+
if (!appPackageJson) {
|
|
396
|
+
return allPackages;
|
|
397
|
+
}
|
|
398
|
+
const relevantPackages = new Map();
|
|
399
|
+
const packagesToCheck = new Set();
|
|
400
|
+
// Start with direct dependencies from app root
|
|
401
|
+
if (appPackageJson.dependencies) {
|
|
402
|
+
Object.keys(appPackageJson.dependencies).forEach((dep) => {
|
|
403
|
+
if (allPackages.has(dep)) {
|
|
404
|
+
packagesToCheck.add(dep);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
// Recursively add dependencies
|
|
409
|
+
const processedPackages = new Set();
|
|
410
|
+
while (packagesToCheck.size > 0) {
|
|
411
|
+
const packageName = Array.from(packagesToCheck)[0];
|
|
412
|
+
packagesToCheck.delete(packageName);
|
|
413
|
+
if (processedPackages.has(packageName)) {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
processedPackages.add(packageName);
|
|
417
|
+
const packageDetails = allPackages.get(packageName);
|
|
418
|
+
if (packageDetails) {
|
|
419
|
+
relevantPackages.set(packageName, packageDetails);
|
|
420
|
+
// Get this package's dependencies
|
|
421
|
+
const packageJson = (0, utils_js_1.getPackageJSON)(packageDetails.path);
|
|
422
|
+
if (packageJson && packageJson.dependencies) {
|
|
423
|
+
Object.keys(packageJson.dependencies).forEach((dep) => {
|
|
424
|
+
if (allPackages.has(dep) && !processedPackages.has(dep)) {
|
|
425
|
+
packagesToCheck.add(dep);
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return relevantPackages;
|
|
432
|
+
}
|
|
346
433
|
function buildAll(options) {
|
|
347
434
|
console.log('Building all LINCD packages of this repository in order of dependencies');
|
|
348
435
|
let lincdPackages = getLocalLincdPackageMap();
|
|
436
|
+
const originalPackageCount = lincdPackages.size;
|
|
437
|
+
// Check if we're in an app context and filter packages accordingly
|
|
438
|
+
const appRoot = findAppRoot();
|
|
439
|
+
if (appRoot) {
|
|
440
|
+
const appPackageJson = (0, utils_js_1.getPackageJSON)(appRoot);
|
|
441
|
+
// Check if this is an app (not a lincd package itself) with lincd dependencies
|
|
442
|
+
const isAppWithLincdDeps = appPackageJson &&
|
|
443
|
+
appPackageJson.lincd !== true &&
|
|
444
|
+
appPackageJson.dependencies &&
|
|
445
|
+
Object.keys(appPackageJson.dependencies).some((dep) => lincdPackages.has(dep));
|
|
446
|
+
if (isAppWithLincdDeps) {
|
|
447
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.blue(`Found app root at: ${appRoot}`));
|
|
448
|
+
const filteredPackages = filterPackagesByDependencyTree(lincdPackages, appRoot);
|
|
449
|
+
console.log(chalk_1.default.magenta(`Found ${originalPackageCount} total LINCD packages, building only ${filteredPackages.size} that are relevant to this app`));
|
|
450
|
+
lincdPackages = filteredPackages;
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.blue(`Building all ${originalPackageCount} packages from workspace`));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.blue(`No workspace root found, building all ${originalPackageCount} packages`));
|
|
458
|
+
}
|
|
349
459
|
let startFrom;
|
|
350
460
|
//by default start building
|
|
351
461
|
let building = true;
|
|
@@ -419,7 +529,8 @@ function buildAll(options) {
|
|
|
419
529
|
log(chalk_1.default.cyan('Building ' + pkg.packageName));
|
|
420
530
|
process.stdout.write(packagesLeft + ' packages left\r');
|
|
421
531
|
}
|
|
422
|
-
return command
|
|
532
|
+
return command
|
|
533
|
+
.then((res) => {
|
|
423
534
|
//empty string or true is success
|
|
424
535
|
//false is success with warnings
|
|
425
536
|
//any other string is the build error text
|
|
@@ -443,7 +554,8 @@ function buildAll(options) {
|
|
|
443
554
|
}
|
|
444
555
|
else {
|
|
445
556
|
if (!skipping) {
|
|
446
|
-
log(chalk_1.default.green('Built ' + pkg.packageName) +
|
|
557
|
+
log(chalk_1.default.green('Built ' + pkg.packageName) +
|
|
558
|
+
(res === false ? chalk_1.default.redBright(' (with warnings)') : ''));
|
|
447
559
|
}
|
|
448
560
|
done.add(pkg);
|
|
449
561
|
packagesLeft--;
|
|
@@ -459,7 +571,7 @@ function buildAll(options) {
|
|
|
459
571
|
}
|
|
460
572
|
})
|
|
461
573
|
.catch(({ error, stdout, stderr }) => {
|
|
462
|
-
|
|
574
|
+
logError(chalk_1.default.red('Failed to build ' + pkg.packageName));
|
|
463
575
|
console.log(stdout);
|
|
464
576
|
process.exit(1);
|
|
465
577
|
// let dependentModules = getDependentP
|
|
@@ -560,6 +672,7 @@ function buildAll(options) {
|
|
|
560
672
|
}
|
|
561
673
|
}, sync);
|
|
562
674
|
}
|
|
675
|
+
exports.buildAll = buildAll;
|
|
563
676
|
function getDependentPackages(dependencies, pkg) {
|
|
564
677
|
let dependentModules = [];
|
|
565
678
|
dependencies.forEach((dModuleDependencies, dModule) => {
|
|
@@ -610,6 +723,7 @@ function getLincdPackages(rootPath = process.cwd()) {
|
|
|
610
723
|
checkWorkspaces(rootPath, pack.workspaces, res);
|
|
611
724
|
return res;
|
|
612
725
|
}
|
|
726
|
+
exports.getLincdPackages = getLincdPackages;
|
|
613
727
|
function setVariable(name, replacement) {
|
|
614
728
|
//prepare name for regexp
|
|
615
729
|
name = name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
@@ -655,7 +769,7 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
|
|
|
655
769
|
setVariable('uri_base', uriBase);
|
|
656
770
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(prefix);
|
|
657
771
|
//copy ontology accessor file
|
|
658
|
-
log(
|
|
772
|
+
log("Creating files for ontology '" + prefix + "'");
|
|
659
773
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
|
|
660
774
|
fs_extra_1.default.copySync(path_1.default.join(dirname__, '..', '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
|
|
661
775
|
//copy data files
|
|
@@ -827,7 +941,7 @@ const createSetComponent = async (name, basePath = process.cwd()) => {
|
|
|
827
941
|
let targetFolder = ensureFolderExists(basePath, 'src', 'components');
|
|
828
942
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
|
|
829
943
|
//copy default shape file
|
|
830
|
-
log(
|
|
944
|
+
log("Creating files for set component '" + name + "'");
|
|
831
945
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
832
946
|
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
|
|
833
947
|
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
@@ -843,7 +957,7 @@ const createComponent = async (name, basePath = process.cwd()) => {
|
|
|
843
957
|
let targetFolder = ensureFolderExists(sourceFolder, 'components');
|
|
844
958
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
|
|
845
959
|
//copy default shape file
|
|
846
|
-
log(
|
|
960
|
+
log("Creating files for component '" + name + "'");
|
|
847
961
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
848
962
|
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.tsx'), targetFile);
|
|
849
963
|
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
@@ -895,19 +1009,19 @@ invalidImports = new Map()) => {
|
|
|
895
1009
|
if ((0, utils_js_1.isImportOutsideOfPackage)(i, depth)) {
|
|
896
1010
|
invalidImports.get(filename).push({
|
|
897
1011
|
type: 'outside_package',
|
|
898
|
-
importPath: i
|
|
1012
|
+
importPath: i,
|
|
899
1013
|
});
|
|
900
1014
|
}
|
|
901
1015
|
if ((0, utils_js_1.isInvalidLINCDImport)(i, depth)) {
|
|
902
1016
|
invalidImports.get(filename).push({
|
|
903
1017
|
type: 'lincd',
|
|
904
|
-
importPath: i
|
|
1018
|
+
importPath: i,
|
|
905
1019
|
});
|
|
906
1020
|
}
|
|
907
1021
|
if ((0, utils_js_1.isImportWithMissingExtension)(i)) {
|
|
908
1022
|
invalidImports.get(filename).push({
|
|
909
1023
|
type: 'missing_extension',
|
|
910
|
-
importPath: i
|
|
1024
|
+
importPath: i,
|
|
911
1025
|
});
|
|
912
1026
|
}
|
|
913
1027
|
});
|
|
@@ -921,15 +1035,17 @@ invalidImports = new Map()) => {
|
|
|
921
1035
|
invalidImports.forEach((value, key) => {
|
|
922
1036
|
// res += '- '+chalk.blueBright(key.split('/').pop()) + ':\n';
|
|
923
1037
|
value.forEach(({ type, importPath }) => {
|
|
924
|
-
let message = key.split('/').pop() +
|
|
1038
|
+
let message = key.split('/').pop() + " imports from '" + importPath + "'";
|
|
925
1039
|
if (type === 'outside_package') {
|
|
926
1040
|
message += ' which is outside the package source root';
|
|
927
1041
|
}
|
|
928
1042
|
if (type === 'lincd') {
|
|
929
|
-
message +=
|
|
1043
|
+
message +=
|
|
1044
|
+
' which should not contain /src/ or /lib/ in the import path';
|
|
930
1045
|
}
|
|
931
1046
|
if (type === 'missing_extension') {
|
|
932
|
-
message +=
|
|
1047
|
+
message +=
|
|
1048
|
+
' which should end with a file extension. Like .js or .scss';
|
|
933
1049
|
}
|
|
934
1050
|
res += chalk_1.default.red(message + '\n');
|
|
935
1051
|
});
|
|
@@ -986,10 +1102,16 @@ const depCheck = async (packagePath = process.cwd()) => {
|
|
|
986
1102
|
if (missingLincdPackages.length > 0) {
|
|
987
1103
|
reject(chalk_1.default.red(packagePath.split('/').pop() +
|
|
988
1104
|
'\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
|
|
989
|
-
missingLincdPackages
|
|
1105
|
+
missingLincdPackages
|
|
1106
|
+
.map((missedKey) => {
|
|
1107
|
+
const files = results.missing[missedKey];
|
|
1108
|
+
return `${missedKey} (${files.length} files: ${files.join(', ')})`;
|
|
1109
|
+
})
|
|
1110
|
+
.join(',\n- ')));
|
|
990
1111
|
}
|
|
991
1112
|
else if (missing.length > 0) {
|
|
992
|
-
resolve(chalk_1.default.redBright('warning: ' +
|
|
1113
|
+
resolve(chalk_1.default.redBright('warning: ' +
|
|
1114
|
+
packagePath.split('/').pop() +
|
|
993
1115
|
' is missing dependencies:\n - ' +
|
|
994
1116
|
missing.join('\n - ')));
|
|
995
1117
|
}
|
|
@@ -1055,9 +1177,92 @@ const ensureEnvironmentLoaded = async () => {
|
|
|
1055
1177
|
}
|
|
1056
1178
|
};
|
|
1057
1179
|
exports.ensureEnvironmentLoaded = ensureEnvironmentLoaded;
|
|
1180
|
+
const runMethod = async (packageName, method, options) => {
|
|
1181
|
+
await (0, exports.ensureEnvironmentLoaded)();
|
|
1182
|
+
if (options.spawn) {
|
|
1183
|
+
let lincdConfig = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lincd.config.js')}`).then(s => __importStar(require(s)))).default;
|
|
1184
|
+
//@ts-ignore
|
|
1185
|
+
const ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer'))))
|
|
1186
|
+
.LincdServer;
|
|
1187
|
+
await Promise.resolve(`${path_1.default.join(process.cwd(), 'scripts', 'storage-config.js')}`).then(s => __importStar(require(s)));
|
|
1188
|
+
let server = new ServerClass({
|
|
1189
|
+
loadAppComponent: async () => (await Promise.resolve(`${path_1.default.join(process.cwd(), 'src', 'App')}`).then(s => __importStar(require(s)))).default,
|
|
1190
|
+
...lincdConfig,
|
|
1191
|
+
});
|
|
1192
|
+
//init the server
|
|
1193
|
+
console.log('Initializing server...');
|
|
1194
|
+
server.initOnly().then(() => {
|
|
1195
|
+
//process the backend method call
|
|
1196
|
+
console.log('Running method ' + method);
|
|
1197
|
+
//mock the request and response objects
|
|
1198
|
+
let request = {
|
|
1199
|
+
body: {},
|
|
1200
|
+
query: {},
|
|
1201
|
+
params: {},
|
|
1202
|
+
headers: {},
|
|
1203
|
+
method: 'POST',
|
|
1204
|
+
url: '/' + packageName + '/' + method,
|
|
1205
|
+
};
|
|
1206
|
+
let response = {
|
|
1207
|
+
status: (statusCode) => {
|
|
1208
|
+
console.log('Response status code:', statusCode);
|
|
1209
|
+
return response;
|
|
1210
|
+
},
|
|
1211
|
+
json: (data) => {
|
|
1212
|
+
console.log('Response data:', data);
|
|
1213
|
+
},
|
|
1214
|
+
send: (data) => {
|
|
1215
|
+
console.log('Response data:', data);
|
|
1216
|
+
},
|
|
1217
|
+
};
|
|
1218
|
+
//TODO; allow sending args
|
|
1219
|
+
server
|
|
1220
|
+
.callBackendMethod(packageName, method, [], request, response)
|
|
1221
|
+
.then(() => {
|
|
1222
|
+
console.log('Done');
|
|
1223
|
+
process.exit();
|
|
1224
|
+
});
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
else {
|
|
1228
|
+
//reuse the existing running LincdServer instance.
|
|
1229
|
+
//make a HTTP call
|
|
1230
|
+
//'/call/:pkg/:method',
|
|
1231
|
+
fetch(process.env.SITE_ROOT + '/call/' + packageName + '/' + method, {
|
|
1232
|
+
method: 'POST',
|
|
1233
|
+
headers: {
|
|
1234
|
+
'Content-Type': 'application/json',
|
|
1235
|
+
},
|
|
1236
|
+
})
|
|
1237
|
+
.then((response) => {
|
|
1238
|
+
if (!response.ok) {
|
|
1239
|
+
throw new Error('Network response was not ok');
|
|
1240
|
+
}
|
|
1241
|
+
return response.json();
|
|
1242
|
+
})
|
|
1243
|
+
.then((data) => {
|
|
1244
|
+
console.log('Response data:', data);
|
|
1245
|
+
process.exit();
|
|
1246
|
+
})
|
|
1247
|
+
.catch((error) => {
|
|
1248
|
+
var _a;
|
|
1249
|
+
if (error.code === 'ECONNREFUSED' ||
|
|
1250
|
+
((_a = error.cause) === null || _a === void 0 ? void 0 : _a.code) === 'ECONNREFUSED') {
|
|
1251
|
+
console.error(chalk_1.default.red('Could not connect to the backend server. Is it running?'));
|
|
1252
|
+
console.error(`Make sure you ${chalk_1.default.magenta('run "yarn start" in a separate process')} before calling this method.`);
|
|
1253
|
+
}
|
|
1254
|
+
else {
|
|
1255
|
+
console.error('Error during backend call:', error);
|
|
1256
|
+
}
|
|
1257
|
+
process.exit(1);
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
exports.runMethod = runMethod;
|
|
1058
1262
|
const startServer = async (initOnly = false, ServerClass = null) => {
|
|
1059
1263
|
await (0, exports.ensureEnvironmentLoaded)();
|
|
1060
|
-
let lincdConfig = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lincd.config.js')}`).then(s => __importStar(require(s))))
|
|
1264
|
+
let lincdConfig = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lincd.config.js')}`).then(s => __importStar(require(s))))
|
|
1265
|
+
.default;
|
|
1061
1266
|
// function scssLoadcall(source, filename) {
|
|
1062
1267
|
// return 'console.log("SCSS CALL: ' + filename + '");\n' + source;
|
|
1063
1268
|
// process.exit();
|
|
@@ -1073,8 +1278,19 @@ const startServer = async (initOnly = false, ServerClass = null) => {
|
|
|
1073
1278
|
ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer')))).LincdServer;
|
|
1074
1279
|
}
|
|
1075
1280
|
await Promise.resolve(`${path_1.default.join(process.cwd(), 'scripts', 'storage-config.js')}`).then(s => __importStar(require(s)));
|
|
1281
|
+
let appPromise;
|
|
1282
|
+
if (process.env.NODE_ENV !== 'development') {
|
|
1283
|
+
appPromise = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lib', 'App.js')}`).then(s => __importStar(require(s))))
|
|
1284
|
+
.default;
|
|
1285
|
+
}
|
|
1286
|
+
else {
|
|
1287
|
+
appPromise = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'src', 'App.tsx')}`).then(s => __importStar(require(s))))
|
|
1288
|
+
.default;
|
|
1289
|
+
}
|
|
1076
1290
|
let server = new ServerClass({
|
|
1077
|
-
loadAppComponent: async () =>
|
|
1291
|
+
loadAppComponent: async () => {
|
|
1292
|
+
return appPromise;
|
|
1293
|
+
},
|
|
1078
1294
|
...lincdConfig,
|
|
1079
1295
|
});
|
|
1080
1296
|
//Important to use slice, because when using clusers, child processes need to be able to read the same arguments
|
|
@@ -1089,10 +1305,16 @@ const startServer = async (initOnly = false, ServerClass = null) => {
|
|
|
1089
1305
|
};
|
|
1090
1306
|
exports.startServer = startServer;
|
|
1091
1307
|
const buildApp = async () => {
|
|
1308
|
+
await (0, exports.buildFrontend)();
|
|
1309
|
+
await (0, exports.buildBackend)();
|
|
1310
|
+
console.log(chalk_1.default.magenta(`✅ ${process.env.NODE_ENV} app build finished`));
|
|
1311
|
+
};
|
|
1312
|
+
exports.buildApp = buildApp;
|
|
1313
|
+
const buildFrontend = async () => {
|
|
1092
1314
|
await (0, exports.ensureEnvironmentLoaded)();
|
|
1093
1315
|
const webpackAppConfig = await (await Promise.resolve().then(() => __importStar(require('./config-webpack-app.js')))).getWebpackAppConfig();
|
|
1094
|
-
console.log(chalk_1.default.magenta(
|
|
1095
|
-
|
|
1316
|
+
console.log(chalk_1.default.magenta(`🛠 Building ${process.env.NODE_ENV} frontend bundles`));
|
|
1317
|
+
await new Promise((resolve, reject) => {
|
|
1096
1318
|
(0, webpack_1.default)(webpackAppConfig, async (err, stats) => {
|
|
1097
1319
|
if (err) {
|
|
1098
1320
|
console.error(err.stack || err);
|
|
@@ -1128,13 +1350,16 @@ const buildApp = async () => {
|
|
|
1128
1350
|
}).then(async () => {
|
|
1129
1351
|
// make sure environment is not development for storage config
|
|
1130
1352
|
// and if we want to upload to storage, we need set S3_BUCKET_ENDPOINT
|
|
1131
|
-
if (process.env.NODE_ENV === 'development' ||
|
|
1353
|
+
if (process.env.NODE_ENV === 'development' ||
|
|
1354
|
+
!process.env.S3_BUCKET_ENDPOINT) {
|
|
1132
1355
|
console.warn('Upload build to storage skip in development environment or S3_BUCKET_ENDPOINT is not set');
|
|
1133
|
-
|
|
1356
|
+
return;
|
|
1357
|
+
// process.exit();
|
|
1134
1358
|
}
|
|
1135
1359
|
if (process.env.APP_ENV) {
|
|
1136
1360
|
console.warn('Not uploading to CDN for app builds');
|
|
1137
|
-
|
|
1361
|
+
return;
|
|
1362
|
+
// process.exit();
|
|
1138
1363
|
}
|
|
1139
1364
|
// load the storage config
|
|
1140
1365
|
const storageConfig = await Promise.resolve(`${path_1.default.join(process.cwd(), 'scripts', 'storage-config.js')}`).then(s => __importStar(require(s)));
|
|
@@ -1150,6 +1375,12 @@ const buildApp = async () => {
|
|
|
1150
1375
|
}
|
|
1151
1376
|
// get all files in the web directory and then upload them to the storage
|
|
1152
1377
|
const files = await (0, utils_js_1.getFiles)(pathDir);
|
|
1378
|
+
console.log(chalk_1.default.magenta(`🕊 Publishing ${files.length} public files to linked file storage`));
|
|
1379
|
+
const clearSpinner = (0, ora_1.default)({
|
|
1380
|
+
discardStdin: true,
|
|
1381
|
+
text: `Publishing ${files.length} public files`,
|
|
1382
|
+
}).start();
|
|
1383
|
+
let counter = 0;
|
|
1153
1384
|
const uploads = files.map(async (filePath) => {
|
|
1154
1385
|
// read file content
|
|
1155
1386
|
const fileContent = await fs_extra_1.default.promises.readFile(filePath);
|
|
@@ -1157,15 +1388,79 @@ const buildApp = async () => {
|
|
|
1157
1388
|
// example: /Users/username/project/www/index.html -> /project/www/index.html
|
|
1158
1389
|
const pathname = filePath.replace(pathDir, `/${rootDirectory}`);
|
|
1159
1390
|
// upload file to storage
|
|
1160
|
-
|
|
1391
|
+
await LinkedFileStorage_1.LinkedFileStorage.saveFile(pathname, fileContent)
|
|
1392
|
+
.then(() => {
|
|
1393
|
+
clearSpinner.text = `${counter++}/${files.length}: - Published ${pathname} `;
|
|
1394
|
+
})
|
|
1395
|
+
.catch(console.error);
|
|
1161
1396
|
});
|
|
1162
1397
|
const urls = await Promise.all(uploads);
|
|
1163
|
-
|
|
1164
|
-
process.exit();
|
|
1398
|
+
clearSpinner.succeed(`${urls.length} files uploaded to storage`);
|
|
1165
1399
|
}
|
|
1166
1400
|
});
|
|
1167
1401
|
};
|
|
1168
|
-
exports.
|
|
1402
|
+
exports.buildFrontend = buildFrontend;
|
|
1403
|
+
const buildBackend = async () => {
|
|
1404
|
+
console.log(chalk_1.default.magenta(`🛠 Preparing ${process.env.NODE_ENV} backend`));
|
|
1405
|
+
//run tsc in the backend folder
|
|
1406
|
+
await (0, exports.ensureEnvironmentLoaded)();
|
|
1407
|
+
const sourceFolder = path_1.default.join(process.cwd(), 'src');
|
|
1408
|
+
const targetFolder = path_1.default.join(process.cwd(), 'lib');
|
|
1409
|
+
// Step 1: Clear lib folder
|
|
1410
|
+
const clearSpinner = (0, ora_1.default)({
|
|
1411
|
+
discardStdin: true,
|
|
1412
|
+
text: 'Clearing lib folder',
|
|
1413
|
+
}).start();
|
|
1414
|
+
try {
|
|
1415
|
+
if (fs_extra_1.default.existsSync(targetFolder)) {
|
|
1416
|
+
await fs_extra_1.default.remove(targetFolder);
|
|
1417
|
+
}
|
|
1418
|
+
clearSpinner.succeed('Lib folder cleared');
|
|
1419
|
+
}
|
|
1420
|
+
catch (e) {
|
|
1421
|
+
console.error(e);
|
|
1422
|
+
clearSpinner.fail('Failed to clear lib folder');
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
// Step 2: Compile TS files
|
|
1426
|
+
const compileSpinner = (0, ora_1.default)({
|
|
1427
|
+
discardStdin: true,
|
|
1428
|
+
text: 'Compiling backend TS files',
|
|
1429
|
+
}).start();
|
|
1430
|
+
try {
|
|
1431
|
+
await (0, utils_js_1.execPromise)(`yarn exec tsc`);
|
|
1432
|
+
compileSpinner.succeed('Backend TS files compiled');
|
|
1433
|
+
}
|
|
1434
|
+
catch (e) {
|
|
1435
|
+
console.error(e);
|
|
1436
|
+
compileSpinner.fail('Failed to compile backend TS files');
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
// Step 3: Copy CSS files
|
|
1440
|
+
const copySpinner = (0, ora_1.default)({
|
|
1441
|
+
discardStdin: true,
|
|
1442
|
+
text: 'Copying CSS files',
|
|
1443
|
+
}).start();
|
|
1444
|
+
try {
|
|
1445
|
+
const cssFiles = await (0, utils_js_1.getFiles)(sourceFolder, '.css');
|
|
1446
|
+
await Promise.all(cssFiles.map((file) => {
|
|
1447
|
+
const targetFile = file.replace(sourceFolder, targetFolder);
|
|
1448
|
+
//ensure the target folder exists
|
|
1449
|
+
const targetDir = path_1.default.dirname(targetFile);
|
|
1450
|
+
if (!fs_extra_1.default.existsSync(targetDir)) {
|
|
1451
|
+
fs_extra_1.default.mkdirSync(targetDir, { recursive: true });
|
|
1452
|
+
}
|
|
1453
|
+
return fs_extra_1.default.copyFile(file, targetFile);
|
|
1454
|
+
}));
|
|
1455
|
+
copySpinner.succeed(`${cssFiles.length} CSS files copied`);
|
|
1456
|
+
}
|
|
1457
|
+
catch (e) {
|
|
1458
|
+
console.error(e);
|
|
1459
|
+
copySpinner.fail('Failed to copy CSS files');
|
|
1460
|
+
}
|
|
1461
|
+
return true;
|
|
1462
|
+
};
|
|
1463
|
+
exports.buildBackend = buildBackend;
|
|
1169
1464
|
const upgradePackages = async () => {
|
|
1170
1465
|
await (0, exports.ensureEnvironmentLoaded)();
|
|
1171
1466
|
// let packages = getLincdPackages();
|
|
@@ -1175,7 +1470,9 @@ const upgradePackages = async () => {
|
|
|
1175
1470
|
const tsConfigCJS = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-cjs.json');
|
|
1176
1471
|
const tsConfigESM = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-esm.json');
|
|
1177
1472
|
const typesFile = path_1.default.join(dirname, '../../defaults/package/src', 'types.d.ts');
|
|
1178
|
-
const tsConfigTemplate = await fs_extra_1.default
|
|
1473
|
+
const tsConfigTemplate = await fs_extra_1.default
|
|
1474
|
+
.readJson(path_1.default.join(dirname, '../../defaults/package', 'tsconfig.json'))
|
|
1475
|
+
.catch((err) => {
|
|
1179
1476
|
console.log(err);
|
|
1180
1477
|
});
|
|
1181
1478
|
runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
|
|
@@ -1290,7 +1587,9 @@ const upgradePackages = async () => {
|
|
|
1290
1587
|
// }
|
|
1291
1588
|
// })
|
|
1292
1589
|
// });
|
|
1293
|
-
files
|
|
1590
|
+
files
|
|
1591
|
+
.filter((f) => f.match(/\.(scss\.json|css\.json)$/))
|
|
1592
|
+
.forEach((cssJsonFile) => {
|
|
1294
1593
|
console.log('Removing ' + cssJsonFile);
|
|
1295
1594
|
fs_extra_1.default.unlinkSync(cssJsonFile);
|
|
1296
1595
|
});
|
|
@@ -1340,7 +1639,7 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
|
|
|
1340
1639
|
//extra variable for clarity (will be same as 'name')
|
|
1341
1640
|
setVariable('output_file_name', name);
|
|
1342
1641
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(cleanPackageName);
|
|
1343
|
-
log(
|
|
1642
|
+
log("Creating new LINCD package '" + name + "'");
|
|
1344
1643
|
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'package'), targetFolder);
|
|
1345
1644
|
//replace variables in some of the copied files
|
|
1346
1645
|
await Promise.all([
|
|
@@ -1463,7 +1762,7 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
|
|
|
1463
1762
|
spinner.text = step.name;
|
|
1464
1763
|
spinner.start();
|
|
1465
1764
|
}
|
|
1466
|
-
return step.apply().then(stepResult => {
|
|
1765
|
+
return step.apply().then((stepResult) => {
|
|
1467
1766
|
//if a build step returns a string,
|
|
1468
1767
|
//a warning is shown but the build is still successful with warnings
|
|
1469
1768
|
if (typeof stepResult === 'string') {
|
|
@@ -1492,6 +1791,10 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
|
|
|
1492
1791
|
});
|
|
1493
1792
|
});
|
|
1494
1793
|
};
|
|
1794
|
+
buildStep({
|
|
1795
|
+
name: 'Checking imports',
|
|
1796
|
+
apply: () => (0, exports.checkImports)(packagePath + '/src'),
|
|
1797
|
+
});
|
|
1495
1798
|
buildStep({
|
|
1496
1799
|
name: 'Compiling ESM',
|
|
1497
1800
|
apply: async () => {
|
|
@@ -1508,26 +1811,29 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
|
|
|
1508
1811
|
name: 'Copying files to lib folder',
|
|
1509
1812
|
apply: async () => {
|
|
1510
1813
|
const files = await (0, glob_1.glob)(packagePath + '/src/**/*.{json,d.ts,css,scss}');
|
|
1511
|
-
return Promise.all(files.map(
|
|
1814
|
+
return Promise.all(files.map(async (file) => {
|
|
1512
1815
|
try {
|
|
1513
|
-
await fs_extra_1.default.copy(file, packagePath +
|
|
1514
|
-
|
|
1816
|
+
await fs_extra_1.default.copy(file, packagePath +
|
|
1817
|
+
'/lib/esm/' +
|
|
1818
|
+
file.replace(packagePath + '/src/', ''));
|
|
1819
|
+
await fs_extra_1.default.copy(file, packagePath +
|
|
1820
|
+
'/lib/cjs/' +
|
|
1821
|
+
file.replace(packagePath + '/src/', ''));
|
|
1515
1822
|
return true;
|
|
1516
1823
|
}
|
|
1517
1824
|
catch (err) {
|
|
1518
1825
|
console.warn(err);
|
|
1519
1826
|
return false;
|
|
1520
1827
|
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
return allResults.every(r => r === true);
|
|
1828
|
+
})).then((allResults) => {
|
|
1829
|
+
return allResults.every((r) => r === true);
|
|
1524
1830
|
});
|
|
1525
1831
|
},
|
|
1526
1832
|
});
|
|
1527
1833
|
buildStep({
|
|
1528
1834
|
name: 'Dual package support',
|
|
1529
1835
|
apply: () => {
|
|
1530
|
-
return (0, utils_js_1.execPromise)('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then(res => {
|
|
1836
|
+
return (0, utils_js_1.execPromise)('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
|
|
1531
1837
|
return res === '';
|
|
1532
1838
|
});
|
|
1533
1839
|
},
|
|
@@ -1538,16 +1844,16 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
|
|
|
1538
1844
|
return (0, exports.removeOldFiles)(packagePath);
|
|
1539
1845
|
},
|
|
1540
1846
|
});
|
|
1541
|
-
buildStep({
|
|
1542
|
-
name: 'Checking imports',
|
|
1543
|
-
apply: () => (0, exports.checkImports)(packagePath),
|
|
1544
|
-
});
|
|
1545
1847
|
buildStep({
|
|
1546
1848
|
name: 'Checking dependencies',
|
|
1547
1849
|
apply: () => (0, exports.depCheck)(packagePath),
|
|
1548
1850
|
});
|
|
1549
|
-
let success = await buildProcess.catch(err => {
|
|
1550
|
-
let msg = typeof err === 'string' || err instanceof Error
|
|
1851
|
+
let success = await buildProcess.catch((err) => {
|
|
1852
|
+
let msg = typeof err === 'string' || err instanceof Error
|
|
1853
|
+
? err.toString()
|
|
1854
|
+
: err.error && !err.error.toString().includes('Command failed:')
|
|
1855
|
+
? err.error
|
|
1856
|
+
: err.stdout + '\n' + err.stderr;
|
|
1551
1857
|
if (logResults) {
|
|
1552
1858
|
spinner.stopAndPersist({
|
|
1553
1859
|
symbol: chalk_1.default.red('✖'),
|
|
@@ -1565,15 +1871,19 @@ const buildPackage = async (target, target2, packagePath = process.cwd(), logRes
|
|
|
1565
1871
|
if (logResults) {
|
|
1566
1872
|
spinner.stopAndPersist({
|
|
1567
1873
|
symbol: chalk_1.default.greenBright('✔'),
|
|
1568
|
-
text: success === true
|
|
1874
|
+
text: success === true
|
|
1875
|
+
? 'Build successful'
|
|
1876
|
+
: 'Build successful with warnings',
|
|
1569
1877
|
});
|
|
1570
1878
|
}
|
|
1571
1879
|
}
|
|
1572
1880
|
else {
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1881
|
+
if (logResults) {
|
|
1882
|
+
spinner.stopAndPersist({
|
|
1883
|
+
symbol: chalk_1.default.red('✖'),
|
|
1884
|
+
text: 'Build failed',
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1577
1887
|
}
|
|
1578
1888
|
return success;
|
|
1579
1889
|
};
|
|
@@ -1608,18 +1918,20 @@ exports.compilePackage = compilePackage;
|
|
|
1608
1918
|
const compilePackageESM = async (packagePath = process.cwd()) => {
|
|
1609
1919
|
//echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
|
|
1610
1920
|
let compileCommand = `yarn exec tsc -p tsconfig-esm.json`;
|
|
1611
|
-
return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
|
|
1921
|
+
return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then((res) => {
|
|
1612
1922
|
return res === '';
|
|
1613
1923
|
});
|
|
1614
1924
|
};
|
|
1615
1925
|
exports.compilePackageESM = compilePackageESM;
|
|
1616
1926
|
const compilePackageCJS = async (packagePath = process.cwd()) => {
|
|
1617
1927
|
let compileCommand = `yarn exec tsc -p tsconfig-cjs.json`;
|
|
1618
|
-
return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath })
|
|
1928
|
+
return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath })
|
|
1929
|
+
.then((res) => {
|
|
1619
1930
|
return res === '';
|
|
1620
|
-
})
|
|
1931
|
+
})
|
|
1932
|
+
.catch((err) => {
|
|
1621
1933
|
return {
|
|
1622
|
-
error: err.stdout
|
|
1934
|
+
error: err.stdout,
|
|
1623
1935
|
};
|
|
1624
1936
|
});
|
|
1625
1937
|
};
|
|
@@ -1735,7 +2047,7 @@ var publishUpdated = function (test = false) {
|
|
|
1735
2047
|
})
|
|
1736
2048
|
.catch(({ error, stdout, stderr }) => {
|
|
1737
2049
|
if (error) {
|
|
1738
|
-
console.
|
|
2050
|
+
console.error(error.message);
|
|
1739
2051
|
}
|
|
1740
2052
|
if (stdout) {
|
|
1741
2053
|
console.log(stderr);
|
|
@@ -1811,7 +2123,7 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
|
|
|
1811
2123
|
.then((res) => {
|
|
1812
2124
|
if (res.indexOf('Aborted due to warnings') !== -1 ||
|
|
1813
2125
|
res.indexOf('Could not publish') !== -1 ||
|
|
1814
|
-
res.indexOf(
|
|
2126
|
+
res.indexOf("Couldn't publish") !== -1) {
|
|
1815
2127
|
console.log(res);
|
|
1816
2128
|
return chalk_1.default.red(pkg.packageName + ' failed\n');
|
|
1817
2129
|
}
|
|
@@ -1824,7 +2136,7 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
|
|
|
1824
2136
|
chalk_1.default.magenta(publishVersion));
|
|
1825
2137
|
})
|
|
1826
2138
|
.catch(({ error, stdout, stderr }) => {
|
|
1827
|
-
|
|
2139
|
+
logError('Failed to publish: ' + error.message);
|
|
1828
2140
|
return chalk_1.default.red(pkg.packageName + ' failed to publish');
|
|
1829
2141
|
});
|
|
1830
2142
|
};
|
|
@@ -1840,16 +2152,26 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1840
2152
|
// let packages = getLocalLincdModules();
|
|
1841
2153
|
let packages = getLocalLincdPackageMap();
|
|
1842
2154
|
// console.log(packages);
|
|
1843
|
-
let jsonldPkgUpdated = await
|
|
2155
|
+
// let jsonldPkgUpdated = await needsRebuilding(
|
|
2156
|
+
// packages.get('lincd-jsonld'),
|
|
2157
|
+
// useGitForLastModified,
|
|
2158
|
+
// );
|
|
1844
2159
|
// let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
|
|
1845
2160
|
//if either cli or jsonldPkg needs to be rebuilt
|
|
1846
2161
|
// if (jsonldPkgUpdated || cliPkgUpdated) {
|
|
1847
|
-
if (jsonldPkgUpdated)
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
2162
|
+
// if (jsonldPkgUpdated)
|
|
2163
|
+
// {
|
|
2164
|
+
// await execPromise(
|
|
2165
|
+
// 'yarn exec tsc && echo "compiled lincd-jsonld"',
|
|
2166
|
+
// false,
|
|
2167
|
+
// false,
|
|
2168
|
+
// {
|
|
2169
|
+
// cwd: packages.get('lincd-jsonld').path,
|
|
2170
|
+
// },
|
|
2171
|
+
// true,
|
|
2172
|
+
// );
|
|
2173
|
+
// // await execPromise('yarn build-core', false, false, {}, true);
|
|
2174
|
+
// }
|
|
1853
2175
|
let rebuildAllModules = false;
|
|
1854
2176
|
// if (cliPkgUpdated) {
|
|
1855
2177
|
// rebuildAllModules = true;
|
|
@@ -1863,9 +2185,10 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1863
2185
|
return async (pkg) => {
|
|
1864
2186
|
// debugInfo('# Checking package ' + pkg.packageName);
|
|
1865
2187
|
let needRebuild = await (0, utils_js_1.needsRebuilding)(pkg, useGitForLastModified);
|
|
1866
|
-
if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated)
|
|
1867
|
-
|
|
1868
|
-
|
|
2188
|
+
// if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated)
|
|
2189
|
+
// {
|
|
2190
|
+
// needRebuild = true;
|
|
2191
|
+
// }
|
|
1869
2192
|
if (needRebuild || rebuildAllModules) {
|
|
1870
2193
|
//TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
|
|
1871
2194
|
// log(packageName+' modified since last commit on '+now.toString());
|
|
@@ -1874,42 +2197,31 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1874
2197
|
return chalk_1.default.blue(pkg.packageName + ' should be build');
|
|
1875
2198
|
}
|
|
1876
2199
|
log('Building ' + pkg.packageName);
|
|
1877
|
-
|
|
1878
|
-
return (0, utils_js_1.execPromise)('cd ' +
|
|
1879
|
-
pkg.path +
|
|
1880
|
-
' && yarn build' +
|
|
1881
|
-
(target ? ' ' + target : '') +
|
|
1882
|
-
(target2 ? ' ' + target2 : ''))
|
|
2200
|
+
return (0, exports.buildPackage)(null, null, path_1.default.join(process.cwd(), pkg.path), false)
|
|
1883
2201
|
.then((res) => {
|
|
1884
|
-
|
|
2202
|
+
//empty string or true is success
|
|
2203
|
+
//false is success with warnings
|
|
2204
|
+
//any other string is the build error text
|
|
2205
|
+
//undefined result means it failed
|
|
2206
|
+
if (typeof res === 'undefined') {
|
|
2207
|
+
logError('Failed to build ' + pkg.packageName);
|
|
2208
|
+
process.exit(1);
|
|
2209
|
+
}
|
|
2210
|
+
else {
|
|
1885
2211
|
(0, utils_js_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
|
|
1886
2212
|
return chalk_1.default.green(pkg.packageName + ' built');
|
|
1887
2213
|
}
|
|
1888
|
-
else if (typeof res === 'string') {
|
|
1889
|
-
warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
|
|
1890
|
-
// console.log(res);
|
|
1891
|
-
process.exit(1);
|
|
1892
|
-
}
|
|
1893
2214
|
})
|
|
1894
|
-
.catch((
|
|
1895
|
-
|
|
1896
|
-
console.
|
|
2215
|
+
.catch((err) => {
|
|
2216
|
+
logError('Failed to build ' + pkg.packageName);
|
|
2217
|
+
console.error(err);
|
|
1897
2218
|
process.exit(1);
|
|
1898
|
-
// let dependentModules = getDependentPackages(dependencies, pkg);
|
|
1899
|
-
// if (dependentModules.length > 0) {
|
|
1900
|
-
// // printBuildResults(failedModules, done);
|
|
1901
|
-
// warn(chalk.red(pkg.packageName + ' build failed'));
|
|
1902
|
-
// warn(
|
|
1903
|
-
// 'Stopping build-updated process because ' +
|
|
1904
|
-
// dependentModules.length +
|
|
1905
|
-
// ' other packages depend on this package.\n',
|
|
1906
|
-
// ); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
1907
|
-
// }
|
|
1908
2219
|
});
|
|
1909
2220
|
}
|
|
1910
2221
|
};
|
|
1911
|
-
}, (results) => {
|
|
2222
|
+
}, (dependencies, results) => {
|
|
1912
2223
|
if (results.length) {
|
|
2224
|
+
log(chalk_1.default.green('Changed packages have been rebuilt'));
|
|
1913
2225
|
log('Summary:');
|
|
1914
2226
|
log(results.join('\n'));
|
|
1915
2227
|
}
|
|
@@ -1949,16 +2261,15 @@ var executeCommandForEachPackage = function (packages, command, filterMethod, fi
|
|
|
1949
2261
|
}
|
|
1950
2262
|
let seen = false;
|
|
1951
2263
|
packages = packages.filter((pkg) => {
|
|
1952
|
-
if (!seen &&
|
|
1953
|
-
pkg.packageName.includes(startFrom)) {
|
|
2264
|
+
if (!seen && pkg.packageName.includes(startFrom)) {
|
|
1954
2265
|
seen = true;
|
|
1955
2266
|
}
|
|
1956
2267
|
return seen;
|
|
1957
2268
|
});
|
|
1958
2269
|
}
|
|
1959
|
-
log(
|
|
2270
|
+
log("Executing '" +
|
|
1960
2271
|
chalk_1.default.blueBright(command) +
|
|
1961
|
-
'
|
|
2272
|
+
"' on packages " +
|
|
1962
2273
|
chalk_1.default.magenta(packages.map((m) => m.packageName).join(', ')));
|
|
1963
2274
|
var p = Promise.resolve(true);
|
|
1964
2275
|
packages.forEach((pkg) => {
|
|
@@ -2042,20 +2353,19 @@ var executeCommandForPackage = function (packageName, command) {
|
|
|
2042
2353
|
let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
|
|
2043
2354
|
modDetails.packageName.indexOf(packageName) !== -1);
|
|
2044
2355
|
if (packageDetails) {
|
|
2045
|
-
log(
|
|
2356
|
+
log("Executing 'cd " +
|
|
2046
2357
|
packageDetails.path +
|
|
2047
|
-
' && yarn
|
|
2358
|
+
' && yarn lincd' +
|
|
2048
2359
|
(command ? ' ' + command : '') +
|
|
2049
|
-
'
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
(command ? ' ' + command : ''));
|
|
2360
|
+
"'");
|
|
2361
|
+
(0, child_process_2.spawn)(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', // Windows quirk
|
|
2362
|
+
['lincd', command || null], {
|
|
2363
|
+
cwd: packageDetails.path,
|
|
2364
|
+
stdio: 'inherit',
|
|
2365
|
+
});
|
|
2056
2366
|
}
|
|
2057
2367
|
else {
|
|
2058
|
-
warn(
|
|
2368
|
+
warn("Could not find a pkg who's name (partially) matched " +
|
|
2059
2369
|
chalk_1.default.cyan(packageName));
|
|
2060
2370
|
}
|
|
2061
2371
|
};
|