tnp-helpers 19.0.44 → 19.0.46

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.
Files changed (72) hide show
  1. package/browser/fesm2022/tnp-helpers.mjs +703 -124
  2. package/browser/fesm2022/tnp-helpers.mjs.map +1 -1
  3. package/browser/lib/base/classes/base-cli-worker/base-cli-worker-database-config.d.ts +10 -0
  4. package/browser/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +10 -9
  5. package/browser/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +9 -3
  6. package/browser/lib/base/classes/base-cli-worker/index.d.ts +1 -0
  7. package/browser/lib/base/classes/base-java-jdk.d.ts +1 -1
  8. package/browser/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.d.ts +2 -2
  9. package/browser/lib/build-info._auto-generated_.d.ts +1 -1
  10. package/browser/lib/helpers/for-backend/helpers-file-folders.d.ts +1 -1
  11. package/browser/lib/models.d.ts +0 -2
  12. package/browser/lib/utils.d.ts +51 -29
  13. package/browser/package.json +1 -1
  14. package/lib/base/classes/base-cli-worker/base-cli-worker-database-config.d.ts +14 -0
  15. package/lib/base/classes/base-cli-worker/base-cli-worker-database-config.js +31 -0
  16. package/lib/base/classes/base-cli-worker/base-cli-worker-database-config.js.map +1 -0
  17. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +11 -10
  18. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js +3 -15
  19. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js.map +1 -1
  20. package/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +9 -3
  21. package/lib/base/classes/base-cli-worker/base-cli-worker.js +32 -10
  22. package/lib/base/classes/base-cli-worker/base-cli-worker.js.map +1 -1
  23. package/lib/base/classes/base-cli-worker/index.d.ts +1 -0
  24. package/lib/base/classes/base-cli-worker/index.js +1 -0
  25. package/lib/base/classes/base-cli-worker/index.js.map +1 -1
  26. package/lib/base/classes/base-global-command-line.backend.d.ts +5 -0
  27. package/lib/base/classes/base-global-command-line.backend.js +156 -7
  28. package/lib/base/classes/base-global-command-line.backend.js.map +1 -1
  29. package/lib/base/classes/base-java-jdk.d.ts +1 -1
  30. package/lib/base/classes/base-java-jdk.js +5 -261
  31. package/lib/base/classes/base-java-jdk.js.map +1 -1
  32. package/lib/base/classes/base-project.js +6 -2
  33. package/lib/base/classes/base-project.js.map +1 -1
  34. package/lib/base/classes/base-release-process.js +2 -2
  35. package/lib/base/classes/base-release-process.js.map +1 -1
  36. package/lib/base/core-project.js +0 -2
  37. package/lib/base/core-project.js.map +1 -1
  38. package/lib/base/tcp-udp-ports/not-assignable-port.entity.js +2 -2
  39. package/lib/base/tcp-udp-ports/tcp-udp-ports.context.js +2 -18
  40. package/lib/base/tcp-udp-ports/tcp-udp-ports.context.js.map +1 -1
  41. package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.d.ts +3 -3
  42. package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js +15 -5
  43. package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js.map +1 -1
  44. package/lib/build-info._auto-generated_.d.ts +1 -1
  45. package/lib/build-info._auto-generated_.js +1 -1
  46. package/lib/helpers/for-backend/helpers-file-folders.d.ts +1 -1
  47. package/lib/helpers/for-backend/helpers-file-folders.js +2 -0
  48. package/lib/helpers/for-backend/helpers-file-folders.js.map +1 -1
  49. package/lib/helpers/for-browser/angular.helper.js +2 -2
  50. package/lib/models.d.ts +0 -2
  51. package/lib/models.js.map +1 -1
  52. package/lib/old/base-component.js +2 -2
  53. package/lib/old/base-formly-component.js +2 -2
  54. package/lib/old/dual-component-ctrl.js +2 -2
  55. package/lib/utils.d.ts +51 -29
  56. package/lib/utils.js +476 -4
  57. package/lib/utils.js.map +1 -1
  58. package/package.json +1 -1
  59. package/tmp-environment.json +11 -7
  60. package/websql/fesm2022/tnp-helpers.mjs +703 -124
  61. package/websql/fesm2022/tnp-helpers.mjs.map +1 -1
  62. package/websql/lib/base/classes/base-cli-worker/base-cli-worker-database-config.d.ts +10 -0
  63. package/websql/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +10 -9
  64. package/websql/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +9 -3
  65. package/websql/lib/base/classes/base-cli-worker/index.d.ts +1 -0
  66. package/websql/lib/base/classes/base-java-jdk.d.ts +1 -1
  67. package/websql/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.d.ts +2 -2
  68. package/websql/lib/build-info._auto-generated_.d.ts +1 -1
  69. package/websql/lib/helpers/for-backend/helpers-file-folders.d.ts +1 -1
  70. package/websql/lib/models.d.ts +0 -2
  71. package/websql/lib/utils.d.ts +51 -29
  72. package/websql/package.json +1 -1
