@cnbcool/cnb-cli 1.15.9 → 1.15.10

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
@@ -150,4 +150,4 @@ PR 页面路径: ${s}
150
150
  登录成功 \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,G.maskToken)(n.access_token)}`),n.refresh_token)console.log(` refresh_token : ${(0,G.maskToken)(n.refresh_token)}`);if(n.id_token)console.log(` id_token : ${(0,G.maskToken)(n.id_token)}`)}let a=Math.floor(Date.now()/1000),l=`https://api.${new URL(r.platformURL).hostname}`,u={access_token:n.access_token,expires_at:a+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,G.saveToken)(u),r.debug)console.log(`Token 已保存到 ${(0,G.getTokenPath)()}`)}catch(s){console.error(`
151
151
  登录失败: ${s.message}`),process.exit(1)}})}});var og=o((so)=>{Object.defineProperty(so,"__esModule",{value:!0});so.registerLogoutCommand=i1;var xI=r1(require("fs")),e1=re(),t1=oe();function r1(e){return e&&e.__esModule?e:{default:e}}function i1(e){e.command("logout").description("退出登录,删除本地保存的 access_token").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=(0,e1.getTokenPath)(),i=(0,t1.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{xI.default.unlinkSync(r),console.log("已成功退出登录。")}catch(s){console.error(`退出登录失败: ${s.message}`),process.exit(1)}})}});var ag=o((po)=>{Object.defineProperty(po,"__esModule",{value:!0});po.registerStatusCommand=a1;var s1=_t(),p1=_e(),n1=re(),o1={workbuddy:"WorkBuddy 远程获取",codebuddy_env:"CNB_TOKEN_FOR_CODEBUDDY 环境变量",env:"CNB_TOKEN 环境变量"};function a1(e){e.command("status").description("检查当前登录状态(token 是否存在、是否过期)").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=await(0,s1.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 来源: ${o1[r.source]}`);return}let i=(0,n1.getTokenPath)(),s=r.store;if(t.debug)console.log(`Token 文件路径 : ${i}`),console.log(`Platform URL : ${s.platform_url||"未知"}`),console.log(`Client ID : ${s.client_id||"未知"}`),console.log(`Expires At : ${new Date(s.expires_at*1000).toLocaleString()}`);if(Math.floor(Date.now()/1000)>=s.expires_at)if(s.refresh_token){if(t.debug)console.log("Token 已过期,尝试使用 refresh_token 刷新...");try{if(await(0,p1.refreshAccessToken)(s),console.log("✅ 已登录。"),t.debug)console.log(" (Token 已自动刷新)")}catch(a){if(t.debug)console.log(`刷新失败: ${a.message}`);console.log("⚠️ 未登录,请执行 `cnb login` 重新授权。")}}else console.log("⚠️ 未登录,请执行 `cnb login` 重新授权。");else console.log("✅ 已登录。")})}});var dg=o((no)=>{Object.defineProperty(no,"__esModule",{value:!0});no.registerGitCredentialCommand=l1;var d1=ve(),c1=ro(),y1=8000;function l1(e){e.command("git-credential <action>").description("作为 git credential helper,向 git 提供 CNB 凭据(仅供 git 内部调用)").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").action(async(t,r,i)=>{let s=i.args.slice(0,-1);if(s.length>0)console.error(`[git-credential]: custom args: ${s.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 p=await b1(y1),n=h1(p,"=");m1(n),await u1(n),process.exit(0)}catch(p){console.error(p?.message?p.message:String(p)),process.exit(2)}})}async function u1(e){let{host:t}=e;console.error(`[git-credential]: for ${e.protocol}://${e.host}/${e.path??""}`);let r=(0,c1.getGitRemoteHosts)();if(!t||r.length===0||!r.includes(t))throw Error(`unknown host: ${t}`);let i=await g1(e);process.stdout.write(`username=${i.username}
152
152
  `),process.stdout.write(`password=${i.password}
153
- `),console.error("[git-credential]: done")}async function g1(e){return{username:"cnb",password:await(0,d1.resolveToken)()}}function m1(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 b1(e){return new Promise((t,r)=>{let i=[],s=!1,p=()=>{if(s)return;s=!0,clearTimeout(n),t(Buffer.concat(i).toString("utf-8"))},n=setTimeout(()=>{if(s)return;s=!0,console.error("[git-credential]: timeout occurred"),r(Error("stdin timeout"))},e);process.stdin.on("data",(a)=>{if(i.push(a),a.length===1&&a[0]===10)p()}),process.stdin.on("end",()=>{p()}),process.stdin.on("error",(a)=>{if(s)return;s=!0,clearTimeout(n),r(a)})})}function h1(e,t){return e.split(/(?:\r\n|\r|\n)/).filter(Boolean).map((r)=>{let i=r.indexOf(t),s=i>=0?r.substring(0,i).trim():r.trim(),p=i>=0?r.substring(i+1).trim():"";return{key:s,value:p}}).reduce((r,{key:i,value:s})=>{if(i)r[i]=s;return r},{})}});Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"parseArguments",{enumerable:!0,get:function(){return z1.parseUnknownOptions}});var f1=pt(),_1=Ao(),v1=Cu(),P1=Du(),j1=ng(),k1=og(),K1=ag(),A1=dg(),z1=Et(),O=new f1.Command;O.name("cnb").description("CNB OpenAPI 命令行工具").version("1.15.9","--version","显示版本号").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").option("-s, --short","显示当前仓库的快捷命令").addHelpText("after",(0,_1.getExtraHelpText)());(0,j1.registerLoginCommand)(O);(0,k1.registerLogoutCommand)(O);(0,K1.registerStatusCommand)(O);(0,A1.registerGitCredentialCommand)(O);(0,v1.registerModuleCommands)(O);(0,P1.registerFallbackAction)(O);O.parseAsync(process.argv);
153
+ `),console.error("[git-credential]: done")}async function g1(e){return{username:"cnb",password:await(0,d1.resolveToken)()}}function m1(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 b1(e){return new Promise((t,r)=>{let i=[],s=!1,p=()=>{if(s)return;s=!0,clearTimeout(n),t(Buffer.concat(i).toString("utf-8"))},n=setTimeout(()=>{if(s)return;s=!0,console.error("[git-credential]: timeout occurred"),r(Error("stdin timeout"))},e);process.stdin.on("data",(a)=>{if(i.push(a),a.length===1&&a[0]===10)p()}),process.stdin.on("end",()=>{p()}),process.stdin.on("error",(a)=>{if(s)return;s=!0,clearTimeout(n),r(a)})})}function h1(e,t){return e.split(/(?:\r\n|\r|\n)/).filter(Boolean).map((r)=>{let i=r.indexOf(t),s=i>=0?r.substring(0,i).trim():r.trim(),p=i>=0?r.substring(i+1).trim():"";return{key:s,value:p}}).reduce((r,{key:i,value:s})=>{if(i)r[i]=s;return r},{})}});Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"parseArguments",{enumerable:!0,get:function(){return z1.parseUnknownOptions}});var f1=pt(),_1=Ao(),v1=Cu(),P1=Du(),j1=ng(),k1=og(),K1=ag(),A1=dg(),z1=Et(),O=new f1.Command;O.name("cnb").description("CNB OpenAPI 命令行工具").version("1.15.10","--version","显示版本号").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").option("-s, --short","显示当前仓库的快捷命令").addHelpText("after",(0,_1.getExtraHelpText)());(0,j1.registerLoginCommand)(O);(0,k1.registerLogoutCommand)(O);(0,K1.registerStatusCommand)(O);(0,A1.registerGitCredentialCommand)(O);(0,v1.registerModuleCommands)(O);(0,P1.registerFallbackAction)(O);O.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-cli",
3
- "version": "1.15.9",
3
+ "version": "1.15.10",
4
4
  "description": "CNB OpenAPI 命令行工具,基于 CNB 平台 Swagger 自动生成,支持 Issues、PR、Git、组织管理等全部 API 操作",
5
5
  "main": "skills/cnb-api/scripts/core/index.js",
6
6
  "bin": {