@cnbcool/cnb-cli 1.9.6 → 1.9.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 +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -120,4 +120,4 @@ PR 页面路径: ${p}
120
120
  登录成功 \uD83C\uDF89`),r.debug){if(console.log(` token_type : ${n.token_type}`),console.log(` expires_in : ${n.expires_in}`),console.log(` scope : ${n.scope||""}`),console.log(` access_token : ${(0,H.maskToken)(n.access_token)}`),n.refresh_token)console.log(` refresh_token : ${(0,H.maskToken)(n.refresh_token)}`);if(n.id_token)console.log(` id_token : ${(0,H.maskToken)(n.id_token)}`)}let y=Math.floor(Date.now()/1000),l=`https://api.${new URL(r.platformURL).hostname}`,u={access_token:n.access_token,expires_at:y+n.expires_in,platform_url:r.platformURL,client_id:r.clientID,login_host:l};if(n.refresh_token)u.refresh_token=n.refresh_token;if((0,H.saveToken)(u),r.debug)console.log(`Token 已保存到 ${(0,H.getTokenPath)()}`)}catch(p){console.error(`
121
121
  登录失败: ${p.message}`),process.exit(1)}})}});var mu=o((Sn)=>{Object.defineProperty(Sn,"__esModule",{value:!0});Sn.registerLogoutCommand=m5;var l5=b5(require("fs")),u5=D(),g5=te();function b5(e){return e&&e.__esModule?e:{default:e}}function m5(e){e.command("logout").description("退出登录,删除本地保存的 access_token").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=(0,u5.getTokenPath)(),i=(0,g5.loadToken)();if(!i){console.log("当前未登录,无需退出。");return}if(t.debug)console.log(`Token 文件路径: ${r}`),console.log(`Platform URL : ${i.platform_url}`),console.log(`Client ID : ${i.client_id}`);try{l5.default.unlinkSync(r),console.log("已成功退出登录。")}catch(p){console.error(`退出登录失败: ${p.message}`),process.exit(1)}})}});var hu=o((Tn)=>{Object.defineProperty(Tn,"__esModule",{value:!0});Tn.registerStatusCommand=j5;var h5=st(),_5=le(),f5=D(),v5={workbuddy:"WorkBuddy 远程获取",codebuddy_env:"CNB_TOKEN_FOR_CODEBUDDY 环境变量",env:"CNB_TOKEN 环境变量"};function j5(e){e.command("status").description("检查当前登录状态(token 是否存在、是否过期)").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=await(0,h5.resolveTokenSource)();if(r.source==="none"){console.log(r.reason?`⚠️ ${r.reason}`:"⚠️ 未登录,请执行 `cnb login` 进行授权。");return}if(r.source!=="file"){if(console.log("✅ 已登录。"),t.debug)console.log(` Token 来源: ${v5[r.source]}`);return}let i=(0,f5.getTokenPath)(),p=r.store;if(t.debug)console.log(`Token 文件路径 : ${i}`),console.log(`Platform URL : ${p.platform_url||"未知"}`),console.log(`Client ID : ${p.client_id||"未知"}`),console.log(`Expires At : ${new Date(p.expires_at*1000).toLocaleString()}`);if(Math.floor(Date.now()/1000)>=p.expires_at)if(p.refresh_token){if(t.debug)console.log("Token 已过期,尝试使用 refresh_token 刷新...");try{if(await(0,_5.refreshAccessToken)(p),console.log("✅ 已登录。"),t.debug)console.log(" (Token 已自动刷新)")}catch(y){if(t.debug)console.log(`刷新失败: ${y.message}`);console.log("⚠️ 未登录,请执行 `cnb login` 重新授权。")}}else console.log("⚠️ 未登录,请执行 `cnb login` 重新授权。");else console.log("✅ 已登录。")})}});var _u=o((Vn)=>{Object.defineProperty(Vn,"__esModule",{value:!0});Vn.registerGitCredentialCommand=z5;var P5=ue(),K5=["cnb.cool","cnb.woa.com"],A5=8000;function z5(e){e.command("git-credential <action>").description("作为 git credential helper,向 git 提供 CNB 凭据(仅供 git 内部调用)").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").action(async(t,r,i)=>{let p=i.args.slice(0,-1);if(p.length>0)console.error(`[git-credential]: custom args: ${p.join(" ")}`);if(t==="store"||t==="erase")console.error(`[git-credential]: ${t} ignored`),process.exit(0);if(t!=="get")console.error(`[git-credential]: unknown action: ${t}`),process.exit(1);try{let s=await q5(A5),n=I5(s,"=");N5(n),await w5(n),process.exit(0)}catch(s){console.error(s?.message?s.message:String(s)),process.exit(2)}})}async function w5(e){let{host:t}=e;if(console.error(`[git-credential]: for ${e.protocol}://${e.host}/${e.path??""}`),!t||!K5.includes(t))throw Error(`unknown host: ${t}`);let r=await k5(e);process.stdout.write(`username=${r.username}
