@cnbcool/cnb-cli 1.13.2 → 1.13.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 +1 -1
package/dist/index.js
CHANGED
|
@@ -149,4 +149,4 @@ PR 页面路径: ${s}
|
|
|
149
149
|
登录成功 \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(`
|
|
150
150
|
登录失败: ${s.message}`),process.exit(1)}})}});var sg=o((ro)=>{Object.defineProperty(ro,"__esModule",{value:!0});ro.registerLogoutCommand=OI;var QI=GI(require("fs")),HI=re(),BI=oe();function GI(e){return e&&e.__esModule?e:{default:e}}function OI(e){e.command("logout").description("退出登录,删除本地保存的 access_token").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=(0,HI.getTokenPath)(),i=(0,BI.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{QI.default.unlinkSync(r),console.log("已成功退出登录。")}catch(s){console.error(`退出登录失败: ${s.message}`),process.exit(1)}})}});var pg=o((io)=>{Object.defineProperty(io,"__esModule",{value:!0});io.registerStatusCommand=t1;var CI=ft(),DI=_e(),xI=re(),e1={workbuddy:"WorkBuddy 远程获取",codebuddy_env:"CNB_TOKEN_FOR_CODEBUDDY 环境变量",env:"CNB_TOKEN 环境变量"};function t1(e){e.command("status").description("检查当前登录状态(token 是否存在、是否过期)").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let r=await(0,CI.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 来源: ${e1[r.source]}`);return}let i=(0,xI.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,DI.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 ng=o((so)=>{Object.defineProperty(so,"__esModule",{value:!0});so.registerGitCredentialCommand=p1;var r1=ve(),i1=["cnb.cool","cnb.woa.com"],s1=8000;function p1(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 d1(s1),n=c1(p,"=");a1(n),await n1(n),process.exit(0)}catch(p){console.error(p?.message?p.message:String(p)),process.exit(2)}})}async function n1(e){let{host:t}=e;if(console.error(`[git-credential]: for ${e.protocol}://${e.host}/${e.path??""}`),!t||!i1.includes(t))throw Error(`unknown host: ${t}`);let r=await o1(e);process.stdout.write(`username=${r.username}
|
|
151
151
|
`),process.stdout.write(`password=${r.password}
|
|
152
|
-
`),console.error("[git-credential]: done")}async function o1(e){return{username:"cnb",password:await(0,r1.resolveToken)()}}function a1(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 d1(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 c1(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 _1.parseUnknownOptions}});var y1=st(),l1=ko(),u1=Gu(),g1=Ou(),m1=ig(),b1=sg(),h1=pg(),f1=ng(),_1=Rt(),O=new y1.Command;O.name("cnb").description("CNB OpenAPI 命令行工具").version("1.13.
|
|
152
|
+
`),console.error("[git-credential]: done")}async function o1(e){return{username:"cnb",password:await(0,r1.resolveToken)()}}function a1(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 d1(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 c1(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 _1.parseUnknownOptions}});var y1=st(),l1=ko(),u1=Gu(),g1=Ou(),m1=ig(),b1=sg(),h1=pg(),f1=ng(),_1=Rt(),O=new y1.Command;O.name("cnb").description("CNB OpenAPI 命令行工具").version("1.13.4","--version","显示版本号").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").option("-s, --short","显示当前仓库的快捷命令").addHelpText("after",(0,l1.getExtraHelpText)());(0,m1.registerLoginCommand)(O);(0,b1.registerLogoutCommand)(O);(0,h1.registerStatusCommand)(O);(0,f1.registerGitCredentialCommand)(O);(0,u1.registerModuleCommands)(O);(0,g1.registerFallbackAction)(O);O.parseAsync(process.argv);
|