tnp-helpers 19.0.5 → 19.0.7
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/browser/fesm2022/tnp-helpers.mjs +2399 -234
- package/browser/fesm2022/tnp-helpers.mjs.map +1 -1
- package/browser/lib/base/linked-project.d.ts +4 -1
- package/browser/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +6 -6
- package/browser/lib/build-info._auto-generated_.d.ts +2 -1
- package/browser/lib/helpers/helpers.d.ts +1 -0
- package/browser/lib/index.d.ts +3 -1
- package/browser/lib/old/execute-command.d.ts +12 -0
- package/browser/lib/old/helpers.d.ts +62 -0
- package/browser/lib/old/models.d.ts +81 -0
- package/browser/lib/utils.d.ts +42 -21
- package/browser/package.json +1 -1
- package/client/fesm2022/tnp-helpers.mjs +2399 -234
- package/client/fesm2022/tnp-helpers.mjs.map +1 -1
- package/client/lib/base/linked-project.d.ts +4 -1
- package/client/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +6 -6
- package/client/lib/build-info._auto-generated_.d.ts +2 -1
- package/client/lib/helpers/helpers.d.ts +1 -0
- package/client/lib/index.d.ts +3 -1
- package/client/lib/old/execute-command.d.ts +12 -0
- package/client/lib/old/helpers.d.ts +62 -0
- package/client/lib/old/models.d.ts +81 -0
- package/client/lib/utils.d.ts +42 -21
- package/client/package.json +1 -1
- package/lib/base/classes/base-bower-json.js +2 -2
- package/lib/base/classes/base-bower-json.js.map +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-config.js +2 -2
- package/lib/base/classes/base-cli-worker/base-cli-worker-config.js.map +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js +14 -14
- package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js.map +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js +10 -10
- package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js.map +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker.js +18 -18
- package/lib/base/classes/base-cli-worker/base-cli-worker.js.map +1 -1
- package/lib/base/classes/base-command-line-feature.backend.js +10 -10
- package/lib/base/classes/base-command-line-feature.backend.js.map +1 -1
- package/lib/base/classes/base-compiler-for-project.d.ts +1 -1
- package/lib/base/classes/base-compiler-for-project.js +13 -13
- package/lib/base/classes/base-compiler-for-project.js.map +1 -1
- package/lib/base/classes/base-db.js +7 -7
- package/lib/base/classes/base-db.js.map +1 -1
- package/lib/base/classes/base-debounce-compiler-for-project.d.ts +1 -1
- package/lib/base/classes/base-debounce-compiler-for-project.js +5 -5
- package/lib/base/classes/base-debounce-compiler-for-project.js.map +1 -1
- package/lib/base/classes/base-git.js +26 -25
- package/lib/base/classes/base-git.js.map +1 -1
- package/lib/base/classes/base-global-command-line.backend.d.ts +3 -1
- package/lib/base/classes/base-global-command-line.backend.js +60 -49
- package/lib/base/classes/base-global-command-line.backend.js.map +1 -1
- package/lib/base/classes/base-ignore-hide.js +2 -2
- package/lib/base/classes/base-ignore-hide.js.map +1 -1
- package/lib/base/classes/base-json-file-reader.js +24 -24
- package/lib/base/classes/base-json-file-reader.js.map +1 -1
- package/lib/base/classes/base-library-build.js +52 -52
- package/lib/base/classes/base-library-build.js.map +1 -1
- package/lib/base/classes/base-linked-projects.js +23 -23
- package/lib/base/classes/base-linked-projects.js.map +1 -1
- package/lib/base/classes/base-node-modules.js +37 -37
- package/lib/base/classes/base-node-modules.js.map +1 -1
- package/lib/base/classes/base-npm-helpers.d.ts +1 -1
- package/lib/base/classes/base-npm-helpers.js +14 -14
- package/lib/base/classes/base-npm-helpers.js.map +1 -1
- package/lib/base/classes/base-package-json.d.ts +1 -1
- package/lib/base/classes/base-package-json.js +27 -27
- package/lib/base/classes/base-package-json.js.map +1 -1
- package/lib/base/classes/base-powershell.js +7 -2
- package/lib/base/classes/base-powershell.js.map +1 -1
- package/lib/base/classes/base-process-manager.js +8 -8
- package/lib/base/classes/base-process-manager.js.map +1 -1
- package/lib/base/classes/base-project-resolver.js +34 -33
- package/lib/base/classes/base-project-resolver.js.map +1 -1
- package/lib/base/classes/base-project.d.ts +1 -1
- package/lib/base/classes/base-project.js +62 -62
- package/lib/base/classes/base-project.js.map +1 -1
- package/lib/base/classes/base-quick-fixes.js +9 -9
- package/lib/base/classes/base-quick-fixes.js.map +1 -1
- package/lib/base/classes/base-release-process.d.ts +1 -1
- package/lib/base/classes/base-release-process.js +19 -19
- package/lib/base/classes/base-release-process.js.map +1 -1
- package/lib/base/classes/base-start-config.backend.js +13 -13
- package/lib/base/classes/base-start-config.backend.js.map +1 -1
- package/lib/base/classes/base-static-pages.js +6 -6
- package/lib/base/classes/base-static-pages.js.map +1 -1
- package/lib/base/classes/base-vscode.js +31 -24
- package/lib/base/classes/base-vscode.js.map +1 -1
- package/lib/base/commit-data.js +25 -25
- package/lib/base/commit-data.js.map +1 -1
- package/lib/base/core-project.d.ts +1 -1
- package/lib/base/core-project.js +9 -9
- package/lib/base/core-project.js.map +1 -1
- package/lib/base/gh-temp-code.js +6 -6
- package/lib/base/gh-temp-code.js.map +1 -1
- package/lib/base/index-rebuilder.backend.js +1 -1
- package/lib/base/index-rebuilder.backend.js.map +1 -1
- package/lib/base/linked-project.d.ts +4 -1
- package/lib/base/linked-project.js +18 -9
- package/lib/base/linked-project.js.map +1 -1
- package/lib/base/tcp-udp-ports/not-assignable-port.entity.js +2 -2
- package/lib/base/tcp-udp-ports/ports.controller.d.ts +1 -1
- package/lib/base/tcp-udp-ports/ports.controller.js +21 -21
- package/lib/base/tcp-udp-ports/ports.controller.js.map +1 -1
- package/lib/base/tcp-udp-ports/ports.entity.d.ts +1 -1
- package/lib/base/tcp-udp-ports/ports.entity.js +10 -10
- package/lib/base/tcp-udp-ports/ports.entity.js.map +1 -1
- package/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +9 -9
- package/lib/base/tcp-udp-ports/tcp-udp-ports.context.js +9 -9
- package/lib/base/tcp-udp-ports/tcp-udp-ports.context.js.map +1 -1
- package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js +18 -18
- package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js.map +1 -1
- package/lib/build-info._auto-generated_.d.ts +2 -1
- package/lib/build-info._auto-generated_.js +3 -2
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/helpers/for-backend/helpers-cli-tool.backend.js +40 -40
- package/lib/helpers/for-backend/helpers-cli-tool.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-console-gui.js +2 -2
- package/lib/helpers/for-backend/helpers-console-gui.js.map +1 -1
- package/lib/helpers/for-backend/helpers-dependencies.backend.js +2 -2
- package/lib/helpers/for-backend/helpers-dependencies.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-file-folders.js +131 -131
- package/lib/helpers/for-backend/helpers-file-folders.js.map +1 -1
- package/lib/helpers/for-backend/helpers-git.backend.js +120 -106
- package/lib/helpers/for-backend/helpers-git.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-network.backend.js +2 -3
- package/lib/helpers/for-backend/helpers-network.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-npm.backend.js +2 -2
- package/lib/helpers/for-backend/helpers-npm.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-path.backend.js +6 -6
- package/lib/helpers/for-backend/helpers-path.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-process.d.ts +1 -1
- package/lib/helpers/for-backend/helpers-process.js +41 -41
- package/lib/helpers/for-backend/helpers-process.js.map +1 -1
- package/lib/helpers/for-backend/helpers-system-terminal.backend.js +2 -2
- package/lib/helpers/for-backend/helpers-system-terminal.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-vscode.backend.d.ts +1 -1
- package/lib/helpers/for-backend/helpers-vscode.backend.js +2 -2
- package/lib/helpers/for-backend/helpers-vscode.backend.js.map +1 -1
- package/lib/helpers/for-browser/angular.helper.js +2 -2
- package/lib/helpers/helpers-array-obj.js +10 -10
- package/lib/helpers/helpers-array-obj.js.map +1 -1
- package/lib/helpers/helpers-json5.backend.js +6 -6
- package/lib/helpers/helpers-json5.backend.js.map +1 -1
- package/lib/helpers/helpers-numbers.js.map +1 -1
- package/lib/helpers/helpers-strings-regexes.js +5 -5
- package/lib/helpers/helpers-strings-regexes.js.map +1 -1
- package/lib/helpers/helpers-strings.js +3 -3
- package/lib/helpers/helpers-strings.js.map +1 -1
- package/lib/helpers/helpers.d.ts +1 -0
- package/lib/helpers/helpers.js +42 -30
- package/lib/helpers/helpers.js.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/lib/lowdb/adapters/node/TextFile.js +2 -2
- package/lib/lowdb/adapters/node/TextFile.js.map +1 -1
- package/lib/models.d.ts +1 -1
- package/lib/models.js +8 -8
- package/lib/models.js.map +1 -1
- package/lib/old/base-component.js +2 -2
- package/lib/old/base-formly-component.js +2 -2
- package/lib/old/dual-component-ctrl.js +2 -2
- package/lib/old/execute-command.js +20 -8
- package/lib/old/execute-command.js.map +1 -1
- package/lib/old/helpers.js +2 -2
- package/lib/old/helpers.js.map +1 -1
- package/lib/old/models.d.ts +1 -1
- package/lib/utils.d.ts +42 -21
- package/lib/utils.js +340 -54
- package/lib/utils.js.map +1 -1
- package/lib/validators/validators-firedev.js +6 -6
- package/lib/validators/validators-firedev.js.map +1 -1
- package/lib/validators/validators-git.js.map +1 -1
- package/lib/validators/validators-network.js +2 -2
- package/lib/validators/validators-network.js.map +1 -1
- package/migrations/1736198527297_init.d.ts +1 -1
- package/migrations/1736198527297_init.js +5 -5
- package/migrations/1736198527297_init.js.map +1 -1
- package/migrations/1736199486472_addingNotAssignablePorts.d.ts +1 -1
- package/migrations/1736199486472_addingNotAssignablePorts.js +8 -8
- package/migrations/1736199486472_addingNotAssignablePorts.js.map +1 -1
- package/migrations/1736454437350_addFreePorts.d.ts +1 -1
- package/migrations/1736454437350_addFreePorts.js +11 -11
- package/migrations/1736454437350_addFreePorts.js.map +1 -1
- package/package.json +1 -1
- package/tmp-environment.json +4 -4
- package/websql/fesm2022/tnp-helpers.mjs +2436 -238
- package/websql/fesm2022/tnp-helpers.mjs.map +1 -1
- package/websql/lib/base/linked-project.d.ts +4 -1
- package/websql/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +6 -6
- package/websql/lib/build-info._auto-generated_.d.ts +2 -1
- package/websql/lib/helpers/helpers.d.ts +1 -0
- package/websql/lib/index.d.ts +3 -1
- package/websql/lib/old/execute-command.d.ts +12 -0
- package/websql/lib/old/helpers.d.ts +62 -0
- package/websql/lib/old/models.d.ts +81 -0
- package/websql/lib/utils.d.ts +42 -21
- package/websql/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UtilsQuickFixes = exports.UtilsMd = exports.UtilsHttp = exports.UtilsTypescript = exports.UtilsNpm = void 0;
|
|
4
4
|
//#region imports
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const lib_1 = require("tnp-core/lib");
|
|
6
|
+
const lib_2 = require("tnp-core/lib");
|
|
7
7
|
const typescript_1 = require("typescript");
|
|
8
|
+
const index_1 = require("./index");
|
|
8
9
|
//#endregion
|
|
9
10
|
//#region utils npm
|
|
10
11
|
var UtilsNpm;
|
|
11
12
|
(function (UtilsNpm) {
|
|
12
13
|
//#region is special version
|
|
13
14
|
UtilsNpm.isSpecialVersion = (version) => {
|
|
14
|
-
return
|
|
15
|
+
return lib_2.CoreModels.NpmSpecialVersions.includes(version);
|
|
15
16
|
};
|
|
16
17
|
//#endregion
|
|
17
18
|
//#region clear version
|
|
@@ -22,7 +23,7 @@ var UtilsNpm;
|
|
|
22
23
|
}
|
|
23
24
|
version = (version || '')
|
|
24
25
|
.trim()
|
|
25
|
-
.replace(new RegExp(
|
|
26
|
+
.replace(new RegExp(lib_2.Utils.escapeStringForRegEx('undefined'), 'g'), '0');
|
|
26
27
|
if (removePrefixes) {
|
|
27
28
|
version = version.replace('^', '').replace('~', '');
|
|
28
29
|
}
|
|
@@ -40,7 +41,7 @@ var UtilsNpm;
|
|
|
40
41
|
}
|
|
41
42
|
version = (version || '')
|
|
42
43
|
.trim()
|
|
43
|
-
.replace(new RegExp(
|
|
44
|
+
.replace(new RegExp(lib_2.Utils.escapeStringForRegEx('undefined'), 'g'), '0');
|
|
44
45
|
const splited = version.split('.');
|
|
45
46
|
let [major, minor, patch, alphaOrBetaOrRc] = splited;
|
|
46
47
|
if (splited.length === 1) {
|
|
@@ -170,7 +171,7 @@ var UtilsTypescript;
|
|
|
170
171
|
if (!filePath.endsWith('.ts')) {
|
|
171
172
|
return [];
|
|
172
173
|
}
|
|
173
|
-
const file =
|
|
174
|
+
const file = index_1.Helpers.readFile(filePath);
|
|
174
175
|
return UtilsTypescript.exportsFromContent(file);
|
|
175
176
|
//#endregion
|
|
176
177
|
};
|
|
@@ -271,13 +272,13 @@ var UtilsTypescript;
|
|
|
271
272
|
if (!absoluteFilePath.endsWith('.ts')) {
|
|
272
273
|
return [];
|
|
273
274
|
}
|
|
274
|
-
const sourceCode =
|
|
275
|
+
const sourceCode = index_1.Helpers.readFile(absoluteFilePath);
|
|
275
276
|
return UtilsTypescript.extractClassNameFromString(sourceCode);
|
|
276
277
|
//#endregion
|
|
277
278
|
};
|
|
278
279
|
UtilsTypescript.extractDefaultClassNameFromFile = (absoluteFilePath) => {
|
|
279
280
|
//#region @backendFunc
|
|
280
|
-
const sourceCode =
|
|
281
|
+
const sourceCode = index_1.Helpers.readFile(absoluteFilePath);
|
|
281
282
|
return UtilsTypescript.extractDefaultClassNameFromString(sourceCode);
|
|
282
283
|
//#endregion
|
|
283
284
|
};
|
|
@@ -285,31 +286,73 @@ var UtilsTypescript;
|
|
|
285
286
|
//#region format file(s) with prettier
|
|
286
287
|
UtilsTypescript.formatFile = (absPathToFile) => {
|
|
287
288
|
//#region @backendFunc
|
|
288
|
-
if (
|
|
289
|
+
if (index_1.Helpers.exists(absPathToFile)) {
|
|
289
290
|
const { execSync } = require('child_process');
|
|
290
|
-
|
|
291
|
+
index_1.Helpers.logInfo(`Formatting file: ${absPathToFile}`);
|
|
291
292
|
try {
|
|
292
|
-
execSync(`prettier --write ${
|
|
293
|
-
cwd:
|
|
293
|
+
execSync(`prettier --write ${lib_1.path.basename(absPathToFile)}`, {
|
|
294
|
+
cwd: lib_1.path.dirname(absPathToFile),
|
|
294
295
|
});
|
|
295
296
|
}
|
|
296
297
|
catch (error) {
|
|
297
298
|
console.warn(`Not able to format file: ${absPathToFile}`);
|
|
298
299
|
}
|
|
299
|
-
|
|
300
|
+
index_1.Helpers.taskDone(`Formatting file done.`);
|
|
300
301
|
}
|
|
301
302
|
//#endregion
|
|
302
303
|
};
|
|
303
304
|
UtilsTypescript.formatAllFilesInsideFolder = (absPathToFolder) => {
|
|
304
305
|
//#region @backendFunc
|
|
305
|
-
if (
|
|
306
|
+
if (index_1.Helpers.exists(absPathToFolder)) {
|
|
307
|
+
if (!index_1.Helpers.isFolder(absPathToFolder)) {
|
|
308
|
+
index_1.Helpers.error(`"${absPathToFolder}" is not a folder`);
|
|
309
|
+
}
|
|
306
310
|
const { execSync } = require('child_process');
|
|
307
311
|
try {
|
|
308
312
|
execSync(`prettier --write .`, { cwd: absPathToFolder });
|
|
309
313
|
}
|
|
310
314
|
catch (error) {
|
|
311
|
-
console.warn(`Not able to files in: ${absPathToFolder}`);
|
|
315
|
+
console.warn(`Not able to prettier all files in: ${absPathToFolder}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
};
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region lint file(s) with eslint
|
|
322
|
+
UtilsTypescript.eslintFixFile = (absPathToFile) => {
|
|
323
|
+
//#region @backendFunc
|
|
324
|
+
absPathToFile = (0, lib_1.crossPlatformPath)(absPathToFile);
|
|
325
|
+
if (index_1.Helpers.exists(absPathToFile)) {
|
|
326
|
+
const { execSync } = require('child_process');
|
|
327
|
+
index_1.Helpers.logInfo(`Fixing file with eslint: ${absPathToFile}`);
|
|
328
|
+
try {
|
|
329
|
+
execSync(`npx --yes eslint --fix ${lib_1.path.basename(absPathToFile)}`, {
|
|
330
|
+
cwd: lib_1.path.dirname(absPathToFile),
|
|
331
|
+
});
|
|
312
332
|
}
|
|
333
|
+
catch (error) { }
|
|
334
|
+
index_1.Helpers.taskDone(`Eslint file fix done.`);
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
};
|
|
338
|
+
UtilsTypescript.eslintFixAllFilesInsideFolder = (absPathToFolder) => {
|
|
339
|
+
//#region @backendFunc
|
|
340
|
+
absPathToFolder = (0, lib_1.crossPlatformPath)(absPathToFolder);
|
|
341
|
+
if (index_1.Helpers.exists(absPathToFolder)) {
|
|
342
|
+
index_1.Helpers.info(`Fixing files with eslint in: ${absPathToFolder}`);
|
|
343
|
+
const lintFixFn = () => {
|
|
344
|
+
try {
|
|
345
|
+
index_1.Helpers.run(`npx --yes eslint --fix . `, {
|
|
346
|
+
cwd: absPathToFolder,
|
|
347
|
+
output: false,
|
|
348
|
+
silence: true,
|
|
349
|
+
}).sync();
|
|
350
|
+
}
|
|
351
|
+
catch (error) { }
|
|
352
|
+
};
|
|
353
|
+
lintFixFn();
|
|
354
|
+
lintFixFn(); // sometimes it needs to be run twice
|
|
355
|
+
index_1.Helpers.info(`Eslint fixing files done.`);
|
|
313
356
|
}
|
|
314
357
|
//#endregion
|
|
315
358
|
};
|
|
@@ -359,14 +402,14 @@ var UtilsTypescript;
|
|
|
359
402
|
};
|
|
360
403
|
UtilsTypescript.getTaonContextsNamesFromFile = (tsAbsFilePath) => {
|
|
361
404
|
//#region @backendFunc
|
|
362
|
-
return UtilsTypescript.getTaonContextFromContent(
|
|
405
|
+
return UtilsTypescript.getTaonContextFromContent(index_1.Helpers.readFile(tsAbsFilePath));
|
|
363
406
|
//#endregion
|
|
364
407
|
};
|
|
365
408
|
//#endregion
|
|
366
409
|
//#region extract selectors from Angular components class files
|
|
367
410
|
UtilsTypescript.extractAngularComponentSelectors = (fileAbsPath) => {
|
|
368
411
|
//#region @backendFunc
|
|
369
|
-
const sourceFile = (0, typescript_1.createSourceFile)(fileAbsPath,
|
|
412
|
+
const sourceFile = (0, typescript_1.createSourceFile)(fileAbsPath, index_1.Helpers.readFile(fileAbsPath), typescript_1.ScriptTarget.Latest, true);
|
|
370
413
|
const selectors = [];
|
|
371
414
|
const visit = (node) => {
|
|
372
415
|
if ((0, typescript_1.isClassDeclaration)(node) && node.name) {
|
|
@@ -406,7 +449,7 @@ var UtilsTypescript;
|
|
|
406
449
|
//#region wrap one line with comment
|
|
407
450
|
UtilsTypescript.wrapWithComment = (oneLineComment, absDestFilePath) => {
|
|
408
451
|
//#region @backendFunc
|
|
409
|
-
const ext =
|
|
452
|
+
const ext = lib_1.path.extname(absDestFilePath).toLowerCase();
|
|
410
453
|
let commentSyntax;
|
|
411
454
|
switch (ext) {
|
|
412
455
|
case '.ts':
|
|
@@ -445,7 +488,7 @@ var UtilsTypescript;
|
|
|
445
488
|
*/
|
|
446
489
|
UtilsTypescript.setValueToVariableInTsFile = (tsAbsFilePath, variableName, valueOfVariable, addIfNotExists = true) => {
|
|
447
490
|
//#region @backendFunc
|
|
448
|
-
const sourceText =
|
|
491
|
+
const sourceText = index_1.Helpers.readFile(tsAbsFilePath);
|
|
449
492
|
const sourceFile = (0, typescript_1.createSourceFile)(tsAbsFilePath, sourceText, typescript_1.ScriptTarget.Latest,
|
|
450
493
|
/*setParentNodes */ true);
|
|
451
494
|
// We'll build an AST transformer that modifies or inserts our variable declaration
|
|
@@ -519,7 +562,7 @@ var UtilsTypescript;
|
|
|
519
562
|
const printer = (0, typescript_1.createPrinter)();
|
|
520
563
|
const newContent = printer.printFile(transformedSourceFile);
|
|
521
564
|
// Overwrite the file
|
|
522
|
-
|
|
565
|
+
index_1.Helpers.writeFile(tsAbsFilePath, newContent);
|
|
523
566
|
result.dispose();
|
|
524
567
|
//#endregion
|
|
525
568
|
};
|
|
@@ -527,31 +570,61 @@ var UtilsTypescript;
|
|
|
527
570
|
//#region recognize imports from file
|
|
528
571
|
//#region helpers / ts import export class
|
|
529
572
|
class TsImportExport {
|
|
573
|
+
/**
|
|
574
|
+
* for external modification
|
|
575
|
+
*/
|
|
576
|
+
embeddedPathToFileResult;
|
|
577
|
+
/**
|
|
578
|
+
* for external modification
|
|
579
|
+
*/
|
|
580
|
+
packageName;
|
|
581
|
+
/**
|
|
582
|
+
* for external modification
|
|
583
|
+
*/
|
|
584
|
+
isIsomorphic;
|
|
585
|
+
//#region generated/readonly files
|
|
530
586
|
type;
|
|
531
587
|
/**
|
|
532
588
|
* ORIGNAL
|
|
533
589
|
* Name of the file that is being imported/exported
|
|
534
|
-
* with parenthesis included
|
|
590
|
+
* with parenthesis included , example
|
|
591
|
+
* 'my-file' or "my-file" or `my-file`
|
|
535
592
|
*/
|
|
536
593
|
embeddedPathToFile;
|
|
537
594
|
/**
|
|
538
|
-
* same as cleanEmbeddedPathToFile but without quotes (parenthesis)
|
|
595
|
+
* same as cleanEmbeddedPathToFile but without quotes (parenthesis), example:
|
|
596
|
+
* my-file or my-file or my-file
|
|
539
597
|
*/
|
|
540
598
|
cleanEmbeddedPathToFile;
|
|
599
|
+
startRow;
|
|
600
|
+
startCol;
|
|
601
|
+
endRow;
|
|
602
|
+
endCol;
|
|
603
|
+
parenthesisType;
|
|
604
|
+
importElements = [];
|
|
605
|
+
//#endregion
|
|
606
|
+
//#region constructor
|
|
607
|
+
constructor(type, embeddedPathToFile, start, end, parenthesisType, importElements = []) {
|
|
608
|
+
this.type = type;
|
|
609
|
+
this.isIsomorphic = false;
|
|
610
|
+
this.embeddedPathToFile = embeddedPathToFile;
|
|
611
|
+
this.cleanEmbeddedPathToFile =
|
|
612
|
+
this.removeStartEndQuotes(embeddedPathToFile);
|
|
613
|
+
this.embeddedPathToFileResult = embeddedPathToFile;
|
|
614
|
+
this.startRow = start.line + 1; // TypeScript lines are zero-based
|
|
615
|
+
this.startCol = start.character + 1;
|
|
616
|
+
this.endRow = end.line + 1;
|
|
617
|
+
this.endCol = end.character + 1;
|
|
618
|
+
this.parenthesisType = parenthesisType;
|
|
619
|
+
this.importElements = importElements;
|
|
620
|
+
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region remove quotes
|
|
541
623
|
removeStartEndQuotes(str) {
|
|
542
624
|
return str.replace(/^['"`]/, '').replace(/['"`]$/, '');
|
|
543
625
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
*/
|
|
547
|
-
embeddedPathToFileResult;
|
|
548
|
-
/**
|
|
549
|
-
* @deprecated use cleanEmbeddedPathToFile
|
|
550
|
-
*/
|
|
551
|
-
packageName;
|
|
552
|
-
isIsomorphic;
|
|
553
|
-
startRow;
|
|
554
|
-
startCol;
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region get string part
|
|
555
628
|
/**
|
|
556
629
|
* it will extract part of the file content
|
|
557
630
|
* that is between startRow, startCol and endRow, endCol
|
|
@@ -588,30 +661,15 @@ var UtilsTypescript;
|
|
|
588
661
|
}
|
|
589
662
|
return extractedLines.join('\n');
|
|
590
663
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
parenthesisType;
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region wrap in current parenthesis
|
|
594
666
|
wrapInParenthesis(str) {
|
|
595
667
|
return this.parenthesisType === 'single'
|
|
596
668
|
? `'${str}'`
|
|
597
669
|
: this.parenthesisType === 'double'
|
|
598
670
|
? `"${str}"`
|
|
599
671
|
: `\`${str}\``;
|
|
600
|
-
|
|
601
|
-
importElements = [];
|
|
602
|
-
constructor(type, embeddedPathToFile, start, end, parenthesisType, importElements = []) {
|
|
603
|
-
this.type = type;
|
|
604
|
-
this.isIsomorphic = false;
|
|
605
|
-
this.embeddedPathToFile = embeddedPathToFile;
|
|
606
|
-
this.cleanEmbeddedPathToFile =
|
|
607
|
-
this.removeStartEndQuotes(embeddedPathToFile);
|
|
608
|
-
this.embeddedPathToFileResult = embeddedPathToFile;
|
|
609
|
-
this.startRow = start.line + 1; // TypeScript lines are zero-based
|
|
610
|
-
this.startCol = start.character + 1;
|
|
611
|
-
this.endRow = end.line + 1;
|
|
612
|
-
this.endCol = end.character + 1;
|
|
613
|
-
this.parenthesisType = parenthesisType;
|
|
614
|
-
this.importElements = importElements;
|
|
672
|
+
//#endregion
|
|
615
673
|
}
|
|
616
674
|
}
|
|
617
675
|
UtilsTypescript.TsImportExport = TsImportExport;
|
|
@@ -644,7 +702,7 @@ var UtilsTypescript;
|
|
|
644
702
|
};
|
|
645
703
|
UtilsTypescript.recognizeImportsFromFile = (fileAbsPAth) => {
|
|
646
704
|
//#region @backendFunc
|
|
647
|
-
const content =
|
|
705
|
+
const content = index_1.Helpers.readFile(fileAbsPAth);
|
|
648
706
|
return UtilsTypescript.recognizeImportsFromContent(content);
|
|
649
707
|
//#endregion
|
|
650
708
|
};
|
|
@@ -694,6 +752,234 @@ var UtilsTypescript;
|
|
|
694
752
|
//#endregion
|
|
695
753
|
};
|
|
696
754
|
//#endregion
|
|
755
|
+
//#region fix standalone ng 19
|
|
756
|
+
/**
|
|
757
|
+
* Transition methods ng18 => ng19
|
|
758
|
+
* Remove standalone:true from component decorator
|
|
759
|
+
* and add standalone: false if not exists
|
|
760
|
+
*/
|
|
761
|
+
function transformComponentStandaloneOption(sourceText) {
|
|
762
|
+
//#region @backendFunc
|
|
763
|
+
const sourceFile = (0, typescript_1.createSourceFile)('temp.ts', sourceText, typescript_1.ScriptTarget.Latest, true, typescript_1.ScriptKind.TS);
|
|
764
|
+
const printer = (0, typescript_1.createPrinter)({ newLine: typescript_1.NewLineKind.LineFeed });
|
|
765
|
+
// @ts-ignore
|
|
766
|
+
const transformerFactory = context => {
|
|
767
|
+
const { factory } = context;
|
|
768
|
+
const visit = node => {
|
|
769
|
+
if ((0, typescript_1.isDecorator)(node) &&
|
|
770
|
+
(0, typescript_1.isCallExpression)(node.expression) &&
|
|
771
|
+
(0, typescript_1.isIdentifier)(node.expression.expression) &&
|
|
772
|
+
node.expression.expression.text === 'Component') {
|
|
773
|
+
const args = node.expression.arguments;
|
|
774
|
+
if (args.length === 1 && (0, typescript_1.isObjectLiteralExpression)(args[0])) {
|
|
775
|
+
const originalProps = args[0].properties;
|
|
776
|
+
const newProps = [];
|
|
777
|
+
let hasStandalone = false;
|
|
778
|
+
let standaloneIsTrue = false;
|
|
779
|
+
for (const prop of originalProps) {
|
|
780
|
+
if ((0, typescript_1.isPropertyAssignment)(prop) &&
|
|
781
|
+
(0, typescript_1.isIdentifier)(prop.name) &&
|
|
782
|
+
prop.name.text === 'standalone') {
|
|
783
|
+
hasStandalone = true;
|
|
784
|
+
if (prop.initializer.kind === typescript_1.SyntaxKind.TrueKeyword) {
|
|
785
|
+
standaloneIsTrue = true;
|
|
786
|
+
continue; // skip it
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
newProps.push(prop);
|
|
790
|
+
}
|
|
791
|
+
if (!hasStandalone) {
|
|
792
|
+
// add standalone: false
|
|
793
|
+
newProps.push(factory.createPropertyAssignment(factory.createIdentifier('standalone'), factory.createFalse()));
|
|
794
|
+
}
|
|
795
|
+
const newArgs = [
|
|
796
|
+
factory.updateObjectLiteralExpression(args[0], newProps),
|
|
797
|
+
];
|
|
798
|
+
const newExpression = factory.updateCallExpression(node.expression, node.expression.expression, undefined, newArgs);
|
|
799
|
+
return factory.updateDecorator(node, newExpression);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return (0, typescript_1.visitEachChild)(node, visit, context);
|
|
803
|
+
};
|
|
804
|
+
return node => (0, typescript_1.visitNode)(node, visit);
|
|
805
|
+
};
|
|
806
|
+
const result = (0, typescript_1.transform)(sourceFile, [transformerFactory]);
|
|
807
|
+
const transformedSourceFile = result.transformed[0];
|
|
808
|
+
const resultText = printer.printFile(transformedSourceFile);
|
|
809
|
+
result.dispose();
|
|
810
|
+
return resultText;
|
|
811
|
+
//#endregion
|
|
812
|
+
}
|
|
813
|
+
UtilsTypescript.transformComponentStandaloneOption = transformComponentStandaloneOption;
|
|
814
|
+
//#endregion
|
|
815
|
+
//#region escape @ in html text
|
|
816
|
+
const escapeAtInHtmlText = (fileContent) => {
|
|
817
|
+
return fileContent.replace(/>([^<@]*?)@([^<]*)</g, (_match, before, after) => {
|
|
818
|
+
return `>${before}@${after}<`;
|
|
819
|
+
});
|
|
820
|
+
};
|
|
821
|
+
UtilsTypescript.fixHtmlTemplatesInDir = (directoryPath) => {
|
|
822
|
+
//#region @backendFunc
|
|
823
|
+
index_1.Helpers.taskStarted(`(before prettier) Fixing HTML templates in`);
|
|
824
|
+
const files = index_1.Helpers.filesFrom(directoryPath, true, false);
|
|
825
|
+
for (const fullPath of files) {
|
|
826
|
+
const file = lib_1.path.basename(fullPath);
|
|
827
|
+
if (index_1.Helpers.exists(fullPath)) {
|
|
828
|
+
const stat = lib_1.fse.statSync(fullPath);
|
|
829
|
+
if (file.endsWith('.html')) {
|
|
830
|
+
const original = index_1.Helpers.readFile(fullPath);
|
|
831
|
+
const fixed = escapeAtInHtmlText(original);
|
|
832
|
+
if (fixed !== original) {
|
|
833
|
+
index_1.Helpers.writeFile(fullPath, fixed);
|
|
834
|
+
console.log(`Html fixed @ -> @: ${fullPath}`);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
index_1.Helpers.taskDone(`(before prettier) Fixing HTML templates done.`);
|
|
840
|
+
//#endregion
|
|
841
|
+
};
|
|
842
|
+
//#endregion
|
|
843
|
+
//#region remove tagged imports/exports
|
|
844
|
+
function removeTaggedImportExport(tsFileContent, tags) {
|
|
845
|
+
//#region @backendFunc
|
|
846
|
+
const sourceFile = (0, typescript_1.createSourceFile)('temp.ts', tsFileContent, typescript_1.ScriptTarget.Latest, true, typescript_1.ScriptKind.TS);
|
|
847
|
+
// debug && console.log(tsFileContent);
|
|
848
|
+
const lines = tsFileContent.split(/\r?\n/);
|
|
849
|
+
const tagRegex = new RegExp(tags
|
|
850
|
+
.map(t => (Array.isArray(t) ? t[0] : t))
|
|
851
|
+
.filter(Boolean)
|
|
852
|
+
.map(lib_2.Utils.escapeStringForRegEx)
|
|
853
|
+
.join('|'), 'i');
|
|
854
|
+
let a = 0;
|
|
855
|
+
for (const statement of sourceFile.statements) {
|
|
856
|
+
// debug && console.log('processing line ' + a++);
|
|
857
|
+
if (!(0, typescript_1.isImportDeclaration)(statement) && !(0, typescript_1.isExportDeclaration)(statement)) {
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
const start = statement.getStart();
|
|
861
|
+
const end = statement.getEnd();
|
|
862
|
+
const startLine = sourceFile.getLineAndCharacterOfPosition(start).line;
|
|
863
|
+
const endLine = sourceFile.getLineAndCharacterOfPosition(end).line;
|
|
864
|
+
// get full text including trailing comments
|
|
865
|
+
const endLineText = lines[endLine]; // ← get real line content from file
|
|
866
|
+
if (!tagRegex.test(endLineText))
|
|
867
|
+
continue;
|
|
868
|
+
// debug &&
|
|
869
|
+
// console.log(`
|
|
870
|
+
// start: ${start}
|
|
871
|
+
// end: ${end}
|
|
872
|
+
// startLine: ${startLine}
|
|
873
|
+
// endLine: ${endLine}
|
|
874
|
+
// endLineText: >> ${endLineText} <<
|
|
875
|
+
// `);
|
|
876
|
+
// console.log('removing line ' + startLine + ' to ' + endLine);
|
|
877
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
878
|
+
const original = lines[i];
|
|
879
|
+
lines[i] = '/* */' + ' '.repeat(Math.max(0, original.length - 4));
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
// debug && console.log('\n\n\n\n');
|
|
883
|
+
const result = lines.join('\n');
|
|
884
|
+
// debug && console.log(result)
|
|
885
|
+
return result;
|
|
886
|
+
//#endregion
|
|
887
|
+
}
|
|
888
|
+
UtilsTypescript.removeTaggedImportExport = removeTaggedImportExport;
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region wrap first imports in region
|
|
891
|
+
UtilsTypescript.wrapFirstImportsInImportsRegion = (fileContent) => {
|
|
892
|
+
//#region @backendFunc
|
|
893
|
+
const importRegionStart = `//#re` + `gion imports`;
|
|
894
|
+
const importRegionEnd = `//#end` + `region`;
|
|
895
|
+
const sourceFile = (0, typescript_1.createSourceFile)('temp.ts', fileContent, typescript_1.ScriptTarget.Latest, true);
|
|
896
|
+
const lines = fileContent.split(/\r?\n/);
|
|
897
|
+
const importDeclarations = [];
|
|
898
|
+
for (const statement of sourceFile.statements) {
|
|
899
|
+
if ((0, typescript_1.isImportDeclaration)(statement)) {
|
|
900
|
+
importDeclarations.push(statement);
|
|
901
|
+
}
|
|
902
|
+
else if ((0, typescript_1.isEmptyStatement)(statement) ||
|
|
903
|
+
((0, typescript_1.isExpressionStatement)(statement) &&
|
|
904
|
+
statement.getFullText(sourceFile).trim() === '')) {
|
|
905
|
+
// skip empty lines or empty statements
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
else {
|
|
909
|
+
break; // stop at first non-import statement
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
if (importDeclarations.length === 0) {
|
|
913
|
+
return fileContent; // nothing to wrap
|
|
914
|
+
}
|
|
915
|
+
const firstImportStart = importDeclarations[0].getFullStart();
|
|
916
|
+
const lastImportEnd = importDeclarations[importDeclarations.length - 1].getEnd();
|
|
917
|
+
// Get the line numbers (1-based)
|
|
918
|
+
const startLine = sourceFile.getLineAndCharacterOfPosition(firstImportStart).line;
|
|
919
|
+
const endLine = sourceFile.getLineAndCharacterOfPosition(lastImportEnd).line;
|
|
920
|
+
const before = lines.slice(0, startLine);
|
|
921
|
+
const importBlock = lines.slice(startLine, endLine + 1);
|
|
922
|
+
const after = lines.slice(endLine + 1);
|
|
923
|
+
return [
|
|
924
|
+
...before,
|
|
925
|
+
importRegionStart,
|
|
926
|
+
...importBlock,
|
|
927
|
+
importRegionEnd,
|
|
928
|
+
...after,
|
|
929
|
+
].join('\n');
|
|
930
|
+
//#endregion
|
|
931
|
+
};
|
|
932
|
+
//#endregion
|
|
933
|
+
//#region wrap entities class fields with region
|
|
934
|
+
const applyEdits = (original, edits) => {
|
|
935
|
+
edits.sort((a, b) => b.pos - a.pos); // apply from end to start
|
|
936
|
+
let result = original;
|
|
937
|
+
for (const edit of edits) {
|
|
938
|
+
result = result.slice(0, edit.pos) + edit.text + result.slice(edit.pos);
|
|
939
|
+
}
|
|
940
|
+
return result;
|
|
941
|
+
};
|
|
942
|
+
/**
|
|
943
|
+
* wrap class field with decorators
|
|
944
|
+
* wrap class methods with decorators
|
|
945
|
+
*/
|
|
946
|
+
function wrapContentClassMembersDecoratorsWithRegion(classFileContent, wrapTag = '@websql') {
|
|
947
|
+
//#region @backendFunc
|
|
948
|
+
const sourceFile = (0, typescript_1.createSourceFile)('temp.ts', classFileContent, typescript_1.ScriptTarget.Latest, true);
|
|
949
|
+
const edits = [];
|
|
950
|
+
const isAlreadyWrapped = (decorator) => {
|
|
951
|
+
const text = decorator.getFullText(sourceFile);
|
|
952
|
+
return (text.includes(`//#reg` + `ion ${wrapTag}`) ||
|
|
953
|
+
text.includes(`//#end` + `reg` + `ion`));
|
|
954
|
+
};
|
|
955
|
+
const visit = (node) => {
|
|
956
|
+
if ((0, typescript_1.isClassDeclaration)(node)) {
|
|
957
|
+
for (const member of node.members) {
|
|
958
|
+
if (!(0, typescript_1.isPropertyDeclaration)(member) && !(0, typescript_1.isMethodDeclaration)(member))
|
|
959
|
+
continue;
|
|
960
|
+
const decorators = (0, typescript_1.canHaveDecorators)(member)
|
|
961
|
+
? (0, typescript_1.getDecorators)(member)
|
|
962
|
+
: undefined;
|
|
963
|
+
if (!decorators || decorators.length === 0)
|
|
964
|
+
continue;
|
|
965
|
+
for (const decorator of decorators) {
|
|
966
|
+
if (isAlreadyWrapped(decorator))
|
|
967
|
+
continue;
|
|
968
|
+
const start = decorator.getStart();
|
|
969
|
+
const end = decorator.getEnd();
|
|
970
|
+
edits.push({ pos: start, text: `\n//#reg` + `ion ${wrapTag}\n` });
|
|
971
|
+
edits.push({ pos: end, text: `\n//#end` + `reg` + `ion` }); // No extra newline
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
(0, typescript_1.forEachChild)(node, visit);
|
|
976
|
+
};
|
|
977
|
+
visit(sourceFile);
|
|
978
|
+
return applyEdits(classFileContent, edits);
|
|
979
|
+
//#endregion
|
|
980
|
+
}
|
|
981
|
+
UtilsTypescript.wrapContentClassMembersDecoratorsWithRegion = wrapContentClassMembersDecoratorsWithRegion;
|
|
982
|
+
//#endregion
|
|
697
983
|
})(UtilsTypescript || (exports.UtilsTypescript = UtilsTypescript = {}));
|
|
698
984
|
//#endregion
|
|
699
985
|
//#region utils http
|
|
@@ -831,9 +1117,9 @@ var UtilsQuickFixes;
|
|
|
831
1117
|
/**
|
|
832
1118
|
* for some reason electron is being bundled - and it is not needed for cli
|
|
833
1119
|
*/
|
|
834
|
-
UtilsQuickFixes.replaceElectronWithNothing = (jsContent) => {
|
|
1120
|
+
UtilsQuickFixes.replaceElectronWithNothing = (jsContent, packageName) => {
|
|
835
1121
|
//#region @backendFunc
|
|
836
|
-
return jsContent.replace(`mod${'ule.exports'} = ${'requ' + 'ire'}("
|
|
1122
|
+
return jsContent.replace(`mod${'ule.exports'} = ${'requ' + 'ire'}("${packageName}");`, '');
|
|
837
1123
|
//#endregion
|
|
838
1124
|
};
|
|
839
1125
|
})(UtilsQuickFixes || (exports.UtilsQuickFixes = UtilsQuickFixes = {}));
|