@longzai-intelligence-bun/cli 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -135,4 +135,4 @@ ${J.default.gray(Fa+Na.repeat(i+2)+Ia)}
135
135
  `);let d=0,f=0;p(),a=setInterval(()=>{if(r&&s===c)return;h(),c=s;let n=J.default.magenta(t[d]);if(r)process.stdout.write(`${n} ${s}...`);else if(e===`timer`)process.stdout.write(`${n} ${s} ${_(l)}`);else{let e=`.`.repeat(Math.floor(f)).slice(0,3);process.stdout.write(`${n} ${s}${e}`)}d=d+1<t.length?d+1:0,f=f<t.length?f+.125:0},n)},y=(t=``,n=0)=>{o=!1,clearInterval(a),h();let r=n===0?J.default.green(ka):n===1?J.default.red(Da):J.default.red(Oa);s=g(t??s),e===`timer`?process.stdout.write(`${r} ${s} ${_(l)}
136
136
  `):process.stdout.write(`${r} ${s}
137
137
  `),m(),i()};return{start:v,stop:y,message:(e=``)=>{s=g(e??s)}}},Ya={red:e=>J.default.red(e),green:e=>J.default.green(e),yellow:e=>J.default.yellow(e),blue:e=>J.default.blue(e),cyan:e=>J.default.cyan(e),magenta:e=>J.default.magenta(e),gray:e=>J.default.gray(e),bold:e=>J.default.bold(e),dim:e=>J.default.dim(e)},Xa={async select(e,t){let n=await Ga({message:e,options:t.map(e=>({value:e.value,label:e.label,hint:e.hint}))});return fa(n)&&(qa(`操作已取消`),process.exit(0)),typeof n==`string`?n:String(n)},async textInput(e,t){let n=await Ua({message:e,placeholder:t?.placeholder,defaultValue:t?.defaultValue});return fa(n)&&(qa(`操作已取消`),process.exit(0)),typeof n==`string`?n:String(n)},async confirm(e,t){let n=await Wa({message:e,initialValue:t?.defaultValue??!1});return fa(n)&&(qa(`操作已取消`),process.exit(0)),typeof n==`boolean`?n:!!n},spinner(){let e=Ja();return{start(t){e.start(t)},stop(t){e.stop(t)}}},note(e,t){Ka(e,t)},log:{info(e){$.info(J.default.blue(e))},success(e){$.success(J.default.green(e))},warn(e){$.warn(J.default.yellow(e))},error(e){$.error(J.default.red(e))},step(e){$.step(e)}}},Za=`@lzi-bun-cli generated, do not edit`;function Qa(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`}function $a(e){return`[${e.map(e=>Qa(e)).join(`, `)}]`}function eo(e){let t=[];return e.lines!==void 0&&t.push(`lines = ${e.lines}`),e.functions!==void 0&&t.push(`functions = ${e.functions}`),e.statements!==void 0&&t.push(`statements = ${e.statements}`),`{ ${t.join(`, `)} }`}function to(e,t){if(t!==void 0){if(typeof t==`boolean`||typeof t==`number`)return`${e} = ${t}`;if(typeof t==`string`)return`${e} = ${Qa(t)}`;if(Array.isArray(t))return t.length===0?void 0:`${e} = ${$a(t)}`}}function no(e){let t=e.test,n=[],r=to(`preload`,t.preload);r&&n.push(r);let i=to(`coverage`,t.coverage);i&&n.push(i);let a=to(`coverageSkipTestFiles`,t.coverageSkipTestFiles);a&&n.push(a);let o=to(`coverageReporter`,t.coverageReporter);o&&n.push(o);let s=to(`coverageDir`,t.coverageDir);s&&n.push(s);let c=to(`coveragePathIgnorePatterns`,t.coveragePathIgnorePatterns);c&&n.push(c),t.coverageThreshold!==void 0&&(typeof t.coverageThreshold==`number`?n.push(`coverageThreshold = ${t.coverageThreshold}`):n.push(`coverageThreshold = ${eo(t.coverageThreshold)}`));let l=to(`coverageIgnoreSourcemaps`,t.coverageIgnoreSourcemaps);l&&n.push(l);let u=to(`timeout`,t.timeout);return u&&n.push(u),`${`# ${Za}`}\n${`[test]\n${n.join(`
138
- `)}\n`}`}function ro(e){if(!e?.test)return null;let t=e.test;return t.coverage===void 0&&t.coverageThreshold===void 0&&t.coveragePathIgnorePatterns===void 0&&t.coverageReporter===void 0&&t.coverageSkipTestFiles===void 0&&t.coverageDir===void 0&&t.preload===void 0&&t.timeout===void 0?null:{content:no({test:t}),shouldWrite:!0}}function io(e){return e.map(e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `)}function ao(...e){process.stdout.write(`${io(e)}\n`)}function oo(...e){process.stderr.write(`${io(e)}\n`)}var so=class extends Error{configPath;constructor(e,t){super(e),this.name=`SharedConfigError`,this.configPath=t}},co=class extends so{searchFrom;constructor(e){super(`未在 ${e} 及其上级目录中找到 lzi.config.ts 配置文件`,e),this.name=`SharedConfigNotFoundError`,this.searchFrom=e}},lo=class extends so{cause;constructor(e,t){super(`加载配置文件 ${e} 失败`,e),this.name=`SharedConfigLoadError`,this.cause=t}};function uo(e=process.cwd()){let n=o(e);for(;;){let e=a(n,`lzi.config.ts`);if(t(e))return e;let r=i(n);if(r===n)return null;n=r}}async function fo(e={}){let t=e.cwd??process.cwd(),n=uo(t);if(n===null)throw new co(t);let r=o(n,`..`);try{return{config:(await import(n)).default,configPath:r,configFilePath:n}}catch(e){throw new lo(n,e)}}function po(e,n=process.cwd()){let r=Array.isArray(e)?e:[e],s=o(n);for(;;){for(let e of r){let n=a(s,e);if(t(n))return n}let e=i(s);if(e===s)return null;s=e}}async function mo(e={}){let t=e.cwd??o(process.cwd());if(e.standaloneFile){let n=po(e.standaloneFile,t);if(n)try{let e=await import(n);return{success:!0,config:e.default??e,source:`standalone`,configFilePath:n}}catch(e){throw new lo(n,e)}}if(e.unifiedField)try{let{config:n,configFilePath:r}=await fo({cwd:t}),i=n?.[e.unifiedField];if(i!==void 0)return{success:!0,config:i,source:`unified`,configFilePath:r}}catch{}return{success:!1,configFilePath:null}}const ho=async()=>{let e=await mo({standaloneFile:`lzi-bun.config.ts`,unifiedField:`bun`});return e.success?e.config:(ao(`提示: 未找到配置文件 lzi-bun.config.ts,使用默认配置`),{})},go=[`src/**/*.test.ts`,`src/**/*.test.tsx`,`__tests__/**/*.test.ts`];function _o(e){let t=[`bun`,`test`];return e.watch===!0&&t.push(`--watch`),e.coverage===!0&&t.push(`--coverage`),e.extra&&e.extra.length>0&&t.push(...e.extra),t}async function vo(e){let t=new Set;for(let n of e){let e=new Bun.Glob(n);for await(let n of e.scan({cwd:process.cwd(),onlyFiles:!0}))t.add(n)}return t.size}const yo=async e=>{let i=ro(e);if(!i?.shouldWrite)return;let o=a(process.cwd(),`bunfig.toml`);t(o)&&(n(o,`utf8`).includes(`@lzi-bun-cli generated, do not edit`)||(oo(`错误: ${o} 已存在且非 lzi-bun-cli 生成(缺少 ${Za} 标记)`),oo(`如需 lzi-bun-cli 接管,请删除该文件或手动合并后重试`),process.exit(1))),r(o,i.content,`utf8`),ao(`已生成 ${o}(lzi-bun-cli 接管覆盖率配置)`)},bo=async e=>{let t=await ho(),n=t.test?.passWithNoTests??!0;await vo(t.test?.include??go)===0&&(n&&(ao(`无测试文件,跳过(type-only / facade 包,passWithNoTests)`),process.exit(0)),oo(`错误: 未找到测试文件,且 test.passWithNoTests 为 false`),oo(`(如该包确为 type-only / facade 包,请在 lzi-dev.config.ts 设置 test.passWithNoTests: true)`),process.exit(1)),await yo(t);let r=_o(e),i=await Bun.spawn(r,{cwd:process.cwd(),stdout:`inherit`,stderr:`inherit`}).exited;i!==0&&process.exit(i)};function xo(e){So(e)}function So(e){Ni(e,{name:`test`,description:`运行 bun 测试(替代三件套,零测试包默认放行)`,options:[{flags:`--watch`,description:`监听模式(对应 test:watch)`},{flags:`--coverage`,description:`覆盖率(对应 test:coverage)`}],schema:Wr({watch:Ir().optional(),coverage:Ir().optional()}),action:async(e,t)=>{await bo({watch:e.watch===!0,coverage:e.coverage===!0,extra:t})}})}const Co=ki({name:`lzi-bun-cli`,description:`Longzai Intelligence bun 工具集`,interaction:Xa,color:Ya});xo(Co);async function wo(){await Co.parseAsync(process.argv)}wo().catch(e=>{process.stderr.write(`错误: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)});export{};
138
+ `)}\n`}`}function ro(e){if(!e?.test)return null;let t=e.test;return t.coverage===void 0&&t.coverageThreshold===void 0&&t.coveragePathIgnorePatterns===void 0&&t.coverageReporter===void 0&&t.coverageSkipTestFiles===void 0&&t.coverageDir===void 0&&t.preload===void 0&&t.timeout===void 0?null:{content:no({test:t}),shouldWrite:!0}}function io(e){return e.map(e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `)}function ao(...e){process.stdout.write(`${io(e)}\n`)}function oo(...e){process.stderr.write(`${io(e)}\n`)}var so=class extends Error{configPath;constructor(e,t){super(e),this.name=`SharedConfigError`,this.configPath=t}},co=class extends so{searchFrom;constructor(e){super(`未在 ${e} 及其上级目录中找到 lzi.config.ts 配置文件`,e),this.name=`SharedConfigNotFoundError`,this.searchFrom=e}},lo=class extends so{cause;constructor(e,t){super(`加载配置文件 ${e} 失败`,e),this.name=`SharedConfigLoadError`,this.cause=t}};function uo(e=process.cwd()){let n=o(e);for(;;){let e=a(n,`lzi.config.ts`);if(t(e))return e;let r=i(n);if(r===n)return null;n=r}}async function fo(e={}){let t=e.cwd??process.cwd(),n=uo(t);if(n===null)throw new co(t);let r=o(n,`..`);try{return{config:(await import(n)).default,configPath:r,configFilePath:n}}catch(e){throw new lo(n,e)}}function po(e,n=process.cwd()){let r=Array.isArray(e)?e:[e],s=o(n);for(;;){for(let e of r){let n=a(s,e);if(t(n))return n}let e=i(s);if(e===s)return null;s=e}}async function mo(e={}){let t=e.cwd??o(process.cwd());if(e.standaloneFile){let n=po(e.standaloneFile,t);if(n)try{let e=await import(n);return{success:!0,config:e.default??e,source:`standalone`,configFilePath:n}}catch(e){throw new lo(n,e)}}if(e.unifiedField)try{let{config:n,configFilePath:r}=await fo({cwd:t}),i=n?.[e.unifiedField];if(i!==void 0)return{success:!0,config:i,source:`unified`,configFilePath:r}}catch{}return{success:!1,configFilePath:null}}const ho=async()=>{let e=await mo({standaloneFile:`lzi-bun.config.ts`,unifiedField:`bun`});return e.success?e.config:(ao(`提示: 未找到配置文件 lzi-bun.config.ts,使用默认配置`),{})},go=[`src/**/*.test.ts`,`src/**/*.test.tsx`,`__tests__/**/*.test.ts`];function _o(e){let t=[`bun`,`test`];return e.watch===!0&&t.push(`--watch`),e.coverage===!0&&t.push(`--coverage`),e.extra&&e.extra.length>0&&t.push(...e.extra),t}async function vo(e){let t=new Set;for(let n of e){let e=new Bun.Glob(n);for await(let n of e.scan({cwd:process.cwd(),onlyFiles:!0}))t.add(n)}return t.size}const yo=async(e,i=!1)=>{let o=ro(e);if(!o?.shouldWrite){i&&ao(`(无 coverage 配置,不会生成 bunfig.toml)`);return}let s=a(process.cwd(),`bunfig.toml`);if(i){ao(`[dry-run] 将写入 ${s}:`),ao(o.content);return}t(s)&&(n(s,`utf8`).includes(`@lzi-bun-cli generated, do not edit`)||(oo(`错误: ${s} 已存在且非 lzi-bun-cli 生成(缺少 ${Za} 标记)`),oo(`如需 lzi-bun-cli 接管,请删除该文件或手动合并后重试`),process.exit(1))),r(s,o.content,`utf8`),ao(`已生成 ${s}(lzi-bun-cli 接管覆盖率配置)`)},bo=async e=>{let t=await ho(),n=t.test?.passWithNoTests??!0;await vo(t.test?.include??go)===0&&(n&&(ao(`无测试文件,跳过(type-only / facade 包,passWithNoTests)`),process.exit(0)),oo(`错误: 未找到测试文件,且 test.passWithNoTests 为 false`),oo(`(如该包确为 type-only / facade 包,请在 lzi-dev.config.ts 设置 test.passWithNoTests: true)`),process.exit(1)),await yo(t);let r=_o(e),i=await Bun.spawn(r,{cwd:process.cwd(),stdout:`inherit`,stderr:`inherit`}).exited;i!==0&&process.exit(i)},xo=async e=>{let t=await ho();await yo(t,e.dryRun===!0)};function So(e){Co(e),wo(e)}function Co(e){Ni(e,{name:`test`,description:`运行 bun 测试(替代三件套,零测试包默认放行)`,options:[{flags:`--watch`,description:`监听模式(对应 test:watch)`},{flags:`--coverage`,description:`覆盖率(对应 test:coverage)`}],schema:Wr({watch:Ir().optional(),coverage:Ir().optional()}),action:async(e,t)=>{await bo({watch:e.watch===!0,coverage:e.coverage===!0,extra:t})}})}function wo(e){Ni(e,{name:`generate`,description:`生成 bunfig.toml(不执行测试,支持 --dry-run 预览)`,options:[{flags:`--dry-run`,description:`仅预览将写入的内容,不写盘`}],schema:Wr({dryRun:Ir().optional()}),action:async e=>{await xo({dryRun:e.dryRun===!0})}})}const To=ki({name:`lzi-bun-cli`,description:`Longzai Intelligence bun 工具集`,interaction:Xa,color:Ya});So(To);async function Eo(){await To.parseAsync(process.argv)}Eo().catch(e=>{process.stderr.write(`错误: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)});export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-bun/cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Longzai Intelligence bun 工具集 CLI",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -33,7 +33,7 @@
33
33
  "test:coverage": "bun test --coverage"
34
34
  },
35
35
  "dependencies": {
36
- "@longzai-intelligence-bun/config": "0.0.2",
36
+ "@longzai-intelligence-bun/config": "0.0.3",
37
37
  "@longzai-intelligence-cli/core": "^0.0.10",
38
38
  "@longzai-intelligence-cli/standard": "^0.0.10",
39
39
  "@longzai-intelligence-shared-config/core": "^0.0.5",