@clerc/core
Advanced tools
Comparing version 0.42.0 to 0.42.1
@@ -95,6 +95,6 @@ import { Equals, Dict, CamelCase, MaybeArray as MaybeArray$1 } from '@clerc/utils'; | ||
type Locales = Dict<Dict<string>>; | ||
type TranslateFunction = (name: string, ...arguments_: string[]) => string | undefined; | ||
type TranslateFn = (name: string, ...args: string[]) => string | undefined; | ||
interface I18N { | ||
add: (locales: Locales) => void; | ||
t: TranslateFunction; | ||
t: TranslateFn; | ||
} | ||
@@ -152,4 +152,4 @@ | ||
} | ||
type Handler<C extends Commands = Commands, K extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> = (context: HandlerContext<C, K, GF>) => void; | ||
type HandlerInCommand<C extends HandlerContext> = (context: { | ||
type Handler<C extends Commands = Commands, K extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> = (ctx: HandlerContext<C, K, GF>) => void; | ||
type HandlerInCommand<C extends HandlerContext> = (ctx: { | ||
[K in keyof C]: C[K]; | ||
@@ -161,7 +161,7 @@ }) => void; | ||
}; | ||
type Inspector<C extends Commands = Commands> = InspectorFunction<C> | InspectorObject<C>; | ||
type InspectorFunction<C extends Commands = Commands> = (context: InspectorContext<C>, next: () => void) => void; | ||
type Inspector<C extends Commands = Commands> = InspectorFn<C> | InspectorObject<C>; | ||
type InspectorFn<C extends Commands = Commands> = (ctx: InspectorContext<C>, next: () => void) => void; | ||
interface InspectorObject<C extends Commands = Commands> { | ||
enforce?: "pre" | "post"; | ||
fn: InspectorFunction<C>; | ||
fn: InspectorFn<C>; | ||
} | ||
@@ -295,3 +295,3 @@ | ||
*/ | ||
errorHandler(handler: (error: any) => void): this; | ||
errorHandler(handler: (err: any) => void): this; | ||
/** | ||
@@ -429,10 +429,10 @@ * Register a command | ||
commandName: string; | ||
constructor(commandName: string, t: TranslateFunction); | ||
constructor(commandName: string, t: TranslateFn); | ||
} | ||
declare class NoSuchCommandError extends Error { | ||
commandName: string; | ||
constructor(commandName: string, t: TranslateFunction); | ||
constructor(commandName: string, t: TranslateFn); | ||
} | ||
declare class NoCommandGivenError extends Error { | ||
constructor(t: TranslateFunction); | ||
constructor(t: TranslateFn); | ||
} | ||
@@ -442,19 +442,19 @@ declare class CommandNameConflictError extends Error { | ||
n2: string; | ||
constructor(n1: string, n2: string, t: TranslateFunction); | ||
constructor(n1: string, n2: string, t: TranslateFn); | ||
} | ||
declare class ScriptNameNotSetError extends Error { | ||
constructor(t: TranslateFunction); | ||
constructor(t: TranslateFn); | ||
} | ||
declare class DescriptionNotSetError extends Error { | ||
constructor(t: TranslateFunction); | ||
constructor(t: TranslateFn); | ||
} | ||
declare class VersionNotSetError extends Error { | ||
constructor(t: TranslateFunction); | ||
constructor(t: TranslateFn); | ||
} | ||
declare class InvalidCommandNameError extends Error { | ||
commandName: string; | ||
constructor(commandName: string, t: TranslateFunction); | ||
constructor(commandName: string, t: TranslateFn); | ||
} | ||
declare class LocaleNotCalledFirstError extends Error { | ||
constructor(t: TranslateFunction); | ||
constructor(t: TranslateFn); | ||
} | ||
@@ -469,6 +469,6 @@ | ||
declare function resolveFlattenCommands(commands: Commands, t: TranslateFunction): Map<string[] | typeof Root, CommandAlias>; | ||
declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFunction): [Command<string | RootType> | undefined, string[] | RootType | undefined]; | ||
declare function resolveFlattenCommands(commands: Commands, t: TranslateFn): Map<string[] | typeof Root, CommandAlias>; | ||
declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined]; | ||
declare const resolveArgv: () => string[]; | ||
declare function compose(inspectors: Inspector[]): (context: InspectorContext) => void; | ||
declare function compose(inspectors: Inspector[]): (ctx: InspectorContext) => void; | ||
declare const isValidName: (name: CommandType) => boolean; | ||
@@ -480,2 +480,2 @@ declare const withBrackets: (s: string, isOptional?: boolean) => string; | ||
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext, InspectorFunction, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, ScriptNameNotSetError, TranslateFunction, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, isValidName, resolveArgv, resolveCommand, resolveFlattenCommands, stripFlags, withBrackets }; | ||
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, ScriptNameNotSetError, TranslateFn, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, isValidName, resolveArgv, resolveCommand, resolveFlattenCommands, stripFlags, withBrackets }; |
@@ -147,4 +147,4 @@ import { format } from 'node:util'; | ||
function mapParametersToArguments(mapping, parameters, cliArguments, t) { | ||
for (let index = 0; index < parameters.length; index += 1) { | ||
const { name, required, spread } = parameters[index]; | ||
for (let i = 0; i < parameters.length; i += 1) { | ||
const { name, required, spread } = parameters[i]; | ||
const camelCaseName = camelCase(name); | ||
@@ -154,5 +154,5 @@ if (camelCaseName in mapping) { | ||
} | ||
const value = spread ? cliArguments.slice(index) : cliArguments[index]; | ||
const value = spread ? cliArguments.slice(i) : cliArguments[i]; | ||
if (spread) { | ||
index = parameters.length; | ||
i = parameters.length; | ||
} | ||
@@ -201,7 +201,7 @@ if (required && (!value || spread && value.length === 0)) { | ||
const parsed = typeFlag((_a = command == null ? void 0 : command.flags) != null ? _a : /* @__PURE__ */ Object.create(null), [...argv]); | ||
const { _: arguments_ } = parsed; | ||
const { _: args } = parsed; | ||
if (name === Root) { | ||
continue; | ||
} | ||
if (arrayStartsWith(arguments_, name)) { | ||
if (arrayStartsWith(args, name)) { | ||
return [command, name]; | ||
@@ -234,3 +234,3 @@ } | ||
} | ||
const mergedInspectorFunctions = [ | ||
const mergedInspectorFns = [ | ||
...inspectorMap.pre, | ||
@@ -240,7 +240,7 @@ ...inspectorMap.normal, | ||
]; | ||
return (context) => { | ||
return (ctx) => { | ||
return dispatch(0); | ||
function dispatch(index) { | ||
const inspector = mergedInspectorFunctions[index]; | ||
return inspector(context, dispatch.bind(null, index + 1)); | ||
function dispatch(i) { | ||
const inspector = mergedInspectorFns[i]; | ||
return inspector(ctx, dispatch.bind(null, i + 1)); | ||
} | ||
@@ -255,3 +255,3 @@ }; | ||
const detectLocale = () => process.env.CLERC_LOCALE ? process.env.CLERC_LOCALE : Intl.DateTimeFormat().resolvedOptions().locale; | ||
const stripFlags = (argv) => argv.filter((argument) => !argument.startsWith("-")); | ||
const stripFlags = (argv) => argv.filter((arg) => !arg.startsWith("-")); | ||
@@ -312,6 +312,6 @@ var __accessCheck = (obj, member, msg) => { | ||
}, | ||
t: (name, ...arguments_) => { | ||
t: (name, ...args) => { | ||
const localeObject = __privateGet(this, _locales)[__privateGet(this, _locale)] || __privateGet(this, _locales)[__privateGet(this, _defaultLocale)]; | ||
const defaultLocaleObject = __privateGet(this, _locales)[__privateGet(this, _defaultLocale)]; | ||
return localeObject[name] ? format(localeObject[name], ...arguments_) : defaultLocaleObject[name] ? format(defaultLocaleObject[name], ...arguments_) : void 0; | ||
return localeObject[name] ? format(localeObject[name], ...args) : defaultLocaleObject[name] ? format(defaultLocaleObject[name], ...args) : void 0; | ||
} | ||
@@ -708,4 +708,5 @@ }; | ||
const parsed = typeFlag(flagsMerged, [...argv]); | ||
const { _: arguments_, flags, unknownFlags } = parsed; | ||
let parameters = !isCommandResolved || command.name === Root ? arguments_ : arguments_.slice(command.name.split(" ").length); | ||
const parametersOffset = (command == null ? void 0 : command.name) === Root || called === Root ? 0 : (called == null ? void 0 : called.length) ? called.length : command == null ? void 0 : command.name.split(" ").length; | ||
const { _: args, flags, unknownFlags } = parsed; | ||
let parameters = !isCommandResolved || command.name === Root ? args : args.slice(parametersOffset); | ||
let commandParameters = (_a = command == null ? void 0 : command.parameters) != null ? _a : []; | ||
@@ -717,3 +718,3 @@ const hasEof = commandParameters.indexOf("--"); | ||
commandParameters = commandParameters.slice(0, hasEof); | ||
const eofArguments = arguments_["--"]; | ||
const eofArguments = args["--"]; | ||
parameters = parameters.slice(0, -eofArguments.length || void 0); | ||
@@ -756,12 +757,12 @@ mapParametersToArguments( | ||
_callWithErrorHandling = new WeakSet(); | ||
callWithErrorHandling_fn = function(function_) { | ||
callWithErrorHandling_fn = function(fn) { | ||
try { | ||
function_(); | ||
} catch (error) { | ||
fn(); | ||
} catch (e) { | ||
if (__privateGet(this, _errorHandlers).length > 0) { | ||
for (const callback of __privateGet(this, _errorHandlers)) { | ||
callback(error); | ||
for (const cb of __privateGet(this, _errorHandlers)) { | ||
cb(e); | ||
} | ||
} else { | ||
throw error; | ||
throw e; | ||
} | ||
@@ -782,3 +783,3 @@ } | ||
enforce: "post", | ||
fn: (context) => { | ||
fn: (ctx) => { | ||
const [command] = getCommand(); | ||
@@ -790,3 +791,3 @@ const stringName = stripFlags(argv).join(" "); | ||
} | ||
__privateGet(this, _commandEmitter).emit(command.name, context); | ||
__privateGet(this, _commandEmitter).emit(command.name, ctx); | ||
} | ||
@@ -793,0 +794,0 @@ }; |
{ | ||
"name": "@clerc/core", | ||
"version": "0.42.0", | ||
"version": "0.42.1", | ||
"author": "Ray <i@mk1.io> (https://github.com/so1ve)", | ||
@@ -55,3 +55,3 @@ "type": "module", | ||
"type-flag": "^3.0.0", | ||
"@clerc/utils": "0.42.0" | ||
"@clerc/utils": "0.42.1" | ||
}, | ||
@@ -58,0 +58,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1259
44515
+ Added@clerc/utils@0.42.1(transitive)
- Removed@clerc/utils@0.42.0(transitive)
Updated@clerc/utils@0.42.1