@cnbcool/cnb-cli 1.10.3 → 1.10.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.
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -123,4 +123,4 @@ PR 页面路径: ${s}
|
|
|
123
123
|
登录成功 \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,R.maskToken)(n.access_token)}`),n.refresh_token)console.log(` refresh_token : ${(0,R.maskToken)(n.refresh_token)}`);if(n.id_token)console.log(` id_token : ${(0,R.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,R.saveToken)(u),r.debug)console.log(`Token 已保存到 ${(0,R.getTokenPath)()}`)}catch(s){console.error(`
|
|
124
124
|
登录失败: ${s.message}`),process.exit(1)}})}});var Iu=o((Zn)=>{Object.defineProperty(Zn,"__esModule",{value:!0});Zn.registerLogoutCommand=$S;var FS=YS(require("fs")),JS=ee(),MS=pe();function YS(e){return e&&e.__esModule?e:{default:e}}function $S(e){e.command("logout").description("退出登录,删除本地保存的 access_token").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=(0,JS.getTokenPath)(),i=(0,MS.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{FS.default.unlinkSync(r),console.log("已成功退出登录。")}catch(s){console.error(`退出登录失败: ${s.message}`),process.exit(1)}})}});var Vu=o((Xn)=>{Object.defineProperty(Xn,"__esModule",{value:!0});Xn.registerStatusCommand=BS;var ZS=gt(),XS=he(),QS=ee(),HS={workbuddy:"WorkBuddy 远程获取",codebuddy_env:"CNB_TOKEN_FOR_CODEBUDDY 环境变量",env:"CNB_TOKEN 环境变量"};function BS(e){e.command("status").description("检查当前登录状态(token 是否存在、是否过期)").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=await(0,ZS.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 来源: ${HS[r.source]}`);return}let i=(0,QS.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,XS.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 Eu=o((Qn)=>{Object.defineProperty(Qn,"__esModule",{value:!0});Qn.registerGitCredentialCommand=LS;var GS=_e(),RS=["cnb.cool","cnb.woa.com"],OS=8000;function LS(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 eW(OS),n=tW(p,"=");xS(n),await DS(n),process.exit(0)}catch(p){console.error(p?.message?p.message:String(p)),process.exit(2)}})}async function DS(e){let{host:t}=e;if(console.error(`[git-credential]: for ${e.protocol}://${e.host}/${e.path??""}`),!t||!RS.includes(t))throw Error(`unknown host: ${t}`);let r=await CS(e);process.stdout.write(`username=${r.username}
|
|
125
125
|
`),process.stdout.write(`password=${r.password}
|
|
126
|
-
`),console.error("[git-credential]: done")}async function CS(e){return{username:"cnb",password:await(0,GS.resolveToken)()}}function xS(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 eW(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 tW(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 dW.parseUnknownOptions}});var rW=et(),iW=ao(),sW=zu(),pW=wu(),nW=Wu(),oW=Iu(),aW=Vu(),cW=Eu(),dW=Tt(),O=new rW.Command;O.name("cnb").description("CNB OpenAPI 命令行工具").version("1.10.
|
|
126
|
+
`),console.error("[git-credential]: done")}async function CS(e){return{username:"cnb",password:await(0,GS.resolveToken)()}}function xS(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 eW(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 tW(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 dW.parseUnknownOptions}});var rW=et(),iW=ao(),sW=zu(),pW=wu(),nW=Wu(),oW=Iu(),aW=Vu(),cW=Eu(),dW=Tt(),O=new rW.Command;O.name("cnb").description("CNB OpenAPI 命令行工具").version("1.10.4","-v, --version","显示版本号").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").option("-s, --short","显示当前仓库的快捷命令").addHelpText("after",(0,iW.getExtraHelpText)());(0,nW.registerLoginCommand)(O);(0,oW.registerLogoutCommand)(O);(0,aW.registerStatusCommand)(O);(0,cW.registerGitCredentialCommand)(O);(0,sW.registerModuleCommands)(O);(0,pW.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.10.
|
|
3
|
+
"version": "1.10.4",
|
|
4
4
|
"description": "CNB OpenAPI 命令行工具,基于 CNB 平台 Swagger 自动生成,支持 Issues、PR、Git、组织管理等全部 API 操作",
|
|
5
5
|
"main": "skills/cnb-api/scripts/core/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"author": "",
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@cnbcool/cnb-api-generate": "^2.
|
|
45
|
+
"@cnbcool/cnb-api-generate": "^2.9.0",
|
|
46
46
|
"bun": "^1.3.9",
|
|
47
47
|
"skills": "^1.4.4"
|
|
48
48
|
}
|