lincd-cli 1.2.2 → 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/package/src/backend.ts +2 -1
- package/lib/cjs/cli-methods.js +248 -112
- package/lib/cjs/cli-methods.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 +7 -17
- package/lib/cjs/config-webpack-app.js.map +1 -1
- package/lib/cjs/config-webpack.js +9 -18
- 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 +1 -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 +32 -33
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/cli-methods.js +244 -100
- package/lib/esm/cli-methods.js.map +1 -1
- package/lib/esm/config-grunt.cjs +24 -27
- package/lib/esm/config-grunt.cjs.map +1 -1
- package/lib/esm/package.json +1 -1
- package/lib/esm/utils.js +12 -4
- package/lib/esm/utils.js.map +1 -1
- package/package.json +6 -1
package/lib/esm/cli-methods.js
CHANGED
|
@@ -14,19 +14,21 @@ import { getEnvFile } from 'env-cmd/dist/get-env-vars.js';
|
|
|
14
14
|
import fs from 'fs-extra';
|
|
15
15
|
import path, { dirname } from 'path';
|
|
16
16
|
import { debugInfo, execp, execPromise, getFileImports, getFiles, getLastCommitTime, getPackageJSON, isImportOutsideOfPackage, isImportWithMissingExtension, isInvalidLINCDImport, needsRebuilding, } from './utils.js';
|
|
17
|
-
import {
|
|
17
|
+
import { spawn as spawnChild } from 'child_process';
|
|
18
18
|
import { findNearestPackageJson } from 'find-nearest-package-json';
|
|
19
|
+
import { statSync } from 'fs';
|
|
19
20
|
import { LinkedFileStorage } from 'lincd/utils/LinkedFileStorage';
|
|
20
|
-
import { spawn as spawnChild } from 'child_process';
|
|
21
21
|
// import pkg from 'lincd/utils/LinkedFileStorage';
|
|
22
22
|
// const { LinkedFileStorage } = pkg;
|
|
23
23
|
// const config = require('lincd-server/site.webpack.config');
|
|
24
24
|
import { glob } from 'glob';
|
|
25
25
|
import webpack from 'webpack';
|
|
26
|
-
import stagedGitFiles from 'staged-git-files';
|
|
27
26
|
import ora from 'ora';
|
|
28
|
-
|
|
29
|
-
let dirname__ = typeof __dirname !== 'undefined'
|
|
27
|
+
import stagedGitFiles from 'staged-git-files';
|
|
28
|
+
let dirname__ = typeof __dirname !== 'undefined'
|
|
29
|
+
? __dirname
|
|
30
|
+
: //@ts-ignore
|
|
31
|
+
dirname(import.meta.url).replace('file:/', '');
|
|
30
32
|
var variables = {};
|
|
31
33
|
export const createApp = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
|
|
32
34
|
if (!name) {
|
|
@@ -46,7 +48,7 @@ export const createApp = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...ar
|
|
|
46
48
|
fs.renameSync(path.join(targetFolder, 'gitignore.template'), path.join(targetFolder, '.gitignore'));
|
|
47
49
|
fs.renameSync(path.join(targetFolder, 'yarnrc.yml.template'), path.join(targetFolder, '.yarnrc.yml'));
|
|
48
50
|
// fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
|
|
49
|
-
log(
|
|
51
|
+
log("Creating new LINCD application '" + name + "'");
|
|
50
52
|
//replace variables in some copied files
|
|
51
53
|
yield replaceVariablesInFolder(targetFolder);
|
|
52
54
|
let hasYarn = yield hasYarnInstalled();
|
|
@@ -72,10 +74,15 @@ function progressUpdate(message) {
|
|
|
72
74
|
}
|
|
73
75
|
export function warn(...messages) {
|
|
74
76
|
messages.forEach((message) => {
|
|
75
|
-
console.
|
|
77
|
+
console.warn(chalk.redBright('Warning: ') + message);
|
|
76
78
|
// console.log(chalk.red(message));
|
|
77
79
|
});
|
|
78
80
|
}
|
|
81
|
+
export function logError(...messages) {
|
|
82
|
+
messages.forEach((message) => {
|
|
83
|
+
console.error(chalk.redBright('Error: ') + message);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
79
86
|
export function developPackage(target, mode) {
|
|
80
87
|
if (!target)
|
|
81
88
|
target = 'es6';
|
|
@@ -309,9 +316,121 @@ function hasDependency(pkg, childPkg, dependencies, depth = 1) {
|
|
|
309
316
|
console.log('going up');
|
|
310
317
|
return false;
|
|
311
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Finds the topmost package.json that could be an APP_ROOT
|
|
321
|
+
* Returns null if no app root is found (standalone repo case)
|
|
322
|
+
*/
|
|
323
|
+
function findAppRoot(startPath = process.cwd()) {
|
|
324
|
+
let currentPath = startPath;
|
|
325
|
+
let candidateRoots = [];
|
|
326
|
+
// Walk up the directory tree
|
|
327
|
+
for (let i = 0; i < 10; i++) {
|
|
328
|
+
const packageJsonPath = path.join(currentPath, 'package.json');
|
|
329
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
330
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
331
|
+
candidateRoots.push({
|
|
332
|
+
path: currentPath,
|
|
333
|
+
hasWorkspaces: !!packageJson.workspaces,
|
|
334
|
+
isLincd: packageJson.lincd === true,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
const parentPath = path.join(currentPath, '..');
|
|
338
|
+
// If we've reached the root or haven't moved up
|
|
339
|
+
if (parentPath === currentPath) {
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
currentPath = parentPath;
|
|
343
|
+
}
|
|
344
|
+
// Find the topmost package.json that has workspaces
|
|
345
|
+
// Prefer non-lincd packages (app roots) over lincd packages
|
|
346
|
+
let appRoot = null;
|
|
347
|
+
for (let i = candidateRoots.length - 1; i >= 0; i--) {
|
|
348
|
+
const candidate = candidateRoots[i];
|
|
349
|
+
if (candidate.hasWorkspaces && !candidate.isLincd) {
|
|
350
|
+
appRoot = candidate.path;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// If no non-lincd workspace found, use the topmost workspace
|
|
355
|
+
if (!appRoot) {
|
|
356
|
+
for (let i = candidateRoots.length - 1; i >= 0; i--) {
|
|
357
|
+
if (candidateRoots[i].hasWorkspaces) {
|
|
358
|
+
appRoot = candidateRoots[i].path;
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return appRoot;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Filters packages to only include those in the dependency tree of the app root
|
|
367
|
+
*/
|
|
368
|
+
function filterPackagesByDependencyTree(allPackages, appRootPath) {
|
|
369
|
+
const appPackageJson = getPackageJSON(appRootPath);
|
|
370
|
+
if (!appPackageJson) {
|
|
371
|
+
return allPackages;
|
|
372
|
+
}
|
|
373
|
+
const relevantPackages = new Map();
|
|
374
|
+
const packagesToCheck = new Set();
|
|
375
|
+
// Start with direct dependencies from app root
|
|
376
|
+
if (appPackageJson.dependencies) {
|
|
377
|
+
Object.keys(appPackageJson.dependencies).forEach((dep) => {
|
|
378
|
+
if (allPackages.has(dep)) {
|
|
379
|
+
packagesToCheck.add(dep);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
// Recursively add dependencies
|
|
384
|
+
const processedPackages = new Set();
|
|
385
|
+
while (packagesToCheck.size > 0) {
|
|
386
|
+
const packageName = Array.from(packagesToCheck)[0];
|
|
387
|
+
packagesToCheck.delete(packageName);
|
|
388
|
+
if (processedPackages.has(packageName)) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
processedPackages.add(packageName);
|
|
392
|
+
const packageDetails = allPackages.get(packageName);
|
|
393
|
+
if (packageDetails) {
|
|
394
|
+
relevantPackages.set(packageName, packageDetails);
|
|
395
|
+
// Get this package's dependencies
|
|
396
|
+
const packageJson = getPackageJSON(packageDetails.path);
|
|
397
|
+
if (packageJson && packageJson.dependencies) {
|
|
398
|
+
Object.keys(packageJson.dependencies).forEach((dep) => {
|
|
399
|
+
if (allPackages.has(dep) && !processedPackages.has(dep)) {
|
|
400
|
+
packagesToCheck.add(dep);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return relevantPackages;
|
|
407
|
+
}
|
|
312
408
|
export function buildAll(options) {
|
|
313
409
|
console.log('Building all LINCD packages of this repository in order of dependencies');
|
|
314
410
|
let lincdPackages = getLocalLincdPackageMap();
|
|
411
|
+
const originalPackageCount = lincdPackages.size;
|
|
412
|
+
// Check if we're in an app context and filter packages accordingly
|
|
413
|
+
const appRoot = findAppRoot();
|
|
414
|
+
if (appRoot) {
|
|
415
|
+
const appPackageJson = getPackageJSON(appRoot);
|
|
416
|
+
// Check if this is an app (not a lincd package itself) with lincd dependencies
|
|
417
|
+
const isAppWithLincdDeps = appPackageJson &&
|
|
418
|
+
appPackageJson.lincd !== true &&
|
|
419
|
+
appPackageJson.dependencies &&
|
|
420
|
+
Object.keys(appPackageJson.dependencies).some((dep) => lincdPackages.has(dep));
|
|
421
|
+
if (isAppWithLincdDeps) {
|
|
422
|
+
debugInfo(chalk.blue(`Found app root at: ${appRoot}`));
|
|
423
|
+
const filteredPackages = filterPackagesByDependencyTree(lincdPackages, appRoot);
|
|
424
|
+
console.log(chalk.magenta(`Found ${originalPackageCount} total LINCD packages, building only ${filteredPackages.size} that are relevant to this app`));
|
|
425
|
+
lincdPackages = filteredPackages;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
debugInfo(chalk.blue(`Building all ${originalPackageCount} packages from workspace`));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
debugInfo(chalk.blue(`No workspace root found, building all ${originalPackageCount} packages`));
|
|
433
|
+
}
|
|
315
434
|
let startFrom;
|
|
316
435
|
//by default start building
|
|
317
436
|
let building = true;
|
|
@@ -385,7 +504,8 @@ export function buildAll(options) {
|
|
|
385
504
|
log(chalk.cyan('Building ' + pkg.packageName));
|
|
386
505
|
process.stdout.write(packagesLeft + ' packages left\r');
|
|
387
506
|
}
|
|
388
|
-
return command
|
|
507
|
+
return command
|
|
508
|
+
.then((res) => {
|
|
389
509
|
//empty string or true is success
|
|
390
510
|
//false is success with warnings
|
|
391
511
|
//any other string is the build error text
|
|
@@ -409,7 +529,8 @@ export function buildAll(options) {
|
|
|
409
529
|
}
|
|
410
530
|
else {
|
|
411
531
|
if (!skipping) {
|
|
412
|
-
log(chalk.green('Built ' + pkg.packageName) +
|
|
532
|
+
log(chalk.green('Built ' + pkg.packageName) +
|
|
533
|
+
(res === false ? chalk.redBright(' (with warnings)') : ''));
|
|
413
534
|
}
|
|
414
535
|
done.add(pkg);
|
|
415
536
|
packagesLeft--;
|
|
@@ -425,7 +546,7 @@ export function buildAll(options) {
|
|
|
425
546
|
}
|
|
426
547
|
})
|
|
427
548
|
.catch(({ error, stdout, stderr }) => {
|
|
428
|
-
|
|
549
|
+
logError(chalk.red('Failed to build ' + pkg.packageName));
|
|
429
550
|
console.log(stdout);
|
|
430
551
|
process.exit(1);
|
|
431
552
|
// let dependentModules = getDependentP
|
|
@@ -608,7 +729,7 @@ const camelCase = (str) => {
|
|
|
608
729
|
}
|
|
609
730
|
return str;
|
|
610
731
|
};
|
|
611
|
-
export const createOntology = (prefix_1, uriBase_1, ...
|
|
732
|
+
export const createOntology = (prefix_1, uriBase_1, ...args_2) => __awaiter(void 0, [prefix_1, uriBase_1, ...args_2], void 0, function* (prefix, uriBase, basePath = process.cwd()) {
|
|
612
733
|
if (!prefix) {
|
|
613
734
|
console.warn('Please provide a suggested prefix as the first argument');
|
|
614
735
|
return;
|
|
@@ -621,7 +742,7 @@ export const createOntology = (prefix_1, uriBase_1, ...args_1) => __awaiter(void
|
|
|
621
742
|
setVariable('uri_base', uriBase);
|
|
622
743
|
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(prefix);
|
|
623
744
|
//copy ontology accessor file
|
|
624
|
-
log(
|
|
745
|
+
log("Creating files for ontology '" + prefix + "'");
|
|
625
746
|
let targetFile = path.join(targetFolder, hyphenName + '.ts');
|
|
626
747
|
fs.copySync(path.join(dirname__, '..', '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
|
|
627
748
|
//copy data files
|
|
@@ -771,7 +892,7 @@ export const getScriptDir = () => {
|
|
|
771
892
|
// return dirname(import.meta.url).replace('file:/','');
|
|
772
893
|
// }
|
|
773
894
|
};
|
|
774
|
-
export const createShape = (
|
|
895
|
+
export const createShape = (name_2, ...args_3) => __awaiter(void 0, [name_2, ...args_3], void 0, function* (name, basePath = process.cwd()) {
|
|
775
896
|
let sourceFolder = getSourceFolder(basePath);
|
|
776
897
|
let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
|
|
777
898
|
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
|
|
@@ -789,11 +910,11 @@ export const createShape = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...
|
|
|
789
910
|
log(`Added an import of this file from ${chalk.magenta(indexPath)}`);
|
|
790
911
|
}
|
|
791
912
|
});
|
|
792
|
-
export const createSetComponent = (
|
|
913
|
+
export const createSetComponent = (name_3, ...args_4) => __awaiter(void 0, [name_3, ...args_4], void 0, function* (name, basePath = process.cwd()) {
|
|
793
914
|
let targetFolder = ensureFolderExists(basePath, 'src', 'components');
|
|
794
915
|
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
|
|
795
916
|
//copy default shape file
|
|
796
|
-
log(
|
|
917
|
+
log("Creating files for set component '" + name + "'");
|
|
797
918
|
let targetFile = path.join(targetFolder, hyphenName + '.tsx');
|
|
798
919
|
fs.copySync(path.join(getScriptDir(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
|
|
799
920
|
let targetFile2 = path.join(targetFolder, hyphenName + '.scss');
|
|
@@ -803,12 +924,12 @@ export const createSetComponent = (name_1, ...args_1) => __awaiter(void 0, [name
|
|
|
803
924
|
let indexPath = addLineToIndex(`import './components/${hyphenName}.js';`, 'components');
|
|
804
925
|
log(`Created a new set component in ${chalk.magenta(targetFile.replace(basePath, ''))}`, `Created a new stylesheet in ${chalk.magenta(targetFile2.replace(basePath, ''))}`, `Added an import of this file from ${chalk.magenta(indexPath)}`);
|
|
805
926
|
});
|
|
806
|
-
export const createComponent = (
|
|
927
|
+
export const createComponent = (name_4, ...args_5) => __awaiter(void 0, [name_4, ...args_5], void 0, function* (name, basePath = process.cwd()) {
|
|
807
928
|
let sourceFolder = getSourceFolder(basePath);
|
|
808
929
|
let targetFolder = ensureFolderExists(sourceFolder, 'components');
|
|
809
930
|
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
|
|
810
931
|
//copy default shape file
|
|
811
|
-
log(
|
|
932
|
+
log("Creating files for component '" + name + "'");
|
|
812
933
|
let targetFile = path.join(targetFolder, hyphenName + '.tsx');
|
|
813
934
|
fs.copySync(path.join(getScriptDir(), '..', 'defaults', 'component.tsx'), targetFile);
|
|
814
935
|
let targetFile2 = path.join(targetFolder, hyphenName + '.scss');
|
|
@@ -826,7 +947,7 @@ export const createComponent = (name_1, ...args_1) => __awaiter(void 0, [name_1,
|
|
|
826
947
|
//read the source of all ts/tsx files in the src folder
|
|
827
948
|
//if there is an import that imports a lincd package with /src/ in it, then warn
|
|
828
949
|
//if there is an import that imports something from outside the src folder, then warn
|
|
829
|
-
export const checkImports = (...
|
|
950
|
+
export const checkImports = (...args_6) => __awaiter(void 0, [...args_6], void 0, function* (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside the src folder
|
|
830
951
|
invalidImports = new Map()) {
|
|
831
952
|
const dir = fs.readdirSync(sourceFolder);
|
|
832
953
|
// Start checking each file in the source folder
|
|
@@ -885,15 +1006,17 @@ invalidImports = new Map()) {
|
|
|
885
1006
|
invalidImports.forEach((value, key) => {
|
|
886
1007
|
// res += '- '+chalk.blueBright(key.split('/').pop()) + ':\n';
|
|
887
1008
|
value.forEach(({ type, importPath }) => {
|
|
888
|
-
let message = key.split('/').pop() +
|
|
1009
|
+
let message = key.split('/').pop() + " imports from '" + importPath + "'";
|
|
889
1010
|
if (type === 'outside_package') {
|
|
890
1011
|
message += ' which is outside the package source root';
|
|
891
1012
|
}
|
|
892
1013
|
if (type === 'lincd') {
|
|
893
|
-
message +=
|
|
1014
|
+
message +=
|
|
1015
|
+
' which should not contain /src/ or /lib/ in the import path';
|
|
894
1016
|
}
|
|
895
1017
|
if (type === 'missing_extension') {
|
|
896
|
-
message +=
|
|
1018
|
+
message +=
|
|
1019
|
+
' which should end with a file extension. Like .js or .scss';
|
|
897
1020
|
}
|
|
898
1021
|
res += chalk.red(message + '\n');
|
|
899
1022
|
});
|
|
@@ -930,7 +1053,7 @@ export const depCheckStaged = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
930
1053
|
});
|
|
931
1054
|
});
|
|
932
1055
|
});
|
|
933
|
-
export const depCheck = (...
|
|
1056
|
+
export const depCheck = (...args_7) => __awaiter(void 0, [...args_7], void 0, function* (packagePath = process.cwd()) {
|
|
934
1057
|
return new Promise((resolve, reject) => {
|
|
935
1058
|
depcheck(packagePath, {}, (results) => {
|
|
936
1059
|
if (results.missing) {
|
|
@@ -950,13 +1073,16 @@ export const depCheck = (...args_1) => __awaiter(void 0, [...args_1], void 0, fu
|
|
|
950
1073
|
if (missingLincdPackages.length > 0) {
|
|
951
1074
|
reject(chalk.red(packagePath.split('/').pop() +
|
|
952
1075
|
'\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
|
|
953
|
-
missingLincdPackages
|
|
1076
|
+
missingLincdPackages
|
|
1077
|
+
.map((missedKey) => {
|
|
954
1078
|
const files = results.missing[missedKey];
|
|
955
1079
|
return `${missedKey} (${files.length} files: ${files.join(', ')})`;
|
|
956
|
-
})
|
|
1080
|
+
})
|
|
1081
|
+
.join(',\n- ')));
|
|
957
1082
|
}
|
|
958
1083
|
else if (missing.length > 0) {
|
|
959
|
-
resolve(chalk.redBright('warning: ' +
|
|
1084
|
+
resolve(chalk.redBright('warning: ' +
|
|
1085
|
+
packagePath.split('/').pop() +
|
|
960
1086
|
' is missing dependencies:\n - ' +
|
|
961
1087
|
missing.join('\n - ')));
|
|
962
1088
|
}
|
|
@@ -1025,7 +1151,8 @@ export const runMethod = (packageName, method, options) => __awaiter(void 0, voi
|
|
|
1025
1151
|
if (options.spawn) {
|
|
1026
1152
|
let lincdConfig = (yield import(path.join(process.cwd(), 'lincd.config.js'))).default;
|
|
1027
1153
|
//@ts-ignore
|
|
1028
|
-
const ServerClass = (yield import('lincd-server/shapes/LincdServer'))
|
|
1154
|
+
const ServerClass = (yield import('lincd-server/shapes/LincdServer'))
|
|
1155
|
+
.LincdServer;
|
|
1029
1156
|
yield import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
|
|
1030
1157
|
let server = new ServerClass(Object.assign({ loadAppComponent: () => __awaiter(void 0, void 0, void 0, function* () { return (yield import(path.join(process.cwd(), 'src', 'App'))).default; }) }, lincdConfig));
|
|
1031
1158
|
//init the server
|
|
@@ -1055,7 +1182,9 @@ export const runMethod = (packageName, method, options) => __awaiter(void 0, voi
|
|
|
1055
1182
|
},
|
|
1056
1183
|
};
|
|
1057
1184
|
//TODO; allow sending args
|
|
1058
|
-
server
|
|
1185
|
+
server
|
|
1186
|
+
.callBackendMethod(packageName, method, [], request, response)
|
|
1187
|
+
.then(() => {
|
|
1059
1188
|
console.log('Done');
|
|
1060
1189
|
process.exit();
|
|
1061
1190
|
});
|
|
@@ -1070,17 +1199,21 @@ export const runMethod = (packageName, method, options) => __awaiter(void 0, voi
|
|
|
1070
1199
|
headers: {
|
|
1071
1200
|
'Content-Type': 'application/json',
|
|
1072
1201
|
},
|
|
1073
|
-
})
|
|
1202
|
+
})
|
|
1203
|
+
.then((response) => {
|
|
1074
1204
|
if (!response.ok) {
|
|
1075
1205
|
throw new Error('Network response was not ok');
|
|
1076
1206
|
}
|
|
1077
1207
|
return response.json();
|
|
1078
|
-
})
|
|
1208
|
+
})
|
|
1209
|
+
.then((data) => {
|
|
1079
1210
|
console.log('Response data:', data);
|
|
1080
1211
|
process.exit();
|
|
1081
|
-
})
|
|
1212
|
+
})
|
|
1213
|
+
.catch((error) => {
|
|
1082
1214
|
var _a;
|
|
1083
|
-
if (error.code === 'ECONNREFUSED' ||
|
|
1215
|
+
if (error.code === 'ECONNREFUSED' ||
|
|
1216
|
+
((_a = error.cause) === null || _a === void 0 ? void 0 : _a.code) === 'ECONNREFUSED') {
|
|
1084
1217
|
console.error(chalk.red('Could not connect to the backend server. Is it running?'));
|
|
1085
1218
|
console.error(`Make sure you ${chalk.magenta('run "yarn start" in a separate process')} before calling this method.`);
|
|
1086
1219
|
}
|
|
@@ -1091,9 +1224,10 @@ export const runMethod = (packageName, method, options) => __awaiter(void 0, voi
|
|
|
1091
1224
|
});
|
|
1092
1225
|
}
|
|
1093
1226
|
});
|
|
1094
|
-
export const startServer = (...
|
|
1227
|
+
export const startServer = (...args_8) => __awaiter(void 0, [...args_8], void 0, function* (initOnly = false, ServerClass = null) {
|
|
1095
1228
|
yield ensureEnvironmentLoaded();
|
|
1096
|
-
let lincdConfig = (yield import(path.join(process.cwd(), 'lincd.config.js')))
|
|
1229
|
+
let lincdConfig = (yield import(path.join(process.cwd(), 'lincd.config.js')))
|
|
1230
|
+
.default;
|
|
1097
1231
|
// function scssLoadcall(source, filename) {
|
|
1098
1232
|
// return 'console.log("SCSS CALL: ' + filename + '");\n' + source;
|
|
1099
1233
|
// process.exit();
|
|
@@ -1111,10 +1245,12 @@ export const startServer = (...args_1) => __awaiter(void 0, [...args_1], void 0,
|
|
|
1111
1245
|
yield import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
|
|
1112
1246
|
let appPromise;
|
|
1113
1247
|
if (process.env.NODE_ENV !== 'development') {
|
|
1114
|
-
appPromise = (yield import(path.join(process.cwd(), 'lib', 'App.js')))
|
|
1248
|
+
appPromise = (yield import(path.join(process.cwd(), 'lib', 'App.js')))
|
|
1249
|
+
.default;
|
|
1115
1250
|
}
|
|
1116
1251
|
else {
|
|
1117
|
-
appPromise = (yield import(path.join(process.cwd(), 'src', 'App.
|
|
1252
|
+
appPromise = (yield import(path.join(process.cwd(), 'src', 'App.tsx')))
|
|
1253
|
+
.default;
|
|
1118
1254
|
}
|
|
1119
1255
|
let server = new ServerClass(Object.assign({ loadAppComponent: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1120
1256
|
return appPromise;
|
|
@@ -1174,7 +1310,8 @@ export const buildFrontend = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
1174
1310
|
}).then(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1175
1311
|
// make sure environment is not development for storage config
|
|
1176
1312
|
// and if we want to upload to storage, we need set S3_BUCKET_ENDPOINT
|
|
1177
|
-
if (process.env.NODE_ENV === 'development' ||
|
|
1313
|
+
if (process.env.NODE_ENV === 'development' ||
|
|
1314
|
+
!process.env.S3_BUCKET_ENDPOINT) {
|
|
1178
1315
|
console.warn('Upload build to storage skip in development environment or S3_BUCKET_ENDPOINT is not set');
|
|
1179
1316
|
return;
|
|
1180
1317
|
// process.exit();
|
|
@@ -1211,9 +1348,11 @@ export const buildFrontend = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
1211
1348
|
// example: /Users/username/project/www/index.html -> /project/www/index.html
|
|
1212
1349
|
const pathname = filePath.replace(pathDir, `/${rootDirectory}`);
|
|
1213
1350
|
// upload file to storage
|
|
1214
|
-
yield LinkedFileStorage.saveFile(pathname, fileContent)
|
|
1351
|
+
yield LinkedFileStorage.saveFile(pathname, fileContent)
|
|
1352
|
+
.then(() => {
|
|
1215
1353
|
clearSpinner.text = `${counter++}/${files.length}: - Published ${pathname} `;
|
|
1216
|
-
})
|
|
1354
|
+
})
|
|
1355
|
+
.catch(console.error);
|
|
1217
1356
|
}));
|
|
1218
1357
|
const urls = yield Promise.all(uploads);
|
|
1219
1358
|
clearSpinner.succeed(`${urls.length} files uploaded to storage`);
|
|
@@ -1289,7 +1428,9 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
1289
1428
|
const tsConfigCJS = path.join(dirname, '../../defaults/package', 'tsconfig-cjs.json');
|
|
1290
1429
|
const tsConfigESM = path.join(dirname, '../../defaults/package', 'tsconfig-esm.json');
|
|
1291
1430
|
const typesFile = path.join(dirname, '../../defaults/package/src', 'types.d.ts');
|
|
1292
|
-
const tsConfigTemplate = yield fs
|
|
1431
|
+
const tsConfigTemplate = yield fs
|
|
1432
|
+
.readJson(path.join(dirname, '../../defaults/package', 'tsconfig.json'))
|
|
1433
|
+
.catch((err) => {
|
|
1293
1434
|
console.log(err);
|
|
1294
1435
|
});
|
|
1295
1436
|
runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
|
|
@@ -1404,7 +1545,9 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
1404
1545
|
// }
|
|
1405
1546
|
// })
|
|
1406
1547
|
// });
|
|
1407
|
-
files
|
|
1548
|
+
files
|
|
1549
|
+
.filter((f) => f.match(/\.(scss\.json|css\.json)$/))
|
|
1550
|
+
.forEach((cssJsonFile) => {
|
|
1408
1551
|
console.log('Removing ' + cssJsonFile);
|
|
1409
1552
|
fs.unlinkSync(cssJsonFile);
|
|
1410
1553
|
});
|
|
@@ -1422,7 +1565,7 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
1422
1565
|
// })
|
|
1423
1566
|
// });
|
|
1424
1567
|
});
|
|
1425
|
-
export const createPackage = (
|
|
1568
|
+
export const createPackage = (name_5, uriBase_2, ...args_9) => __awaiter(void 0, [name_5, uriBase_2, ...args_9], void 0, function* (name, uriBase, basePath = process.cwd()) {
|
|
1426
1569
|
if (!name) {
|
|
1427
1570
|
console.warn('Please provide a name as the first argument');
|
|
1428
1571
|
return;
|
|
@@ -1453,7 +1596,7 @@ export const createPackage = (name_1, uriBase_1, ...args_1) => __awaiter(void 0,
|
|
|
1453
1596
|
//extra variable for clarity (will be same as 'name')
|
|
1454
1597
|
setVariable('output_file_name', name);
|
|
1455
1598
|
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(cleanPackageName);
|
|
1456
|
-
log(
|
|
1599
|
+
log("Creating new LINCD package '" + name + "'");
|
|
1457
1600
|
fs.copySync(path.join(getScriptDir(), '..', '..', 'defaults', 'package'), targetFolder);
|
|
1458
1601
|
//replace variables in some of the copied files
|
|
1459
1602
|
yield Promise.all([
|
|
@@ -1555,7 +1698,7 @@ export const register = function (registryURL) {
|
|
|
1555
1698
|
console.warn(chalk.red('Warning:') + ' not found: ' + process.cwd() + '/package.json');
|
|
1556
1699
|
}
|
|
1557
1700
|
};
|
|
1558
|
-
export const buildPackage = (target_1, target2_1, ...
|
|
1701
|
+
export const buildPackage = (target_1, target2_1, ...args_10) => __awaiter(void 0, [target_1, target2_1, ...args_10], void 0, function* (target, target2, packagePath = process.cwd(), logResults = true) {
|
|
1559
1702
|
let spinner;
|
|
1560
1703
|
if (logResults) {
|
|
1561
1704
|
//TODO: replace with listr so we can show multiple processes at once
|
|
@@ -1574,7 +1717,7 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
|
|
|
1574
1717
|
spinner.text = step.name;
|
|
1575
1718
|
spinner.start();
|
|
1576
1719
|
}
|
|
1577
|
-
return step.apply().then(stepResult => {
|
|
1720
|
+
return step.apply().then((stepResult) => {
|
|
1578
1721
|
//if a build step returns a string,
|
|
1579
1722
|
//a warning is shown but the build is still successful with warnings
|
|
1580
1723
|
if (typeof stepResult === 'string') {
|
|
@@ -1623,26 +1766,29 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
|
|
|
1623
1766
|
name: 'Copying files to lib folder',
|
|
1624
1767
|
apply: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1625
1768
|
const files = yield glob(packagePath + '/src/**/*.{json,d.ts,css,scss}');
|
|
1626
|
-
return Promise.all(files.map((
|
|
1769
|
+
return Promise.all(files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1627
1770
|
try {
|
|
1628
|
-
yield fs.copy(file, packagePath +
|
|
1629
|
-
|
|
1771
|
+
yield fs.copy(file, packagePath +
|
|
1772
|
+
'/lib/esm/' +
|
|
1773
|
+
file.replace(packagePath + '/src/', ''));
|
|
1774
|
+
yield fs.copy(file, packagePath +
|
|
1775
|
+
'/lib/cjs/' +
|
|
1776
|
+
file.replace(packagePath + '/src/', ''));
|
|
1630
1777
|
return true;
|
|
1631
1778
|
}
|
|
1632
1779
|
catch (err) {
|
|
1633
1780
|
console.warn(err);
|
|
1634
1781
|
return false;
|
|
1635
1782
|
}
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
return allResults.every(r => r === true);
|
|
1783
|
+
}))).then((allResults) => {
|
|
1784
|
+
return allResults.every((r) => r === true);
|
|
1639
1785
|
});
|
|
1640
1786
|
}),
|
|
1641
1787
|
});
|
|
1642
1788
|
buildStep({
|
|
1643
1789
|
name: 'Dual package support',
|
|
1644
1790
|
apply: () => {
|
|
1645
|
-
return execPromise('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then(res => {
|
|
1791
|
+
return execPromise('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
|
|
1646
1792
|
return res === '';
|
|
1647
1793
|
});
|
|
1648
1794
|
},
|
|
@@ -1657,8 +1803,12 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
|
|
|
1657
1803
|
name: 'Checking dependencies',
|
|
1658
1804
|
apply: () => depCheck(packagePath),
|
|
1659
1805
|
});
|
|
1660
|
-
let success = yield buildProcess.catch(err => {
|
|
1661
|
-
let msg = typeof err === 'string' || err instanceof Error
|
|
1806
|
+
let success = yield buildProcess.catch((err) => {
|
|
1807
|
+
let msg = typeof err === 'string' || err instanceof Error
|
|
1808
|
+
? err.toString()
|
|
1809
|
+
: err.error && !err.error.toString().includes('Command failed:')
|
|
1810
|
+
? err.error
|
|
1811
|
+
: err.stdout + '\n' + err.stderr;
|
|
1662
1812
|
if (logResults) {
|
|
1663
1813
|
spinner.stopAndPersist({
|
|
1664
1814
|
symbol: chalk.red('✖'),
|
|
@@ -1676,19 +1826,23 @@ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0
|
|
|
1676
1826
|
if (logResults) {
|
|
1677
1827
|
spinner.stopAndPersist({
|
|
1678
1828
|
symbol: chalk.greenBright('✔'),
|
|
1679
|
-
text: success === true
|
|
1829
|
+
text: success === true
|
|
1830
|
+
? 'Build successful'
|
|
1831
|
+
: 'Build successful with warnings',
|
|
1680
1832
|
});
|
|
1681
1833
|
}
|
|
1682
1834
|
}
|
|
1683
1835
|
else {
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1836
|
+
if (logResults) {
|
|
1837
|
+
spinner.stopAndPersist({
|
|
1838
|
+
symbol: chalk.red('✖'),
|
|
1839
|
+
text: 'Build failed',
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1688
1842
|
}
|
|
1689
1843
|
return success;
|
|
1690
1844
|
});
|
|
1691
|
-
export const compilePackage = (...
|
|
1845
|
+
export const compilePackage = (...args_11) => __awaiter(void 0, [...args_11], void 0, function* (packagePath = process.cwd()) {
|
|
1692
1846
|
//echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
|
|
1693
1847
|
// let cjsConfig = fs.existsSync(path.join(packagePath,'tsconfig-cjs.json'));
|
|
1694
1848
|
// let esmConfig = fs.existsSync(path.join(packagePath,'tsconfig-esm.json'));
|
|
@@ -1714,18 +1868,20 @@ export const compilePackage = (...args_1) => __awaiter(void 0, [...args_1], void
|
|
|
1714
1868
|
yield compilePackageESM(packagePath);
|
|
1715
1869
|
yield compilePackageCJS(packagePath);
|
|
1716
1870
|
});
|
|
1717
|
-
export const compilePackageESM = (...
|
|
1871
|
+
export const compilePackageESM = (...args_12) => __awaiter(void 0, [...args_12], void 0, function* (packagePath = process.cwd()) {
|
|
1718
1872
|
//echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
|
|
1719
1873
|
let compileCommand = `yarn exec tsc -p tsconfig-esm.json`;
|
|
1720
|
-
return execPromise(compileCommand, false, false, { cwd: packagePath }).then(res => {
|
|
1874
|
+
return execPromise(compileCommand, false, false, { cwd: packagePath }).then((res) => {
|
|
1721
1875
|
return res === '';
|
|
1722
1876
|
});
|
|
1723
1877
|
});
|
|
1724
|
-
export const compilePackageCJS = (...
|
|
1878
|
+
export const compilePackageCJS = (...args_13) => __awaiter(void 0, [...args_13], void 0, function* (packagePath = process.cwd()) {
|
|
1725
1879
|
let compileCommand = `yarn exec tsc -p tsconfig-cjs.json`;
|
|
1726
|
-
return execPromise(compileCommand, false, false, { cwd: packagePath })
|
|
1880
|
+
return execPromise(compileCommand, false, false, { cwd: packagePath })
|
|
1881
|
+
.then((res) => {
|
|
1727
1882
|
return res === '';
|
|
1728
|
-
})
|
|
1883
|
+
})
|
|
1884
|
+
.catch((err) => {
|
|
1729
1885
|
return {
|
|
1730
1886
|
error: err.stdout,
|
|
1731
1887
|
};
|
|
@@ -1842,7 +1998,7 @@ export var publishUpdated = function (test = false) {
|
|
|
1842
1998
|
}))
|
|
1843
1999
|
.catch(({ error, stdout, stderr }) => {
|
|
1844
2000
|
if (error) {
|
|
1845
|
-
console.
|
|
2001
|
+
console.error(error.message);
|
|
1846
2002
|
}
|
|
1847
2003
|
if (stdout) {
|
|
1848
2004
|
console.log(stderr);
|
|
@@ -1920,7 +2076,7 @@ export var publishPackage = function (pkg, test, info, publishVersion) {
|
|
|
1920
2076
|
.then((res) => {
|
|
1921
2077
|
if (res.indexOf('Aborted due to warnings') !== -1 ||
|
|
1922
2078
|
res.indexOf('Could not publish') !== -1 ||
|
|
1923
|
-
res.indexOf(
|
|
2079
|
+
res.indexOf("Couldn't publish") !== -1) {
|
|
1924
2080
|
console.log(res);
|
|
1925
2081
|
return chalk.red(pkg.packageName + ' failed\n');
|
|
1926
2082
|
}
|
|
@@ -1933,7 +2089,7 @@ export var publishPackage = function (pkg, test, info, publishVersion) {
|
|
|
1933
2089
|
chalk.magenta(publishVersion));
|
|
1934
2090
|
})
|
|
1935
2091
|
.catch(({ error, stdout, stderr }) => {
|
|
1936
|
-
|
|
2092
|
+
logError('Failed to publish: ' + error.message);
|
|
1937
2093
|
return chalk.red(pkg.packageName + ' failed to publish');
|
|
1938
2094
|
});
|
|
1939
2095
|
});
|
|
@@ -1995,42 +2151,31 @@ export var buildUpdated = function (back_1, target_1, target2_1) {
|
|
|
1995
2151
|
return chalk.blue(pkg.packageName + ' should be build');
|
|
1996
2152
|
}
|
|
1997
2153
|
log('Building ' + pkg.packageName);
|
|
1998
|
-
|
|
1999
|
-
return execPromise('cd ' +
|
|
2000
|
-
pkg.path +
|
|
2001
|
-
' && yarn build' +
|
|
2002
|
-
(target ? ' ' + target : '') +
|
|
2003
|
-
(target2 ? ' ' + target2 : ''))
|
|
2154
|
+
return buildPackage(null, null, path.join(process.cwd(), pkg.path), false)
|
|
2004
2155
|
.then((res) => {
|
|
2005
|
-
|
|
2156
|
+
//empty string or true is success
|
|
2157
|
+
//false is success with warnings
|
|
2158
|
+
//any other string is the build error text
|
|
2159
|
+
//undefined result means it failed
|
|
2160
|
+
if (typeof res === 'undefined') {
|
|
2161
|
+
logError('Failed to build ' + pkg.packageName);
|
|
2162
|
+
process.exit(1);
|
|
2163
|
+
}
|
|
2164
|
+
else {
|
|
2006
2165
|
debugInfo(chalk.green(pkg.packageName + ' successfully built'));
|
|
2007
2166
|
return chalk.green(pkg.packageName + ' built');
|
|
2008
2167
|
}
|
|
2009
|
-
else if (typeof res === 'string') {
|
|
2010
|
-
warn(chalk.red('Failed to build ' + pkg.packageName));
|
|
2011
|
-
console.log(res);
|
|
2012
|
-
process.exit(1);
|
|
2013
|
-
}
|
|
2014
2168
|
})
|
|
2015
|
-
.catch((
|
|
2016
|
-
|
|
2017
|
-
console.
|
|
2169
|
+
.catch((err) => {
|
|
2170
|
+
logError('Failed to build ' + pkg.packageName);
|
|
2171
|
+
console.error(err);
|
|
2018
2172
|
process.exit(1);
|
|
2019
|
-
// let dependentModules = getDependentPackages(dependencies, pkg);
|
|
2020
|
-
// if (dependentModules.length > 0) {
|
|
2021
|
-
// // printBuildResults(failedModules, done);
|
|
2022
|
-
// warn(chalk.red(pkg.packageName + ' build failed'));
|
|
2023
|
-
// warn(
|
|
2024
|
-
// 'Stopping build-updated process because ' +
|
|
2025
|
-
// dependentModules.length +
|
|
2026
|
-
// ' other packages depend on this package.\n',
|
|
2027
|
-
// ); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
2028
|
-
// }
|
|
2029
2173
|
});
|
|
2030
2174
|
}
|
|
2031
2175
|
});
|
|
2032
|
-
}, (results) => {
|
|
2176
|
+
}, (dependencies, results) => {
|
|
2033
2177
|
if (results.length) {
|
|
2178
|
+
log(chalk.green('Changed packages have been rebuilt'));
|
|
2034
2179
|
log('Summary:');
|
|
2035
2180
|
log(results.join('\n'));
|
|
2036
2181
|
}
|
|
@@ -2070,16 +2215,15 @@ export var executeCommandForEachPackage = function (packages, command, filterMet
|
|
|
2070
2215
|
}
|
|
2071
2216
|
let seen = false;
|
|
2072
2217
|
packages = packages.filter((pkg) => {
|
|
2073
|
-
if (!seen &&
|
|
2074
|
-
pkg.packageName.includes(startFrom)) {
|
|
2218
|
+
if (!seen && pkg.packageName.includes(startFrom)) {
|
|
2075
2219
|
seen = true;
|
|
2076
2220
|
}
|
|
2077
2221
|
return seen;
|
|
2078
2222
|
});
|
|
2079
2223
|
}
|
|
2080
|
-
log(
|
|
2224
|
+
log("Executing '" +
|
|
2081
2225
|
chalk.blueBright(command) +
|
|
2082
|
-
'
|
|
2226
|
+
"' on packages " +
|
|
2083
2227
|
chalk.magenta(packages.map((m) => m.packageName).join(', ')));
|
|
2084
2228
|
var p = Promise.resolve(true);
|
|
2085
2229
|
packages.forEach((pkg) => {
|
|
@@ -2162,11 +2306,11 @@ export var executeCommandForPackage = function (packageName, command) {
|
|
|
2162
2306
|
let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
|
|
2163
2307
|
modDetails.packageName.indexOf(packageName) !== -1);
|
|
2164
2308
|
if (packageDetails) {
|
|
2165
|
-
log(
|
|
2309
|
+
log("Executing 'cd " +
|
|
2166
2310
|
packageDetails.path +
|
|
2167
2311
|
' && yarn lincd' +
|
|
2168
2312
|
(command ? ' ' + command : '') +
|
|
2169
|
-
'
|
|
2313
|
+
"'");
|
|
2170
2314
|
spawnChild(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', // Windows quirk
|
|
2171
2315
|
['lincd', command || null], {
|
|
2172
2316
|
cwd: packageDetails.path,
|
|
@@ -2174,7 +2318,7 @@ export var executeCommandForPackage = function (packageName, command) {
|
|
|
2174
2318
|
});
|
|
2175
2319
|
}
|
|
2176
2320
|
else {
|
|
2177
|
-
warn(
|
|
2321
|
+
warn("Could not find a pkg who's name (partially) matched " +
|
|
2178
2322
|
chalk.cyan(packageName));
|
|
2179
2323
|
}
|
|
2180
2324
|
};
|