@nmakarov/cli-toolkit 0.14.0 → 0.16.0
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/args.cjs +49 -9
- package/dist/args.cjs.map +1 -1
- package/dist/args.js +49 -9
- package/dist/args.js.map +1 -1
- package/dist/db.cjs +9 -2
- package/dist/db.cjs.map +1 -1
- package/dist/db.js +9 -2
- package/dist/db.js.map +1 -1
- package/dist/errors.cjs +17 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/filedatabase.cjs +16 -24
- package/dist/filedatabase.cjs.map +1 -1
- package/dist/filedatabase.js +16 -23
- package/dist/filedatabase.js.map +1 -1
- package/dist/http-client.cjs +44 -34
- package/dist/http-client.cjs.map +1 -1
- package/dist/http-client.js +44 -34
- package/dist/http-client.js.map +1 -1
- package/dist/http-client2.cjs +368 -0
- package/dist/http-client2.cjs.map +1 -0
- package/dist/http-client2.js +340 -0
- package/dist/http-client2.js.map +1 -0
- package/dist/index.cjs +214 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +214 -90
- package/dist/index.js.map +1 -1
- package/dist/init.cjs +192 -76
- package/dist/init.cjs.map +1 -1
- package/dist/init.js +192 -76
- package/dist/init.js.map +1 -1
- package/dist/logger.cjs +19 -36
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.js +19 -36
- package/dist/logger.js.map +1 -1
- package/dist/mock-server.cjs +13 -16
- package/dist/mock-server.cjs.map +1 -1
- package/dist/mock-server.js +13 -16
- package/dist/mock-server.js.map +1 -1
- package/dist/params.cjs +114 -15
- package/dist/params.cjs.map +1 -1
- package/dist/params.js +114 -15
- package/dist/params.js.map +1 -1
- package/dist/screen.cjs +2 -0
- package/dist/screen.cjs.map +1 -1
- package/dist/screen.js +2 -0
- package/dist/screen.js.map +1 -1
- package/package.json +9 -2
package/dist/index.js
CHANGED
|
@@ -656,6 +656,8 @@ async function showScreen(config2) {
|
|
|
656
656
|
keyMatches = true;
|
|
657
657
|
} else if (input === binding.key) {
|
|
658
658
|
keyMatches = true;
|
|
659
|
+
} else if (key?.name === binding.key) {
|
|
660
|
+
keyMatches = true;
|
|
659
661
|
}
|
|
660
662
|
if (keyMatches) {
|
|
661
663
|
if (binding.enabled === false) {
|
|
@@ -1071,20 +1073,31 @@ var Args = class _Args {
|
|
|
1071
1073
|
configValues = {};
|
|
1072
1074
|
configsLoaded = [];
|
|
1073
1075
|
env = "local";
|
|
1074
|
-
constructor(
|
|
1076
|
+
constructor(contextOrConfig = {}, config2) {
|
|
1077
|
+
const hasContext = config2 !== void 0;
|
|
1078
|
+
const configToUse = hasContext ? config2 ?? {} : contextOrConfig ?? {};
|
|
1079
|
+
const context = hasContext ? contextOrConfig : void 0;
|
|
1075
1080
|
this.aliases = {};
|
|
1076
1081
|
this.overrides = {};
|
|
1077
1082
|
this.defaults = {};
|
|
1078
1083
|
this.prefixes = ["not", "no"];
|
|
1079
|
-
if (Object.keys(
|
|
1080
|
-
this.configure(
|
|
1084
|
+
if (Object.keys(configToUse).length > 0) {
|
|
1085
|
+
this.configure(configToUse);
|
|
1081
1086
|
}
|
|
1082
|
-
const args =
|
|
1087
|
+
const args = configToUse.args || process.argv.slice(2);
|
|
1083
1088
|
this.parseArgs(args);
|
|
1084
1089
|
this.env = this.get("env")?.toLowerCase() || "local";
|
|
1085
1090
|
this.loadDotEnv();
|
|
1086
1091
|
this.loadConfigFiles();
|
|
1087
1092
|
this.checkConflicts();
|
|
1093
|
+
if (context && typeof context.registerCleanup === "function") {
|
|
1094
|
+
context.registerCleanup((ctx) => {
|
|
1095
|
+
const unusedArgs = ctx.args.getUnused();
|
|
1096
|
+
if (unusedArgs.length > 0) {
|
|
1097
|
+
ctx.logger.warn("Unused CLI args:", unusedArgs.join(", "));
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1088
1101
|
}
|
|
1089
1102
|
/**
|
|
1090
1103
|
* Configure Args options
|
|
@@ -1106,12 +1119,15 @@ var Args = class _Args {
|
|
|
1106
1119
|
}
|
|
1107
1120
|
}
|
|
1108
1121
|
/**
|
|
1109
|
-
* Initialize Args instance
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1122
|
+
* Initialize Args instance.
|
|
1123
|
+
* Args.init(context, config) when used from init/setup: context has registerCleanup, Args registers unused-args cleanup.
|
|
1124
|
+
* Args.init(config) for standalone use (no cleanup).
|
|
1112
1125
|
*/
|
|
1113
|
-
static init(config2
|
|
1114
|
-
|
|
1126
|
+
static init(contextOrConfig, config2) {
|
|
1127
|
+
if (config2 !== void 0) {
|
|
1128
|
+
return new _Args(contextOrConfig, config2);
|
|
1129
|
+
}
|
|
1130
|
+
return new _Args(contextOrConfig ?? {});
|
|
1115
1131
|
}
|
|
1116
1132
|
/**
|
|
1117
1133
|
* Parse command line arguments
|
|
@@ -1291,6 +1307,32 @@ var Args = class _Args {
|
|
|
1291
1307
|
}
|
|
1292
1308
|
return void 0;
|
|
1293
1309
|
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Return which layer provided the value for get(key): overrides, cli, config, env, or default.
|
|
1312
|
+
* Does not add key to usedKeys. Use after get(key) when you need the origin.
|
|
1313
|
+
*/
|
|
1314
|
+
getSource(key) {
|
|
1315
|
+
const resolvedKey = this.aliases[key] || key;
|
|
1316
|
+
const lcKey = resolvedKey.toLowerCase();
|
|
1317
|
+
const overrideKey = Object.keys(this.overrides).find((k) => k.toLowerCase() === lcKey);
|
|
1318
|
+
if (overrideKey !== void 0) return "overrides";
|
|
1319
|
+
const lcKeyWithEnv = `${lcKey}${this.env ? `_${this.env.toLowerCase()}` : ""}`;
|
|
1320
|
+
if (this.env && this.args[lcKeyWithEnv] !== void 0) return "cli";
|
|
1321
|
+
if (this.args[lcKey] !== void 0) return "cli";
|
|
1322
|
+
const configKey = Object.keys(this.configValues).find((k) => k.toLowerCase() === lcKey);
|
|
1323
|
+
if (configKey !== void 0) return "config";
|
|
1324
|
+
const envKey = this.toEnvKey(resolvedKey);
|
|
1325
|
+
const envKeyWithEnv = `${envKey}${this.env ? `_${this.env.toUpperCase()}` : ""}`;
|
|
1326
|
+
const envSpecificKey = Object.keys(process.env).find((k) => this.env && k.toUpperCase() === envKeyWithEnv);
|
|
1327
|
+
const envKeyFound = Object.keys(process.env).find((k) => k.toUpperCase() === envKey);
|
|
1328
|
+
const envKeyAlt = envKey.replace(/_([0-9])/g, "$1");
|
|
1329
|
+
const envKeyAltFound = !envKeyFound ? Object.keys(process.env).find((k) => k.toUpperCase() === envKeyAlt) : null;
|
|
1330
|
+
if (envSpecificKey || envKeyFound || envKeyAltFound) return "env";
|
|
1331
|
+
const defaultKey = Object.keys(this.defaults).find((k) => k.toLowerCase() === lcKey);
|
|
1332
|
+
if (defaultKey !== void 0) return "default";
|
|
1333
|
+
if (lcKey === "env" && process.env.NODE_ENV !== void 0) return "env";
|
|
1334
|
+
return void 0;
|
|
1335
|
+
}
|
|
1294
1336
|
/**
|
|
1295
1337
|
* Set a value (for testing/internal use)
|
|
1296
1338
|
*/
|
|
@@ -1516,6 +1558,12 @@ var ParamError = class extends FrameworkError {
|
|
|
1516
1558
|
this.name = "ParamError";
|
|
1517
1559
|
}
|
|
1518
1560
|
};
|
|
1561
|
+
var FileDatabaseError = class extends FrameworkError {
|
|
1562
|
+
constructor(message) {
|
|
1563
|
+
super(message);
|
|
1564
|
+
this.name = "FileDatabaseError";
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1519
1567
|
|
|
1520
1568
|
// src/params/custom-types.ts
|
|
1521
1569
|
var joiEdateType = (value, helpers) => {
|
|
@@ -1641,17 +1689,53 @@ var Params = class _Params {
|
|
|
1641
1689
|
context;
|
|
1642
1690
|
// Partial context during initialization
|
|
1643
1691
|
params = {};
|
|
1692
|
+
paramSources = {};
|
|
1644
1693
|
definitions = {};
|
|
1645
1694
|
args;
|
|
1646
1695
|
paramSetters = [];
|
|
1647
1696
|
paramGetters = [];
|
|
1648
1697
|
trackedParams = [];
|
|
1698
|
+
_currentModule = "script";
|
|
1699
|
+
/** Resolved early in constructor so cleanup does not read params lazily */
|
|
1700
|
+
_showUsedParams = false;
|
|
1649
1701
|
constructor(context, options = {}) {
|
|
1650
1702
|
this.context = context;
|
|
1651
1703
|
this.args = context.args;
|
|
1652
1704
|
if (Object.keys(options).length > 0) {
|
|
1653
1705
|
this.configure(options);
|
|
1654
1706
|
}
|
|
1707
|
+
this._showUsedParams = this.get("showUsedParams", "boolean default false");
|
|
1708
|
+
if (context && typeof context.registerCleanup === "function") {
|
|
1709
|
+
context.registerCleanup((ctx) => {
|
|
1710
|
+
if (!ctx.params.getShowUsedParams()) return;
|
|
1711
|
+
const byModule = ctx.params.getFiguredByModule();
|
|
1712
|
+
const modules = Object.keys(byModule).sort();
|
|
1713
|
+
if (modules.length === 0) return;
|
|
1714
|
+
const logger = ctx.logger;
|
|
1715
|
+
logger.debug("[Params]: list of used params:");
|
|
1716
|
+
if (typeof logger.highlight !== "function") {
|
|
1717
|
+
for (const mod of modules) {
|
|
1718
|
+
logger.debug(` [${mod}]`);
|
|
1719
|
+
for (const [key, entry] of Object.entries(byModule[mod])) {
|
|
1720
|
+
logger.debug(` ${key}: ${JSON.stringify(entry.value)} (${entry.source})`);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
for (const mod of modules) {
|
|
1726
|
+
logger.debug(` [${mod}]`);
|
|
1727
|
+
for (const [key, entry] of Object.entries(byModule[mod])) {
|
|
1728
|
+
const valueStr = JSON.stringify(entry.value);
|
|
1729
|
+
const display = entry.source === "default" ? valueStr : logger.highlight(valueStr);
|
|
1730
|
+
logger.debug(` ${key}: ${display} (${entry.source})`);
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
/** Whether --showUsedParams was requested (resolved in constructor). */
|
|
1737
|
+
getShowUsedParams() {
|
|
1738
|
+
return this._showUsedParams;
|
|
1655
1739
|
}
|
|
1656
1740
|
/**
|
|
1657
1741
|
* Configure parameters
|
|
@@ -1670,14 +1754,15 @@ var Params = class _Params {
|
|
|
1670
1754
|
return new _Params(context, options || {});
|
|
1671
1755
|
}
|
|
1672
1756
|
/**
|
|
1673
|
-
* Track a parameter request for --stopAfter=init
|
|
1757
|
+
* Track a parameter request for --stopAfter=init and --showUsedParams
|
|
1674
1758
|
*/
|
|
1675
|
-
trackParam(key, definition, value, source) {
|
|
1759
|
+
trackParam(key, definition, value, source, moduleName) {
|
|
1676
1760
|
this.trackedParams.push({
|
|
1677
1761
|
key,
|
|
1678
1762
|
definition,
|
|
1679
1763
|
value,
|
|
1680
|
-
source
|
|
1764
|
+
source,
|
|
1765
|
+
module: moduleName ?? this._currentModule
|
|
1681
1766
|
});
|
|
1682
1767
|
}
|
|
1683
1768
|
/**
|
|
@@ -1687,7 +1772,7 @@ var Params = class _Params {
|
|
|
1687
1772
|
return [...this.trackedParams];
|
|
1688
1773
|
}
|
|
1689
1774
|
/**
|
|
1690
|
-
* Get all figured parameters as a record
|
|
1775
|
+
* Get all figured parameters as a record (flat, last occurrence per key)
|
|
1691
1776
|
* Returns all parameters that were collected during initialization,
|
|
1692
1777
|
* whether from CLI args, options, or defaults
|
|
1693
1778
|
*/
|
|
@@ -1701,6 +1786,19 @@ var Params = class _Params {
|
|
|
1701
1786
|
}
|
|
1702
1787
|
return result;
|
|
1703
1788
|
}
|
|
1789
|
+
/**
|
|
1790
|
+
* Get figured parameters grouped by module name.
|
|
1791
|
+
* Same param can appear in multiple modules (e.g. source, resource).
|
|
1792
|
+
*/
|
|
1793
|
+
getFiguredByModule() {
|
|
1794
|
+
const byModule = {};
|
|
1795
|
+
for (const param of this.trackedParams) {
|
|
1796
|
+
const mod = param.module;
|
|
1797
|
+
if (!byModule[mod]) byModule[mod] = {};
|
|
1798
|
+
byModule[mod][param.key] = { value: param.value, source: param.source };
|
|
1799
|
+
}
|
|
1800
|
+
return byModule;
|
|
1801
|
+
}
|
|
1704
1802
|
/**
|
|
1705
1803
|
* Clear tracked parameters
|
|
1706
1804
|
*/
|
|
@@ -1819,14 +1917,19 @@ var Params = class _Params {
|
|
|
1819
1917
|
source = "options";
|
|
1820
1918
|
} else if (valFromArgs !== void 0 && valFromArgs !== null) {
|
|
1821
1919
|
value = this.validate(key, valFromArgs, def);
|
|
1822
|
-
|
|
1920
|
+
const argsSource = this.args.getSource?.(key);
|
|
1921
|
+
if (argsSource === "overrides") source = "options";
|
|
1922
|
+
else if (argsSource === "cli" || argsSource === "env" || argsSource === "config") source = argsSource;
|
|
1923
|
+
else if (argsSource === "default") source = "default";
|
|
1924
|
+
else source = "cli";
|
|
1823
1925
|
} else if (valFromParams !== void 0 && valFromParams !== null) {
|
|
1824
1926
|
value = this.validate(key, valFromParams, def);
|
|
1825
|
-
source = "options";
|
|
1927
|
+
source = this.paramSources[key] ?? "options";
|
|
1826
1928
|
} else {
|
|
1827
1929
|
value = this.validate(key, void 0, def);
|
|
1828
1930
|
source = "default";
|
|
1829
1931
|
}
|
|
1932
|
+
this.paramSources[key] = source;
|
|
1830
1933
|
this.trackParam(key, definition || "string", value, source);
|
|
1831
1934
|
if (value !== void 0 && def.values && !def.values.includes(value)) {
|
|
1832
1935
|
throw new ParamError(`key ${key} should be one of ${def.values}`);
|
|
@@ -1847,19 +1950,63 @@ var Params = class _Params {
|
|
|
1847
1950
|
}
|
|
1848
1951
|
}
|
|
1849
1952
|
/**
|
|
1850
|
-
* Get all parameters from definitions
|
|
1851
|
-
* Processes
|
|
1953
|
+
* Get all parameters from definitions (main script).
|
|
1954
|
+
* Same as getAllForModule("script", defs). Processes left-to-right for cross-parameter references.
|
|
1852
1955
|
*/
|
|
1853
1956
|
getAll(defs) {
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1957
|
+
return this.getAllForModule("script", defs);
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Get all parameters from definitions for a given module name.
|
|
1961
|
+
* Figured params are grouped by module when using --showUsedParams.
|
|
1962
|
+
* Processes parameters left-to-right to support cross-parameter references.
|
|
1963
|
+
* If moduleName is omitted, it is inferred from the caller's file path (directory name under src/).
|
|
1964
|
+
*/
|
|
1965
|
+
getAllForModule(moduleNameOrDefs, defs) {
|
|
1966
|
+
let moduleName;
|
|
1967
|
+
let definitions;
|
|
1968
|
+
if (defs !== void 0) {
|
|
1969
|
+
moduleName = moduleNameOrDefs;
|
|
1970
|
+
definitions = defs;
|
|
1971
|
+
} else {
|
|
1972
|
+
definitions = moduleNameOrDefs;
|
|
1973
|
+
moduleName = this._inferModuleNameFromStack();
|
|
1974
|
+
}
|
|
1975
|
+
const prev = this._currentModule;
|
|
1976
|
+
this._currentModule = moduleName;
|
|
1977
|
+
try {
|
|
1978
|
+
const res = {};
|
|
1979
|
+
for (const [k, def] of Object.entries(definitions)) {
|
|
1980
|
+
const value = this.get(k, def);
|
|
1981
|
+
res[k] = value;
|
|
1982
|
+
if (value !== void 0) {
|
|
1983
|
+
this.params[k] = value;
|
|
1984
|
+
}
|
|
1860
1985
|
}
|
|
1986
|
+
return res;
|
|
1987
|
+
} finally {
|
|
1988
|
+
this._currentModule = prev;
|
|
1861
1989
|
}
|
|
1862
|
-
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Infer module name from call stack: first caller outside params/index gives path like .../src/<moduleName>/...
|
|
1993
|
+
*/
|
|
1994
|
+
_inferModuleNameFromStack() {
|
|
1995
|
+
const stack = new Error().stack;
|
|
1996
|
+
if (!stack) return "script";
|
|
1997
|
+
const lines = stack.split("\n");
|
|
1998
|
+
const paramsIndexPath = "params" + (typeof process !== "undefined" && process.platform === "win32" ? "\\" : "/") + "index.";
|
|
1999
|
+
for (const line of lines) {
|
|
2000
|
+
const parenMatch = line.match(/\(([^)]+)\)/);
|
|
2001
|
+
if (!parenMatch) continue;
|
|
2002
|
+
const parts = parenMatch[1].split(":");
|
|
2003
|
+
if (parts.length < 3) continue;
|
|
2004
|
+
const path4 = parts.slice(0, -2).join(":").replace(/^file:\/\//, "");
|
|
2005
|
+
if (!path4 || path4.includes(paramsIndexPath)) continue;
|
|
2006
|
+
const srcMatch = path4.match(/[/\\]src[/\\]([^/\\]+)(?:[/\\]|$)/);
|
|
2007
|
+
if (srcMatch) return srcMatch[1];
|
|
2008
|
+
}
|
|
2009
|
+
return "script";
|
|
1863
2010
|
}
|
|
1864
2011
|
/**
|
|
1865
2012
|
* Run all registered getters for a key
|
|
@@ -2081,13 +2228,7 @@ function defaultVersionSynopsisFunction(metadata) {
|
|
|
2081
2228
|
}
|
|
2082
2229
|
|
|
2083
2230
|
// src/filedatabase/index.ts
|
|
2084
|
-
var
|
|
2085
|
-
constructor(message) {
|
|
2086
|
-
super(message);
|
|
2087
|
-
this.name = "FileDatabaseError";
|
|
2088
|
-
}
|
|
2089
|
-
};
|
|
2090
|
-
var FileDatabase = class {
|
|
2231
|
+
var FileDatabase = class _FileDatabase {
|
|
2091
2232
|
basePath;
|
|
2092
2233
|
namespace;
|
|
2093
2234
|
tableName = null;
|
|
@@ -2124,18 +2265,8 @@ var FileDatabase = class {
|
|
|
2124
2265
|
maxVersions: "number default 5",
|
|
2125
2266
|
pageSize: "number default 5000"
|
|
2126
2267
|
};
|
|
2127
|
-
const
|
|
2128
|
-
config2 = {
|
|
2129
|
-
basePath: opts.basePath ?? paramsConfig.basePath,
|
|
2130
|
-
namespace: opts.namespace ?? paramsConfig.namespace,
|
|
2131
|
-
tableName: opts.tableName ?? paramsConfig.tableName ?? null,
|
|
2132
|
-
versioned: opts.versioned ?? true,
|
|
2133
|
-
maxVersions: opts.maxVersions ?? paramsConfig.maxVersions,
|
|
2134
|
-
pageSize: opts.pageSize ?? paramsConfig.pageSize,
|
|
2135
|
-
useMetadata: opts.useMetadata ?? true,
|
|
2136
|
-
freeSpaceThreshold: opts.freeSpaceThreshold ?? 100 * 1024 * 1024,
|
|
2137
|
-
logger: context.logger
|
|
2138
|
-
};
|
|
2268
|
+
const discovered = context.params.getAllForModule(defs);
|
|
2269
|
+
config2 = { ...discovered, ...opts, logger: context.logger };
|
|
2139
2270
|
} else {
|
|
2140
2271
|
config2 = contextOrConfig;
|
|
2141
2272
|
}
|
|
@@ -2153,6 +2284,13 @@ var FileDatabase = class {
|
|
|
2153
2284
|
this.logger = config2.logger || console;
|
|
2154
2285
|
this.metadata = this.getDefaultMetadata();
|
|
2155
2286
|
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Initialize FileDatabase from context and options.
|
|
2289
|
+
* Params are read via getAllForModule("filedatabase", defs) for --showUsedParams grouping.
|
|
2290
|
+
*/
|
|
2291
|
+
static init(context, options) {
|
|
2292
|
+
return new _FileDatabase(context, options ?? {});
|
|
2293
|
+
}
|
|
2156
2294
|
/**
|
|
2157
2295
|
* Get default metadata structure
|
|
2158
2296
|
*/
|
|
@@ -3018,9 +3156,6 @@ function listSources(basePath) {
|
|
|
3018
3156
|
return [];
|
|
3019
3157
|
}
|
|
3020
3158
|
}
|
|
3021
|
-
function fileDatabaseInit(context, options = {}) {
|
|
3022
|
-
return new FileDatabase(context, options);
|
|
3023
|
-
}
|
|
3024
3159
|
|
|
3025
3160
|
// src/db/index.ts
|
|
3026
3161
|
import knex from "knex";
|
|
@@ -3319,6 +3454,13 @@ var Db = class {
|
|
|
3319
3454
|
isConnectedToDb() {
|
|
3320
3455
|
return this.isConnected && this.knexInstance !== null;
|
|
3321
3456
|
}
|
|
3457
|
+
/**
|
|
3458
|
+
* Initialize Db with context (connects and registers disconnect cleanup).
|
|
3459
|
+
* Params are read via getAllForModule("db", defs). Same as dbInit(context, dbNameOrConnectionString).
|
|
3460
|
+
*/
|
|
3461
|
+
static async init(context, dbNameOrConnectionString) {
|
|
3462
|
+
return dbFindAndConnect(context, dbNameOrConnectionString);
|
|
3463
|
+
}
|
|
3322
3464
|
};
|
|
3323
3465
|
function capitalizeFirstLetter(str) {
|
|
3324
3466
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -3332,7 +3474,7 @@ async function dbConnect(context, connectionString, name, dbProfile) {
|
|
|
3332
3474
|
acquireConnectionTimeout: "number default 10000",
|
|
3333
3475
|
sslRejectUnauthorized: "boolean default false"
|
|
3334
3476
|
};
|
|
3335
|
-
const paramsConfig = context.params.
|
|
3477
|
+
const paramsConfig = context.params.getAllForModule(defs);
|
|
3336
3478
|
const config2 = {
|
|
3337
3479
|
connectionString,
|
|
3338
3480
|
name: paramsConfig.name || name || "default",
|
|
@@ -3382,7 +3524,7 @@ async function dbFindAndConnect(context, dbNameOrConnectionString) {
|
|
|
3382
3524
|
dbConnectionString: "string",
|
|
3383
3525
|
dbProfile: "boolean default false"
|
|
3384
3526
|
};
|
|
3385
|
-
const paramsConfig = context.params.
|
|
3527
|
+
const paramsConfig = context.params.getAllForModule(defs);
|
|
3386
3528
|
dbName = paramsConfig.dbName;
|
|
3387
3529
|
dbConnectionString = paramsConfig.dbConnectionString;
|
|
3388
3530
|
dbProfile = paramsConfig.dbProfile;
|
|
@@ -3474,8 +3616,7 @@ var Logger = class _Logger {
|
|
|
3474
3616
|
this.updateTransport();
|
|
3475
3617
|
}
|
|
3476
3618
|
/**
|
|
3477
|
-
* Configure logger options
|
|
3478
|
-
* Only parameters present in options are updated
|
|
3619
|
+
* Configure logger options. Accepts both LoggerOptions shape and flat param names (levels string, progressWithTimes, progressThrottleMs).
|
|
3479
3620
|
*/
|
|
3480
3621
|
configure(options) {
|
|
3481
3622
|
if (options.mode !== void 0) {
|
|
@@ -3485,32 +3626,24 @@ var Logger = class _Logger {
|
|
|
3485
3626
|
this.options.route = options.route;
|
|
3486
3627
|
this.updateTransport();
|
|
3487
3628
|
}
|
|
3488
|
-
if (options.prefix !== void 0)
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
if (options.
|
|
3492
|
-
this.options.silent = options.silent;
|
|
3493
|
-
}
|
|
3494
|
-
if (options.showLevel !== void 0) {
|
|
3495
|
-
this.options.showLevel = options.showLevel;
|
|
3496
|
-
}
|
|
3497
|
-
if (options.timestamp !== void 0) {
|
|
3498
|
-
this.options.timestamp = options.timestamp;
|
|
3499
|
-
}
|
|
3629
|
+
if (options.prefix !== void 0) this.options.prefix = options.prefix;
|
|
3630
|
+
if (options.silent !== void 0) this.options.silent = options.silent;
|
|
3631
|
+
if (options.showLevel !== void 0) this.options.showLevel = options.showLevel;
|
|
3632
|
+
if (options.timestamp !== void 0) this.options.timestamp = options.timestamp;
|
|
3500
3633
|
if (options.levels !== void 0) {
|
|
3501
|
-
|
|
3634
|
+
const levels = typeof options.levels === "string" ? options.levels.split(",") : options.levels;
|
|
3635
|
+
this.options.levels = this.normalizeLevels(levels);
|
|
3502
3636
|
}
|
|
3503
3637
|
if (options.progress !== void 0) {
|
|
3504
|
-
if (options.progress.withTimes !== void 0)
|
|
3505
|
-
|
|
3506
|
-
}
|
|
3507
|
-
if (options.progress.throttleMs !== void 0) {
|
|
3508
|
-
this.options.progressThrottle = options.progress.throttleMs;
|
|
3509
|
-
}
|
|
3638
|
+
if (options.progress.withTimes !== void 0) this.options.progressTimes = options.progress.withTimes;
|
|
3639
|
+
if (options.progress.throttleMs !== void 0) this.options.progressThrottle = options.progress.throttleMs;
|
|
3510
3640
|
}
|
|
3641
|
+
const flat = options;
|
|
3642
|
+
if (flat.progressWithTimes !== void 0) this.options.progressTimes = flat.progressWithTimes;
|
|
3643
|
+
if (flat.progressThrottleMs !== void 0) this.options.progressThrottle = flat.progressThrottleMs;
|
|
3511
3644
|
}
|
|
3512
3645
|
/**
|
|
3513
|
-
* Initialize logger from context and CLI parameters
|
|
3646
|
+
* Initialize logger from context and CLI parameters. Whatever is in options goes (after discovered params).
|
|
3514
3647
|
*/
|
|
3515
3648
|
static init(context, options) {
|
|
3516
3649
|
const paramDefs = {
|
|
@@ -3524,20 +3657,8 @@ var Logger = class _Logger {
|
|
|
3524
3657
|
progressWithTimes: "boolean default false",
|
|
3525
3658
|
progressThrottleMs: "number"
|
|
3526
3659
|
};
|
|
3527
|
-
const
|
|
3528
|
-
const config2 = {
|
|
3529
|
-
mode: options?.mode ?? cliParams.mode,
|
|
3530
|
-
route: options?.route ?? cliParams.route,
|
|
3531
|
-
prefix: options?.prefix ?? cliParams.prefix,
|
|
3532
|
-
silent: options?.silent ?? cliParams.silent,
|
|
3533
|
-
showLevel: options?.showLevel ?? cliParams.showLevel,
|
|
3534
|
-
timestamp: options?.timestamp ?? cliParams.timestamp,
|
|
3535
|
-
levels: options?.levels ?? (cliParams.levels ? cliParams.levels.split(",") : void 0),
|
|
3536
|
-
progress: options?.progress ?? {
|
|
3537
|
-
withTimes: cliParams.progressWithTimes,
|
|
3538
|
-
throttleMs: cliParams.progressThrottleMs
|
|
3539
|
-
}
|
|
3540
|
-
};
|
|
3660
|
+
const discovered = context.params.getAllForModule(paramDefs);
|
|
3661
|
+
const config2 = { ...discovered, ...options };
|
|
3541
3662
|
const logger = new _Logger(context, config2);
|
|
3542
3663
|
context.logger = logger;
|
|
3543
3664
|
return logger;
|
|
@@ -3564,6 +3685,10 @@ var Logger = class _Logger {
|
|
|
3564
3685
|
}
|
|
3565
3686
|
this.options.mode = mode;
|
|
3566
3687
|
}
|
|
3688
|
+
/** Returns a styled string (bright white) for highlighting; keeps chalk inside logger. */
|
|
3689
|
+
highlight(text) {
|
|
3690
|
+
return chalk.whiteBright(text);
|
|
3691
|
+
}
|
|
3567
3692
|
debug(message, ...chunks) {
|
|
3568
3693
|
this.out({ level: "debug", message, chunks });
|
|
3569
3694
|
}
|
|
@@ -3739,12 +3864,7 @@ function extractComponentOptions(opts, componentName) {
|
|
|
3739
3864
|
return componentOptions;
|
|
3740
3865
|
}
|
|
3741
3866
|
function setup(opts = {}) {
|
|
3742
|
-
const args = Args.init({
|
|
3743
|
-
overrides: opts.overrides || {},
|
|
3744
|
-
defaults: opts.defaults || {}
|
|
3745
|
-
});
|
|
3746
3867
|
const partialContext = {
|
|
3747
|
-
args,
|
|
3748
3868
|
emitter: new EventEmitter(),
|
|
3749
3869
|
isStop: () => false,
|
|
3750
3870
|
cleanupFunctions: [],
|
|
@@ -3752,6 +3872,11 @@ function setup(opts = {}) {
|
|
|
3752
3872
|
partialContext.cleanupFunctions.push(fn);
|
|
3753
3873
|
}
|
|
3754
3874
|
};
|
|
3875
|
+
const args = Args.init(partialContext, {
|
|
3876
|
+
overrides: opts.overrides || {},
|
|
3877
|
+
defaults: opts.defaults || {}
|
|
3878
|
+
});
|
|
3879
|
+
partialContext.args = args;
|
|
3755
3880
|
const params = Params.init(partialContext, opts.overrides || {});
|
|
3756
3881
|
partialContext.params = params;
|
|
3757
3882
|
const loggerOptions = extractComponentOptions(opts, "logger");
|
|
@@ -3804,7 +3929,6 @@ export {
|
|
|
3804
3929
|
dbInit,
|
|
3805
3930
|
defaultFileSynopsisFunction,
|
|
3806
3931
|
defaultVersionSynopsisFunction,
|
|
3807
|
-
fileDatabaseInit,
|
|
3808
3932
|
getArgsInstance,
|
|
3809
3933
|
createElement2 as h,
|
|
3810
3934
|
joiEdateType,
|