package/lib/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UtilsZip = exports.UtilsZipBrowser = exports.UtilsDotFile = exports.UtilsVSCode = exports.UtilsQuickFixes = exports.UtilsMd = exports.UtilsHttp = exports.UtilsTypescript = exports.UtilsNpm = void 0;
3
+ exports.UtilsJava = exports.UtilsTaonWorker = exports.UtilsZip = exports.UtilsZipBrowser = exports.UtilsDotFile = exports.UtilsVSCode = exports.UtilsQuickFixes = exports.UtilsMd = exports.UtilsHttp = exports.UtilsTypescript = exports.UtilsNpm = void 0;
4
4
  //#region imports
5
5
  const lib_1 = require("tnp-config/lib");
6
6
  const lib_2 = require("tnp-core/lib");
@@ -1255,7 +1255,7 @@ var UtilsDotFile;
1255
1255
  };
1256
1256
  //#endregion
1257
1257
  //#region set value to/from dot file
1258
- UtilsDotFile.setValueToDotFile = (dotFileAbsPath, value, key) => {
1258
+ UtilsDotFile.setValueToDotFile = (dotFileAbsPath, key, value) => {
1259
1259
  //#region @backendFunc
1260
1260
  dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
1261
1261
  let envContent = '';
@@ -1285,6 +1285,37 @@ var UtilsDotFile;
1285
1285
  //#endregion
1286
1286
  };
1287
1287
  //#endregion
1288
+ //#region set comment to key in dot file
1289
+ UtilsDotFile.setCommentToKeyInDotFile = (dotFileAbsPath, key, comment) => {
1290
+ //#region @backendFunc
1291
+ dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
1292
+ let envContent = '';
1293
+ if (lib_2.fse.existsSync(dotFileAbsPath)) {
1294
+ envContent = index_1.Helpers.readFile(dotFileAbsPath, '');
1295
+ }
1296
+ else {
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
+ // Regex: match line starting with "KEY=" and capture value part
1302
+ const regex = new RegExp(`^(${key}=[^#\\n]*)(?:#.*)?$`, 'm');
1303
+ if (regex.test(envContent)) {
1304
+ // Replace existing comment (strip old, append new)
1305
+ envContent = envContent.replace(regex, `$1 # ${comment}`);
1306
+ }
1307
+ else {
1308
+ // Append as new entry with empty value but with comment
1309
+ if (envContent.length > 0 && !envContent.endsWith('\n')) {
1310
+ envContent += '\n';
1311
+ }
1312
+ envContent += `${key}= # ${comment}\n`;
1313
+ }
1314
+ index_1.Helpers.writeFile(dotFileAbsPath, envContent);
1315
+ index_1.Helpers.info(`[${lib_1.config.frameworkName}-helpers] Updated comment for ${key} in ${lib_2.path.basename(dotFileAbsPath)}`);
1316
+ //#endregion
1317
+ };
1318
+ //#endregion
1288
1319
  //#region get value from dot file
1289
1320
  UtilsDotFile.getValueFromDotFile = (dotFileAbsPath, key) => {
1290
1321
  //#region @backendFunc
@@ -1356,6 +1387,74 @@ var UtilsDotFile;
1356
1387
  //#endregion
1357
1388
  };
1358
1389
  //#endregion
1390
+ //#region get comments keys as json object
1391
+ /**
1392
+ * @returns key|comment pairs as json object
1393
+ */
1394
+ UtilsDotFile.getCommentsKeysAsJsonObject = (dotFileAbsPath) => {
1395
+ //#region @backendFunc
1396
+ dotFileAbsPath = (0, lib_2.crossPlatformPath)(dotFileAbsPath);
1397
+ if (!index_1.Helpers.exists(dotFileAbsPath)) {
1398
+ return {};
1399
+ }
1400
+ const envContent = index_1.Helpers.readFile(dotFileAbsPath, '');
1401
+ const result = {};
1402
+ const lines = envContent.split(/\r?\n/);
1403
+ const extractInlineComment = (valuePart) => {
1404
+ // Find the first unquoted `#`
1405
+ let inSingle = false;
1406
+ let inDouble = false;
1407
+ let escaped = false;
1408
+ for (let i = 0; i < valuePart.length; i++) {
1409
+ const ch = valuePart[i];
1410
+ if (escaped) {
1411
+ escaped = false;
1412
+ continue;
1413
+ }
1414
+ if (ch === '\\') {
1415
+ escaped = true;
1416
+ continue;
1417
+ }
1418
+ if (!inDouble && ch === "'") {
1419
+ inSingle = !inSingle;
1420
+ continue;
1421
+ }
1422
+ if (!inSingle && ch === '"') {
1423
+ inDouble = !inDouble;
1424
+ continue;
1425
+ }
1426
+ if (!inSingle && !inDouble && ch === '#') {
1427
+ // Everything after '#' is the comment
1428
+ const raw = valuePart.slice(i + 1);
1429
+ const comment = raw.replace(/^\s+/, ''); // trim only leading spaces after '#'
1430
+ return comment.length ? comment : '';
1431
+ }
1432
+ }
1433
+ return undefined;
1434
+ };
1435
+ for (const line of lines) {
1436
+ const raw = line;
1437
+ const trimmed = raw.trim();
1438
+ // Skip empty or full-line comments
1439
+ if (!trimmed || trimmed.startsWith('#'))
1440
+ continue;
1441
+ // Support optional leading `export `
1442
+ const withoutExport = trimmed.startsWith('export ')
1443
+ ? trimmed.slice('export '.length).trim()
1444
+ : trimmed;
1445
+ const eqIdx = withoutExport.indexOf('=');
1446
+ if (eqIdx === -1)
1447
+ continue;
1448
+ const key = withoutExport.slice(0, eqIdx).trim();
1449
+ if (!key)
1450
+ continue;
1451
+ const valuePart = withoutExport.slice(eqIdx + 1);
1452
+ result[key] = extractInlineComment(valuePart);
1453
+ }
1454
+ return result;
1455
+ //#endregion
1456
+ };
1457
+ //#endregion
1359
1458
  })(UtilsDotFile || (exports.UtilsDotFile = UtilsDotFile = {}));
