UNPKG

@ppgjs/cli

Version:

PpgJs's command line tools

11 lines (10 loc) 50.5 kB
#!/usr/bin/env node "use strict";const f$1=require("cac"),c12=require("c12"),u=require("fs-extra"),l$1=require("kolorist"),o$3=require("enquirer"),fs=require("fs"),e$2=require("path"),pkgTypes=require("pkg-types"),simpleGit=require("simple-git"),axios=require("axios"),b$2=require("dayjs"),querystring=require("querystring"),ejs=require("ejs"),fastGlob=require("fast-glob"),prettier=require("prettier"),ping=require("ping"),f=require("dns"),e$3=require("bumpp"),c$2=require("form-data"),semver=require("semver"),h$3=require("archiver");function _interopDefaultCompat(F){return F&&typeof F=="object"&&"default"in F?F.default:F}function _interopNamespaceCompat(F){if(F&&typeof F=="object"&&"default"in F)return F;const d=Object.create(null);if(F)for(const B in F)d[B]=F[B];return d.default=F,d}const f__default$1=_interopDefaultCompat(f$1),u__default=_interopDefaultCompat(u),l__namespace=_interopNamespaceCompat(l$1),o__default=_interopDefaultCompat(o$3),e__default=_interopDefaultCompat(e$2),b__default=_interopDefaultCompat(b$2),f__default=_interopDefaultCompat(f),e__default$1=_interopDefaultCompat(e$3),c__default=_interopDefaultCompat(c$2),h__default=_interopDefaultCompat(h$3),e$1={useRemote:"origin"};async function execCommand(F,d=[],B={}){const{execa:y}=await import("execa");return(await y(F,d,B))?.stdout?.trim()||""}function createMkdir(F){u.existsSync(F)||(u.mkdirSync(F,{recursive:!0}),console.log("\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u521B\u5EFA"))}const t$1=console.log,n$2=(F="")=>t$1(l__namespace.yellow(F)),g=(F="")=>t$1(l__namespace.green(F)),s=(F="")=>t$1(l__namespace.red(F)),r$1=(F="")=>t$1(l__namespace.lightBlue(F)),c$1=(F="")=>t$1(l__namespace.lightMagenta(F)),RegGitVersion=/^.*[0-9]{1,4}(\.[0-9]{1,4}){2,3}$/,RegResultSplitToArr=/\n{1,}\s*/,p$1=async(F,d)=>{try{const B=[execCommand(`git tag -d ${F}`)];d.includes(`refs/tags/${F}`)&&B.push(execCommand("git",["push",e$1.useRemote,`:refs/tags/${F}`])),await Promise.all(B)}catch(B){console.warn(`error:\u5220\u9664tag:${F}\u9519\u8BEF`,B)}};async function deleteTag(F=""){let d=[];if(F&&d.push(F),!F){const v=(await execCommand("git tag -l")).split(RegResultSplitToArr),{tags:k}=await o__default.prompt([{name:"tags",type:"multiselect",message:"\u8BF7\u9009\u62E9\u9700\u8981\u5220\u9664\u7684tag",choices:v.map(x=>({name:x})),validate(x){return!!x.length||"\u8BF7\u9009\u62E9\u81F3\u5C11\u4E00\u4E2Atag"}}]);d=k}const B=await execCommand(`git ls-remote --tags ${e$1.useRemote}`),y=[];d.forEach(v=>{y.push(p$1(v,B))}),await Promise.all(y),g("\u64CD\u4F5C\u5B8C\u6210\u4E86")}var m$1=Object.defineProperty,h$2=(F,d,B)=>d in F?m$1(F,d,{enumerable:!0,configurable:!0,writable:!0,value:B}):F[d]=B,n$1=(F,d,B)=>(h$2(F,typeof d!="symbol"?d+"":d,B),B);class VersionInfo{constructor(){n$1(this,"projectName",""),n$1(this,"originBranch",""),n$1(this,"versionMainBranch",""),n$1(this,"versionNumber",""),n$1(this,"projectMainBranch",""),n$1(this,"funcName","")}async init(){await this.getProjectName(),this.originBranch=await execCommand("git",["symbolic-ref","--short","HEAD"]),n$2(`\u5F53\u524D\u5206\u652F:${this.originBranch}`);const d=this.originBranch.split("/")[0];verifyVersion(d)&&(this.versionNumber=d,this.setMainBranch()),await Promise.all([this.setProjectMainBranch()]),await checkWorkingNoCommit(),watchProcessAccident(backToOriginalBranch);try{await execCommand("git",["remote","update",e$1.useRemote,"--prune"])}catch(B){console.log("\u5237\u65B0\u5206\u652F\u9519\u8BEF: ",B)}}setMainBranch(){this.versionMainBranch=`${this.versionNumber}/main`}async setVersionNumber(d){const{version:B}=await o__default.prompt([mergePromptOptions(PromptMap.inputVersion,JSON.parse(JSON.stringify({default:this.versionNumber,message:d})))]);this.versionNumber=B,n$2(`\u5F53\u524D\u7248\u672C:${this.versionNumber}`),this.setMainBranch(),n$2(`\u5F53\u524D\u7248\u672C\u4E3B\u5206\u652F:${this.versionMainBranch}`)}async setProjectMainBranch(){const[d,B]=await Promise.all([checkBranch("master"),checkBranch("main")]);d.remoteExist?this.projectMainBranch="master":B.remoteExist?this.projectMainBranch="main":(s(`\u5F53\u524D\u9879\u76EE\u7F3A\u5C11\u4E3B\u5206\u652F:${this.versionMainBranch}`),await exitWithError())}setFuncName(d){this.funcName=d}async getFuncFullName(){return this.funcName||(s("\u62B1\u6B49\u6CA1\u6709\u627E\u5230\u529F\u80FD\u5206\u652F"),await exitWithError()),`${this.versionNumber}/${this.funcName}`}async getProjectName(){const d=await getPackageJsonAttr({packageJson:["name"]});d&&d.name&&(this.projectName=d.name,n$2(`\u5F53\u524D\u9879\u76EE\u540D\u79F0:${d.name}`))}}const versionInfo=new VersionInfo;var EGitVersionActionType=(F=>(F.new="new",F.merge="merge",F.mq="mq",F.build="build",F.publish="publish",F.check="check",F.fix="fix",F.move="move",F.test="test",F))(EGitVersionActionType||{});const actionDescription={new:"\u521B\u5EFA\u65B0\u7684\u7248\u672C\u529F\u80FD\u5206\u652F",merge:"\u5408\u5E76\u529F\u80FD\u5206\u652F\u5230\u7248\u672C\u4E3B\u5206\u652F",mq:"\u53D1\u8D77\u5408\u5E76\u8BF7\u6C42\uFF1A\u529F\u80FD\u5206\u652F->\u7248\u672C\u4E3B\u5206\u652F",test:"\u5C06\u7248\u672C\u4E3B\u5206\u652F\u5408\u5E76\u5230test\u5206\u652F",build:"\u5207\u6362\u5230\u7248\u672C\u4E3B\u5206\u652F\uFF0C\u7B49\u5F85\u6253\u5305",publish:"\u53D1\u5E03\u7248\u672C\uFF0C\u7248\u672C\u4E3B\u5206\u652F\u5408\u5E76\u5230master\u5206\u652F",check:"\u68C0\u6D4B\u5F53\u524D\u7248\u672C\u7684\u5206\u652F\u662F\u5426\u90FD\u5408\u5E76\u5230\u4E3B\u5206\u652F",fix:"\u521B\u5EFA\u4E00\u4E2A\u4FEE\u590D\u5206\u652F\uFF0C\u4FEE\u590D\u7EBF\u4E0A\u7248\u672CBug",move:"\u7248\u672C\u529F\u80FD\u5206\u652F\u8FC1\u79FB\u5230\u4E0B\u4E2A\u7248\u672C"},chooseActionType=async F=>{let d;if(F){const B=EGitVersionActionType[F];B&&(d=B)}if(!d){const B=Object.keys(EGitVersionActionType).map(v=>({name:v,message:`${v.padEnd(10)}${actionDescription[v]}`})),{choicesActionType:y}=await o__default.prompt([{name:"choicesActionType",type:"select",message:"\u8BF7\u9009\u62E9\u64CD\u4F5C\u7C7B\u578B",choices:B}]);d=y}return d},chooseIsBuild=async(F=!0)=>{const{isBuild:d}=await o__default.prompt([{name:"isBuild",type:"confirm",initial:F,message:"\u662F\u5426\u9700\u8981\u7F16\u8BD1"}]);return d},chooseAnCheck=async(F,d=!0)=>{const{isCheck:B}=await o__default.prompt([{name:"isCheck",type:"confirm",initial:d,message:F}]);return B},chooseBuildEnv=async()=>{const{env:F}=await o__default.prompt([{name:"env",type:"select",message:"\u8BF7\u9009\u62E9\u64CD\u4F5C\u7C7B\u578B",choices:[{name:"dev",message:`${"dev".padEnd(8)}\u5F00\u53D1\u73AF\u5883`},{name:"test",message:`${"test".padEnd(8)}\u6D4B\u8BD5\u73AF\u5883`},{name:"prod",message:`${"prod".padEnd(8)}\u751F\u4EA7\u73AF\u5883`}]}]);return F},chooseOfficialBuildProject=async()=>{const{project:F}=await o__default.prompt([{name:"project",type:"select",message:"\u8BF7\u9009\u62E9\u8981\u6253\u5305\u7684\u9879\u76EE",choices:[{name:"open"},{name:"index"}]}]);return F},chooseMergeRequestTargetBranch=async(F,d=0)=>{const{branchName:B}=await o__default.prompt([{name:"branchName",type:"select",initial:d,message:"\u8BF7\u9009\u62E9\u76EE\u6807\u5206\u652F\uFF0C(\u9ED8\u8BA4\u7248\u672C\u4E3B\u5206\u652F)",choices:F.map(y=>({name:y}))}]);return B};async function createUpdateMdFile(F=!0,d=!1,B=""){const y=e$2.join(process.cwd(),"doc","update.md");if(!F&&u.existsSync(y))return d&&c$1(`Warn: ${y} \u5DF2\u5B58\u5728`),!1;const v=readStaticTemplateFileSync("update_md.ejs");if(typeof v=="boolean")return s("Error: \u521B\u5EFAupdate.md\u5931\u8D25"),!1;const k=ejs.render(v,{version:B}),x=await prettier.format(k,{parser:"markdown"});return u.writeFileSync(y,x),!0}async function openUpdateMdFile(){try{const F=await fastGlob.glob(["**/doc/update.md"],{ignore:["**/node_modules/**"]});if(F.length)return(await import("open")).default(F[0]),await r$1(`\u6253\u5F00 ${versionInfo.versionNumber} \u7248\u672C\u5347\u7EA7\u6B65\u9AA4\u6587\u6863`),!0}catch(F){console.log("openUpdateMdFile Error:",F)}return!1}async function openAndClearUpdateMdFile(){const F=await fastGlob.glob(["**/doc/update.md"],{ignore:["**/node_modules/**"]});if(!F.length)return;const d=await execCommand("uname"),B=e$2.resolve(process.cwd(),F[0]);let y="";if(d==="Darwin")y=e$2.resolve(`/tmp/${versionInfo.projectName}.${versionInfo.versionNumber}.update.md`),u.copyFileSync(B,y);else{const v="C:/tmp";createMkdir(v),y=e$2.join(v,`./${versionInfo.projectName}.${versionInfo.versionNumber}.update.md`)}u.copyFileSync(B,y),await createUpdateMdFile(),(await import("open")).default(y)}function backToOriginalBranch(){return gitCheckoutBranch(versionInfo.originBranch)}async function mergeAToB(F,d){r$1(`\u5408\u5E76\u5206\u652F:${F} to ${d}`),await gitCheckoutBranch(F,"",!1),await gitPull(!1),await gitCheckoutBranch(d),await gitPull(!1);try{await execCommand("git",["merge",F,"--no-edit"])}catch{terminalLog.start("\u7B49\u5F85\u89E3\u51B3\u5408\u5E76\u51B2\u7A81"),await verifyMergeStatus()}await gitPush(),terminalLog.SuccessEnd(`\u5408\u5E76\u5206\u652F:${F} to ${d} \u5408\u5E76\u5B8C\u6210`)}async function gitPullMainNewCode(){await gitCheckoutBranch(versionInfo.projectMainBranch),await gitPull(!0)}async function checkInvalidBranch(){return versionInfo.originBranch==="master"||versionInfo.originBranch==="main"||versionInfo.originBranch.endsWith("/main")?(s(`\u5F53\u524D\u5206\u652F ${versionInfo.originBranch} \u9519\u8BEF\uFF0C\u4E0D\u80FD\u8FDB\u884C\u64CD\u4F5C`),exitWithError()):!0}async function gitGetCurrentBranch(){return execCommand("git",["symbolic-ref","--short","HEAD"])}function getGitlabTokenPath(){const F=process.env.HOME;return F?e__default.join(F,"gitlab.token"):(s("\u6CA1\u6709\u627E\u5230\u7CFB\u7EDF\u9ED8\u8BA4\u8DEF\u5F84"),"")}function deleteGitlabToken(){u.writeFileSync(getGitlabTokenPath(),"")}async function initGitToken(){if(await readGitlabToken({showError:!1}))return!0;const{tempToken:F}=await o__default.prompt({name:"tempToken",type:"text",message:"\u8BF7\u586B\u5199\u4E34\u65F6\u4EE4\u724C",validate:B=>B.trim().length?!0:"\u8BF7\u8F93\u5165\u6709\u6548\u7684\u5B57\u7B26\u4E32"}),d=getGitlabTokenPath();return d?(u.writeFileSync(d,F),!0):!1}function readGitlabToken({showError:F}={showError:!0}){const d="gitlab.token",B=getGitlabTokenPath();if(!B)return"";const y=process.env.HOME;try{u.statSync(B)}catch{return s(`\u6CA1\u6709\u627E\u5230 ${B} \u6587\u4EF6`),n$2(`\u8BF7\u521B\u5EFA\u5E76\u5199\u5728 ${y} \u76EE\u5F55\u4E0B\u7684 ${d} \u6587\u4EF6\u4E2D\uFF0C\u5185\u5BB9\u4E3AGitLab\u4E2A\u4EBA\u8BBF\u95EE\u4EE4\u724C`),r$1("\u5BFC\u822A\u94FE\u63A5: http://git.rantron.biz:3002/-/profile/personal_access_tokens"),""}let v="";try{v=u.readFileSync(B,{encoding:"utf8"}).trim(),v||s(`${B} \u6587\u4EF6\u6CA1\u6709\u5185\u5BB9`)}catch{F&&s(`\u8BFB\u53D6 ${B} \u6587\u4EF6\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u662F\u5426\u5B58\u5728`)}return v}async function getGitlabProjectId(){const{value:F=""}=await gitProject.getConfig(`remote.${e$1.useRemote}.url`),d=F?.match(/\/([^/]+\/[^/]+)\.git$/);if(d&&d[1]){const B=d[1];return encodeURIComponent(B)}throw new Error(`\u83B7\u53D6 \u9879\u76EEid \u9519\u8BEF\u5566 ${F}`)}async function getGitlabLaunchMergeRequestByProjectId({projectId:F,gitlabToken:d,originBranch:B,targetBranch:y}){try{const v=await new axios.Axios({headers:{"PRIVATE-TOKEN":d}}).post(`http://git.rantron.biz:3002/api/v4/projects/${F}/merge_requests`,querystring.stringify({source_branch:B,target_branch:y,title:`new merge request ${B} -> ${y}`})),k=JSON.parse(v.data);if(k.iid)return r$1(`\u521B\u5EFA\u5408\u5E76\u8BF7\u6C42\u6210\u529F ${B} -> ${y} \uFF0C\u8BF7\u6C42id\uFF1A${k.iid}\uFF0C\u627E\u9879\u76EE\u8D1F\u8D23\u4EBA\u8FDB\u884C\u5BA1\u6838`),r$1(`\u5BFC\u822A\u94FE\u63A5: ${k.web_url}`),!0;if(k.message)console.log(`${l__namespace.red("\u8BF7\u6C42\u5408\u5E76\u53D1\u751F\u9519\u8BEF\uFF0C")}${l__namespace.lightMagenta(`\u9519\u8BEF\u4FE1\u606F\uFF1A${k.message}`)}`);else throw k}catch(v){console.log("\u{1F3F7}\uFE0F ~ getGitlabLaunchMergeRequestByProjectId error:",v),deleteGitlabToken(),s(v)}return!1}async function checkWorkingStatus(){return execCommand("git",["status"])}async function checkWorkingNoCommit(){return(await checkWorkingStatus()).includes("nothing to commit")?!0:(s("\u5F53\u524D\u5206\u652F\u8FD8\u6CA1\u63D0\u4EA4\uFF0C\u8BF7\u63D0\u4EA4\u540E\u518D\u64CD\u4F5C"),await exitWithError(),!1)}async function verifyMergeStatus(){return await sleep(),(await checkWorkingStatus()).includes("nothing to commit")?!0:verifyMergeStatus()}async function gitPush(F=!0,d=""){const B=d||await gitGetCurrentBranch();try{const y=await execCommand("git",["push","-u",e$1.useRemote,B]);return F&&g(`\u63A8\u9001\u5206\u652F ${B} \u5230 \u8FDC\u7A0B ${e$1.useRemote} `),y}catch(y){return s(`\u63A8\u9001\u5931\u8D25 ${B} `),Promise.reject(y)}}async function gitPull(F=!0){const d=await execCommand("git",["pull"]);if(F){const B=await gitGetCurrentBranch();g(`\u62C9\u53D6 ${B} \u5206\u652F\u6700\u65B0\u4EE3\u7801`)}return d}async function gitCheckoutBranch(F,d="",B=!0){return await gitGetCurrentBranch()===F||(await execCommand("git",["checkout",F]),B&&g(d||`\u5207\u6362\u5206\u652F\u5230 ${F} `)),!0}async function gitDeleteBranch(F,d={deleteRemote:!1,deleteLocal:!0,showLog:!0,logMessage:""}){if(d.deleteLocal&&await execCommand("git",["branch","-d",F]),d.deleteRemote){if(F.includes("main"))throw new Error("delete protected branches using");await execCommand("git",["push",e$1.useRemote,"--delete",F])}(d.deleteLocal||d.deleteRemote)&&d.showLog&&g(d?.logMessage||`\u5220\u9664\u5206\u652F ${F} \u6210\u529F`)}function verifyVersion(F){return RegGitVersion.test(F)}async function checkBranch(F){const[d,B]=await Promise.all([execCommand("git branch"),execCommand("git branch -r")]),y=d.split(RegResultSplitToArr).map(j=>j.replace(/\*\s/,"")),v=B.split(RegResultSplitToArr),k=y.includes(F),x=!!v.find(j=>j===`${e$1.useRemote}/${F}`);return{remoteExist:x,localExist:k,allExist:x&&k,allNotExist:!x&&!k}}async function deleteLocalVersionOriginMain(){return await gitDeleteBranch(versionInfo.versionMainBranch,{showLog:!1}),!0}async function checkVersionMainBranch(F=versionInfo.versionMainBranch){const d=async(y=!0)=>{await gitPush(y,F),await deleteLocalVersionOriginMain()},B=await checkBranch(F);B.allNotExist?(await gitPullMainNewCode(),await execCommand("git",["branch",F]),await d(!1),g(`\u521B\u5EFA\u7248\u672C\u4E3B\u5206\u652F ${F}\uFF0C\u5E76\u63A8\u9001\u5230\u8FDC\u7A0B`)):B.localExist&&await d(),await gitCheckoutBranch(versionInfo.projectMainBranch,"",!1),await deleteLocalVersionOriginMain()}function _$1(F){const d=F.split("/");if(!d.length)throw new Error("\u6CA1\u6709\u89E3\u6790\u51FA\u529F\u80FD\u5206\u652F");return d.pop()}async function parseFuncFromBranch(){const F=_$1(versionInfo.originBranch);versionInfo.setFuncName(F),r$1(`\u5F53\u524D\u529F\u80FD:${versionInfo.funcName}`)}async function readFunc(){if(!versionInfo.funcName){const{inputFuncName:F}=await o__default.prompt({name:"inputFuncName",type:"text",message:"\u8BF7\u8F93\u5165\u65B0\u529F\u80FD\u540D",validate:d=>{const B=d.trim();if(B.length){if(/\s/.test(B))return"\u8F93\u5165\u7684\u7248\u672C\u53F7\u4E4B\u95F4\u4E0D\u80FD\u5305\u542B\u7A7A\u683C ps: addPage | fixError"}else return"\u8BF7\u8F93\u5165\u6709\u6548\u7684\u529F\u80FD\u540D\u79F0 ps: addPage | fixError";return!0}});versionInfo.setFuncName(F.trim())}r$1(`\u5F53\u524D\u529F\u80FD:${versionInfo.funcName}`)}async function checkFunBranchExist(){const F=await versionInfo.getFuncFullName(),{localExist:d,remoteExist:B,allExist:y}=await checkBranch(F);return y?(s(`\u7248\u672C\u529F\u80FD\u5206\u652F ${F} \u5DF2\u5B58\u5728!!!`),!0):B?(s(`\u7248\u672C\u529F\u80FD\u5206\u652F ${F} \u8FDC\u7A0B\u5DF2\u7ECF\u5B58\u5728!!!`),!0):d?(s(`\u7248\u672C\u529F\u80FD\u5206\u652F ${F} \u672C\u5730\u5DF2\u7ECF\u5B58\u5728!!!`),!0):!1}async function createBranchFromProjectFuncBranch(){await readFunc(),await checkFunBranchExist()&&(await backToOriginalBranch(),await exitWithError()),await gitPullMainNewCode();const F=await versionInfo.getFuncFullName();await execCommand("git",["checkout","-b",F]),await gitPush(),g(`${F} \u529F\u80FD\u5206\u652F\u521B\u5EFA\u5B8C\u6210`)}async function checkOriginMainBranchExist(){return(await checkBranch(versionInfo.versionMainBranch)).remoteExist||(s(`\u62B1\u6B49 ${versionInfo.versionMainBranch} \u7248\u672C\u4E3B\u5206\u652F\u4E0D\u5B58\u5728`),await exitWithError()),!0}function checkBranchIsProjectMainBranch(F){return F===versionInfo.projectMainBranch||F===`remotes/${e$1.useRemote}/${versionInfo.projectMainBranch}`}function q(F){return!!(F.startsWith(versionInfo.versionNumber)||F.includes(`${e$1.useRemote}/${versionInfo.versionNumber}/`))}async function checkVersionMainBranchHasNotMerged(){await gitCheckoutBranch(versionInfo.versionMainBranch),await gitPull();const F=(await execCommand("git",["branch","-a","--no-merged"])).split(RegResultSplitToArr);try{const d=[];if(F.forEach(B=>{if(checkBranchIsProjectMainBranch(B)||q(B)){const y=B.replace(`remotes/${e$1.useRemote}/`,"");d.includes(y)||d.push(y)}}),d.length)throw new Error(`\u5206\u652F [${l__namespace.green(d.join("\uFF0C"))}] \u8FD8\u6CA1\u5408\u5E76\uFF0C\u8BF7\u5148\u5408\u5E76\u540E\u518D \u53D1\u5E03/\u6253\u5305`)}catch(d){s(d),await backToOriginalBranch(),versionInfo.originBranch!==await gitGetCurrentBranch()&&await deleteLocalVersionOriginMain(),await exitWithError()}}async function startBuild(F=!0){if(await chooseIsBuild(F)){r$1("\u5F00\u59CB\u6253\u5305...");try{return await execCommand("npm",["run","build"],{stdio:"inherit"}),g("\u7F16\u8BD1\u5B8C\u6210!"),!0}catch{return s("\u7F16\u8BD1\u5931\u8D25!"),!1}}return!1}async function E(F=!0){F&&await openUpdateMdFile(),await startBuild()&&await chooseAnCheck("\u662F\u5426\u9700\u8981\u5C06\u6253\u5305\u597D\u7684\u6587\u4EF6\u63A8\u9001\u5230\u8FDC\u7AEF")&&(await gitProject.add("./*").commit(`chore: build test branch ${b__default().format("M-D_H:m")}`),await gitPush())}async function M$1(){await openUpdateMdFile();const F=await chooseBuildEnv();switch(F){case"dev":await mergeAToB(versionInfo.versionMainBranch,"dev"),await startBuild(),await gitProject.add("./*").commit("build dist"),console.log(l__namespace.bgLightRed("\u63A5\u4E0B\u6765\u5E72\u8FD9\u4E8B\uFF1A")),console.log(l__namespace.bgLightRed(" \u9489\u9489@cyc\uFF0Ccyc\u4F1A\u6253\u5305\u90E8\u7F72\u5230dev\u73AF\u5883"));break;case"test":await startBuild(),await gitProject.add("./*").commit("build dist"),await gitPush(),console.log(l__namespace.bgLightRed("\u63A5\u4E0B\u6765\u5E72\u8FD9\u4E8B\uFF1A")),console.log(l__namespace.bgLightRed(" \u81EA\u5DF1\u4E0D\u884C\u5C31\u547C\u53EB\u6D4B\u8BD5\u6216\u8005\u540E\u7AEF\u540C\u5B66\u6784\u5EFA\u90E8\u7F72\u8BE5\u5206\u652F\uFF0C\u5373\u53EF\u5728test\u73AF\u5883\u8FDB\u884C\u6D4B\u8BD5"));break;case"prod":console.log(l__namespace.bgLightRed("\u63A5\u4E0B\u6765\u5E72\u8FD9\u4E8B\uFF1A")),console.log(l__namespace.bgLightRed(" \u9489\u9489@cyc\uFF0C\u544A\u8BC9\u4ED6\u5347\u7EA7\u7684\u5206\u652F\uFF0Ccyc\u4F1A\u6253\u5305\u90E8\u7F72\u5230prod\u73AF\u5883"));break;default:s(`Error:${F}`)}}async function N(){const F=await chooseOfficialBuildProject();await execCommand("npm",["run",`build:${F}`],{stdio:"inherit"}),console.log(l__namespace.bgLightRed("\u63A5\u4E0B\u6765\u5E72\u8FD9\u4E8B\uFF1A")),console.log(l__namespace.bgLightRed(" \u9489\u9489@cyc\uFF0C\u5C06\u6253\u5305\u6587\u4EF6\u53D1\u7ED9\u4ED6"))}async function handleMoreProjectBuildByTest(){switch(versionInfo.projectName){case"operator-ts":await M$1();break;case"official-ts":await N();break;default:await E(!1)}}async function handleMoreProjectBuild(){switch(versionInfo.projectName){case"operator-ts":await M$1();break;case"official-ts":await N();break;default:await E()}}async function exitHandleCurrentBranch(){versionInfo.originBranch!==await gitGetCurrentBranch()&&(await backToOriginalBranch(),await deleteLocalVersionOriginMain())}async function publishAddTag(){const F=`${versionInfo.versionNumber}/publish/${b__default().format("YY/M/D")}`;await execCommand("git",["tag","-f",F]),await execCommand("git",["push","-f",e$1.useRemote,F]),r$1(`\u7248\u672C\u589E\u52A0tag${F}`)}async function oldPublish(){c$1("\u51C6\u5907\u53D1\u5E03..."),await mergeAToB(versionInfo.versionMainBranch,versionInfo.projectMainBranch),await publishAddTag(),await openAndClearUpdateMdFile(),await gitProject.add("./*").commit(`\u5347\u7EA7\u7248\u672C\uFF1A${versionInfo.versionNumber}`),await gitPush(),await exitHandleCurrentBranch(),g(`${versionInfo.versionNumber} \u7248\u672C\u53D1\u5E03\u6210\u529F`)}async function moveFuncBranch(){const F=await checkFunBranchExist();await backToOriginalBranch(),F&&await exitWithError();const d=`${versionInfo.originBranch.split("/")[0]}/main`,B=await versionInfo.getFuncFullName();await execCommand("git",["branch","-m",versionInfo.originBranch,B]),gitPush(),r$1(`\u4FEE\u6539\u5206\u652F ${versionInfo.originBranch} \u4E3A ${B}`);const{remoteExist:y}=await checkBranch(d);await gitDeleteBranch(versionInfo.originBranch,{deleteRemote:y,deleteLocal:!1}),y&&n$2(`\u5220\u9664\u8FDC\u7A0B\u5206\u652F ${versionInfo.originBranch}`);const{remoteExist:v,localExist:k}=await checkBranch(d);if(v||k)try{await gitDeleteBranch(d,{deleteRemote:v,deleteLocal:k,showLog:!1})}catch(x){if(JSON.stringify(x).includes("delete protected branches using")){if(!await gitlabApiDeleteBranch(d))return}else{s(x);return}}await checkVersionMainBranch(d),await gitCheckoutBranch(B)}async function gitlabApiDeleteBranch(F){try{const d=await getGitlabProjectId();if(!await initGitToken())return!1;const B=await readGitlabToken();return await new axios.Axios({headers:{"PRIVATE-TOKEN":B}}).delete(`http://git.rantron.biz:3002/api/v4/projects/${d}/repository/branches/${encodeURIComponent(F)}`),await execCommand("git",["remote","update",e$1.useRemote,"--prune"]),!0}catch(d){r$1(`\u5220\u9664\u8FDC\u7A0B ${F} \u5206\u652F\u9519\u8BEF error ${d}`)}return!1}async function createFixBranch(){versionInfo.setFuncName("fixOnline");const F=await versionInfo.getFuncFullName();await checkFunBranchExist()?await gitProject.checkout(F):(terminalLog.start("\u4FEE\u590D\u5206\u652F\u521B\u5EFA\u4E2D"),await gitProject.checkoutLocalBranch(F).push(e$1.useRemote,F,["-u"]),terminalLog.SuccessEnd("\u4FEE\u590D\u5206\u652F\u521B\u5EFA\u5B8C\u6210"))}async function getMergeRequestTargetBranch(){const{all:F}=await gitProject.branch(["-r"]),d=F.filter(B=>B.includes(`${e$1.useRemote}/${versionInfo.versionNumber}/`)&&!B.endsWith(`${e$1.useRemote}/${versionInfo.originBranch}`)).sort((B,y)=>B.includes("main")&&!y.includes("main")?-1:!B.includes("main")&&y.includes("main")?1:0);if(!d.length)throw await backToOriginalBranch(),new Error("\u6CA1\u6709\u5176\u4ED6\u7248\u672C\u5206\u652F");return(await chooseMergeRequestTargetBranch(d)).replace(`${e$1.useRemote}/`,"")}const getMergeRquestOriginBranch=async F=>{const d=`${versionInfo.originBranch}_temp_merge`;let B=versionInfo.originBranch,y=!0;try{await execCommand("git",["merge",`${e$1.useRemote}/${F}`,"--no-commit"]),gitProject.merge(["--abort"]),y=!1}catch{n$2("\u548C\u7248\u672C\u4E3B\u5206\u652F\u5B58\u5728\u51B2\u7A81\uFF0C\u5148\u5728\u5F53\u524D\u5206\u652F\u89E3\u51B3\u51B2\u7A81\u540E\u518D\u63D0\u4EA4\u5408\u5E76\u8BF7\u6C42\u3002"),gitProject.merge(["--abort"])}try{await Promise.all([execCommand("git",["push","--delete",e$1.useRemote,d]),execCommand("git",["branch","-d",d])])}catch{}return y&&(B=d,await execCommand("git",["checkout","-b",d]),await gitPush(),await mergeAToB(F,d)),B},w$1=/^(\d{1,3}\.){3}\d{1,3}$/,A$1=/^([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,5})$/,o$2=F=>w$1.test(F),p=F=>A$1.test(F),P=F=>o$2(F)||p(F),m=async(F="\u8BF7\u8F93\u5165ip/\u57DF\u540D",d="\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip/\u57DF\u540D",B=1)=>o__default.prompt([{name:"ip",type:"text",message:F,required:!0,validate(y){return B===1?P(y)||d:B===2?o$2(y)||d:p(y)||d}}]),R$1=F=>p(F)?new Promise(d=>{f__default.lookup(`${F}`,(B,y)=>{d(B?"":`\u5BF9\u5E94\u7684IP\u5730\u5740:${l__namespace.lightCyan(y)}`)})}):Promise.resolve(""),I=F=>new Promise(d=>{ping.sys.probe(F,B=>{const y=B?l__namespace.green("alive"):l__namespace.red("dead");d(`${l__namespace.lightBlue(F)} is ${y}`)})}),b$1=F=>Promise.resolve(""),h$1=async F=>{const[d,B,y]=await Promise.all([I(F),R$1(F),b$1()]);return`${d} ${B} ${y}`};async function PingPort(F,d=""){if(F){let B="",y=d;if(!o$2(y)){const{ip:U}=await m("\u8BF7\u8F93\u5165\u8303\u56F4\u8D77\u59CB\u7684ip","\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip",2);y=U}const{ip:v}=await m("\u8BF7\u8F93\u5165\u8303\u56F4\u7ED3\u675F\u7684ip","\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip",2);B=v;const k=y.split(".").map(Number),x=B.split(".").map(Number),j=[];for(let U=k[3];U<=x[3];U+=1){const V=[...k];V[3]=U,j.push(I(V.join(".")))}terminalLog.start("\u6B63\u5728\u75AF\u72C2ping\u4E2D");const L=await Promise.all(j);console.log(` ------------------- ${L.join(` `)} -------------------`),terminalLog.SuccessEnd("ping\u5B8C\u6210\u5566")}else{let B="";if(P(d)&&(B=d),!B){const{ip:v}=await m();B=v}const y=await h$1(B);console.log(` ------------------- ${y} -------------------`)}}const PromptMap={inputVersion:{name:"version",type:"text",message:"\u8BF7\u8F93\u5165\u7248\u672C\u53F7",required:!0,validate(F){return verifyVersion(F)||"\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u7248\u672C\u53F7 ps: 1.0.0 | project1.0.0"}}},mergePromptOptions=(F,d={})=>({...F,...d}),c=()=>{const F=__dirname.split(/(\\|\/)/);for(;F.length&&!/^(dist|src)$/.test(F[F.length-1]);)F.pop();return F.join("/")},readStaticFile=(F="")=>{const d=c(),B=e$2.join(d,"./static/",F);try{return fs.readFileSync(B).toString()}catch{s(`Error:\u6587\u4EF6\u4E0D\u5B58\u5728${B}`)}return!1},readStaticTemplateFileSync=(F="")=>readStaticFile(e$2.join("./template",F));var o$1=Object.defineProperty,a$1=(F,d,B)=>d in F?o$1(F,d,{enumerable:!0,configurable:!0,writable:!0,value:B}):F[d]=B,i$1=(F,d,B)=>(a$1(F,typeof d!="symbol"?d+"":d,B),B);const r="simpleDotsScrolling";class h{constructor(){i$1(this,"shapeList",[r,"monkey","speaker","moon","earth","smiley"]),i$1(this,"index",0),i$1(this,"count",0),i$1(this,"spinner"),i$1(this,"timer"),i$1(this,"preTextFormat",""),i$1(this,"showDesc",""),i$1(this,"startNow",Date.now()),this.init()}async init(){const d=await import("ora");this.spinner=await d.default({color:"green",spinner:r,prefixText:"start"})}setSpinnerStyle(d,B){this.spinner&&Object.assign(this.spinner,{prefixText:B,spinner:d})}start(d="waiting",B="waiting **s"){this.showDesc=l__namespace.red(d),this.index=0,this.preTextFormat=B,this.spinner?.start(this.showDesc),this.startNow=Date.now(),this.circle()}SuccessEnd(d){this.spinner&&this.spinner.succeed(`${d}\u{1F604}`),this.end()}FailEnd(d){this.spinner&&this.spinner.fail(`${d}\u{1F604}`),this.end()}end(){clearInterval(this.timer),this.setSpinnerStyle(r,"")}circle(){this.timer=setInterval(()=>{const d=this.getLoadingSeconds();if(this.spinner&&this.shapeList.length){d%3||(this.index=(this.index+1)%this.shapeList.length);const B=this.preTextFormat.replace("**",`${d}`);this.setSpinnerStyle(this.shapeList[this.index],l__namespace.blue(l__namespace.bgGreen(B)))}},1e3)}getLoadingSeconds(){return Math.ceil((Date.now()-this.startNow)/1e3)}}const terminalLog=new h,sleep=(F=1e3)=>new Promise(d=>{setTimeout(()=>{d("\u7761\u7720\u5B8C\u6210")},F)});function exitWithSuccess(F=!0){return F?new Promise(d=>{process.stdin.setRawMode(!0),process.stdin.resume(),g("cli\u6267\u884C\u5B8C\u6210\uFF0C\u6309\u4EFB\u610F\u952E\u9000\u51FA\u3002"),process.stdin.on("data",()=>{d("\u811A\u672C\u6267\u884C\u5B8C\u6210"),process.exit()})}):(g("cli\u6267\u884C\u5B8C\u6210"),"\u811A\u672C\u6267\u884C\u5B8C\u6210")}function exitWithError(){return new Promise((F,d)=>{process.stdin.setRawMode(!0),process.stdin.resume(),s("cli\u6267\u884C\u5931\u8D25\uFF0C\u6309\u4EFB\u610F\u952E\u9000\u51FA\uFF01"),process.stdin.on("data",()=>{d(new Error("Program Exit")),process.exit()})})}function watchProcessAccident(F,d=!1){process.on("exit",async B=>{B!==0&&(d&&await F(),s(`\u8FDB\u7A0B\u9000\u51FA\u7F16\u7801:${B}`))}),process.on("SIGINT",async()=>{await F(),process.exit(0)})}const getPackageJsonAttr=async F=>{const d={};if(F.packageJson){const B=(Array.isArray(F.packageJson)?F.packageJson:[typeof F.packageJson=="string"?F.packageJson:F.name]).filter(v=>v&&typeof v=="string"),y=await pkgTypes.readPackageJSON(F.cwd).catch(v=>{});if(y){const v={};B.forEach(k=>{y[k]&&(v[k]=y[k])}),Object.assign(d,v)}}return d},t={baseDir:process.cwd(),binary:"git",maxConcurrentProcesses:6,trimmed:!1},gitProject=simpleGit.simpleGit(t),o="*.{js,jsx,mjs,cjs,json,ts,tsx,mts,cts,vue,svelte,astro}",a={cwd:process.cwd(),cleanupDirs:["**/dist","**/package-lock.json","**/yarn.lock","**/pnpm-lock.yaml","**/node_modules","!node_modules/**"],gitCommitTypes:[["init","\u9879\u76EE\u521D\u59CB\u5316"],["feat","\u6DFB\u52A0\u65B0\u7279\u6027"],["fix","\u4FEE\u590Dbug"],["docs","\u4EC5\u4EC5\u4FEE\u6539\u6587\u6863"],["style","\u4EC5\u4EC5\u4FEE\u6539\u4E86\u7A7A\u683C\u3001\u683C\u5F0F\u7F29\u8FDB\u3001\u9017\u53F7\u7B49\u7B49\uFF0C\u4E0D\u6539\u53D8\u4EE3\u7801\u903B\u8F91"],["refactor","\u4EE3\u7801\u91CD\u6784\uFF0C\u6CA1\u6709\u52A0\u65B0\u529F\u80FD\u6216\u8005\u4FEE\u590Dbug"],["perf","\u4F18\u5316\u76F8\u5173\uFF0C\u6BD4\u5982\u63D0\u5347\u6027\u80FD\u3001\u4F53\u9A8C"],["test","\u6DFB\u52A0\u6D4B\u8BD5\u7528\u4F8B"],["build","\u4F9D\u8D56\u76F8\u5173\u7684\u5185\u5BB9"],["ci","CI\u914D\u7F6E\u76F8\u5173\uFF0C\u4F8B\u5982\u5BF9k8s\uFF0Cdocker\u7684\u914D\u7F6E\u6587\u4EF6\u7684\u4FEE\u6539"],["chore","\u6539\u53D8\u6784\u5EFA\u6D41\u7A0B\u3001\u6216\u8005\u589E\u52A0\u4F9D\u8D56\u5E93\u3001\u5DE5\u5177\u7B49"],["revert","\u56DE\u6EDA\u5230\u4E0A\u4E00\u4E2A\u7248\u672C"]],gitCommitScopes:[["projects","\u9879\u76EE\u642D\u5EFA"],["components","\u7EC4\u4EF6\u76F8\u5173"],["hooks","hook \u76F8\u5173"],["utils","utils \u76F8\u5173"],["types","ts\u7C7B\u578B\u76F8\u5173"],["styles","\u6837\u5F0F\u76F8\u5173"],["deps","\u9879\u76EE\u4F9D\u8D56"],["auth","\u5BF9 auth \u4FEE\u6539"],["release","\u7248\u672C\u53D1\u5E03"],["other","\u5176\u4ED6\u4FEE\u6539"]],ncuCommandArgs:["--deep","-u"],changelogOptions:{},prettierWriteGlob:[`!**/${o}`,"!*.min.*","!CHANGELOG.md","!dist","!LICENSE*","!output","!coverage","!public","!temp","!package-lock.json","!pnpm-lock.yaml","!yarn.lock","!.github","!__snapshots__","!node_modules"],lintStagedConfig:{[o]:"eslint --fix","*":"soy prettier-write"}};async function loadCliOptions(F,d=process.cwd()){const B={overrides:F,name:"ppg",defaults:a,cwd:d,packageJson:["name"]},{config:y}=await c12.loadConfig(B),v=await getPackageJsonAttr(B);return Object.assign(y||{},v)}const version="0.0.34";async function gitCommit(F,d){const B=F.map(([x,j])=>{const L=`${`${x}:`.padEnd(12)}${j}`;return{name:x,message:L}}),y=d.map(([x,j])=>({name:x,message:`${x.padEnd(12)} (${j})`})),v=await o__default.prompt([{name:"types",type:"select",message:"\u8BF7\u9009\u62E9\u63D0\u4EA4\u7C7B\u578B",choices:B},{name:"scopes",type:"select",message:"\u9009\u62E9\u4E00\u4E2Ascope",choices:y},{name:"description",type:"text",message:"\u8BF7\u8F93\u5165\u63D0\u4EA4\u63CF\u8FF0",required:!0}]),k=`${v.types}(${v.scopes}): ${v.description}`;execCommand("git",["commit","-m",k],{stdio:"inherit"})}async function openStore(F=""){let d=F;if(d||(d=await execCommand("git",["remote","get-url",e$1.useRemote])),!d)return s("\u6CA1\u6709\u53EF\u6253\u5F00\u7684\u7F51\u5740(\uFF3E\uFF0D\uFF3E)");const B=await import("open");r$1(`\u6253\u5F00\u5730\u5740: ${d}`);try{await B.default(d,{wait:!0}),g("Default browser opened successfully.")}catch(y){s(`Unable to open the default browser:${y}`)}return!0}const A=async()=>{if(await checkInvalidBranch(),await versionInfo.setVersionNumber(),!await initGitToken())return;await gitPullMainNewCode();const F=await getMergeRequestTargetBranch();await mergeAToB(versionInfo.projectMainBranch,versionInfo.originBranch),await backToOriginalBranch();const d=readGitlabToken();if(!d)return;const B=await getMergeRquestOriginBranch(F),y=await getGitlabProjectId();await getGitlabLaunchMergeRequestByProjectId({projectId:y,gitlabToken:d,originBranch:B,targetBranch:F}),await backToOriginalBranch()},$=async()=>{await checkInvalidBranch(),await versionInfo.setVersionNumber(),await gitPullMainNewCode(),await mergeAToB(versionInfo.projectMainBranch,versionInfo.originBranch),await mergeAToB(versionInfo.originBranch,versionInfo.versionMainBranch),await backToOriginalBranch(),await gitDeleteBranch(versionInfo.versionMainBranch)},O=async()=>{await versionInfo.setVersionNumber(),await checkVersionMainBranch(),await createBranchFromProjectFuncBranch()},S=async()=>{await versionInfo.setVersionNumber(),await checkOriginMainBranchExist(),n$2("\u51C6\u5907\u68C0\u6D4B..."),await checkVersionMainBranchHasNotMerged(),g(`\u68C0\u6D4B\u5B8C\u6210,${versionInfo.versionNumber} \u7248\u672C\u7684\u5206\u652F\u5168\u90E8\u5DF2\u5408\u5E76\u5230\u4E3B\u5206\u652F`),await backToOriginalBranch()},C=async()=>{await versionInfo.setVersionNumber(),await checkOriginMainBranchExist(),await checkVersionMainBranchHasNotMerged(),await handleMoreProjectBuild(),await exitHandleCurrentBranch()},H=async()=>{await versionInfo.setVersionNumber(),await checkOriginMainBranchExist(),await checkVersionMainBranchHasNotMerged(),["fhd_miniprogram_monorepo"].includes(versionInfo.projectName)?(s(`\u5728gitlab\u4E2D\u63D0\u4EA4\u5408\u5E76\u8BF7\u6C42\uFF0C\u5C06 ${versionInfo.versionMainBranch} \u5408\u5E76\u5230 ${versionInfo.projectMainBranch}`),await openStore()):await oldPublish()},W=async()=>{await gitProject.checkout(versionInfo.projectMainBranch).pull(),await versionInfo.setVersionNumber("\u8BF7\u8F93\u5165\u4FEE\u590D\u7684\u7248\u672C\u53F7"),await createFixBranch()},_=async()=>{await checkInvalidBranch(),await parseFuncFromBranch(),await versionInfo.setVersionNumber("\u8BF7\u8F93\u5165\u8FC1\u79FB\u7684\u76EE\u6807\u7248\u672C\u53F7"),await checkVersionMainBranch(),await moveFuncBranch()},D$1=async()=>{await checkInvalidBranch(),await versionInfo.setVersionNumber(),await checkVersionMainBranchHasNotMerged(),await mergeAToB(versionInfo.versionMainBranch,"test"),await handleMoreProjectBuildByTest(),await backToOriginalBranch(),await gitDeleteBranch(versionInfo.versionMainBranch)};async function getVersion(F){await versionInfo.init();const d=await chooseActionType(F);switch(d){case EGitVersionActionType.mq:await A();break;case EGitVersionActionType.merge:await $();break;case EGitVersionActionType.new:await O();break;case EGitVersionActionType.check:await S();break;case EGitVersionActionType.build:await C();break;case EGitVersionActionType.publish:await H();break;case EGitVersionActionType.fix:await W();break;case EGitVersionActionType.move:await _();break;case EGitVersionActionType.test:await D$1();break;default:s(`\u6CA1\u6709\u4EFB\u4F55\u811A\u672C\u53EF\u6267\u884C ${d}`)}await exitWithSuccess(!1)}async function gitCommitVerify(){const F=await execCommand("git",["rev-parse"]),d=e__default.join(F,".git","COMMIT_EDITMSG"),B=fs.readFileSync(d,{encoding:"utf8"});if(!/(?<type>[a-z]+)(\((?<scope>[a-z]+)\))?(?<breaking>!)?:(?<description>.+)/i.test(B))throw new Error(`${l__namespace.bgRed(" ERROR ")} ${l__namespace.red(`Git\u63D0\u4EA4\u4FE1\u606F\u4E0D\u7B26\u5408 Git Conventional Message \u89C4\u8303! `)}${l__namespace.green("\u63A8\u8350\u4F7F\u7528\u547D\u4EE4 pnpm commit \u751F\u6210\u7B26\u5408\u89C4\u8303\u7684Git\u63D0\u4EA4\u4FE1\u606F")}`)}async function release(){await e__default$1({files:["**/package.json","!**/node_modules"],all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}var EPlatForm=(F=>(F[F.WEChAT=0]="WEChAT",F[F.ALIPAY=1]="ALIPAY",F[F.STATIC=2]="STATIC",F[F.AD_STATIC=3]="AD_STATIC",F[F.PL_OPERATOR=4]="PL_OPERATOR",F[F.SAAS_MERCHANT=5]="SAAS_MERCHANT",F))(EPlatForm||{});const getUploadInfoRoot=()=>{const F=process.env.HOME;if(!F)return s("\u6CA1\u6709\u627E\u5230\u7CFB\u7EDF\u9ED8\u8BA4\u8DEF\u5F84"),"";const d=e__default.join(F,"fhdUploadFile.json");return u__default.existsSync(d)||u__default.writeJSONSync(d,{}),d},initUploadInfo=()=>{const F=getUploadInfoRoot();return u__default.readJsonSync(F)},R={0:"wxFileRoot",1:"aliFileRoot",2:"staticFileRoot",4:"ploperatorFileRoot",5:"saasMerchantFileRoot",3:"adStaticFileRoot"},getFileRoot=async(F,d)=>{const B=getUploadInfoRoot(),y=u__default.readJsonSync(B),v=R[F];if(d&&u__default.existsSync(e$2.resolve(d))?y[v]=e$2.resolve(d):d&&s(`\u8DEF\u5F84\u4E0D\u5B58\u5728 ${d}`),!y[v]){const{pathRoot:k}=await o__default.prompt([{name:"pathRoot",type:"text",message:"\u8BF7\u8F93\u5165\u8DEF\u5F84",required:!0}]);return getFileRoot(F,k)}return y[v]},ChcZipName="chc\u6821\u9A8C\u6587\u4EF6.zip",StaticZipName="static.zip",welfareZipName="welfare.zip",SaasZipName="saas.zip",prepareDirFileZip=async(F,d)=>{const B=e__default.join(F,".."),y=e__default.resolve(F);if(!fs.existsSync(y))return s(`${y}\u4E0D\u5B58\u5728`),!1;const v=fs.createWriteStream(e__default.join(B,d)),k=h__default("zip",{zlib:{level:9}});if(k.on("error",x=>{throw s(` archiveSaas error-> ${JSON.stringify(x)}`),x}),v.on("close",()=>{g(`\u6587\u4EF6 \u538B\u7F29\u5305\u521B\u5EFA\u5B8C\u6210\uFF0C\u6587\u4EF6\u5927\u5C0F: ${k.pointer()} \u5B57\u8282`)}),v.on("error",x=>{throw s(` archive zip error-> ${JSON.stringify(x)}`),x}),k.pipe(v),!d.split(".")[0])throw"\u6CA1\u6709\u6587\u4EF6\u540D\u79F0";k.directory(y,d.split(".")[0]),k.finalize(),await sleep()},prepareAliZipFile=async F=>{const d=e__default.join(F,".."),B=e__default.resolve(F);if(!fs.existsSync(B))return s(`${B}\u4E0D\u5B58\u5728`),!1;const y=fs.createWriteStream(e__default.join(d,ChcZipName)),v=h__default("zip",{zlib:{level:9}});y.on("close",()=>{g(`\u6821\u9A8C\u6587\u4EF6 \u538B\u7F29\u5305\u521B\u5EFA\u5B8C\u6210\uFF0C\u6587\u4EF6\u5927\u5C0F: ${v.pointer()} \u5B57\u8282`)}),v.on("error",j=>{throw s(` archiveCheck error-> ${JSON.stringify(j)}`),j});const k=new Set;function x(j){fs.readdirSync(j).forEach(L=>{const U=e__default.join(j,L);if(fs.statSync(U).isDirectory())x(U);else if([".html",".txt"].includes(e__default.extname(L))){if(k.has(L))return;k.add(L),v.append(fs.createReadStream(U),{name:e__default.basename(L)})}})}x(B),v.pipe(y),v.finalize(),await sleep()};var n=Object.defineProperty,i=(F,d,B)=>d in F?n(F,d,{enumerable:!0,configurable:!0,writable:!0,value:B}):F[d]=B,e=(F,d,B)=>(i(F,typeof d!="symbol"?d+"":d,B),B);class FileUploadAxios{constructor(){e(this,"token",""),e(this,"axiosInstance"),this.axiosInstance=new axios.Axios({}),this.axiosInstance.interceptors.request.use(d=>{const B=d.data instanceof c__default;if(d.method==="post"&&!B){const y=d.data||{};y.token=y.token||this.token,y.referer="mgrapi",d.data=querystring.stringify(y)}else if(d.method==="get"){const y={...d.params||{}};d.params={...y,token:y.token||this.token,referer:"mgrapi"}}return d}),this.axiosInstance.interceptors.response.use(d=>{const B=JSON.parse(d.data||"{}"),y=B.rcode===0;return{...d,data:{...B||{},isSuccess:y}}})}setToken(d=""){this.token=d}}new FileUploadAxios;var b=Object.defineProperty,D=(F,d,B)=>d in F?b(F,d,{enumerable:!0,configurable:!0,writable:!0,value:B}):F[d]=B,l=(F,d,B)=>(D(F,typeof d!="symbol"?d+"":d,B),B);const M={[EPlatForm.WEChAT]:[49,48,41],[EPlatForm.ALIPAY]:[49,48],[EPlatForm.STATIC]:[36],[EPlatForm.PL_OPERATOR]:[52],[EPlatForm.SAAS_MERCHANT]:[41],[EPlatForm.AD_STATIC]:[37]},w=[{id:49,name:"chc\u9A8C\u8BC1\u6587\u4EF6",productName:"fhdchcstatic",uploadZipFileName:ChcZipName,uploadDesc:"SaaS\u5C0F\u7A0B\u5E8F\u6821\u9A8C\u6587\u4EF6\u4E0A\u4F20"},{id:48,name:"img1\u9A8C\u8BC1\u6587\u4EF6",productName:"fhdostatic",uploadDesc:"SaaS\u5C0F\u7A0B\u5E8F\u6821\u9A8C\u6587\u4EF6\u4E0A\u4F20",uploadZipFileName:ChcZipName},{id:41,name:"\u5BC4\u5FEB\u9012\u9759\u6001\u8D44\u6E90",productName:"jkdstatic",uploadDesc:"SaaS\u5C0F\u7A0B\u5E8F\u6821\u9A8C\u6587\u4EF6\u4E0A\u4F20",uploadZipFileName:SaasZipName},{id:36,name:"\u98CE\u706B\u9012\u5BC4\u9012\u9759\u6001\u8D44\u6E90-static",productName:"fhdostatic",uploadDesc:"\u56FE\u7247\u4E0A\u4F20",uploadZipFileName:StaticZipName},{id:52,name:"\u5BC4\u9012\u8FD0\u8425\u7CFB\u7EDF",productName:"ploperator",uploadDesc:"\u90E8\u7F72\u7EFC\u5408\u8FD0\u8425\u7CFB\u7EDF",uploadZipFileName:""},{id:37,name:"\u5E7F\u544A\u9759\u6001\u8D44\u6E90",productName:"fhdostatic",uploadDesc:"\u56FE\u7247\u4E0A\u4F20",uploadZipFileName:welfareZipName}];class J{constructor(d){l(this,"uploadRequest",new FileUploadAxios),l(this,"localUploadInfo",initUploadInfo()),l(this,"publishFileRoot",""),l(this,"configFilePath",getUploadInfoRoot()),l(this,"uploadInfoList",[]),l(this,"currentPlatfrom"),l(this,"initUploadInfoList",async()=>{const{data:{data:B,isSuccess:y}}=await this.uploadRequest.axiosInstance.get("https://mgrapi.fhd001.com/mgr/rdc/staticResource/getUserStaticResourceDirectoryList.do");if(!y)throw s(JSON.stringify(B)),new Error("\u83B7\u53D6\u4E0A\u4F20\u914D\u7F6E\u5931\u8D25");const v=w.map(k=>{const x=B.find(U=>U.id===k.id);if(!x?.lastStaticResourcePublishLog?.version)return console.info("\u7EBF\u4E0A\u914D\u7F6E\u4E0D\u5B58\u5728:",k.name,",id:",k.id),!1;const{version:j}=x?.lastStaticResourcePublishLog||{},L=semver.inc(j,"patch")||"";return{...k,oldPublishVersion:j,newPublishVersion:L}}).filter(Boolean);this.uploadInfoList=v}),l(this,"publicZip",async B=>{const{data:{data:y,isSuccess:v}}=await this.uploadRequest.axiosInstance.post("https://mgrapi.fhd001.com/mgr/common/upload/createUploadToken",{fileName:B.uploadZipFileName,isPrivate:!0});if(!v)throw s(`${B.name} \u83B7\u53D6\u4E0A\u4F20token errorinfo -> ${JSON.stringify(y)}`),new Error("\u4E0A\u4F20\u5931\u8D25");const k=new c__default;if(!B.uploadZipFileName.trim())throw new Error("\u6587\u4EF6\u540D\u4E3A\u7A7A");const x=e__default.join(this.publishFileRoot,B.uploadZipFileName),j=u.readFileSync(x);k.append("files[]",j,{filename:B.uploadZipFileName.split(".")[0]}),k.append("token",y);const L={headers:{Referer:"https://oss.fhd001.com/",Origin:"https://oss.fhd001.com"}},{data:{data:U,isSuccess:V}}=await this.uploadRequest.axiosInstance.post("https://download.fhd001.com/upload",k,L);if(V)g(`${B.name} \u4E0A\u4F20\u6210\u529F`);else throw s(`${B.name} \u4E0A\u4F20\u5931\u8D25 errorinfo -> ${JSON.stringify(U)}`),console.log("\u{1F3F7}\uFE0F index.ts ~ error => ",U),new Error("\u4E0A\u4F20\u5931\u8D25");const{data:{data:G,isSuccess:Z}}=await this.uploadRequest.axiosInstance.post("https://mgrapi.fhd001.com/mgr/rdc/staticResource/staticResourcePublish.do",{staticResourceDirectoryId:B.id,version:B.newPublishVersion,description:B.uploadDesc,ossFilePath:U});if(!Z)throw s(`${B.name} \u53D1\u5E03\u5931\u8D25 errorinfo -> ${JSON.stringify(G)}`),new Error("\u53D1\u5E03\u5931\u8D25");g(`${B.name} \u53D1\u5E03\u6210\u529F`)}),l(this,"uploadEntry",async()=>{await this.initUploadInfoList();const B=M[this.currentPlatfrom],y=this.uploadInfoList.filter(v=>B.includes(v.id));await Promise.all(y.map(v=>this.publicZip(v)))}),l(this,"initToken",async B=>{if(B){const{data:{isSuccess:v}}=await this.uploadRequest.axiosInstance.get("https://mgrapi.fhd001.com/mgr/rdc/staticResource/getUserStaticResourceDirectoryList.do",{params:{token:B}});if(v)return g("token \u6821\u9A8C\u901A\u8FC7"),this.uploadRequest.setToken(B),this.localUploadInfo.token=B,this.writeConfigFile(),B;s("token \u65E0\u6548\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165")}const{inputToken:y}=await o__default.prompt([{name:"inputToken",type:"text",message:"\u8BF7\u8F93\u5165\u706B\u82B1\u6D3Etoken",required:!0}]);return this.initToken(y)}),this.currentPlatfrom=d}writeConfigFile(){u.writeJson(this.configFilePath,this.localUploadInfo)}async wxMain(d){this.localUploadInfo.wxFileRoot=await getFileRoot(this.currentPlatfrom,d),this.publishFileRoot=e__default.join(this.localUploadInfo.wxFileRoot,".."),await prepareDirFileZip(this.localUploadInfo.wxFileRoot,SaasZipName),await prepareAliZipFile(this.localUploadInfo.wxFileRoot);const B=getUploadInfoRoot(),y=u__default.readJsonSync(B);await this.initToken(y.token),await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async aliMain(d){this.localUploadInfo.aliFileRoot=await getFileRoot(this.currentPlatfrom,d),this.publishFileRoot=e__default.join(this.localUploadInfo.aliFileRoot,".."),await prepareAliZipFile(this.localUploadInfo.aliFileRoot);const B=getUploadInfoRoot(),y=u__default.readJsonSync(B);await this.initToken(y.token),await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async staticMain(d){this.localUploadInfo.staticFileRoot=await getFileRoot(this.currentPlatfrom,d),this.publishFileRoot=e__default.join(this.localUploadInfo.aliFileRoot,".."),await prepareDirFileZip(this.localUploadInfo.staticFileRoot,StaticZipName);const B=getUploadInfoRoot(),y=u__default.readJsonSync(B);await this.initToken(y.token);const v=w.find(x=>x.id===36);if(!v)throw new Error("\u672A\u627E\u5230\u9759\u6001\u8D44\u6E90\u9879\u76EE");const{desc:k}=await o__default.prompt([{name:"desc",type:"text",message:"\u8BF7\u8F93\u5165\u4E0A\u4F20\u63CF\u8FF0\u4FE1\u606F",required:!0,initial:v.uploadDesc}]);v.uploadDesc=k,await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async staticAdMain(d){this.localUploadInfo.adStaticFileRoot=await getFileRoot(this.currentPlatfrom,d),this.publishFileRoot=e__default.join(this.localUploadInfo.adStaticFileRoot,".."),await prepareDirFileZip(this.localUploadInfo.adStaticFileRoot,welfareZipName);const B=getUploadInfoRoot(),y=u__default.readJsonSync(B);await this.initToken(y.token);const v=w.find(x=>x.id===37);if(!v)throw new Error("\u672A\u627E\u5230\u9759\u6001\u8D44\u6E90\u9879\u76EE");const{desc:k}=await o__default.prompt([{name:"desc",type:"text",message:"\u8BF7\u8F93\u5165\u4E0A\u4F20\u63CF\u8FF0\u4FE1\u606F",required:!0,initial:v.uploadDesc}]);v.uploadDesc=k,await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async plOperatorMain(d){this.localUploadInfo.ploperatorFileRoot=await getFileRoot(this.currentPlatfrom,d);const B=u.readdirSync(e__default.resolve(this.localUploadInfo.ploperatorFileRoot));if(!B.length)return s(`${this.localUploadInfo.ploperatorFileRoot} \u76EE\u5F55\u4E0B\u6CA1\u6709\u6587\u4EF6`);this.publishFileRoot=e__default.resolve(this.localUploadInfo.ploperatorFileRoot);const y=getUploadInfoRoot(),v=u__default.readJsonSync(y);await this.initToken(v.token);const k=w.find(L=>L.id===52);if(!k)throw new Error("\u672A\u627E\u5230\u9759\u6001\u8D44\u6E90\u9879\u76EE");const{fileName:x,desc:j}=await o__default.prompt([{name:"fileName",type:"select",message:"\u8BF7\u9009\u62E9\u4E0A\u4F20\u7684\u538B\u7F29\u5305",required:!0,choices:B},{name:"desc",type:"text",message:"\u8BF7\u8F93\u5165\u53D1\u5E03\u63CF\u8FF0\u4FE1\u606F",required:!0,initial:"\u53D1\u5E03\u7EFC\u5408\u8FD0\u8425\u7CFB\u7EDF"}]);k.uploadDesc=j,k.uploadZipFileName=x,await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async saasMerchantMain(d){this.localUploadInfo.saasMerchantFileRoot=await getFileRoot(this.currentPlatfrom,d);const B=u.readdirSync(e__default.resolve(this.localUploadInfo.saasMerchantFileRoot));if(!B.length)return s(`${this.localUploadInfo.saasMerchantFileRoot} \u76EE\u5F55\u4E0B\u6CA1\u6709\u6587\u4EF6`);this.publishFileRoot=e__default.resolve(this.localUploadInfo.saasMerchantFileRoot);const y=getUploadInfoRoot(),v=u__default.readJsonSync(y);await this.initToken(v.token);const k=w.find(L=>L.id===41);if(!k)throw new Error("\u672A\u627E\u5230\u9759\u6001\u8D44\u6E90\u9879\u76EE");const{fileName:x,desc:j}=await o__default.prompt([{name:"fileName",type:"select",message:"\u8BF7\u9009\u62E9\u4E0A\u4F20\u7684\u538B\u7F29\u5305",required:!0,choices:B},{name:"desc",type:"text",message:"\u8BF7\u8F93\u5165\u53D1\u5E03\u63CF\u8FF0\u4FE1\u606F",required:!0,initial:"\u53D1\u5E03SaaS\u5546\u6237\u540E\u53F0"}]);k.uploadDesc=j,k.uploadZipFileName=x,await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}}async function T(){const F=await loadCliOptions(),d=f__default$1("ppg");d.version(version).help();const B={"git-commit":{desc:"\u521B\u5EFA\u4E00\u4E2A\u7B26\u5408 Conventional Commit \u89C4\u8303\u7684\u63D0\u4EA4\u4FE1\u606F",alias:"gc",action:async()=>{try{await gitCommit(F.gitCommitTypes,F.gitCommitScopes)}catch{exitWithError()}}},"git-version [actionType]":{desc:"\u7248\u672C\u5206\u652F\u64CD\u4F5C",alias:"gv",action:async y=>{try{await getVersion(y)}catch(v){backToOriginalBranch(),n$2(JSON.stringify(v)),exitWithError()}}},"git-commit-verify":{desc:"\u68C0\u6D4B\u6700\u8FD1\u7684\u4E00\u6B21commit\u4FE1\u606F\u662F\u5426\u7B26\u5408 Conventional Commit\u89C4\u8303",alias:"gcv",action:async()=>{await gitCommitVerify()}},"ping [ip]":{desc:"ping ip/\u57DF\u540D",alias:"p",options:[["-m, --more","Whether to ping multiple ips",{default:!1}]],action:async(y,v)=>{await PingPort(v.more,y)}},"delete-tag [tagName]":{desc:"\u5220\u9664\u8FDC\u7A0Btag",alias:"dt",action:async y=>{await deleteTag(y)}},"public-verify-vx [fileRoot]":{desc:"\u5C06\u6821\u9A8C\u6587\u4EF6\u53D1\u5E03\u5230\u8FDC\u7A0B-\u5FAE\u4FE1",alias:"pvv",action:async y=>{await new J(EPlatForm.WEChAT).wxMain(y)}},"public-verify-ali [fileRoot]":{desc:"\u5C06\u6821\u9A8C\u6587\u4EF6\u53D1\u5E03\u5230\u8FDC\u7A0B-\u652F\u4ED8\u5B9D/\u6296\u97F3",alias:"pva",action:async y=>{await new J(EPlatForm.ALIPAY).aliMain(y)}},"public-static [fileRoot]":{desc:"\u5C06\u5BC4\u9012\u9759\u6001\u8D44\u6E90\u53D1\u5E03\u5230\u8FDC\u7A0B",alias:"ps",action:async y=>{await new J(EPlatForm.STATIC).staticMain(y)}},"public-ad [fileRoot]":{desc:"\u5C06\u5E7F\u544A\u6001\u8D44\u6E90\u53D1\u5E03\u5230\u8FDC\u7A0B",alias:"pa",action:async y=>{await new J(EPlatForm.AD_STATIC).staticAdMain(y)}},"public-ploperator [fileRoot]":{desc:"\u90E8\u7F72\u7EFC\u5408\u8FD0\u8425\u7CFB\u7EDF",alias:"ppl",action:async y=>{await new J(EPlatForm.PL_OPERATOR).plOperatorMain(y)}},"public-merchant [fileRoot]":{desc:"\u90E8\u7F72SaaS\u5546\u6237\u540E\u53F0",alias:"ppm",action:async y=>{await new J(EPlatForm.SAAS_MERCHANT).saasMerchantMain(y)}},open:{desc:"\u5728\u6D4F\u89C8\u5668\u6253\u5F00\u5F53\u524D\u4ED3\u5E93",alias:"o",action:async()=>{await openStore()}},release:{desc:"\u53