@tbox.cn/app-cli 1.0.0-alpha.3 → 1.0.0-alpha.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.
Files changed (2) hide show
  1. package/dist/index.js +2 -2
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -37,8 +37,8 @@ import{A as ae,B as Wt,C as qn,D as Zn,E as Xn,F as fe,G as Xe,H as Ye,I as Qe,a
37
37
  `),s=o===""?[]:o.split(`
38
38
  `),i=Bs(n,r),a=Bs(n,s),c=new Map;for(let y of i)c.set(y.start,{ours:y});for(let y of a){let g=c.get(y.start);g?g.theirs=y:c.set(y.start,{theirs:y})}let d=[],l=[],p=new Set,f=(y,g)=>{let h=Math.max(y?.oldLines.length??0,g?.oldLines.length??0);return y&&g?JSON.stringify(y.oldLines)===JSON.stringify(g.oldLines)&&JSON.stringify(y.newLines)===JSON.stringify(g.newLines)?d.push(...y.newLines):(l.push([...y.newLines,"--",...g.newLines].join(`
39
39
  `)),d.push("<<<<<<< ours",...y.newLines,"=======",...g.newLines,">>>>>>> theirs")):y?d.push(...y.newLines):d.push(...g.newLines),h},u=0;for(;u<n.length;){let y=c.get(u);if(!y||p.has(u)){d.push(n[u]),u++;continue}p.add(u);let g=f(y.ours,y.theirs);g>0&&(u+=g)}let m=c.get(n.length);return m&&!p.has(n.length)&&f(m.ours,m.theirs),{merged:d.join(`
40
- `),conflicts:l}}function un(e){return/^<<<<<<< ours|^>>>>>>> theirs|^=======$/m.test(e)}var wl=new Set(["node_modules","dist",".git",".tbox"]);async function mn(e){let t=new Map;if(!te(e))return t;async function o(n){let r=J.join(e,n),s=await yl(r,{withFileTypes:!0});for(let i of s){if(wl.has(i.name))continue;let a=n?`${n}/${i.name}`:i.name,c=J.join(r,i.name);if(i.isDirectory())await o(a);else try{t.set(a,await Hs(c,"utf8"))}catch{}}}return await o(""),t}function qs(e){let t=J.join(e,"tbox.module.json");if(!te(t))throw new Error(`模块源缺 tbox.module.json: ${e}`);let o=JSON.parse(gl(t,"utf8"));if(o.schemaVersion!==1||!o.id)throw new Error("模块 tbox.module.json 非法");return o}async function Zs(e,t){let o=process.cwd(),n=J.join(o,"modules",e);if(!te(n))throw new Error(`模块不存在: modules/${e}`);if(!t.source)throw new Error("1.0 module update 需要 --source <新模块目录>");let r=J.resolve(t.source);if(!te(r))throw new Error(`新模块源不存在: ${r}`);let s=qs(r);if(s.id!==e)throw new Error(`新模块 id "${s.id}" 与目标 "${e}" 不一致`);let i=await mn(n),a=await mn(r),c=t.baseSource?await mn(J.resolve(t.baseSource)):void 0,d=[],l=0;for(let[p,f]of a){let u=i.get(p);if(u===f)continue;let m=J.join(n,p);if(u===void 0){await Us(J.dirname(m),{recursive:!0}),await Ke(m,f,"utf8"),l++;continue}if(!c){if(!t.force)throw new Error(`文件 ${p} 本地已修改;请补 --base-source 做 3-way,或加 --force 覆盖`);await Ke(m,f,"utf8"),l++;continue}let y=c.get(p);if(y===void 0){if(!t.force)throw new Error(`base 缺文件 ${p};请补 --base-source 或加 --force`);await Ke(m,f,"utf8"),l++;continue}if(u===y){await Ke(m,f,"utf8"),l++;continue}if(f===y)continue;let g=vo(y,u,f);await Ke(m,g.merged,"utf8"),(g.conflicts.length>0||un(g.merged))&&d.push(p),l++}if(c)for(let[p,f]of c)a.has(p)||i.get(p)===f&&(await Gs(J.join(n,p),{force:!0}),l++);console.log(`✅ modules/${e} 更新完成(${l} 个文件变更)`),d.length&&(console.error(`冲突文件: ${d.join(", ")}(已写 <<<<<<< ours 标记)`),process.exitCode=1)}async function Xs(e){let t=process.cwd();if(!e.source)throw new Error("1.0 module add 暂要求 --source <模块目录>(vendored 源码;不走 node_modules)");let o=J.resolve(e.source);if(!te(o))throw new Error(`模块源不存在: ${o}`);let n=qs(o),r=J.join(t,"modules",n.id);if(te(r)&&!e.force)throw new Error(`模块已存在: modules/${n.id}(加 --force 覆盖)`);await Us(r,{recursive:!0});for(let i of["src","skills","schemas","assets","INTEGRATION.md","AGENTS.md","README.md","LICENSE"]){let a=J.join(o,i);te(a)&&await hl(a,J.join(r,i),{recursive:!0,force:!0})}await Ke(J.join(r,"tbox.module.json"),`${JSON.stringify(n,null,2)}
41
- `,"utf8");let s=J.join(o,"package.json");if(te(s)){let i=JSON.parse(await Hs(s,"utf8")),a=i.tbox?.upstream,c={};te(J.join(o,"src","index.ts"))&&(c["."]="./src/index.ts"),te(J.join(o,"src","server","index.ts"))&&(c["./server"]="./src/server/index.ts"),te(J.join(o,"src","client","index.ts"))&&(c["./client"]="./src/client/index.ts"),te(J.join(o,"src","shared","index.ts"))&&(c["./shared"]="./src/shared/index.ts"),c["./package.json"]="./package.json";let d={...i,name:`@app/module-${n.id}`,private:!0,exports:c,tbox:{...i.tbox,upstream:a??{package:String(i.name),version:String(i.version??n.version)}}};await Ke(J.join(r,"package.json"),`${JSON.stringify(d,null,2)}
40
+ `),conflicts:l}}function un(e){return/^<<<<<<< ours|^>>>>>>> theirs|^=======$/m.test(e)}var wl=new Set(["node_modules","dist",".git",".tbox"]);async function mn(e){let t=new Map;if(!te(e))return t;async function o(n){let r=J.join(e,n),s=await yl(r,{withFileTypes:!0});for(let i of s){if(wl.has(i.name))continue;let a=n?`${n}/${i.name}`:i.name,c=J.join(r,i.name);if(i.isDirectory())await o(a);else try{t.set(a,await Hs(c,"utf8"))}catch{}}}return await o(""),t}function qs(e){let t=J.join(e,"tbox.module.json");if(!te(t))throw new Error(`模块源缺 tbox.module.json: ${e}`);let o=JSON.parse(gl(t,"utf8"));if(o.schemaVersion!==1||!o.id)throw new Error("模块 tbox.module.json 非法");return o}async function Zs(e,t){let o=process.cwd(),n=J.join(o,"modules",e);if(!te(n))throw new Error(`模块不存在: modules/${e}`);if(!t.source)throw new Error("1.0 module update 需要 --source <新模块目录>");let r=J.resolve(t.source);if(!te(r))throw new Error(`新模块源不存在: ${r}`);let s=qs(r);if(s.id!==e)throw new Error(`新模块 id "${s.id}" 与目标 "${e}" 不一致`);let i=await mn(n),a=await mn(r),c=t.baseSource?await mn(J.resolve(t.baseSource)):void 0,d=[],l=0;for(let[p,f]of a){let u=i.get(p);if(u===f)continue;let m=J.join(n,p);if(u===void 0){await Us(J.dirname(m),{recursive:!0}),await Ke(m,f,"utf8"),l++;continue}if(!c){if(!t.force)throw new Error(`文件 ${p} 本地已修改;请补 --base-source 做 3-way,或加 --force 覆盖`);await Ke(m,f,"utf8"),l++;continue}let y=c.get(p);if(y===void 0){if(!t.force)throw new Error(`base 缺文件 ${p};请补 --base-source 或加 --force`);await Ke(m,f,"utf8"),l++;continue}if(u===y){await Ke(m,f,"utf8"),l++;continue}if(f===y)continue;let g=vo(y,u,f);await Ke(m,g.merged,"utf8"),(g.conflicts.length>0||un(g.merged))&&d.push(p),l++}if(c)for(let[p,f]of c)a.has(p)||i.get(p)===f&&(await Gs(J.join(n,p),{force:!0}),l++);console.log(`✅ modules/${e} 更新完成(${l} 个文件变更)`),d.length&&(console.error(`冲突文件: ${d.join(", ")}(已写 <<<<<<< ours 标记)`),process.exitCode=1)}async function Xs(e){let t=process.cwd();if(!e.source)throw new Error("1.0 module add 暂要求 --source <模块目录>(vendored 源码;不走 node_modules)");let o=J.resolve(e.source);if(!te(o))throw new Error(`模块源不存在: ${o}`);let n=qs(o),r=J.join(t,"modules",n.id);if(te(r)&&!e.force)throw new Error(`模块已存在: modules/${n.id}(加 --force 覆盖)`);await Us(r,{recursive:!0});for(let i of["src","skills","schemas","assets","tsconfig.json","tsup.config.ts","INTEGRATION.md","AGENTS.md","README.md","LICENSE"]){let a=J.join(o,i);te(a)&&await hl(a,J.join(r,i),{recursive:!0,force:!0})}await Ke(J.join(r,"tbox.module.json"),`${JSON.stringify(n,null,2)}
41
+ `,"utf8");let s=J.join(o,"package.json");if(te(s)){let i=JSON.parse(await Hs(s,"utf8")),a=i.tbox?.upstream,c={};te(J.join(o,"src","index.ts"))&&(c["."]="./src/index.ts"),te(J.join(o,"src","server","index.ts"))&&(c["./server"]="./src/server/index.ts"),te(J.join(o,"src","client","index.ts"))&&(c["./client"]="./src/client/index.ts"),te(J.join(o,"src","shared","index.ts"))&&(c["./shared"]="./src/shared/index.ts"),c["./package.json"]="./package.json";let d=i.scripts??{},l={...i,name:`@app/module-${n.id}`,private:!0,exports:c,scripts:d.test&&!d.test.includes("--passWithNoTests")?{...d,test:`${d.test} --passWithNoTests`}:d,tbox:{...i.tbox,upstream:a??{package:String(i.name),version:String(i.version??n.version)}}};await Ke(J.join(r,"package.json"),`${JSON.stringify(l,null,2)}
42
42
  `,"utf8")}console.log(`✅ modules/${n.id}${te(s)?"(vendored)":"(local)"}`),console.log(" 下一步: pnpm install && pnpm check")}async function Ys(e){let t=J.join(process.cwd(),"modules",e);if(!te(t))throw new Error(`模块不存在: modules/${e}`);await Gs(t,{recursive:!0,force:!0}),console.log(`✅ 已移除 modules/${e}`)}function kl(e){let t=oe.join(e,"tbox.module.json");if(!ke(t))return null;try{let o=_t(JSON.parse(hn(t,"utf8")));return o.ok?o.value:null}catch{return null}}function xl(e,t){if(!e)return null;let o=oe.dirname(e),n=oe.join(o,t);if(ke(oe.join(n,"package.json")))return n;try{let r=vl(o).find(s=>s.endsWith(".tgz")&&s.includes(`-${t}-`));if(r)return oe.join(o,r)}catch{}return null}function gn(e,t){let o=oe.join(e,"packages",t);return ke(o)&&!Qt(o)?!0:N(e)?.npmModules.some(r=>r.id===t&&r.mode==="sdk")??!1}async function We(e){if(V(process.cwd())){let t=e.source,o=null;t&&(pt(t)&&!ke(oe.resolve(t))||t.endsWith(".tgz")&&ke(oe.resolve(t)))&&t&&(o=re(t,e.registry),t=o.sourceDir);try{await Xs({pkg:e.pkg,source:t}),await De(process.cwd())}finally{(o?.source instanceof X||o?.source instanceof pe)&&o.source.dispose()}return}await Q(()=>Qs(e,new Set,!1))}async function Qs(e,t,o){let n=[];try{await jl(e,t,o,n)}finally{for(let r of n)r.dispose()}}async function jl(e,t,o,n){let r=process.cwd();if(!N(r))throw new Error("当前目录不是 tbox-app 应用(缺 .tbox/app.json)");if(At(r),/^@tbox\.cn\/app-theme-/.test(e.pkg)||/\/app-theme-/.test(e.pkg))throw new Error(`主题包不属模块面(${e.pkg})——换/装主题请用 ${C} theme use <id>${e.source?` --source ${e.source}`:""}`);let s,i=null,a=null,c=!!e.source&&pt(e.source);if(e.mode==="local"){let g=e.pkg;s=g.startsWith("module-")?g:`module-${g}`,fe(s,`--mode local ${e.pkg}`)}else{if(!e.source)throw new Error(`--mode ${e.mode} 需要 --source <目录或 tgz 或 registry 包>`);if(!(c&&!ke(oe.resolve(e.source)))&&!e.source.endsWith(".tgz")&&!Ze.isUsable(e.source))throw new Error(`模块源无效(缺 package.json): ${e.source}`);a=re(e.source,e.registry),(a.source instanceof X||a.source instanceof pe)&&n.push(a.source);let h=e.pkg.replace(/@[^/]+$/,"");s=dr(h),fe(s,`--mode ${e.mode} ${e.pkg}`),i=kl(a.sourceDir)}if(o&&gn(r,s)){console.log(` ⚠️ 依赖 ${s} 已安装,跳过`);return}if(!o&&gn(r,s)){let g=ke(oe.join(r,"packages",s))?`packages/${s}`:"manifest 已登记(sdk 包,无本地目录)";throw new Error(`模块 ${s} 已存在(${g})。若要重新展开请先 remove 或手动处理;装配唯一覆盖入口为 sync --force`)}if(t.has(s))return;if(t.add(s),!e.noDeps){let g=i?.dependencies?.modules??[],h=await Vs(r,[],void 0,[{id:s,deps:g}]);if(h.cycles.length>0)throw new Error(`依赖环:${h.cycles.map(k=>k.join(" → ")).join(";")}`);for(let k of h.conflicts)console.warn(` ⚠️ 依赖版本冲突: ${k}`);let x=[...h.contracts,...h.order].filter(k=>k!==s&&!gn(r,k));for(let k of[...new Set(x)]){let $=/^(module|scenario|contracts|provider)-/.test(k)?`@tbox.cn/app-${k}`:`@tbox.cn/${k}`,b=c?$:xl(e.source,k);if(!b){console.warn(` ⚠️ 依赖 ${k} 未安装且未找到源(--source 兄弟目录/tgz),可 --no-deps 跳过`);continue}let D=re(b,e.registry);(D.source instanceof X||D.source instanceof pe)&&n.push(D.source);let M=ke(oe.join(D.sourceDir,"tbox.module.json")),F=tr($,M);await Qs({pkg:$,mode:F,source:b,registry:e.registry},t,!0)}}let d;if(e.mode==="local"){let g=e.pkg,h=g.startsWith("module-")?g:`module-${g}`;await Qe(Ye("module-app"),oe.join(r,"packages",h),{id:h,pkg:`@app/${h}`},!1),d={id:h,package:`@app/${h}`,version:"0.1.0",mode:"local"},await Je(r,`@app/${h}`,"add");let{doctorErrors:x}=await go(r,d);x.length>0?console.error(`❌ 已安装 ${d.package}(mode=local${o?", 依赖":""})但结构校验未过——见上方 doctor 错误`):console.log(`✅ 已安装 ${d.package}(mode=local${o?", 依赖":""})`);return}else{let g=a.sourceDir,h=a.source.resolveVersion();e.mode==="codegen"&&(eo(g),await fr(r,g,{id:s,package:e.pkg.replace(/@[^/]+$/,""),version:h,mode:"codegen",baseVersion:h},_e(r).values()),await Je(r,Yt(s),"add")),d={id:s,package:e.pkg.replace(/@[^/]+$/,""),version:h,mode:e.mode,...e.mode==="codegen"?{baseVersion:h}:{}}}let l=N(r);if(await ae(r,Wt(l,d)),d.mode==="codegen"){let g=await oo(r,_e(r).values());g.length>0&&console.log(` codegen 引用同步: ${g.join(", ")}`)}let p=await he(r);p.changedFiles.length>0&&console.log(` 装配更新: ${p.changedFiles.join(", ")}`);for(let g of p.warnings)console.warn(` ⚠️ ${g}`);for(let g of p.depConflicts)console.warn(` ⚠️ 依赖冲突: ${g}`);let f=await Z(r),m=(await ee({appDir:r,declared:p.declared,actual:f},{skip:["integration-services"]})).filter(g=>g.level==="error");if(m.length>0){console.error("❌ doctor 错误:");for(let g of m)console.error(` - [${g.rule}] ${g.message}`);process.exitCode=1}let y=await De(r);y.generated?console.log(` ⚡ 已生成 mock 槽绑定(config/integrations.json:${y.services.join(", ")})`):y.reason==="in-place"&&console.log(" ℹ config/integrations.json 已在场,跳过 mock 绑定生成"),console.log(`✅ 已安装 ${d.package}(mode=${e.mode}${o?", 依赖":""})`),Sl(r,d.id),console.log(` 下一步: pnpm install && ${C} module doctor`)}function Sl(e,t){try{let o=oe.join(e,"packages",t,"package.json");if(!ke(o))return;let r=JSON.parse(hn(o,"utf8")).dependencies?.["@tbox.cn/app-contracts-mall"],s=typeof r=="string"?r.replace(/[\^~]/,""):void 0;if(!s)return;let i=oe.join(e,"pnpm-workspace.yaml");if(!ke(i))return;let d=hn(i,"utf8").match(/['"]?@tbox\.cn\/app-contracts-mall['"]?\s*:\s*['"]([^'"]+)['"]/)?.[1]?.replace(/[\^~]/,"");if(!d)return;$l(s,d)>0&&console.warn(` ⚠️ 版本配套:${t} 依赖 contracts-mall ${s}+,当前应用 catalog 为 ${d}——请升级模板或应用 catalog(015 W1)`)}catch{}}function $l(e,t){let o=e.split(".").map(Number),n=t.split(".").map(Number),r=(o[0]??0)-(n[0]??0);return Math.sign(r!==0?r:(o[1]??0)-(n[1]??0))}import{existsSync as ko}from"fs";import{cp as bl,readFile as Dl,rm as El,writeFile as Cl}from"fs/promises";import st from"path";function Il(e){return ko(st.join(e,"mini.project.json"))&&ko(st.join(e,"app.json"))&&ko(st.join(e,"pages"))}async function xo(e){return Q(()=>Rl(e))}async function Rl(e){let t=e.platform??"alipay";fe(t,"miniapp-container init");let o=process.cwd(),n=N(o);if(!n)throw new Error("当前目录不是 tbox-app 应用(缺 .tbox/app.json)");let r=`@tbox.cn/app-miniapp-container-${t}`,s;if(e.source)s=re(e.source,e.registry);else try{s=re(r,e.registry)}catch(i){throw new Error(`未找到 ${r}(registry 拉取失败:${i.message})。离线场景用 --source <容器目录或 tgz>`)}try{let i=s.sourceDir;if(!Il(i))throw new Error(`源不是小程序容器工程(缺 mini.project.json/app.json/pages): ${e.source??r}`);let a=st.join(o,"apps",`miniapp-container-${t}`);if(ko(a)){if(!e.force)throw new Error(`容器已存在: apps/miniapp-container-${t}(--force 删除重展开)`);await El(a,{recursive:!0,force:!0})}await bl(i,a,{recursive:!0,force:!0,filter:f=>{let u=st.basename(f);return!["node_modules","dist",".git",".DS_Store",".tbox"].includes(u)}});let c=st.join(a,"package.json"),d=JSON.parse(await Dl(c,"utf8")),l=typeof d.name=="string"?d.name:r;d.name=`@app/miniapp-container-${t}`,d.private=!0,await Cl(c,JSON.stringify(d,null,2)+`
43
43
  `,"utf8");let p=Lt(i);await ae(o,Zn(n,{id:t,package:p.name??r,version:s.source.resolveVersion()||p.version,dir:`apps/miniapp-container-${t}`})),Ce(o),console.log(`✅ 已初始化容器 @app/miniapp-container-${t}(v${s.source.resolveVersion()||p.version},源 ${l})`),console.log(` ⚡ 展开至 apps/miniapp-container-${t}(workspace apps/* 自动纳管)`),console.log(` 下一步: pnpm install && pnpm --filter @app/miniapp-container-${t} dev`),console.log(" 指引: npx --yes @tbox.cn/app-cli skills get miniapp-container")}finally{(s.source instanceof X||s.source instanceof pe)&&s.source.dispose()}}import{z as Se}from"zod";import{existsSync as ei,readFileSync as ti,writeFileSync as yn}from"fs";import{join as oi}from"path";function jo(e,t={}){let o=oi(e,"config","service-slots.json"),n=oi(e,"config");if(!ei(n))return{action:"skipped",removedSlots:[]};let r=new Set;for(let l of Vt(e))if(l.via!=="config-override")for(let p of l.slots)r.add(p);let s=[...r].sort(),i={seededAt:new Date().toISOString(),slots:s.length,source:"tbox-app seed(词汇引导快照;meta 区用户所有——改名请手写 meta 条目)"};if(!ei(o))return yn(o,`${JSON.stringify({$comment:i,slots:s,meta:{}},null,2)}
44
44
  `),{action:"seeded",removedSlots:[]};if(!t.force){try{let l=JSON.parse(ti(o,"utf8")),p=Array.isArray(l.slots)&&l.slots.length===0,f=l.meta&&typeof l.meta=="object"&&!Array.isArray(l.meta)?Object.keys(l.meta).length===0:!0;if(!p||!f)return{action:"skipped",removedSlots:[]}}catch{return{action:"skipped",removedSlots:[]}}return yn(o,`${JSON.stringify({$comment:i,slots:s,meta:{}},null,2)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-cli",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "type": "module",
5
5
  "description": "tbox-app CLI(生成应用面):starter / create / new / skills / schema / module add|remove|list|sync|diff|doctor|inspect|update / provider / theme / miniapp-container(纯函数核心 + commander 薄壳)。仓内开发命令见私有 @tbox.cn/app-cli-dev。",
6
6
  "bin": {
@@ -35,8 +35,8 @@
35
35
  "zod": "3.25.76",
36
36
  "jsonc-parser": "3.3.1",
37
37
  "zod-to-json-schema": "3.25.2",
38
- "@tbox.cn/app-build": "1.0.0-alpha.1",
39
- "@tbox.cn/app-toolkit": "1.0.0-alpha.1"
38
+ "@tbox.cn/app-toolkit": "1.0.0-alpha.1",
39
+ "@tbox.cn/app-build": "1.0.0-alpha.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/diff": "7.0.2",