@longzai-intelligence-cli/core 0.0.11 → 0.0.13
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.js +2 -2
- package/package.json +2 -2
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{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s}from"node:path";import{fileURLToPath as c}from"node:url";import*as l from"zod";
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{createNodeLogger as e}from"@longzai-intelligence-logger/node";import{Command as t}from"commander";import{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{dirname as o,join as s}from"node:path";import{fileURLToPath as c}from"node:url";import*as l from"zod";let u;function d(){return u??=e(`@longzai-intelligence-cli/core/provider`),u}const f={red:e=>e,green:e=>e,yellow:e=>e,blue:e=>e,cyan:e=>e,magenta:e=>e,gray:e=>e,bold:e=>e,dim:e=>e};let p={select:async(e,t)=>t[0]?.value??``,textInput:async(e,t)=>t?.defaultValue??``,confirm:async(e,t)=>t?.defaultValue??!1,spinner:()=>({start:e=>d().info(e),stop:e=>d().info(e)}),note:(e,t)=>{t?d().info(`${t}: ${e}`):d().info(e)},log:{info:e=>d().info(e),success:e=>d().info(e),warn:e=>d().warn(e),error:e=>d().error(e),step:e=>d().info(e)}},m=f;function h(e){p=e}function g(e){m=e}function _(){return p}function v(){return m}function y(e){return typeof e==`object`&&!!e&&(!(`name`in e)||typeof e.name==`string`)&&`version`in e&&typeof e.version==`string`}const b=()=>{let e=process.env.CLI_VERSION;if(typeof e==`string`&&e.length>0)return e;try{let e=s(o(c(import.meta.url)),`..`,`package.json`),t=JSON.parse(i(e,`utf-8`));if(y(t)&&t.name===`@longzai-intelligence-cli/core`)return t.version}catch{}return`0.0.0`};function x(e){let n=e.version??b();e.interaction&&h(e.interaction),e.color&&g(e.color);let r=new t;return r.name(e.name).version(n,`-v, --version`,`输出 ${e.name} 的版本号`),e.description&&r.description(e.description),r}let S;function C(){return S??=e(`@longzai-intelligence-cli/core/output`),S}var w=class{format;constructor(e=`text`){this.format=e}get colors(){return v()}success(e,t){this.format===`json`?C().info(JSON.stringify({success:!0,data:e},null,2)):C().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)};C().info(JSON.stringify({success:!1,error:t},null,2))}else{let t=e instanceof Error?e.message:String(e);C().error(this.colors.red(`错误: ${t}`))}}info(e){this.format===`json`?C().info(JSON.stringify({success:!0,message:e},null,2)):C().info(this.colors.blue(e))}warn(e){this.format===`json`?C().info(JSON.stringify({success:!0,warning:e},null,2)):C().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});C().info(JSON.stringify({success:!0,data:n},null,2))}else{let n=e.map((e,n)=>Math.min(60,Math.max(e.length,...t.map(e=>(e[n]??``).length))));C().info(e.map((e,t)=>this.colors.bold(e.padEnd(n[t]??0))).join(` `)),C().info(n.map(e=>`─`.repeat(e??0)).join(` `));for(let e of t)C().info(e.map((e,t)=>{let r=n[t]??0,i=e??``;return i.length>r?i.slice(0,Math.max(0,r-1))+`…`:i.padEnd(r)}).join(` `))}}formatData(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e,null,2)}};function T(e){return e===`json`?`json`:`text`}async function E(e,t){return _().select(e,t)}async function D(e,t){return _().textInput(e,t)}async function O(e,t){return _().confirm(e,t)}function k(){return _().spinner()}function A(e,t){_().note(e,t)}const j={info(e){_().log.info(e)},success(e){_().log.success(e)},warn(e){_().log.warn(e)},error(e){_().log.error(e)},step(e){_().log.step(e)}};let M;function N(){return M??=e(`@longzai-intelligence-cli/core/progress`),M}function P(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${v().blue(a)} ${r.toFixed(0)}%${i}`),r>=100&&process.stdout.write(`
|
|
2
2
|
`)}},done(e){process.stdout.write(`
|
|
3
|
-
`),e&&
|
|
3
|
+
`),e&&N().info(v().green(`✓ ${e}`))}}}const F={debug:`gray`,error:`red`,fatal:`red`,info:`green`,trace:`gray`,warn:`yellow`};function I(e){try{return new Date(e).toLocaleString(`zh-CN`,{day:`2-digit`,hour:`2-digit`,hour12:!1,minute:`2-digit`,month:`2-digit`,second:`2-digit`,year:`numeric`})}catch{return e}}function L(e){let t=e.toLowerCase(),n=e.toUpperCase().padEnd(5),r=F[t]??`green`;return v()[r](n)}function R(e){let t=v(),n=[];return e.timestamp!==void 0&&n.push(t.gray(I(e.timestamp))),n.push(L(e.level??`info`)),e.serviceName!==void 0&&e.serviceName!==``&&n.push(t.blue(`[${e.serviceName}]`)),n.push(e.message??String(e.message??``)),e.metadata!==void 0&&typeof e.metadata==`object`&&Object.keys(e.metadata).length>0&&n.push(t.gray(JSON.stringify(e.metadata))),n.join(` `)}function z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function B(e,t=``){let n={};for(let[r,i]of Object.entries(e)){let e=t===``?r:`${t}.${r}`;z(i)?Object.assign(n,B(i,e)):n[e]=String(i??``)}return n}const V=l.array(l.unknown());function H(e){return V.safeParse(e).success}var U=class{filePath;constructor(e){this.filePath=e;let t=o(e);n(t)||r(t,{recursive:!0}),n(e)||a(e,`[]`,`utf-8`)}read(){try{let e=i(this.filePath,`utf-8`),t=JSON.parse(e);return H(t)?t:[]}catch{return[]}}write(e){let t=o(this.filePath);n(t)||r(t,{recursive:!0}),a(this.filePath,JSON.stringify(e,null,2),`utf-8`)}add(e){let t=this.read();t.push(e),this.write(t)}find(e){return this.read().find(e)}remove(e){let t=this.read(),n=t.filter(t=>!e(t));return n.length!==t.length&&(this.write(n),!0)}update(e,t){let n=this.read(),r=!1,i=n.map(n=>e(n)?(r=!0,t(n)):n);return r&&this.write(i),r}};function W(e){return`${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}let G;function K(){return G??=e(`@longzai-intelligence-cli/core/define-command`),G}function q(e,t){let n=e.commands.find(e=>e.name()===t);return n===void 0?e.command(t):n}function J(e,t){if(t.length===1){let n=t[0];if(n===void 0)throw Error(`defineCommand: segments 为空,无法解析命令名`);return e.command(n)}let[n,...r]=t;if(n===void 0)throw Error(`defineCommand: segments 首段为空,无法解析父命令名`);let i=r.pop();if(i===void 0)throw Error(`defineCommand: segments 末段为空,无法解析子命令名`);let a=q(e,n);for(let e of r)a=q(a,e);return a.command(i)}function Y(e,n){let r=J(e,n.name.split(` `).filter(e=>e.length>0));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(`, `);K().error(v().red(`参数校验失败: ${e}`)),_().log.error(`参数校验失败: ${e}`),process.exit(1)}await n.action(o.data,a)})}export{U as JsonStorage,w as OutputFormatter,O as confirm,x as createCli,Y as defineCommand,B as flattenObject,L as formatLevel,R as formatLogEntry,I as formatTimestamp,W as generateId,b as getCliVersion,v as getColorProvider,_ as getInteractionProvider,j as log,A as note,T as parseOutputFormat,P as progressBar,q as resolveCommandParent,E as select,g as setColorProvider,h as setInteractionProvider,k as spinner,D as textInput};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-cli/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Longzai Intelligence CLI 核心契约与平台无关能力",
|
|
6
6
|
"keywords": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@longzai-intelligence-builder/utils": "^0.2.13",
|
|
43
|
-
"@longzai-intelligence-logger/node": "^0.1.
|
|
43
|
+
"@longzai-intelligence-logger/node": "^0.1.7",
|
|
44
44
|
"commander": "^14.0.0",
|
|
45
45
|
"zod": "^4.4.3"
|
|
46
46
|
},
|