tnp-helpers 19.0.52 → 19.0.54
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 +168 -265
- package/browser/fesm2022/tnp-helpers.mjs.map +1 -1
- package/browser/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +4 -1
- package/browser/lib/base/classes/base-docker.d.ts +16 -0
- package/browser/lib/base/classes/base-git.d.ts +1 -0
- package/browser/lib/base/classes/base-project.d.ts +2 -0
- package/browser/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +7 -6
- package/browser/lib/build-info._auto-generated_.d.ts +1 -1
- package/browser/lib/utils.d.ts +41 -16
- package/browser/package.json +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js +4 -2
- 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 +4 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker.js +39 -13
- package/lib/base/classes/base-cli-worker/base-cli-worker.js.map +1 -1
- package/lib/base/classes/base-docker.d.ts +15 -0
- package/lib/base/classes/base-docker.js +56 -0
- package/lib/base/classes/base-docker.js.map +1 -0
- package/lib/base/classes/base-git.d.ts +1 -0
- package/lib/base/classes/base-git.js +4 -0
- package/lib/base/classes/base-git.js.map +1 -1
- package/lib/base/classes/base-global-command-line.backend.d.ts +5 -0
- package/lib/base/classes/base-global-command-line.backend.js +129 -33
- package/lib/base/classes/base-global-command-line.backend.js.map +1 -1
- package/lib/base/classes/base-project.d.ts +2 -0
- package/lib/base/classes/base-project.js +61 -57
- package/lib/base/classes/base-project.js.map +1 -1
- package/lib/base/classes/base-vscode.js +7 -1
- package/lib/base/classes/base-vscode.js.map +1 -1
- package/lib/base/tcp-udp-ports/not-assignable-port.entity.js +2 -2
- package/lib/base/tcp-udp-ports/ports.entity.d.ts +1 -1
- package/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +9 -8
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/env/env.angular-node-app.d.ts +2 -0
- package/lib/env/env.angular-node-app.js +4 -2
- package/lib/env/env.angular-node-app.js.map +1 -1
- package/lib/env/env.docs-webapp.d.ts +2 -0
- package/lib/env/env.docs-webapp.js +4 -2
- package/lib/env/env.docs-webapp.js.map +1 -1
- package/lib/env/env.electron-app.d.ts +2 -0
- package/lib/env/env.electron-app.js +4 -2
- package/lib/env/env.electron-app.js.map +1 -1
- package/lib/env/env.mobile-app.d.ts +2 -0
- package/lib/env/env.mobile-app.js +4 -2
- package/lib/env/env.mobile-app.js.map +1 -1
- package/lib/env/env.npm-lib-and-cli-tool.d.ts +2 -0
- package/lib/env/env.npm-lib-and-cli-tool.js +4 -2
- package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
- package/lib/env/env.vscode-plugin.d.ts +2 -0
- package/lib/env/env.vscode-plugin.js +4 -2
- package/lib/env/env.vscode-plugin.js.map +1 -1
- package/lib/helpers/for-backend/helpers-file-folders.js +1 -1
- package/lib/helpers/for-backend/helpers-file-folders.js.map +1 -1
- package/lib/helpers/for-backend/helpers-git.backend.js +14 -4
- package/lib/helpers/for-backend/helpers-git.backend.js.map +1 -1
- package/lib/helpers/for-browser/angular.helper.js +2 -2
- 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/utils.d.ts +41 -16
- package/lib/utils.js +124 -229
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
- package/websql/fesm2022/tnp-helpers.mjs +168 -265
- package/websql/fesm2022/tnp-helpers.mjs.map +1 -1
- package/websql/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +4 -1
- package/websql/lib/base/classes/base-docker.d.ts +16 -0
- package/websql/lib/base/classes/base-git.d.ts +1 -0
- package/websql/lib/base/classes/base-project.d.ts +2 -0
- package/websql/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +7 -6
- package/websql/lib/build-info._auto-generated_.d.ts +1 -1
- package/websql/lib/utils.d.ts +41 -16
- package/websql/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UtilsPasswords = exports.UtilsJava = exports.UtilsTaonWorker = exports.UtilsZip = exports.UtilsZipBrowser = exports.
|
|
3
|
+
exports.UtilsCliMethod = exports.FilePathMetaData = exports.UtilsPasswords = exports.UtilsJava = exports.UtilsTaonWorker = exports.UtilsZip = exports.UtilsZipBrowser = exports.UtilsVSCode = exports.UtilsQuickFixes = exports.UtilsMd = exports.UtilsHttp = exports.UtilsTypescript = exports.UtilsNpm = void 0;
|
|
4
4
|
//#region imports
|
|
5
5
|
const node_crypto_1 = require("node:crypto"); // @backend
|
|
6
6
|
const lib_1 = require("tnp-config/lib");
|
|
7
7
|
const lib_2 = require("tnp-core/lib");
|
|
8
8
|
const lib_3 = require("tnp-core/lib");
|
|
9
9
|
const typescript_1 = require("typescript");
|
|
10
|
+
const lib_4 = require("typescript-class-helpers/lib");
|
|
10
11
|
const index_1 = require("./index");
|
|
11
12
|
//#endregion
|
|
12
13
|
//#region utils npm
|
|
@@ -1267,226 +1268,6 @@ var UtilsVSCode;
|
|
|
1267
1268
|
};
|
|
1268
1269
|
})(UtilsVSCode || (exports.UtilsVSCode = UtilsVSCode = {}));
|
|
1269
1270
|
//#endregion
|
|
1270
|
-
//#region utils dot file
|
|
1271
|
-
var UtilsDotFile;
|
|
1272
|
-
(function (UtilsDotFile) {
|
|
1273
|
-
//#region parse value from dot file util
|
|
1274
|
-
const parseValue = (rawValue) => {
|
|
1275
|
-
const val = rawValue.trim().replace(/^"|"$/g, '');
|
|
1276
|
-
// Try boolean
|
|
1277
|
-
if (val.toLowerCase() === 'true')
|
|
1278
|
-
return true;
|
|
1279
|
-
if (val.toLowerCase() === 'false')
|
|
1280
|
-
return false;
|
|
1281
|
-
// Try number
|
|
1282
|
-
if (!isNaN(Number(val)) && val !== '')
|
|
1283
|
-
return Number(val);
|
|
1284
|
-
return val;
|
|
1285
|
-
};
|
|
1286
|
-
//#endregion
|
|
1287
|
-
//#region set value to/from dot file
|
|
1288
|
-
UtilsDotFile.setValueToDotFile = (dotFileAbsPath, key, value) => {
|
|
1289
|
-
//#region @backendFunc
|
|
1290
|
-
dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
|
|
1291
|
-
let envContent = '';
|
|
1292
|
-
if (lib_2.fse.existsSync(dotFileAbsPath)) {
|
|
1293
|
-
envContent = index_1.Helpers.readFile(dotFileAbsPath, '');
|
|
1294
|
-
}
|
|
1295
|
-
else {
|
|
1296
|
-
// Create file if it doesn't exist
|
|
1297
|
-
index_1.Helpers.writeFile(dotFileAbsPath, '');
|
|
1298
|
-
index_1.Helpers.logInfo(`[${lib_1.config.frameworkName}-helpers] Created ${lib_2.path.basename(dotFileAbsPath)}`);
|
|
1299
|
-
envContent = '';
|
|
1300
|
-
}
|
|
1301
|
-
const regex = new RegExp(`^${key}=.*$`, 'm');
|
|
1302
|
-
if (regex.test(envContent)) {
|
|
1303
|
-
// Replace existing
|
|
1304
|
-
envContent = envContent.replace(regex, `${key}=${value}`);
|
|
1305
|
-
}
|
|
1306
|
-
else {
|
|
1307
|
-
// Append new
|
|
1308
|
-
if (envContent.length > 0 && !envContent.endsWith('\n')) {
|
|
1309
|
-
envContent += '\n';
|
|
1310
|
-
}
|
|
1311
|
-
envContent += `${key}=${value}\n`;
|
|
1312
|
-
}
|
|
1313
|
-
index_1.Helpers.writeFile(dotFileAbsPath, envContent);
|
|
1314
|
-
index_1.Helpers.info(`[${lib_1.config.frameworkName}-helpers] Updated ${lib_2.path.basename(dotFileAbsPath)}: ${key}=${value}`);
|
|
1315
|
-
//#endregion
|
|
1316
|
-
};
|
|
1317
|
-
//#endregion
|
|
1318
|
-
//#region set comment to key in dot file
|
|
1319
|
-
UtilsDotFile.setCommentToKeyInDotFile = (dotFileAbsPath, key, comment) => {
|
|
1320
|
-
//#region @backendFunc
|
|
1321
|
-
dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
|
|
1322
|
-
let envContent = '';
|
|
1323
|
-
if (lib_2.fse.existsSync(dotFileAbsPath)) {
|
|
1324
|
-
envContent = index_1.Helpers.readFile(dotFileAbsPath, '');
|
|
1325
|
-
}
|
|
1326
|
-
else {
|
|
1327
|
-
index_1.Helpers.writeFile(dotFileAbsPath, '');
|
|
1328
|
-
index_1.Helpers.logInfo(`[${lib_1.config.frameworkName}-helpers] Created ${lib_2.path.basename(dotFileAbsPath)}`);
|
|
1329
|
-
envContent = '';
|
|
1330
|
-
}
|
|
1331
|
-
// Regex: match line starting with "KEY=" and capture value part
|
|
1332
|
-
const regex = new RegExp(`^(${key}=[^#\\n]*)(?:#.*)?$`, 'm');
|
|
1333
|
-
if (regex.test(envContent)) {
|
|
1334
|
-
// Replace existing comment (strip old, append new)
|
|
1335
|
-
envContent = envContent.replace(regex, `$1 # ${comment}`);
|
|
1336
|
-
}
|
|
1337
|
-
else {
|
|
1338
|
-
// Append as new entry with empty value but with comment
|
|
1339
|
-
if (envContent.length > 0 && !envContent.endsWith('\n')) {
|
|
1340
|
-
envContent += '\n';
|
|
1341
|
-
}
|
|
1342
|
-
envContent += `${key}= # ${comment}\n`;
|
|
1343
|
-
}
|
|
1344
|
-
index_1.Helpers.writeFile(dotFileAbsPath, envContent);
|
|
1345
|
-
index_1.Helpers.info(`[${lib_1.config.frameworkName}-helpers] Updated comment for ${key} in ${lib_2.path.basename(dotFileAbsPath)}`);
|
|
1346
|
-
//#endregion
|
|
1347
|
-
};
|
|
1348
|
-
//#endregion
|
|
1349
|
-
//#region get value from dot file
|
|
1350
|
-
UtilsDotFile.getValueFromDotFile = (dotFileAbsPath, key) => {
|
|
1351
|
-
//#region @backendFunc
|
|
1352
|
-
dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
|
|
1353
|
-
if (!lib_2.fse.existsSync(dotFileAbsPath)) {
|
|
1354
|
-
index_1.Helpers.warn(`[${lib_1.config.frameworkName}-helpers] File ${lib_2.path.basename(dotFileAbsPath)} does not exist.`);
|
|
1355
|
-
return;
|
|
1356
|
-
}
|
|
1357
|
-
const envContent = lib_2.fse.readFileSync(dotFileAbsPath, 'utf-8');
|
|
1358
|
-
// Parse line by line
|
|
1359
|
-
const lines = envContent.split(/\r?\n/);
|
|
1360
|
-
for (const line of lines) {
|
|
1361
|
-
const trimmed = line.trim();
|
|
1362
|
-
if (!trimmed || trimmed.startsWith('#'))
|
|
1363
|
-
continue;
|
|
1364
|
-
const [k, ...rest] = trimmed.split('=');
|
|
1365
|
-
if (k === key) {
|
|
1366
|
-
return parseValue(rest.join('='));
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
//#endregion
|
|
1370
|
-
};
|
|
1371
|
-
//#endregion
|
|
1372
|
-
//#region set values keys from object
|
|
1373
|
-
UtilsDotFile.setValuesKeysFromObject = (dotFileAbsPath, obj, options) => {
|
|
1374
|
-
//#region @backendFunc
|
|
1375
|
-
dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
|
|
1376
|
-
options = options || {};
|
|
1377
|
-
let envContent = options.setAsNewFile
|
|
1378
|
-
? ''
|
|
1379
|
-
: index_1.Helpers.readFile(dotFileAbsPath, '');
|
|
1380
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
1381
|
-
const stringValue = String(value);
|
|
1382
|
-
const regex = new RegExp(`^${key}=.*$`, 'm');
|
|
1383
|
-
if (regex.test(envContent)) {
|
|
1384
|
-
envContent = envContent.replace(regex, `${key}=${stringValue}`);
|
|
1385
|
-
}
|
|
1386
|
-
else {
|
|
1387
|
-
if (envContent.length > 0 && !envContent.endsWith('\n')) {
|
|
1388
|
-
envContent += '\n';
|
|
1389
|
-
}
|
|
1390
|
-
envContent += `${key}=${stringValue}\n`;
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
index_1.Helpers.writeFile(dotFileAbsPath, envContent);
|
|
1394
|
-
//#endregion
|
|
1395
|
-
};
|
|
1396
|
-
//#endregion
|
|
1397
|
-
//#region get values keys as json object
|
|
1398
|
-
UtilsDotFile.getValuesKeysAsJsonObject = (dotFileAbsPath) => {
|
|
1399
|
-
//#region @backendFunc
|
|
1400
|
-
dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
|
|
1401
|
-
if (!index_1.Helpers.exists(dotFileAbsPath)) {
|
|
1402
|
-
return {};
|
|
1403
|
-
}
|
|
1404
|
-
const envContent = index_1.Helpers.readFile(dotFileAbsPath, '');
|
|
1405
|
-
const result = {};
|
|
1406
|
-
const lines = envContent.split(/\r?\n/);
|
|
1407
|
-
for (const line of lines) {
|
|
1408
|
-
const trimmed = line.trim();
|
|
1409
|
-
if (!trimmed || trimmed.startsWith('#'))
|
|
1410
|
-
continue;
|
|
1411
|
-
const [key, ...rest] = trimmed.split('=');
|
|
1412
|
-
if (key) {
|
|
1413
|
-
result[key] = parseValue(rest.join('='));
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
return result;
|
|
1417
|
-
//#endregion
|
|
1418
|
-
};
|
|
1419
|
-
//#endregion
|
|
1420
|
-
//#region get comments keys as json object
|
|
1421
|
-
/**
|
|
1422
|
-
* @returns key|comment pairs as json object
|
|
1423
|
-
*/
|
|
1424
|
-
UtilsDotFile.getCommentsKeysAsJsonObject = (dotFileAbsPath) => {
|
|
1425
|
-
//#region @backendFunc
|
|
1426
|
-
dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
|
|
1427
|
-
if (!index_1.Helpers.exists(dotFileAbsPath)) {
|
|
1428
|
-
return {};
|
|
1429
|
-
}
|
|
1430
|
-
const envContent = index_1.Helpers.readFile(dotFileAbsPath, '');
|
|
1431
|
-
const result = {};
|
|
1432
|
-
const lines = envContent.split(/\r?\n/);
|
|
1433
|
-
const extractInlineComment = (valuePart) => {
|
|
1434
|
-
// Find the first unquoted `#`
|
|
1435
|
-
let inSingle = false;
|
|
1436
|
-
let inDouble = false;
|
|
1437
|
-
let escaped = false;
|
|
1438
|
-
for (let i = 0; i < valuePart.length; i++) {
|
|
1439
|
-
const ch = valuePart[i];
|
|
1440
|
-
if (escaped) {
|
|
1441
|
-
escaped = false;
|
|
1442
|
-
continue;
|
|
1443
|
-
}
|
|
1444
|
-
if (ch === '\\') {
|
|
1445
|
-
escaped = true;
|
|
1446
|
-
continue;
|
|
1447
|
-
}
|
|
1448
|
-
if (!inDouble && ch === "'") {
|
|
1449
|
-
inSingle = !inSingle;
|
|
1450
|
-
continue;
|
|
1451
|
-
}
|
|
1452
|
-
if (!inSingle && ch === '"') {
|
|
1453
|
-
inDouble = !inDouble;
|
|
1454
|
-
continue;
|
|
1455
|
-
}
|
|
1456
|
-
if (!inSingle && !inDouble && ch === '#') {
|
|
1457
|
-
// Everything after '#' is the comment
|
|
1458
|
-
const raw = valuePart.slice(i + 1);
|
|
1459
|
-
const comment = raw.replace(/^\s+/, ''); // trim only leading spaces after '#'
|
|
1460
|
-
return comment.length ? comment : '';
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
return undefined;
|
|
1464
|
-
};
|
|
1465
|
-
for (const line of lines) {
|
|
1466
|
-
const raw = line;
|
|
1467
|
-
const trimmed = raw.trim();
|
|
1468
|
-
// Skip empty or full-line comments
|
|
1469
|
-
if (!trimmed || trimmed.startsWith('#'))
|
|
1470
|
-
continue;
|
|
1471
|
-
// Support optional leading `export `
|
|
1472
|
-
const withoutExport = trimmed.startsWith('export ')
|
|
1473
|
-
? trimmed.slice('export '.length).trim()
|
|
1474
|
-
: trimmed;
|
|
1475
|
-
const eqIdx = withoutExport.indexOf('=');
|
|
1476
|
-
if (eqIdx === -1)
|
|
1477
|
-
continue;
|
|
1478
|
-
const key = withoutExport.slice(0, eqIdx).trim();
|
|
1479
|
-
if (!key)
|
|
1480
|
-
continue;
|
|
1481
|
-
const valuePart = withoutExport.slice(eqIdx + 1);
|
|
1482
|
-
result[key] = extractInlineComment(valuePart);
|
|
1483
|
-
}
|
|
1484
|
-
return result;
|
|
1485
|
-
//#endregion
|
|
1486
|
-
};
|
|
1487
|
-
//#endregion
|
|
1488
|
-
})(UtilsDotFile || (exports.UtilsDotFile = UtilsDotFile = {}));
|
|
1489
|
-
//#endregion
|
|
1490
1271
|
//#region utils zip browser
|
|
1491
1272
|
var UtilsZipBrowser;
|
|
1492
1273
|
(function (UtilsZipBrowser) {
|
|
@@ -1638,20 +1419,20 @@ var UtilsZip;
|
|
|
1638
1419
|
*/
|
|
1639
1420
|
UtilsZip.zipDir = async (absPathToDir, options) => {
|
|
1640
1421
|
//#region @backendFunc
|
|
1641
|
-
const zipPath = `${absPathToDir}.zip`;
|
|
1642
|
-
const
|
|
1422
|
+
const zipPath = `${lib_2.path.basename(absPathToDir)}.zip`;
|
|
1423
|
+
const destinationFilePath = (0, lib_2.crossPlatformPath)([
|
|
1643
1424
|
lib_2.path.dirname(absPathToDir),
|
|
1644
1425
|
zipPath,
|
|
1645
1426
|
]);
|
|
1646
1427
|
if (options.overrideIfZipFileExists) {
|
|
1647
1428
|
try {
|
|
1648
|
-
index_1.Helpers.removeFileIfExists(
|
|
1429
|
+
index_1.Helpers.removeFileIfExists(destinationFilePath);
|
|
1649
1430
|
}
|
|
1650
1431
|
catch (error) { }
|
|
1651
1432
|
}
|
|
1652
|
-
if (index_1.Helpers.exists(
|
|
1653
|
-
index_1.Helpers.info(`[${lib_1.config.frameworkName}-helpers] Zip file already exists: ${
|
|
1654
|
-
return
|
|
1433
|
+
if (index_1.Helpers.exists(destinationFilePath)) {
|
|
1434
|
+
index_1.Helpers.info(`[${lib_1.config.frameworkName}-helpers] Zip file already exists: ${destinationFilePath}`);
|
|
1435
|
+
return destinationFilePath;
|
|
1655
1436
|
}
|
|
1656
1437
|
const yazl = await Promise.resolve().then(() => require('yazl')); // Use default import for yazl
|
|
1657
1438
|
const pipeline = (await Promise.resolve().then(() => require('stream/promises'))).pipeline;
|
|
@@ -1671,8 +1452,8 @@ var UtilsZip;
|
|
|
1671
1452
|
};
|
|
1672
1453
|
await addDirectoryToZip(absPathToDir, absPathToDir);
|
|
1673
1454
|
zipfile.end();
|
|
1674
|
-
await pipeline(zipfile.outputStream, lib_2.fse.createWriteStream(
|
|
1675
|
-
return
|
|
1455
|
+
await pipeline(zipfile.outputStream, lib_2.fse.createWriteStream(destinationFilePath));
|
|
1456
|
+
return destinationFilePath;
|
|
1676
1457
|
//#endregion;
|
|
1677
1458
|
};
|
|
1678
1459
|
// Unzip: `/some/path/folder.zip` → `/some/path/folder`
|
|
@@ -2111,4 +1892,118 @@ var UtilsPasswords;
|
|
|
2111
1892
|
// })();
|
|
2112
1893
|
})(UtilsPasswords || (exports.UtilsPasswords = UtilsPasswords = {}));
|
|
2113
1894
|
//#endregion
|
|
1895
|
+
//#region utils filepath metadata
|
|
1896
|
+
var FilePathMetaData;
|
|
1897
|
+
(function (FilePathMetaData) {
|
|
1898
|
+
const TERMINATOR = 'xxxxx'; // terminates metadata block
|
|
1899
|
+
const KV_SEPARATOR = '...'; // key/value separator
|
|
1900
|
+
const PAIR_SEPARATOR = 'IxIxI'; // between pairs
|
|
1901
|
+
//#region embed data into filename
|
|
1902
|
+
/**
|
|
1903
|
+
* Embed metadata into filename while preserving the extension.
|
|
1904
|
+
*
|
|
1905
|
+
* Example:
|
|
1906
|
+
* embedData({ version: "1.2.3", envName: "__" }, "project.zip")
|
|
1907
|
+
* -> "version|-|1.2.3||--||envName|-|__|||project.zip"
|
|
1908
|
+
*/
|
|
1909
|
+
function embedData(data, orgFilename, options) {
|
|
1910
|
+
options = options || {};
|
|
1911
|
+
const ext = lib_2.path.extname(orgFilename);
|
|
1912
|
+
const base = lib_2.path.basename(orgFilename, ext);
|
|
1913
|
+
const meta = Object.entries(data)
|
|
1914
|
+
.map(([key, value]) => `${key}${KV_SEPARATOR}${value ?? ''}`)
|
|
1915
|
+
.join(PAIR_SEPARATOR);
|
|
1916
|
+
return `${meta}${TERMINATOR}${options.skipAddingBasenameAtEnd ? '' : base}${ext}`;
|
|
1917
|
+
}
|
|
1918
|
+
FilePathMetaData.embedData = embedData;
|
|
1919
|
+
//#endregion
|
|
1920
|
+
//#region extract data from filename
|
|
1921
|
+
/**
|
|
1922
|
+
* Extract metadata from filename (reverse of embedData).
|
|
1923
|
+
*
|
|
1924
|
+
* Example:
|
|
1925
|
+
* extractData<{ version: string; env: string }>("myfile__version-1.2.3__env-prod.zip")
|
|
1926
|
+
* -> { version: "1.2.3", env: "prod" }
|
|
1927
|
+
*/
|
|
1928
|
+
function extractData(filename) {
|
|
1929
|
+
const ext = lib_2.path.extname(filename);
|
|
1930
|
+
const thereIsNoExt = ext.includes('|') || ext.includes('-');
|
|
1931
|
+
const base = thereIsNoExt ? filename : lib_2.path.basename(filename, ext);
|
|
1932
|
+
// Everything BEFORE the FIRST TERMINATOR
|
|
1933
|
+
const idx = base.lastIndexOf(TERMINATOR);
|
|
1934
|
+
const metaPart = idx >= 0 ? base.substring(0, idx) : base;
|
|
1935
|
+
const data = {};
|
|
1936
|
+
let cursor = 0;
|
|
1937
|
+
while (cursor <= metaPart.length) {
|
|
1938
|
+
const sepIdx = metaPart.indexOf(PAIR_SEPARATOR, cursor);
|
|
1939
|
+
const segment = sepIdx === -1
|
|
1940
|
+
? metaPart.substring(cursor)
|
|
1941
|
+
: metaPart.substring(cursor, sepIdx);
|
|
1942
|
+
if (segment) {
|
|
1943
|
+
const kvIdx = segment.indexOf(KV_SEPARATOR);
|
|
1944
|
+
if (kvIdx > -1) {
|
|
1945
|
+
const key = segment.substring(0, kvIdx);
|
|
1946
|
+
const value = segment.substring(kvIdx + KV_SEPARATOR.length);
|
|
1947
|
+
data[key] = value;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
if (sepIdx === -1)
|
|
1951
|
+
break;
|
|
1952
|
+
cursor = sepIdx + PAIR_SEPARATOR.length;
|
|
1953
|
+
}
|
|
1954
|
+
return data;
|
|
1955
|
+
}
|
|
1956
|
+
FilePathMetaData.extractData = extractData;
|
|
1957
|
+
//#endregion
|
|
1958
|
+
//#region get only metadata string
|
|
1959
|
+
FilePathMetaData.getOnlyMetadataString = (filename) => {
|
|
1960
|
+
const ext = lib_2.path.extname(filename);
|
|
1961
|
+
const base = lib_2.path.basename(filename, ext);
|
|
1962
|
+
const idx = base.lastIndexOf(TERMINATOR);
|
|
1963
|
+
if (idx === -1)
|
|
1964
|
+
return ''; // no terminator
|
|
1965
|
+
const metaPart = base.substring(0, idx);
|
|
1966
|
+
if (!metaPart.trim())
|
|
1967
|
+
return ''; // empty metadata
|
|
1968
|
+
return metaPart;
|
|
1969
|
+
};
|
|
1970
|
+
//#endregion
|
|
1971
|
+
})(FilePathMetaData || (exports.FilePathMetaData = FilePathMetaData = {}));
|
|
1972
|
+
//#endregion
|
|
1973
|
+
//#region utils cli
|
|
1974
|
+
/**
|
|
1975
|
+
* Easy way to connect CLI commands to cli class methods.
|
|
1976
|
+
*
|
|
1977
|
+
* Example:
|
|
1978
|
+
* in clic class
|
|
1979
|
+
* $FirstCli {
|
|
1980
|
+
*
|
|
1981
|
+
* @UtilsCliMethod.decorator('doSomething')
|
|
1982
|
+
* doSomething() {
|
|
1983
|
+
* console.log('doing something');
|
|
1984
|
+
* }
|
|
1985
|
+
* }
|
|
1986
|
+
*
|
|
1987
|
+
* UtilsCliMethod.getFrom($FirstCli.prototype.doSomething) // "firstcli:dosomething"
|
|
1988
|
+
*
|
|
1989
|
+
*/
|
|
1990
|
+
var UtilsCliMethod;
|
|
1991
|
+
(function (UtilsCliMethod) {
|
|
1992
|
+
const CLI_METHOD_KEY = Symbol('cliMethod');
|
|
1993
|
+
UtilsCliMethod.decorator = (methodName) => {
|
|
1994
|
+
return (target, propertyKey, descriptor) => {
|
|
1995
|
+
// If name not given, fallback to property key
|
|
1996
|
+
Reflect.defineMetadata(CLI_METHOD_KEY, `${lib_3._.camelCase(lib_4.CLASS.getName(target?.constructor)).toLowerCase()}` +
|
|
1997
|
+
`:${lib_3._.camelCase(methodName ?? propertyKey).toLowerCase()}`, descriptor.value);
|
|
1998
|
+
};
|
|
1999
|
+
};
|
|
2000
|
+
UtilsCliMethod.getFrom = (ClassPrototypeMethodFnHere, globalMethod = false) => {
|
|
2001
|
+
const fullCliMethodName = Reflect.getMetadata(CLI_METHOD_KEY, ClassPrototypeMethodFnHere);
|
|
2002
|
+
if (globalMethod) {
|
|
2003
|
+
return fullCliMethodName.split(':')[1];
|
|
2004
|
+
}
|
|
2005
|
+
return fullCliMethodName;
|
|
2006
|
+
};
|
|
2007
|
+
})(UtilsCliMethod || (exports.UtilsCliMethod = UtilsCliMethod = {}));
|
|
2008
|
+
//#endregion
|
|
2114
2009
|
//# sourceMappingURL=utils.js.map
|