1360
1459
  //#endregion
1361
1460
  //#region utils zip browser
@@ -1504,11 +1603,28 @@ var UtilsZip;
1504
1603
  //#endregion
1505
1604
  };
1506
1605
  //#endregion
1507
- UtilsZip.zipDir = async (absPathToDir) => {
1606
+ /**
1607
+ * @returns absolute path to zip file
1608
+ */
1609
+ UtilsZip.zipDir = async (absPathToDir, options) => {
1508
1610
  //#region @backendFunc
1611
+ const zipPath = `${absPathToDir}.zip`;
1612
+ const destinationFileName = (0, lib_2.crossPlatformPath)([
1613
+ lib_2.path.dirname(absPathToDir),
1614
+ zipPath,
1615
+ ]);
1616
+ if (options.overrideIfZipFileExists) {
1617
+ try {
1618
+ index_1.Helpers.removeFileIfExists(destinationFileName);
1619
+ }
1620
+ catch (error) { }
1621
+ }
1622
+ if (index_1.Helpers.exists(destinationFileName)) {
1623
+ index_1.Helpers.info(`[${lib_1.config.frameworkName}-helpers] Zip file already exists: ${destinationFileName}`);
1624
+ return destinationFileName;
1625
+ }
1509
1626
  const yazl = await Promise.resolve().then(() => require('yazl')); // Use default import for yazl
1510
1627
  const pipeline = (await Promise.resolve().then(() => require('stream/promises'))).pipeline;
1511
- const zipPath = `${absPathToDir}.zip`;
1512
1628
  const zipfile = new yazl.ZipFile();
1513
1629
  const addDirectoryToZip = async (dir, basePath) => {
1514
1630
  const entries = await lib_2.fse.promises.readdir(dir, { withFileTypes: true });
@@ -1526,6 +1642,7 @@ var UtilsZip;
1526
1642
  await addDirectoryToZip(absPathToDir, absPathToDir);
1527
1643
  zipfile.end();
1528
1644
  await pipeline(zipfile.outputStream, lib_2.fse.createWriteStream(zipPath));
1645
+ return destinationFileName;
1529
1646
  //#endregion;
1530
1647
  };
1531
1648
  // Unzip: `/some/path/folder.zip` → `/some/path/folder`
@@ -1566,4 +1683,359 @@ var UtilsZip;
1566
1683
  };
1567
1684
  })(UtilsZip || (exports.UtilsZip = UtilsZip = {}));
