@putkoff/abstract-utilities 0.1.200 → 0.1.201
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/dist/cjs/index.js
CHANGED
|
@@ -1487,74 +1487,52 @@ function Spinner() {
|
|
|
1487
1487
|
}
|
|
1488
1488
|
|
|
1489
1489
|
// src/functions/config_utils/src/config_utils.ts
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
if (filePath) {
|
|
1500
|
-
configUrl = filePath;
|
|
1501
|
-
}
|
|
1502
|
-
else if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) }) !== 'undefined' && typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) === 'string') {
|
|
1503
|
-
// ES module: resolve relative to this file
|
|
1504
|
-
try {
|
|
1505
|
-
configUrl = new URL('./config.json', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))).href;
|
|
1506
|
-
}
|
|
1507
|
-
catch (_b) {
|
|
1508
|
-
configUrl = 'config.json';
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
else {
|
|
1512
|
-
// browser fallback
|
|
1513
|
-
const baseURI = safeGlobalProp('document', 'baseURI');
|
|
1490
|
+
/**
|
|
1491
|
+
* Attempt to load config.json if present, otherwise return empty object.
|
|
1492
|
+
*/
|
|
1493
|
+
function getConfigJson() {
|
|
1494
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1495
|
+
// Node environment: check if file exists
|
|
1496
|
+
if (typeof process !== 'undefined' &&
|
|
1497
|
+
process.versions != null &&
|
|
1498
|
+
process.versions.node) {
|
|
1514
1499
|
try {
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1500
|
+
// dynamically require fs to check existence
|
|
1501
|
+
const fs = yield import('fs');
|
|
1502
|
+
const path = yield import('path');
|
|
1503
|
+
const configPath = path.resolve(__dirname, 'config.json');
|
|
1504
|
+
if (fs.existsSync(configPath)) {
|
|
1505
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1506
|
+
return require(configPath);
|
|
1507
|
+
}
|
|
1519
1508
|
}
|
|
1520
|
-
catch (
|
|
1521
|
-
|
|
1509
|
+
catch (_a) {
|
|
1510
|
+
// fall through
|
|
1522
1511
|
}
|
|
1523
1512
|
}
|
|
1524
|
-
//
|
|
1513
|
+
// Browser or fallback: try fetching via HTTP
|
|
1525
1514
|
const fetchFn = safeGlobalProp('fetch');
|
|
1526
1515
|
if (typeof fetchFn === 'function') {
|
|
1527
1516
|
try {
|
|
1528
|
-
const res = yield fetchFn(
|
|
1517
|
+
const res = yield fetchFn('config.json');
|
|
1529
1518
|
if (res.ok) {
|
|
1530
|
-
|
|
1531
|
-
// cache & return
|
|
1532
|
-
_cachedConfig = (_a = json) !== null && _a !== void 0 ? _a : {};
|
|
1533
|
-
return _cachedConfig;
|
|
1519
|
+
return (yield res.json());
|
|
1534
1520
|
}
|
|
1535
1521
|
}
|
|
1536
|
-
catch (
|
|
1537
|
-
|
|
1522
|
+
catch (_b) {
|
|
1523
|
+
// ignore
|
|
1538
1524
|
}
|
|
1539
1525
|
}
|
|
1540
|
-
//
|
|
1526
|
+
// Node fallback: read from disk via readJsonFile
|
|
1541
1527
|
try {
|
|
1542
|
-
const disk = yield readJsonFile(
|
|
1543
|
-
|
|
1544
|
-
return _cachedConfig;
|
|
1528
|
+
const disk = yield readJsonFile('config.json');
|
|
1529
|
+
return disk !== null && disk !== void 0 ? disk : {};
|
|
1545
1530
|
}
|
|
1546
|
-
catch (
|
|
1547
|
-
|
|
1531
|
+
catch (_c) {
|
|
1532
|
+
// ignore
|
|
1548
1533
|
}
|
|
1549
|
-
//
|
|
1550
|
-
|
|
1551
|
-
return _cachedConfig;
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
function getConfig(key) {
|
|
1555
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1556
|
-
const cfg = yield loadConfig();
|
|
1557
|
-
return key != null ? cfg[key] : cfg;
|
|
1534
|
+
// final fallback
|
|
1535
|
+
return {};
|
|
1558
1536
|
});
|
|
1559
1537
|
}
|
|
1560
1538
|
|
|
@@ -1657,8 +1635,8 @@ exports.getBaseDir = getBaseDir;
|
|
|
1657
1635
|
exports.getBody = getBody;
|
|
1658
1636
|
exports.getCleanArray = getCleanArray;
|
|
1659
1637
|
exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
|
|
1660
|
-
exports.getConfig = getConfig;
|
|
1661
1638
|
exports.getConfigContent = getConfigContent;
|
|
1639
|
+
exports.getConfigJson = getConfigJson;
|
|
1662
1640
|
exports.getConfigVar = getConfigVar;
|
|
1663
1641
|
exports.getDbConfigsPath = getDbConfigsPath;
|
|
1664
1642
|
exports.getDistDir = getDistDir;
|
|
@@ -1698,7 +1676,6 @@ exports.get_window_parts = get_window_parts;
|
|
|
1698
1676
|
exports.get_window_pathname = get_window_pathname;
|
|
1699
1677
|
exports.isLoggedIn = isLoggedIn;
|
|
1700
1678
|
exports.isTokenExpired = isTokenExpired;
|
|
1701
|
-
exports.loadConfig = loadConfig;
|
|
1702
1679
|
exports.make_path = make_path;
|
|
1703
1680
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1704
1681
|
exports.normalizeUrl = normalizeUrl;
|