@storm-software/config-tools 1.176.13 → 1.176.15

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.
@@ -0,0 +1,158 @@
1
+ import {
2
+ formatTimestamp
3
+ } from "./chunk-CZ4IE2QN.js";
4
+ import {
5
+ getLogLevel
6
+ } from "./chunk-K4CDYUQR.js";
7
+ import {
8
+ getChalk
9
+ } from "./chunk-P2KJ6EZO.js";
10
+ import {
11
+ CONSOLE_ICONS
12
+ } from "./chunk-LM2UMGYA.js";
13
+ import {
14
+ LogLevel,
15
+ LogLevelLabel
16
+ } from "./chunk-POXTJ6GF.js";
17
+ import {
18
+ DEFAULT_COLOR_CONFIG
19
+ } from "./chunk-66NG3IMH.js";
20
+
21
+ // src/logger/console.ts
22
+ var getLogFn = (logLevel = LogLevel.INFO, config = {}, _chalk = getChalk()) => {
23
+ const colors = !config.colors?.dark && !config.colors?.["base"] && !config.colors?.["base"]?.dark ? DEFAULT_COLOR_CONFIG : config.colors?.dark && typeof config.colors.dark === "string" ? config.colors : config.colors?.["base"]?.dark && typeof config.colors["base"].dark === "string" ? config.colors["base"].dark : config.colors?.["base"] ? config.colors?.["base"] : DEFAULT_COLOR_CONFIG;
24
+ const configLogLevel = config.logLevel || process.env.STORM_LOG_LEVEL || LogLevelLabel.INFO;
25
+ if (logLevel > getLogLevel(configLogLevel) || logLevel <= LogLevel.SILENT || getLogLevel(configLogLevel) <= LogLevel.SILENT) {
26
+ return (_) => {
27
+ };
28
+ }
29
+ if (typeof logLevel === "number" && LogLevel.FATAL >= logLevel) {
30
+ return (message) => {
31
+ console.error(
32
+ `
33
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.fatal ?? "#7d1a1a")(`[${CONSOLE_ICONS[LogLevelLabel.FATAL]} Fatal] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
34
+ `
35
+ );
36
+ };
37
+ }
38
+ if (typeof logLevel === "number" && LogLevel.ERROR >= logLevel) {
39
+ return (message) => {
40
+ console.error(
41
+ `
42
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.danger ?? "#f85149")(`[${CONSOLE_ICONS[LogLevelLabel.ERROR]} Error] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
43
+ `
44
+ );
45
+ };
46
+ }
47
+ if (typeof logLevel === "number" && LogLevel.WARN >= logLevel) {
48
+ return (message) => {
49
+ console.warn(
50
+ `
51
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.warning ?? "#e3b341")(`[${CONSOLE_ICONS[LogLevelLabel.WARN]} Warn] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
52
+ `
53
+ );
54
+ };
55
+ }
56
+ if (typeof logLevel === "number" && LogLevel.SUCCESS >= logLevel) {
57
+ return (message) => {
58
+ console.info(
59
+ `
60
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.success ?? "#56d364")(`[${CONSOLE_ICONS[LogLevelLabel.SUCCESS]} Success] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
61
+ `
62
+ );
63
+ };
64
+ }
65
+ if (typeof logLevel === "number" && LogLevel.INFO >= logLevel) {
66
+ return (message) => {
67
+ console.info(
68
+ `
69
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.info ?? "#58a6ff")(`[${CONSOLE_ICONS[LogLevelLabel.INFO]} Info] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
70
+ `
71
+ );
72
+ };
73
+ }
74
+ if (typeof logLevel === "number" && LogLevel.DEBUG >= logLevel) {
75
+ return (message) => {
76
+ console.debug(
77
+ `
78
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex("#3e9eff")(`[${CONSOLE_ICONS[LogLevelLabel.DEBUG]} Debug] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
79
+ `
80
+ );
81
+ };
82
+ }
83
+ if (typeof logLevel === "number" && LogLevel.TRACE >= logLevel) {
84
+ return (message) => {
85
+ console.debug(
86
+ `
87
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex("#0070E0")(`[${CONSOLE_ICONS[LogLevelLabel.TRACE]} Trace] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
88
+ `
89
+ );
90
+ };
91
+ }
92
+ return (message) => {
93
+ console.log(
94
+ `
95
+ ${_chalk.gray(formatTimestamp())} ${_chalk.hex("#0356a8")(`[${CONSOLE_ICONS[LogLevelLabel.ALL]} System] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
96
+ `
97
+ );
98
+ };
99
+ };
100
+ var writeFatal = (message, config) => getLogFn(LogLevel.FATAL, config)(message);
101
+ var writeError = (message, config) => getLogFn(LogLevel.ERROR, config)(message);
102
+ var writeWarning = (message, config) => getLogFn(LogLevel.WARN, config)(message);
103
+ var writeInfo = (message, config) => getLogFn(LogLevel.INFO, config)(message);
104
+ var writeSuccess = (message, config) => getLogFn(LogLevel.SUCCESS, config)(message);
105
+ var writeDebug = (message, config) => getLogFn(LogLevel.DEBUG, config)(message);
106
+ var writeTrace = (message, config) => getLogFn(LogLevel.TRACE, config)(message);
107
+ var writeSystem = (message, config) => getLogFn(LogLevel.ALL, config)(message);
108
+ var getStopwatch = (name) => {
109
+ const start = process.hrtime();
110
+ return () => {
111
+ const end = process.hrtime(start);
112
+ console.info(
113
+ `
114
+ > \u23F1\uFE0F The${name ? ` ${name}` : ""} process took ${Math.round(
115
+ end[0] * 1e3 + end[1] / 1e6
116
+ )}ms to complete
117
+ `
118
+ );
119
+ };
120
+ };
121
+ var MAX_DEPTH = 4;
122
+ var formatLogMessage = (message, options = {}, depth = 0) => {
123
+ if (depth > MAX_DEPTH) {
124
+ return "<max depth>";
125
+ }
126
+ const prefix = options.prefix ?? "-";
127
+ const skip = options.skip ?? [];
128
+ return typeof message === "undefined" || message === null || !message && typeof message !== "boolean" ? "<none>" : typeof message === "string" ? message : Array.isArray(message) ? `
129
+ ${message.map((item, index) => ` ${prefix}> #${index} = ${formatLogMessage(item, { prefix: `${prefix}-`, skip }, depth + 1)}`).join("\n")}` : typeof message === "object" ? `
130
+ ${Object.keys(message).filter((key) => !skip.includes(key)).map(
131
+ (key) => ` ${prefix}> ${key} = ${_isFunction(message[key]) ? "<function>" : typeof message[key] === "object" ? formatLogMessage(
132
+ message[key],
133
+ { prefix: `${prefix}-`, skip },
134
+ depth + 1
135
+ ) : message[key]}`
136
+ ).join("\n")}` : message;
137
+ };
138
+ var _isFunction = (value) => {
139
+ try {
140
+ return value instanceof Function || typeof value === "function" || !!(value?.constructor && value?.call && value?.apply);
141
+ } catch (e) {
142
+ return false;
143
+ }
144
+ };
145
+
146
+ export {
147
+ getLogFn,
148
+ writeFatal,
149
+ writeError,
150
+ writeWarning,
151
+ writeInfo,
152
+ writeSuccess,
153
+ writeDebug,
154
+ writeTrace,
155
+ writeSystem,
156
+ getStopwatch,
157
+ formatLogMessage
158
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkN3XDUGRPcjs = require('./chunk-N3XDUGRP.cjs');
5
+
6
+
7
+ var _chunkZAEOJ4NDcjs = require('./chunk-ZAEOJ4ND.cjs');
8
+
9
+ // src/get-config.ts
10
+ var getConfig = (workspaceRoot, skipLogs = false) => {
11
+ return _chunkN3XDUGRPcjs.loadStormWorkspaceConfig.call(void 0, workspaceRoot, skipLogs);
12
+ };
13
+ var getWorkspaceConfig = (skipLogs = true, options = {}) => {
14
+ let workspaceRoot = options.workspaceRoot;
15
+ if (!workspaceRoot) {
16
+ workspaceRoot = _chunkZAEOJ4NDcjs.findWorkspaceRoot.call(void 0, options.cwd);
17
+ }
18
+ return getConfig(workspaceRoot, skipLogs);
19
+ };
20
+ var tryGetWorkspaceConfig = async (skipLogs = true, options = {}) => {
21
+ try {
22
+ let workspaceRoot = options.workspaceRoot;
23
+ if (!workspaceRoot) {
24
+ workspaceRoot = _chunkZAEOJ4NDcjs.findWorkspaceRoot.call(void 0, options.cwd);
25
+ }
26
+ return _chunkN3XDUGRPcjs.tryLoadStormWorkspaceConfig.call(void 0,
27
+ workspaceRoot,
28
+ skipLogs,
29
+ options.useDefault
30
+ );
31
+ } catch (e) {
32
+ return void 0;
33
+ }
34
+ };
35
+
36
+
37
+
38
+
39
+
40
+ exports.getConfig = getConfig; exports.getWorkspaceConfig = getWorkspaceConfig; exports.tryGetWorkspaceConfig = tryGetWorkspaceConfig;
@@ -0,0 +1,81 @@
1
+ import {
2
+ findWorkspaceRoot
3
+ } from "./chunk-6RRYSEZX.js";
4
+
5
+ // src/utilities/apply-workspace-tokens.ts
6
+ var applyWorkspaceBaseTokens = async (option, tokenParams) => {
7
+ let result = option;
8
+ if (!result) {
9
+ return result;
10
+ }
11
+ if (tokenParams) {
12
+ const optionKeys = Object.keys(tokenParams);
13
+ if (optionKeys.some((optionKey) => result.includes(`{${optionKey}}`))) {
14
+ for (const optionKey of optionKeys) {
15
+ if (result.includes(`{${optionKey}}`)) {
16
+ result = result.replaceAll(
17
+ `{${optionKey}}`,
18
+ tokenParams?.[optionKey] || ""
19
+ );
20
+ }
21
+ }
22
+ }
23
+ }
24
+ if (tokenParams.config) {
25
+ const configKeys = Object.keys(tokenParams.config);
26
+ if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) {
27
+ for (const configKey of configKeys) {
28
+ if (result.includes(`{${configKey}}`)) {
29
+ result = result.replaceAll(
30
+ `{${configKey}}`,
31
+ tokenParams.config[configKey] || ""
32
+ );
33
+ }
34
+ }
35
+ }
36
+ }
37
+ if (result.includes("{workspaceRoot}")) {
38
+ result = result.replaceAll(
39
+ "{workspaceRoot}",
40
+ tokenParams.workspaceRoot ?? tokenParams.config?.workspaceRoot ?? findWorkspaceRoot()
41
+ );
42
+ }
43
+ return result;
44
+ };
45
+ var applyWorkspaceProjectTokens = (option, tokenParams) => {
46
+ return applyWorkspaceBaseTokens(option, tokenParams);
47
+ };
48
+ var applyWorkspaceTokens = async (options, tokenParams, tokenizerFn) => {
49
+ if (!options) {
50
+ return {};
51
+ }
52
+ const result = {};
53
+ for (const option of Object.keys(options)) {
54
+ if (typeof options[option] === "string") {
55
+ result[option] = await Promise.resolve(
56
+ tokenizerFn(options[option], tokenParams)
57
+ );
58
+ } else if (Array.isArray(options[option])) {
59
+ result[option] = await Promise.all(
60
+ options[option].map(
61
+ async (item) => typeof item === "string" ? await Promise.resolve(tokenizerFn(item, tokenParams)) : item
62
+ )
63
+ );
64
+ } else if (typeof options[option] === "object") {
65
+ result[option] = await applyWorkspaceTokens(
66
+ options[option],
67
+ tokenParams,
68
+ tokenizerFn
69
+ );
70
+ } else {
71
+ result[option] = options[option];
72
+ }
73
+ }
74
+ return result;
75
+ };
76
+
77
+ export {
78
+ applyWorkspaceBaseTokens,
79
+ applyWorkspaceProjectTokens,
80
+ applyWorkspaceTokens
81
+ };
@@ -0,0 +1,39 @@
1
+ import {
2
+ DEFAULT_COLOR_CONFIG
3
+ } from "./chunk-66NG3IMH.js";
4
+
5
+ // src/utilities/colors.ts
6
+ function getColorConfig(config) {
7
+ if (!config?.colors || typeof config.colors !== "object" || !config.colors["dark"] && (!config.colors["base"] || typeof config.colors !== "object" || !config.colors["base"]?.["dark"])) {
8
+ return DEFAULT_COLOR_CONFIG;
9
+ }
10
+ if (config.colors["base"]) {
11
+ if (typeof config.colors["base"]["dark"] === "object") {
12
+ return config.colors["base"]["dark"];
13
+ } else if (config.colors["base"]["dark"] === "string") {
14
+ return config.colors["base"];
15
+ }
16
+ }
17
+ if (typeof config.colors["dark"] === "object") {
18
+ return config.colors["dark"];
19
+ }
20
+ return config.colors ?? DEFAULT_COLOR_CONFIG;
21
+ }
22
+ function getColor(key, config) {
23
+ const colors = getColorConfig(config);
24
+ const result = (typeof colors["dark"] === "object" ? colors["dark"][key] : colors[key]) || DEFAULT_COLOR_CONFIG["dark"][key] || DEFAULT_COLOR_CONFIG[key];
25
+ if (result) {
26
+ return result;
27
+ }
28
+ if (key === "link") {
29
+ return getColor("info", config);
30
+ } else if (key === "fatal") {
31
+ return getColor("danger", config);
32
+ }
33
+ return getColor("brand", config);
34
+ }
35
+
36
+ export {
37
+ getColorConfig,
38
+ getColor
39
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkHDZDJM2Acjs = require('./chunk-HDZDJM2A.cjs');
4
+
5
+ // src/utilities/toml.ts
6
+ var _jtoml = require('@ltd/j-toml'); var _jtoml2 = _interopRequireDefault(_jtoml);
7
+ function parseCargoTomlWithTree(tree, projectRoot, projectName) {
8
+ const cargoTomlString = _optionalChain([tree, 'access', _ => _.read, 'call', _2 => _2(`${projectRoot}/Cargo.toml`), 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
9
+ if (!cargoTomlString) {
10
+ _chunkHDZDJM2Acjs.writeError.call(void 0, `Cannot find a Cargo.toml file in the ${projectName}`);
11
+ throw new Error();
12
+ }
13
+ return parseCargoToml(cargoTomlString);
14
+ }
15
+ function parseCargoToml(cargoString) {
16
+ if (!cargoString) {
17
+ throw new Error("Cargo.toml is empty");
18
+ }
19
+ return _jtoml2.default.parse(cargoString, {
20
+ x: { comment: true }
21
+ });
22
+ }
23
+ function stringifyCargoToml(cargoToml) {
24
+ const tomlString = _jtoml2.default.stringify(cargoToml, {
25
+ newlineAround: "section"
26
+ });
27
+ if (Array.isArray(tomlString)) {
28
+ return tomlString.join("\n");
29
+ }
30
+ return tomlString;
31
+ }
32
+ function modifyCargoTable(toml, section, key, value) {
33
+ toml[section] ??= _jtoml2.default.Section({});
34
+ toml[section][key] = typeof value === "object" && !Array.isArray(value) ? _jtoml2.default.inline(value) : typeof value === "function" ? value() : value;
35
+ }
36
+ function modifyCargoNestedTable(toml, section, key, value) {
37
+ toml[section] ??= {};
38
+ toml[section][key] = _jtoml2.default.Section(value);
39
+ }
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ exports.parseCargoTomlWithTree = parseCargoTomlWithTree; exports.parseCargoToml = parseCargoToml; exports.stringifyCargoToml = stringifyCargoToml; exports.modifyCargoTable = modifyCargoTable; exports.modifyCargoNestedTable = modifyCargoNestedTable;