122
122
  `),process.stdout.write(`password=${r.password}
123
- `),console.error("[git-credential]: done")}async function k5(e){return{username:"cnb",password:await(0,P5.resolveToken)()}}function N5(e){if(!e.path)return;if(e.path.endsWith(".git"))e.path=e.path.slice(0,-4);else if(e.path.endsWith(".git/info/lfs"))e.path=e.path.slice(0,-13)}function q5(e){return new Promise((t,r)=>{let i=[],p=!1,s=()=>{if(p)return;p=!0,clearTimeout(n),t(Buffer.concat(i).toString("utf-8"))},n=setTimeout(()=>{if(p)return;p=!0,console.error("[git-credential]: timeout occurred"),r(Error("stdin timeout"))},e);process.stdin.on("data",(y)=>{if(i.push(y),y.length===1&&y[0]===10)s()}),process.stdin.on("end",()=>{s()}),process.stdin.on("error",(y)=>{if(p)return;p=!0,clearTimeout(n),r(y)})})}function I5(e,t){return e.split(/(?:\r\n|\r|\n)/).filter(Boolean).map((r)=>{let i=r.indexOf(t),p=i>=0?r.substring(0,i).trim():r.trim(),s=i>=0?r.substring(i+1).trim():"";return{key:p,value:s}}).reduce((r,{key:i,value:p})=>{if(i)r[i]=p;return r},{})}});Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"parseArguments",{enumerable:!0,get:function(){return F5.parseUnknownOptions}});var S5=He(),T5=Dn(),V5=ou(),E5=yu(),W5=bu(),U5=mu(),J5=hu(),Y5=_u(),F5=vt(),G=new S5.Command;G.name("cnb").description("CNB OpenAPI 命令行工具").version("1.9.6","-v, --version","显示版本号").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").option("-s, --short","显示当前仓库的快捷命令").addHelpText("after",(0,T5.getExtraHelpText)());(0,W5.registerLoginCommand)(G);(0,U5.registerLogoutCommand)(G);(0,J5.registerStatusCommand)(G);(0,Y5.registerGitCredentialCommand)(G);(0,V5.registerModuleCommands)(G);(0,E5.registerFallbackAction)(G);G.parseAsync(process.argv);
123
+ `),console.error("[git-credential]: done")}async function k5(e){return{username:"cnb",password:await(0,P5.resolveToken)()}}function N5(e){if(!e.path)return;if(e.path.endsWith(".git"))e.path=e.path.slice(0,-4);else if(e.path.endsWith(".git/info/lfs"))e.path=e.path.slice(0,-13)}function q5(e){return new Promise((t,r)=>{let i=[],p=!1,s=()=>{if(p)return;p=!0,clearTimeout(n),t(Buffer.concat(i).toString("utf-8"))},n=setTimeout(()=>{if(p)return;p=!0,console.error("[git-credential]: timeout occurred"),r(Error("stdin timeout"))},e);process.stdin.on("data",(y)=>{if(i.push(y),y.length===1&&y[0]===10)s()}),process.stdin.on("end",()=>{s()}),process.stdin.on("error",(y)=>{if(p)return;p=!0,clearTimeout(n),r(y)})})}function I5(e,t){return e.split(/(?:\r\n|\r|\n)/).filter(Boolean).map((r)=>{let i=r.indexOf(t),p=i>=0?r.substring(0,i).trim():r.trim(),s=i>=0?r.substring(i+1).trim():"";return{key:p,value:s}}).reduce((r,{key:i,value:p})=>{if(i)r[i]=p;return r},{})}});Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"parseArguments",{enumerable:!0,get:function(){return F5.parseUnknownOptions}});var S5=He(),T5=Dn(),V5=ou(),E5=yu(),W5=bu(),U5=mu(),J5=hu(),Y5=_u(),F5=vt(),G=new S5.Command;G.name("cnb").description("CNB OpenAPI 命令行工具").version("1.9.7","-v, --version","显示版本号").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").option("-s, --short","显示当前仓库的快捷命令").addHelpText("after",(0,T5.getExtraHelpText)());(0,W5.registerLoginCommand)(G);(0,U5.registerLogoutCommand)(G);(0,J5.registerStatusCommand)(G);(0,Y5.registerGitCredentialCommand)(G);(0,V5.registerModuleCommands)(G);(0,E5.registerFallbackAction)(G);G.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-cli",
3
- "version": "1.9.6",
3
+ "version": "1.9.7",
4
4
  "description": "CNB OpenAPI 命令行工具,基于 CNB 平台 Swagger 自动生成,支持 Issues、PR、Git、组织管理等全部 API 操作",
5
5
  "main": "skills/cnb-api/scripts/core/index.js",
6
6
  "bin": {