@longzai-intelligence-bun/cli 0.0.6 → 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.
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -141,4 +141,4 @@ ${K.default.gray(La+Fa.repeat(i+2)+Ra)}
|
|
|
141
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
142
|
`)}`),`# @lzi-bun-cli generated, do not edit\n${t.join(`
|
|
143
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
|
|
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.
|
|
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.
|
|
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",
|