@reliverse/rempts 1.6.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/LICENSE +21 -0
- package/README.md +408 -0
- package/bin/core-impl/anykey/anykey-mod.d.ts +12 -0
- package/bin/core-impl/anykey/anykey-mod.js +125 -0
- package/bin/core-impl/date/date.d.ts +2 -0
- package/bin/core-impl/date/date.js +236 -0
- package/bin/core-impl/editor/editor-mod.d.ts +25 -0
- package/bin/core-impl/editor/editor-mod.js +897 -0
- package/bin/core-impl/figures/figures-mod.d.ts +462 -0
- package/bin/core-impl/figures/figures-mod.js +286 -0
- package/bin/core-impl/figures/figures.test.d.ts +1 -0
- package/bin/core-impl/figures/figures.test.js +474 -0
- package/bin/core-impl/input/confirm-prompt.d.ts +5 -0
- package/bin/core-impl/input/confirm-prompt.js +173 -0
- package/bin/core-impl/input/input-prompt.d.ts +16 -0
- package/bin/core-impl/input/input-prompt.js +370 -0
- package/bin/core-impl/launcher/deprecated/_parser.ts.txt +167 -0
- package/bin/core-impl/launcher/deprecated/_utils.ts.txt +41 -0
- package/bin/core-impl/launcher/deprecated/args.ts.txt +108 -0
- package/bin/core-impl/launcher/deprecated/command.ts.txt +95 -0
- package/bin/core-impl/launcher/deprecated/launcher-mod.ts.txt +50 -0
- package/bin/core-impl/launcher/deprecated/usage.ts.txt +157 -0
- package/bin/core-impl/launcher/launcher-mod.d.ts +87 -0
- package/bin/core-impl/launcher/launcher-mod.js +364 -0
- package/bin/core-impl/msg-fmt/colors.d.ts +30 -0
- package/bin/core-impl/msg-fmt/colors.js +42 -0
- package/bin/core-impl/msg-fmt/logger.d.ts +17 -0
- package/bin/core-impl/msg-fmt/logger.js +106 -0
- package/bin/core-impl/msg-fmt/mapping.d.ts +3 -0
- package/bin/core-impl/msg-fmt/mapping.js +49 -0
- package/bin/core-impl/msg-fmt/messages.d.ts +35 -0
- package/bin/core-impl/msg-fmt/messages.js +316 -0
- package/bin/core-impl/msg-fmt/terminal.d.ts +15 -0
- package/bin/core-impl/msg-fmt/terminal.js +60 -0
- package/bin/core-impl/msg-fmt/variants.d.ts +11 -0
- package/bin/core-impl/msg-fmt/variants.js +52 -0
- package/bin/core-impl/next-steps/next-steps.d.ts +14 -0
- package/bin/core-impl/next-steps/next-steps.js +24 -0
- package/bin/core-impl/number/number-mod.d.ts +28 -0
- package/bin/core-impl/number/number-mod.js +197 -0
- package/bin/core-impl/results/results.d.ts +7 -0
- package/bin/core-impl/results/results.js +27 -0
- package/bin/core-impl/select/multiselect-prompt.d.ts +2 -0
- package/bin/core-impl/select/multiselect-prompt.js +342 -0
- package/bin/core-impl/select/nummultiselect-prompt.d.ts +6 -0
- package/bin/core-impl/select/nummultiselect-prompt.js +105 -0
- package/bin/core-impl/select/numselect-prompt.d.ts +7 -0
- package/bin/core-impl/select/numselect-prompt.js +115 -0
- package/bin/core-impl/select/select-prompt.d.ts +33 -0
- package/bin/core-impl/select/select-prompt.js +303 -0
- package/bin/core-impl/select/toggle-prompt.d.ts +5 -0
- package/bin/core-impl/select/toggle-prompt.js +209 -0
- package/bin/core-impl/st-end/end.d.ts +2 -0
- package/bin/core-impl/st-end/end.js +42 -0
- package/bin/core-impl/st-end/start.d.ts +17 -0
- package/bin/core-impl/st-end/start.js +67 -0
- package/bin/core-impl/task/progress.d.ts +2 -0
- package/bin/core-impl/task/progress.js +57 -0
- package/bin/core-impl/task/spinner.d.ts +15 -0
- package/bin/core-impl/task/spinner.js +110 -0
- package/bin/core-impl/utils/colorize.d.ts +2 -0
- package/bin/core-impl/utils/colorize.js +135 -0
- package/bin/core-impl/utils/errors.d.ts +1 -0
- package/bin/core-impl/utils/errors.js +17 -0
- package/bin/core-impl/utils/prevent.d.ts +8 -0
- package/bin/core-impl/utils/prevent.js +65 -0
- package/bin/core-impl/utils/prompt-end.d.ts +8 -0
- package/bin/core-impl/utils/prompt-end.js +34 -0
- package/bin/core-impl/utils/stream-text.d.ts +18 -0
- package/bin/core-impl/utils/stream-text.js +136 -0
- package/bin/core-impl/utils/system.d.ts +6 -0
- package/bin/core-impl/utils/system.js +7 -0
- package/bin/core-impl/utils/validate.d.ts +21 -0
- package/bin/core-impl/utils/validate.js +17 -0
- package/bin/core-impl/visual/animate/animate.d.ts +14 -0
- package/bin/core-impl/visual/animate/animate.js +65 -0
- package/bin/core-impl/visual/ascii-art/ascii-art.d.ts +6 -0
- package/bin/core-impl/visual/ascii-art/ascii-art.js +13 -0
- package/bin/core-types.d.ts +334 -0
- package/bin/core-types.js +0 -0
- package/bin/main.d.ts +36 -0
- package/bin/main.js +86 -0
- package/package.json +58 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { reliArgParser } from "@reliverse/reliarg";
|
|
2
|
+
import { relinka } from "@reliverse/relinka";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import path from "pathe";
|
|
6
|
+
const isDebugMode = process.argv.includes("--debug");
|
|
7
|
+
function debugLog(...args) {
|
|
8
|
+
if (isDebugMode) {
|
|
9
|
+
relinka("info", "[DEBUG]", ...args);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function defineCommand(options) {
|
|
13
|
+
return {
|
|
14
|
+
meta: options.meta,
|
|
15
|
+
args: options.args || {},
|
|
16
|
+
run: options.run,
|
|
17
|
+
subCommands: options.subCommands
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function showUsage(command, parserOptions = {}) {
|
|
21
|
+
relinka("info", `${command.meta.name} v${command.meta.version || ""}`);
|
|
22
|
+
if (command.meta.description) {
|
|
23
|
+
relinka("info", command.meta.description);
|
|
24
|
+
}
|
|
25
|
+
const fileCmds = parserOptions.fileBasedCmds;
|
|
26
|
+
if (fileCmds?.enable) {
|
|
27
|
+
const usageLine = `Usage: ${command.meta.name} <subCommand> [options]`;
|
|
28
|
+
relinka("info", usageLine);
|
|
29
|
+
try {
|
|
30
|
+
const commandsDir = path.resolve(fileCmds.cmdsRootPath);
|
|
31
|
+
const items = await fs.readdir(commandsDir, { withFileTypes: true });
|
|
32
|
+
const subCommandNames = [];
|
|
33
|
+
for (const dirent of items) {
|
|
34
|
+
if (dirent.isDirectory() || dirent.isFile()) {
|
|
35
|
+
const name = dirent.name.replace(/\.[jt]s$/, "");
|
|
36
|
+
try {
|
|
37
|
+
const importPath = path.join(
|
|
38
|
+
commandsDir,
|
|
39
|
+
dirent.isDirectory() ? `${name}/index.js` : `${name}.js`
|
|
40
|
+
);
|
|
41
|
+
const imported = await import(path.resolve(importPath));
|
|
42
|
+
if (imported.default && !imported.default.meta?.hidden) {
|
|
43
|
+
subCommandNames.push(name);
|
|
44
|
+
}
|
|
45
|
+
} catch (_err) {
|
|
46
|
+
debugLog(`Skipping file ${dirent.name}:`, _err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (subCommandNames.length > 0) {
|
|
51
|
+
relinka("info", "\nAvailable file-based subCommands:");
|
|
52
|
+
subCommandNames.forEach((sc) => relinka("info", ` ${sc}`));
|
|
53
|
+
}
|
|
54
|
+
} catch (_err) {
|
|
55
|
+
relinka(
|
|
56
|
+
"info",
|
|
57
|
+
`
|
|
58
|
+
(No file-based subcommands found in ${fileCmds.cmdsRootPath}.)`
|
|
59
|
+
);
|
|
60
|
+
debugLog("Error reading file-based commands:", _err);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
const subCommandNames = [];
|
|
64
|
+
if (command.subCommands) {
|
|
65
|
+
for (const [name, spec] of Object.entries(command.subCommands)) {
|
|
66
|
+
try {
|
|
67
|
+
const cmd = await loadSubCommand(spec);
|
|
68
|
+
if (!cmd?.meta?.hidden) {
|
|
69
|
+
const aliasDisplay = cmd.meta.aliases ? ` (aliases: ${cmd.meta.aliases.join(", ")})` : "";
|
|
70
|
+
subCommandNames.push(`${name}${aliasDisplay}`);
|
|
71
|
+
}
|
|
72
|
+
} catch (_err) {
|
|
73
|
+
debugLog(`Error loading subcommand ${name}:`, _err);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
let usageLine = `Usage: ${command.meta.name}`;
|
|
78
|
+
if (subCommandNames.length > 0) {
|
|
79
|
+
usageLine += " <subCommand> [options]";
|
|
80
|
+
} else {
|
|
81
|
+
usageLine += ` [options] ${renderPositional(command.args)}`;
|
|
82
|
+
}
|
|
83
|
+
relinka("info", usageLine);
|
|
84
|
+
if (subCommandNames.length > 0) {
|
|
85
|
+
relinka("info", "\nAvailable subCommands:");
|
|
86
|
+
subCommandNames.forEach((sc) => relinka("info", ` ${sc}`));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
relinka("info", "\nOptions:");
|
|
90
|
+
relinka("info", " -h, --help Show help");
|
|
91
|
+
relinka("info", " -v, --version Show version");
|
|
92
|
+
relinka("info", " --debug Enable debug mode");
|
|
93
|
+
for (const [key, def] of Object.entries(command.args || {})) {
|
|
94
|
+
if (def.type === "positional") {
|
|
95
|
+
relinka(
|
|
96
|
+
"info",
|
|
97
|
+
` <${key}> : ${def.description || ""} ${def.required ? "(required)" : ""}`
|
|
98
|
+
);
|
|
99
|
+
} else {
|
|
100
|
+
relinka(
|
|
101
|
+
"info",
|
|
102
|
+
` --${key} : ${def.description || ""} (type=${def.type})${def.required ? " (required)" : ""}${def.default !== void 0 ? ` [default: ${def.default}]` : ""}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export async function runMain(command, parserOptions = {}) {
|
|
108
|
+
if (!parserOptions.fileBasedCmds && (!command.subCommands || Object.keys(command.subCommands).length === 0)) {
|
|
109
|
+
parserOptions.fileBasedCmds = {
|
|
110
|
+
enable: true,
|
|
111
|
+
cmdsRootPath: "src/cli/args"
|
|
112
|
+
// default path
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const argv = process.argv.slice(2);
|
|
116
|
+
const autoExit = parserOptions.autoExit !== false;
|
|
117
|
+
if (checkHelp(argv)) {
|
|
118
|
+
await showUsage(command, parserOptions);
|
|
119
|
+
if (autoExit) process.exit(0);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (checkVersion(argv)) {
|
|
123
|
+
relinka("info", `${command.meta.name} v${command.meta.version || ""}`);
|
|
124
|
+
if (autoExit) process.exit(0);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const fileBasedEnabled = parserOptions.fileBasedCmds?.enable;
|
|
128
|
+
if (fileBasedEnabled && argv.length > 0) {
|
|
129
|
+
const subName = argv.shift();
|
|
130
|
+
try {
|
|
131
|
+
await runFileBasedSubCmd(
|
|
132
|
+
subName,
|
|
133
|
+
parserOptions.fileBasedCmds,
|
|
134
|
+
parserOptions
|
|
135
|
+
);
|
|
136
|
+
if (autoExit) process.exit(0);
|
|
137
|
+
return;
|
|
138
|
+
} catch (err) {
|
|
139
|
+
relinka("error", "Error loading file-based subcommand:", err.message);
|
|
140
|
+
if (autoExit) process.exit(1);
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!fileBasedEnabled && command.subCommands && argv.length > 0) {
|
|
145
|
+
const maybeSub = argv[0];
|
|
146
|
+
let subSpec;
|
|
147
|
+
for (const [key, spec] of Object.entries(command.subCommands)) {
|
|
148
|
+
if (key === maybeSub) {
|
|
149
|
+
subSpec = spec;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const cmd = await loadSubCommand(spec);
|
|
154
|
+
if (cmd.meta.aliases?.includes(maybeSub)) {
|
|
155
|
+
subSpec = spec;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
} catch (_err) {
|
|
159
|
+
debugLog(`Error checking alias for subcommand ${key}:`, _err);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (subSpec) {
|
|
163
|
+
argv.shift();
|
|
164
|
+
try {
|
|
165
|
+
await runSubCommand(subSpec, parserOptions);
|
|
166
|
+
if (autoExit) process.exit(0);
|
|
167
|
+
return;
|
|
168
|
+
} catch (err) {
|
|
169
|
+
relinka("error", "Error running subcommand:", err.message);
|
|
170
|
+
if (autoExit) process.exit(1);
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
await runCommandWithArgs(command, argv, parserOptions);
|
|
176
|
+
}
|
|
177
|
+
function checkHelp(argv) {
|
|
178
|
+
return argv.includes("--help") || argv.includes("-h");
|
|
179
|
+
}
|
|
180
|
+
function checkVersion(argv) {
|
|
181
|
+
return argv.includes("--version") || argv.includes("-v");
|
|
182
|
+
}
|
|
183
|
+
async function loadSubCommand(spec) {
|
|
184
|
+
if (typeof spec === "string") {
|
|
185
|
+
const mod = await import(spec);
|
|
186
|
+
if (!mod.default) {
|
|
187
|
+
throw new Error(`Subcommand module "${spec}" has no default export`);
|
|
188
|
+
}
|
|
189
|
+
return mod.default;
|
|
190
|
+
}
|
|
191
|
+
const imported = await spec();
|
|
192
|
+
if ("default" in imported && imported.default) {
|
|
193
|
+
return imported.default;
|
|
194
|
+
}
|
|
195
|
+
if (imported) {
|
|
196
|
+
return imported;
|
|
197
|
+
}
|
|
198
|
+
throw new Error("Subcommand import did not return a valid command");
|
|
199
|
+
}
|
|
200
|
+
async function runFileBasedSubCmd(subName, fileCmdOpts, parserOptions) {
|
|
201
|
+
const subPathDir = path.join(fileCmdOpts.cmdsRootPath, subName);
|
|
202
|
+
let importPath;
|
|
203
|
+
const possibleFiles = [
|
|
204
|
+
path.join(subPathDir, "index.js"),
|
|
205
|
+
path.join(subPathDir, "index.ts"),
|
|
206
|
+
path.join(subPathDir, `${subName}-mod.js`),
|
|
207
|
+
path.join(subPathDir, `${subName}-mod.ts`),
|
|
208
|
+
path.join(fileCmdOpts.cmdsRootPath, `${subName}.js`),
|
|
209
|
+
path.join(fileCmdOpts.cmdsRootPath, `${subName}.ts`),
|
|
210
|
+
path.join(fileCmdOpts.cmdsRootPath, `arg-${subName}.js`),
|
|
211
|
+
path.join(fileCmdOpts.cmdsRootPath, `arg-${subName}.ts`)
|
|
212
|
+
];
|
|
213
|
+
const dirExists = await fs.pathExists(subPathDir);
|
|
214
|
+
let isDirCommand = false;
|
|
215
|
+
if (dirExists) {
|
|
216
|
+
const stats = await fs.stat(subPathDir);
|
|
217
|
+
isDirCommand = stats.isDirectory();
|
|
218
|
+
}
|
|
219
|
+
if (isDirCommand) {
|
|
220
|
+
for (const pattern of possibleFiles.slice(0, 4)) {
|
|
221
|
+
if (await fs.pathExists(pattern)) {
|
|
222
|
+
importPath = pattern;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!importPath) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`No valid command file found in directory "${subName}". Expected one of: index.{js,ts} or ${subName}-mod.{js,ts}`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
for (const pattern of possibleFiles.slice(4)) {
|
|
233
|
+
if (await fs.pathExists(pattern)) {
|
|
234
|
+
importPath = pattern;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!importPath) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`No valid command file found for "${subName}". Expected one of: ${subName}.{js,ts} or arg-${subName}.{js,ts}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const imported = await import(path.resolve(importPath));
|
|
245
|
+
const subCommand = imported.default;
|
|
246
|
+
if (!subCommand) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`File-based subcommand "${subName}" has no default export or is invalid.`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
const argvRemaining = process.argv.slice(2);
|
|
252
|
+
await runCommandWithArgs(subCommand, argvRemaining, parserOptions);
|
|
253
|
+
}
|
|
254
|
+
async function runSubCommand(spec, parserOptions) {
|
|
255
|
+
const subCommand = await loadSubCommand(spec);
|
|
256
|
+
const argvRemaining = process.argv.slice(2);
|
|
257
|
+
await runCommandWithArgs(subCommand, argvRemaining, parserOptions);
|
|
258
|
+
}
|
|
259
|
+
async function runCommandWithArgs(command, argv, parserOptions) {
|
|
260
|
+
const autoExit = parserOptions.autoExit !== false;
|
|
261
|
+
const booleanKeys = Object.keys(command.args || {}).filter(
|
|
262
|
+
(k) => command.args[k].type === "boolean"
|
|
263
|
+
);
|
|
264
|
+
const defaultMap = {};
|
|
265
|
+
for (const [argKey, def] of Object.entries(command.args || {})) {
|
|
266
|
+
if (def.default !== void 0) {
|
|
267
|
+
defaultMap[argKey] = def.default;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const mergedParserOptions = {
|
|
271
|
+
...parserOptions,
|
|
272
|
+
boolean: [...parserOptions.boolean || [], ...booleanKeys],
|
|
273
|
+
defaults: { ...defaultMap, ...parserOptions.defaults || {} }
|
|
274
|
+
};
|
|
275
|
+
const parsed = reliArgParser(argv, mergedParserOptions);
|
|
276
|
+
debugLog("Parsed arguments:", parsed);
|
|
277
|
+
const finalArgs = {};
|
|
278
|
+
const positionalKeys = Object.keys(command.args || {}).filter(
|
|
279
|
+
(k) => command.args[k].type === "positional"
|
|
280
|
+
);
|
|
281
|
+
const leftoverPositionals = [...parsed._ || []];
|
|
282
|
+
for (let i = 0; i < positionalKeys.length; i++) {
|
|
283
|
+
const key = positionalKeys[i];
|
|
284
|
+
const def = command.args?.[key];
|
|
285
|
+
const val = leftoverPositionals[i];
|
|
286
|
+
if (val == null && def.required) {
|
|
287
|
+
relinka("error", `Missing required positional argument: <${key}>`);
|
|
288
|
+
await showUsage(command, parserOptions);
|
|
289
|
+
if (autoExit) process.exit(1);
|
|
290
|
+
else throw new Error(`Missing required positional argument: <${key}>`);
|
|
291
|
+
}
|
|
292
|
+
finalArgs[key] = val != null ? castArgValue(def, val, key) : def.default;
|
|
293
|
+
}
|
|
294
|
+
const otherKeys = Object.keys(command.args || {}).filter(
|
|
295
|
+
(k) => command.args[k].type !== "positional"
|
|
296
|
+
);
|
|
297
|
+
for (const key of otherKeys) {
|
|
298
|
+
const def = command.args?.[key];
|
|
299
|
+
let rawVal = parsed[key];
|
|
300
|
+
if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
|
|
301
|
+
rawVal = [rawVal];
|
|
302
|
+
}
|
|
303
|
+
if (rawVal == null && def.required) {
|
|
304
|
+
relinka("error", `Missing required argument: --${key}`);
|
|
305
|
+
await showUsage(command, parserOptions);
|
|
306
|
+
if (autoExit) process.exit(1);
|
|
307
|
+
else throw new Error(`Missing required argument: --${key}`);
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
finalArgs[key] = castArgValue(def, rawVal, key);
|
|
311
|
+
} catch (err) {
|
|
312
|
+
relinka("error", String(err));
|
|
313
|
+
if (autoExit) process.exit(1);
|
|
314
|
+
else throw err;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const ctx = {
|
|
318
|
+
args: finalArgs,
|
|
319
|
+
raw: argv
|
|
320
|
+
};
|
|
321
|
+
try {
|
|
322
|
+
await command.run(ctx);
|
|
323
|
+
} catch (err) {
|
|
324
|
+
relinka("error", `Error while executing command:
|
|
325
|
+
${String(err)}`);
|
|
326
|
+
if (autoExit) process.exit(1);
|
|
327
|
+
else throw err;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function castArgValue(def, rawVal, argName) {
|
|
331
|
+
if (rawVal == null) {
|
|
332
|
+
return def.default ?? void 0;
|
|
333
|
+
}
|
|
334
|
+
switch (def.type) {
|
|
335
|
+
case "boolean":
|
|
336
|
+
if (typeof rawVal === "string") {
|
|
337
|
+
const lower = rawVal.toLowerCase();
|
|
338
|
+
if (lower === "true") return true;
|
|
339
|
+
if (lower === "false") return false;
|
|
340
|
+
}
|
|
341
|
+
return Boolean(rawVal);
|
|
342
|
+
case "string":
|
|
343
|
+
return typeof rawVal === "string" ? rawVal : String(rawVal);
|
|
344
|
+
case "number": {
|
|
345
|
+
const n = Number(rawVal);
|
|
346
|
+
if (Number.isNaN(n)) {
|
|
347
|
+
throw new Error(`Invalid number provided for --${argName}: ${rawVal}`);
|
|
348
|
+
}
|
|
349
|
+
return n;
|
|
350
|
+
}
|
|
351
|
+
case "positional":
|
|
352
|
+
return String(rawVal);
|
|
353
|
+
case "array":
|
|
354
|
+
return Array.isArray(rawVal) ? rawVal : [String(rawVal)];
|
|
355
|
+
default:
|
|
356
|
+
return rawVal;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function renderPositional(args) {
|
|
360
|
+
const positionalKeys = Object.keys(args || {}).filter(
|
|
361
|
+
(k) => args[k].type === "positional"
|
|
362
|
+
);
|
|
363
|
+
return positionalKeys.map((k) => `<${k}>`).join(" ");
|
|
364
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ColorName, OutputColor, StandardColor } from "../../core-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Maps complex colors (gradients, bright, background) to standard terminal colors.
|
|
4
|
+
* Used by ora spinners and other terminal utilities that only support basic colors.
|
|
5
|
+
*
|
|
6
|
+
* Handles:
|
|
7
|
+
* - Gradient colors -> solid colors (e.g., retroGradient -> cyan)
|
|
8
|
+
* - Bright colors -> base colors (e.g., redBright -> red)
|
|
9
|
+
* - Background colors -> foreground colors (e.g., bgRed -> red)
|
|
10
|
+
* - Special colors -> undefined (reset, inverse, dim, none)
|
|
11
|
+
*
|
|
12
|
+
* @param color The complex color to convert
|
|
13
|
+
* @returns A standard terminal color or undefined for special colors
|
|
14
|
+
*/
|
|
15
|
+
export declare function toBaseColor(color?: ColorName): StandardColor | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Maps any color type to a standard solid color for consistent display.
|
|
18
|
+
* Similar to toBaseColor but always returns a color (never undefined).
|
|
19
|
+
*
|
|
20
|
+
* Handles:
|
|
21
|
+
* - Gradient colors -> solid colors (e.g., retroGradient -> cyan)
|
|
22
|
+
* - Bright colors -> base colors (e.g., redBright -> red)
|
|
23
|
+
* - Background colors -> foreground colors (e.g., bgRed -> red)
|
|
24
|
+
* - Special colors (reset, inverse, none) -> dim
|
|
25
|
+
* - Undefined -> dim
|
|
26
|
+
*
|
|
27
|
+
* @param color The color to convert
|
|
28
|
+
* @returns A standard terminal color, defaulting to "dim" for special cases
|
|
29
|
+
*/
|
|
30
|
+
export declare function toSolidColor(color?: ColorName): OutputColor;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const GRADIENT_COLOR_MAP = {
|
|
2
|
+
retroGradient: "cyan",
|
|
3
|
+
viceGradient: "green",
|
|
4
|
+
gradientGradient: "blue",
|
|
5
|
+
rainbowGradient: "blue",
|
|
6
|
+
cristalGradient: "blue",
|
|
7
|
+
mindGradient: "blue",
|
|
8
|
+
passionGradient: "blue"
|
|
9
|
+
};
|
|
10
|
+
const SPECIAL_COLORS = ["reset", "inverse", "none"];
|
|
11
|
+
function stripBrightModifier(color) {
|
|
12
|
+
return color.replace("Bright", "");
|
|
13
|
+
}
|
|
14
|
+
function stripBgModifier(color) {
|
|
15
|
+
return color.replace("bg", "").toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
function stripColorModifiers(color) {
|
|
18
|
+
if (color.includes("Bright")) {
|
|
19
|
+
return stripBrightModifier(color);
|
|
20
|
+
}
|
|
21
|
+
if (color.startsWith("bg")) {
|
|
22
|
+
return stripBgModifier(color);
|
|
23
|
+
}
|
|
24
|
+
return color;
|
|
25
|
+
}
|
|
26
|
+
export function toBaseColor(color) {
|
|
27
|
+
if (!color || color === "dim" || SPECIAL_COLORS.includes(color)) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
if (color in GRADIENT_COLOR_MAP) {
|
|
31
|
+
return GRADIENT_COLOR_MAP[color];
|
|
32
|
+
}
|
|
33
|
+
if (color.includes("Bright") || color.startsWith("bg")) {
|
|
34
|
+
const baseColor = stripColorModifiers(color);
|
|
35
|
+
return baseColor;
|
|
36
|
+
}
|
|
37
|
+
return color;
|
|
38
|
+
}
|
|
39
|
+
export function toSolidColor(color) {
|
|
40
|
+
const baseColor = toBaseColor(color);
|
|
41
|
+
return baseColor ?? "dim";
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AllKinds, StreamOptions } from "../../core-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Logs messages with configurable styling and formatting.
|
|
4
|
+
* Doesn't support streaming functionality.
|
|
5
|
+
*/
|
|
6
|
+
export declare function relinkaByRemptsDeprecated(kind: AllKinds, title: string, content?: string, hint?: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* Asynchronous version of relinka that supports streaming functionality.
|
|
9
|
+
* Use this when you want animated text output with optional spinner.
|
|
10
|
+
*
|
|
11
|
+
* Streaming is controlled by the streamOpts parameter:
|
|
12
|
+
* - Use { useSpinner: true } for spinner animation
|
|
13
|
+
* - Use { delay: number } for character-by-character streaming
|
|
14
|
+
* - Content and hint are optional regardless of streaming
|
|
15
|
+
*/
|
|
16
|
+
export declare const relinkaAsyncByRemptsDeprecated: (kind: AllKinds, title: string, content?: string, hint?: string, streamOpts?: StreamOptions) => Promise<void>;
|
|
17
|
+
export declare const throwError: (error: unknown) => never;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
streamText,
|
|
3
|
+
streamTextWithSpinner
|
|
4
|
+
} from "../utils/stream-text.js";
|
|
5
|
+
import { toSolidColor } from "./colors.js";
|
|
6
|
+
import { msg } from "./messages.js";
|
|
7
|
+
const verboseLogging = false;
|
|
8
|
+
const MESSAGE_CONFIGS = {
|
|
9
|
+
log: {
|
|
10
|
+
type: "M_INFO",
|
|
11
|
+
titleColor: "retroGradient",
|
|
12
|
+
titleTypography: "bold"
|
|
13
|
+
},
|
|
14
|
+
info: {
|
|
15
|
+
type: "M_INFO",
|
|
16
|
+
titleColor: "retroGradient",
|
|
17
|
+
titleTypography: "bold"
|
|
18
|
+
},
|
|
19
|
+
success: {
|
|
20
|
+
type: "M_INFO",
|
|
21
|
+
titleColor: "viceGradient",
|
|
22
|
+
titleTypography: "bold"
|
|
23
|
+
},
|
|
24
|
+
warn: {
|
|
25
|
+
type: "M_ERROR",
|
|
26
|
+
titleColor: "yellowBright",
|
|
27
|
+
titleTypography: "bold"
|
|
28
|
+
},
|
|
29
|
+
error: {
|
|
30
|
+
type: "M_ERROR",
|
|
31
|
+
titleColor: "yellowBright",
|
|
32
|
+
titleTypography: "bold"
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export function relinkaByRemptsDeprecated(kind, title, content, hint) {
|
|
36
|
+
const isVerbose = kind.endsWith("-verbose");
|
|
37
|
+
const baseKind = isVerbose ? kind.replace("-verbose", "") : kind;
|
|
38
|
+
if (isVerbose && !verboseLogging) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const config = MESSAGE_CONFIGS[baseKind];
|
|
42
|
+
msg({
|
|
43
|
+
...config,
|
|
44
|
+
title: isVerbose ? `[debug] ${title}` : title,
|
|
45
|
+
content: content ?? "",
|
|
46
|
+
contentColor: "dim",
|
|
47
|
+
contentTypography: "italic",
|
|
48
|
+
hint: hint ?? ""
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export const relinkaAsyncByRemptsDeprecated = async (kind, title, content, hint, streamOpts) => {
|
|
52
|
+
const isVerbose = kind.endsWith("-verbose");
|
|
53
|
+
const baseKind = isVerbose ? kind.replace("-verbose", "") : kind;
|
|
54
|
+
if (isVerbose && !verboseLogging) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const config = MESSAGE_CONFIGS[baseKind];
|
|
58
|
+
if (!streamOpts) {
|
|
59
|
+
msg({
|
|
60
|
+
...config,
|
|
61
|
+
title: isVerbose ? `[debug] ${title}` : title,
|
|
62
|
+
content: content ?? "",
|
|
63
|
+
contentColor: "dim",
|
|
64
|
+
contentTypography: "italic",
|
|
65
|
+
hint: hint ?? ""
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const titleText = isVerbose ? `[debug] ${title}` : title;
|
|
70
|
+
if (streamOpts.useSpinner) {
|
|
71
|
+
await streamTextWithSpinner({
|
|
72
|
+
text: titleText,
|
|
73
|
+
color: toSolidColor(config.titleColor),
|
|
74
|
+
delay: streamOpts.delay,
|
|
75
|
+
spinnerFrames: streamOpts.spinnerFrames,
|
|
76
|
+
spinnerDelay: streamOpts.spinnerDelay
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
await streamText({
|
|
80
|
+
text: titleText,
|
|
81
|
+
color: toSolidColor(config.titleColor),
|
|
82
|
+
delay: streamOpts.delay
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (content) {
|
|
86
|
+
await streamText({
|
|
87
|
+
text: content,
|
|
88
|
+
color: toSolidColor(config.contentColor) ?? "dim",
|
|
89
|
+
delay: streamOpts.delay
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (hint) {
|
|
93
|
+
await streamText({
|
|
94
|
+
text: hint,
|
|
95
|
+
color: "dim",
|
|
96
|
+
delay: streamOpts.delay
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export const throwError = (error) => {
|
|
101
|
+
msg({
|
|
102
|
+
type: "M_ERROR",
|
|
103
|
+
title: error instanceof Error ? `\u{1F914} Failed to set up the project: ${error.message}` : "\u{1F914} An unknown error occurred."
|
|
104
|
+
});
|
|
105
|
+
process.exit(1);
|
|
106
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { re } from "@reliverse/relico";
|
|
2
|
+
import gradient, { cristal, mind, passion, retro, vice } from "gradient-string";
|
|
3
|
+
import { rainbow } from "gradient-string";
|
|
4
|
+
export const colorMap = {
|
|
5
|
+
// @reliverse/relico
|
|
6
|
+
none: (text) => text,
|
|
7
|
+
reset: re.reset,
|
|
8
|
+
bgCyan: re.bgCyan,
|
|
9
|
+
bgCyanBright: re.bgCyanBright,
|
|
10
|
+
black: re.black,
|
|
11
|
+
blue: re.blue,
|
|
12
|
+
blueBright: re.blueBright,
|
|
13
|
+
cyan: re.cyan,
|
|
14
|
+
cyanBright: re.cyanBright,
|
|
15
|
+
dim: re.dim,
|
|
16
|
+
gray: re.gray,
|
|
17
|
+
green: re.green,
|
|
18
|
+
greenBright: re.greenBright,
|
|
19
|
+
inverse: (text) => re.bold(re.inverse(text)),
|
|
20
|
+
magenta: re.magenta,
|
|
21
|
+
magentaBright: re.magentaBright,
|
|
22
|
+
red: re.red,
|
|
23
|
+
redBright: re.redBright,
|
|
24
|
+
white: re.white,
|
|
25
|
+
yellow: re.yellow,
|
|
26
|
+
yellowBright: re.yellowBright,
|
|
27
|
+
// gradient-string
|
|
28
|
+
cristalGradient: cristal,
|
|
29
|
+
gradientGradient: gradient([
|
|
30
|
+
"red",
|
|
31
|
+
"yellow",
|
|
32
|
+
"green",
|
|
33
|
+
"cyan",
|
|
34
|
+
"blue",
|
|
35
|
+
"magenta"
|
|
36
|
+
]),
|
|
37
|
+
mindGradient: mind,
|
|
38
|
+
passionGradient: passion,
|
|
39
|
+
rainbowGradient: rainbow,
|
|
40
|
+
retroGradient: retro,
|
|
41
|
+
viceGradient: vice
|
|
42
|
+
};
|
|
43
|
+
export const typographyMap = {
|
|
44
|
+
none: (text) => text,
|
|
45
|
+
bold: re.bold,
|
|
46
|
+
italic: re.italic,
|
|
47
|
+
strikethrough: re.strikethrough,
|
|
48
|
+
underline: re.underline
|
|
49
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ColorName, FmtMsgOptions, Symbols } from "../../core-types.js";
|
|
2
|
+
export declare const symbols: Symbols;
|
|
3
|
+
/**
|
|
4
|
+
* Returns a colored vertical bar symbol. Prevents gradient colors for bars.
|
|
5
|
+
*/
|
|
6
|
+
export declare const bar: ({ borderColor, }?: {
|
|
7
|
+
borderColor?: ColorName;
|
|
8
|
+
}) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Main formatter function: builds the final text output based on FmtMsgOptions.
|
|
11
|
+
*/
|
|
12
|
+
export declare function fmt(opts: FmtMsgOptions): {
|
|
13
|
+
text: string;
|
|
14
|
+
lineCount: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Logs a formatted message to the console and records how many lines it occupies.
|
|
18
|
+
*/
|
|
19
|
+
export declare function msg(opts: FmtMsgOptions): void;
|
|
20
|
+
/**
|
|
21
|
+
* Undo the last printed message by deleting its lines from the terminal.
|
|
22
|
+
* @param count How many messages to undo. Defaults to 1.
|
|
23
|
+
*/
|
|
24
|
+
export declare function msgUndo(count?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Undo all printed messages so far.
|
|
27
|
+
*/
|
|
28
|
+
export declare function msgUndoAll(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Prints: "│ <text>" (two spaces after the bar).
|
|
31
|
+
* If text is empty, it just prints "│".
|
|
32
|
+
* If indent is 1, it prints "│ <text>" (one space).
|
|
33
|
+
* If indent is 2, it prints "│ <text>" (two spaces), etc.
|
|
34
|
+
*/
|
|
35
|
+
export declare function printLineBar(text: string, indent?: number): void;
|