lincd-cli 1.1.11 → 1.2.1
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/.eslintignore +3 -1
- package/defaults/app-with-backend/lincd.config.js +1 -3
- package/defaults/app-with-backend/package.json +11 -21
- package/defaults/app-with-backend/scripts/storage-config.js +6 -6
- package/defaults/app-with-backend/src/App.module.css +17 -0
- package/defaults/app-with-backend/src/App.tsx +11 -15
- package/defaults/app-with-backend/src/backend.ts +8 -0
- package/defaults/app-with-backend/src/components/Error.tsx +2 -5
- package/defaults/app-with-backend/src/components/Spinner.tsx +3 -3
- package/defaults/app-with-backend/src/config-frontend.ts +6 -6
- package/defaults/app-with-backend/src/index.tsx +1 -0
- package/defaults/app-with-backend/src/layout/DefaultLayout.module.css +12 -0
- package/defaults/app-with-backend/src/layout/DefaultLayout.tsx +3 -4
- package/defaults/app-with-backend/src/layout/Header.module.css +25 -0
- package/defaults/app-with-backend/src/layout/Header.tsx +10 -6
- package/defaults/app-with-backend/src/package.ts +1 -3
- package/defaults/app-with-backend/src/pages/Home.tsx +2 -3
- package/defaults/app-with-backend/src/routes.tsx +8 -7
- package/defaults/app-with-backend/src/theme.css +100 -0
- package/defaults/app-with-backend/tsconfig.json +8 -5
- 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} +779 -322
- package/lib/cjs/cli-methods.js.map +1 -0
- package/lib/cjs/cli.js +208 -0
- package/lib/cjs/cli.js.map +1 -0
- package/lib/cjs/config-grunt.cjs +276 -0
- package/lib/cjs/config-grunt.cjs.map +1 -0
- package/lib/cjs/config-webpack-app.js +495 -0
- package/lib/cjs/config-webpack-app.js.map +1 -0
- package/lib/cjs/config-webpack.js +444 -0
- package/lib/cjs/config-webpack.js.map +1 -0
- package/lib/{index.js → cjs/index.js} +5 -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 +86 -0
- package/lib/cjs/loaders/css-loader.mjs.map +1 -0
- package/lib/cjs/loaders/register.js +11 -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 +141 -0
- package/lib/{plugins → cjs/plugins}/check-imports.js +1 -1
- package/lib/cjs/plugins/check-imports.js.map +1 -0
- package/lib/cjs/plugins/declaration-plugin.js +285 -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/lincd-tailwind-sources.js +32 -0
- package/lib/cjs/plugins/lincd-tailwind-sources.js.map +1 -0
- package/lib/cjs/plugins/watch-run.js.map +1 -0
- package/lib/cjs/tailwind.config.js +18 -0
- package/lib/cjs/tailwind.config.js.map +1 -0
- package/lib/{utils.js → cjs/utils.js} +112 -52
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/cli-methods.js +2045 -0
- package/lib/esm/cli-methods.js.map +1 -0
- package/lib/{cli.js → esm/cli.js} +65 -44
- package/lib/esm/cli.js.map +1 -0
- package/lib/{config-grunt.js → esm/config-grunt.cjs} +15 -16
- package/lib/esm/config-grunt.cjs.map +1 -0
- package/lib/esm/config-webpack-app.js +460 -0
- package/lib/esm/config-webpack-app.js.map +1 -0
- package/lib/{config-webpack.js → esm/config-webpack.js} +37 -50
- package/lib/esm/config-webpack.js.map +1 -0
- package/lib/esm/index.js +10 -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 +86 -0
- package/lib/esm/loaders/css-loader.mjs.map +1 -0
- package/lib/esm/loaders/register.js +9 -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 +141 -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/lincd-tailwind-sources.js +27 -0
- package/lib/esm/plugins/lincd-tailwind-sources.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/tailwind.config.js +13 -0
- package/lib/esm/tailwind.config.js.map +1 -0
- package/lib/esm/utils.js +521 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib-template/cjs/package.json +3 -0
- package/lib-template/esm/package.json +3 -0
- package/package.json +64 -24
- package/tsconfig-cjs.json +9 -0
- package/tsconfig-esm.json +10 -0
- package/defaults/app-with-backend/babel.config.js +0 -4
- package/defaults/app-with-backend/src/App.scss +0 -6
- package/defaults/app-with-backend/src/App.scss.json +0 -1
- package/defaults/app-with-backend/src/components/Error.scss.json +0 -1
- package/defaults/app-with-backend/src/components/Spinner.scss.json +0 -1
- package/defaults/app-with-backend/src/layout/DefaultLayout.scss +0 -6
- package/defaults/app-with-backend/src/layout/DefaultLayout.scss.json +0 -1
- package/defaults/app-with-backend/src/layout/Header.scss +0 -10
- package/defaults/app-with-backend/src/layout/Header.scss.json +0 -1
- package/defaults/app-with-backend/src/pages/Home.scss.json +0 -1
- package/defaults/app-with-backend/src/scss/global-overwrites.scss +0 -11
- package/defaults/app-with-backend/src/scss/variables.scss +0 -23
- 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/defaults/app-with-backend/{web → public}/favicon-144x144.png +0 -0
- /package/defaults/app-with-backend/{web → public}/favicon-57x57.png +0 -0
- /package/defaults/app-with-backend/{web → public}/favicon-72x72.png +0 -0
- /package/defaults/app-with-backend/{web → public}/favicon.ico +0 -0
- /package/defaults/app-with-backend/src/components/{Error.scss → Error.module.css} +0 -0
- /package/defaults/app-with-backend/src/components/{Spinner.scss → Spinner.module.css} +0 -0
- /package/defaults/app-with-backend/src/pages/{Home.scss → Home.module.css} +0 -0
- /package/{expose-grunt.js → expose-grunt.cjs} +0 -0
- /package/lib/{interfaces.js → cjs/interfaces.js} +0 -0
- /package/lib/{plugins → cjs/plugins}/watch-run.js +0 -0
|
@@ -1,24 +1,66 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
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
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.
|
|
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;
|
|
7
44
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
45
|
const child_process_1 = require("child_process");
|
|
9
46
|
const depcheck_1 = __importDefault(require("depcheck"));
|
|
10
|
-
const
|
|
47
|
+
const get_env_vars_js_1 = require("env-cmd/dist/get-env-vars.js");
|
|
11
48
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
|
-
const path_1 =
|
|
13
|
-
const
|
|
49
|
+
const path_1 = __importStar(require("path"));
|
|
50
|
+
const utils_js_1 = require("./utils.js");
|
|
14
51
|
const fs_1 = require("fs");
|
|
15
52
|
const find_nearest_package_json_1 = require("find-nearest-package-json");
|
|
53
|
+
const LinkedFileStorage_1 = require("lincd/utils/LinkedFileStorage");
|
|
54
|
+
// import pkg from 'lincd/utils/LinkedFileStorage';
|
|
55
|
+
// const { LinkedFileStorage } = pkg;
|
|
16
56
|
// const config = require('lincd-server/site.webpack.config');
|
|
17
|
-
|
|
57
|
+
const glob_1 = require("glob");
|
|
58
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
59
|
+
const staged_git_files_1 = __importDefault(require("staged-git-files"));
|
|
60
|
+
const ora_1 = __importDefault(require("ora"));
|
|
61
|
+
//@ts-ignore
|
|
62
|
+
let dirname__ = typeof __dirname !== 'undefined' ? __dirname : (0, path_1.dirname)(import.meta.url).replace('file:/', '');
|
|
18
63
|
var variables = {};
|
|
19
|
-
var open = require('open');
|
|
20
|
-
var stagedGitFiles = require('staged-git-files');
|
|
21
|
-
const webpack = require('webpack');
|
|
22
64
|
const createApp = async (name, basePath = process.cwd()) => {
|
|
23
65
|
if (!name) {
|
|
24
66
|
console.warn('Please provide a name as the first argument');
|
|
@@ -28,7 +70,7 @@ const createApp = async (name, basePath = process.cwd()) => {
|
|
|
28
70
|
if (!fs_extra_1.default.existsSync(targetFolder)) {
|
|
29
71
|
fs_extra_1.default.mkdirSync(targetFolder);
|
|
30
72
|
}
|
|
31
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
73
|
+
fs_extra_1.default.copySync(path_1.default.join(dirname__, '..', '..', 'defaults', 'app-with-backend'), targetFolder);
|
|
32
74
|
//make sure the data folder exists (even though its empty).. copying empty folders does not work with fs.copySync
|
|
33
75
|
fs_extra_1.default.mkdirSync(path_1.default.join(targetFolder, 'data'), { recursive: true });
|
|
34
76
|
fs_extra_1.default.mkdirSync(path_1.default.join(targetFolder, 'data/uploads/resized'), {
|
|
@@ -37,21 +79,21 @@ const createApp = async (name, basePath = process.cwd()) => {
|
|
|
37
79
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'gitignore.template'), path_1.default.join(targetFolder, '.gitignore'));
|
|
38
80
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, 'yarnrc.yml.template'), path_1.default.join(targetFolder, '.yarnrc.yml'));
|
|
39
81
|
// fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
|
|
40
|
-
log(
|
|
82
|
+
log('Creating new LINCD application \'' + name + '\'');
|
|
41
83
|
//replace variables in some copied files
|
|
42
84
|
await replaceVariablesInFolder(targetFolder);
|
|
43
85
|
let hasYarn = await hasYarnInstalled();
|
|
44
86
|
let installCommand = hasYarn
|
|
45
87
|
? 'export NODE_OPTIONS="--no-network-family-autoselection" && yarn install'
|
|
46
88
|
: 'npm install';
|
|
47
|
-
await (0,
|
|
89
|
+
await (0, utils_js_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
|
|
48
90
|
console.warn('Could not install dependencies or start application');
|
|
49
91
|
});
|
|
50
92
|
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
93
|
};
|
|
52
94
|
exports.createApp = createApp;
|
|
53
95
|
function logHelp() {
|
|
54
|
-
(0,
|
|
96
|
+
(0, utils_js_1.execp)('yarn exec lincd help');
|
|
55
97
|
}
|
|
56
98
|
function log(...messages) {
|
|
57
99
|
messages.forEach((message) => {
|
|
@@ -64,11 +106,10 @@ function progressUpdate(message) {
|
|
|
64
106
|
}
|
|
65
107
|
function warn(...messages) {
|
|
66
108
|
messages.forEach((message) => {
|
|
67
|
-
console.log(chalk_1.default.
|
|
109
|
+
console.log(chalk_1.default.redBright('Warning: ') + message);
|
|
68
110
|
// console.log(chalk.red(message));
|
|
69
111
|
});
|
|
70
112
|
}
|
|
71
|
-
exports.warn = warn;
|
|
72
113
|
function developPackage(target, mode) {
|
|
73
114
|
if (!target)
|
|
74
115
|
target = 'es6';
|
|
@@ -94,7 +135,6 @@ function developPackage(target, mode) {
|
|
|
94
135
|
console.warn('unknown build target. Use es5 or es6');
|
|
95
136
|
}
|
|
96
137
|
}
|
|
97
|
-
exports.developPackage = developPackage;
|
|
98
138
|
function checkWorkspaces(rootPath, workspaces, res) {
|
|
99
139
|
// console.log('checking workspaces at '+rootPath+": "+workspaces.toString());
|
|
100
140
|
if (workspaces.packages) {
|
|
@@ -140,7 +180,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
|
|
|
140
180
|
//get dependencies of each package
|
|
141
181
|
let leastDependentPackage;
|
|
142
182
|
lincdPackages.forEach((pkg) => {
|
|
143
|
-
var pack = (0,
|
|
183
|
+
var pack = (0, utils_js_1.getPackageJSON)(pkg.path);
|
|
144
184
|
if (pack) {
|
|
145
185
|
//get lincd related dependencies and get the actual package details from the package map by removing '@dacore/' from the package name
|
|
146
186
|
let packageDependencies = Object.keys(pack.dependencies)
|
|
@@ -165,9 +205,17 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
|
|
|
165
205
|
let startStack = [leastDependentPackage];
|
|
166
206
|
const runPackage = (runFunction, pck) => {
|
|
167
207
|
return runFunction(pck)
|
|
168
|
-
.catch((
|
|
169
|
-
|
|
170
|
-
|
|
208
|
+
.catch((errorObj) => {
|
|
209
|
+
if (errorObj.error) {
|
|
210
|
+
let { error, stdout, stderr } = errorObj;
|
|
211
|
+
warn('Uncaught exception whilst running parallel function on ' +
|
|
212
|
+
pck.packageName, (error === null || error === void 0 ? void 0 : error.message) ? error.message : error === null || error === void 0 ? void 0 : error.toString());
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
warn('Uncaught exception whilst running parallel function on ' +
|
|
216
|
+
pck.packageName, errorObj === null || errorObj === void 0 ? void 0 : errorObj.toString());
|
|
217
|
+
process.exit();
|
|
218
|
+
}
|
|
171
219
|
// warn(chalk.red(pck.packageName+' failed:'));
|
|
172
220
|
// console.log(stdout);
|
|
173
221
|
})
|
|
@@ -336,10 +384,10 @@ function buildAll(options) {
|
|
|
336
384
|
// let packagesLeft = lincdPackages.size - done.size;
|
|
337
385
|
runOnPackagesGroupedByDependencies(lincdPackages, (packageGroup, dependencies) => {
|
|
338
386
|
if (done.size > 0) {
|
|
339
|
-
(0,
|
|
387
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.magenta('\n-------\nThese packages are next, since all their dependencies have now been build:'));
|
|
340
388
|
// log(stack);
|
|
341
389
|
}
|
|
342
|
-
(0,
|
|
390
|
+
(0, utils_js_1.debugInfo)('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
|
|
343
391
|
return async (pkg) => {
|
|
344
392
|
let command;
|
|
345
393
|
let skipping = false;
|
|
@@ -358,50 +406,119 @@ function buildAll(options) {
|
|
|
358
406
|
}
|
|
359
407
|
//unless told otherwise, build the package
|
|
360
408
|
if (!command) {
|
|
361
|
-
command = (0,
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
|
|
409
|
+
command = (0, exports.buildPackage)(null, null, path_1.default.join(process.cwd(), pkg.path), false);
|
|
410
|
+
// command = execPromise(
|
|
411
|
+
// 'cd ' + pkg.path + ' && yarn exec lincd build',
|
|
412
|
+
// // (target ? ' ' + target : '') +
|
|
413
|
+
// // (target2 ? ' ' + target2 : ''),
|
|
414
|
+
// false,
|
|
415
|
+
// false,
|
|
416
|
+
// {},
|
|
417
|
+
// false,
|
|
418
|
+
// );
|
|
365
419
|
log(chalk_1.default.cyan('Building ' + pkg.packageName));
|
|
366
420
|
process.stdout.write(packagesLeft + ' packages left\r');
|
|
367
421
|
}
|
|
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) {
|
|
422
|
+
return command.then(res => {
|
|
423
|
+
//empty string or true is success
|
|
424
|
+
//false is success with warnings
|
|
425
|
+
//any other string is the build error text
|
|
426
|
+
//undefined result means it failed
|
|
427
|
+
// if (res !== '' && res !== true && res !== false) {
|
|
428
|
+
if (typeof res === 'undefined') {
|
|
429
|
+
failedModules.push(pkg.packageName);
|
|
430
|
+
let dependentModules = getDependentPackages(dependencies, pkg);
|
|
431
|
+
if (dependentModules.length > 0) {
|
|
432
|
+
printBuildResults(failedModules, done);
|
|
433
|
+
console.log('Stopping build process because an error occurred whilst building ' +
|
|
434
|
+
pkg.packageName +
|
|
435
|
+
', which ' +
|
|
436
|
+
dependentModules.length +
|
|
437
|
+
' other packages depend on.'); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
438
|
+
log('Run ' +
|
|
439
|
+
chalk_1.default.greenBright(`lincd build-all --from=${pkg.packageName}`) +
|
|
440
|
+
' to build only the remaining packages'); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
400
441
|
process.exit(1);
|
|
401
442
|
}
|
|
402
443
|
}
|
|
403
|
-
|
|
444
|
+
else {
|
|
445
|
+
if (!skipping) {
|
|
446
|
+
log(chalk_1.default.green('Built ' + pkg.packageName) + (res === false ? chalk_1.default.redBright(' (with warnings)') : ''));
|
|
447
|
+
}
|
|
448
|
+
done.add(pkg);
|
|
449
|
+
packagesLeft--;
|
|
450
|
+
// log(chalk.magenta(packagesLeft + ' packages left'));
|
|
451
|
+
process.stdout.write(packagesLeft + ' packages left\r');
|
|
452
|
+
if (packagesLeft == 0) {
|
|
453
|
+
printBuildResults(failedModules, done);
|
|
454
|
+
if (failedModules.length > 0) {
|
|
455
|
+
process.exit(1);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return res;
|
|
459
|
+
}
|
|
460
|
+
})
|
|
461
|
+
.catch(({ error, stdout, stderr }) => {
|
|
462
|
+
warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
|
|
463
|
+
console.log(stdout);
|
|
464
|
+
process.exit(1);
|
|
465
|
+
// let dependentModules = getDependentP
|
|
404
466
|
});
|
|
467
|
+
//undefined result means it failed
|
|
468
|
+
/*if (typeof res === 'undefined')
|
|
469
|
+
{
|
|
470
|
+
// .catch(({ error,stdout,stderr }) => {
|
|
471
|
+
//this prints out the webpack output, including the build errors
|
|
472
|
+
// warn('Failed to build ' + pkg.packageName);
|
|
473
|
+
// console.log(stdout);
|
|
474
|
+
failedModules.push(pkg.packageName);
|
|
475
|
+
let dependentModules = getDependentPackages(dependencies,pkg);
|
|
476
|
+
if (dependentModules.length > 0)
|
|
477
|
+
{
|
|
478
|
+
printBuildResults(failedModules,done);
|
|
479
|
+
console.log(
|
|
480
|
+
'Stopping build process because an error occurred whilst building ' +
|
|
481
|
+
pkg.packageName +
|
|
482
|
+
', which ' +
|
|
483
|
+
dependentModules.length +
|
|
484
|
+
' other packages depend on.',
|
|
485
|
+
); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
486
|
+
log(
|
|
487
|
+
'Run ' +
|
|
488
|
+
chalk.greenBright(`lincd build-all --from=${pkg.packageName}`) +
|
|
489
|
+
' to build only the remaining packages',
|
|
490
|
+
); //"+dependentModules.map(d => d.packageName).join(", ")));
|
|
491
|
+
process.exit(1);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
else //true is successful build, false is successful but with warnings
|
|
495
|
+
{
|
|
496
|
+
//successful build
|
|
497
|
+
// })
|
|
498
|
+
// .then((res) => {
|
|
499
|
+
if (!skipping)
|
|
500
|
+
{
|
|
501
|
+
log(chalk.green('Built ' + pkg.packageName)+(res === false ? chalk.redBright(' (with warnings)') : ''));
|
|
502
|
+
}
|
|
503
|
+
done.add(pkg);
|
|
504
|
+
|
|
505
|
+
packagesLeft--;
|
|
506
|
+
// log(chalk.magenta(packagesLeft + ' packages left'));
|
|
507
|
+
process.stdout.write(packagesLeft + ' packages left\r');
|
|
508
|
+
if (packagesLeft == 0)
|
|
509
|
+
{
|
|
510
|
+
printBuildResults(failedModules,done);
|
|
511
|
+
if (failedModules.length > 0)
|
|
512
|
+
{
|
|
513
|
+
process.exit(1);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return res;
|
|
518
|
+
}*/
|
|
519
|
+
// }).catch(err => {
|
|
520
|
+
// console.log(err);
|
|
521
|
+
// })
|
|
405
522
|
};
|
|
406
523
|
}, (dependencies) => {
|
|
407
524
|
//if no more packages to build but we never started building...
|
|
@@ -443,7 +560,6 @@ function buildAll(options) {
|
|
|
443
560
|
}
|
|
444
561
|
}, sync);
|
|
445
562
|
}
|
|
446
|
-
exports.buildAll = buildAll;
|
|
447
563
|
function getDependentPackages(dependencies, pkg) {
|
|
448
564
|
let dependentModules = [];
|
|
449
565
|
dependencies.forEach((dModuleDependencies, dModule) => {
|
|
@@ -473,11 +589,11 @@ function getLocalLincdModules(rootPath = './') {
|
|
|
473
589
|
});
|
|
474
590
|
}
|
|
475
591
|
function getLincdPackages(rootPath = process.cwd()) {
|
|
476
|
-
let pack = (0,
|
|
592
|
+
let pack = (0, utils_js_1.getPackageJSON)();
|
|
477
593
|
if (!pack || !pack.workspaces) {
|
|
478
594
|
for (let i = 0; i <= 3; i++) {
|
|
479
595
|
rootPath = path_1.default.join(process.cwd(), ...Array(i).fill('..'));
|
|
480
|
-
pack = (0,
|
|
596
|
+
pack = (0, utils_js_1.getPackageJSON)(rootPath);
|
|
481
597
|
if (pack && pack.workspaces) {
|
|
482
598
|
// log('Found workspace at '+packagePath);
|
|
483
599
|
break;
|
|
@@ -494,7 +610,6 @@ function getLincdPackages(rootPath = process.cwd()) {
|
|
|
494
610
|
checkWorkspaces(rootPath, pack.workspaces, res);
|
|
495
611
|
return res;
|
|
496
612
|
}
|
|
497
|
-
exports.getLincdPackages = getLincdPackages;
|
|
498
613
|
function setVariable(name, replacement) {
|
|
499
614
|
//prepare name for regexp
|
|
500
615
|
name = name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
@@ -540,28 +655,28 @@ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
|
|
|
540
655
|
setVariable('uri_base', uriBase);
|
|
541
656
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(prefix);
|
|
542
657
|
//copy ontology accessor file
|
|
543
|
-
log(
|
|
658
|
+
log('Creating files for ontology \'' + prefix + '\'');
|
|
544
659
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
|
|
545
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
660
|
+
fs_extra_1.default.copySync(path_1.default.join(dirname__, '..', '..', 'defaults', 'package', 'src', 'ontologies', 'example-ontology.ts'), targetFile);
|
|
546
661
|
//copy data files
|
|
547
662
|
let targetDataFile = path_1.default.join(targetFolder, '..', 'data', hyphenName + '.json');
|
|
548
663
|
let targetDataFile2 = path_1.default.join(targetFolder, '..', 'data', hyphenName + '.json.d.ts');
|
|
549
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
550
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
664
|
+
fs_extra_1.default.copySync(path_1.default.join(dirname__, '..', '..', 'defaults', 'package', 'src', 'data', 'example-ontology.json'), targetDataFile);
|
|
665
|
+
fs_extra_1.default.copySync(path_1.default.join(dirname__, '..', '..', 'defaults', 'package', 'src', 'data', 'example-ontology.json.d.ts'), targetDataFile2);
|
|
551
666
|
await replaceVariablesInFiles(targetFile, targetDataFile, targetDataFile2);
|
|
552
667
|
log(`Prepared a new ontology data files in ${chalk_1.default.magenta(targetDataFile.replace(basePath, ''))}`, `And an ontology accessor file in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
|
|
553
668
|
//if this is not a lincd app (but a lincd package instead)
|
|
554
669
|
if (!sourceFolder.includes('frontend')) {
|
|
555
670
|
//then also add an import to index
|
|
556
|
-
let indexPath = addLineToIndex(`import './ontologies/${hyphenName}';`, 'ontologies');
|
|
671
|
+
let indexPath = addLineToIndex(`import './ontologies/${hyphenName}.js';`, 'ontologies');
|
|
557
672
|
log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
558
673
|
}
|
|
559
674
|
};
|
|
560
675
|
exports.createOntology = createOntology;
|
|
561
|
-
const addLineToIndex = function (line, insertMatchString) {
|
|
676
|
+
const addLineToIndex = function (line, insertMatchString, root = process.cwd(), insertAtStart = false) {
|
|
562
677
|
//import ontology in index
|
|
563
678
|
let indexPath = ['index.ts', 'index.tsx']
|
|
564
|
-
.map((f) => path_1.default.join('src', f))
|
|
679
|
+
.map((f) => path_1.default.join(root, 'src', f))
|
|
565
680
|
.find((indexFileName) => {
|
|
566
681
|
return fs_extra_1.default.existsSync(indexFileName);
|
|
567
682
|
});
|
|
@@ -570,8 +685,9 @@ const addLineToIndex = function (line, insertMatchString) {
|
|
|
570
685
|
let lines = indexContents.split(/\n/g);
|
|
571
686
|
let newContents;
|
|
572
687
|
for (var key in lines) {
|
|
688
|
+
//if the match string is found
|
|
573
689
|
if (lines[key].indexOf(insertMatchString) !== -1) {
|
|
574
|
-
//
|
|
690
|
+
//add the new line after this line
|
|
575
691
|
lines[key] += `\n${line}`;
|
|
576
692
|
newContents = lines.join('\n');
|
|
577
693
|
// log("Found at "+key,lines,newContents);
|
|
@@ -579,7 +695,12 @@ const addLineToIndex = function (line, insertMatchString) {
|
|
|
579
695
|
}
|
|
580
696
|
}
|
|
581
697
|
if (!newContents) {
|
|
582
|
-
|
|
698
|
+
if (insertAtStart) {
|
|
699
|
+
newContents = `${line}\n${indexContents}`;
|
|
700
|
+
}
|
|
701
|
+
else {
|
|
702
|
+
newContents = `${indexContents}\n${line}`;
|
|
703
|
+
}
|
|
583
704
|
// log("Added at end",newContents);
|
|
584
705
|
}
|
|
585
706
|
fs_extra_1.default.writeFileSync(indexPath, newContents);
|
|
@@ -593,13 +714,13 @@ const replaceVariablesInFiles = function (...files) {
|
|
|
593
714
|
};
|
|
594
715
|
const replaceVariablesInFolder = function (folder) {
|
|
595
716
|
//get all files in folder, including files that start with a dot
|
|
596
|
-
glob(folder + '/**/*', { dot: true, nodir: true }, function (err, files) {
|
|
717
|
+
glob_1.glob(folder + '/**/*', { dot: true, nodir: true }, async function (err, files) {
|
|
597
718
|
if (err) {
|
|
598
719
|
console.log('Error', err);
|
|
599
720
|
}
|
|
600
721
|
else {
|
|
601
722
|
// console.log(files);
|
|
602
|
-
|
|
723
|
+
await Promise.all(files.map((file) => {
|
|
603
724
|
return replaceVariablesInFile(file);
|
|
604
725
|
}));
|
|
605
726
|
}
|
|
@@ -609,7 +730,7 @@ const replaceVariablesInFilesWithRoot = function (root, ...files) {
|
|
|
609
730
|
return replaceVariablesInFiles(...files.map((f) => path_1.default.join(root, f)));
|
|
610
731
|
};
|
|
611
732
|
const hasYarnInstalled = async function () {
|
|
612
|
-
let version = (await (0,
|
|
733
|
+
let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
|
|
613
734
|
console.log('yarn probably not working');
|
|
614
735
|
return '';
|
|
615
736
|
}));
|
|
@@ -665,6 +786,24 @@ function getSourceFolder(basePath = process.cwd()) {
|
|
|
665
786
|
return path_1.default.join(basePath, 'src');
|
|
666
787
|
}
|
|
667
788
|
}
|
|
789
|
+
/**
|
|
790
|
+
* get __dirname for either ESM/CJS
|
|
791
|
+
*/
|
|
792
|
+
const getScriptDir = () => {
|
|
793
|
+
return dirname__;
|
|
794
|
+
// // @ts-ignore
|
|
795
|
+
// if (typeof __dirname !== 'undefined')
|
|
796
|
+
// {
|
|
797
|
+
// // @ts-ignore
|
|
798
|
+
// return __dirname;
|
|
799
|
+
// }
|
|
800
|
+
// else
|
|
801
|
+
// {
|
|
802
|
+
// // @ts-ignore
|
|
803
|
+
// return dirname(import.meta.url).replace('file:/','');
|
|
804
|
+
// }
|
|
805
|
+
};
|
|
806
|
+
exports.getScriptDir = getScriptDir;
|
|
668
807
|
const createShape = async (name, basePath = process.cwd()) => {
|
|
669
808
|
let sourceFolder = getSourceFolder(basePath);
|
|
670
809
|
let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
|
|
@@ -672,14 +811,14 @@ const createShape = async (name, basePath = process.cwd()) => {
|
|
|
672
811
|
//copy default shape file
|
|
673
812
|
// log("Creating files for shape '" + name + "'");
|
|
674
813
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
|
|
675
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
814
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'shape.ts'), targetFile);
|
|
676
815
|
//replace variables in some of the copied files
|
|
677
816
|
await replaceVariablesInFiles(targetFile);
|
|
678
817
|
log(`Created a new shape class template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
|
|
679
818
|
//if this is NOT a lincd app (but a lincd package)
|
|
680
819
|
let indexPath;
|
|
681
820
|
if (!sourceFolder.includes('frontend')) {
|
|
682
|
-
indexPath = addLineToIndex(`import './shapes/${hyphenName}';`, 'shapes');
|
|
821
|
+
indexPath = addLineToIndex(`import './shapes/${hyphenName}.js';`, 'shapes');
|
|
683
822
|
log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
684
823
|
}
|
|
685
824
|
};
|
|
@@ -688,14 +827,14 @@ const createSetComponent = async (name, basePath = process.cwd()) => {
|
|
|
688
827
|
let targetFolder = ensureFolderExists(basePath, 'src', 'components');
|
|
689
828
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
|
|
690
829
|
//copy default shape file
|
|
691
|
-
log(
|
|
830
|
+
log('Creating files for set component \'' + name + '\'');
|
|
692
831
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
693
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
832
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'set-component.tsx'), targetFile);
|
|
694
833
|
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
695
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
834
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'component.scss'), targetFile2);
|
|
696
835
|
//replace variables in some of the copied files
|
|
697
836
|
await replaceVariablesInFiles(targetFile, targetFile2);
|
|
698
|
-
let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
|
|
837
|
+
let indexPath = addLineToIndex(`import './components/${hyphenName}.js';`, 'components');
|
|
699
838
|
log(`Created a new set component in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`, `Created a new stylesheet in ${chalk_1.default.magenta(targetFile2.replace(basePath, ''))}`, `Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
700
839
|
};
|
|
701
840
|
exports.createSetComponent = createSetComponent;
|
|
@@ -704,26 +843,26 @@ const createComponent = async (name, basePath = process.cwd()) => {
|
|
|
704
843
|
let targetFolder = ensureFolderExists(sourceFolder, 'components');
|
|
705
844
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
|
|
706
845
|
//copy default shape file
|
|
707
|
-
log(
|
|
846
|
+
log('Creating files for component \'' + name + '\'');
|
|
708
847
|
let targetFile = path_1.default.join(targetFolder, hyphenName + '.tsx');
|
|
709
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
848
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.tsx'), targetFile);
|
|
710
849
|
let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
|
|
711
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
850
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', 'defaults', 'component.scss'), targetFile2);
|
|
712
851
|
//replace variables in some of the copied files
|
|
713
852
|
await replaceVariablesInFiles(targetFile, targetFile2);
|
|
714
853
|
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, ''))}`);
|
|
715
854
|
//if this is not a lincd app (but a lincd package instead)
|
|
716
855
|
if (!sourceFolder.includes('frontend')) {
|
|
717
856
|
//then also add an import to index
|
|
718
|
-
let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
|
|
857
|
+
let indexPath = addLineToIndex(`import './components/${hyphenName}.js';`, 'components');
|
|
719
858
|
log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
|
|
720
859
|
}
|
|
721
860
|
};
|
|
722
861
|
exports.createComponent = createComponent;
|
|
723
862
|
//read the source of all ts/tsx files in the src folder
|
|
724
863
|
//if there is an import that imports a lincd package with /src/ in it, then warn
|
|
725
|
-
//if there is an import that imports outside
|
|
726
|
-
const checkImports = async (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside
|
|
864
|
+
//if there is an import that imports something from outside the src folder, then warn
|
|
865
|
+
const checkImports = async (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside the src folder
|
|
727
866
|
invalidImports = new Map()) => {
|
|
728
867
|
const dir = fs_extra_1.default.readdirSync(sourceFolder);
|
|
729
868
|
// Start checking each file in the source folder
|
|
@@ -733,45 +872,81 @@ invalidImports = new Map()) => {
|
|
|
733
872
|
// INFO: For future use - if this part fails, it could be due to user permissions
|
|
734
873
|
// i.e. the program not having access to check the file metadata
|
|
735
874
|
if (!filename.match(/\.tsx?$/)) {
|
|
736
|
-
|
|
737
|
-
|
|
875
|
+
try {
|
|
876
|
+
if ((0, fs_1.statSync)(filename).isDirectory()) {
|
|
877
|
+
await (0, exports.checkImports)(filename, depth + 1, invalidImports);
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
// Ignore all files that aren't one of the following:
|
|
881
|
+
// - .ts
|
|
882
|
+
// - .tsx
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
catch (e) {
|
|
887
|
+
console.log(e);
|
|
738
888
|
}
|
|
739
|
-
// Ignore all files that aren't one of the following:
|
|
740
|
-
// - .ts
|
|
741
|
-
// - .tsx
|
|
742
|
-
continue;
|
|
743
889
|
}
|
|
744
|
-
const allImports = await (0,
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
890
|
+
const allImports = await (0, utils_js_1.getFileImports)(filename);
|
|
891
|
+
if (!invalidImports.has(filename)) {
|
|
892
|
+
invalidImports.set(filename, []);
|
|
893
|
+
}
|
|
894
|
+
allImports.forEach((i) => {
|
|
895
|
+
if ((0, utils_js_1.isImportOutsideOfPackage)(i, depth)) {
|
|
896
|
+
invalidImports.get(filename).push({
|
|
897
|
+
type: 'outside_package',
|
|
898
|
+
importPath: i
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
if ((0, utils_js_1.isInvalidLINCDImport)(i, depth)) {
|
|
902
|
+
invalidImports.get(filename).push({
|
|
903
|
+
type: 'lincd',
|
|
904
|
+
importPath: i
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
if ((0, utils_js_1.isImportWithMissingExtension)(i)) {
|
|
908
|
+
invalidImports.get(filename).push({
|
|
909
|
+
type: 'missing_extension',
|
|
910
|
+
importPath: i
|
|
911
|
+
});
|
|
752
912
|
}
|
|
753
913
|
});
|
|
754
914
|
}
|
|
915
|
+
let res = '';
|
|
916
|
+
//check if invalidImports has any
|
|
917
|
+
let flat = [...invalidImports.values()].flat();
|
|
755
918
|
// All recursion must have finished, display any errors
|
|
756
|
-
if (depth === 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/'));
|
|
919
|
+
if (depth === 0 && flat.length > 0) {
|
|
920
|
+
res += chalk_1.default.red('Invalid imports found.\n');
|
|
760
921
|
invalidImports.forEach((value, key) => {
|
|
761
|
-
|
|
762
|
-
value.forEach((
|
|
922
|
+
// res += '- '+chalk.blueBright(key.split('/').pop()) + ':\n';
|
|
923
|
+
value.forEach(({ type, importPath }) => {
|
|
924
|
+
let message = key.split('/').pop() + ' imports from \'' + importPath + '\'';
|
|
925
|
+
if (type === 'outside_package') {
|
|
926
|
+
message += ' which is outside the package source root';
|
|
927
|
+
}
|
|
928
|
+
if (type === 'lincd') {
|
|
929
|
+
message += ' which should not contain /src/ or /lib/ in the import path';
|
|
930
|
+
}
|
|
931
|
+
if (type === 'missing_extension') {
|
|
932
|
+
message += ' which should end with a file extension. Like .js or .scss';
|
|
933
|
+
}
|
|
934
|
+
res += chalk_1.default.red(message + '\n');
|
|
935
|
+
});
|
|
763
936
|
});
|
|
764
|
-
|
|
937
|
+
throw res;
|
|
938
|
+
// process.exit(1);
|
|
765
939
|
}
|
|
766
940
|
else if (depth === 0 && invalidImports.size === 0) {
|
|
767
|
-
console.info('All imports OK');
|
|
768
|
-
process.exit(0);
|
|
941
|
+
// console.info('All imports OK');
|
|
942
|
+
// process.exit(0);
|
|
943
|
+
return true;
|
|
769
944
|
}
|
|
770
945
|
};
|
|
771
946
|
exports.checkImports = checkImports;
|
|
772
947
|
const depCheckStaged = async () => {
|
|
773
948
|
console.log('Checking dependencies of staged files');
|
|
774
|
-
|
|
949
|
+
(0, staged_git_files_1.default)(async function (err, results) {
|
|
775
950
|
const packages = new Set();
|
|
776
951
|
await Promise.all(results.map(async (file) => {
|
|
777
952
|
// console.log('STAGED: ', file.filename);
|
|
@@ -791,50 +966,54 @@ const depCheckStaged = async () => {
|
|
|
791
966
|
});
|
|
792
967
|
};
|
|
793
968
|
exports.depCheckStaged = depCheckStaged;
|
|
794
|
-
const depCheck = async (
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
return lincdPackage
|
|
969
|
+
const depCheck = async (packagePath = process.cwd()) => {
|
|
970
|
+
return new Promise((resolve, reject) => {
|
|
971
|
+
(0, depcheck_1.default)(packagePath, {}, (results) => {
|
|
972
|
+
if (results.missing) {
|
|
973
|
+
let lincdPackages = getLocalLincdModules();
|
|
974
|
+
let missing = Object.keys(results.missing);
|
|
975
|
+
//filter out missing types, if it builds we're not too concerned about that at the moment?
|
|
976
|
+
//especially things like @types/react, @types/react-dom, @types/node (they are added elsewhere?)
|
|
977
|
+
// missing = missing.filter(m => m.indexOf('@types/') === 0);
|
|
978
|
+
//currently react is not an explicit dependency, but we should add it as a peer dependency
|
|
979
|
+
missing.splice(missing.indexOf('react'), 1);
|
|
980
|
+
let missingLincdPackages = missing.filter((missingDep) => {
|
|
981
|
+
return lincdPackages.some((lincdPackage) => {
|
|
982
|
+
return lincdPackage.packageName === missingDep;
|
|
983
|
+
});
|
|
807
984
|
});
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
985
|
+
//currently just missing LINCD packages cause a hard failure exit code
|
|
986
|
+
if (missingLincdPackages.length > 0) {
|
|
987
|
+
reject(chalk_1.default.red(packagePath.split('/').pop() +
|
|
988
|
+
'\n[ERROR] These LINCD packages are imported but they are not listed in package.json:\n- ' +
|
|
989
|
+
missingLincdPackages.join(',\n- ')));
|
|
990
|
+
}
|
|
991
|
+
else if (missing.length > 0) {
|
|
992
|
+
resolve(chalk_1.default.redBright('warning: ' + packagePath.split('/').pop() +
|
|
993
|
+
' is missing dependencies:\n - ' +
|
|
994
|
+
missing.join('\n - ')));
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
resolve(true);
|
|
998
|
+
}
|
|
820
999
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1000
|
+
// if(Object.keys(results.invalidFiles).length > 0) {
|
|
1001
|
+
// console.warn(chalk.red("Invalid files:\n")+Object.keys(results.invalidFiles).join(",\n"));
|
|
1002
|
+
// }
|
|
1003
|
+
// if(Object.keys(results.invalidDirs).length > 0) {
|
|
1004
|
+
// console.warn(chalk.red("Invalid dirs:\n")+results.invalidDirs.toString());
|
|
1005
|
+
// }
|
|
1006
|
+
// if(results.unused) {
|
|
1007
|
+
// console.warn("Unused dependencies: "+results.missing.join(", "));
|
|
1008
|
+
// }
|
|
1009
|
+
});
|
|
831
1010
|
});
|
|
832
1011
|
};
|
|
833
1012
|
exports.depCheck = depCheck;
|
|
834
1013
|
const ensureEnvironmentLoaded = async () => {
|
|
835
1014
|
if (!process.env.NODE_ENV) {
|
|
836
1015
|
//load env-cmd for development environment
|
|
837
|
-
let { GetEnvVars } = require('env-cmd');
|
|
1016
|
+
let { GetEnvVars } = await Promise.resolve().then(() => __importStar(require('env-cmd')));
|
|
838
1017
|
let envCmdrcPath = path_1.default.join(process.cwd(), '.env-cmdrc.json');
|
|
839
1018
|
if (!fs_extra_1.default.existsSync(envCmdrcPath)) {
|
|
840
1019
|
console.warn('No .env-cmdrc.json found in this folder. Are you running this command from the root of a LINCD app?');
|
|
@@ -878,13 +1057,24 @@ const ensureEnvironmentLoaded = async () => {
|
|
|
878
1057
|
exports.ensureEnvironmentLoaded = ensureEnvironmentLoaded;
|
|
879
1058
|
const startServer = async (initOnly = false, ServerClass = null) => {
|
|
880
1059
|
await (0, exports.ensureEnvironmentLoaded)();
|
|
881
|
-
let lincdConfig =
|
|
1060
|
+
let lincdConfig = (await Promise.resolve(`${path_1.default.join(process.cwd(), 'lincd.config.js')}`).then(s => __importStar(require(s)))).default;
|
|
1061
|
+
// function scssLoadcall(source, filename) {
|
|
1062
|
+
// return 'console.log("SCSS CALL: ' + filename + '");\n' + source;
|
|
1063
|
+
// process.exit();
|
|
1064
|
+
// }
|
|
1065
|
+
// hook.hook('.scss', scssLoadcall);
|
|
1066
|
+
// hook.hook('.css', scssLoadcall);
|
|
1067
|
+
// import.meta.
|
|
1068
|
+
// // hook.hook('*.css', scssLoadcall);
|
|
1069
|
+
// // hook.hook('Body.module.css', scssLoadcall);
|
|
1070
|
+
// hook.hook('.module.css', scssLoadcall);
|
|
882
1071
|
if (!ServerClass) {
|
|
883
|
-
|
|
1072
|
+
//@ts-ignore
|
|
1073
|
+
ServerClass = (await Promise.resolve().then(() => __importStar(require('lincd-server/shapes/LincdServer')))).LincdServer;
|
|
884
1074
|
}
|
|
885
|
-
|
|
1075
|
+
await Promise.resolve(`${path_1.default.join(process.cwd(), 'scripts', 'storage-config.js')}`).then(s => __importStar(require(s)));
|
|
886
1076
|
let server = new ServerClass({
|
|
887
|
-
loadAppComponent: () =>
|
|
1077
|
+
loadAppComponent: async () => (await Promise.resolve(`${path_1.default.join(process.cwd(), 'src', 'App')}`).then(s => __importStar(require(s)))).default,
|
|
888
1078
|
...lincdConfig,
|
|
889
1079
|
});
|
|
890
1080
|
//Important to use slice, because when using clusers, child processes need to be able to read the same arguments
|
|
@@ -900,15 +1090,12 @@ const startServer = async (initOnly = false, ServerClass = null) => {
|
|
|
900
1090
|
exports.startServer = startServer;
|
|
901
1091
|
const buildApp = async () => {
|
|
902
1092
|
await (0, exports.ensureEnvironmentLoaded)();
|
|
903
|
-
const webpackAppConfig = require('./config-webpack-app').
|
|
1093
|
+
const webpackAppConfig = await (await Promise.resolve().then(() => __importStar(require('./config-webpack-app.js')))).getWebpackAppConfig();
|
|
904
1094
|
console.log(chalk_1.default.magenta(`Building ${process.env.NODE_ENV} app bundles`));
|
|
905
1095
|
return new Promise((resolve, reject) => {
|
|
906
|
-
|
|
1096
|
+
(0, webpack_1.default)(webpackAppConfig, async (err, stats) => {
|
|
907
1097
|
if (err) {
|
|
908
1098
|
console.error(err.stack || err);
|
|
909
|
-
if (err.details) {
|
|
910
|
-
console.error(err.details);
|
|
911
|
-
}
|
|
912
1099
|
process.exit(1);
|
|
913
1100
|
}
|
|
914
1101
|
const info = stats.toJson();
|
|
@@ -922,10 +1109,9 @@ const buildApp = async () => {
|
|
|
922
1109
|
console.log(stats.toString({
|
|
923
1110
|
chunks: false,
|
|
924
1111
|
assets: true,
|
|
925
|
-
|
|
1112
|
+
entrypoints: false,
|
|
926
1113
|
modules: false,
|
|
927
1114
|
moduleAssets: false,
|
|
928
|
-
moduleChunks: false,
|
|
929
1115
|
colors: true,
|
|
930
1116
|
}));
|
|
931
1117
|
console.log('App build process finished');
|
|
@@ -939,9 +1125,190 @@ const buildApp = async () => {
|
|
|
939
1125
|
}
|
|
940
1126
|
// process.exit();
|
|
941
1127
|
});
|
|
1128
|
+
}).then(async () => {
|
|
1129
|
+
// make sure environment is not development for storage config
|
|
1130
|
+
// and if we want to upload to storage, we need set S3_BUCKET_ENDPOINT
|
|
1131
|
+
if (process.env.NODE_ENV === 'development' || !process.env.S3_BUCKET_ENDPOINT) {
|
|
1132
|
+
console.warn('Upload build to storage skip in development environment or S3_BUCKET_ENDPOINT is not set');
|
|
1133
|
+
process.exit();
|
|
1134
|
+
}
|
|
1135
|
+
if (process.env.APP_ENV) {
|
|
1136
|
+
console.warn('Not uploading to CDN for app builds');
|
|
1137
|
+
process.exit();
|
|
1138
|
+
}
|
|
1139
|
+
// load the storage config
|
|
1140
|
+
const storageConfig = await Promise.resolve(`${path_1.default.join(process.cwd(), 'scripts', 'storage-config.js')}`).then(s => __importStar(require(s)));
|
|
1141
|
+
// check if LincdFileStorage has a default FileStore
|
|
1142
|
+
// if yes: copy all the files in the build folder over with LincdFileStorage
|
|
1143
|
+
if (LinkedFileStorage_1.LinkedFileStorage.getDefaultStore()) {
|
|
1144
|
+
// get public directory
|
|
1145
|
+
const rootDirectory = 'public';
|
|
1146
|
+
const pathDir = path_1.default.join(process.cwd(), rootDirectory);
|
|
1147
|
+
if (!fs_extra_1.default.existsSync(pathDir)) {
|
|
1148
|
+
console.warn('No public directory found. Please create a public directory in the root of your project');
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
// get all files in the web directory and then upload them to the storage
|
|
1152
|
+
const files = await (0, utils_js_1.getFiles)(pathDir);
|
|
1153
|
+
const uploads = files.map(async (filePath) => {
|
|
1154
|
+
// read file content
|
|
1155
|
+
const fileContent = await fs_extra_1.default.promises.readFile(filePath);
|
|
1156
|
+
// replace pathDir with rootDirectory in filePath to get pathname
|
|
1157
|
+
// example: /Users/username/project/www/index.html -> /project/www/index.html
|
|
1158
|
+
const pathname = filePath.replace(pathDir, `/${rootDirectory}`);
|
|
1159
|
+
// upload file to storage
|
|
1160
|
+
return await LinkedFileStorage_1.LinkedFileStorage.saveFile(pathname, fileContent);
|
|
1161
|
+
});
|
|
1162
|
+
const urls = await Promise.all(uploads);
|
|
1163
|
+
console.log(`${urls.length} files uploaded to storage`);
|
|
1164
|
+
process.exit();
|
|
1165
|
+
}
|
|
942
1166
|
});
|
|
943
1167
|
};
|
|
944
1168
|
exports.buildApp = buildApp;
|
|
1169
|
+
const upgradePackages = async () => {
|
|
1170
|
+
await (0, exports.ensureEnvironmentLoaded)();
|
|
1171
|
+
// let packages = getLincdPackages();
|
|
1172
|
+
// let packages = getLocalLincdModules();
|
|
1173
|
+
let packages = getLocalLincdPackageMap();
|
|
1174
|
+
let dirname = (0, exports.getScriptDir)();
|
|
1175
|
+
const tsConfigCJS = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-cjs.json');
|
|
1176
|
+
const tsConfigESM = path_1.default.join(dirname, '../../defaults/package', 'tsconfig-esm.json');
|
|
1177
|
+
const typesFile = path_1.default.join(dirname, '../../defaults/package/src', 'types.d.ts');
|
|
1178
|
+
const tsConfigTemplate = await fs_extra_1.default.readJson(path_1.default.join(dirname, '../../defaults/package', 'tsconfig.json')).catch(err => {
|
|
1179
|
+
console.log(err);
|
|
1180
|
+
});
|
|
1181
|
+
runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
|
|
1182
|
+
// packageGroup.forEach((pkg) => {
|
|
1183
|
+
// console.log(' Upgrading ' + pkg.packageName);
|
|
1184
|
+
console.log('-----');
|
|
1185
|
+
return async (pkg) => {
|
|
1186
|
+
if (pkg.packageName === 'lincd')
|
|
1187
|
+
return;
|
|
1188
|
+
// await execPromise(`cd ${pkg.path} && yarn upgrade`);
|
|
1189
|
+
console.log('Upgrading ' + pkg.packageName);
|
|
1190
|
+
//
|
|
1191
|
+
// //create a new file src/tsconfig-cjs.json
|
|
1192
|
+
// //copy the contents of tsconfig.json into it
|
|
1193
|
+
// if (!fs.existsSync(path.join(pkg.path,'tsconfig-cjs.json')))
|
|
1194
|
+
// {
|
|
1195
|
+
// await fs.copy(tsConfigCJS,path.join(pkg.path,'tsconfig-cjs.json'));
|
|
1196
|
+
// await fs.copy(tsConfigESM,path.join(pkg.path,'tsconfig-esm.json'));
|
|
1197
|
+
// console.log('Copied new tsconfig to ' + pkg.packageName);
|
|
1198
|
+
// }
|
|
1199
|
+
//
|
|
1200
|
+
// //read tsconfig
|
|
1201
|
+
// await fs.readJson(path.join(pkg.path,'tsconfig.json')).then((tsconfig) => {
|
|
1202
|
+
// let oldCompilerOpts = tsconfig.compilerOptions;
|
|
1203
|
+
// tsconfig.compilerOptions = tsConfigTemplate.compilerOptions;
|
|
1204
|
+
// tsconfig.compilerOptions.types = oldCompilerOpts.types;
|
|
1205
|
+
// tsconfig.compilerOptions.plugins = [{"name": "typescript-plugin-css-modules"}];
|
|
1206
|
+
//
|
|
1207
|
+
// console.log('Upgraded tsconfig for ' + pkg.packageName);
|
|
1208
|
+
// return fs.writeJson(path.join(pkg.path,'tsconfig.json'),tsconfig,{spaces: 2});
|
|
1209
|
+
// });
|
|
1210
|
+
// //import types at the beginning of index.ts
|
|
1211
|
+
// addLineToIndex(`import './types';`,null,pkg.path,true);
|
|
1212
|
+
// //copy over the types file
|
|
1213
|
+
// await fs.copy(typesFile,path.join(pkg.path,'src','types.d.ts'));
|
|
1214
|
+
// await fs.readJson(path.join(pkg.path,'package.json')).then((packageJson) => {
|
|
1215
|
+
// let version = packageJson.version;
|
|
1216
|
+
// let nextVersion;
|
|
1217
|
+
// if (version.split('.').shift() === '0')
|
|
1218
|
+
// {
|
|
1219
|
+
// nextVersion = getNextMajorVersion(version);
|
|
1220
|
+
// }
|
|
1221
|
+
// else
|
|
1222
|
+
// {
|
|
1223
|
+
// nextVersion = getNextMinorVersion(version);
|
|
1224
|
+
// }
|
|
1225
|
+
// console.log('Upgraded version for ' + pkg.packageName + ' to ' + nextVersion);
|
|
1226
|
+
//
|
|
1227
|
+
// packageJson.version = nextVersion;
|
|
1228
|
+
// packageJson.devDependencies['tsconfig-to-dual-package'] = '^1.2.0';
|
|
1229
|
+
// packageJson.devDependencies['typescript-plugin-css-modules'] = '^5.1.0';
|
|
1230
|
+
//
|
|
1231
|
+
// packageJson.main = 'lib/cjs/index.js';
|
|
1232
|
+
// packageJson.module = 'lib/esm/index.js';
|
|
1233
|
+
// packageJson.exports = {
|
|
1234
|
+
// '.': {
|
|
1235
|
+
// 'types': './lib/esm/index.d.ts',
|
|
1236
|
+
// 'import': './lib/esm/index.js',
|
|
1237
|
+
// 'require': './lib/cjs/index.js',
|
|
1238
|
+
// },
|
|
1239
|
+
// './*': {
|
|
1240
|
+
// 'types': './lib/esm/*.d.ts',
|
|
1241
|
+
// 'import': './lib/esm/*.js',
|
|
1242
|
+
// 'require': './lib/cjs/*.js',
|
|
1243
|
+
// },
|
|
1244
|
+
// };
|
|
1245
|
+
// packageJson.typesVersions = {
|
|
1246
|
+
// '*': {
|
|
1247
|
+
// '*': [
|
|
1248
|
+
// 'lib/esm/*',
|
|
1249
|
+
// ],
|
|
1250
|
+
// },
|
|
1251
|
+
// };
|
|
1252
|
+
//
|
|
1253
|
+
// return fs.writeJson(path.join(pkg.path,'package.json'),packageJson,{ spaces: 2 });
|
|
1254
|
+
// });
|
|
1255
|
+
//change .css files and .scss files to .module.css and .module.scss
|
|
1256
|
+
let files = await (0, utils_js_1.getFiles)(path_1.default.join(pkg.path, 'src'));
|
|
1257
|
+
// let tsFiles = files.filter(f => f.match(/\.(ts|tsx)$/));
|
|
1258
|
+
// let cssFiles = files.filter(f => f.match(/\.(css|scss)$/)).filter(f => !f.match(/\.module\.(css|scss)$/));
|
|
1259
|
+
// cssFiles.forEach(cssFile => {
|
|
1260
|
+
// let cssFileName = path.basename(cssFile);
|
|
1261
|
+
// let newFile = cssFileName.replace(/\.s?css$/,'.module$&');
|
|
1262
|
+
// let newFilePath = cssFile.replace(/\.s?css$/,'.module$&');
|
|
1263
|
+
// let jsonFile = cssFileName.replace(/\.s?css$/,'$&.json');
|
|
1264
|
+
// fs.renameSync(cssFile,newFilePath);
|
|
1265
|
+
// console.log('Renaming ' + cssFileName + ' to ' + newFilePath);
|
|
1266
|
+
// //find other files that import this file and update them
|
|
1267
|
+
// tsFiles.forEach(tsFile => {
|
|
1268
|
+
// //read contents of f2
|
|
1269
|
+
// let contents = fs.readFileSync(tsFile,'utf8');
|
|
1270
|
+
// //if it imports f
|
|
1271
|
+
// if (contents.indexOf(cssFileName) !== -1)
|
|
1272
|
+
// {
|
|
1273
|
+
// //find the whole line that imports f
|
|
1274
|
+
// let line = contents.split('\n').find(l => l.indexOf(cssFileName) !== -1);
|
|
1275
|
+
// // console.log("OLD: "+line);
|
|
1276
|
+
// let jsonLine = contents.split('\n').find(l => l.indexOf(jsonFile) !== -1);
|
|
1277
|
+
// // console.log("JSON: "+jsonLine);
|
|
1278
|
+
// //if not commented out
|
|
1279
|
+
// if(line.indexOf('//') === -1) {
|
|
1280
|
+
// let previousImportPath = line.match(/['"](.*)['"]/)[1];
|
|
1281
|
+
// let newImportPath = previousImportPath.replace(cssFileName,newFile);
|
|
1282
|
+
// let newContents = contents.replace(line,`import style from '${newImportPath}';`)
|
|
1283
|
+
// .replace(jsonLine+'\n','');
|
|
1284
|
+
// // console.log("\n");
|
|
1285
|
+
// fs.writeFileSync(tsFile,newContents);
|
|
1286
|
+
// console.log('Updated imports in ' + tsFile);
|
|
1287
|
+
// // fs.writeFileSync
|
|
1288
|
+
// // fs.writeFileSync(i,fs.readFileSync(i,'utf8').replace(f,newFile));
|
|
1289
|
+
// }
|
|
1290
|
+
// }
|
|
1291
|
+
// })
|
|
1292
|
+
// });
|
|
1293
|
+
files.filter(f => f.match(/\.(scss\.json|css\.json)$/)).forEach(cssJsonFile => {
|
|
1294
|
+
console.log('Removing ' + cssJsonFile);
|
|
1295
|
+
fs_extra_1.default.unlinkSync(cssJsonFile);
|
|
1296
|
+
});
|
|
1297
|
+
};
|
|
1298
|
+
// });
|
|
1299
|
+
}, () => {
|
|
1300
|
+
console.log('Finished upgrading packages');
|
|
1301
|
+
});
|
|
1302
|
+
// packages.forEach((pkg,key) => {
|
|
1303
|
+
// console.log(key+' Upgrading ' + pkg.packageName);
|
|
1304
|
+
// execPromise(`cd ${pkg.path} && yarn upgrade`).then(() => {
|
|
1305
|
+
// console.log('Upgraded ' + pkg.packageName);
|
|
1306
|
+
// }).catch(err => {
|
|
1307
|
+
// console.warn(err);
|
|
1308
|
+
// })
|
|
1309
|
+
// });
|
|
1310
|
+
};
|
|
1311
|
+
exports.upgradePackages = upgradePackages;
|
|
945
1312
|
const createPackage = async (name, uriBase, basePath = process.cwd()) => {
|
|
946
1313
|
if (!name) {
|
|
947
1314
|
console.warn('Please provide a name as the first argument');
|
|
@@ -973,8 +1340,8 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
|
|
|
973
1340
|
//extra variable for clarity (will be same as 'name')
|
|
974
1341
|
setVariable('output_file_name', name);
|
|
975
1342
|
let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(cleanPackageName);
|
|
976
|
-
log(
|
|
977
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
1343
|
+
log('Creating new LINCD package \'' + name + '\'');
|
|
1344
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'package'), targetFolder);
|
|
978
1345
|
//replace variables in some of the copied files
|
|
979
1346
|
await Promise.all([
|
|
980
1347
|
'src/index.ts',
|
|
@@ -1001,14 +1368,14 @@ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
|
|
|
1001
1368
|
console.log('rename ', path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
|
|
1002
1369
|
fs_extra_1.default.renameSync(path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
|
|
1003
1370
|
});
|
|
1004
|
-
let version = (await (0,
|
|
1371
|
+
let version = (await (0, utils_js_1.execPromise)('yarn --version').catch((err) => {
|
|
1005
1372
|
console.log('yarn probably not working');
|
|
1006
1373
|
return '';
|
|
1007
1374
|
}));
|
|
1008
1375
|
let installCommand = version.toString().match(/[0-9]+/)
|
|
1009
1376
|
? 'yarn install'
|
|
1010
1377
|
: 'npm install';
|
|
1011
|
-
await (0,
|
|
1378
|
+
await (0, utils_js_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
|
|
1012
1379
|
console.warn('Could not install dependencies');
|
|
1013
1380
|
});
|
|
1014
1381
|
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 +1397,6 @@ var buildFailed = function (output) {
|
|
|
1030
1397
|
return (output.indexOf('Aborted due to warnings') !== -1 &&
|
|
1031
1398
|
output.indexOf('Command failed') !== -1);
|
|
1032
1399
|
};
|
|
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
1400
|
const register = function (registryURL) {
|
|
1071
1401
|
if (fs_extra_1.default.existsSync(process.cwd() + '/package.json')) {
|
|
1072
1402
|
var pack = JSON.parse(fs_extra_1.default.readFileSync(process.cwd() + '/package.json', 'utf8'));
|
|
@@ -1114,104 +1444,186 @@ const register = function (registryURL) {
|
|
|
1114
1444
|
}
|
|
1115
1445
|
};
|
|
1116
1446
|
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 is a directory
|
|
1130
|
-
const stats = await fs_extra_1.default.stat(filePath);
|
|
1131
|
-
let isDir = stats.isDirectory();
|
|
1132
|
-
if (isDir) {
|
|
1133
|
-
continue;
|
|
1134
|
-
}
|
|
1135
|
-
// Check if the file exists before attempting to delete it
|
|
1136
|
-
if (await fs_extra_1.default.pathExists(filePath)) {
|
|
1137
|
-
const stats = await fs_extra_1.default.stat(filePath);
|
|
1138
|
-
const currentTime = new Date().getTime();
|
|
1139
|
-
const lastModifiedTime = stats.mtime.getTime();
|
|
1140
|
-
// Check if the difference between the current time and last modified time is greater than 10 seconds
|
|
1141
|
-
if (currentTime - lastModifiedTime > 120000) {
|
|
1142
|
-
// Attempt to delete the file
|
|
1143
|
-
await fs_extra_1.default.remove(filePath);
|
|
1144
|
-
console.log(`Removed: ${filePath}`);
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
else {
|
|
1148
|
-
console.warn(`File ${filePath} does not exist.`);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1447
|
+
const buildPackage = async (target, target2, packagePath = process.cwd(), logResults = true) => {
|
|
1448
|
+
let spinner;
|
|
1449
|
+
if (logResults) {
|
|
1450
|
+
//TODO: replace with listr so we can show multiple processes at once
|
|
1451
|
+
spinner = (0, ora_1.default)({
|
|
1452
|
+
discardStdin: true,
|
|
1453
|
+
text: 'Compiling ESM',
|
|
1454
|
+
}).start();
|
|
1151
1455
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
const buildPackage = (target, target2, packagePath = process.cwd(), logResults = true) => {
|
|
1158
|
-
if (target == 'production' || target == 'es5' || target == 'es6' || !target) {
|
|
1159
|
-
if (!fs_extra_1.default.existsSync(path_1.default.join(packagePath, 'Gruntfile.js'))) {
|
|
1160
|
-
console.warn(`No Gruntfile found at ${packagePath}\\Gruntfile.js. Cannot build.`);
|
|
1161
|
-
return;
|
|
1162
|
-
}
|
|
1163
|
-
var nodeEnv = '';
|
|
1164
|
-
if (target == 'production') {
|
|
1165
|
-
if (!(target2 == 'es5' || target2 == 'es6' || typeof target2 == 'undefined')) {
|
|
1166
|
-
console.warn('unknown second build target. Use es5 or es6', target2);
|
|
1167
|
-
return;
|
|
1456
|
+
let buildProcess = Promise.resolve(true);
|
|
1457
|
+
let buildStep = (step) => {
|
|
1458
|
+
buildProcess = buildProcess.then((previousResult) => {
|
|
1459
|
+
if (!previousResult) {
|
|
1460
|
+
return false;
|
|
1168
1461
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1173
|
-
else {
|
|
1174
|
-
nodeEnv = "NODE_ENV='production' ";
|
|
1462
|
+
if (logResults) {
|
|
1463
|
+
spinner.text = step.name;
|
|
1464
|
+
spinner.start();
|
|
1175
1465
|
}
|
|
1466
|
+
return step.apply().then(stepResult => {
|
|
1467
|
+
//if a build step returns a string,
|
|
1468
|
+
//a warning is shown but the build is still successful with warnings
|
|
1469
|
+
if (typeof stepResult === 'string') {
|
|
1470
|
+
// spinner.text = step.name + ' - ' + stepResult;
|
|
1471
|
+
if (logResults) {
|
|
1472
|
+
spinner.warn(step.name + ' - ' + stepResult);
|
|
1473
|
+
spinner.stop();
|
|
1474
|
+
}
|
|
1475
|
+
//can still continue
|
|
1476
|
+
return true;
|
|
1477
|
+
}
|
|
1478
|
+
else if (stepResult === true || typeof stepResult === 'undefined') {
|
|
1479
|
+
if (logResults) {
|
|
1480
|
+
spinner.succeed();
|
|
1481
|
+
}
|
|
1482
|
+
return previousResult && true;
|
|
1483
|
+
}
|
|
1484
|
+
else if (typeof stepResult === 'object' && stepResult.error) {
|
|
1485
|
+
if (logResults) {
|
|
1486
|
+
spinner.fail(step.name + ' - ' + stepResult.error);
|
|
1487
|
+
spinner.stop();
|
|
1488
|
+
}
|
|
1489
|
+
//failed and should stop
|
|
1490
|
+
return false;
|
|
1491
|
+
}
|
|
1492
|
+
});
|
|
1493
|
+
});
|
|
1494
|
+
};
|
|
1495
|
+
buildStep({
|
|
1496
|
+
name: 'Compiling ESM',
|
|
1497
|
+
apply: async () => {
|
|
1498
|
+
return (0, exports.compilePackageESM)(packagePath);
|
|
1499
|
+
},
|
|
1500
|
+
});
|
|
1501
|
+
buildStep({
|
|
1502
|
+
name: 'Compiling CJS',
|
|
1503
|
+
apply: async () => {
|
|
1504
|
+
return (0, exports.compilePackageCJS)(packagePath);
|
|
1505
|
+
},
|
|
1506
|
+
});
|
|
1507
|
+
buildStep({
|
|
1508
|
+
name: 'Copying files to lib folder',
|
|
1509
|
+
apply: async () => {
|
|
1510
|
+
const files = await (0, glob_1.glob)(packagePath + '/src/**/*.{json,d.ts,css,scss}');
|
|
1511
|
+
return Promise.all(files.map((async (file) => {
|
|
1512
|
+
try {
|
|
1513
|
+
await fs_extra_1.default.copy(file, packagePath + '/lib/esm/' + file.replace(packagePath + '/src/', ''));
|
|
1514
|
+
await fs_extra_1.default.copy(file, packagePath + '/lib/cjs/' + file.replace(packagePath + '/src/', ''));
|
|
1515
|
+
return true;
|
|
1516
|
+
}
|
|
1517
|
+
catch (err) {
|
|
1518
|
+
console.warn(err);
|
|
1519
|
+
return false;
|
|
1520
|
+
}
|
|
1521
|
+
;
|
|
1522
|
+
}))).then((allResults) => {
|
|
1523
|
+
return allResults.every(r => r === true);
|
|
1524
|
+
});
|
|
1525
|
+
},
|
|
1526
|
+
});
|
|
1527
|
+
buildStep({
|
|
1528
|
+
name: 'Dual package support',
|
|
1529
|
+
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 => {
|
|
1531
|
+
return res === '';
|
|
1532
|
+
});
|
|
1533
|
+
},
|
|
1534
|
+
});
|
|
1535
|
+
buildStep({
|
|
1536
|
+
name: 'Removing old files from lib folder',
|
|
1537
|
+
apply: async () => {
|
|
1538
|
+
return (0, exports.removeOldFiles)(packagePath);
|
|
1539
|
+
},
|
|
1540
|
+
});
|
|
1541
|
+
buildStep({
|
|
1542
|
+
name: 'Checking imports',
|
|
1543
|
+
apply: () => (0, exports.checkImports)(packagePath),
|
|
1544
|
+
});
|
|
1545
|
+
buildStep({
|
|
1546
|
+
name: 'Checking dependencies',
|
|
1547
|
+
apply: () => (0, exports.depCheck)(packagePath),
|
|
1548
|
+
});
|
|
1549
|
+
let success = await buildProcess.catch(err => {
|
|
1550
|
+
let msg = typeof err === 'string' || err instanceof Error ? err.toString() : (err.error && !err.error.toString().includes("Command failed:") ? err.error : err.stdout + '\n' + err.stderr);
|
|
1551
|
+
if (logResults) {
|
|
1552
|
+
spinner.stopAndPersist({
|
|
1553
|
+
symbol: chalk_1.default.red('✖'),
|
|
1554
|
+
// text: 'Build failed',
|
|
1555
|
+
});
|
|
1176
1556
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1557
|
+
else {
|
|
1558
|
+
console.log(chalk_1.default.red(packagePath.split('/').pop(), ' - Build failed:'));
|
|
1559
|
+
console.log(err);
|
|
1560
|
+
}
|
|
1561
|
+
console.log(msg);
|
|
1562
|
+
});
|
|
1563
|
+
//will be undefined if there was an error
|
|
1564
|
+
if (typeof success !== 'undefined' && success !== false) {
|
|
1565
|
+
if (logResults) {
|
|
1566
|
+
spinner.stopAndPersist({
|
|
1567
|
+
symbol: chalk_1.default.greenBright('✔'),
|
|
1568
|
+
text: success === true ? 'Build successful' : 'Build successful with warnings',
|
|
1569
|
+
});
|
|
1179
1570
|
}
|
|
1180
|
-
log('building once: ' +
|
|
1181
|
-
nodeEnv +
|
|
1182
|
-
'grunt build' +
|
|
1183
|
-
(target ? '-' + target : '') +
|
|
1184
|
-
(target2 ? '-' + target2 : '') +
|
|
1185
|
-
' --color');
|
|
1186
|
-
let method = logResults ? utils_1.execp : utils_1.execPromise;
|
|
1187
|
-
//NOTE: we moved SCSS:JSON out of webpack and grunt, into this file
|
|
1188
|
-
//this is the beginning of a transition away from grunt
|
|
1189
|
-
//but for the time being it's perhaps a bit strange that we
|
|
1190
|
-
// let x = postcss([
|
|
1191
|
-
// postcssModules({
|
|
1192
|
-
// generateScopedName,
|
|
1193
|
-
// }),
|
|
1194
|
-
// ]);
|
|
1195
|
-
//execute the command to build the method, and provide the current work directory as option
|
|
1196
|
-
return method(nodeEnv +
|
|
1197
|
-
'grunt build' +
|
|
1198
|
-
(target ? '-' + target : '') +
|
|
1199
|
-
(target2 ? '-' + target2 : '') +
|
|
1200
|
-
' --color', false, false, { cwd: packagePath })
|
|
1201
|
-
.then(() => {
|
|
1202
|
-
// Once the build is complete, remove old files
|
|
1203
|
-
return (0, exports.removeOldFiles)(packagePath);
|
|
1204
|
-
})
|
|
1205
|
-
.catch((err) => {
|
|
1206
|
-
console.error('Error building package:', err);
|
|
1207
|
-
process.exit(1);
|
|
1208
|
-
});
|
|
1209
1571
|
}
|
|
1210
1572
|
else {
|
|
1211
|
-
|
|
1573
|
+
spinner.stopAndPersist({
|
|
1574
|
+
symbol: chalk_1.default.red('✖'),
|
|
1575
|
+
text: 'Build failed',
|
|
1576
|
+
});
|
|
1212
1577
|
}
|
|
1578
|
+
return success;
|
|
1213
1579
|
};
|
|
1214
1580
|
exports.buildPackage = buildPackage;
|
|
1581
|
+
const compilePackage = async (packagePath = process.cwd()) => {
|
|
1582
|
+
//echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
|
|
1583
|
+
// let cjsConfig = fs.existsSync(path.join(packagePath,'tsconfig-cjs.json'));
|
|
1584
|
+
// let esmConfig = fs.existsSync(path.join(packagePath,'tsconfig-esm.json'));
|
|
1585
|
+
// let compileCJS = `yarn exec tsc -p tsconfig-cjs.json`;
|
|
1586
|
+
// let compileESM = `yarn exec tsc -p tsconfig-esm.json`;
|
|
1587
|
+
// let compileCommand;
|
|
1588
|
+
// if (cjsConfig && esmConfig)
|
|
1589
|
+
// {
|
|
1590
|
+
// compileCommand = `${compileCJS} && ${compileESM}`;
|
|
1591
|
+
// }
|
|
1592
|
+
// else if (cjsConfig)
|
|
1593
|
+
// {
|
|
1594
|
+
// compileCommand = compileCJS;
|
|
1595
|
+
// }
|
|
1596
|
+
// else if (esmConfig)
|
|
1597
|
+
// {
|
|
1598
|
+
// compileCommand = compileESM;
|
|
1599
|
+
// }
|
|
1600
|
+
// else
|
|
1601
|
+
// {
|
|
1602
|
+
// compileCommand = `yarn exec tsc`;
|
|
1603
|
+
// }
|
|
1604
|
+
await (0, exports.compilePackageESM)(packagePath);
|
|
1605
|
+
await (0, exports.compilePackageCJS)(packagePath);
|
|
1606
|
+
};
|
|
1607
|
+
exports.compilePackage = compilePackage;
|
|
1608
|
+
const compilePackageESM = async (packagePath = process.cwd()) => {
|
|
1609
|
+
//echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
|
|
1610
|
+
let compileCommand = `yarn exec tsc -p tsconfig-esm.json`;
|
|
1611
|
+
return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
|
|
1612
|
+
return res === '';
|
|
1613
|
+
});
|
|
1614
|
+
};
|
|
1615
|
+
exports.compilePackageESM = compilePackageESM;
|
|
1616
|
+
const compilePackageCJS = async (packagePath = process.cwd()) => {
|
|
1617
|
+
let compileCommand = `yarn exec tsc -p tsconfig-cjs.json`;
|
|
1618
|
+
return (0, utils_js_1.execPromise)(compileCommand, false, false, { cwd: packagePath }).then(res => {
|
|
1619
|
+
return res === '';
|
|
1620
|
+
}).catch(err => {
|
|
1621
|
+
return {
|
|
1622
|
+
error: err.stdout
|
|
1623
|
+
};
|
|
1624
|
+
});
|
|
1625
|
+
};
|
|
1626
|
+
exports.compilePackageCJS = compilePackageCJS;
|
|
1215
1627
|
var publishUpdated = function (test = false) {
|
|
1216
1628
|
let packages = getLocalLincdModules();
|
|
1217
1629
|
var p = Promise.resolve('');
|
|
@@ -1229,22 +1641,22 @@ var publishUpdated = function (test = false) {
|
|
|
1229
1641
|
// console.log("Will be requesting npm view from this current working directory:\n"+process.cwd());
|
|
1230
1642
|
// return execPromise('npm view '+pkg.packageName+' --json').then((output:string) => {
|
|
1231
1643
|
let shouldPublish;
|
|
1232
|
-
var pack = (0,
|
|
1644
|
+
var pack = (0, utils_js_1.getPackageJSON)(pckg.path);
|
|
1233
1645
|
let version = getNextVersion(pack.version);
|
|
1234
1646
|
if (pack.private) {
|
|
1235
1647
|
shouldPublish = false;
|
|
1236
|
-
(0,
|
|
1648
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.blue('--> is private, skipping'));
|
|
1237
1649
|
return chalk_1.default.gray(pckg.packageName + ' is private');
|
|
1238
1650
|
// return previousResult + ' ' + chalk.gray(pckg.packageName + ' is private\n');
|
|
1239
1651
|
}
|
|
1240
1652
|
console.log('testing npm');
|
|
1241
|
-
return (0,
|
|
1653
|
+
return (0, utils_js_1.execPromise)('npm info ' + pckg.packageName + ' --json')
|
|
1242
1654
|
.then(async (output) => {
|
|
1243
1655
|
console.log('testing npm done');
|
|
1244
1656
|
var info;
|
|
1245
1657
|
try {
|
|
1246
1658
|
if (output == '' || output.includes('E404')) {
|
|
1247
|
-
(0,
|
|
1659
|
+
(0, utils_js_1.debugInfo)('Empty or 404 response from `npm info`. This package was probably not published before');
|
|
1248
1660
|
// throw new Error('Empty response from `yarn info`. This pkg was probably not published before');
|
|
1249
1661
|
// return;
|
|
1250
1662
|
shouldPublish = true;
|
|
@@ -1267,10 +1679,10 @@ var publishUpdated = function (test = false) {
|
|
|
1267
1679
|
// }
|
|
1268
1680
|
let lastPublishDate = new Date(lastPublish);
|
|
1269
1681
|
// let {lastModifiedTime, lastModifiedName, lastModified} = getLastModifiedSourceTime(pkg.path);
|
|
1270
|
-
let lastCommitInfo = await (0,
|
|
1682
|
+
let lastCommitInfo = await (0, utils_js_1.getLastCommitTime)(pckg.path);
|
|
1271
1683
|
if (!lastCommitInfo) {
|
|
1272
1684
|
shouldPublish = false;
|
|
1273
|
-
(0,
|
|
1685
|
+
(0, utils_js_1.debugInfo)('Could not determine last git commit');
|
|
1274
1686
|
// return previousResult + ' ' + chalk.red(pckg.packageName + ' - could not determine last commit\n');
|
|
1275
1687
|
return chalk_1.default.red(pckg.packageName + ' - could not determine last commit');
|
|
1276
1688
|
}
|
|
@@ -1364,7 +1776,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
|
|
|
1364
1776
|
}
|
|
1365
1777
|
// let path = './';
|
|
1366
1778
|
for (let i = 0; i <= 10; i++) {
|
|
1367
|
-
let envFile = await (0,
|
|
1779
|
+
let envFile = await (0, get_env_vars_js_1.getEnvFile)({
|
|
1368
1780
|
filePath: relativeToPath + path + '.env.json',
|
|
1369
1781
|
}).catch((err) => {
|
|
1370
1782
|
return null;
|
|
@@ -1378,7 +1790,7 @@ async function getEnvJsonPath(relativeToPath = process.cwd()) {
|
|
|
1378
1790
|
}
|
|
1379
1791
|
var publishPackage = async function (pkg, test, info, publishVersion) {
|
|
1380
1792
|
if (!pkg) {
|
|
1381
|
-
let localPackageJson = (0,
|
|
1793
|
+
let localPackageJson = (0, utils_js_1.getPackageJSON)();
|
|
1382
1794
|
pkg = {
|
|
1383
1795
|
path: process.cwd(),
|
|
1384
1796
|
packageName: localPackageJson.name,
|
|
@@ -1388,18 +1800,18 @@ var publishPackage = async function (pkg, test, info, publishVersion) {
|
|
|
1388
1800
|
publishVersion = info ? getNextVersion(info.version) : 'patch';
|
|
1389
1801
|
}
|
|
1390
1802
|
if (test) {
|
|
1391
|
-
(0,
|
|
1803
|
+
(0, utils_js_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
|
|
1392
1804
|
//when testing what needs to be published
|
|
1393
1805
|
return chalk_1.default.blue(pkg.packageName + ' should publish');
|
|
1394
1806
|
}
|
|
1395
1807
|
console.log(chalk_1.default.blue('publishing ' + pkg.packageName + ' ' + publishVersion));
|
|
1396
1808
|
//looking for an .env.json file in our workspace, which may store our NPM AUTH key
|
|
1397
1809
|
let envJsonPath = await getEnvJsonPath(pkg.path);
|
|
1398
|
-
return (0,
|
|
1810
|
+
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)
|
|
1399
1811
|
.then((res) => {
|
|
1400
1812
|
if (res.indexOf('Aborted due to warnings') !== -1 ||
|
|
1401
1813
|
res.indexOf('Could not publish') !== -1 ||
|
|
1402
|
-
res.indexOf(
|
|
1814
|
+
res.indexOf('Couldn\'t publish') !== -1) {
|
|
1403
1815
|
console.log(res);
|
|
1404
1816
|
return chalk_1.default.red(pkg.packageName + ' failed\n');
|
|
1405
1817
|
}
|
|
@@ -1428,12 +1840,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1428
1840
|
// let packages = getLocalLincdModules();
|
|
1429
1841
|
let packages = getLocalLincdPackageMap();
|
|
1430
1842
|
// console.log(packages);
|
|
1431
|
-
let jsonldPkgUpdated = await (0,
|
|
1843
|
+
let jsonldPkgUpdated = await (0, utils_js_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
|
|
1432
1844
|
// let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
|
|
1433
1845
|
//if either cli or jsonldPkg needs to be rebuilt
|
|
1434
1846
|
// if (jsonldPkgUpdated || cliPkgUpdated) {
|
|
1435
1847
|
if (jsonldPkgUpdated) {
|
|
1436
|
-
await (0,
|
|
1848
|
+
await (0, utils_js_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
|
|
1437
1849
|
cwd: packages.get('lincd-jsonld').path,
|
|
1438
1850
|
}, true);
|
|
1439
1851
|
// await execPromise('yarn build-core', false, false, {}, true);
|
|
@@ -1445,12 +1857,12 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1445
1857
|
// }
|
|
1446
1858
|
let packagesLeft = packages.size;
|
|
1447
1859
|
runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
|
|
1448
|
-
(0,
|
|
1449
|
-
(0,
|
|
1860
|
+
(0, utils_js_1.debugInfo)('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
|
|
1861
|
+
(0, utils_js_1.debugInfo)(packagesLeft + ' packages left.');
|
|
1450
1862
|
packagesLeft = packagesLeft - packageGroup.length;
|
|
1451
1863
|
return async (pkg) => {
|
|
1452
1864
|
// debugInfo('# Checking package ' + pkg.packageName);
|
|
1453
|
-
let needRebuild = await (0,
|
|
1865
|
+
let needRebuild = await (0, utils_js_1.needsRebuilding)(pkg, useGitForLastModified);
|
|
1454
1866
|
if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
|
|
1455
1867
|
needRebuild = true;
|
|
1456
1868
|
}
|
|
@@ -1458,18 +1870,26 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1458
1870
|
//TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
|
|
1459
1871
|
// log(packageName+' modified since last commit on '+now.toString());
|
|
1460
1872
|
if (test) {
|
|
1461
|
-
(0,
|
|
1873
|
+
(0, utils_js_1.debugInfo)('Need to build ' + pkg.packageName);
|
|
1462
1874
|
return chalk_1.default.blue(pkg.packageName + ' should be build');
|
|
1463
1875
|
}
|
|
1464
1876
|
log('Building ' + pkg.packageName);
|
|
1465
|
-
return (
|
|
1877
|
+
// return buildPackage(null,null,pkg.path)
|
|
1878
|
+
return (0, utils_js_1.execPromise)('cd ' +
|
|
1466
1879
|
pkg.path +
|
|
1467
1880
|
' && yarn build' +
|
|
1468
1881
|
(target ? ' ' + target : '') +
|
|
1469
1882
|
(target2 ? ' ' + target2 : ''))
|
|
1470
1883
|
.then((res) => {
|
|
1471
|
-
|
|
1472
|
-
|
|
1884
|
+
if (res === '') {
|
|
1885
|
+
(0, utils_js_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
|
|
1886
|
+
return chalk_1.default.green(pkg.packageName + ' built');
|
|
1887
|
+
}
|
|
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
|
+
}
|
|
1473
1893
|
})
|
|
1474
1894
|
.catch(({ error, stdout, stderr }) => {
|
|
1475
1895
|
warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
|
|
@@ -1501,9 +1921,11 @@ var buildUpdated = async function (back, target, target2, useGitForLastModified
|
|
|
1501
1921
|
};
|
|
1502
1922
|
exports.buildUpdated = buildUpdated;
|
|
1503
1923
|
const printBuildResults = function (failed, done) {
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1924
|
+
if (done.size > 0 || done.length > 0) {
|
|
1925
|
+
log('Successfully built: ' +
|
|
1926
|
+
chalk_1.default.green([...done].map((m) => m.packageName).join(', ')) +
|
|
1927
|
+
'\n');
|
|
1928
|
+
}
|
|
1507
1929
|
if (failed.length > 0) {
|
|
1508
1930
|
warn('Failed to build: ' + chalk_1.default.red(failed.join(', ')) + '\n');
|
|
1509
1931
|
}
|
|
@@ -1528,21 +1950,21 @@ var executeCommandForEachPackage = function (packages, command, filterMethod, fi
|
|
|
1528
1950
|
let seen = false;
|
|
1529
1951
|
packages = packages.filter((pkg) => {
|
|
1530
1952
|
if (!seen &&
|
|
1531
|
-
|
|
1953
|
+
pkg.packageName.includes(startFrom)) {
|
|
1532
1954
|
seen = true;
|
|
1533
1955
|
}
|
|
1534
1956
|
return seen;
|
|
1535
1957
|
});
|
|
1536
1958
|
}
|
|
1537
|
-
log(
|
|
1959
|
+
log('Executing \'' +
|
|
1538
1960
|
chalk_1.default.blueBright(command) +
|
|
1539
|
-
|
|
1961
|
+
'\' on packages ' +
|
|
1540
1962
|
chalk_1.default.magenta(packages.map((m) => m.packageName).join(', ')));
|
|
1541
1963
|
var p = Promise.resolve(true);
|
|
1542
1964
|
packages.forEach((pkg) => {
|
|
1543
1965
|
p = p.then(() => {
|
|
1544
1966
|
log('# Package ' + chalk_1.default.magenta(pkg.packageName));
|
|
1545
|
-
return (0,
|
|
1967
|
+
return (0, utils_js_1.execp)('cd ' + pkg.path + ' && ' + command);
|
|
1546
1968
|
});
|
|
1547
1969
|
});
|
|
1548
1970
|
return p;
|
|
@@ -1564,8 +1986,8 @@ exports.addLinesToFile = addLinesToFile;
|
|
|
1564
1986
|
var addCapacitor = async function (basePath = process.cwd()) {
|
|
1565
1987
|
let targetFolder = ensureFolderExists(basePath);
|
|
1566
1988
|
log('Adding capacitor');
|
|
1567
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
1568
|
-
fs_extra_1.default.copySync(path_1.default.join(
|
|
1989
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'app-static'), targetFolder);
|
|
1990
|
+
fs_extra_1.default.copySync(path_1.default.join((0, exports.getScriptDir)(), '..', '..', 'defaults', 'capacitor', 'scripts'), path_1.default.join(targetFolder, 'scripts'));
|
|
1569
1991
|
//update .env-cmdrc.json file
|
|
1570
1992
|
let envCmdPath = path_1.default.resolve(basePath, '.env-cmdrc.json');
|
|
1571
1993
|
let envCmd = JSON.parse(fs_extra_1.default.readFileSync(envCmdPath, { encoding: 'utf8' }));
|
|
@@ -1587,7 +2009,7 @@ var addCapacitor = async function (basePath = process.cwd()) {
|
|
|
1587
2009
|
log('Edited .env-cmdrc.json');
|
|
1588
2010
|
gitIgnore('android/app/build', 'android/**/capacitor.build.gradle', 'ios/App/App/public');
|
|
1589
2011
|
//update package.json scripts
|
|
1590
|
-
let pack = (0,
|
|
2012
|
+
let pack = (0, utils_js_1.getPackageJSON)(basePath);
|
|
1591
2013
|
pack.scripts['build-staging'] =
|
|
1592
2014
|
'env-cmd -e _main, staging node scripts/build.js';
|
|
1593
2015
|
pack.scripts['fix-app'] = 'node scripts/fix-namespace.js';
|
|
@@ -1602,8 +2024,8 @@ var addCapacitor = async function (basePath = process.cwd()) {
|
|
|
1602
2024
|
pack.scripts['cap:sync'] = 'yarn cap sync';
|
|
1603
2025
|
fs_extra_1.default.writeFile(path_1.default.resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
|
|
1604
2026
|
log('Added new run script to package.json');
|
|
1605
|
-
await (0,
|
|
1606
|
-
await (0,
|
|
2027
|
+
await (0, utils_js_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
|
|
2028
|
+
await (0, utils_js_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/app @capacitor/ios`, false, false, null, true);
|
|
1607
2029
|
// TODO: Do we need to add `npx cap init`? If yes, we should not copy capacitor config.ts yet
|
|
1608
2030
|
// await execPromise(`npx cap init`, true, false, null, true);
|
|
1609
2031
|
// got error:
|
|
@@ -1620,20 +2042,55 @@ var executeCommandForPackage = function (packageName, command) {
|
|
|
1620
2042
|
let packageDetails = getLincdPackages().find((modDetails) => modDetails.packageName.indexOf(packageName) !== -1 ||
|
|
1621
2043
|
modDetails.packageName.indexOf(packageName) !== -1);
|
|
1622
2044
|
if (packageDetails) {
|
|
1623
|
-
log(
|
|
2045
|
+
log('Executing \'cd ' +
|
|
1624
2046
|
packageDetails.path +
|
|
1625
2047
|
' && yarn exec lincd' +
|
|
1626
2048
|
(command ? ' ' + command : '') +
|
|
1627
|
-
|
|
1628
|
-
|
|
2049
|
+
'\'');
|
|
2050
|
+
//TODO : replace with spawn("path to executable", ["params"], {stdio: "inherit"});
|
|
2051
|
+
// maybe make spawnPromise that returns a promise
|
|
2052
|
+
return (0, utils_js_1.execp)('cd ' +
|
|
1629
2053
|
packageDetails.path +
|
|
1630
2054
|
' && yarn exec lincd' +
|
|
1631
2055
|
(command ? ' ' + command : ''));
|
|
1632
2056
|
}
|
|
1633
2057
|
else {
|
|
1634
|
-
warn(
|
|
2058
|
+
warn('Could not find a pkg who\'s name (partially) matched ' +
|
|
1635
2059
|
chalk_1.default.cyan(packageName));
|
|
1636
2060
|
}
|
|
1637
2061
|
};
|
|
1638
2062
|
exports.executeCommandForPackage = executeCommandForPackage;
|
|
2063
|
+
/**
|
|
2064
|
+
* Function to remove files older than 10 seconds from the 'lib' folder.
|
|
2065
|
+
* @param {string} packagePath - The path to the package directory.
|
|
2066
|
+
*/
|
|
2067
|
+
const removeOldFiles = async (packagePath) => {
|
|
2068
|
+
const libPath = path_1.default.join(packagePath, 'lib');
|
|
2069
|
+
try {
|
|
2070
|
+
// Read all files in the 'lib' folder asynchronously
|
|
2071
|
+
const files = await (0, glob_1.glob)(packagePath + '/lib/**/*.*');
|
|
2072
|
+
// Iterate through each file
|
|
2073
|
+
for (const file of files) {
|
|
2074
|
+
// const filePath = path.join(libPath, file);
|
|
2075
|
+
// Check if the file exists before attempting to delete it
|
|
2076
|
+
// if (await fs.pathExists(filePath)) {
|
|
2077
|
+
const stats = await fs_extra_1.default.stat(file);
|
|
2078
|
+
const currentTime = new Date().getTime();
|
|
2079
|
+
const lastModifiedTime = stats.mtime.getTime();
|
|
2080
|
+
// Check if the difference between the current time and last modified time is greater than 120 seconds
|
|
2081
|
+
if (currentTime - lastModifiedTime > 120000) {
|
|
2082
|
+
// Attempt to delete the file
|
|
2083
|
+
await fs_extra_1.default.unlink(file);
|
|
2084
|
+
// console.log(`Removed: ${file}`);
|
|
2085
|
+
}
|
|
2086
|
+
// }
|
|
2087
|
+
}
|
|
2088
|
+
return true;
|
|
2089
|
+
}
|
|
2090
|
+
catch (error) {
|
|
2091
|
+
console.error(`Error removing files: ${error.message}`);
|
|
2092
|
+
return false;
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
exports.removeOldFiles = removeOldFiles;
|
|
1639
2096
|
//# sourceMappingURL=cli-methods.js.map
|