@cnbcool/cnb-cli 1.17.35 → 1.17.37
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
|
@@ -297,4 +297,4 @@ PR 页面路径: ${s}
|
|
|
297
297
|
登录成功 \uD83C\uDF89`),i.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,fe.maskToken)(n.access_token)}`),n.refresh_token)console.log(` refresh_token : ${(0,fe.maskToken)(n.refresh_token)}`);if(n.id_token)console.log(` id_token : ${(0,fe.maskToken)(n.id_token)}`)}let o=Math.floor(Date.now()/1000),c=`https://api.${new URL(i.platformURL).host}`,l={access_token:n.access_token,expires_at:o+n.expires_in,platform_url:i.platformURL,client_id:i.clientID,login_host:c};if(n.refresh_token)l.refresh_token=n.refresh_token;if((0,fe.saveToken)(l),i.debug)console.log(`Token 已保存到 ${(0,fe.getTokenPath)()}`)}catch(s){console.error(`
|
|
298
298
|
登录失败: ${s.message}`),process.exit(1)}})}});var b0=d((Dc)=>{Object.defineProperty(Dc,"__esModule",{value:!0});Dc.registerLogoutCommand=R$;var N$=S$(require("fs")),W$=Se(),T$=Re(),I$=$t();function S$(e){return e&&e.__esModule?e:{default:e}}function R$(e){e.command("logout").description("退出登录,删除本地保存的 access_token").option("--host <string>","只退出指定平台域名的登录态(如 cnb.cool),不传则退出全部域名的登录态").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let i=(0,W$.getTokenPath)();if(t.host){if((0,I$.removeToken)(t.host))console.log(`已成功退出 ${t.host} 的登录。`);else console.log(`${t.host} 当前未登录,无需退出。`);return}let{auths:r}=(0,T$.readTokenFile)(),s=Object.keys(r);if(!s.length){console.log("当前未登录,无需退出。");return}if(t.debug){console.log(`Token 文件路径: ${i}`);for(let p of s)console.log(`${p}: Platform URL=${r[p].platform_url}, Client ID=${r[p].client_id}`)}try{N$.default.unlinkSync(i),console.log(`已成功退出全部登录(${s.join("、")})。`)}catch(p){console.error(`退出登录失败: ${p.message}`),process.exit(1)}})}});var h0=d((Cc)=>{Object.defineProperty(Cc,"__esModule",{value:!0});Cc.registerStatusCommand=M$;var V$=Fr(),F$=Zt(),J$=Se(),L$={workbuddy:"WorkBuddy 远程获取",codebuddy_env:"CNB_TOKEN_FOR_CODEBUDDY 环境变量",env:"CNB_TOKEN 环境变量"};function M$(e){e.command("status").description("检查当前登录状态(token 是否存在、是否过期)").option("--host <string>","查看指定平台域名的登录态(如 cnb.cool),不传则按当前仓库 git remote、CNB_API_ENDPOINT 的顺序推断,都没有对应登录态时取最近一次保存的").option("--debug","打印调试信息",!1).helpOption("-h, --help","显示帮助文档").action(async(t)=>{let i=await(0,V$.resolveTokenSource)(t.host);if(i.source==="none"){console.log(i.reason?`⚠️ ${i.reason}`:"⚠️ 未登录,请执行 `cnb login` 进行授权。");return}if(i.source!=="file"){if(console.log("✅ 已登录。"),t.debug)console.log(` Token 来源: ${L$[i.source]}`);return}let r=(0,J$.getTokenPath)(),s=i.store;if(t.debug)console.log(`Token 文件路径 : ${r}`),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,F$.refreshAccessToken)(s),console.log("✅ 已登录。"),t.debug)console.log(" (Token 已自动刷新)")}catch(o){if(t.debug)console.log(`刷新失败: ${o.message}`);console.log("⚠️ 未登录,请执行 `cnb login` 重新授权。")}}else console.log("⚠️ 未登录,请执行 `cnb login` 重新授权。");else console.log("✅ 已登录。")})}});var _0=d((xc)=>{Object.defineProperty(xc,"__esModule",{value:!0});xc.registerGitCredentialCommand=Y$;var $$=Xt(),Z$=xe(),X$=8000;function Y$(e){e.command("git-credential <action>").description("作为 git credential helper,向 git 提供 CNB 凭据(仅供 git 内部调用)").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").action(async(t,i,r)=>{let s=r.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 G$(X$),n=O$(p,"=");B$(n),await Q$(n),process.exit(0)}catch(p){console.error(p?.message?p.message:String(p)),process.exit(2)}})}async function Q$(e){let{host:t}=e;console.error(`[git-credential]: for ${e.protocol}://${e.host}/${e.path??""}`);let i=(0,Z$.getGitRemoteHosts)();if(!t||i.length===0||!i.includes(t))throw Error(`unknown host: ${t}`);let r=await H$(t);process.stdout.write(`username=${r.username}
|
|
299
299
|
`),process.stdout.write(`password=${r.password}
|
|
300
|
-
`),console.error("[git-credential]: done")}async function H$(e){return{username:"cnb",password:await(0,$$.resolveToken)(e)}}function B$(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 G$(e){return new Promise((t,i)=>{let r=[],s=!1,p=()=>{if(s)return;s=!0,clearTimeout(n),t(Buffer.concat(r).toString("utf-8"))},n=setTimeout(()=>{if(s)return;s=!0,console.error("[git-credential]: timeout occurred"),i(Error("stdin timeout"))},e);process.stdin.on("data",(o)=>{if(r.push(o),o.length===1&&o[0]===10)p()}),process.stdin.on("end",()=>{p()}),process.stdin.on("error",(o)=>{if(s)return;s=!0,clearTimeout(n),i(o)})})}function O$(e,t){return e.split(/(?:\r\n|\r|\n)/).filter(Boolean).map((i)=>{let r=i.indexOf(t),s=r>=0?i.substring(0,r).trim():i.trim(),p=r>=0?i.substring(r+1).trim():"";return{key:s,value:p}}).reduce((i,{key:r,value:s})=>{if(r)i[r]=s;return i},{})}});Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"parseArguments",{enumerable:!0,get:function(){return s9.parseUnknownOptions}});var E$=jr(),D$=hy(),C$=o0(),x$=a0(),e9=m0(),t9=b0(),i9=h0(),r9=_0(),s9=Or(),Pe=new E$.Command;Pe.name("cnb").description("CNB OpenAPI 命令行工具").version("1.17.
|
|
300
|
+
`),console.error("[git-credential]: done")}async function H$(e){return{username:"cnb",password:await(0,$$.resolveToken)(e)}}function B$(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 G$(e){return new Promise((t,i)=>{let r=[],s=!1,p=()=>{if(s)return;s=!0,clearTimeout(n),t(Buffer.concat(r).toString("utf-8"))},n=setTimeout(()=>{if(s)return;s=!0,console.error("[git-credential]: timeout occurred"),i(Error("stdin timeout"))},e);process.stdin.on("data",(o)=>{if(r.push(o),o.length===1&&o[0]===10)p()}),process.stdin.on("end",()=>{p()}),process.stdin.on("error",(o)=>{if(s)return;s=!0,clearTimeout(n),i(o)})})}function O$(e,t){return e.split(/(?:\r\n|\r|\n)/).filter(Boolean).map((i)=>{let r=i.indexOf(t),s=r>=0?i.substring(0,r).trim():i.trim(),p=r>=0?i.substring(r+1).trim():"";return{key:s,value:p}}).reduce((i,{key:r,value:s})=>{if(r)i[r]=s;return i},{})}});Object.defineProperty(exports,"__esModule",{value:!0});Object.defineProperty(exports,"parseArguments",{enumerable:!0,get:function(){return s9.parseUnknownOptions}});var E$=jr(),D$=hy(),C$=o0(),x$=a0(),e9=m0(),t9=b0(),i9=h0(),r9=_0(),s9=Or(),Pe=new E$.Command;Pe.name("cnb").description("CNB OpenAPI 命令行工具").version("1.17.37","--version","显示版本号").allowUnknownOption().allowExcessArguments().helpOption("-h, --help","显示帮助文档").option("-s, --short","显示当前仓库的快捷命令").addHelpText("after",(0,D$.getExtraHelpText)());(0,e9.registerLoginCommand)(Pe);(0,t9.registerLogoutCommand)(Pe);(0,i9.registerStatusCommand)(Pe);(0,r9.registerGitCredentialCommand)(Pe);(0,C$.registerModuleCommands)(Pe);(0,x$.registerFallbackAction)(Pe);Pe.parseAsync(process.argv);
|