@reliverse/rempts 1.7.48 → 1.7.50
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-npm/bin/mod.d.mts +57 -92
- package/dist-npm/bin/mod.mjs +208 -512
- package/package.json +8 -8
package/dist-npm/bin/mod.d.mts
CHANGED
|
@@ -1152,40 +1152,43 @@ type EmptyArgs = Record<string, never>;
|
|
|
1152
1152
|
interface BaseArgProps {
|
|
1153
1153
|
description?: string;
|
|
1154
1154
|
required?: boolean;
|
|
1155
|
-
allowed?: string[];
|
|
1155
|
+
allowed?: readonly string[];
|
|
1156
1156
|
}
|
|
1157
1157
|
interface BaseArgDefinition {
|
|
1158
1158
|
type: string;
|
|
1159
1159
|
description?: string;
|
|
1160
1160
|
required?: boolean;
|
|
1161
1161
|
default?: any;
|
|
1162
|
-
allowed?: any[];
|
|
1162
|
+
allowed?: readonly any[];
|
|
1163
1163
|
dependencies?: string[];
|
|
1164
1164
|
}
|
|
1165
1165
|
type PositionalArgDefinition = BaseArgDefinition & {
|
|
1166
1166
|
type: "positional";
|
|
1167
1167
|
default?: string;
|
|
1168
|
+
allowed?: readonly string[];
|
|
1168
1169
|
};
|
|
1169
1170
|
type BooleanArgDefinition = BaseArgDefinition & {
|
|
1170
1171
|
type: "boolean";
|
|
1171
1172
|
default?: boolean;
|
|
1172
|
-
allowed?: boolean[];
|
|
1173
|
+
allowed?: readonly boolean[];
|
|
1173
1174
|
alias?: string;
|
|
1174
1175
|
};
|
|
1175
1176
|
type StringArgDefinition = BaseArgDefinition & {
|
|
1176
1177
|
type: "string";
|
|
1177
1178
|
default?: string;
|
|
1179
|
+
allowed?: readonly string[];
|
|
1178
1180
|
alias?: string;
|
|
1179
1181
|
};
|
|
1180
1182
|
type NumberArgDefinition = BaseArgDefinition & {
|
|
1181
1183
|
type: "number";
|
|
1182
1184
|
default?: number;
|
|
1183
|
-
allowed?: number[];
|
|
1185
|
+
allowed?: readonly number[];
|
|
1184
1186
|
alias?: string;
|
|
1185
1187
|
};
|
|
1186
1188
|
type ArrayArgDefinition = BaseArgDefinition & {
|
|
1187
1189
|
type: "array";
|
|
1188
1190
|
default?: string | readonly string[];
|
|
1191
|
+
allowed?: readonly string[];
|
|
1189
1192
|
alias?: string;
|
|
1190
1193
|
};
|
|
1191
1194
|
type ArgDefinition = PositionalArgDefinition | BooleanArgDefinition | StringArgDefinition | NumberArgDefinition | ArrayArgDefinition;
|
|
@@ -1297,49 +1300,69 @@ interface Command<A extends ArgDefinitions = EmptyArgs> {
|
|
|
1297
1300
|
*/
|
|
1298
1301
|
router?: AnyRouter;
|
|
1299
1302
|
}
|
|
1303
|
+
type ExtractAllowed<T extends ArgDefinition> = T extends {
|
|
1304
|
+
type: "positional";
|
|
1305
|
+
allowed: readonly (infer U)[];
|
|
1306
|
+
} ? U : T extends {
|
|
1307
|
+
type: "positional";
|
|
1308
|
+
} ? string : T extends {
|
|
1309
|
+
type: "boolean";
|
|
1310
|
+
allowed: readonly (infer U)[];
|
|
1311
|
+
} ? U : T extends {
|
|
1312
|
+
type: "boolean";
|
|
1313
|
+
} ? boolean : T extends {
|
|
1314
|
+
type: "string";
|
|
1315
|
+
allowed: readonly (infer U)[];
|
|
1316
|
+
} ? U : T extends {
|
|
1317
|
+
type: "string";
|
|
1318
|
+
} ? string : T extends {
|
|
1319
|
+
type: "number";
|
|
1320
|
+
allowed: readonly (infer U)[];
|
|
1321
|
+
} ? U : T extends {
|
|
1322
|
+
type: "number";
|
|
1323
|
+
} ? number : T extends {
|
|
1324
|
+
type: "array";
|
|
1325
|
+
allowed: readonly (infer U)[];
|
|
1326
|
+
} ? U[] : T extends {
|
|
1327
|
+
type: "array";
|
|
1328
|
+
} ? string[] : never;
|
|
1300
1329
|
type InferArgTypes<A extends ArgDefinitions> = {
|
|
1301
|
-
[K in keyof A]: A[K]
|
|
1302
|
-
type: "array";
|
|
1303
|
-
} ? string[] : never;
|
|
1330
|
+
[K in keyof A]: ExtractAllowed<A[K]>;
|
|
1304
1331
|
};
|
|
1305
1332
|
interface FileBasedOptions {
|
|
1306
1333
|
enable: boolean;
|
|
1307
1334
|
cmdsRootPath: string;
|
|
1308
1335
|
}
|
|
1309
1336
|
|
|
1337
|
+
interface CallCmdOptions {
|
|
1338
|
+
/** Whether to automatically exit process on errors (default: false for programmatic usage) */
|
|
1339
|
+
autoExit?: boolean;
|
|
1340
|
+
/** Whether to show debug output */
|
|
1341
|
+
debug?: boolean;
|
|
1342
|
+
/** Whether to call lifecycle hooks (onCmdInit/onCmdExit) */
|
|
1343
|
+
useLifecycleHooks?: boolean;
|
|
1344
|
+
/** Custom parser options for argv processing */
|
|
1345
|
+
parserOptions?: ReliArgParserOptions;
|
|
1346
|
+
}
|
|
1310
1347
|
/**
|
|
1311
|
-
*
|
|
1348
|
+
* Programmatically call a defineCommand command with arguments.
|
|
1349
|
+
* Fully compatible with launcher-mod.ts execution logic.
|
|
1312
1350
|
*
|
|
1313
|
-
* @param
|
|
1314
|
-
* @
|
|
1351
|
+
* @param command - The command definition created with defineCommand()
|
|
1352
|
+
* @param input - Either argv array (CLI-style) or args object (programmatic style)
|
|
1353
|
+
* @param options - Optional configuration for execution
|
|
1354
|
+
* @returns Promise resolving to the command context
|
|
1315
1355
|
*
|
|
1316
1356
|
* @example
|
|
1317
1357
|
* ```ts
|
|
1318
|
-
* //
|
|
1319
|
-
* const
|
|
1358
|
+
* // CLI-style with argv array
|
|
1359
|
+
* const result = await callCmd(myCommand, ['--flag', 'value', 'positional']);
|
|
1320
1360
|
*
|
|
1321
|
-
* //
|
|
1322
|
-
* await
|
|
1323
|
-
* await runCmd(cmd, [`--dev ${isDev}`]); // ❌ Wrong - creates single string
|
|
1361
|
+
* // Programmatic style with object
|
|
1362
|
+
* const result = await callCmd(myCommand, { flag: true, name: 'value' });
|
|
1324
1363
|
* ```
|
|
1325
1364
|
*/
|
|
1326
|
-
declare function
|
|
1327
|
-
|
|
1328
|
-
/**
|
|
1329
|
-
* Static implementation functions for the typed command system.
|
|
1330
|
-
* These functions are imported by the generated cmds.ts file.
|
|
1331
|
-
*/
|
|
1332
|
-
declare function argsToStringArray(args: Record<string, unknown>): string[];
|
|
1333
|
-
declare function createCallCmd<TCommandArgsMap>(): Promise<(<T extends keyof TCommandArgsMap>(cmdName: T, args?: TCommandArgsMap[T]) => Promise<void>)>;
|
|
1334
|
-
declare function createGetTypedCmd<TCommandArgsMap>(): Promise<(<T extends keyof TCommandArgsMap>(cmdName: T) => Promise<{
|
|
1335
|
-
command: Command;
|
|
1336
|
-
run: (args?: TCommandArgsMap[T]) => Promise<void>;
|
|
1337
|
-
}>)>;
|
|
1338
|
-
declare function callCmdImpl<TCommandArgsMap>(cmdName: keyof TCommandArgsMap, args?: TCommandArgsMap[keyof TCommandArgsMap]): Promise<void>;
|
|
1339
|
-
declare function getTypedCmdImpl<TCommandArgsMap>(cmdName: keyof TCommandArgsMap): Promise<{
|
|
1340
|
-
command: Command;
|
|
1341
|
-
run: (args?: TCommandArgsMap[keyof TCommandArgsMap]) => Promise<void>;
|
|
1342
|
-
}>;
|
|
1365
|
+
declare function callCmd<A extends ArgDefinitions = EmptyArgs>(command: Command<A>, input: string[] | Partial<InferArgTypes<A>>, options?: CallCmdOptions): Promise<CommandContext<InferArgTypes<A>>>;
|
|
1343
1366
|
|
|
1344
1367
|
/**
|
|
1345
1368
|
* JSON representation of a commander `Command` instance
|
|
@@ -1758,64 +1781,6 @@ declare function createCli<A extends ArgDefinitions = EmptyArgs>(options: Comman
|
|
|
1758
1781
|
* for IntelliSense and validation for array defaults against options.
|
|
1759
1782
|
*/
|
|
1760
1783
|
declare function defineArgs<A extends ArgDefinitions>(args: A): A;
|
|
1761
|
-
/**
|
|
1762
|
-
* Programmatically run a command with subcommand support and flexible argument handling.
|
|
1763
|
-
* This function can handle subcommands (including nested), positional arguments, and automatically normalizes
|
|
1764
|
-
* template literals and space-separated strings.
|
|
1765
|
-
*
|
|
1766
|
-
* @param command The command definition (from defineCommand)
|
|
1767
|
-
* @param argv The argv array to parse (default: []). Supports template literals and subcommands.
|
|
1768
|
-
* @param parserOptions Optional reliArgParser options
|
|
1769
|
-
*
|
|
1770
|
-
* @example
|
|
1771
|
-
* ```ts
|
|
1772
|
-
* // ✅ Single command with template literals
|
|
1773
|
-
* await runCmdWithSubcommands(cmd, [`--dev ${isDev}`]);
|
|
1774
|
-
*
|
|
1775
|
-
* // ✅ Subcommand with arguments
|
|
1776
|
-
* await runCmdWithSubcommands(cmd, [`build --input src/mod.ts --someBoolean`]);
|
|
1777
|
-
*
|
|
1778
|
-
* // ✅ Subcommand with positional arguments
|
|
1779
|
-
* await runCmdWithSubcommands(cmd, [`build src/mod.ts --someBoolean`]);
|
|
1780
|
-
*
|
|
1781
|
-
* // ✅ Nested subcommands
|
|
1782
|
-
* await runCmdWithSubcommands(cmd, [`build someSubCmd src/mod.ts --no-cjs`]);
|
|
1783
|
-
* await runCmdWithSubcommands(cmd, [`build sub1 sub2 sub3 file.ts --flag`]);
|
|
1784
|
-
*
|
|
1785
|
-
* // ✅ Mixed array with subcommands
|
|
1786
|
-
* await runCmdWithSubcommands(cmd, [
|
|
1787
|
-
* `build someSubCmd src/mod.ts`,
|
|
1788
|
-
* "--no-cjs",
|
|
1789
|
-
* "--verbose"
|
|
1790
|
-
* ]);
|
|
1791
|
-
* ```
|
|
1792
|
-
*/
|
|
1793
|
-
declare function runCmdWithSubcommands<A extends ArgDefinitions = EmptyArgs>(command: Command<A>, argv?: string[], parserOptions?: ReliArgParserOptions & {
|
|
1794
|
-
fileBased?: FileBasedOptions;
|
|
1795
|
-
autoExit?: boolean;
|
|
1796
|
-
}): Promise<any>;
|
|
1797
|
-
/**
|
|
1798
|
-
* Programmatically run a command's run() handler with parsed arguments.
|
|
1799
|
-
* Does not handle subcommands, file-based commands, or global hooks.
|
|
1800
|
-
* Suitable for use in demos, tests, or programmatic invocation.
|
|
1801
|
-
*
|
|
1802
|
-
* @param command The command definition (from defineCommand)
|
|
1803
|
-
* @param argv The argv array to parse (default: []). Each argument should be a separate array element.
|
|
1804
|
-
* @param parserOptions Optional reliArgParser options
|
|
1805
|
-
*
|
|
1806
|
-
* @example
|
|
1807
|
-
* **each argument as separate array element**:
|
|
1808
|
-
* ```ts
|
|
1809
|
-
* await runCmd(cmd, ["--dev", "true"]);
|
|
1810
|
-
* await runCmd(cmd, ["--name", "John", "--verbose"]);
|
|
1811
|
-
* ```
|
|
1812
|
-
* **automatic normalization of template literals**:
|
|
1813
|
-
* ```ts
|
|
1814
|
-
* await runCmd(cmd, [`--dev ${isDev}`]); // Automatically converted to ["--dev", "true"]
|
|
1815
|
-
* await runCmd(cmd, [`--dev ${isDev} --build mod.ts`]); // ["--dev", "true", "--build", "mod.ts"]
|
|
1816
|
-
* ```
|
|
1817
|
-
*/
|
|
1818
|
-
declare function runCmd<A extends ArgDefinitions = EmptyArgs>(command: Command<A>, argv?: string[], parserOptions?: ReliArgParserOptions): Promise<void>;
|
|
1819
1784
|
|
|
1820
1785
|
declare const runMain: typeof createCli;
|
|
1821
1786
|
|
|
@@ -2329,5 +2294,5 @@ declare function createAsciiArt({ message, font, clearConsole, }: {
|
|
|
2329
2294
|
clearConsole?: boolean;
|
|
2330
2295
|
}): Promise<void>;
|
|
2331
2296
|
|
|
2332
|
-
export { CANCEL, CliValidationError, FailedToExitError, StandardSchemaV1Error, TrpcCommand, addCompletions, animateText, animationMap, anykeyPrompt, applyVariant,
|
|
2333
|
-
export type { AllKinds, AnyProcedure, AnyRouter, ArgDefinition, ArgDefinitions, ArrayArgDefinition, BaseArgDefinition, BaseArgProps, BooleanArgDefinition, BorderColorName, CancelValue, ChoiceOptions, ClackPromptsLike, ColorName, Command, CommandContext, CommandHook, CommandJSON, CommandMeta, CommandRun, CommandSpec, CommanderProgramLike, CommandsMap, ConfirmPromptOptions, CreateCallerFactoryLike, DatePromptOptions, DefineCommandOptions, Dependencies, EditorExitResult, EmptyArgs, EnquirerLike, FileBasedOptions, FmtMsgOptions, GroupContext, GroupOptions, GroupStep, GroupSteps, InferArgTypes, InputPromptOptions, InquirerPromptOptions, InquirerPromptsLike, Log, Logger, MessageConfig, MessageKind, MsgConfig, MsgType, MultiselectPromptParams, NumberArgDefinition, OmeletteInstanceLike, OrpcProcedureLike, OrpcRouterLike, OutputColor, ParsedProcedure, PositionalArgDefinition, PreventWrongTerminalSizeOptions, ProgressBar, ProgressBarOptions, PromptContext, PromptOptions, PromptType, Promptable, Prompter, PromptsLike, RenderParams, Result, ResultsType, SelectOption, SelectPromptParams, SeparatorOption, StandardColor, StandardSchemaV1, StandardSchemaV1FailureResult, StandardSchemaV1InferInput, StandardSchemaV1InferOutput, StandardSchemaV1Issue, StandardSchemaV1PathSegment, StandardSchemaV1Props, StandardSchemaV1Result, StandardSchemaV1SuccessResult, StandardSchemaV1Types, StreamOptions, StreamTextOptions, StringArgDefinition, SymbolName, Symbols, TogglePromptParams, Trpc10ProcedureLike, Trpc10RouterLike, Trpc11ProcedureLike, Trpc11ProcedureRecordLike, Trpc11RouterLike, TrpcCli, TrpcCliMeta, TrpcCliParams, TrpcCliRunParams, TrpcServerModuleLike, TypographyName, VariantName$1 as VariantName, inferRouterContext };
|
|
2297
|
+
export { CANCEL, CliValidationError, FailedToExitError, StandardSchemaV1Error, TrpcCommand, addCompletions, animateText, animationMap, anykeyPrompt, applyVariant, bar, block, breakLines, callCmd, cancel, colorMap, colorize, commandToJSON, completePrompt, confirm, confirmPrompt, countLines, createAsciiArt, createCancel, createCli, createMultiStep, createRpcCli, createShadowCommand, createStep, datePrompt, defineArgs, defineCommand, deleteLastLine, deleteLastLines, endPrompt, errorHandler, fallbackSymbols, figures, flattenedProperties, fmt, getColumns, getDescription, getEnumChoices, getExactTerminalWidth, getSchemaTypes, getTerminalHeight, getTerminalWidth, group, incompatiblePropertyPairs, input, inputPrompt, intro, introPrompt, isCancel, isOrpcRouter, isTerminalInteractive, isTrpc11Procedure, isTrpc11Router, isValidName, isValidVariant, isWindows, lineByLineConsoleLogger, lineByLineLogger, log, looksLikeInstanceof, looksLikeStandardSchema, looksLikeStandardSchemaFailure, mainSymbols, msg, msgUndo, msgUndoAll, multiselect, multiselectPrompt, nextStepsPrompt, normalizeName, numMultiSelectPrompt, numSelectPrompt, numberPrompt, outro, outroPrompt, parseProcedureInputs, parseRouter, password, pm, prettifyStandardSchemaError, preventUnsupportedTTY, preventWindowsHomeDirRoot, preventWrongTerminalSize, printLineBar, promptify, relinkaAsyncByRemptsDeprecated, relinkaByRemptsDeprecated, reliversePrompts, removeCursor, renderEndLine, renderEndLineInput, restoreCursor, resultPrompt, runMain, select, selectPrompt, selectSimple, setRawMode, showUsage, spinner, startEditor, startPrompt, streamText, streamTextBox, streamTextWithSpinner, symbols, taskProgressPrompt, taskSpinPrompt, text, throwError, toBaseColor, toDotPath, toSolidColor, togglePrompt, typographyMap, useSpinner, variantMap };
|
|
2298
|
+
export type { AllKinds, AnyProcedure, AnyRouter, ArgDefinition, ArgDefinitions, ArrayArgDefinition, BaseArgDefinition, BaseArgProps, BooleanArgDefinition, BorderColorName, CallCmdOptions, CancelValue, ChoiceOptions, ClackPromptsLike, ColorName, Command, CommandContext, CommandHook, CommandJSON, CommandMeta, CommandRun, CommandSpec, CommanderProgramLike, CommandsMap, ConfirmPromptOptions, CreateCallerFactoryLike, DatePromptOptions, DefineCommandOptions, Dependencies, EditorExitResult, EmptyArgs, EnquirerLike, FileBasedOptions, FmtMsgOptions, GroupContext, GroupOptions, GroupStep, GroupSteps, InferArgTypes, InputPromptOptions, InquirerPromptOptions, InquirerPromptsLike, Log, Logger, MessageConfig, MessageKind, MsgConfig, MsgType, MultiselectPromptParams, NumberArgDefinition, OmeletteInstanceLike, OrpcProcedureLike, OrpcRouterLike, OutputColor, ParsedProcedure, PositionalArgDefinition, PreventWrongTerminalSizeOptions, ProgressBar, ProgressBarOptions, PromptContext, PromptOptions, PromptType, Promptable, Prompter, PromptsLike, RenderParams, Result, ResultsType, SelectOption, SelectPromptParams, SeparatorOption, StandardColor, StandardSchemaV1, StandardSchemaV1FailureResult, StandardSchemaV1InferInput, StandardSchemaV1InferOutput, StandardSchemaV1Issue, StandardSchemaV1PathSegment, StandardSchemaV1Props, StandardSchemaV1Result, StandardSchemaV1SuccessResult, StandardSchemaV1Types, StreamOptions, StreamTextOptions, StringArgDefinition, SymbolName, Symbols, TogglePromptParams, Trpc10ProcedureLike, Trpc10RouterLike, Trpc11ProcedureLike, Trpc11ProcedureRecordLike, Trpc11RouterLike, TrpcCli, TrpcCliMeta, TrpcCliParams, TrpcCliRunParams, TrpcServerModuleLike, TypographyName, VariantName$1 as VariantName, inferRouterContext };
|
package/dist-npm/bin/mod.mjs
CHANGED
|
@@ -16,12 +16,11 @@ import readline__default from 'node:readline';
|
|
|
16
16
|
import { ReadStream, WriteStream } from 'node:tty';
|
|
17
17
|
import readline$1 from 'node:readline/promises';
|
|
18
18
|
import { repeat, digit, buildRegExp, startOfString, endOfString } from 'ts-regex-builder';
|
|
19
|
-
import path
|
|
19
|
+
import path from '@reliverse/pathkit';
|
|
20
20
|
import fs from '@reliverse/relifso';
|
|
21
21
|
import { loadConfig } from 'c12';
|
|
22
22
|
import termkit from 'terminal-kit';
|
|
23
23
|
import { homedir } from 'node:os';
|
|
24
|
-
import { createJiti } from 'jiti';
|
|
25
24
|
import { reliArgParser } from '@reliverse/reliarg';
|
|
26
25
|
import { readPackageJSON } from 'pkg-types';
|
|
27
26
|
import { inspect } from 'node:util';
|
|
@@ -3112,286 +3111,230 @@ async function introPrompt(optionsOrTitle) {
|
|
|
3112
3111
|
const startPrompt = introPrompt;
|
|
3113
3112
|
const intro = introPrompt;
|
|
3114
3113
|
|
|
3115
|
-
|
|
3116
|
-
debug
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
const COMMAND_EXTENSIONS = [".ts", ".js"];
|
|
3121
|
-
const COMMAND_FILENAMES = ["cmd.ts", "cmd.js"];
|
|
3122
|
-
const getCallerDirectory = async () => {
|
|
3123
|
-
if (process$1.env._REMPTS_CALLER_DIR) {
|
|
3124
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3125
|
-
relinka("verbose", `Using explicit caller directory: ${process$1.env._REMPTS_CALLER_DIR}`);
|
|
3126
|
-
}
|
|
3127
|
-
return process$1.env._REMPTS_CALLER_DIR;
|
|
3128
|
-
}
|
|
3129
|
-
const stack = new Error().stack?.split("\n") ?? [];
|
|
3130
|
-
const cwd = process$1.cwd();
|
|
3131
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3132
|
-
relinka("verbose", "Stack trace for getCallerDirectory:");
|
|
3133
|
-
stack.forEach((line, index) => {
|
|
3134
|
-
relinka("verbose", ` [${index}]: ${line.trim()}`);
|
|
3135
|
-
});
|
|
3136
|
-
}
|
|
3137
|
-
for (const line of stack) {
|
|
3138
|
-
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
3139
|
-
if (match?.[1]) {
|
|
3140
|
-
const filePath = match[1];
|
|
3141
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3142
|
-
relinka("verbose", `Checking file path: ${filePath}`);
|
|
3143
|
-
}
|
|
3144
|
-
if (!filePath.includes("node_modules") && !filePath.includes("command-runner") && !filePath.includes("command-typed") && !filePath.includes("launcher-mod") && !filePath.includes("launcher-types") && !filePath.endsWith("mod.mjs") && // Skip compiled output
|
|
3145
|
-
!filePath.endsWith("mod.js") && // Skip compiled output
|
|
3146
|
-
!filePath.endsWith("mod.ts")) {
|
|
3147
|
-
try {
|
|
3148
|
-
const fileDir = dirname(filePath);
|
|
3149
|
-
let currentDir2 = fileDir;
|
|
3150
|
-
let packageRoot = null;
|
|
3151
|
-
while (currentDir2 !== dirname(currentDir2)) {
|
|
3152
|
-
try {
|
|
3153
|
-
const packageJsonPath = resolve(currentDir2, "package.json");
|
|
3154
|
-
if (await fs.pathExists(packageJsonPath)) {
|
|
3155
|
-
packageRoot = currentDir2;
|
|
3156
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3157
|
-
relinka("verbose", `Found package.json at: ${packageRoot}`);
|
|
3158
|
-
}
|
|
3159
|
-
const cwdPackageJsonPath = resolve(cwd, "package.json");
|
|
3160
|
-
if (await fs.pathExists(cwdPackageJsonPath)) {
|
|
3161
|
-
try {
|
|
3162
|
-
const callerPackage = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
|
|
3163
|
-
const cwdPackage = JSON.parse(await fs.readFile(cwdPackageJsonPath, "utf-8"));
|
|
3164
|
-
if (callerPackage.name !== cwdPackage.name || callerPackage.version !== cwdPackage.version) {
|
|
3165
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3166
|
-
relinka("verbose", `Using caller package root: ${packageRoot} (${callerPackage.name}@${callerPackage.version})`);
|
|
3167
|
-
}
|
|
3168
|
-
return packageRoot;
|
|
3169
|
-
}
|
|
3170
|
-
} catch {
|
|
3171
|
-
if (resolve(packageRoot) !== resolve(cwd)) {
|
|
3172
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3173
|
-
relinka("verbose", `Using caller package root (different path): ${packageRoot}`);
|
|
3174
|
-
}
|
|
3175
|
-
return packageRoot;
|
|
3176
|
-
}
|
|
3177
|
-
}
|
|
3178
|
-
} else {
|
|
3179
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3180
|
-
relinka("verbose", `Using caller package root (no CWD package.json): ${packageRoot}`);
|
|
3181
|
-
}
|
|
3182
|
-
return packageRoot;
|
|
3183
|
-
}
|
|
3184
|
-
break;
|
|
3185
|
-
}
|
|
3186
|
-
} catch {
|
|
3187
|
-
}
|
|
3188
|
-
currentDir2 = dirname(currentDir2);
|
|
3189
|
-
}
|
|
3190
|
-
const resolvedFileDir = resolve(fileDir);
|
|
3191
|
-
const resolvedCwd = resolve(cwd);
|
|
3192
|
-
if (resolvedFileDir !== resolvedCwd && !resolvedFileDir.startsWith(resolvedCwd)) {
|
|
3193
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3194
|
-
relinka("verbose", `Using caller directory (different from CWD): ${fileDir}`);
|
|
3195
|
-
}
|
|
3196
|
-
return packageRoot || fileDir;
|
|
3197
|
-
}
|
|
3198
|
-
} catch {
|
|
3199
|
-
continue;
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3114
|
+
async function callCmd(command, input, options = {}) {
|
|
3115
|
+
const { autoExit = false, debug = false, useLifecycleHooks = true, parserOptions = {} } = options;
|
|
3116
|
+
const debugLog = (...args) => {
|
|
3117
|
+
if (debug) {
|
|
3118
|
+
relinka("log", "[callCmd DEBUG]", ...args);
|
|
3202
3119
|
}
|
|
3203
|
-
}
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
if (await fs.pathExists(packageJsonPath)) {
|
|
3215
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3216
|
-
relinka("verbose", `Found command package in node_modules: ${packageDir}`);
|
|
3217
|
-
}
|
|
3218
|
-
return packageDir;
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
} catch {
|
|
3222
|
-
continue;
|
|
3223
|
-
}
|
|
3224
|
-
}
|
|
3120
|
+
};
|
|
3121
|
+
debugLog("Calling command with input:", input);
|
|
3122
|
+
debugLog("Command meta:", command.meta);
|
|
3123
|
+
try {
|
|
3124
|
+
let ctx;
|
|
3125
|
+
if (Array.isArray(input)) {
|
|
3126
|
+
debugLog("Processing argv input:", input);
|
|
3127
|
+
ctx = await parseArgsFromArgv(command, input, parserOptions);
|
|
3128
|
+
} else {
|
|
3129
|
+
debugLog("Processing object input:", input);
|
|
3130
|
+
ctx = await createContextFromArgs(command, input);
|
|
3225
3131
|
}
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3132
|
+
debugLog("Created context:", ctx);
|
|
3133
|
+
if (useLifecycleHooks && command.onCmdInit) {
|
|
3134
|
+
debugLog("Calling onCmdInit hook");
|
|
3135
|
+
await command.onCmdInit(ctx);
|
|
3136
|
+
}
|
|
3137
|
+
if (command.run) {
|
|
3138
|
+
debugLog("Executing command run function");
|
|
3139
|
+
await command.run(ctx);
|
|
3140
|
+
} else {
|
|
3141
|
+
const error = "Command has no run function defined";
|
|
3142
|
+
debugLog(error);
|
|
3143
|
+
if (autoExit) {
|
|
3144
|
+
relinka("error", error);
|
|
3145
|
+
process$1.exit(1);
|
|
3236
3146
|
}
|
|
3237
|
-
|
|
3147
|
+
throw new Error(error);
|
|
3148
|
+
}
|
|
3149
|
+
if (useLifecycleHooks && command.onCmdExit) {
|
|
3150
|
+
debugLog("Calling onCmdExit hook");
|
|
3151
|
+
await command.onCmdExit(ctx);
|
|
3152
|
+
}
|
|
3153
|
+
debugLog("Command execution completed successfully");
|
|
3154
|
+
return ctx;
|
|
3155
|
+
} catch (error) {
|
|
3156
|
+
debugLog("Error during command execution:", error);
|
|
3157
|
+
if (autoExit) {
|
|
3158
|
+
relinka("error", `Error while executing command: ${String(error)}`);
|
|
3159
|
+
process$1.exit(1);
|
|
3238
3160
|
}
|
|
3239
|
-
|
|
3161
|
+
throw error;
|
|
3240
3162
|
}
|
|
3241
|
-
|
|
3242
|
-
|
|
3163
|
+
}
|
|
3164
|
+
async function parseArgsFromArgv(command, argv, parserOptions) {
|
|
3165
|
+
const booleanKeys = Object.keys(command.args || {}).filter(
|
|
3166
|
+
(k) => command.args?.[k]?.type === "boolean"
|
|
3167
|
+
);
|
|
3168
|
+
const defaultMap = {};
|
|
3169
|
+
for (const [argKey, def] of Object.entries(command.args || {})) {
|
|
3170
|
+
if (def.type === "boolean") {
|
|
3171
|
+
defaultMap[argKey] = def.default !== void 0 ? def.default : false;
|
|
3172
|
+
} else if (def.default !== void 0) {
|
|
3173
|
+
defaultMap[argKey] = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
|
|
3174
|
+
}
|
|
3243
3175
|
}
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3176
|
+
const mergedParserOptions = {
|
|
3177
|
+
...parserOptions,
|
|
3178
|
+
boolean: [...parserOptions.boolean || [], ...booleanKeys],
|
|
3179
|
+
defaults: { ...defaultMap, ...parserOptions.defaults || {} }
|
|
3180
|
+
};
|
|
3181
|
+
const parsed = reliArgParser(argv, mergedParserOptions);
|
|
3182
|
+
const finalArgs = {};
|
|
3183
|
+
const positionalKeys = Object.keys(command.args || {}).filter(
|
|
3184
|
+
(k) => command.args?.[k]?.type === "positional"
|
|
3185
|
+
);
|
|
3186
|
+
const leftoverPositionals = [...parsed._ || []];
|
|
3187
|
+
for (let i = 0; i < positionalKeys.length; i++) {
|
|
3188
|
+
const key = positionalKeys[i];
|
|
3189
|
+
if (!key || !command.args) continue;
|
|
3190
|
+
const def = command.args[key];
|
|
3191
|
+
const val = leftoverPositionals[i];
|
|
3192
|
+
finalArgs[key] = val != null && def ? castArgValue$1(def, val, key) : def?.default;
|
|
3254
3193
|
}
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3194
|
+
const otherKeys = Object.keys(command.args || {}).filter(
|
|
3195
|
+
(k) => command.args?.[k]?.type !== "positional"
|
|
3196
|
+
);
|
|
3197
|
+
for (const key of otherKeys) {
|
|
3198
|
+
const def = command.args?.[key];
|
|
3199
|
+
if (!def) continue;
|
|
3200
|
+
let rawVal = parsed[key];
|
|
3201
|
+
if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
|
|
3202
|
+
rawVal = [rawVal];
|
|
3203
|
+
}
|
|
3204
|
+
const casted = rawVal !== void 0 ? castArgValue$1(def, rawVal, key) : def.default;
|
|
3205
|
+
const argUsed = rawVal !== void 0 && (def.type === "boolean" ? casted === true : true);
|
|
3206
|
+
if (casted == null && def.required) {
|
|
3207
|
+
throw new Error(`Missing required argument: --${key}`);
|
|
3208
|
+
}
|
|
3209
|
+
if (argUsed && def.dependencies?.length) {
|
|
3210
|
+
const missingDeps = def.dependencies.filter((d) => {
|
|
3211
|
+
const depVal = parsed[d] ?? defaultMap[d];
|
|
3212
|
+
return !depVal;
|
|
3213
|
+
});
|
|
3214
|
+
if (missingDeps.length > 0) {
|
|
3215
|
+
const depsList = missingDeps.map((d) => `--${d}`).join(", ");
|
|
3216
|
+
throw new Error(
|
|
3217
|
+
`Argument --${key} can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} set`
|
|
3218
|
+
);
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
finalArgs[key] = def.type === "boolean" ? Boolean(casted) : casted;
|
|
3259
3222
|
}
|
|
3260
|
-
|
|
3261
|
-
|
|
3223
|
+
return {
|
|
3224
|
+
args: finalArgs,
|
|
3225
|
+
raw: argv
|
|
3226
|
+
};
|
|
3227
|
+
}
|
|
3228
|
+
async function createContextFromArgs(command, inputArgs) {
|
|
3229
|
+
const finalArgs = {};
|
|
3230
|
+
for (const [key, def] of Object.entries(command.args || {})) {
|
|
3231
|
+
const inputValue = inputArgs[key];
|
|
3232
|
+
let value;
|
|
3233
|
+
if (inputValue !== void 0) {
|
|
3234
|
+
value = castArgValue$1(def, inputValue, key);
|
|
3235
|
+
} else if (def.default !== void 0) {
|
|
3236
|
+
value = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
|
|
3237
|
+
} else if (def.type === "boolean") {
|
|
3238
|
+
value = false;
|
|
3239
|
+
} else {
|
|
3240
|
+
value = void 0;
|
|
3241
|
+
}
|
|
3242
|
+
if (value == null && def.required) {
|
|
3243
|
+
throw new Error(`Missing required argument: ${key}`);
|
|
3244
|
+
}
|
|
3245
|
+
if (value != null && def.dependencies?.length) {
|
|
3246
|
+
const missingDeps = def.dependencies.filter((d) => {
|
|
3247
|
+
const depVal = inputArgs[d];
|
|
3248
|
+
return !depVal;
|
|
3249
|
+
});
|
|
3250
|
+
if (missingDeps.length > 0) {
|
|
3251
|
+
const depsList = missingDeps.join(", ");
|
|
3252
|
+
throw new Error(
|
|
3253
|
+
`Argument '${key}' can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} provided`
|
|
3254
|
+
);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
finalArgs[key] = value;
|
|
3262
3258
|
}
|
|
3263
|
-
return
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
resolve(callerDir, normalizedCmdPath, "cmd.ts"),
|
|
3274
|
-
resolve(callerDir, normalizedCmdPath, "cmd.js"),
|
|
3275
|
-
// Command in app subdirectory
|
|
3276
|
-
resolve(callerDir, "app", normalizedCmdPath, "cmd.ts"),
|
|
3277
|
-
resolve(callerDir, "app", normalizedCmdPath, "cmd.js"),
|
|
3278
|
-
// Command in src subdirectory
|
|
3279
|
-
resolve(callerDir, "src", normalizedCmdPath, "cmd.ts"),
|
|
3280
|
-
resolve(callerDir, "src", normalizedCmdPath, "cmd.js"),
|
|
3281
|
-
// Command in src/app subdirectory
|
|
3282
|
-
resolve(callerDir, "src", "app", normalizedCmdPath, "cmd.ts"),
|
|
3283
|
-
resolve(callerDir, "src", "app", normalizedCmdPath, "cmd.js"),
|
|
3284
|
-
// Command in src-ts subdirectory
|
|
3285
|
-
resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.ts"),
|
|
3286
|
-
resolve(callerDir, "src-ts", normalizedCmdPath, "cmd.js"),
|
|
3287
|
-
// Command in src-ts/app subdirectory (for dler-like structures)
|
|
3288
|
-
resolve(callerDir, "src-ts", "app", normalizedCmdPath, "cmd.ts"),
|
|
3289
|
-
resolve(callerDir, "src-ts", "app", normalizedCmdPath, "cmd.js"),
|
|
3290
|
-
// Command in lib subdirectory
|
|
3291
|
-
resolve(callerDir, "lib", normalizedCmdPath, "cmd.ts"),
|
|
3292
|
-
resolve(callerDir, "lib", normalizedCmdPath, "cmd.js"),
|
|
3293
|
-
// Command in lib/app subdirectory
|
|
3294
|
-
resolve(callerDir, "lib", "app", normalizedCmdPath, "cmd.ts"),
|
|
3295
|
-
resolve(callerDir, "lib", "app", normalizedCmdPath, "cmd.js"),
|
|
3296
|
-
// Command in dist subdirectory (compiled)
|
|
3297
|
-
resolve(callerDir, "dist", normalizedCmdPath, "cmd.js"),
|
|
3298
|
-
resolve(callerDir, "dist", "app", normalizedCmdPath, "cmd.js"),
|
|
3299
|
-
// Command in bin subdirectory
|
|
3300
|
-
resolve(callerDir, "bin", normalizedCmdPath, "cmd.ts"),
|
|
3301
|
-
resolve(callerDir, "bin", normalizedCmdPath, "cmd.js"),
|
|
3302
|
-
// Command in bin/app subdirectory (common for CLI tools)
|
|
3303
|
-
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.ts"),
|
|
3304
|
-
resolve(callerDir, "bin", "app", normalizedCmdPath, "cmd.js"),
|
|
3305
|
-
// Command in commands subdirectory
|
|
3306
|
-
resolve(callerDir, "commands", normalizedCmdPath, "cmd.ts"),
|
|
3307
|
-
resolve(callerDir, "commands", normalizedCmdPath, "cmd.js"),
|
|
3308
|
-
// Command in cli subdirectory
|
|
3309
|
-
resolve(callerDir, "cli", normalizedCmdPath, "cmd.ts"),
|
|
3310
|
-
resolve(callerDir, "cli", normalizedCmdPath, "cmd.js"),
|
|
3311
|
-
// Command in cli/commands subdirectory
|
|
3312
|
-
resolve(callerDir, "cli", "commands", normalizedCmdPath, "cmd.ts"),
|
|
3313
|
-
resolve(callerDir, "cli", "commands", normalizedCmdPath, "cmd.js"),
|
|
3314
|
-
// Command in tools subdirectory
|
|
3315
|
-
resolve(callerDir, "tools", normalizedCmdPath, "cmd.ts"),
|
|
3316
|
-
resolve(callerDir, "tools", normalizedCmdPath, "cmd.js"),
|
|
3317
|
-
// Command in scripts subdirectory
|
|
3318
|
-
resolve(callerDir, "scripts", normalizedCmdPath, "cmd.ts"),
|
|
3319
|
-
resolve(callerDir, "scripts", normalizedCmdPath, "cmd.js")
|
|
3320
|
-
];
|
|
3321
|
-
for (const path of commonCommandLocations) {
|
|
3322
|
-
if (await fs.pathExists(path)) {
|
|
3323
|
-
paths.push(path);
|
|
3259
|
+
return {
|
|
3260
|
+
args: finalArgs,
|
|
3261
|
+
raw: []
|
|
3262
|
+
// No raw argv for object input
|
|
3263
|
+
};
|
|
3264
|
+
}
|
|
3265
|
+
function castArgValue$1(def, rawVal, argName) {
|
|
3266
|
+
if (rawVal == null) {
|
|
3267
|
+
if (def.type === "array" && typeof def.default === "string") {
|
|
3268
|
+
return [def.default];
|
|
3324
3269
|
}
|
|
3270
|
+
return def.default ?? void 0;
|
|
3325
3271
|
}
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
relinka("verbose", `Normalized path: ${normalizedPath}`);
|
|
3356
|
-
relinka("verbose", `Resolved path: ${resolvedPath}`);
|
|
3357
|
-
}
|
|
3358
|
-
const candidatePaths = await generateCandidatePaths(resolvedPath);
|
|
3359
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3360
|
-
relinka("verbose", `Candidate paths: ${candidatePaths.join(", ")}`);
|
|
3361
|
-
}
|
|
3362
|
-
for (const path of candidatePaths) {
|
|
3363
|
-
const command = await tryLoadCommand(path);
|
|
3364
|
-
if (command) {
|
|
3365
|
-
if (process$1.env.NODE_ENV === "development") {
|
|
3366
|
-
relinka("verbose", `Successfully loaded command from: ${path}`);
|
|
3367
|
-
}
|
|
3368
|
-
return command;
|
|
3272
|
+
let castedValue;
|
|
3273
|
+
switch (def.type) {
|
|
3274
|
+
case "boolean":
|
|
3275
|
+
if (typeof rawVal === "string") {
|
|
3276
|
+
const lower = rawVal.toLowerCase();
|
|
3277
|
+
if (lower === "true") castedValue = true;
|
|
3278
|
+
else if (lower === "false") castedValue = false;
|
|
3279
|
+
else castedValue = Boolean(rawVal);
|
|
3280
|
+
} else {
|
|
3281
|
+
castedValue = Boolean(rawVal);
|
|
3282
|
+
}
|
|
3283
|
+
if (def.allowed && !def.allowed.includes(castedValue)) {
|
|
3284
|
+
throw new Error(
|
|
3285
|
+
`Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
3286
|
+
);
|
|
3287
|
+
}
|
|
3288
|
+
return castedValue;
|
|
3289
|
+
case "string":
|
|
3290
|
+
castedValue = typeof rawVal === "string" ? rawVal : String(rawVal);
|
|
3291
|
+
if (def.allowed && !def.allowed.includes(castedValue)) {
|
|
3292
|
+
throw new Error(
|
|
3293
|
+
`Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
3294
|
+
);
|
|
3295
|
+
}
|
|
3296
|
+
return castedValue;
|
|
3297
|
+
case "number": {
|
|
3298
|
+
const n = Number(rawVal);
|
|
3299
|
+
if (Number.isNaN(n)) {
|
|
3300
|
+
throw new Error(`Invalid number provided for ${argName}: ${rawVal}`);
|
|
3369
3301
|
}
|
|
3302
|
+
if (def.allowed && !def.allowed.includes(n)) {
|
|
3303
|
+
throw new Error(
|
|
3304
|
+
`Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
3305
|
+
);
|
|
3306
|
+
}
|
|
3307
|
+
return n;
|
|
3370
3308
|
}
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3309
|
+
case "positional":
|
|
3310
|
+
castedValue = String(rawVal);
|
|
3311
|
+
if (def.allowed && !def.allowed.includes(castedValue)) {
|
|
3312
|
+
throw new Error(
|
|
3313
|
+
`Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
3314
|
+
);
|
|
3377
3315
|
}
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3316
|
+
return castedValue;
|
|
3317
|
+
case "array": {
|
|
3318
|
+
const arrVal = Array.isArray(rawVal) ? rawVal : [String(rawVal)];
|
|
3319
|
+
const result = [];
|
|
3320
|
+
for (let v of arrVal.map(String)) {
|
|
3321
|
+
if (v.startsWith("[") && v.endsWith("]")) {
|
|
3322
|
+
v = v.slice(1, -1);
|
|
3323
|
+
}
|
|
3324
|
+
const parts = v.split(/\s*,\s*/).filter(Boolean);
|
|
3325
|
+
for (const p of parts) {
|
|
3326
|
+
if (def.allowed && !def.allowed.includes(p)) {
|
|
3327
|
+
throw new Error(
|
|
3328
|
+
`Invalid value in array ${argName}: ${p}. Allowed values are: ${def.allowed.join(", ")}`
|
|
3329
|
+
);
|
|
3383
3330
|
}
|
|
3384
|
-
return command;
|
|
3385
3331
|
}
|
|
3332
|
+
result.push(...parts);
|
|
3386
3333
|
}
|
|
3334
|
+
return result;
|
|
3387
3335
|
}
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
if (error instanceof Error && error.message.includes("No command file found")) {
|
|
3391
|
-
throw error;
|
|
3392
|
-
}
|
|
3393
|
-
relinka("error", `Failed to load command from ${cmdPath}:`, error);
|
|
3394
|
-
throw createLoadError(cmdPath, error);
|
|
3336
|
+
default:
|
|
3337
|
+
return rawVal;
|
|
3395
3338
|
}
|
|
3396
3339
|
}
|
|
3397
3340
|
|
|
@@ -6226,110 +6169,6 @@ function normalizeArgv(argv) {
|
|
|
6226
6169
|
}
|
|
6227
6170
|
return normalized;
|
|
6228
6171
|
}
|
|
6229
|
-
async function runCmdWithSubcommands(command, argv = [], parserOptions = {}) {
|
|
6230
|
-
const normalizedArgv = normalizeArgv(argv);
|
|
6231
|
-
let currentCommand = command;
|
|
6232
|
-
let currentArgv = normalizedArgv;
|
|
6233
|
-
while (currentCommand.commands && currentArgv.length > 0 && currentArgv[0] && !isFlag(currentArgv[0])) {
|
|
6234
|
-
const [maybeSub, ...restArgv] = currentArgv;
|
|
6235
|
-
let subSpec;
|
|
6236
|
-
for (const [key, spec] of Object.entries(currentCommand.commands)) {
|
|
6237
|
-
if (key === maybeSub) {
|
|
6238
|
-
subSpec = spec;
|
|
6239
|
-
break;
|
|
6240
|
-
}
|
|
6241
|
-
try {
|
|
6242
|
-
const cmd = await loadSubCommand(spec);
|
|
6243
|
-
if (cmd.meta?.aliases?.includes(maybeSub)) {
|
|
6244
|
-
subSpec = spec;
|
|
6245
|
-
break;
|
|
6246
|
-
}
|
|
6247
|
-
} catch (err) {
|
|
6248
|
-
debugLog(`Error checking alias for command ${key}:`, err);
|
|
6249
|
-
}
|
|
6250
|
-
}
|
|
6251
|
-
if (!subSpec) break;
|
|
6252
|
-
const loaded = await loadSubCommand(subSpec);
|
|
6253
|
-
currentCommand = loaded;
|
|
6254
|
-
currentArgv = restArgv;
|
|
6255
|
-
}
|
|
6256
|
-
return await runCommandWithArgs(currentCommand, currentArgv, {
|
|
6257
|
-
...parserOptions,
|
|
6258
|
-
autoExit: false
|
|
6259
|
-
// Don't exit process in programmatic usage
|
|
6260
|
-
});
|
|
6261
|
-
}
|
|
6262
|
-
async function runCmd(command, argv = [], parserOptions = {}) {
|
|
6263
|
-
const normalizedArgv = normalizeArgv(argv);
|
|
6264
|
-
const booleanKeys = Object.keys(command.args || {}).filter(
|
|
6265
|
-
(k) => command.args?.[k]?.type === "boolean"
|
|
6266
|
-
);
|
|
6267
|
-
const defaultMap = {};
|
|
6268
|
-
for (const [argKey, def] of Object.entries(command.args || {})) {
|
|
6269
|
-
if (def.type === "boolean") {
|
|
6270
|
-
defaultMap[argKey] = def.default !== void 0 ? def.default : false;
|
|
6271
|
-
} else if (def.default !== void 0) {
|
|
6272
|
-
defaultMap[argKey] = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
|
|
6273
|
-
}
|
|
6274
|
-
}
|
|
6275
|
-
const mergedParserOptions = {
|
|
6276
|
-
...parserOptions,
|
|
6277
|
-
boolean: [...parserOptions.boolean || [], ...booleanKeys],
|
|
6278
|
-
defaults: { ...defaultMap, ...parserOptions.defaults || {} }
|
|
6279
|
-
};
|
|
6280
|
-
const parsed = reliArgParser(normalizedArgv, mergedParserOptions);
|
|
6281
|
-
debugLog("Parsed arguments (runCmd):", parsed);
|
|
6282
|
-
const finalArgs = {};
|
|
6283
|
-
const positionalKeys = Object.keys(command.args || {}).filter(
|
|
6284
|
-
(k) => command.args?.[k]?.type === "positional"
|
|
6285
|
-
);
|
|
6286
|
-
const leftoverPositionals = [...parsed._ || []];
|
|
6287
|
-
for (let i = 0; i < positionalKeys.length; i++) {
|
|
6288
|
-
const key = positionalKeys[i];
|
|
6289
|
-
if (!key || !command.args) continue;
|
|
6290
|
-
const def = command.args[key];
|
|
6291
|
-
const val = leftoverPositionals[i];
|
|
6292
|
-
finalArgs[key] = val != null && def ? castArgValue(def, val, key) : def?.default;
|
|
6293
|
-
}
|
|
6294
|
-
const otherKeys = Object.keys(command.args || {}).filter(
|
|
6295
|
-
(k) => command.args?.[k]?.type !== "positional"
|
|
6296
|
-
);
|
|
6297
|
-
for (const key of otherKeys) {
|
|
6298
|
-
const def = command.args?.[key];
|
|
6299
|
-
if (!def) continue;
|
|
6300
|
-
let rawVal = parsed[key];
|
|
6301
|
-
if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
|
|
6302
|
-
rawVal = [rawVal];
|
|
6303
|
-
}
|
|
6304
|
-
const casted = rawVal !== void 0 ? castArgValue(def, rawVal, key) : def.default;
|
|
6305
|
-
const argUsed = rawVal !== void 0 && (def.type === "boolean" ? casted === true : true);
|
|
6306
|
-
if (casted == null && def.required) {
|
|
6307
|
-
throw new Error(`Missing required argument: --${key}`);
|
|
6308
|
-
}
|
|
6309
|
-
if (argUsed && def.dependencies?.length) {
|
|
6310
|
-
const missingDeps = def.dependencies.filter((d) => {
|
|
6311
|
-
const depVal = parsed[d] ?? defaultMap[d];
|
|
6312
|
-
return !depVal;
|
|
6313
|
-
});
|
|
6314
|
-
if (missingDeps.length) {
|
|
6315
|
-
const depsList = missingDeps.map((d) => `--${d}`).join(", ");
|
|
6316
|
-
throw new Error(
|
|
6317
|
-
`Argument --${key} can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} set`
|
|
6318
|
-
);
|
|
6319
|
-
}
|
|
6320
|
-
}
|
|
6321
|
-
finalArgs[key] = def.type === "boolean" ? Boolean(casted) : casted;
|
|
6322
|
-
}
|
|
6323
|
-
const ctx = {
|
|
6324
|
-
args: finalArgs,
|
|
6325
|
-
raw: argv
|
|
6326
|
-
};
|
|
6327
|
-
if (typeof command.run === "function") {
|
|
6328
|
-
await command.run(ctx);
|
|
6329
|
-
} else {
|
|
6330
|
-
throw new Error("Command has no run() handler.");
|
|
6331
|
-
}
|
|
6332
|
-
}
|
|
6333
6172
|
function getParsedContext(command, argv, parserOptions) {
|
|
6334
6173
|
const normalizedArgv = normalizeArgv(argv);
|
|
6335
6174
|
const booleanKeys = Object.keys(command.args || {}).filter(
|
|
@@ -6437,149 +6276,6 @@ function levenshteinDistance(a, b) {
|
|
|
6437
6276
|
return matrix[b.length][a.length];
|
|
6438
6277
|
}
|
|
6439
6278
|
|
|
6440
|
-
function argsToStringArray(args) {
|
|
6441
|
-
const result = [];
|
|
6442
|
-
for (const [key, value] of Object.entries(args)) {
|
|
6443
|
-
if (value === void 0 || value === null) continue;
|
|
6444
|
-
if (typeof value === "boolean") {
|
|
6445
|
-
result.push(`--${key}=${value}`);
|
|
6446
|
-
} else if (Array.isArray(value)) {
|
|
6447
|
-
result.push(`--${key}=${value.join(",")}`);
|
|
6448
|
-
} else {
|
|
6449
|
-
result.push(`--${key}=${String(value)}`);
|
|
6450
|
-
}
|
|
6451
|
-
}
|
|
6452
|
-
return result;
|
|
6453
|
-
}
|
|
6454
|
-
async function createCallCmd() {
|
|
6455
|
-
return async function callCmd(cmdName, args) {
|
|
6456
|
-
const originalCaller = await getOriginalCallerDirectory();
|
|
6457
|
-
try {
|
|
6458
|
-
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6459
|
-
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6460
|
-
await runCmd(command, stringArgs);
|
|
6461
|
-
} catch (error) {
|
|
6462
|
-
console.error(`Error running command '${String(cmdName)}':`, error);
|
|
6463
|
-
throw error;
|
|
6464
|
-
}
|
|
6465
|
-
};
|
|
6466
|
-
}
|
|
6467
|
-
async function createGetTypedCmd() {
|
|
6468
|
-
return async function getTypedCmd(cmdName) {
|
|
6469
|
-
const originalCaller = await getOriginalCallerDirectory();
|
|
6470
|
-
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6471
|
-
return {
|
|
6472
|
-
command,
|
|
6473
|
-
run: async (args) => {
|
|
6474
|
-
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6475
|
-
await runCmd(command, stringArgs);
|
|
6476
|
-
}
|
|
6477
|
-
};
|
|
6478
|
-
};
|
|
6479
|
-
}
|
|
6480
|
-
async function callCmdImpl(cmdName, args) {
|
|
6481
|
-
const originalCaller = await getOriginalCallerDirectory();
|
|
6482
|
-
try {
|
|
6483
|
-
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6484
|
-
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6485
|
-
await runCmd(command, stringArgs);
|
|
6486
|
-
} catch (error) {
|
|
6487
|
-
console.error(`Error running command '${String(cmdName)}':`, error);
|
|
6488
|
-
throw error;
|
|
6489
|
-
}
|
|
6490
|
-
}
|
|
6491
|
-
async function getOriginalCallerDirectory() {
|
|
6492
|
-
const stack = new Error().stack?.split("\n") ?? [];
|
|
6493
|
-
const cwd = process.cwd();
|
|
6494
|
-
for (const line of stack) {
|
|
6495
|
-
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
6496
|
-
if (match?.[1]) {
|
|
6497
|
-
const filePath = match[1];
|
|
6498
|
-
if (!filePath.includes("node_modules") && !filePath.includes("command-runner") && !filePath.includes("command-typed") && // Skip this current file
|
|
6499
|
-
!filePath.includes("launcher-mod") && !filePath.includes("launcher-types") && !filePath.endsWith("mod.mjs") && !filePath.endsWith("mod.js") && !filePath.endsWith("mod.ts")) {
|
|
6500
|
-
try {
|
|
6501
|
-
const fileDir = dirname(filePath);
|
|
6502
|
-
let currentDir = fileDir;
|
|
6503
|
-
while (currentDir !== dirname(currentDir)) {
|
|
6504
|
-
try {
|
|
6505
|
-
const packageJsonPath = resolve(currentDir, "package.json");
|
|
6506
|
-
if (await fs.pathExists(packageJsonPath)) {
|
|
6507
|
-
const cwdPackageJsonPath = resolve(cwd, "package.json");
|
|
6508
|
-
if (await fs.pathExists(cwdPackageJsonPath)) {
|
|
6509
|
-
try {
|
|
6510
|
-
const callerPackage = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
|
|
6511
|
-
const cwdPackage = JSON.parse(await fs.readFile(cwdPackageJsonPath, "utf-8"));
|
|
6512
|
-
if (callerPackage.name !== cwdPackage.name) {
|
|
6513
|
-
return currentDir;
|
|
6514
|
-
}
|
|
6515
|
-
} catch {
|
|
6516
|
-
if (resolve(currentDir) !== resolve(cwd)) {
|
|
6517
|
-
return currentDir;
|
|
6518
|
-
}
|
|
6519
|
-
}
|
|
6520
|
-
} else {
|
|
6521
|
-
return currentDir;
|
|
6522
|
-
}
|
|
6523
|
-
break;
|
|
6524
|
-
}
|
|
6525
|
-
} catch {
|
|
6526
|
-
}
|
|
6527
|
-
currentDir = dirname(currentDir);
|
|
6528
|
-
}
|
|
6529
|
-
} catch {
|
|
6530
|
-
continue;
|
|
6531
|
-
}
|
|
6532
|
-
}
|
|
6533
|
-
}
|
|
6534
|
-
}
|
|
6535
|
-
for (const line of stack) {
|
|
6536
|
-
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
6537
|
-
if (match?.[1]) {
|
|
6538
|
-
const filePath = match[1];
|
|
6539
|
-
if (filePath.includes("node_modules")) {
|
|
6540
|
-
try {
|
|
6541
|
-
const nodeModulesMatch = filePath.match(/(.+\/node_modules\/(?:@[^\/]+\/[^\/]+|[^\/]+))/);
|
|
6542
|
-
if (nodeModulesMatch?.[1]) {
|
|
6543
|
-
const packageDir = nodeModulesMatch[1];
|
|
6544
|
-
const packageJsonPath = resolve(packageDir, "package.json");
|
|
6545
|
-
if (await fs.pathExists(packageJsonPath)) {
|
|
6546
|
-
return packageDir;
|
|
6547
|
-
}
|
|
6548
|
-
}
|
|
6549
|
-
} catch {
|
|
6550
|
-
continue;
|
|
6551
|
-
}
|
|
6552
|
-
}
|
|
6553
|
-
}
|
|
6554
|
-
}
|
|
6555
|
-
return cwd;
|
|
6556
|
-
}
|
|
6557
|
-
async function loadCommandWithCaller(cmdPath, callerDir) {
|
|
6558
|
-
const originalEnvVar = process.env._REMPTS_CALLER_DIR;
|
|
6559
|
-
process.env._REMPTS_CALLER_DIR = callerDir;
|
|
6560
|
-
try {
|
|
6561
|
-
const command = await loadCommand(cmdPath);
|
|
6562
|
-
return command;
|
|
6563
|
-
} finally {
|
|
6564
|
-
if (originalEnvVar !== void 0) {
|
|
6565
|
-
process.env._REMPTS_CALLER_DIR = originalEnvVar;
|
|
6566
|
-
} else {
|
|
6567
|
-
delete process.env._REMPTS_CALLER_DIR;
|
|
6568
|
-
}
|
|
6569
|
-
}
|
|
6570
|
-
}
|
|
6571
|
-
async function getTypedCmdImpl(cmdName) {
|
|
6572
|
-
const originalCaller = await getOriginalCallerDirectory();
|
|
6573
|
-
const command = await loadCommandWithCaller(cmdName, originalCaller);
|
|
6574
|
-
return {
|
|
6575
|
-
command,
|
|
6576
|
-
run: async (args) => {
|
|
6577
|
-
const stringArgs = args ? argsToStringArray(args) : [];
|
|
6578
|
-
await runCmd(command, stringArgs);
|
|
6579
|
-
}
|
|
6580
|
-
};
|
|
6581
|
-
}
|
|
6582
|
-
|
|
6583
6279
|
const runMain = createCli;
|
|
6584
6280
|
|
|
6585
6281
|
const log = relinka;
|
|
@@ -8522,4 +8218,4 @@ function normalizeName(name) {
|
|
|
8522
8218
|
return lastSegment.replace(/[^a-zA-Z0-9-]/g, "");
|
|
8523
8219
|
}
|
|
8524
8220
|
|
|
8525
|
-
export { CANCEL, CliValidationError, FailedToExitError, StandardSchemaV1Error, TrpcCommand, addCompletions, animateText, animationMap, anykeyPrompt, applyVariant,
|
|
8221
|
+
export { CANCEL, CliValidationError, FailedToExitError, StandardSchemaV1Error, TrpcCommand, addCompletions, animateText, animationMap, anykeyPrompt, applyVariant, bar, block, breakLines, callCmd, cancel, colorMap, colorize, commandToJSON, completePrompt, confirm, confirmPrompt, countLines$1 as countLines, createAsciiArt, createCancel, createCli, createMultiStep, createRpcCli, createShadowCommand, createStep, datePrompt, defineArgs, defineCommand, deleteLastLine, deleteLastLines, endPrompt, errorHandler, fallbackSymbols, figures, flattenedProperties, fmt, getColumns, getDescription, getEnumChoices, getExactTerminalWidth, getSchemaTypes, getTerminalHeight, getTerminalWidth$1 as getTerminalWidth, group, incompatiblePropertyPairs, input, inputPrompt, intro, introPrompt, isCancel, isOrpcRouter, isTerminalInteractive, isTrpc11Procedure, isTrpc11Router, isValidName, isValidVariant, isWindows, lineByLineConsoleLogger, lineByLineLogger, log, looksLikeInstanceof, looksLikeStandardSchema, looksLikeStandardSchemaFailure, mainSymbols, msg, msgUndo, msgUndoAll, multiselect, multiselectPrompt, nextStepsPrompt, normalizeName, numMultiSelectPrompt, numSelectPrompt, numberPrompt, outro, outroPrompt, parseProcedureInputs, parseRouter, password, pm, prettifyStandardSchemaError, preventUnsupportedTTY, preventWindowsHomeDirRoot, preventWrongTerminalSize, printLineBar, promptify, relinkaAsyncByRemptsDeprecated, relinkaByRemptsDeprecated, reliversePrompts, removeCursor, renderEndLine, renderEndLineInput, restoreCursor, resultPrompt, runMain, select, selectPrompt, selectSimple, setRawMode, showUsage, spinner, startEditor, startPrompt, streamText, streamTextBox, streamTextWithSpinner, symbols, taskProgressPrompt, taskSpinPrompt, text, throwError, toBaseColor, toDotPath, toSolidColor, togglePrompt, typographyMap, useSpinner, variantMap };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reliverse/rempts",
|
|
3
3
|
"author": "reliverse",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.50",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "./dist-npm/bin/mod.mjs",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
],
|
|
37
37
|
"description": "@reliverse/rempts is a modern, type-safe toolkit for building delightful cli experiences. it's fast, flexible, and made for developer happiness. file-based commands keep things simple.",
|
|
38
38
|
"scripts": {
|
|
39
|
+
"dev": "bun example/cli.ts",
|
|
39
40
|
"pub": "bun unbuild && bun publish",
|
|
40
|
-
"dev": "node -e 'console.log(`👉 bun dev:[prompts,modern,classic]`)'",
|
|
41
41
|
"dev:prompts": "bun example/prompts/mod.ts",
|
|
42
42
|
"dev:modern": "bun example/launcher/modern.ts",
|
|
43
43
|
"dev:classic": "bun example/launcher/classic.ts",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"@clack/prompts": "^0.11.0",
|
|
52
52
|
"@figliolia/chalk-animation": "^1.0.4",
|
|
53
53
|
"@inquirer/prompts": "^7.8.3",
|
|
54
|
-
"@orpc/server": "^1.8.
|
|
54
|
+
"@orpc/server": "^1.8.4",
|
|
55
55
|
"@reliverse/pathkit": "^1.3.4",
|
|
56
56
|
"@reliverse/reliarg": "^1.0.3",
|
|
57
57
|
"@reliverse/relico": "^1.3.5",
|
|
58
58
|
"@reliverse/relifso": "^1.4.5",
|
|
59
|
-
"@reliverse/relinka": "^1.5.
|
|
59
|
+
"@reliverse/relinka": "^1.5.6",
|
|
60
60
|
"@reliverse/runtime": "^1.0.3",
|
|
61
61
|
"@trpc/server": "^11.5.0",
|
|
62
62
|
"ansi-escapes": "^7.0.0",
|
|
@@ -85,13 +85,13 @@
|
|
|
85
85
|
"unicorn-magic": "^0.3.0",
|
|
86
86
|
"valibot": "^1.1.0",
|
|
87
87
|
"wrap-ansi": "^9.0.0",
|
|
88
|
-
"zod": "^4.0
|
|
88
|
+
"zod": "^4.1.0",
|
|
89
89
|
"zod-to-json-schema": "^3.24.6"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"@biomejs/biome": "^2.2.
|
|
93
|
-
"@orpc/contract": "^1.8.
|
|
94
|
-
"@reliverse/dler": "1.7.
|
|
92
|
+
"@biomejs/biome": "^2.2.2",
|
|
93
|
+
"@orpc/contract": "^1.8.4",
|
|
94
|
+
"@reliverse/dler": "1.7.101",
|
|
95
95
|
"@reliverse/rse": "^1.7.12",
|
|
96
96
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
97
97
|
"@types/bun": "^1.2.20",
|