sb-mig
Version:
CLI to rule the world. (and handle stuff related to Storyblok CMS)
70 lines (69 loc) • 2.75 kB
TypeScript
/**
* CLI-specific utility functions for building and parsing CLI commands
*/
import type { RequestBaseConfig } from "../../api/utils/request.js";
/**
* Property accessor - curried function to get a property from an object
* @example prop('name')({ name: 'hero' }) // => 'hero'
*/
export declare const prop: (k: any) => (o: any) => any;
/**
* Pipe functions left to right (function composition)
* @example pipe(addOne, double)(5) // => 12
*/
export declare const pipe: (...fns: any[]) => (x: any) => any;
/**
* Extract elements after the first two from CLI input array
* Used for parsing component names from commands like: sync components hero card
* @example unpackElements(['sync', 'components', 'hero', 'card']) // => ['hero', 'card']
*/
export declare const unpackElements: (input: string[]) => string[];
/**
* Extract the third element from CLI input array
* Used for parsing single component name from commands
* @example unpackOne(['sync', 'components', 'hero']) // => 'hero'
*/
export declare const unpackOne: (input: string[]) => string | undefined;
/**
* Factory for creating flag matchers
* Used to determine which CLI action to take based on provided flags
*
* @param flags - The flags object from CLI parser
* @param rules - Object mapping action names to required flag combinations
* @param whitelist - Flags to ignore when matching (e.g., 'from', 'to')
* @returns A function that checks if a given action type matches the flags
*
* @example
* const rules = { all: ['all'], allWithPresets: ['all', 'presets'] };
* const isIt = isItFactory({ all: true, presets: true }, rules, []);
* isIt('allWithPresets') // => true
*/
export declare const isItFactory: <T>(flags: any, rules: any, whitelist: string[]) => (type: T) => boolean;
/**
* Extract 'from' space ID from flags, falling back to config spaceId
*/
export declare const getFrom: (flags: any, config: RequestBaseConfig) => string;
/**
* Extract 'to' space ID from flags, falling back to config spaceId
*/
export declare const getTo: (flags: any, config: RequestBaseConfig) => string;
/**
* Extract 'sourceSpace' from flags, falling back to config spaceId
*/
export declare const getSourceSpace: (flags: any, config: RequestBaseConfig) => string;
/**
* Extract 'targetSpace' from flags, falling back to config spaceId
*/
export declare const getTargetSpace: (flags: any, config: RequestBaseConfig) => string;
/**
* Extract 'what' flag, defaulting to 'all'
*/
export declare const getWhat: (flags: any) => string;
/**
* Extract 'where' flag, defaulting to 'all'
*/
export declare const getWhere: (flags: any) => string;
/**
* Extract 'recursive' flag, defaulting to false
*/
export declare const getRecursive: (flags: any) => boolean;