@longzai-intelligence-cli/core 0.0.3 → 0.0.4

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-BqT_7tdF.js";
2
- import { Command } from "commander";
2
+ import { Command, Command as Command$1 } from "commander";
3
3
  import * as z from "zod";
4
4
  //#region src/contracts.d.ts
5
5
  /**
@@ -281,7 +281,7 @@ type CreateCliOptions = {
281
281
  * @param options - 工厂配置
282
282
  * @returns commander Command 实例
283
283
  */
284
- declare function createCli(options: CreateCliOptions): Command;
284
+ declare function createCli(options: CreateCliOptions): Command$1;
285
285
  //#endregion
286
286
  //#region src/version.d.ts
287
287
  /**
@@ -567,6 +567,6 @@ type CommandSpec<T extends z.ZodType> = {
567
567
  * @param program - commander Command 实例
568
568
  * @param spec - 命令参数规格
569
569
  */
570
- declare function defineCommand<T extends z.ZodType>(program: Command, spec: CommandSpec<T>): void;
570
+ declare function defineCommand<T extends z.ZodType>(program: Command$1, spec: CommandSpec<T>): void;
571
571
  //#endregion
572
- export { type ColorProvider, type CommandSpec, type ConfirmOptions, type CreateCliOptions, type InteractionProvider, type LogToolset, type OptionDecl, type OutputFormat, OutputFormatter, type ProgressController, type SelectOption, type SpinnerController, type TextInputOptions, confirm, createCli, defineCommand, getCliVersion, getColorProvider, getInteractionProvider, log, note, parseOutputFormat, progressBar, select, setColorProvider, setInteractionProvider, spinner, textInput };
572
+ export { type ColorProvider, type Command, type CommandSpec, type ConfirmOptions, type CreateCliOptions, type InteractionProvider, type LogToolset, type OptionDecl, type OutputFormat, OutputFormatter, type ProgressController, type SelectOption, type SpinnerController, type TextInputOptions, confirm, createCli, defineCommand, getCliVersion, getColorProvider, getInteractionProvider, log, note, parseOutputFormat, progressBar, select, setColorProvider, setInteractionProvider, spinner, textInput };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import"./rolldown-runtime-BqT_7tdF.js";import{createNodeLogger as e}from"@longzai-intelligence-logger/node";import{Command as t}from"commander";import"node:fs";import"node:path";import"node:url";const n=e(`@longzai-intelligence-cli/core/provider`),r={red:e=>e,green:e=>e,yellow:e=>e,blue:e=>e,bold:e=>e,gray:e=>e};let i={select:async(e,t)=>t[0]?.value??``,textInput:async(e,t)=>t?.defaultValue??``,confirm:async(e,t)=>t?.defaultValue??!1,spinner:()=>({start:e=>n.info(e),stop:e=>n.info(e)}),note:(e,t)=>{t?n.info(`${t}: ${e}`):n.info(e)},log:{info:e=>n.info(e),success:e=>n.info(e),warn:e=>n.warn(e),error:e=>n.error(e),step:e=>n.info(e)}},a=r;function o(e){i=e}function s(e){a=e}function c(){return i}function l(){return a}const u=()=>`0.0.3`;function d(e){let n=e.version??u();e.interaction&&o(e.interaction),e.color&&s(e.color);let r=new t;return r.name(e.name).version(n,`-v, --version`,`输出 ${e.name} 的版本号`),e.description&&r.description(e.description),r}const f=e(`@longzai-intelligence-cli/core/output`);var p=class{format;constructor(e=`text`){this.format=e}get colors(){return l()}success(e,t){this.format===`json`?f.info(JSON.stringify({success:!0,data:e},null,2)):f.info(t?this.colors.green(t):this.colors.green(this.formatData(e)))}error(e){if(this.format===`json`){let t=e instanceof Error?{message:e.message,name:e.name}:{message:String(e)};f.info(JSON.stringify({success:!1,error:t},null,2))}else{let t=e instanceof Error?e.message:String(e);f.error(this.colors.red(`错误: ${t}`))}}info(e){this.format===`json`?f.info(JSON.stringify({success:!0,message:e},null,2)):f.info(this.colors.blue(e))}warn(e){this.format===`json`?f.info(JSON.stringify({success:!0,warning:e},null,2)):f.info(this.colors.yellow(e))}table(e,t){if(this.format===`json`){let n=t.map(t=>{let n={};return e.forEach((e,r)=>{n[e]=t[r]??``}),n});f.info(JSON.stringify({success:!0,data:n},null,2))}else{let n=e.map((e,n)=>Math.max(e.length,...t.map(e=>(e[n]??``).length)));f.info(e.map((e,t)=>this.colors.bold(e.padEnd(n[t]??0))).join(` `)),f.info(n.map(e=>`-`.repeat(e??0)).join(` `));for(let e of t)f.info(e.map((e,t)=>(e??``).padEnd(n[t]??0)).join(` `))}}formatData(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e,null,2)}};function m(e){return e===`json`?`json`:`text`}async function h(e,t){return c().select(e,t)}async function g(e,t){return c().textInput(e,t)}async function _(e,t){return c().confirm(e,t)}function v(){return c().spinner()}function y(e,t){c().note(e,t)}const b={info(e){c().log.info(e)},success(e){c().log.success(e)},warn(e){c().log.warn(e)},error(e){c().log.error(e)},step(e){c().log.step(e)}},x=e(`@longzai-intelligence-cli/core/progress`);function S(e=100){let t=-1;return{update(e,n){let r=Math.max(0,Math.min(100,e)),i=Math.round(r/100*30),a=`█`.repeat(i)+`░`.repeat(30-i);if(e!==t){t=e;let i=n?` ${n}`:``;process.stdout.write(`\r${l().blue(a)} ${r.toFixed(0)}%${i}`),r>=100&&process.stdout.write(`
1
+ import"./rolldown-runtime-BqT_7tdF.js";import{createNodeLogger as e}from"@longzai-intelligence-logger/node";import{Command as t}from"commander";import"node:fs";import"node:path";import"node:url";const n=e(`@longzai-intelligence-cli/core/provider`),r={red:e=>e,green:e=>e,yellow:e=>e,blue:e=>e,bold:e=>e,gray:e=>e};let i={select:async(e,t)=>t[0]?.value??``,textInput:async(e,t)=>t?.defaultValue??``,confirm:async(e,t)=>t?.defaultValue??!1,spinner:()=>({start:e=>n.info(e),stop:e=>n.info(e)}),note:(e,t)=>{t?n.info(`${t}: ${e}`):n.info(e)},log:{info:e=>n.info(e),success:e=>n.info(e),warn:e=>n.warn(e),error:e=>n.error(e),step:e=>n.info(e)}},a=r;function o(e){i=e}function s(e){a=e}function c(){return i}function l(){return a}const u=()=>`0.0.4`;function d(e){let n=e.version??u();e.interaction&&o(e.interaction),e.color&&s(e.color);let r=new t;return r.name(e.name).version(n,`-v, --version`,`输出 ${e.name} 的版本号`),e.description&&r.description(e.description),r}const f=e(`@longzai-intelligence-cli/core/output`);var p=class{format;constructor(e=`text`){this.format=e}get colors(){return l()}success(e,t){this.format===`json`?f.info(JSON.stringify({success:!0,data:e},null,2)):f.info(t?this.colors.green(t):this.colors.green(this.formatData(e)))}error(e){if(this.format===`json`){let t=e instanceof Error?{message:e.message,name:e.name}:{message:String(e)};f.info(JSON.stringify({success:!1,error:t},null,2))}else{let t=e instanceof Error?e.message:String(e);f.error(this.colors.red(`错误: ${t}`))}}info(e){this.format===`json`?f.info(JSON.stringify({success:!0,message:e},null,2)):f.info(this.colors.blue(e))}warn(e){this.format===`json`?f.info(JSON.stringify({success:!0,warning:e},null,2)):f.info(this.colors.yellow(e))}table(e,t){if(this.format===`json`){let n=t.map(t=>{let n={};return e.forEach((e,r)=>{n[e]=t[r]??``}),n});f.info(JSON.stringify({success:!0,data:n},null,2))}else{let n=e.map((e,n)=>Math.max(e.length,...t.map(e=>(e[n]??``).length)));f.info(e.map((e,t)=>this.colors.bold(e.padEnd(n[t]??0))).join(` `)),f.info(n.map(e=>`-`.repeat(e??0)).join(` `));for(let e of t)f.info(e.map((e,t)=>(e??``).padEnd(n[t]??0)).join(` `))}}formatData(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e,null,2)}};function m(e){return e===`json`?`json`:`text`}async function h(e,t){return c().select(e,t)}async function g(e,t){return c().textInput(e,t)}async function _(e,t){return c().confirm(e,t)}function v(){return c().spinner()}function y(e,t){c().note(e,t)}const b={info(e){c().log.info(e)},success(e){c().log.success(e)},warn(e){c().log.warn(e)},error(e){c().log.error(e)},step(e){c().log.step(e)}},x=e(`@longzai-intelligence-cli/core/progress`);function S(e=100){let t=-1;return{update(e,n){let r=Math.max(0,Math.min(100,e)),i=Math.round(r/100*30),a=`█`.repeat(i)+`░`.repeat(30-i);if(e!==t){t=e;let i=n?` ${n}`:``;process.stdout.write(`\r${l().blue(a)} ${r.toFixed(0)}%${i}`),r>=100&&process.stdout.write(`
2
2
  `)}},done(e){process.stdout.write(`
3
3
  `),e&&x.info(l().green(`✓ ${e}`))}}}const C=e(`@longzai-intelligence-cli/core/define-command`);function w(e,n){let r=e.command(n.name);n.description&&r.description(n.description);for(let e of n.arguments??[])e.description?r.argument(e.signature,e.description):r.argument(e.signature);for(let e of n.options??[])e.defaultValue===void 0?r.option(e.flags,e.description??``):r.option(e.flags,e.description??``,e.defaultValue);r.action(async(...e)=>{let r=e[e.length-1];if(!(r instanceof t))return;let i=r.opts(),a=r.args,o=n.schema.safeParse(i);if(!o.success){let e=o.error.issues.map(e=>e.message).join(`, `);C.error(l().red(`参数校验失败: ${e}`)),c().log.error(`参数校验失败: ${e}`),process.exit(1)}await n.action(o.data,a)})}export{p as OutputFormatter,_ as confirm,d as createCli,w as defineCommand,u as getCliVersion,l as getColorProvider,c as getInteractionProvider,b as log,y as note,m as parseOutputFormat,S as progressBar,h as select,s as setColorProvider,o as setInteractionProvider,v as spinner,g as textInput};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-cli/core",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "cli",