@longzai-intelligence-bun/cli 0.0.5 → 0.0.7

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 +8 -2
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -134,5 +134,11 @@ ${K.default.gray(La+Fa.repeat(i+2)+Ra)}
134
134
  `);process.stdout.write(G.cursor.move(-999,e.length-1)),process.stdout.write(G.erase.down(e.length))},g=e=>e.replace(/\.+$/,``),_=e=>{let t=(performance.now()-e)/1e3,n=Math.floor(t/60),r=Math.floor(t%60);return n>0?`[${n}m ${r}s]`:`[${r}s]`},v=(u=``)=>{o=!0,i=ga(),s=g(u),l=performance.now(),process.stdout.write(`${K.default.gray(X)}
135
135
  `);let d=0,f=0;p(),a=setInterval(()=>{if(r&&s===c)return;h(),c=s;let n=K.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?K.default.green(ja):n===1?K.default.red(ka):K.default.red(Aa);s=g(t??s),e===`timer`?process.stdout.write(`${r} ${s} ${_(l)}
136
136
  `):process.stdout.write(`${r} ${s}
137
- `),m(),i()};return{start:v,stop:y,message:(e=``)=>{s=g(e??s)}}},Za={red:e=>K.default.red(e),green:e=>K.default.green(e),yellow:e=>K.default.yellow(e),blue:e=>K.default.blue(e),cyan:e=>K.default.cyan(e),magenta:e=>K.default.magenta(e),gray:e=>K.default.gray(e),bold:e=>K.default.bold(e),dim:e=>K.default.dim(e)},Qa={async select(e,t){let n=await qa({message:e,options:t.map(e=>({value:e.value,label:e.label,hint:e.hint}))});return ma(n)&&(Ya(`操作已取消`),process.exit(0)),typeof n==`string`?n:String(n)},async textInput(e,t){let n=await Ga({message:e,placeholder:t?.placeholder,defaultValue:t?.defaultValue});return ma(n)&&(Ya(`操作已取消`),process.exit(0)),typeof n==`string`?n:String(n)},async confirm(e,t){let n=await Ka({message:e,initialValue:t?.defaultValue??!1});return ma(n)&&(Ya(`操作已取消`),process.exit(0)),typeof n==`boolean`?n:!!n},spinner(){let e=Xa();return{start(t){e.start(t)},stop(t){e.stop(t)}}},note(e,t){Ja(e,t)},log:{info(e){Z.info(K.default.blue(e))},success(e){Z.success(K.default.green(e))},warn(e){Z.warn(K.default.yellow(e))},error(e){Z.error(K.default.red(e))},step(e){Z.step(e)}}};var $a=class extends Error{configPath;constructor(e,t){super(e),this.name=`SharedConfigError`,this.configPath=t}},eo=class extends $a{cause;constructor(e,t){super(`加载配置文件 ${e} 失败`,e),this.name=`SharedConfigLoadError`,this.cause=t}},to=class extends $a{searchFrom;constructor(e){super(`未在 ${e} 及其上级目录中找到 lzi.config.ts 配置文件`,e),this.name=`SharedConfigNotFoundError`,this.searchFrom=e}};const no=[`packages/*`,`apps/*`];function ro(e){let r=o(e,`package.json`);if(!t(r))throw new to(e);let i;try{i=JSON.parse(n(r,`utf8`)).workspaces}catch(e){throw new eo(r,e)}let a=Array.isArray(i)?i:i?.packages;return a&&a.length>0?a:no}async function io(e,r={}){let i=ro(e),a=new Set,s=[];for(let c of i){let i=new Bun.Glob(`${c}/package.json`);for await(let c of i.scan({cwd:e,absolute:!0,onlyFiles:!0})){let e=o(c,`..`);if(a.has(e))continue;let i;try{i=JSON.parse(n(c,`utf8`))}catch{continue}typeof i.name==`string`&&i.name.length!==0&&(r.configFileName!==void 0&&!t(o(e,r.configFileName))||(a.add(e),s.push({name:i.name,dir:e})))}}return s}function ao(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 oo(e={}){let t=e.cwd??process.cwd(),n=ao(t);if(n===null)throw new to(t);let r=o(n,`..`);try{return{config:(await import(n)).default,configPath:r,configFilePath:n}}catch(e){throw new eo(n,e)}}function so(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 co(e={}){let t=e.cwd??o(process.cwd());if(e.standaloneFile){let n=so(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 eo(n,e)}}if(e.unifiedField)try{let{config:n,configFilePath:r}=await oo({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}}var lo=class extends Error{bunfigPath;constructor(e){super(`${e} 已存在且非 lzi-bun-cli 生成(缺少 @lzi-bun-cli generated, do not edit 标记),如需 lzi-bun-cli 接管,请删除该文件或手动合并后重试`),this.name=`BunfigProtectedError`,this.bunfigPath=e}};function uo(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`}function fo(e){return`[${e.map(e=>uo(e)).join(`, `)}]`}function po(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 mo(e,t){if(t!==void 0){if(typeof t==`boolean`||typeof t==`number`)return`${e} = ${t}`;if(typeof t==`string`)return`${e} = ${uo(t)}`;if(Array.isArray(t))return t.length===0?void 0:`${e} = ${fo(t)}`}}function ho(e){let t=e.test,n=[],r=mo(`preload`,t.preload);r&&n.push(r);let i=mo(`coverage`,t.coverage);i&&n.push(i);let a=mo(`coverageSkipTestFiles`,t.coverageSkipTestFiles);a&&n.push(a);let o=mo(`coverageReporter`,t.coverageReporter);o&&n.push(o);let s=mo(`coverageDir`,t.coverageDir);s&&n.push(s);let c=mo(`coveragePathIgnorePatterns`,t.coveragePathIgnorePatterns);c&&n.push(c),t.coverageThreshold!==void 0&&(typeof t.coverageThreshold==`number`?n.push(`coverageThreshold = ${t.coverageThreshold}`):n.push(`coverageThreshold = ${po(t.coverageThreshold)}`));let l=mo(`coverageIgnoreSourcemaps`,t.coverageIgnoreSourcemaps);l&&n.push(l);let u=mo(`timeout`,t.timeout);return u&&n.push(u),`# @lzi-bun-cli generated, do not edit\n${`[test]\n${n.join(`
138
- `)}\n`}`}function go(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:ho({test:t}),shouldWrite:!0}}function _o(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 Q(...e){process.stdout.write(`${_o(e)}\n`)}function $(...e){process.stderr.write(`${_o(e)}\n`)}const vo=async(e=process.cwd())=>{let t=await co({cwd:e,standaloneFile:`lzi-bun.config.ts`,unifiedField:`bun`});return t.success?t.config:(Q(`提示: 未找到配置文件 lzi-bun.config.ts,使用默认配置`),{})},yo=[`src/**/*.test.ts`,`src/**/*.test.tsx`,`__tests__/**/*.test.ts`];function bo(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 xo(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 So=async(e,i={})=>{let o=a(i.dir??process.cwd(),`bunfig.toml`),s=go(e);if(!s?.shouldWrite)return i.dryRun&&Q(`(无 coverage 配置,不会生成 bunfig.toml)`),{status:`skipped`,bunfigPath:o};if(i.dryRun)return Q(`[dry-run] 将写入 ${o}:`),Q(s.content),{status:`generated`,bunfigPath:o};if(t(o)&&!n(o,`utf8`).includes(`@lzi-bun-cli generated, do not edit`))throw new lo(o);return r(o,s.content,`utf8`),Q(`已生成 ${o}(lzi-bun-cli 接管覆盖率配置)`),{status:`generated`,bunfigPath:o}},Co=async e=>{let t=await vo(),n=t.test?.passWithNoTests??!0;await xo(t.test?.include??yo)===0&&(n&&(Q(`无测试文件,跳过(type-only / facade 包,passWithNoTests)`),process.exit(0)),$(`错误: 未找到测试文件,且 test.passWithNoTests 为 false`),$(`(如该包确为 type-only / facade 包,请在 lzi-dev.config.ts 设置 test.passWithNoTests: true)`),process.exit(1));try{await So(t)}catch(e){throw e instanceof lo&&($(`错误: ${e.message}`),process.exit(1)),e}let r=bo(e),i=await Bun.spawn(r,{cwd:process.cwd(),stdout:`inherit`,stderr:`inherit`}).exited;i!==0&&process.exit(i)},wo=async e=>{let t=await vo();try{await So(t,{dryRun:e})}catch(e){throw e instanceof lo&&($(`错误: ${e.message}`),process.exit(1)),e}},To=e=>{let r=o(e,`package.json`);t(r)||($(`错误: 当前目录 ${e} 无 package.json,--recursive 须在 monorepo root 执行`),process.exit(1));let i;try{i=JSON.parse(n(r,`utf8`)).workspaces}catch{i=void 0}Array.isArray(i)||typeof i==`object`&&i&&`packages`in i||($(`错误: ${e} 的 package.json 未声明 workspaces 字段,--recursive 须在 monorepo root 执行`),process.exit(1))},Eo=async e=>{let t=process.cwd();To(t);let n=await io(t,{configFileName:`lzi-bun.config.ts`});n.length===0&&(Q(`未发现含 lzi-bun.config.ts 的子包,无可生成的目标`),process.exit(0)),Q(`发现 ${n.length} 个含 lzi-bun.config.ts 的子包,开始${e?`预览`:`生成`}...`);let r=[];for(let t of n){Q(`▶ ${t.name}`);try{let n=await vo(t.dir),{status:i}=await So(n,{dryRun:e,dir:t.dir});r.push({name:t.name,dir:t.dir,status:i})}catch(e){r.push({name:t.name,dir:t.dir,status:`failed`,reason:e instanceof Error?e.message:String(e)})}}let i=r.filter(e=>e.status===`generated`),a=r.filter(e=>e.status===`skipped`),o=r.filter(e=>e.status===`failed`);if(Q(``),Q(`汇总:${i.length} 生成 / ${a.length} 跳过 / ${o.length} 失败`),o.length>0){$(``),$(`失败子包:`);for(let e of o)$(` - ${e.name}:${e.reason}`);process.exitCode=1}},Do=async e=>{let t=e.dryRun===!0;if(e.recursive===!0){await Eo(t);return}await wo(t)};function Oo(e){ko(e),Ao(e)}function ko(e){Fi(e,{name:`test`,description:`运行 bun 测试(替代三件套,零测试包默认放行)`,options:[{flags:`--watch`,description:`监听模式(对应 test:watch)`},{flags:`--coverage`,description:`覆盖率(对应 test:coverage)`}],schema:Kr({watch:Rr().optional(),coverage:Rr().optional()}),action:async(e,t)=>{await Co({watch:e.watch===!0,coverage:e.coverage===!0,extra:t})}})}function Ao(e){Fi(e,{name:`config generate`,description:`生成 bunfig.toml(不执行测试,支持 --dry-run 预览、-r 批量)`,options:[{flags:`--dry-run`,description:`仅预览将写入的内容,不写盘`},{flags:`-r, --recursive`,description:`递归处理 monorepo 下含 lzi-bun.config.ts 的子包`}],schema:Kr({dryRun:Rr().optional(),recursive:Rr().optional()}),action:async e=>{await Do({dryRun:e.dryRun===!0,recursive:e.recursive===!0})}})}const jo=ji({name:`lzi-bun-cli`,description:`Longzai Intelligence bun 工具集`,interaction:Qa,color:Za});Oo(jo);async function Mo(){await jo.parseAsync(process.argv)}Mo().catch(e=>{process.stderr.write(`错误: ${e instanceof Error?e.message:String(e)}\n`),process.exit(1)});export{};
137
+ `),m(),i()};return{start:v,stop:y,message:(e=``)=>{s=g(e??s)}}},Za={red:e=>K.default.red(e),green:e=>K.default.green(e),yellow:e=>K.default.yellow(e),blue:e=>K.default.blue(e),cyan:e=>K.default.cyan(e),magenta:e=>K.default.magenta(e),gray:e=>K.default.gray(e),bold:e=>K.default.bold(e),dim:e=>K.default.dim(e)},Qa={async select(e,t){let n=await qa({message:e,options:t.map(e=>({value:e.value,label:e.label,hint:e.hint}))});return ma(n)&&(Ya(`操作已取消`),process.exit(0)),typeof n==`string`?n:String(n)},async textInput(e,t){let n=await Ga({message:e,placeholder:t?.placeholder,defaultValue:t?.defaultValue});return ma(n)&&(Ya(`操作已取消`),process.exit(0)),typeof n==`string`?n:String(n)},async confirm(e,t){let n=await Ka({message:e,initialValue:t?.defaultValue??!1});return ma(n)&&(Ya(`操作已取消`),process.exit(0)),typeof n==`boolean`?n:!!n},spinner(){let e=Xa();return{start(t){e.start(t)},stop(t){e.stop(t)}}},note(e,t){Ja(e,t)},log:{info(e){Z.info(K.default.blue(e))},success(e){Z.success(K.default.green(e))},warn(e){Z.warn(K.default.yellow(e))},error(e){Z.error(K.default.red(e))},step(e){Z.step(e)}}};var $a=class extends Error{configPath;constructor(e,t){super(e),this.name=`SharedConfigError`,this.configPath=t}},eo=class extends $a{cause;constructor(e,t){super(`加载配置文件 ${e} 失败`,e),this.name=`SharedConfigLoadError`,this.cause=t}},to=class extends $a{searchFrom;constructor(e){super(`未在 ${e} 及其上级目录中找到 lzi.config.ts 配置文件`,e),this.name=`SharedConfigNotFoundError`,this.searchFrom=e}};const no=[`packages/*`,`apps/*`];function ro(e){let r=o(e,`package.json`);if(!t(r))throw new to(e);let i;try{i=JSON.parse(n(r,`utf8`)).workspaces}catch(e){throw new eo(r,e)}let a=Array.isArray(i)?i:i?.packages;return a&&a.length>0?a:no}async function io(e,r={}){let i=ro(e),a=new Set,s=[];for(let c of i){let i=new Bun.Glob(`${c}/package.json`);for await(let c of i.scan({cwd:e,absolute:!0,onlyFiles:!0})){let e=o(c,`..`);if(a.has(e))continue;let i;try{i=JSON.parse(n(c,`utf8`))}catch{continue}typeof i.name==`string`&&i.name.length!==0&&(r.configFileName!==void 0&&!t(o(e,r.configFileName))||(a.add(e),s.push({name:i.name,dir:e})))}}return s}function ao(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 oo(e={}){let t=e.cwd??process.cwd(),n=ao(t);if(n===null)throw new to(t);let r=o(n,`..`);try{return{config:(await import(n)).default,configPath:r,configFilePath:n}}catch(e){throw new eo(n,e)}}function so(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 co(e={}){let t=e.cwd??o(process.cwd());if(e.standaloneFile){let n=so(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 eo(n,e)}}if(e.unifiedField)try{let{config:n,configFilePath:r}=await oo({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}}var lo=class extends Error{bunfigPath;constructor(e){super(`${e} 已存在且非 lzi-bun-cli 生成(缺少 @lzi-bun-cli generated, do not edit 标记),如需 lzi-bun-cli 接管,请删除该文件或手动合并后重试`),this.name=`BunfigProtectedError`,this.bunfigPath=e}};const Q=`https://registry.npmjs.org/`,uo=new Map([[`longzai-intelligence`,Q],[`longzai-intelligence-agent-tools`,Q],[`longzai-intelligence-audit`,Q],[`longzai-intelligence-auth`,Q],[`longzai-intelligence-builder`,Q],[`longzai-intelligence-bun`,Q],[`longzai-intelligence-cache`,Q],[`longzai-intelligence-cli`,Q],[`longzai-intelligence-config`,Q],[`longzai-intelligence-design-system`,Q],[`longzai-intelligence-dev-tools`,Q],[`longzai-intelligence-electron`,Q],[`longzai-intelligence-error`,Q],[`longzai-intelligence-event-bus`,Q],[`longzai-intelligence-logger`,Q],[`longzai-intelligence-oxfmt`,Q],[`longzai-intelligence-oxlint`,Q],[`longzai-intelligence-shared-config`,Q],[`longzai-intelligence-shared-kernel`,Q],[`longzai-intelligence-transport`,Q],[`longzai-intelligence-typescript`,Q],[`longzai-intelligence-zod`,Q],[`longzai-intelligence-prettier`,Q],[`longzai-intelligence-tsdown`,Q],[`longzai-intelligence-vitest`,Q],[`longzai-intelligence-academy`,Q],[`longzai-intelligence-accounting`,Q],[`longzai-intelligence-administration`,Q],[`longzai-intelligence-agent`,Q],[`longzai-intelligence-agent-session`,Q],[`longzai-intelligence-agent-swarm`,Q],[`longzai-intelligence-analytics`,Q],[`longzai-intelligence-app-store`,Q],[`longzai-intelligence-architecture`,Q],[`longzai-intelligence-art`,Q],[`longzai-intelligence-arxiv`,Q],[`longzai-intelligence-atomic`,Q],[`longzai-intelligence-attention`,Q],[`longzai-intelligence-audio`,Q],[`longzai-intelligence-auto-research`,Q],[`longzai-intelligence-automate`,Q],[`longzai-intelligence-benchmark`,Q],[`longzai-intelligence-billing`,Q],[`longzai-intelligence-board`,Q],[`longzai-intelligence-broker`,Q],[`longzai-intelligence-business-plan`,Q],[`longzai-intelligence-calendar`,Q],[`longzai-intelligence-capture`,Q],[`longzai-intelligence-chat`,Q],[`longzai-intelligence-claude-code`,Q],[`longzai-intelligence-cloud`,Q],[`longzai-intelligence-code`,Q],[`longzai-intelligence-code-agent`,Q],[`longzai-intelligence-code-reviewer`,Q],[`longzai-intelligence-codebase-research`,Q],[`longzai-intelligence-collaboration`,Q],[`longzai-intelligence-commerce`,Q],[`longzai-intelligence-concrete`,Q],[`longzai-intelligence-context`,Q],[`longzai-intelligence-contract`,Q],[`longzai-intelligence-cookery`,Q],[`longzai-intelligence-country`,Q],[`longzai-intelligence-creativity`,Q],[`longzai-intelligence-customer-service`,Q],[`longzai-intelligence-data`,Q],[`longzai-intelligence-data-science`,Q],[`longzai-intelligence-database`,Q],[`longzai-intelligence-decenterlization`,Q],[`longzai-intelligence-decision`,Q],[`longzai-intelligence-design`,Q],[`longzai-intelligence-design-lab`,Q],[`longzai-intelligence-distill`,Q],[`longzai-intelligence-docs`,Q],[`longzai-intelligence-document`,Q],[`longzai-intelligence-edge`,Q],[`longzai-intelligence-elysia`,Q],[`longzai-intelligence-embodied`,Q],[`longzai-intelligence-empowerment`,Q],[`longzai-intelligence-engineering`,Q],[`longzai-intelligence-event`,Q],[`longzai-intelligence-evolution`,Q],[`longzai-intelligence-execution`,Q],[`longzai-intelligence-experience`,Q],[`longzai-intelligence-expert-thinking`,Q],[`longzai-intelligence-feature-flags`,Q],[`longzai-intelligence-federation`,Q],[`longzai-intelligence-feed`,Q],[`longzai-intelligence-file-processing`,Q],[`longzai-intelligence-fitness`,Q],[`longzai-intelligence-gateway`,Q],[`longzai-intelligence-geo`,Q],[`longzai-intelligence-git`,Q],[`longzai-intelligence-github-trending`,Q],[`longzai-intelligence-hardware`,Q],[`longzai-intelligence-harness`,Q],[`longzai-intelligence-history`,Q],[`longzai-intelligence-human-resource`,Q],[`longzai-intelligence-i18n`,Q],[`longzai-intelligence-idea`,Q],[`longzai-intelligence-identity`,Q],[`longzai-intelligence-impact-maker`,Q],[`longzai-intelligence-intellectual-property`,Q],[`longzai-intelligence-key-management`,Q],[`longzai-intelligence-knowledge`,Q],[`longzai-intelligence-language-model`,Q],[`longzai-intelligence-legal`,Q],[`longzai-intelligence-loop`,Q],[`longzai-intelligence-mail`,Q],[`longzai-intelligence-mandala`,Q],[`longzai-intelligence-map`,Q],[`longzai-intelligence-marketing`,Q],[`longzai-intelligence-marketplace`,Q],[`longzai-intelligence-math`,Q],[`longzai-intelligence-mcn`,Q],[`longzai-intelligence-mcp`,Q],[`longzai-intelligence-memory`,Q],[`longzai-intelligence-mentor`,Q],[`longzai-intelligence-messaging`,Q],[`longzai-intelligence-mindset`,Q],[`longzai-intelligence-mission-control`,Q],[`longzai-intelligence-model-gateway`,Q],[`longzai-intelligence-movie`,Q],[`longzai-intelligence-narrative-analyzer`,Q],[`longzai-intelligence-notification`,Q],[`longzai-intelligence-observability`,Q],[`longzai-intelligence-office-industry`,Q],[`longzai-intelligence-older`,Q],[`longzai-intelligence-one`,Q],[`longzai-intelligence-ontology`,Q],[`longzai-intelligence-opencode`,Q],[`longzai-intelligence-opportunity`,Q],[`longzai-intelligence-organization`,Q],[`longzai-intelligence-orm`,Q],[`longzai-intelligence-outfit`,Q],[`longzai-intelligence-pagination`,Q],[`longzai-intelligence-panel`,Q],[`longzai-intelligence-paper-reader`,Q],[`longzai-intelligence-payment`,Q],[`longzai-intelligence-personal-assistant`,Q],[`longzai-intelligence-pii`,Q],[`longzai-intelligence-policy-research`,Q],[`longzai-intelligence-portal`,Q],[`longzai-intelligence-product-research`,Q],[`longzai-intelligence-project`,Q],[`longzai-intelligence-project-portfolio`,Q],[`longzai-intelligence-promotion`,Q],[`longzai-intelligence-qcloud`,Q],[`longzai-intelligence-react-devtools`,Q],[`longzai-intelligence-reasoning`,Q],[`longzai-intelligence-recruitment`,Q],[`longzai-intelligence-reliability`,Q],[`longzai-intelligence-report`,Q],[`longzai-intelligence-repository`,Q],[`longzai-intelligence-reviewer`,Q],[`longzai-intelligence-risk`,Q],[`longzai-intelligence-sales`,Q],[`longzai-intelligence-scheduler`,Q],[`longzai-intelligence-schema`,Q],[`longzai-intelligence-search`,Q],[`longzai-intelligence-security`,Q],[`longzai-intelligence-security-inventory`,Q],[`longzai-intelligence-serverless`,Q],[`longzai-intelligence-share`,Q],[`longzai-intelligence-skill`,Q],[`longzai-intelligence-slider`,Q],[`longzai-intelligence-smart-transition`,Q],[`longzai-intelligence-sms`,Q],[`longzai-intelligence-soul`,Q],[`longzai-intelligence-sports`,Q],[`longzai-intelligence-storage`,Q],[`longzai-intelligence-strategy`,Q],[`longzai-intelligence-supply-chain`,Q],[`longzai-intelligence-talk`,Q],[`longzai-intelligence-taro`,Q],[`longzai-intelligence-task`,Q],[`longzai-intelligence-tenant`,Q],[`longzai-intelligence-testing`,Q],[`longzai-intelligence-thinking`,Q],[`longzai-intelligence-topology`,Q],[`longzai-intelligence-trader`,Q],[`longzai-intelligence-trae`,Q],[`longzai-intelligence-translator`,Q],[`longzai-intelligence-travel`,Q],[`longzai-intelligence-trending`,Q],[`longzai-intelligence-twitter`,Q],[`longzai-intelligence-usecase`,Q],[`longzai-intelligence-user-research`,Q],[`longzai-intelligence-userscript`,Q],[`longzai-intelligence-utils`,Q],[`longzai-intelligence-value-chain`,Q],[`longzai-intelligence-vector-search`,Q],[`longzai-intelligence-venture-capital`,Q],[`longzai-intelligence-voice`,Q],[`longzai-intelligence-vscode-developer`,Q],[`longzai-intelligence-wealth`,Q],[`longzai-intelligence-web3`,Q],[`longzai-intelligence-webhook`,Q],[`longzai-intelligence-wechat`,Q],[`longzai-intelligence-wiki`,Q],[`longzai-intelligence-work`,Q],[`longzai-intelligence-workflow`,Q],[`longzai-intelligence-workspace`,Q],[`longzai-intelligence-writer`,Q]]);function fo(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`}function po(e){return`[${e.map(e=>fo(e)).join(`, `)}]`}function mo(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 ho(e){let t=[`registry = ${fo(e.registry)}`],n=Object.entries(e.scopes).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${fo(`@${e}`)} = ${fo(t)}`),r=[`[install]\n${t.join(`
138
+ `)}`];return n.length>0&&r.push(`[install.scopes]\n${n.join(`
139
+ `)}`),r.join(`
140
+
141
+ `)}function go(){let e={};for(let[t,n]of uo)e[t]=n;return{registry:`https://mirrors.cloud.tencent.com/npm/`,scopes:e}}function _o(e,t){if(t!==void 0){if(typeof t==`boolean`||typeof t==`number`)return`${e} = ${t}`;if(typeof t==`string`)return`${e} = ${fo(t)}`;if(Array.isArray(t))return t.length===0?void 0:`${e} = ${po(t)}`}}function vo(e){let t=[];e.install&&t.push(ho(e.install));let n=e.test,r=[],i=_o(`preload`,n.preload);i&&r.push(i);let a=_o(`coverage`,n.coverage);a&&r.push(a);let o=_o(`coverageSkipTestFiles`,n.coverageSkipTestFiles);o&&r.push(o);let s=_o(`coverageReporter`,n.coverageReporter);s&&r.push(s);let c=_o(`coverageDir`,n.coverageDir);c&&r.push(c);let l=_o(`coveragePathIgnorePatterns`,n.coveragePathIgnorePatterns);l&&r.push(l),n.coverageThreshold!==void 0&&(typeof n.coverageThreshold==`number`?r.push(`coverageThreshold = ${n.coverageThreshold}`):r.push(`coverageThreshold = ${mo(n.coverageThreshold)}`));let u=_o(`coverageIgnoreSourcemaps`,n.coverageIgnoreSourcemaps);u&&r.push(u);let d=_o(`timeout`,n.timeout);return d&&r.push(d),r.length>0&&t.push(`[test]\n${r.join(`
142
+ `)}`),`# @lzi-bun-cli generated, do not edit\n${t.join(`
143
+
144
+ `)}\n`}function yo(e,t={}){let n=t.isRoot===!0,r=e?.test,i=r?r.coverage!==void 0||r.coverageThreshold!==void 0||r.coveragePathIgnorePatterns!==void 0||r.coverageReporter!==void 0||r.coverageSkipTestFiles!==void 0||r.coverageDir!==void 0||r.preload!==void 0||r.timeout!==void 0:!1;if(!n&&!i)return null;let a={test:r??{}};return n&&(a.install=go()),{content:vo(a),shouldWrite:!0}}function bo(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 $(...e){process.stdout.write(`${bo(e)}\n`)}function xo(...e){process.stderr.write(`${bo(e)}\n`)}const So=async(e=process.cwd())=>{let t=await co({cwd:e,standaloneFile:`lzi-bun.config.ts`,unifiedField:`bun`});return t.success?t.config:($(`提示: 未找到配置文件 lzi-bun.config.ts,使用默认配置`),{})},Co=[`src/**/*.test.ts`,`src/**/*.test.tsx`,`__tests__/**/*.test.ts`],wo=e=>{let r=a(e,`package.json`);if(!t(r))return!1;let i;try{i=JSON.parse(n(r,`utf8`)).workspaces}catch{return!1}return Array.isArray(i)||typeof i==`object`&&!!i&&`packages`in i};function To(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 Eo(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 Do=async(e,i={})=>{let o=i.dir??process.cwd(),s=a(o,`bunfig.toml`),c=yo(e,{isRoot:wo(o)});if(!c?.shouldWrite)return i.dryRun&&$(`(无 coverage 配置,不会生成 bunfig.toml)`),{status:`skipped`,bunfigPath:s};if(i.dryRun)return $(`[dry-run] 将写入 ${s}:`),$(c.content),{status:`generated`,bunfigPath:s};if(t(s)&&!n(s,`utf8`).includes(`@lzi-bun-cli generated, do not edit`))throw new lo(s);return r(s,c.content,`utf8`),$(`已生成 ${s}(lzi-bun-cli 接管覆盖率配置)`),{status:`generated`,bunfigPath:s}},Oo=async e=>{let t=await So(),n=t.test?.passWithNoTests??!0;await Eo(t.test?.include??Co)===0&&(n&&($(`无测试文件,跳过(type-only / facade 包,passWithNoTests)`),process.exit(0)),xo(`错误: 未找到测试文件,且 test.passWithNoTests 为 false`),xo(`(如该包确为 type-only / facade 包,请在 lzi-dev.config.ts 设置 test.passWithNoTests: true)`),process.exit(1));try{await Do(t)}catch(e){throw e instanceof lo&&(xo(`错误: ${e.message}`),process.exit(1)),e}let r=To(e),i=await Bun.spawn(r,{cwd:process.cwd(),stdout:`inherit`,stderr:`inherit`}).exited;i!==0&&process.exit(i)},ko=async e=>{let t=await So();try{await Do(t,{dryRun:e})}catch(e){throw e instanceof lo&&(xo(`错误: ${e.message}`),process.exit(1)),e}},Ao=e=>{let r=o(e,`package.json`);t(r)||(xo(`错误: 当前目录 ${e} 无 package.json,--recursive 须在 monorepo root 执行`),process.exit(1));let i;try{i=JSON.parse(n(r,`utf8`)).workspaces}catch{i=void 0}Array.isArray(i)||typeof i==`object`&&i&&`packages`in i||(xo(`错误: ${e} 的 package.json 未声明 workspaces 字段,--recursive 须在 monorepo root 执行`),process.exit(1))},jo=async e=>{let t=process.cwd();Ao(t);let r=await io(t,{configFileName:`lzi-bun.config.ts`}),i=t.split(`/`).pop()??`root`;try{let e=JSON.parse(n(o(t,`package.json`),`utf8`));e.name&&(i=e.name)}catch{}let a=[{name:i,dir:t}];a.push(...r.map(e=>({name:e.name,dir:e.dir}))),$(`发现 ${a.length} 个目标(root 1 + 子包 ${r.length}),开始${e?`预览`:`生成`}...`);let s=[];for(let t of a){$(`▶ ${t.name}`);try{let n=await So(t.dir),{status:r}=await Do(n,{dryRun:e,dir:t.dir});s.push({name:t.name,dir:t.dir,status:r})}catch(e){s.push({name:t.name,dir:t.dir,status:`failed`,reason:e instanceof Error?e.message:String(e)})}}let c=s.filter(e=>e.status===`generated`),l=s.filter(e=>e.status===`skipped`),u=s.filter(e=>e.status===`failed`);if($(``),$(`汇总:${c.length} 生成 / ${l.length} 跳过 / ${u.length} 失败`),u.length>0){xo(``),xo(`失败子包:`);for(let e of u)xo(` - ${e.name}:${e.reason}`);process.exitCode=1}},Mo=async e=>{let t=e.dryRun===!0;if(e.recursive===!0){await jo(t);return}await ko(t)};function No(e){Po(e),Fo(e)}function Po(e){Fi(e,{name:`test`,description:`运行 bun 测试(替代三件套,零测试包默认放行)`,options:[{flags:`--watch`,description:`监听模式(对应 test:watch)`},{flags:`--coverage`,description:`覆盖率(对应 test:coverage)`}],schema:Kr({watch:Rr().optional(),coverage:Rr().optional()}),action:async(e,t)=>{await Oo({watch:e.watch===!0,coverage:e.coverage===!0,extra:t})}})}function Fo(e){Fi(e,{name:`config generate`,description:`生成 bunfig.toml(不执行测试,支持 --dry-run 预览、-r 批量)`,options:[{flags:`--dry-run`,description:`仅预览将写入的内容,不写盘`},{flags:`-r, --recursive`,description:`递归处理 monorepo 下含 lzi-bun.config.ts 的子包`}],schema:Kr({dryRun:Rr().optional(),recursive:Rr().optional()}),action:async e=>{await Mo({dryRun:e.dryRun===!0,recursive:e.recursive===!0})}})}const Io=ji({name:`lzi-bun-cli`,description:`Longzai Intelligence bun 工具集`,interaction:Qa,color:Za});No(Io);async function Lo(){await Io.parseAsync(process.argv)}Lo().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.5",
3
+ "version": "0.0.7",
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.5",
36
+ "@longzai-intelligence-bun/config": "0.0.7",
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.7",