bob-core 3.0.0-alpha.8 → 3.0.0-beta.1
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/cjs/package-supL7Tgp.cjs +1 -0
- package/dist/cjs/src/flags/option.d.ts +0 -2
- package/dist/cjs/src/index.js +5 -5
- package/dist/cjs/src/lib/types.d.ts +0 -5
- package/dist/cjs/src/shared/parsers.d.ts +1 -1
- package/dist/esm/{package-r-7jybWO.js → package-BNru0kNU.js} +1 -1
- package/dist/esm/src/flags/option.d.ts +0 -2
- package/dist/esm/src/index.js +140 -157
- package/dist/esm/src/lib/types.d.ts +0 -5
- package/dist/esm/src/shared/parsers.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/package-raEIIM6S.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={name:`bob-core`,version:`3.0.0-beta.1`,description:`BOB Core`,type:`module`,main:`./dist/cjs/src/index.js`,module:`./dist/esm/src/index.js`,types:`./dist/esm/src/index.d.ts`,files:[`dist`],exports:{".":{import:{types:`./dist/esm/src/index.d.ts`,default:`./dist/esm/src/index.js`},require:{types:`./dist/cjs/src/index.d.ts`,default:`./dist/cjs/src/index.js`}}},scripts:{start:`node -r @swc-node/register debug/main.ts`,build:`rm -rf ./dist && vite build`,typecheck:`tsc --noEmit`,prepack:`npm run build`,test:`vitest run`,lint:`eslint .`,"lint:fix":`eslint . --fix`},author:`Léo Hubert`,license:`ISC`,devDependencies:{"@eslint/js":`^9.39.4`,"@faker-js/faker":`^10.3.0`,"@swc-node/register":`^1.11.1`,"@trivago/prettier-plugin-sort-imports":`^5.2.2`,"@types/minimist":`^1.2.5`,"@types/node":`^20.14.5`,"@types/string-similarity":`^4.0.2`,"@vitest/coverage-v8":`^4.1.0`,eslint:`^9.39.4`,"eslint-config-prettier":`^10.1.8`,"eslint-plugin-prettier":`^5.5.5`,prettier:`^3.6.2`,tsx:`^4.21.0`,typescript:`^5.9.3`,"typescript-eslint":`^8.57.0`,vite:`^8.0.0`,"vite-plugin-dts":`^4.5.4`,vitest:`^4.1.0`},dependencies:{"@inquirer/prompts":`^8.3.0`,chalk:`^4.1.2`,"inquirer-file-selector":`^1.0.1`,minimist:`^1.2.8`}};exports.default=e;
|
|
@@ -2,7 +2,5 @@ import { FlagProps, ParameterOpts } from '../lib/types.js';
|
|
|
2
2
|
export declare function optionFlag<const T extends readonly string[], const U extends Partial<FlagProps>>(opts: {
|
|
3
3
|
options: T;
|
|
4
4
|
} & U): U & FlagProps<T[number]> & {
|
|
5
|
-
type: 'option';
|
|
6
|
-
options: T;
|
|
7
5
|
parse(input: any, opts: ParameterOpts): T[number];
|
|
8
6
|
};
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`chalk`);c=s(c);let l=require(`node:fs`);l=s(l);let u=require(`node:path`);u=s(u);let d=require(`minimist`);d=s(d);let f=require(`@inquirer/prompts`),p=require(`inquirer-file-selector`);var m=class{level;constructor(e={}){this.level=e.level??`info`}shouldLog(e){let t=[`debug`,`info`,`warn`,`error`],n=t.indexOf(this.level);return t.indexOf(e)>=n}setLevel(e){this.level=e}getLevel(){return this.level}log(...e){console.log(...e)}info(...e){this.shouldLog(`info`)&&console.log(...e)}warn(...e){this.shouldLog(`warn`)&&console.warn(...e)}error(...e){this.shouldLog(`error`)&&console.error(...e)}debug(...e){this.shouldLog(`debug`)&&console.log(...e)}},h=class{getBigrams(e){let t=[],n=e.toLowerCase();for(let e=0;e<n.length-1;e++)t.push(n.slice(e,e+2));return t}calculateSimilarity(e,t){if(e===t)return 1;if(e.length<2||t.length<2)return 0;let n=this.getBigrams(e),r=this.getBigrams(t),i=new Set(r),a=0;for(let e of n)i.has(e)&&(a++,i.delete(e));return 2*a/(n.length+r.length)}findBestMatch(e,t){let n=t.map(t=>({target:t,rating:this.calculateSimilarity(e,t)})),r=0,i=n[0]?.rating??0;for(let e=1;e<n.length;e++)n[e].rating>i&&(i=n[e].rating,r=e);return{ratings:n,bestMatch:n[r],bestMatchIndex:r}}},g=class extends Error{$type=`BobError`},_=class extends g{constructor(e){super(`Command "${e}" not found.`),this.command=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Command ${c.default.bold.yellow(this.command)} not found.`),e.log(``)}},v=class extends g{constructor(e,t={}){super(`Flag ${e} is not recognized`),this.flag=e,this.flagsSchema=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is not recognized.`);let t=Object.entries(this.flagsSchema);if(t.length>0){e.log(``),e.log(` ${c.default.dim(`Available flags:`)}`),e.log(``);let n=t.map(([e,t])=>{let n=t.alias?typeof t.alias==`string`?[t.alias]:t.alias:[],r=t.type===`option`&&`options`in t&&t.options?t.options.join(` | `):t.type;return{nameWithAlias:`--${e}${n.length>0?n.map(e=>`, -${e}`).join(``):``}`,description:t.description||``,typeDisplay:r}}),r=Math.max(...n.map(e=>e.nameWithAlias.length));for(let t of n){let n=` `.repeat(r-t.nameWithAlias.length+2);e.log(` ${c.default.green(t.nameWithAlias)}${n}${t.description} ${c.default.dim(`(${t.typeDisplay})`)}`)}}e.log(``)}},y=class extends g{constructor(e){super(`Argument "${e}" is required.`),this.argument=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.argument)} is required.`),e.log(``)}},b=class extends g{constructor(e){super(`Flag "${e}" is required.`),this.flag=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is required.`),e.log(``)}},x=class extends g{constructor(e,t){let n=`Argument "${e.arg}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.detail=e,this.argDefinition=t}pretty(e){let t=[];if(this.detail.reason!=null&&t.push([`Reason`,this.detail.reason]),this.detail.value!=null&&t.push([`Value`,this.detail.value]),this.argDefinition?.help!=null&&t.push([`Help`,c.default.green(this.argDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.detail.arg)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},S=class extends g{constructor(e,t){let n=`Flag "${e.flag}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.param=e,this.flagDefinition=t}pretty(e){let t=[];if(this.param.reason!=null&&t.push([`Reason`,this.param.reason]),this.param.value!=null&&t.push([`Value`,this.param.value]),this.flagDefinition?.help!=null&&t.push([`Help`,c.default.green(this.flagDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.param.flag)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},C=class extends g{constructor(e,t){super(`Too many arguments provided. Expected ${e}, got ${t}.`),this.expected=e,this.received=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Too many arguments. Expected ${c.default.bold.yellow(String(this.expected))}, got ${c.default.bold.yellow(String(this.received))}.`),e.log(``)}},w=class extends Error{constructor(e){super(e)}},T=class{flags;parsedFlags=null;args;parsedArgs=null;ux;shouldPromptForMissingFlags=!0;shouldValidateUnknownFlags=!0;shouldRejectExtraArguments=!1;constructor(e){this.opts=e,this.ux=e.ux,this.flags=e.flags,this.args=e.args}async init(e){let{_:t,...n}=(0,d.default)(e);return this.shouldValidateUnknownFlags&&this.validateUnknownFlags(n),this.parsedFlags=await this.handleOptions(n),this.parsedArgs=await this.handleArguments(t),{flags:this.parsedFlags,args:this.parsedArgs}}async validate(){await this.validateSchema(this.flags,this.parsedFlags,`flag`),await this.validateSchema(this.args,this.parsedArgs,`arg`)}flag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedFlags[e])&&t!==void 0?t:this.parsedFlags[e]}async setFlag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);if(!(e in this.flags))throw new v(e,this.flags);this.parsedFlags[e]=t}argument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedArgs[e])&&t!==void 0?t:this.parsedArgs[e]}async setArgument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);if(!(e in this.args))throw new x({arg:e,reason:`Argument "${e}" is not recognized`});this.parsedArgs[e]=t}isEmptyValue(e){return e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0}validateUnknownFlags(e){let t=new Set;for(let e in this.flags){t.add(e);let n=this.flags[e],r=Array.isArray(n.alias)?n.alias:n.alias?[n.alias]:[];for(let e of r)t.add(e)}for(let n in e)if(!t.has(n))throw new v(n,this.flags)}async handleOptions(e){let t={};for(let n in this.flags)t[n]=await this.resolveFlagValue(n,this.flags[n],e);return t}async handleArguments(e){let t={},n=[...e],r=Object.keys(this.args).length;for(let e in this.args){let r=this.args[e];if(`multiple`in r&&r.multiple){t[e]=await this.parseValue(n,r,`arg`,{name:e}),n.length=0;continue}t[e]=await this.parseValue(n.shift(),r,`arg`,{name:e})}if(this.shouldRejectExtraArguments&&n.length>0)throw new C(r,r+n.length);return t}async resolveFlagValue(e,t,n){let r,i=[e];t.alias&&i.push(...Array.isArray(t.alias)?t.alias:[t.alias]);for(let e of i)if(e in n){r=n[e];break}return this.parseValue(r,t,`flag`,{name:e})}async parseValue(e,t,n,r){if(this.isEmptyValue(e))return typeof t.default==`function`?await t.default():t.default;if(`multiple`in t&&t.multiple){Array.isArray(e)||(e=[e]);let i=[];for(let a of e)i.push(await this.safeParse(a,t,n,r));return i}return this.safeParse(e,t,n,r)}buildOpts(e,t){return{name:e,ux:this.ux,ctx:this.opts.ctx,definition:t,cmd:this.opts.cmd??Z}}async safeParse(e,t,n,r){try{return t.parse(e,this.buildOpts(r?.name??``,t))}catch(t){if(t instanceof S||t instanceof x||!r)throw t;let i=t instanceof Error?t.message:String(t);throw n===`flag`?new S({flag:r.name,value:e,reason:i}):new x({arg:r.name,value:e,reason:i})}}async validateSchema(e,t,n){for(let r in e){let i=e[r],a=t?.[r],o=this.isEmptyValue(a);if(i.required&&o){if(!this.shouldPromptForMissingFlags)throw n===`flag`?new b(r):new y(r);let e=await this.promptFor(r,i);if(e!=null&&t)a=await this.parseValue(e,i,n,{name:r}),t[r]=a;else throw n===`flag`?new b(r):new y(r)}}}disablePrompting(){return this.shouldPromptForMissingFlags=!1,this}allowUnknownFlags(){return this.shouldValidateUnknownFlags=!1,this}strictMode(){return this.shouldRejectExtraArguments=!0,this}async promptFor(e,t){return t.ask?t.ask(this.buildOpts(e,t)):null}};function E(e){return t=>({type:`custom`,default:e?.multiple||t?.multiple?[]:null,parse:e=>e,...e,...t})}function D(e,t){let n=`multiple`in t&&t.multiple,r=`${c.default.yellow.bold(e)} is required`;return t.description&&(r+=`: ${c.default.gray(`(${t.description})`)}`),r+=` ${c.default.green(`(${t.type}${n?`[]`:``})`)}\n`,r}function ee(e){if(typeof e==`boolean`)throw Error(`Expected a string, got boolean "${e}"`);return String(e)}function te(e,t){let n=typeof e==`number`?e:Number(e);if(isNaN(n))throw new w(`must be a valid number`);if(t?.min!==void 0&&n<t.min)throw new w(`is below minimum ${t.min}`);if(t?.max!==void 0&&n>t.max)throw new w(`exceeds maximum ${t.max}`);return n}function ne(e){if(typeof e==`boolean`)return e;let t=String(e).toLowerCase();if(t===`true`||t===`1`)return!0;if(t===`false`||t===`0`)return!1;throw new w(`Invalid boolean value: "${e}". Expected true, false, 1, or 0.`)}function re(e,t){let n=String(e);if(!t.includes(n))throw new w(`must be one of: ${t.map(e=>`"${e}"`).join(`, `)}`);return n}function ie(e,t){let n=String(e);if(t?.exists&&!l.default.existsSync(n))throw new w(`file does not exist`);return n}function ae(e,t){let n=String(e);if(t?.exists&&!(l.default.existsSync(n)&&l.default.lstatSync(n).isDirectory()))throw new w(`directory does not exist`);return n}function oe(e){try{return new URL(String(e))}catch{throw new w(`Invalid URL: "${e}"`)}}var se=E({default:!1,parse:e=>ne(e),ask:async e=>{let t=D(e.name,e.definition);return await e.ux.askForToggle(t)},type:`boolean`});async function ce(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=D(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
2
|
-
`,{separator:`,`,validate:
|
|
3
|
-
`,{separator:`,`,validate:
|
|
4
|
-
`))};return s(),{increment:(t=1)=>{o||(a=Math.min(a+t,e),s())},update:t=>{o||(a=Math.max(0,Math.min(t,e)),s())},stop:c,[Symbol.dispose]:c,[Symbol.asyncDispose]:c}}function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`chalk`);c=s(c);let l=require(`node:fs`);l=s(l);let u=require(`node:path`);u=s(u);let d=require(`minimist`);d=s(d);let f=require(`@inquirer/prompts`),p=require(`inquirer-file-selector`);var m=class{level;constructor(e={}){this.level=e.level??`info`}shouldLog(e){let t=[`debug`,`info`,`warn`,`error`],n=t.indexOf(this.level);return t.indexOf(e)>=n}setLevel(e){this.level=e}getLevel(){return this.level}log(...e){console.log(...e)}info(...e){this.shouldLog(`info`)&&console.log(...e)}warn(...e){this.shouldLog(`warn`)&&console.warn(...e)}error(...e){this.shouldLog(`error`)&&console.error(...e)}debug(...e){this.shouldLog(`debug`)&&console.log(...e)}},ee=class{getBigrams(e){let t=[],n=e.toLowerCase();for(let e=0;e<n.length-1;e++)t.push(n.slice(e,e+2));return t}calculateSimilarity(e,t){if(e===t)return 1;if(e.length<2||t.length<2)return 0;let n=this.getBigrams(e),r=this.getBigrams(t),i=new Set(r),a=0;for(let e of n)i.has(e)&&(a++,i.delete(e));return 2*a/(n.length+r.length)}findBestMatch(e,t){let n=t.map(t=>({target:t,rating:this.calculateSimilarity(e,t)})),r=0,i=n[0]?.rating??0;for(let e=1;e<n.length;e++)n[e].rating>i&&(i=n[e].rating,r=e);return{ratings:n,bestMatch:n[r],bestMatchIndex:r}}},h=class extends Error{$type=`BobError`},g=class extends h{constructor(e){super(`Command "${e}" not found.`),this.command=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Command ${c.default.bold.yellow(this.command)} not found.`),e.log(``)}},_=class extends h{constructor(e,t={}){super(`Flag ${e} is not recognized`),this.flag=e,this.flagsSchema=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is not recognized.`);let t=Object.entries(this.flagsSchema);if(t.length>0){e.log(``),e.log(` ${c.default.dim(`Available flags:`)}`),e.log(``);let n=t.map(([e,t])=>{let n=t.alias?typeof t.alias==`string`?[t.alias]:t.alias:[],r=t.type===`option`&&`options`in t&&t.options?t.options.join(` | `):t.type;return{nameWithAlias:`--${e}${n.length>0?n.map(e=>`, -${e}`).join(``):``}`,description:t.description||``,typeDisplay:r}}),r=Math.max(...n.map(e=>e.nameWithAlias.length));for(let t of n){let n=` `.repeat(r-t.nameWithAlias.length+2);e.log(` ${c.default.green(t.nameWithAlias)}${n}${t.description} ${c.default.dim(`(${t.typeDisplay})`)}`)}}e.log(``)}},v=class extends h{constructor(e){super(`Argument "${e}" is required.`),this.argument=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.argument)} is required.`),e.log(``)}},y=class extends h{constructor(e){super(`Flag "${e}" is required.`),this.flag=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is required.`),e.log(``)}},b=class extends h{constructor(e,t){let n=`Argument "${e.arg}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.detail=e,this.argDefinition=t}pretty(e){let t=[];if(this.detail.reason!=null&&t.push([`Reason`,this.detail.reason]),this.detail.value!=null&&t.push([`Value`,c.default.yellow(this.detail.value)]),this.argDefinition?.help!=null&&t.push([`Help`,c.default.green(this.argDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.detail.arg)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},x=class extends h{constructor(e,t){let n=`Flag "${e.flag}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.param=e,this.flagDefinition=t}pretty(e){let t=[];if(this.param.reason!=null&&t.push([`Reason`,this.param.reason]),this.param.value!=null&&t.push([`Value`,c.default.yellow(this.param.value)]),this.flagDefinition?.help!=null&&t.push([`Help`,c.default.green(this.flagDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.param.flag)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},te=class extends h{constructor(e,t){super(`Too many arguments provided. Expected ${e}, got ${t}.`),this.expected=e,this.received=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Too many arguments. Expected ${c.default.bold.yellow(String(this.expected))}, got ${c.default.bold.yellow(String(this.received))}.`),e.log(``)}},S=class extends Error{constructor(e){super(e)}},C=class{flags;parsedFlags=null;args;parsedArgs=null;ux;shouldPromptForMissingFlags=!0;shouldValidateUnknownFlags=!0;shouldRejectExtraArguments=!1;constructor(e){this.opts=e,this.ux=e.ux,this.flags=e.flags,this.args=e.args}async init(e){let{_:t,...n}=(0,d.default)(e);return this.shouldValidateUnknownFlags&&this.validateUnknownFlags(n),this.parsedFlags=await this.handleOptions(n),this.parsedArgs=await this.handleArguments(t),{flags:this.parsedFlags,args:this.parsedArgs}}async validate(){await this.validateSchema(this.flags,this.parsedFlags,`flag`),await this.validateSchema(this.args,this.parsedArgs,`arg`)}flag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedFlags[e])&&t!==void 0?t:this.parsedFlags[e]}async setFlag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);if(!(e in this.flags))throw new _(e,this.flags);this.parsedFlags[e]=t}argument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedArgs[e])&&t!==void 0?t:this.parsedArgs[e]}async setArgument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);if(!(e in this.args))throw new b({arg:e,reason:`Argument "${e}" is not recognized`});this.parsedArgs[e]=t}isEmptyValue(e){return e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0}validateUnknownFlags(e){let t=new Set;for(let e in this.flags){t.add(e);let n=this.flags[e],r=Array.isArray(n.alias)?n.alias:n.alias?[n.alias]:[];for(let e of r)t.add(e)}for(let n in e)if(!t.has(n))throw new _(n,this.flags)}async handleOptions(e){let t={};for(let n in this.flags)t[n]=await this.resolveFlagValue(n,this.flags[n],e);return t}async handleArguments(e){let t={},n=[...e],r=Object.keys(this.args).length;for(let e in this.args){let r=this.args[e];if(`multiple`in r&&r.multiple){t[e]=await this.parseValue(n,r,`arg`,{name:e}),n.length=0;continue}t[e]=await this.parseValue(n.shift(),r,`arg`,{name:e})}if(this.shouldRejectExtraArguments&&n.length>0)throw new te(r,r+n.length);return t}async resolveFlagValue(e,t,n){let r,i=[e];t.alias&&i.push(...Array.isArray(t.alias)?t.alias:[t.alias]);for(let e of i)if(e in n){r=n[e];break}return this.parseValue(r,t,`flag`,{name:e})}async parseValue(e,t,n,r){if(this.isEmptyValue(e))return typeof t.default==`function`?await t.default():t.default;if(`multiple`in t&&t.multiple){Array.isArray(e)||(e=[e]);let i=[];for(let a of e)i.push(await this.safeParse(a,t,n,r));return i}return this.safeParse(e,t,n,r)}buildOpts(e,t){return{name:e,ux:this.ux,ctx:this.opts.ctx,definition:t,cmd:this.opts.cmd??Z}}async safeParse(e,t,n,r){try{return t.parse(e,this.buildOpts(r?.name??``,t))}catch(t){if(t instanceof x||t instanceof b||!r)throw t;let i=t instanceof Error?t.message:String(t);throw n===`flag`?new x({flag:r.name,value:e,reason:i}):new b({arg:r.name,value:e,reason:i})}}async validateSchema(e,t,n){for(let r in e){let i=e[r],a=t?.[r],o=this.isEmptyValue(a);if(i.required&&o){if(!this.shouldPromptForMissingFlags)throw n===`flag`?new y(r):new v(r);let e=await this.promptFor(r,i);if(e!=null&&t)a=await this.parseValue(e,i,n,{name:r}),t[r]=a;else throw n===`flag`?new y(r):new v(r)}}}disablePrompting(){return this.shouldPromptForMissingFlags=!1,this}allowUnknownFlags(){return this.shouldValidateUnknownFlags=!1,this}strictMode(){return this.shouldRejectExtraArguments=!0,this}async promptFor(e,t){return t.ask?t.ask(this.buildOpts(e,t)):null}};function w(e){return t=>({type:`custom`,default:e?.multiple||t?.multiple?[]:null,parse:e=>e,...e,...t})}function T(e,t){let n=`multiple`in t&&t.multiple,r=`${c.default.yellow.bold(e)} is required`;return t.description&&(r+=`: ${c.default.gray(`(${t.description})`)}`),r+=` ${c.default.green(`(${t.type}${n?`[]`:``})`)}\n`,r}function ne(e){if(typeof e==`boolean`)throw Error(`Expected a string, got boolean "${e}"`);return String(e)}function re(e,t){let n=typeof e==`number`?e:Number(e);if(isNaN(n))throw new S(`must be a valid number`);if(t?.min!==void 0&&n<t.min)throw new S(`is below minimum ${t.min}`);if(t?.max!==void 0&&n>t.max)throw new S(`exceeds maximum ${t.max}`);return n}function ie(e){if(typeof e==`boolean`)return e;let t=String(e).toLowerCase();if(t===`true`||t===`1`)return!0;if(t===`false`||t===`0`)return!1;throw new S(`Invalid boolean value: "${e}". Expected true, false, 1, or 0.`)}function ae(e,t){let n=String(e);if(!t.includes(n))throw new S(`must be one of: ${t.map(e=>`"${e}"`).join(`, `)}`);return n}function oe(e,t){let n=String(e);if(t?.exists&&!l.default.existsSync(n))throw new S(`file does not exist`);return n}function se(e,t){let n=String(e);if(t?.exists)try{if(!l.default.lstatSync(n).isDirectory())throw new S(`directory does not exist`)}catch(e){throw e instanceof S?e:new S(`directory does not exist`)}return n}function ce(e){try{return new URL(String(e))}catch{throw new S(`Invalid URL: "${e}"`)}}var le=w({default:!1,parse:e=>ie(e),ask:async e=>{let t=T(e.name,e.definition);return await e.ux.askForToggle(t)},type:`boolean`});function E(e,t){return n=>{if((n==null||typeof n==`string`&&n.trim()===``)&&e.required)return`This value is required`;try{e.parse(n,t)}catch(e){return e instanceof S?e.message:`Invalid value`}return!0}}function D(e,t){return n=>{if((n==null||n.trim()===``)&&e.required)return`Please enter at least one value`;for(let r of n.split(`,`)){let n=r.trim();if(n!==``)try{e.parse(n,t)}catch(e){return e instanceof S?`"${n}": ${e.message}`:`"${n}": Invalid value`}}return!0}}async function ue(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=T(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
2
|
+
`,{separator:`,`,validate:D(t,e)}):`secret`in t&&t.secret?e.ux.askForPassword(r,{validate:E(t,e)}):await e.ux.askForInput(r,{validate:E(t,e)})}async function de(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=T(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
3
|
+
`,{separator:`,`,validate:D(t,e)}):await e.ux.askForNumber(r,{validate:n=>{if(n===void 0&&t.required)return`This value is required`;if(n!==void 0)try{t.parse(String(n),e)}catch(e){return e instanceof S?e.message:`Invalid value`}return!0}})}async function fe(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=T(e.name,t);if(t.type!==`option`)return null;let i=t.options.map(e=>({name:e,value:e}));return n?await e.ux.askForCheckbox(r,i):await e.ux.askForSelect(r,i)}async function pe(e){let t=T(e.name,e.definition);return e.ux.askForFile(t,{basePath:process.cwd()})}async function me(e){let t=T(e.name,e.definition);return e.ux.askForDirectory(t,{basePath:process.cwd()})}async function he(e){let t=T(e.name,e.definition);return await e.ux.askForInput(t,{validate:E(e.definition,e)})}var O=w({parse:(e,t)=>se(e,{exists:t.definition.exists}),ask:me,type:`directory`}),k=w({parse:(e,t)=>oe(e,{exists:t.definition.exists}),ask:pe,type:`file`}),A=w({parse:(e,t)=>re(e,{min:t.definition.min,max:t.definition.max}),ask:de,type:`number`});function j(e){return w({parse:(e,t)=>ae(e,t.definition.options),ask:fe,...e,type:`option`})()}var M=w({parse:e=>ne(e),ask:ue,type:`string`}),N=w({parse:e=>ce(e),ask:he,type:`url`}),P={string:M,number:A,option:j,file:k,directory:O,url:N,custom:w},F={string:M,number:A,boolean:le,option:j,file:k,directory:O,url:N,custom:w};function I(e){return Array(e+5).join(` `)}function ge(e){let t=e.type;return t===`option`&&`options`in e&&e.options?`enum: ${e.options.join(`|`)}`:t??`custom`}var L=F.boolean({alias:[`h`],handler:(e,t)=>{if(!e)return{shouldStop:!1};let n=t.cmd,r=n.args,i={...n.baseFlags,...n.flags},a=Object.entries(r),o=Object.entries(i),s=o.map(([e,t])=>{let n=Array.isArray(t.alias)?t.alias:t.alias?[t.alias]:[];return{name:e,...t,flagWithAlias:`--${e}${n.map(e=>`, -${e}`).join(``)}`}}),l=a.filter(([,e])=>e.required);console.log(c.default.yellow(`Description:`)),console.log(` ${n.description}\n`),n.aliases.length>0&&(console.log(c.default.yellow(`Aliases:`)),console.log(` ${n.aliases.join(`, `)}\n`)),console.log(c.default.yellow(`Usage:`)),console.log(` ${n.command} ${l.length>0?l.map(([e])=>`<${e}>`).join(` `):`\b`} [options]`);let u=Math.max(...s.map(e=>e.flagWithAlias.length),0),d=Math.max(...a.map(([e])=>e.length),0),f=d>u?d:u;if(a.length>0){console.log(`\n${c.default.yellow(`Arguments`)}:`);for(let[e,t]of a){let n=I(f-e.length),r=` ${c.default.green(e)} ${n} ${t.description??`\b`}`;if(t.default!==void 0&&!t.required){let e=typeof t.default==`function`?`[function]`:t.multiple?JSON.stringify(t.default):t.default;r+=` ${c.default.yellow(`[default: ${e}]`)}`}`multiple`in t&&t.multiple&&(r+=` ${c.default.white(`(variadic)`)}`),console.log(r)}}if(o.length>0){console.log(`\n${c.default.yellow(`Options`)}:`);for(let e of s){let t=I(f-e.flagWithAlias.length),n=` ${c.default.green(e.flagWithAlias)} ${t} ${e.description??`\b`}`;if(e.type&&(n+=` ${c.default.white(`(${ge(e)})`)}`),e.default!==void 0&&!e.required){let t=typeof e.default==`function`?`(function)`:e.default;n+=` ${c.default.yellow(`[default: ${t}]`)}`}console.log(n)}}let p=n.examples??[];if(p.length>0){console.log(`\n${c.default.yellow(`Examples`)}:`);let e=process.argv[0].split(`/`).pop();e===`node`&&(e+=` `+process.argv[1].split(`/`).pop());for(let[t,n]of p.entries())t>0&&console.log(``),console.log(` ${n.description}\n`),console.log(` ${c.default.green(`${e} ${n.command}`)}`)}return{shouldStop:!0}}}),_e=class extends Error{name=`ExitPromptError`};async function R(e,t){try{return await e()}catch(e){if(e instanceof _e||e instanceof Error&&e.name===`ExitPromptError`)return t;throw e}}async function z(e,t,n){if(t.length===0)throw Error(`No options provided`);let r=t.map(e=>typeof e==`string`?{name:e,value:e}:{name:e.name,value:e.value,disabled:e.disabled,checked:e.checked,description:e.description});return R(()=>(0,f.checkbox)({message:e,choices:r,required:n?.required,pageSize:n?.pageSize,loop:n?.loop,validate:n?.validate,shortcuts:n?.shortcuts}),null)}async function B(e=`Do you want to continue?`,t){return R(()=>(0,f.confirm)({message:e,default:t?.default??!1,transformer:t?.transformer}),!1)}async function ve(e,t){return R(()=>(0,f.editor)({message:e,default:t?.default,postfix:t?.postfix,waitForUserInput:t?.waitForUserInput,validate:t?.validate}),null)}async function V(e,t,n){return R(()=>(0,f.expand)({message:e,choices:t,default:n?.default}),null)}async function H(e,t){return R(async()=>{let n=await(0,p.fileSelector)({message:e,basePath:t?.basePath,type:t?.type===`file+directory`?void 0:t?.type,filter:t?.filter,allowCancel:!0,pageSize:t?.pageSize,loop:t?.loop});return n===null?null:n.path},null)}async function U(e,t){return R(()=>(0,f.input)({message:e,default:t?.default,required:t?.required,validate:t?.validate,transformer:t?.transformer}),null)}async function W(e,t){let n=t?.separator??`,`;return R(async()=>(await(0,f.input)({message:e,default:t?.default,validate:t?.validate})).split(n).map(e=>e.trim()).filter(e=>e.length>0),null)}async function G(e,t){return R(async()=>await(0,f.number)({message:e,default:t?.default,required:t?.required,min:t?.min,max:t?.max,step:t?.step,validate:t?.validate})??null,null)}async function K(e,t){return R(()=>(0,f.password)({message:e,mask:t?.mask,validate:t?.validate}),null)}async function q(e,t,n){return R(()=>(0,f.rawlist)({message:e,choices:t,loop:n?.loop}),null)}async function J(e,t,n){return R(()=>(0,f.search)({message:e,source:t,pageSize:n?.pageSize,validate:n?.validate}),null)}async function ye(e,t,n){if(t.length===0)throw Error(`No options provided`);let r=t.map(e=>typeof e==`string`?{name:e,value:e}:e);return R(()=>(0,f.select)({message:e,choices:r,default:n?.default,pageSize:n?.pageSize,loop:n?.loop}),null)}async function be(e,t){let n=t?.active??`Yes`,r=t?.inactive??`No`;return R(()=>(0,f.confirm)({message:e,default:t?.default??!1,transformer:e=>e?n:r}),!1)}function xe(e,t){let n=t?.separator??`: `,r=t?.keyStyle??c.default.bold,i=Array.isArray(e)?e:Object.entries(e);if(i.length===0)return;let a=Math.max(...i.map(([e])=>e.length));for(let[e,t]of i)console.log(r(e.padEnd(a))+n+String(t??``))}function Se(e=``,t=[`⠙`,`⠘`,`⠰`,`⠴`,`⠤`,`⠦`,`⠆`,`⠃`,`⠋`,`⠉`],n=100){let r=e,i=null,a=0,o=setInterval(function(){i&&=(process.stdout.write(`\r`+` `.repeat(i.length+5)+`\r`),null),process.stdout.write(`\r`+t[a++]+` `+r),a%=t.length},n),s=()=>{clearInterval(o),process.stdout.write(`\r`+` `.repeat(r.length+5)+`\r`)};return{[Symbol.dispose]:s,[Symbol.asyncDispose]:s,updateText:e=>{i=r,r=e},stop:s}}function Ce(e,t){let n=t?.width??30,r=t?.completeChar??`█`,i=t?.incompleteChar??`░`,a=0,o=!1,s=()=>{if(o)return;let t=e<=0?1:Math.min(a/e,1),s=Math.round(t*n),c=`${r.repeat(s)+i.repeat(n-s)} ${Math.round(t*100)}% ${a}/${e}`;process.stdout.write(`\r`+c)},c=()=>{o||(o=!0,process.stdout.write(`
|
|
4
|
+
`))};return s(),{increment:(t=1)=>{o||(a=Math.min(a+t,e),s())},update:t=>{o||(a=Math.max(0,Math.min(t,e)),s())},stop:c,[Symbol.dispose]:c,[Symbol.asyncDispose]:c}}function Y(e,t){if(e.length===0)return;let n=t??Object.keys(e[0]).map(e=>({key:e})),r=n.map(e=>e.header??e.key.toUpperCase()),i=n.map((t,n)=>{let i=Math.max(r[n].length,...e.map(e=>(t.format?t.format(e[t.key]):String(e[t.key]??``)).length));return t.width?Math.min(i,t.width):i}),a=(e,t,n=`left`)=>{if(e.length>t)return e.slice(0,t-1)+`…`;switch(n){case`right`:return e.padStart(t);case`center`:{let n=Math.floor((t-e.length)/2);return` `.repeat(n)+e+` `.repeat(t-e.length-n)}default:return e.padEnd(t)}},o=n.map((e,t)=>a(r[t],i[t],e.alignment)).join(` `);console.log(c.default.bold(o));let s=i.map(e=>`-`.repeat(e)).join(` `);console.log(c.default.dim(s));for(let t of e){let e=n.map((e,n)=>a(e.format?e.format(t[e.key]):String(t[e.key]??``),i[n],e.alignment)).join(` `);console.log(e)}}var X=class{askForConfirmation(e,t){return B(e,t)}askForInput(e,t){return U(e,t)}askForPassword(e,t){return K(e,t)}askForNumber(e,t){return G(e,t)}askForSelect(e,t,n){return ye(e,t,n)}askForCheckbox(e,t,n){return z(e,t,n)}askForSearch(e,t,n){return J(e,t,n)}askForList(e,t){return W(e,t)}askForToggle(e,t){return be(e,t)}askForEditor(e,t){return ve(e,t)}askForRawList(e,t,n){return q(e,t,n)}askForExpand(e,t,n){return V(e,t,n)}askForFile(e,t){return H(e,{...t,type:`file`})}askForDirectory(e,t){return H(e,{...t,type:`directory`})}askForFileSelector(e,t){return H(e,t)}keyValue(e,t){return xe(e,t)}table(e,t){return Y(e,t)}newProgressBar(e,t){return Ce(e,t)}newLoader(e,t,n){return Se(e,t,n)}},Z=class{static $type=`BobCommand`;static command=``;static description=``;static group;static args={};static flags={};static examples=[];static hidden=!1;static aliases=[];static disableDefaultOptions=!1;static disablePrompting=!1;static allowUnknownFlags=!1;static strictMode=!1;ctx;logger;ux;parser;static baseFlags={help:L};newCommandParser(e){return new C({ux:e.ux,ctx:e.ctx,flags:e.flags,args:e.args,cmd:e.cmd})}newUX(){return new X}async run(e){let t=this.constructor;this.ctx=e.ctx,this.logger=e.logger,this.ux=this.newUX();let n;if(`flags`in e)n={flags:e.flags,args:e.args};else{this.parser=this.newCommandParser({ctx:this.ctx,ux:this.ux,flags:t.disableDefaultOptions?t.flags:{...t.baseFlags,...t.flags},args:t.args,cmd:t}),t.allowUnknownFlags&&this.parser.allowUnknownFlags(),t.strictMode&&this.parser.strictMode(),t.disablePrompting&&this.parser.disablePrompting();let r=await this.parser.init(e.args);for(let n in r.flags){let i=r.flags[n],a=t.flags[n]||t.baseFlags[n];if(a&&a.handler){let r={name:n,ux:this.ux,ctx:e.ctx,definition:a,cmd:t},o=a.handler(i,r);if(o&&o.shouldStop)return-1}}await this.parser.validate(),n={flags:r.flags,args:r.args}}if(this.preHandle){let e=await this.preHandle();if(e&&e!==0)return e}return await this.handle(this.ctx,n)??0}};function we(e){return typeof e==`object`&&!!e&&`$type`in e&&e.$type===`BobError`}function Q(e){return typeof e==`function`?e.prototype instanceof Z||e.$type===`BobCommand`:!1}var Te=class{commands={};aliases={};ux;logger;stringSimilarity;constructor(e){this.logger=e?.logger??new m,this.ux=e?.ux??new X,this.stringSimilarity=e?.stringSimilarity??new ee}getAvailableCommands(){return[...Object.keys(this.commands),...Object.keys(this.aliases)]}getCommands(){return Object.values(this.commands)}importFile=async e=>(await import(e)).default;commandResolver=async e=>{let t=await this.importFile(e);return t?(t&&typeof t==`object`&&`default`in t&&(t=t.default),typeof t==`function`&&Q(t)?t:null):null};withCommandResolver(e){return this.commandResolver=e,this}withFileImporter(e){return this.importFile=e,this}registerCommand(e,t=!1){if(!Q(e))throw Error(`Invalid command, it must extend the Command class.`);let n=e.command;if(!n)throw Error(`Cannot register a command with no name. ${e.name} `);if(!t&&this.commands[n])throw Error(`Command ${n} already registered.`);if(!t&&this.aliases[n])throw Error(`Command name ${n} conflicts with an existing alias.`);this.commands[n]=e;for(let r of e.aliases){if(!t&&this.commands[r])throw Error(`Alias ${r} conflicts with an existing command name.`);if(!t&&this.aliases[r])throw Error(`Alias ${r} already registered.`);this.aliases[r]=n}}async loadCommandsPath(e){for await(let t of this.listCommandsFiles(e))try{let e=await this.commandResolver(t);Q(e)&&this.registerCommand(e)}catch(e){throw Error(`Command ${t} failed to load. ${e}`,{cause:e})}}async runCommand(e,t,...n){let r;if(typeof t==`string`){let i=this.commands[t]??this.commands[this.aliases[t]];if(!i){let r=await this.suggestCommand(t);if(r)return await this.runCommand(e,r,...n);throw new g(t)}r=new i}else r=Q(t)?new t:t;return await r.run({ctx:e,logger:this.logger,args:n})??0}async suggestCommand(e){let t=this.getAvailableCommands(),{bestMatch:n,bestMatchIndex:r,ratings:i}=this.stringSimilarity.findBestMatch(e,t),a=i.filter(e=>e.rating>.3).map(e=>e.target);if(n&&(n.rating>0&&a.length<=1||n.rating>.7&&a.length>1)){let n=t[r];return await this.askRunSimilarCommand(e,n)?n:null}if(a.length){this.logger.error(`${c.default.bgRed(` ERROR `)} Command ${c.default.yellow(e)} not found.\n`);let t=await this.ux.askForSelect(c.default.green(`Did you mean to run one of these commands instead?`),a);if(t)return t}throw new g(e)}async askRunSimilarCommand(e,t){return this.logger.error(`${c.default.bgRed(` ERROR `)} Command ${c.default.yellow(e)} not found.\n`),this.ux.askForConfirmation(`${c.default.green(`Do you want to run ${c.default.yellow(t)} instead?`)} `)}async*listCommandsFiles(e){let t=await l.default.promises.readdir(e,{withFileTypes:!0});for(let n of t){let t=u.default.resolve(e,n.name);if(n.isDirectory())yield*this.listCommandsFiles(u.default.resolve(e,n.name));else{if(!t.endsWith(`.ts`)&&!t.endsWith(`.js`)&&!t.endsWith(`.mjs`)&&!t.endsWith(`.cjs`))continue;yield t}}}},Ee=class{logger;constructor(e){this.logger=e}handle(e){if(we(e))return e.pretty(this.logger),-1;throw e}},De=class extends Z{static command=`help`;static description=c.default.bold(`Show help information about the CLI and its commands`);constructor(e){super(),this.opts=e}async handle(){let e=this.opts.commandRegistry.getCommands().filter(e=>!e.hidden),t=this.opts.cliName??`Bob CLI`,n=this.opts.cliVersion??`0.0.0`,r=(await Promise.resolve().then(()=>require(`../package-supL7Tgp.cjs`)))?.default?.version??`0.0.0`;this.logger.log(`${t} ${c.default.green(n)} (core: ${c.default.yellow(r)})
|
|
5
5
|
|
|
6
6
|
${c.default.yellow(`Usage`)}:
|
|
7
7
|
command [options] [arguments]
|
|
8
8
|
|
|
9
9
|
${c.default.yellow(`Available commands`)}:
|
|
10
|
-
`);let i=Math.max(...e.map(e=>{let t=e.aliases.length>0?` (${e.aliases.join(`, `)})`:``;return e.command.length+t.length}))??0,a={};for(let t of e){let e=t.group??t.command.split(`:`)[0];a[e]||(a[e]=[]),a[e].push(t)}let o=Object.entries(a).sort(([e],[t])=>e.toLowerCase().localeCompare(t.toLowerCase())).sort(([,e],[,t])=>e.length-t.length);for(let[e,t]of o){let n=t.length>1;n&&this.logger.log(c.default.yellow(`${e}:`));let r=t.sort((e,t)=>e.command.toLowerCase().localeCompare(t.command.toLowerCase()));for(let e of r){let t=e.aliases.length>0?c.default.gray(` (${e.aliases.join(`, `)})`):``,r=I(i-(e.command.length+(e.aliases.length>0?` (${e.aliases.join(`, `)})`.length:0)));n&&(r=r.slice(2)),this.logger.log(`${n?` `:``}${c.default.green(e.command)}${t} ${r} ${e.description}`)}}}},
|
|
10
|
+
`);let i=Math.max(...e.map(e=>{let t=e.aliases.length>0?` (${e.aliases.join(`, `)})`:``;return e.command.length+t.length}))??0,a={};for(let t of e){let e=t.group??t.command.split(`:`)[0];a[e]||(a[e]=[]),a[e].push(t)}let o=Object.entries(a).sort(([e],[t])=>e.toLowerCase().localeCompare(t.toLowerCase())).sort(([,e],[,t])=>e.length-t.length);for(let[e,t]of o){let n=t.length>1;n&&this.logger.log(c.default.yellow(`${e}:`));let r=t.sort((e,t)=>e.command.toLowerCase().localeCompare(t.command.toLowerCase()));for(let e of r){let t=e.aliases.length>0?c.default.gray(` (${e.aliases.join(`, `)})`):``,r=I(i-(e.command.length+(e.aliases.length>0?` (${e.aliases.join(`, `)})`.length:0)));n&&(r=r.slice(2)),this.logger.log(`${n?` `:``}${c.default.green(e.command)}${t} ${r} ${e.description}`)}}}},Oe=class{ctx;logger;commandRegistry;exceptionHandler;helpCommand;newCommandRegistry(e){return new Te(e)}newHelpCommand(e){return new De(e)}newExceptionHandler(e){return new Ee(e.logger)}constructor(e={}){this.ctx=e.ctx,this.logger=e.logger??new m,this.commandRegistry=this.newCommandRegistry({logger:this.logger}),this.exceptionHandler=this.newExceptionHandler({logger:this.logger}),this.helpCommand=this.newHelpCommand({cliName:e.name,cliVersion:e.version,commandRegistry:this.commandRegistry})}withCommandResolver(e){return this.commandRegistry.withCommandResolver(e),this}withFileImporter(e){return this.commandRegistry.withFileImporter(e),this}async withCommands(...e){for(let t of e)typeof t==`string`?await this.commandRegistry.loadCommandsPath(t):typeof t==`function`?this.registerCommand(t):this.registerCommand(t.constructor)}async runCommand(e,...t){return e?await this.commandRegistry.runCommand(this.ctx??{},e,...t).catch(this.exceptionHandler.handle.bind(this.exceptionHandler)):await this.runHelpCommand()}async runHelpCommand(){return await this.runCommand(this.helpCommand)}registerCommand(e){this.commandRegistry.registerCommand(e)}},$=class e{static parse(t,n={}){let[r,...i]=t.split(/\{(.*?)\}/g).map(e=>e.trim()).filter(Boolean),a={},o={};for(let t of i){let r=e.parseParamSignature(t,n);r.isFlag?a[r.name]=r.definition:o[r.name]=r.definition}return{command:r,flags:a,args:o}}static parseParamSignature(e,t){let n=e,r=!1,i,a,o,s=!1,c=!1,l=!0;if(n.includes(`:`)){let[e,t]=n.split(`:`);n=e.trim(),i=t.trim()}if(n.includes(`=`)){let[e,t]=n.split(`=`);n=e.trim();let r=t.trim();l=!1,r.length?r===`*`?(c=!0,a=[]):r===`true`?(s=!0,a=!0):r===`false`?(s=!0,a=!1):a=r:a=null}else n.startsWith(`--`)&&(s=!0,l=!1,a=!1);if(n.includes(`|`)){let[e,...t]=n.split(`|`);n=e.trim(),o=t.map(e=>e.trim())}n.startsWith(`--`)&&(r=!0,n=n.slice(2)),n.endsWith(`?`)&&(l=!1,n=n.slice(0,-1)),n.endsWith(`*`)&&(c=!0,a=[],n=n.slice(0,-1)),i=i??t[n]??t[`--${n}`];let u;return u=r?s?F.boolean({description:i,alias:o,...a===void 0?{}:{default:a}}):c?F.string({description:i,alias:o,multiple:!0,...l?{required:!0}:{},default:a??[]}):F.string({description:i,alias:o,...l?{required:!0}:{},...a===void 0?{}:{default:a}}):c?P.string({description:i,multiple:!0,...l?{required:!0}:{},default:a??[]}):P.string({description:i,...l?{required:!0}:{},...a===void 0?{}:{default:a}}),{name:n,isFlag:r,definition:u}}},ke=class extends Z{static signature=``;static helperDefinitions={};static get command(){return this.signature.split(/\s/)[0]||``}async run(e){let t=this.constructor;if(t.signature&&!Object.prototype.hasOwnProperty.call(t,`_signatureParsed`)){let e=$.parse(t.signature,t.helperDefinitions),n=Object.prototype.hasOwnProperty.call(t,`flags`)?t.flags:{},r=Object.prototype.hasOwnProperty.call(t,`args`)?t.args:{};t.flags={...e.flags,...n},t.args={...e.args,...r},Object.defineProperty(t,`_signatureParsed`,{value:!0})}return super.run(e)}option(e,t=null){return this.parser.flag(e,t)}argument(e,t=null){return this.parser.argument(e,t)}};exports.Args=P,exports.BadCommandArgument=b,exports.BadCommandFlag=x,exports.BobError=h,exports.Cli=Oe,exports.Command=Z,exports.CommandNotFoundError=g,exports.CommandParser=C,exports.CommandRegistry=Te,exports.CommandSignatureParser=$,exports.CommandWithSignature=ke,exports.ExceptionHandler=Ee,exports.Flags=F,exports.HelpCommandFlag=L,exports.InvalidFlag=_,exports.Logger=m,exports.MissingRequiredArgumentValue=v,exports.MissingRequiredFlagValue=y,exports.StringSimilarity=ee,exports.TooManyArguments=te,exports.UX=X,exports.ValidationError=S,exports.askForCheckbox=z,exports.askForConfirmation=B,exports.askForEditor=ve,exports.askForExpand=V,exports.askForFileSelector=H,exports.askForInput=U,exports.askForList=W,exports.askForNumber=G,exports.askForPassword=K,exports.askForRawList=q,exports.askForSearch=J,exports.askForSelect=ye,exports.askForToggle=be,exports.keyValue=xe,exports.newLoader=Se,exports.newProgressBar=Ce,exports.table=Y,exports.withCancelHandling=R;
|
|
@@ -27,11 +27,6 @@ export type FlagDefinition = FlagProps & {
|
|
|
27
27
|
parse(input: any, opts: ParameterOpts): any;
|
|
28
28
|
};
|
|
29
29
|
export type FlagType<O> = O extends {
|
|
30
|
-
type: 'option';
|
|
31
|
-
options: infer T extends readonly string[];
|
|
32
|
-
} ? O extends {
|
|
33
|
-
multiple: true;
|
|
34
|
-
} ? [T[number]] extends [Array<unknown>] ? T[number] : T[number][] : T[number] : O extends {
|
|
35
30
|
parse: (...args: any[]) => infer R;
|
|
36
31
|
} ? O extends {
|
|
37
32
|
multiple: true;
|
|
@@ -2,7 +2,5 @@ import { FlagProps, ParameterOpts } from '../lib/types.js';
|
|
|
2
2
|
export declare function optionFlag<const T extends readonly string[], const U extends Partial<FlagProps>>(opts: {
|
|
3
3
|
options: T;
|
|
4
4
|
} & U): U & FlagProps<T[number]> & {
|
|
5
|
-
type: 'option';
|
|
6
|
-
options: T;
|
|
7
5
|
parse(input: any, opts: ParameterOpts): T[number];
|
|
8
6
|
};
|
package/dist/esm/src/index.js
CHANGED
|
@@ -119,7 +119,7 @@ var m = class {
|
|
|
119
119
|
}
|
|
120
120
|
pretty(t) {
|
|
121
121
|
let n = [];
|
|
122
|
-
if (this.detail.reason != null && n.push(["Reason", this.detail.reason]), this.detail.value != null && n.push(["Value", this.detail.value]), this.argDefinition?.help != null && n.push(["Help", e.green(this.argDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Argument ${e.bold.yellow(this.detail.arg)} value is invalid.`), n.length > 0) {
|
|
122
|
+
if (this.detail.reason != null && n.push(["Reason", this.detail.reason]), this.detail.value != null && n.push(["Value", e.yellow(this.detail.value)]), this.argDefinition?.help != null && n.push(["Help", e.green(this.argDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Argument ${e.bold.yellow(this.detail.arg)} value is invalid.`), n.length > 0) {
|
|
123
123
|
t.log("");
|
|
124
124
|
let r = Math.max(...n.map(([e]) => e.length));
|
|
125
125
|
for (let [i, a] of n) t.log(` ${" ".repeat(r - i.length)}${e.dim(i)} ${a}`);
|
|
@@ -133,7 +133,7 @@ var m = class {
|
|
|
133
133
|
}
|
|
134
134
|
pretty(t) {
|
|
135
135
|
let n = [];
|
|
136
|
-
if (this.param.reason != null && n.push(["Reason", this.param.reason]), this.param.value != null && n.push(["Value", this.param.value]), this.flagDefinition?.help != null && n.push(["Help", e.green(this.flagDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Flag ${e.bold.yellow(this.param.flag)} value is invalid.`), n.length > 0) {
|
|
136
|
+
if (this.param.reason != null && n.push(["Reason", this.param.reason]), this.param.value != null && n.push(["Value", e.yellow(this.param.value)]), this.flagDefinition?.help != null && n.push(["Help", e.green(this.flagDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Flag ${e.bold.yellow(this.param.flag)} value is invalid.`), n.length > 0) {
|
|
137
137
|
t.log("");
|
|
138
138
|
let r = Math.max(...n.map(([e]) => e.length));
|
|
139
139
|
for (let [i, a] of n) t.log(` ${" ".repeat(r - i.length)}${e.dim(i)} ${a}`);
|
|
@@ -249,7 +249,7 @@ var m = class {
|
|
|
249
249
|
ux: this.ux,
|
|
250
250
|
ctx: this.opts.ctx,
|
|
251
251
|
definition: t,
|
|
252
|
-
cmd: this.opts.cmd ??
|
|
252
|
+
cmd: this.opts.cmd ?? Z
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
async safeParse(e, t, n, r) {
|
|
@@ -342,7 +342,11 @@ function ae(e, n) {
|
|
|
342
342
|
}
|
|
343
343
|
function oe(e, n) {
|
|
344
344
|
let r = String(e);
|
|
345
|
-
if (n?.exists
|
|
345
|
+
if (n?.exists) try {
|
|
346
|
+
if (!t.lstatSync(r).isDirectory()) throw new w("directory does not exist");
|
|
347
|
+
} catch (e) {
|
|
348
|
+
throw e instanceof w ? e : new w("directory does not exist");
|
|
349
|
+
}
|
|
346
350
|
return r;
|
|
347
351
|
}
|
|
348
352
|
function se(e) {
|
|
@@ -365,56 +369,43 @@ var ce = E({
|
|
|
365
369
|
});
|
|
366
370
|
//#endregion
|
|
367
371
|
//#region src/shared/ask-helpers.ts
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
separator: ",",
|
|
372
|
-
validate: (n) => {
|
|
373
|
-
if ((n == null || n.trim() === "") && t.required) return "Please enter at least one value";
|
|
374
|
-
for (let r of n.split(",")) {
|
|
375
|
-
let n = r.trim();
|
|
376
|
-
if (n !== "") try {
|
|
377
|
-
t.parse(n, e);
|
|
378
|
-
} catch (e) {
|
|
379
|
-
return e instanceof w ? `"${n}": ${e.message}` : `"${n}": Invalid value`;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return !0;
|
|
383
|
-
}
|
|
384
|
-
}) : "secret" in t && t.secret ? e.ux.askForPassword(r, { validate: (n) => {
|
|
385
|
-
if ((n == null || typeof n == "string" && n.trim() === "") && t.required) return "This value is required";
|
|
372
|
+
function O(e, t) {
|
|
373
|
+
return (n) => {
|
|
374
|
+
if ((n == null || typeof n == "string" && n.trim() === "") && e.required) return "This value is required";
|
|
386
375
|
try {
|
|
387
|
-
|
|
376
|
+
e.parse(n, t);
|
|
388
377
|
} catch (e) {
|
|
389
378
|
return e instanceof w ? e.message : "Invalid value";
|
|
390
379
|
}
|
|
391
380
|
return !0;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function k(e, t) {
|
|
384
|
+
return (n) => {
|
|
385
|
+
if ((n == null || n.trim() === "") && e.required) return "Please enter at least one value";
|
|
386
|
+
for (let r of n.split(",")) {
|
|
387
|
+
let n = r.trim();
|
|
388
|
+
if (n !== "") try {
|
|
389
|
+
e.parse(n, t);
|
|
390
|
+
} catch (e) {
|
|
391
|
+
return e instanceof w ? `"${n}": ${e.message}` : `"${n}": Invalid value`;
|
|
392
|
+
}
|
|
398
393
|
}
|
|
399
394
|
return !0;
|
|
400
|
-
}
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
async function le(e) {
|
|
398
|
+
let t = e.definition, n = "multiple" in t && t.multiple, r = D(e.name, t);
|
|
399
|
+
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
400
|
+
separator: ",",
|
|
401
|
+
validate: k(t, e)
|
|
402
|
+
}) : "secret" in t && t.secret ? e.ux.askForPassword(r, { validate: O(t, e) }) : await e.ux.askForInput(r, { validate: O(t, e) });
|
|
401
403
|
}
|
|
402
404
|
async function ue(e) {
|
|
403
405
|
let t = e.definition, n = "multiple" in t && t.multiple, r = D(e.name, t);
|
|
404
406
|
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
405
407
|
separator: ",",
|
|
406
|
-
validate: (
|
|
407
|
-
if ((n == null || n.trim() === "") && t.required) return "Please enter at least one value";
|
|
408
|
-
for (let r of n.split(",")) {
|
|
409
|
-
let n = r.trim();
|
|
410
|
-
if (n !== "") try {
|
|
411
|
-
t.parse(n, e);
|
|
412
|
-
} catch (e) {
|
|
413
|
-
return e instanceof w ? `"${n}": ${e.message}` : `"${n}": Invalid value`;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
return !0;
|
|
417
|
-
}
|
|
408
|
+
validate: k(t, e)
|
|
418
409
|
}) : await e.ux.askForNumber(r, { validate: (n) => {
|
|
419
410
|
if (n === void 0 && t.required) return "This value is required";
|
|
420
411
|
if (n !== void 0) try {
|
|
@@ -444,27 +435,19 @@ async function pe(e) {
|
|
|
444
435
|
}
|
|
445
436
|
async function me(e) {
|
|
446
437
|
let t = D(e.name, e.definition);
|
|
447
|
-
return await e.ux.askForInput(t, { validate: (
|
|
448
|
-
if ((t == null || typeof t == "string" && t.trim() === "") && e.definition.required) return "This value is required";
|
|
449
|
-
try {
|
|
450
|
-
e.definition.parse(t, e);
|
|
451
|
-
} catch (e) {
|
|
452
|
-
return e instanceof w ? e.message : "Invalid value";
|
|
453
|
-
}
|
|
454
|
-
return !0;
|
|
455
|
-
} });
|
|
438
|
+
return await e.ux.askForInput(t, { validate: O(e.definition, e) });
|
|
456
439
|
}
|
|
457
440
|
//#endregion
|
|
458
441
|
//#region src/flags/directory.ts
|
|
459
|
-
var
|
|
442
|
+
var A = E({
|
|
460
443
|
parse: (e, t) => oe(e, { exists: t.definition.exists }),
|
|
461
444
|
ask: pe,
|
|
462
445
|
type: "directory"
|
|
463
|
-
}),
|
|
446
|
+
}), j = E({
|
|
464
447
|
parse: (e, t) => ae(e, { exists: t.definition.exists }),
|
|
465
448
|
ask: fe,
|
|
466
449
|
type: "file"
|
|
467
|
-
}),
|
|
450
|
+
}), M = E({
|
|
468
451
|
parse: (e, t) => ne(e, {
|
|
469
452
|
min: t.definition.min,
|
|
470
453
|
max: t.definition.max
|
|
@@ -474,7 +457,7 @@ var O = E({
|
|
|
474
457
|
});
|
|
475
458
|
//#endregion
|
|
476
459
|
//#region src/flags/option.ts
|
|
477
|
-
function
|
|
460
|
+
function N(e) {
|
|
478
461
|
return E({
|
|
479
462
|
parse: (e, t) => ie(e, t.definition.options),
|
|
480
463
|
ask: de,
|
|
@@ -484,35 +467,35 @@ function j(e) {
|
|
|
484
467
|
}
|
|
485
468
|
//#endregion
|
|
486
469
|
//#region src/flags/string.ts
|
|
487
|
-
var
|
|
470
|
+
var P = E({
|
|
488
471
|
parse: (e) => te(e),
|
|
489
472
|
ask: le,
|
|
490
473
|
type: "string"
|
|
491
|
-
}),
|
|
474
|
+
}), F = E({
|
|
492
475
|
parse: (e) => se(e),
|
|
493
476
|
ask: me,
|
|
494
477
|
type: "url"
|
|
495
|
-
}),
|
|
496
|
-
string:
|
|
497
|
-
number:
|
|
498
|
-
option:
|
|
499
|
-
file:
|
|
500
|
-
directory:
|
|
501
|
-
url:
|
|
478
|
+
}), I = {
|
|
479
|
+
string: P,
|
|
480
|
+
number: M,
|
|
481
|
+
option: N,
|
|
482
|
+
file: j,
|
|
483
|
+
directory: A,
|
|
484
|
+
url: F,
|
|
502
485
|
custom: E
|
|
503
|
-
},
|
|
504
|
-
string:
|
|
505
|
-
number:
|
|
486
|
+
}, L = {
|
|
487
|
+
string: P,
|
|
488
|
+
number: M,
|
|
506
489
|
boolean: ce,
|
|
507
|
-
option:
|
|
508
|
-
file:
|
|
509
|
-
directory:
|
|
510
|
-
url:
|
|
490
|
+
option: N,
|
|
491
|
+
file: j,
|
|
492
|
+
directory: A,
|
|
493
|
+
url: F,
|
|
511
494
|
custom: E
|
|
512
495
|
};
|
|
513
496
|
//#endregion
|
|
514
497
|
//#region src/lib/string.ts
|
|
515
|
-
function
|
|
498
|
+
function R(e) {
|
|
516
499
|
return Array(e + 5).join(" ");
|
|
517
500
|
}
|
|
518
501
|
//#endregion
|
|
@@ -521,7 +504,7 @@ function he(e) {
|
|
|
521
504
|
let t = e.type;
|
|
522
505
|
return t === "option" && "options" in e && e.options ? `enum: ${e.options.join("|")}` : t ?? "custom";
|
|
523
506
|
}
|
|
524
|
-
var
|
|
507
|
+
var z = L.boolean({
|
|
525
508
|
alias: ["h"],
|
|
526
509
|
handler: (t, n) => {
|
|
527
510
|
if (!t) return { shouldStop: !1 };
|
|
@@ -541,7 +524,7 @@ var L = F.boolean({
|
|
|
541
524
|
if (o.length > 0) {
|
|
542
525
|
console.log(`\n${e.yellow("Arguments")}:`);
|
|
543
526
|
for (let [t, n] of o) {
|
|
544
|
-
let r =
|
|
527
|
+
let r = R(f - t.length), i = ` ${e.green(t)} ${r} ${n.description ?? "\b"}`;
|
|
545
528
|
if (n.default !== void 0 && !n.required) {
|
|
546
529
|
let t = typeof n.default == "function" ? "[function]" : n.multiple ? JSON.stringify(n.default) : n.default;
|
|
547
530
|
i += ` ${e.yellow(`[default: ${t}]`)}`;
|
|
@@ -552,7 +535,7 @@ var L = F.boolean({
|
|
|
552
535
|
if (s.length > 0) {
|
|
553
536
|
console.log(`\n${e.yellow("Options")}:`);
|
|
554
537
|
for (let t of c) {
|
|
555
|
-
let n =
|
|
538
|
+
let n = R(f - t.flagWithAlias.length), r = ` ${e.green(t.flagWithAlias)} ${n} ${t.description ?? "\b"}`;
|
|
556
539
|
if (t.type && (r += ` ${e.white(`(${he(t)})`)}`), t.default !== void 0 && !t.required) {
|
|
557
540
|
let n = typeof t.default == "function" ? "(function)" : t.default;
|
|
558
541
|
r += ` ${e.yellow(`[default: ${n}]`)}`;
|
|
@@ -574,7 +557,7 @@ var L = F.boolean({
|
|
|
574
557
|
};
|
|
575
558
|
//#endregion
|
|
576
559
|
//#region src/ux/helpers.ts
|
|
577
|
-
async function
|
|
560
|
+
async function B(e, t) {
|
|
578
561
|
try {
|
|
579
562
|
return await e();
|
|
580
563
|
} catch (e) {
|
|
@@ -584,7 +567,7 @@ async function R(e, t) {
|
|
|
584
567
|
}
|
|
585
568
|
//#endregion
|
|
586
569
|
//#region src/ux/askForCheckbox.ts
|
|
587
|
-
async function
|
|
570
|
+
async function V(e, t, n) {
|
|
588
571
|
if (t.length === 0) throw Error("No options provided");
|
|
589
572
|
let r = t.map((e) => typeof e == "string" ? {
|
|
590
573
|
name: e,
|
|
@@ -596,7 +579,7 @@ async function z(e, t, n) {
|
|
|
596
579
|
checked: e.checked,
|
|
597
580
|
description: e.description
|
|
598
581
|
});
|
|
599
|
-
return
|
|
582
|
+
return B(() => i({
|
|
600
583
|
message: e,
|
|
601
584
|
choices: r,
|
|
602
585
|
required: n?.required,
|
|
@@ -608,8 +591,8 @@ async function z(e, t, n) {
|
|
|
608
591
|
}
|
|
609
592
|
//#endregion
|
|
610
593
|
//#region src/ux/askForConfirmation.ts
|
|
611
|
-
async function
|
|
612
|
-
return
|
|
594
|
+
async function H(e = "Do you want to continue?", t) {
|
|
595
|
+
return B(() => a({
|
|
613
596
|
message: e,
|
|
614
597
|
default: t?.default ?? !1,
|
|
615
598
|
transformer: t?.transformer
|
|
@@ -617,8 +600,8 @@ async function B(e = "Do you want to continue?", t) {
|
|
|
617
600
|
}
|
|
618
601
|
//#endregion
|
|
619
602
|
//#region src/ux/askForEditor.ts
|
|
620
|
-
async function
|
|
621
|
-
return
|
|
603
|
+
async function U(e, t) {
|
|
604
|
+
return B(() => o({
|
|
622
605
|
message: e,
|
|
623
606
|
default: t?.default,
|
|
624
607
|
postfix: t?.postfix,
|
|
@@ -628,8 +611,8 @@ async function V(e, t) {
|
|
|
628
611
|
}
|
|
629
612
|
//#endregion
|
|
630
613
|
//#region src/ux/askForExpand.ts
|
|
631
|
-
async function
|
|
632
|
-
return
|
|
614
|
+
async function W(e, t, n) {
|
|
615
|
+
return B(() => s({
|
|
633
616
|
message: e,
|
|
634
617
|
choices: t,
|
|
635
618
|
default: n?.default
|
|
@@ -637,8 +620,8 @@ async function H(e, t, n) {
|
|
|
637
620
|
}
|
|
638
621
|
//#endregion
|
|
639
622
|
//#region src/ux/askForFileSelector.ts
|
|
640
|
-
async function
|
|
641
|
-
return
|
|
623
|
+
async function G(e, t) {
|
|
624
|
+
return B(async () => {
|
|
642
625
|
let n = await ee({
|
|
643
626
|
message: e,
|
|
644
627
|
basePath: t?.basePath,
|
|
@@ -653,8 +636,8 @@ async function U(e, t) {
|
|
|
653
636
|
}
|
|
654
637
|
//#endregion
|
|
655
638
|
//#region src/ux/askForInput.ts
|
|
656
|
-
async function
|
|
657
|
-
return
|
|
639
|
+
async function K(e, t) {
|
|
640
|
+
return B(() => c({
|
|
658
641
|
message: e,
|
|
659
642
|
default: t?.default,
|
|
660
643
|
required: t?.required,
|
|
@@ -664,9 +647,9 @@ async function W(e, t) {
|
|
|
664
647
|
}
|
|
665
648
|
//#endregion
|
|
666
649
|
//#region src/ux/askForList.ts
|
|
667
|
-
async function
|
|
650
|
+
async function q(e, t) {
|
|
668
651
|
let n = t?.separator ?? ",";
|
|
669
|
-
return
|
|
652
|
+
return B(async () => (await c({
|
|
670
653
|
message: e,
|
|
671
654
|
default: t?.default,
|
|
672
655
|
validate: t?.validate
|
|
@@ -674,8 +657,8 @@ async function G(e, t) {
|
|
|
674
657
|
}
|
|
675
658
|
//#endregion
|
|
676
659
|
//#region src/ux/askForNumber.ts
|
|
677
|
-
async function
|
|
678
|
-
return
|
|
660
|
+
async function J(e, t) {
|
|
661
|
+
return B(async () => await l({
|
|
679
662
|
message: e,
|
|
680
663
|
default: t?.default,
|
|
681
664
|
required: t?.required,
|
|
@@ -687,8 +670,8 @@ async function K(e, t) {
|
|
|
687
670
|
}
|
|
688
671
|
//#endregion
|
|
689
672
|
//#region src/ux/askForPassword.ts
|
|
690
|
-
async function
|
|
691
|
-
return
|
|
673
|
+
async function _e(e, t) {
|
|
674
|
+
return B(() => u({
|
|
692
675
|
message: e,
|
|
693
676
|
mask: t?.mask,
|
|
694
677
|
validate: t?.validate
|
|
@@ -696,8 +679,8 @@ async function q(e, t) {
|
|
|
696
679
|
}
|
|
697
680
|
//#endregion
|
|
698
681
|
//#region src/ux/askForRawList.ts
|
|
699
|
-
async function
|
|
700
|
-
return
|
|
682
|
+
async function ve(e, t, n) {
|
|
683
|
+
return B(() => d({
|
|
701
684
|
message: e,
|
|
702
685
|
choices: t,
|
|
703
686
|
loop: n?.loop
|
|
@@ -705,8 +688,8 @@ async function J(e, t, n) {
|
|
|
705
688
|
}
|
|
706
689
|
//#endregion
|
|
707
690
|
//#region src/ux/askForSearch.ts
|
|
708
|
-
async function
|
|
709
|
-
return
|
|
691
|
+
async function ye(e, t, n) {
|
|
692
|
+
return B(() => f({
|
|
710
693
|
message: e,
|
|
711
694
|
source: t,
|
|
712
695
|
pageSize: n?.pageSize,
|
|
@@ -715,13 +698,13 @@ async function _e(e, t, n) {
|
|
|
715
698
|
}
|
|
716
699
|
//#endregion
|
|
717
700
|
//#region src/ux/askForSelect.ts
|
|
718
|
-
async function
|
|
701
|
+
async function be(e, t, n) {
|
|
719
702
|
if (t.length === 0) throw Error("No options provided");
|
|
720
703
|
let r = t.map((e) => typeof e == "string" ? {
|
|
721
704
|
name: e,
|
|
722
705
|
value: e
|
|
723
706
|
} : e);
|
|
724
|
-
return
|
|
707
|
+
return B(() => p({
|
|
725
708
|
message: e,
|
|
726
709
|
choices: r,
|
|
727
710
|
default: n?.default,
|
|
@@ -731,9 +714,9 @@ async function ve(e, t, n) {
|
|
|
731
714
|
}
|
|
732
715
|
//#endregion
|
|
733
716
|
//#region src/ux/askForToggle.ts
|
|
734
|
-
async function
|
|
717
|
+
async function Y(e, t) {
|
|
735
718
|
let n = t?.active ?? "Yes", r = t?.inactive ?? "No";
|
|
736
|
-
return
|
|
719
|
+
return B(() => a({
|
|
737
720
|
message: e,
|
|
738
721
|
default: t?.default ?? !1,
|
|
739
722
|
transformer: (e) => e ? n : r
|
|
@@ -741,7 +724,7 @@ async function ye(e, t) {
|
|
|
741
724
|
}
|
|
742
725
|
//#endregion
|
|
743
726
|
//#region src/ux/keyValue.ts
|
|
744
|
-
function
|
|
727
|
+
function xe(t, n) {
|
|
745
728
|
let r = n?.separator ?? ": ", i = n?.keyStyle ?? e.bold, a = Array.isArray(t) ? t : Object.entries(t);
|
|
746
729
|
if (a.length === 0) return;
|
|
747
730
|
let o = Math.max(...a.map(([e]) => e.length));
|
|
@@ -749,7 +732,7 @@ function be(t, n) {
|
|
|
749
732
|
}
|
|
750
733
|
//#endregion
|
|
751
734
|
//#region src/ux/loader.ts
|
|
752
|
-
function
|
|
735
|
+
function Se(e = "", t = [
|
|
753
736
|
"⠙",
|
|
754
737
|
"⠘",
|
|
755
738
|
"⠰",
|
|
@@ -762,9 +745,9 @@ function xe(e = "", t = [
|
|
|
762
745
|
"⠉"
|
|
763
746
|
], n = 100) {
|
|
764
747
|
let r = e, i = null, a = 0, o = setInterval(function() {
|
|
765
|
-
i &&= (process.stdout.write(
|
|
748
|
+
i &&= (process.stdout.write("\r" + " ".repeat(i.length + 5) + "\r"), null), process.stdout.write("\r" + t[a++] + " " + r), a %= t.length;
|
|
766
749
|
}, n), s = () => {
|
|
767
|
-
clearInterval(o), process.stdout.write(
|
|
750
|
+
clearInterval(o), process.stdout.write("\r" + " ".repeat(r.length + 5) + "\r");
|
|
768
751
|
};
|
|
769
752
|
return {
|
|
770
753
|
[Symbol.dispose]: s,
|
|
@@ -777,7 +760,7 @@ function xe(e = "", t = [
|
|
|
777
760
|
}
|
|
778
761
|
//#endregion
|
|
779
762
|
//#region src/ux/progressBar.ts
|
|
780
|
-
function
|
|
763
|
+
function Ce(e, t) {
|
|
781
764
|
let n = t?.width ?? 30, r = t?.completeChar ?? "█", i = t?.incompleteChar ?? "░", a = 0, o = !1, s = () => {
|
|
782
765
|
if (o) return;
|
|
783
766
|
let t = e <= 0 ? 1 : Math.min(a / e, 1), s = Math.round(t * n), c = `${r.repeat(s) + i.repeat(n - s)} ${Math.round(t * 100)}% ${a}/${e}`;
|
|
@@ -799,7 +782,7 @@ function Se(e, t) {
|
|
|
799
782
|
}
|
|
800
783
|
//#endregion
|
|
801
784
|
//#region src/ux/table.ts
|
|
802
|
-
function
|
|
785
|
+
function we(t, n) {
|
|
803
786
|
if (t.length === 0) return;
|
|
804
787
|
let r = n ?? Object.keys(t[0]).map((e) => ({ key: e })), i = r.map((e) => e.header ?? e.key.toUpperCase()), a = r.map((e, n) => {
|
|
805
788
|
let r = Math.max(i[n].length, ...t.map((t) => (e.format ? e.format(t[e.key]) : String(t[e.key] ?? "")).length));
|
|
@@ -825,71 +808,71 @@ function Ce(t, n) {
|
|
|
825
808
|
}
|
|
826
809
|
//#endregion
|
|
827
810
|
//#region src/ux/index.ts
|
|
828
|
-
var
|
|
811
|
+
var X = class {
|
|
829
812
|
askForConfirmation(e, t) {
|
|
830
|
-
return
|
|
813
|
+
return H(e, t);
|
|
831
814
|
}
|
|
832
815
|
askForInput(e, t) {
|
|
833
|
-
return
|
|
816
|
+
return K(e, t);
|
|
834
817
|
}
|
|
835
818
|
askForPassword(e, t) {
|
|
836
|
-
return
|
|
819
|
+
return _e(e, t);
|
|
837
820
|
}
|
|
838
821
|
askForNumber(e, t) {
|
|
839
|
-
return
|
|
822
|
+
return J(e, t);
|
|
840
823
|
}
|
|
841
824
|
askForSelect(e, t, n) {
|
|
842
|
-
return
|
|
825
|
+
return be(e, t, n);
|
|
843
826
|
}
|
|
844
827
|
askForCheckbox(e, t, n) {
|
|
845
|
-
return
|
|
828
|
+
return V(e, t, n);
|
|
846
829
|
}
|
|
847
830
|
askForSearch(e, t, n) {
|
|
848
|
-
return
|
|
831
|
+
return ye(e, t, n);
|
|
849
832
|
}
|
|
850
833
|
askForList(e, t) {
|
|
851
|
-
return
|
|
834
|
+
return q(e, t);
|
|
852
835
|
}
|
|
853
836
|
askForToggle(e, t) {
|
|
854
|
-
return
|
|
837
|
+
return Y(e, t);
|
|
855
838
|
}
|
|
856
839
|
askForEditor(e, t) {
|
|
857
|
-
return
|
|
840
|
+
return U(e, t);
|
|
858
841
|
}
|
|
859
842
|
askForRawList(e, t, n) {
|
|
860
|
-
return
|
|
843
|
+
return ve(e, t, n);
|
|
861
844
|
}
|
|
862
845
|
askForExpand(e, t, n) {
|
|
863
|
-
return
|
|
846
|
+
return W(e, t, n);
|
|
864
847
|
}
|
|
865
848
|
askForFile(e, t) {
|
|
866
|
-
return
|
|
849
|
+
return G(e, {
|
|
867
850
|
...t,
|
|
868
851
|
type: "file"
|
|
869
852
|
});
|
|
870
853
|
}
|
|
871
854
|
askForDirectory(e, t) {
|
|
872
|
-
return
|
|
855
|
+
return G(e, {
|
|
873
856
|
...t,
|
|
874
857
|
type: "directory"
|
|
875
858
|
});
|
|
876
859
|
}
|
|
877
860
|
askForFileSelector(e, t) {
|
|
878
|
-
return
|
|
861
|
+
return G(e, t);
|
|
879
862
|
}
|
|
880
863
|
keyValue(e, t) {
|
|
881
|
-
return
|
|
864
|
+
return xe(e, t);
|
|
882
865
|
}
|
|
883
866
|
table(e, t) {
|
|
884
|
-
return
|
|
867
|
+
return we(e, t);
|
|
885
868
|
}
|
|
886
869
|
newProgressBar(e, t) {
|
|
887
|
-
return
|
|
870
|
+
return Ce(e, t);
|
|
888
871
|
}
|
|
889
872
|
newLoader(e, t, n) {
|
|
890
|
-
return
|
|
873
|
+
return Se(e, t, n);
|
|
891
874
|
}
|
|
892
|
-
},
|
|
875
|
+
}, Z = class {
|
|
893
876
|
static $type = "BobCommand";
|
|
894
877
|
static command = "";
|
|
895
878
|
static description = "";
|
|
@@ -907,7 +890,7 @@ var Y = class {
|
|
|
907
890
|
logger;
|
|
908
891
|
ux;
|
|
909
892
|
parser;
|
|
910
|
-
static baseFlags = { help:
|
|
893
|
+
static baseFlags = { help: z };
|
|
911
894
|
newCommandParser(e) {
|
|
912
895
|
return new T({
|
|
913
896
|
ux: e.ux,
|
|
@@ -918,7 +901,7 @@ var Y = class {
|
|
|
918
901
|
});
|
|
919
902
|
}
|
|
920
903
|
newUX() {
|
|
921
|
-
return new
|
|
904
|
+
return new X();
|
|
922
905
|
}
|
|
923
906
|
async run(e) {
|
|
924
907
|
let t = this.constructor;
|
|
@@ -967,22 +950,22 @@ var Y = class {
|
|
|
967
950
|
};
|
|
968
951
|
//#endregion
|
|
969
952
|
//#region src/lib/helpers.ts
|
|
970
|
-
function
|
|
953
|
+
function Te(e) {
|
|
971
954
|
return typeof e == "object" && !!e && "$type" in e && e.$type === "BobError";
|
|
972
955
|
}
|
|
973
|
-
function
|
|
974
|
-
return typeof e == "function" ? e.prototype instanceof
|
|
956
|
+
function Q(e) {
|
|
957
|
+
return typeof e == "function" ? e.prototype instanceof Z || e.$type === "BobCommand" : !1;
|
|
975
958
|
}
|
|
976
959
|
//#endregion
|
|
977
960
|
//#region src/CommandRegistry.ts
|
|
978
|
-
var
|
|
961
|
+
var Ee = class {
|
|
979
962
|
commands = {};
|
|
980
963
|
aliases = {};
|
|
981
964
|
ux;
|
|
982
965
|
logger;
|
|
983
966
|
stringSimilarity;
|
|
984
967
|
constructor(e) {
|
|
985
|
-
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new
|
|
968
|
+
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new X(), this.stringSimilarity = e?.stringSimilarity ?? new h();
|
|
986
969
|
}
|
|
987
970
|
getAvailableCommands() {
|
|
988
971
|
return [...Object.keys(this.commands), ...Object.keys(this.aliases)];
|
|
@@ -993,7 +976,7 @@ var Q = class {
|
|
|
993
976
|
importFile = async (e) => (await import(e)).default;
|
|
994
977
|
commandResolver = async (e) => {
|
|
995
978
|
let t = await this.importFile(e);
|
|
996
|
-
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" &&
|
|
979
|
+
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" && Q(t) ? t : null) : null;
|
|
997
980
|
};
|
|
998
981
|
withCommandResolver(e) {
|
|
999
982
|
return this.commandResolver = e, this;
|
|
@@ -1002,7 +985,7 @@ var Q = class {
|
|
|
1002
985
|
return this.importFile = e, this;
|
|
1003
986
|
}
|
|
1004
987
|
registerCommand(e, t = !1) {
|
|
1005
|
-
if (!
|
|
988
|
+
if (!Q(e)) throw Error("Invalid command, it must extend the Command class.");
|
|
1006
989
|
let n = e.command;
|
|
1007
990
|
if (!n) throw Error(`Cannot register a command with no name. ${e.name} `);
|
|
1008
991
|
if (!t && this.commands[n]) throw Error(`Command ${n} already registered.`);
|
|
@@ -1017,7 +1000,7 @@ var Q = class {
|
|
|
1017
1000
|
async loadCommandsPath(e) {
|
|
1018
1001
|
for await (let t of this.listCommandsFiles(e)) try {
|
|
1019
1002
|
let e = await this.commandResolver(t);
|
|
1020
|
-
|
|
1003
|
+
Q(e) && this.registerCommand(e);
|
|
1021
1004
|
} catch (e) {
|
|
1022
1005
|
throw Error(`Command ${t} failed to load. ${e}`, { cause: e });
|
|
1023
1006
|
}
|
|
@@ -1032,7 +1015,7 @@ var Q = class {
|
|
|
1032
1015
|
throw new _(t);
|
|
1033
1016
|
}
|
|
1034
1017
|
r = new i();
|
|
1035
|
-
} else r =
|
|
1018
|
+
} else r = Q(t) ? new t() : t;
|
|
1036
1019
|
return await r.run({
|
|
1037
1020
|
ctx: e,
|
|
1038
1021
|
logger: this.logger,
|
|
@@ -1056,7 +1039,7 @@ var Q = class {
|
|
|
1056
1039
|
return this.logger.error(`${e.bgRed(" ERROR ")} Command ${e.yellow(t)} not found.\n`), this.ux.askForConfirmation(`${e.green(`Do you want to run ${e.yellow(n)} instead?`)} `);
|
|
1057
1040
|
}
|
|
1058
1041
|
async *listCommandsFiles(e) {
|
|
1059
|
-
let r = t.
|
|
1042
|
+
let r = await t.promises.readdir(e, { withFileTypes: !0 });
|
|
1060
1043
|
for (let t of r) {
|
|
1061
1044
|
let r = n.resolve(e, t.name);
|
|
1062
1045
|
if (t.isDirectory()) yield* this.listCommandsFiles(n.resolve(e, t.name));
|
|
@@ -1066,23 +1049,23 @@ var Q = class {
|
|
|
1066
1049
|
}
|
|
1067
1050
|
}
|
|
1068
1051
|
}
|
|
1069
|
-
},
|
|
1052
|
+
}, De = class {
|
|
1070
1053
|
logger;
|
|
1071
1054
|
constructor(e) {
|
|
1072
1055
|
this.logger = e;
|
|
1073
1056
|
}
|
|
1074
1057
|
handle(e) {
|
|
1075
|
-
if (
|
|
1058
|
+
if (Te(e)) return e.pretty(this.logger), -1;
|
|
1076
1059
|
throw e;
|
|
1077
1060
|
}
|
|
1078
|
-
},
|
|
1061
|
+
}, Oe = class extends Z {
|
|
1079
1062
|
static command = "help";
|
|
1080
1063
|
static description = e.bold("Show help information about the CLI and its commands");
|
|
1081
1064
|
constructor(e) {
|
|
1082
1065
|
super(), this.opts = e;
|
|
1083
1066
|
}
|
|
1084
1067
|
async handle() {
|
|
1085
|
-
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0", i = (await import("../package-
|
|
1068
|
+
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0", i = (await import("../package-BNru0kNU.js"))?.default?.version ?? "0.0.0";
|
|
1086
1069
|
this.logger.log(`${n} ${e.green(r)} (core: ${e.yellow(i)})
|
|
1087
1070
|
|
|
1088
1071
|
${e.yellow("Usage")}:
|
|
@@ -1104,25 +1087,25 @@ ${e.yellow("Available commands")}:
|
|
|
1104
1087
|
r && this.logger.log(e.yellow(`${t}:`));
|
|
1105
1088
|
let i = n.sort((e, t) => e.command.toLowerCase().localeCompare(t.command.toLowerCase()));
|
|
1106
1089
|
for (let t of i) {
|
|
1107
|
-
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i =
|
|
1090
|
+
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i = R(a - (t.command.length + (t.aliases.length > 0 ? ` (${t.aliases.join(", ")})`.length : 0)));
|
|
1108
1091
|
r && (i = i.slice(2)), this.logger.log(`${r ? " " : ""}${e.green(t.command)}${n} ${i} ${t.description}`);
|
|
1109
1092
|
}
|
|
1110
1093
|
}
|
|
1111
1094
|
}
|
|
1112
|
-
},
|
|
1095
|
+
}, ke = class {
|
|
1113
1096
|
ctx;
|
|
1114
1097
|
logger;
|
|
1115
1098
|
commandRegistry;
|
|
1116
1099
|
exceptionHandler;
|
|
1117
1100
|
helpCommand;
|
|
1118
1101
|
newCommandRegistry(e) {
|
|
1119
|
-
return new
|
|
1102
|
+
return new Ee(e);
|
|
1120
1103
|
}
|
|
1121
1104
|
newHelpCommand(e) {
|
|
1122
|
-
return new
|
|
1105
|
+
return new Oe(e);
|
|
1123
1106
|
}
|
|
1124
1107
|
newExceptionHandler(e) {
|
|
1125
|
-
return new
|
|
1108
|
+
return new De(e.logger);
|
|
1126
1109
|
}
|
|
1127
1110
|
constructor(e = {}) {
|
|
1128
1111
|
this.ctx = e.ctx, this.logger = e.logger ?? new m(), this.commandRegistry = this.newCommandRegistry({ logger: this.logger }), this.exceptionHandler = this.newExceptionHandler({ logger: this.logger }), this.helpCommand = this.newHelpCommand({
|
|
@@ -1180,27 +1163,27 @@ ${e.yellow("Available commands")}:
|
|
|
1180
1163
|
}
|
|
1181
1164
|
n.startsWith("--") && (r = !0, n = n.slice(2)), n.endsWith("?") && (l = !1, n = n.slice(0, -1)), n.endsWith("*") && (c = !0, a = [], n = n.slice(0, -1)), i = i ?? t[n] ?? t[`--${n}`];
|
|
1182
1165
|
let u;
|
|
1183
|
-
return u = r ? s ?
|
|
1166
|
+
return u = r ? s ? L.boolean({
|
|
1184
1167
|
description: i,
|
|
1185
1168
|
alias: o,
|
|
1186
1169
|
...a === void 0 ? {} : { default: a }
|
|
1187
|
-
}) : c ?
|
|
1170
|
+
}) : c ? L.string({
|
|
1188
1171
|
description: i,
|
|
1189
1172
|
alias: o,
|
|
1190
1173
|
multiple: !0,
|
|
1191
1174
|
...l ? { required: !0 } : {},
|
|
1192
1175
|
default: a ?? []
|
|
1193
|
-
}) :
|
|
1176
|
+
}) : L.string({
|
|
1194
1177
|
description: i,
|
|
1195
1178
|
alias: o,
|
|
1196
1179
|
...l ? { required: !0 } : {},
|
|
1197
1180
|
...a === void 0 ? {} : { default: a }
|
|
1198
|
-
}) : c ?
|
|
1181
|
+
}) : c ? I.string({
|
|
1199
1182
|
description: i,
|
|
1200
1183
|
multiple: !0,
|
|
1201
1184
|
...l ? { required: !0 } : {},
|
|
1202
1185
|
default: a ?? []
|
|
1203
|
-
}) :
|
|
1186
|
+
}) : I.string({
|
|
1204
1187
|
description: i,
|
|
1205
1188
|
...l ? { required: !0 } : {},
|
|
1206
1189
|
...a === void 0 ? {} : { default: a }
|
|
@@ -1210,7 +1193,7 @@ ${e.yellow("Available commands")}:
|
|
|
1210
1193
|
definition: u
|
|
1211
1194
|
};
|
|
1212
1195
|
}
|
|
1213
|
-
},
|
|
1196
|
+
}, Ae = class extends Z {
|
|
1214
1197
|
static signature = "";
|
|
1215
1198
|
static helperDefinitions = {};
|
|
1216
1199
|
static get command() {
|
|
@@ -1238,4 +1221,4 @@ ${e.yellow("Available commands")}:
|
|
|
1238
1221
|
}
|
|
1239
1222
|
};
|
|
1240
1223
|
//#endregion
|
|
1241
|
-
export {
|
|
1224
|
+
export { I as Args, x as BadCommandArgument, S as BadCommandFlag, g as BobError, ke as Cli, Z as Command, _ as CommandNotFoundError, T as CommandParser, Ee as CommandRegistry, $ as CommandSignatureParser, Ae as CommandWithSignature, De as ExceptionHandler, L as Flags, z as HelpCommandFlag, v as InvalidFlag, m as Logger, y as MissingRequiredArgumentValue, b as MissingRequiredFlagValue, h as StringSimilarity, C as TooManyArguments, X as UX, w as ValidationError, V as askForCheckbox, H as askForConfirmation, U as askForEditor, W as askForExpand, G as askForFileSelector, K as askForInput, q as askForList, J as askForNumber, _e as askForPassword, ve as askForRawList, ye as askForSearch, be as askForSelect, Y as askForToggle, xe as keyValue, Se as newLoader, Ce as newProgressBar, we as table, B as withCancelHandling };
|
|
@@ -27,11 +27,6 @@ export type FlagDefinition = FlagProps & {
|
|
|
27
27
|
parse(input: any, opts: ParameterOpts): any;
|
|
28
28
|
};
|
|
29
29
|
export type FlagType<O> = O extends {
|
|
30
|
-
type: 'option';
|
|
31
|
-
options: infer T extends readonly string[];
|
|
32
|
-
} ? O extends {
|
|
33
|
-
multiple: true;
|
|
34
|
-
} ? [T[number]] extends [Array<unknown>] ? T[number] : T[number][] : T[number] : O extends {
|
|
35
30
|
parse: (...args: any[]) => infer R;
|
|
36
31
|
} ? O extends {
|
|
37
32
|
multiple: true;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e={name:`bob-core`,version:`3.0.0-alpha.8`,description:`BOB Core`,type:`module`,main:`./dist/cjs/src/index.js`,module:`./dist/esm/src/index.js`,types:`./dist/esm/src/index.d.ts`,files:[`dist`],exports:{".":{import:{types:`./dist/esm/src/index.d.ts`,default:`./dist/esm/src/index.js`},require:{types:`./dist/cjs/src/index.d.ts`,default:`./dist/cjs/src/index.js`}}},scripts:{start:`node -r @swc-node/register debug/main.ts`,build:`rm -rf ./dist && vite build`,typecheck:`tsc --noEmit`,prepack:`npm run build`,test:`vitest run`,lint:`eslint .`,"lint:fix":`eslint . --fix`},author:`Léo Hubert`,license:`ISC`,devDependencies:{"@eslint/js":`^9.39.4`,"@faker-js/faker":`^10.3.0`,"@swc-node/register":`^1.11.1`,"@trivago/prettier-plugin-sort-imports":`^5.2.2`,"@types/minimist":`^1.2.5`,"@types/node":`^20.14.5`,"@types/string-similarity":`^4.0.2`,"@vitest/coverage-v8":`^4.1.0`,eslint:`^9.39.4`,"eslint-config-prettier":`^10.1.8`,"eslint-plugin-prettier":`^5.5.5`,prettier:`^3.6.2`,tsx:`^4.21.0`,typescript:`^5.9.3`,"typescript-eslint":`^8.57.0`,vite:`^8.0.0`,"vite-plugin-dts":`^4.5.4`,vitest:`^4.1.0`},dependencies:{"@inquirer/prompts":`^8.3.0`,chalk:`^4.1.2`,"inquirer-file-selector":`^1.0.1`,minimist:`^1.2.8`}};exports.default=e;
|