1568
1685
  //#endregion
1686
+ //#region utils worker
1687
+ var UtilsTaonWorker;
1688
+ (function (UtilsTaonWorker) {
1689
+ UtilsTaonWorker.getUniqueForTask = (task, location) => {
1690
+ if (!location) {
1691
+ throw new Error('[UtilsTaonWorker.getUniqueForTask()] Location must be provided');
1692
+ }
1693
+ if (!task) {
1694
+ throw new Error('[UtilsTaonWorker.getUniqueForTask()] Task must be provided');
1695
+ }
1696
+ location = (0, lib_2.crossPlatformPath)(location);
1697
+ return `task(${task?.trim()}) in ${location}`?.trim();
1698
+ };
1699
+ })(UtilsTaonWorker || (exports.UtilsTaonWorker = UtilsTaonWorker = {}));
1700
+ //#endregion
1701
+ //#region utils java
1702
+ var UtilsJava;
1703
+ (function (UtilsJava) {
1704
+ //#region select jdk version
1705
+ UtilsJava.selectJdkVersion = async () => {
1706
+ //#region @backendFunc
1707
+ index_1.Helpers.taskStarted(`Looking for JDK versions...`);
1708
+ const platform = lib_2.os.platform();
1709
+ let currentJava = '';
1710
+ let currentJavaLocation = '';
1711
+ try {
1712
+ currentJava = lib_2.child_process
1713
+ .execSync('java -version 2>&1')
1714
+ .toString()
1715
+ .split('\n')[0];
1716
+ currentJavaLocation = lib_2.child_process
1717
+ .execSync('which java')
1718
+ .toString()
1719
+ .trim();
1720
+ }
1721
+ catch {
1722
+ currentJava = '-- no selected --';
1723
+ currentJavaLocation = '--';
1724
+ }
1725
+ console.log(`\nCURRENT JAVA GLOBAL VERSION: ${currentJava}`);
1726
+ if (currentJavaLocation !== '--') {
1727
+ console.log(`FROM: ${currentJavaLocation}\n`);
1728
+ }
1729
+ let javaVersions = [];
1730
+ if (platform === 'darwin') {
1731
+ try {
1732
+ const result = lib_2.child_process
1733
+ .execSync('/usr/libexec/java_home -V 2>&1')
1734
+ .toString()
1735
+ .split('\n')
1736
+ .filter(l => l.includes('/Library/Java/JavaVirtualMachines'))
1737
+ .map(l => {
1738
+ const match = l.match(/(\/Library\/.*?\/Contents\/Home)/);
1739
+ if (match) {
1740
+ const version = l.match(/(?:jdk-|JDK )([\d._]+)/)?.[1] ?? 'unknown';
1741
+ return { version, path: match[1] };
1742
+ }
1743
+ })
1744
+ .filter(Boolean);
1745
+ javaVersions.push(...result);
1746
+ }
1747
+ catch {
1748
+ console.warn('No versions found via /usr/libexec/java_home');
1749
+ }
1750
+ // ✅ Extra fallback for Homebrew + Corretto
1751
+ const fallbackDirs = [
1752
+ '/Library/Java/JavaVirtualMachines',
1753
+ '/usr/local/Cellar',
1754
+ '/opt/homebrew/Cellar',
1755
+ ];
1756
+ for (const baseDir of fallbackDirs) {
1757
+ try {
1758
+ const dirs = lib_2.fse.readdirSync(baseDir, { withFileTypes: true });
1759
+ for (const dir of dirs) {
1760
+ if (dir.isDirectory() && /(jdk|corretto|openjdk)/i.test(dir.name)) {
1761
+ // Cellar layout: .../openjdk@21/<version>/libexec/openjdk.jdk/Contents/Home
1762
+ const homePath = baseDir.includes('Cellar')
1763
+ ? lib_2.path.join(baseDir, dir.name, lib_2.fse.readdirSync(lib_2.path.join(baseDir, dir.name))[0], 'libexec', 'openjdk.jdk', 'Contents', 'Home')
1764
+ : lib_2.path.join(baseDir, dir.name, 'Contents', 'Home');
1765
+ javaVersions.push({
1766
+ version: UtilsJava.detectJavaVersionMacOS(homePath),
1767
+ path: homePath,
1768
+ });
1769
+ }
1770
+ }
1771
+ }
1772
+ catch {
1773
+ // ignore
1774
+ }
1775
+ }
1776
+ }
1777
+ else if (platform === 'linux') {
1778
+ const knownPaths = ['/usr/lib/jvm', '/usr/java', '/opt/java', '/opt/jdk'];
1779
+ for (const basePath of knownPaths) {
1780
+ try {
1781
+ const dirs = lib_2.fse.readdirSync(basePath, { withFileTypes: true });
1782
+ for (const dir of dirs) {
1783
+ if (dir.isDirectory() && /(jdk|java|corretto)/i.test(dir.name)) {
1784
+ const versionMatch = dir.name.match(/(\d+(?:\.\d+)+)/);
1785
+ javaVersions.push({
1786
+ version: versionMatch?.[1] ?? dir.name,
1787
+ path: lib_2.path.join(basePath, dir.name),
1788
+ });
1789
+ }
1790
+ }
1791
+ }
1792
+ catch {
1793
+ // ignore
1794
+ }
1795
+ }
1796
+ }
1797
+ else if (platform === 'win32') {
1798
+ try {
1799
+ const output = lib_2.child_process.execSync('reg query "HKLM\\SOFTWARE\\JavaSoft\\Java Development Kit"', { encoding: 'utf8' });
1800
+ const lines = output
1801
+ .split('\n')
1802
+ .filter(line => line.includes('JavaSoft\\Java Development Kit'));
1803
+ for (const line of lines) {
1804
+ const version = line.trim().split('\\').pop();
1805
+ const pathOutput = lib_2.child_process.execSync(`reg query "${line.trim()}" /v JavaHome`, {
1806
+ encoding: 'utf8',
1807
+ });
1808
+ const match = pathOutput.match(/JavaHome\s+REG_SZ\s+(.+)/);
1809
+ if (match) {
1810
+ javaVersions.push({
1811
+ version,
1812
+ path: match[1].trim(),
1813
+ });
1814
+ }
1815
+ }
1816
+ }
1817
+ catch {
1818
+ // Ignore registry failure
1819
+ }
1820
+ // Fallback dirs
1821
+ const fallbackDirs = [
1822
+ 'C:\\Program Files\\Amazon Corretto',
1823
+ 'C:\\Program Files\\Java',
1824
+ 'C:\\Program Files\\Eclipse Adoptium',
1825
+ 'C:\\Program Files\\Zulu',
1826
+ 'C:\\Java',
1827
+ ];
1828
+ for (const baseDir of fallbackDirs) {
1829
+ try {
1830
+ const subdirs = lib_2.fse.readdirSync(baseDir, { withFileTypes: true });
1831
+ for (const dir of subdirs) {
1832
+ if (dir.isDirectory() &&
1833
+ /(jdk|corretto|zulu|temurin)/i.test(dir.name)) {
1834
+ const versionMatch = dir.name.match(/(\d+(?:\.\d+)+)/);
1835
+ javaVersions.push({
1836
+ version: versionMatch?.[1] ?? dir.name,
1837
+ path: lib_2.path.join(baseDir, dir.name),
1838
+ });
1839
+ }
1840
+ }
1841
+ }
1842
+ catch {
1843
+ // ignore
1844
+ }
1845
+ }
1846
+ }
1847
+ javaVersions = javaVersions
1848
+ .filter(j => j.version !== 'unknown') // drop unknowns
1849
+ .filter((j, index, self) => index ===
1850
+ self.findIndex(other => lib_2.path.resolve(other.path) === lib_2.path.resolve(j.path)));
1851
+ if (javaVersions.length === 0) {
1852
+ console.log('❌ No installed Java versions found.');
1853
+ return;
1854
+ }
1855
+ const selected = await lib_2.UtilsTerminal.select({
1856
+ question: 'Select Java version for global usage:',
1857
+ choices: javaVersions.map(j => ({
1858
+ name: `${j.version} — ${j.path}`,
1859
+ value: j,
1860
+ })),
1861
+ });
1862
+ return selected.path;
1863
+ //#endregion
1864
+ };
1865
+ //#endregion
1866
+ UtilsJava.detectJavaVersionMacOS = (javaHome) => {
1867
+ //#region @backendFunc
1868
+ try {
1869
+ // 1. Try to read "release" file shipped with every JDK
1870
+ const releaseFile = lib_2.path.join(javaHome, 'release');
1871
+ if (lib_2.fse.existsSync(releaseFile)) {
1872
+ const content = lib_2.fse.readFileSync(releaseFile, 'utf8');
1873
+ const match = content.match(/JAVA_VERSION="([^"]+)"/);
1874
+ if (match) {
1875
+ return match[1];
1876
+ }
1877
+ }
1878
+ // 2. Try folder name (amazon-corretto-21.jdk → 21, valhalla-ea-23 → 23)
1879
+ const folder = lib_2.path.basename(javaHome);
1880
+ const matchFolder = folder.match(/(\d+(?:\.\d+)?)/);
1881
+ if (matchFolder) {
1882
+ return matchFolder[1];
1883
+ }
1884
+ return folder; // fallback: show folder name
1885
+ }
1886
+ catch {
1887
+ return 'unknown';
1888
+ }
1889
+ //#endregion
1890
+ };
1891
+ //#region update java home path
1892
+ UtilsJava.updateJavaHomePath = (selectedPath) => {
1893
+ //#region @backendFunc
1894
+ const platform = lib_2.os.platform();
1895
+ if (platform === 'darwin') {
1896
+ try {
1897
+ const shellPath = lib_2.path.resolve(lib_2.UtilsOs.getRealHomeDir(), '.zshrc'); // or .bash_profile
1898
+ lib_2.child_process.execSync(`export JAVA_HOME="${selectedPath}"`);
1899
+ console.log(`✅ JAVA_HOME set to ${selectedPath} (only in current session).`);
1900
+ console.log(`To make permanent, add to your shell profile:\n\nexport JAVA_HOME="${selectedPath}"\n`);
1901
+ }
1902
+ catch (err) {
1903
+ console.error('❌ Failed to set JAVA_HOME on macOS.');
1904
+ }
1905
+ }
1906
+ else if (platform === 'linux') {
1907
+ try {
1908
+ lib_2.child_process.execSync(`export JAVA_HOME="${selectedPath}"`);
1909
+ lib_2.child_process.execSync(`sudo update-alternatives --set java "${selectedPath}/bin/java"`);
1910
+ console.log(`✅ Set global Java to ${selectedPath}`);
1911
+ }
1912
+ catch {
1913
+ console.log(`⚠️ Could not update alternatives. Try manually:\nexport JAVA_HOME="${selectedPath}"`);
1914
+ }
1915
+ }
1916
+ else if (platform === 'win32') {
1917
+ try {
1918
+ lib_2.child_process.execSync(`setx JAVA_HOME "${selectedPath}"`);
1919
+ console.log(`✅ JAVA_HOME set globally to ${selectedPath}`);
1920
+ console.log(`⚠️ Restart your terminal or computer to apply changes.`);
1921
+ }
1922
+ catch {
1923
+ console.error('❌ Failed to set JAVA_HOME on Windows.');
1924
+ }
1925
+ }
1926
+ //#endregion
1927
+ };
1928
+ //#endregion
1929
+ //#region api methods / selectTomcatVersion
1930
+ UtilsJava.selectTomcatVersion = async () => {
1931
+ //#region @backendFunc
1932
+ const platform = lib_2.os.platform();
1933
+ let currentTomcat = process.env.TOMCAT_HOME || '';
1934
+ let tomcatVersions = [];
1935
+ console.log('\n🔍 Searching for installed Tomcat versions...');
1936
+ if (currentTomcat) {
1937
+ console.log(`CURRENT TOMCAT_HOME: ${currentTomcat}\n`);
1938
+ }
1939
+ if (platform === 'darwin' || platform === 'linux') {
1940
+ // Extended search directories for macOS/Linux
1941
+ const searchDirs = [
1942
+ '/usr/local', // will check for tomcat* here
1943
+ '/opt',
1944
+ '/usr/share',
1945
+ (0, lib_2.crossPlatformPath)([lib_2.UtilsOs.getRealHomeDir(), 'tomcat']),
1946
+ ];
1947
+ for (const base of searchDirs) {
1948
+ try {
1949
+ if (!lib_2.fse.existsSync(base))
1950
+ continue;
1951
+ const subdirs = lib_2.fse.readdirSync(base, { withFileTypes: true });
1952
+ for (const sub of subdirs) {
1953
+ if (sub.isDirectory() &&
1954
+ sub.name.toLowerCase().includes('tomcat')) {
1955
+ const foundPath = lib_2.path.join(base, sub.name);
1956
+ const versionGuess = sub.name.match(/(\d+\.\d+\.\d+)/)?.[1] || sub.name;
1957
+ tomcatVersions.push({
1958
+ version: versionGuess,
1959
+ path: foundPath,
1960
+ });
1961
+ }
1962
+ }
1963
+ }
1964
+ catch {
1965
+ // ignore errors
1966
+ }
1967
+ }
1968
+ }
1969
+ else if (platform === 'win32') {
1970
+ const fallbackDirs = [
1971
+ 'C:\\Program Files\\Apache Software Foundation',
1972
+ 'C:\\Tomcat',
1973
+ ];
1974
+ for (const baseDir of fallbackDirs) {
1975
+ try {
1976
+ if (!lib_2.fse.existsSync(baseDir))
1977
+ continue;
1978
+ const subdirs = lib_2.fse.readdirSync(baseDir, { withFileTypes: true });
1979
+ for (const dir of subdirs) {
1980
+ if (dir.isDirectory() &&
1981
+ dir.name.toLowerCase().includes('tomcat')) {
1982
+ const foundPath = lib_2.path.join(baseDir, dir.name);
1983
+ const versionGuess = dir.name.match(/(\d+\.\d+\.\d+)/)?.[1] || dir.name;
1984
+ tomcatVersions.push({
1985
+ version: versionGuess,
1986
+ path: foundPath,
1987
+ });
1988
+ }
1989
+ }
1990
+ }
1991
+ catch {
1992
+ // ignore
1993
+ }
1994
+ }
1995
+ }
1996
+ if (tomcatVersions.length === 0) {
1997
+ console.log('❌ No Tomcat installations found.');
1998
+ return;
1999
+ }
2000
+ const selected = await lib_2.UtilsTerminal.select({
2001
+ question: 'Select Tomcat installation for global usage:',
2002
+ choices: tomcatVersions.map(t => ({
2003
+ name: `Tomcat ${t.version} — ${t.path}`,
2004
+ value: t,
2005
+ })),
2006
+ });
2007
+ const selectedPath = selected.path;
2008
+ return selectedPath;
2009
+ //#endregion
2010
+ };
2011
+ //#endregion
2012
+ //#region update tomcat home path
2013
+ UtilsJava.updateTomcatHomePath = (selectedPath) => {
2014
+ //#region @backendFunc
2015
+ const platform = lib_2.os.platform();
2016
+ if (platform === 'darwin' || platform === 'linux') {
2017
+ try {
2018
+ lib_2.child_process.execSync(`export TOMCAT_HOME="${selectedPath}"`);
2019
+ console.log(`✅ TOMCAT_HOME set to ${selectedPath} (current session only).`);
2020
+ console.log(`To make permanent, add to your ~/.zshrc or ~/.bashrc:\n\nexport TOMCAT_HOME="${selectedPath}"\n`);
2021
+ }
2022
+ catch {
2023
+ console.error('❌ Failed to set TOMCAT_HOME.');
2024
+ }
2025
+ }
2026
+ else if (platform === 'win32') {
2027
+ try {
2028
+ lib_2.child_process.execSync(`setx TOMCAT_HOME "${selectedPath}"`);
2029
+ console.log(`✅ TOMCAT_HOME set globally to ${selectedPath}`);
2030
+ console.log(`⚠️ Restart your terminal or computer to apply changes.`);
2031
+ }
2032
+ catch {
2033
+ console.error('❌ Failed to set TOMCAT_HOME on Windows.');
2034
+ }
2035
+ }
2036
+ //#endregion
2037
+ };
2038
+ //#endregion
2039
+ })(UtilsJava || (exports.UtilsJava = UtilsJava = {}));
2040
+ //#endregion
1569
2041
  //# sourceMappingURL=utils.js.map