#!/usr/bin/env node "use strict";const f$2=require("cac"),c12=require("c12"),n$3=require("fs-extra"),l=require("kolorist"),o$3=require("enquirer"),fs=require("fs"),r$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$2=require("bumpp"),c$2=require("form-data"),semver=require("semver"),f$1=require("archiver");function _interopDefaultCompat(u){return u&&typeof u=="object"&&"default"in u?u.default:u}function _interopNamespaceCompat(u){if(u&&typeof u=="object"&&"default"in u)return u;const F=Object.create(null);if(u)for(const d in u)F[d]=u[d];return F.default=u,F}const f__default$2=_interopDefaultCompat(f$2),n__default=_interopDefaultCompat(n$3),l__namespace=_interopNamespaceCompat(l),o__default=_interopDefaultCompat(o$3),r__default=_interopDefaultCompat(r$2),b__default=_interopDefaultCompat(b$2),f__default=_interopDefaultCompat(f),e__default=_interopDefaultCompat(e$2),c__default=_interopDefaultCompat(c$2),f__default$1=_interopDefaultCompat(f$1),e$1={useRemote:"origin"};async function execCommand(u,F=[],d={}){const{execa:B}=await import("execa");return(await B(u,F,d))?.stdout?.trim()||""}function createMkdir(u){n$3.existsSync(u)||(n$3.mkdirSync(u,{recursive:!0}),console.log("\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u521B\u5EFA"))}const t$1=console.log,n$2=(u="")=>t$1(l__namespace.yellow(u)),g=(u="")=>t$1(l__namespace.green(u)),s$1=(u="")=>t$1(l__namespace.red(u)),r$1=(u="")=>t$1(l__namespace.lightBlue(u)),c$1=(u="")=>t$1(l__namespace.lightMagenta(u)),RegGitVersion=/^.*[0-9]{1,4}(\.[0-9]{1,4}){2,3}$/,RegResultSplitToArr=/\n{1,}\s*/,p$1=async(u,F)=>{try{const d=[execCommand(`git tag -d ${u}`)];F.includes(`refs/tags/${u}`)&&d.push(execCommand("git",["push",e$1.useRemote,`:refs/tags/${u}`])),await Promise.all(d)}catch(d){console.warn(`error:\u5220\u9664tag:${u}\u9519\u8BEF`,d)}};async function deleteTag(u=""){let F=[];if(u&&F.push(u),!u){const y=(await execCommand("git tag -l")).split(RegResultSplitToArr),{tags:v}=await o__default.prompt([{name:"tags",type:"multiselect",message:"\u8BF7\u9009\u62E9\u9700\u8981\u5220\u9664\u7684tag",choices:y.map(k=>({name:k})),validate(k){return!!k.length||"\u8BF7\u9009\u62E9\u81F3\u5C11\u4E00\u4E2Atag"}}]);F=v}const d=await execCommand(`git ls-remote --tags ${e$1.useRemote}`),B=[];F.forEach(y=>{B.push(p$1(y,d))}),await Promise.all(B),g("\u64CD\u4F5C\u5B8C\u6210\u4E86")}var m$1=Object.defineProperty,h$2=(u,F,d)=>F in u?m$1(u,F,{enumerable:!0,configurable:!0,writable:!0,value:d}):u[F]=d,n$1=(u,F,d)=>(h$2(u,typeof F!="symbol"?F+"":F,d),d);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 F=this.originBranch.split("/")[0];verifyVersion(F)&&(this.versionNumber=F,this.setMainBranch()),await Promise.all([this.setProjectMainBranch()]),await checkWorkingNoCommit(),watchProcessAccident(backToOriginalBranch);try{await execCommand("git",["remote","update",e$1.useRemote,"--prune"])}catch(d){console.log("\u5237\u65B0\u5206\u652F\u9519\u8BEF: ",d)}}setMainBranch(){this.versionMainBranch=`${this.versionNumber}/main`}async setVersionNumber(F){const{version:d}=await o__default.prompt([mergePromptOptions(PromptMap.inputVersion,JSON.parse(JSON.stringify({default:this.versionNumber,message:F})))]);this.versionNumber=d,n$2(`\u5F53\u524D\u7248\u672C:${this.versionNumber}`),this.setMainBranch(),n$2(`\u5F53\u524D\u7248\u672C\u4E3B\u5206\u652F:${this.versionMainBranch}`)}async setProjectMainBranch(){const[F,d]=await Promise.all([checkBranch("master"),checkBranch("main")]);F.remoteExist?this.projectMainBranch="master":d.remoteExist?this.projectMainBranch="main":(s$1(`\u5F53\u524D\u9879\u76EE\u7F3A\u5C11\u4E3B\u5206\u652F:${this.versionMainBranch}`),await exitWithError())}setFuncName(F){this.funcName=F}async getFuncFullName(){return this.funcName||(s$1("\u62B1\u6B49\u6CA1\u6709\u627E\u5230\u529F\u80FD\u5206\u652F"),await exitWithError()),`${this.versionNumber}/${this.funcName}`}async getProjectName(){const F=await getPackageJsonAttr({packageJson:["name"]});F&&F.name&&(this.projectName=F.name,n$2(`\u5F53\u524D\u9879\u76EE\u540D\u79F0:${F.name}`))}}const versionInfo=new VersionInfo;var EGitVersionActionType=(u=>(u.new="new",u.merge="merge",u.mq="mq",u.build="build",u.publish="publish",u.check="check",u.fix="fix",u.move="move",u.test="test",u))(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 u=>{let F;if(u){const d=EGitVersionActionType[u];d&&(F=d)}if(!F){const d=Object.keys(EGitVersionActionType).map(y=>({name:y,message:`${y.padEnd(10)}${actionDescription[y]}`})),{choicesActionType:B}=await o__default.prompt([{name:"choicesActionType",type:"select",message:"\u8BF7\u9009\u62E9\u64CD\u4F5C\u7C7B\u578B",choices:d}]);F=B}return F},chooseIsBuild=async(u=!0)=>{const{isBuild:F}=await o__default.prompt([{name:"isBuild",type:"confirm",initial:u,message:"\u662F\u5426\u9700\u8981\u7F16\u8BD1"}]);return F},chooseAnCheck=async(u,F=!0)=>{const{isCheck:d}=await o__default.prompt([{name:"isCheck",type:"confirm",initial:F,message:u}]);return d},chooseBuildEnv=async()=>{const{env:u}=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 u},chooseOfficialBuildProject=async()=>{const{project:u}=await o__default.prompt([{name:"project",type:"select",message:"\u8BF7\u9009\u62E9\u8981\u6253\u5305\u7684\u9879\u76EE",choices:[{name:"open"},{name:"index"}]}]);return u},chooseMergeRequestTargetBranch=async(u,F=0)=>{const{branchName:d}=await o__default.prompt([{name:"branchName",type:"select",initial:F,message:"\u8BF7\u9009\u62E9\u76EE\u6807\u5206\u652F\uFF0C(\u9ED8\u8BA4\u7248\u672C\u4E3B\u5206\u652F)",choices:u.map(B=>({name:B}))}]);return d};async function createUpdateMdFile(u=!0,F=!1,d=""){const B=r$2.join(process.cwd(),"doc","update.md");if(!u&&n$3.existsSync(B))return F&&c$1(`Warn: ${B} \u5DF2\u5B58\u5728`),!1;const y=readStaticTemplateFileSync("update_md.ejs");if(typeof y=="boolean")return s$1("Error: \u521B\u5EFAupdate.md\u5931\u8D25"),!1;const v=ejs.render(y,{version:d}),k=await prettier.format(v,{parser:"markdown"});return n$3.writeFileSync(B,k),!0}async function openUpdateMdFile(){try{const u=await fastGlob.glob(["**/doc/update.md"],{ignore:["**/node_modules/**"]});if(u.length)return(await import("open")).default(u[0]),await r$1(`\u6253\u5F00 ${versionInfo.versionNumber} \u7248\u672C\u5347\u7EA7\u6B65\u9AA4\u6587\u6863`),!0}catch(u){console.log("openUpdateMdFile Error:",u)}return!1}async function openAndClearUpdateMdFile(){const u=await fastGlob.glob(["**/doc/update.md"],{ignore:["**/node_modules/**"]});if(!u.length)return;const F=await execCommand("uname"),d=r$2.resolve(process.cwd(),u[0]);let B="";if(F==="Darwin")B=r$2.resolve(`/tmp/${versionInfo.projectName}.${versionInfo.versionNumber}.update.md`),n$3.copyFileSync(d,B);else{const y="C:/tmp";createMkdir(y),B=r$2.join(y,`./${versionInfo.projectName}.${versionInfo.versionNumber}.update.md`)}n$3.copyFileSync(d,B),await createUpdateMdFile(),(await import("open")).default(B)}function backToOriginalBranch(){return gitCheckoutBranch(versionInfo.originBranch)}async function mergeAToB(u,F){r$1(`\u5408\u5E76\u5206\u652F:${u} to ${F}`),await gitCheckoutBranch(u,"",!1),await gitPull(!1),await gitCheckoutBranch(F),await gitPull(!1);try{await execCommand("git",["merge",u,"--no-edit"])}catch{terminalLog.start("\u7B49\u5F85\u89E3\u51B3\u5408\u5E76\u51B2\u7A81"),await verifyMergeStatus()}await gitPush(),terminalLog.SuccessEnd(`\u5408\u5E76\u5206\u652F:${u} to ${F} \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$1(`\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 u=process.env.HOME;return u?r__default.join(u,"gitlab.token"):(s$1("\u6CA1\u6709\u627E\u5230\u7CFB\u7EDF\u9ED8\u8BA4\u8DEF\u5F84"),"")}function deleteGitlabToken(){n$3.writeFileSync(getGitlabTokenPath(),"")}async function initGitToken(){if(await readGitlabToken({showError:!1}))return!0;const{tempToken:u}=await o__default.prompt({name:"tempToken",type:"text",message:"\u8BF7\u586B\u5199\u4E34\u65F6\u4EE4\u724C",validate:d=>d.trim().length?!0:"\u8BF7\u8F93\u5165\u6709\u6548\u7684\u5B57\u7B26\u4E32"}),F=getGitlabTokenPath();return F?(n$3.writeFileSync(F,u),!0):!1}function readGitlabToken({showError:u}={showError:!0}){const F="gitlab.token",d=getGitlabTokenPath();if(!d)return"";const B=process.env.HOME;try{n$3.statSync(d)}catch{return s$1(`\u6CA1\u6709\u627E\u5230 ${d} \u6587\u4EF6`),n$2(`\u8BF7\u521B\u5EFA\u5E76\u5199\u5728 ${B} \u76EE\u5F55\u4E0B\u7684 ${F} \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 y="";try{y=n$3.readFileSync(d,{encoding:"utf8"}).trim(),y||s$1(`${d} \u6587\u4EF6\u6CA1\u6709\u5185\u5BB9`)}catch{u&&s$1(`\u8BFB\u53D6 ${d} \u6587\u4EF6\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u662F\u5426\u5B58\u5728`)}return y}async function getGitlabProjectId(){const{value:u=""}=await gitProject.getConfig(`remote.${e$1.useRemote}.url`),F=u?.match(/\/([^/]+\/[^/]+)\.git$/);if(F&&F[1]){const d=F[1];return encodeURIComponent(d)}throw new Error(`\u83B7\u53D6 \u9879\u76EEid \u9519\u8BEF\u5566 ${u}`)}async function getGitlabLaunchMergeRequestByProjectId({projectId:u,gitlabToken:F,originBranch:d,targetBranch:B}){try{const y=await new axios.Axios({headers:{"PRIVATE-TOKEN":F}}).post(`http://git.rantron.biz:3002/api/v4/projects/${u}/merge_requests`,querystring.stringify({source_branch:d,target_branch:B,title:`new merge request ${d} -> ${B}`})),v=JSON.parse(y.data);if(v.iid)return r$1(`\u521B\u5EFA\u5408\u5E76\u8BF7\u6C42\u6210\u529F ${d} -> ${B} \uFF0C\u8BF7\u6C42id\uFF1A${v.iid}\uFF0C\u627E\u9879\u76EE\u8D1F\u8D23\u4EBA\u8FDB\u884C\u5BA1\u6838`),r$1(`\u5BFC\u822A\u94FE\u63A5: ${v.web_url}`),!0;if(v.message)console.log(`${l__namespace.red("\u8BF7\u6C42\u5408\u5E76\u53D1\u751F\u9519\u8BEF\uFF0C")}${l__namespace.lightMagenta(`\u9519\u8BEF\u4FE1\u606F\uFF1A${v.message}`)}`);else throw v}catch(y){console.log("\u{1F3F7}\uFE0F ~ getGitlabLaunchMergeRequestByProjectId error:",y),deleteGitlabToken(),s$1(y)}return!1}async function checkWorkingStatus(){return execCommand("git",["status"])}async function checkWorkingNoCommit(){return(await checkWorkingStatus()).includes("nothing to commit")?!0:(s$1("\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(u=!0,F=""){const d=F||await gitGetCurrentBranch();try{const B=await execCommand("git",["push","-u",e$1.useRemote,d]);return u&&g(`\u63A8\u9001\u5206\u652F ${d} \u5230 \u8FDC\u7A0B ${e$1.useRemote} `),B}catch(B){return s$1(`\u63A8\u9001\u5931\u8D25 ${d} `),Promise.reject(B)}}async function gitPull(u=!0){const F=await execCommand("git",["pull"]);if(u){const d=await gitGetCurrentBranch();g(`\u62C9\u53D6 ${d} \u5206\u652F\u6700\u65B0\u4EE3\u7801`)}return F}async function gitCheckoutBranch(u,F="",d=!0){return await gitGetCurrentBranch()===u||(await execCommand("git",["checkout",u]),d&&g(F||`\u5207\u6362\u5206\u652F\u5230 ${u} `)),!0}async function gitDeleteBranch(u,F={deleteRemote:!1,deleteLocal:!0,showLog:!0,logMessage:""}){if(F.deleteLocal&&await execCommand("git",["branch","-d",u]),F.deleteRemote){if(u.includes("main"))throw new Error("delete protected branches using");await execCommand("git",["push",e$1.useRemote,"--delete",u])}(F.deleteLocal||F.deleteRemote)&&F.showLog&&g(F?.logMessage||`\u5220\u9664\u5206\u652F ${u} \u6210\u529F`)}function verifyVersion(u){return RegGitVersion.test(u)}async function checkBranch(u){const[F,d]=await Promise.all([execCommand("git branch"),execCommand("git branch -r")]),B=F.split(RegResultSplitToArr).map(x=>x.replace(/\*\s/,"")),y=d.split(RegResultSplitToArr),v=B.includes(u),k=!!y.find(x=>x===`${e$1.useRemote}/${u}`);return{remoteExist:k,localExist:v,allExist:k&&v,allNotExist:!k&&!v}}async function deleteLocalVersionOriginMain(){return await gitDeleteBranch(versionInfo.versionMainBranch,{showLog:!1}),!0}async function checkVersionMainBranch(u=versionInfo.versionMainBranch){const F=async(B=!0)=>{await gitPush(B,u),await deleteLocalVersionOriginMain()},d=await checkBranch(u);d.allNotExist?(await gitPullMainNewCode(),await execCommand("git",["branch",u]),await F(!1),g(`\u521B\u5EFA\u7248\u672C\u4E3B\u5206\u652F ${u}\uFF0C\u5E76\u63A8\u9001\u5230\u8FDC\u7A0B`)):d.localExist&&await F(),await gitCheckoutBranch(versionInfo.projectMainBranch,"",!1),await deleteLocalVersionOriginMain()}function _$1(u){const F=u.split("/");if(!F.length)throw new Error("\u6CA1\u6709\u89E3\u6790\u51FA\u529F\u80FD\u5206\u652F");return F.pop()}async function parseFuncFromBranch(){const u=_$1(versionInfo.originBranch);versionInfo.setFuncName(u),r$1(`\u5F53\u524D\u529F\u80FD:${versionInfo.funcName}`)}async function readFunc(){if(!versionInfo.funcName){const{inputFuncName:u}=await o__default.prompt({name:"inputFuncName",type:"text",message:"\u8BF7\u8F93\u5165\u65B0\u529F\u80FD\u540D",validate:F=>{const d=F.trim();if(d.length){if(/\s/.test(d))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(u.trim())}r$1(`\u5F53\u524D\u529F\u80FD:${versionInfo.funcName}`)}async function checkFunBranchExist(){const u=await versionInfo.getFuncFullName(),{localExist:F,remoteExist:d,allExist:B}=await checkBranch(u);return B?(s$1(`\u7248\u672C\u529F\u80FD\u5206\u652F ${u} \u5DF2\u5B58\u5728!!!`),!0):d?(s$1(`\u7248\u672C\u529F\u80FD\u5206\u652F ${u} \u8FDC\u7A0B\u5DF2\u7ECF\u5B58\u5728!!!`),!0):F?(s$1(`\u7248\u672C\u529F\u80FD\u5206\u652F ${u} \u672C\u5730\u5DF2\u7ECF\u5B58\u5728!!!`),!0):!1}async function createBranchFromProjectFuncBranch(){await readFunc(),await checkFunBranchExist()&&(await backToOriginalBranch(),await exitWithError()),await gitPullMainNewCode();const u=await versionInfo.getFuncFullName();await execCommand("git",["checkout","-b",u]),await gitPush(),g(`${u} \u529F\u80FD\u5206\u652F\u521B\u5EFA\u5B8C\u6210`)}async function checkOriginMainBranchExist(){return(await checkBranch(versionInfo.versionMainBranch)).remoteExist||(s$1(`\u62B1\u6B49 ${versionInfo.versionMainBranch} \u7248\u672C\u4E3B\u5206\u652F\u4E0D\u5B58\u5728`),await exitWithError()),!0}function checkBranchIsProjectMainBranch(u){return u===versionInfo.projectMainBranch||u===`remotes/${e$1.useRemote}/${versionInfo.projectMainBranch}`}function q(u){return!!(u.startsWith(versionInfo.versionNumber)||u.includes(`${e$1.useRemote}/${versionInfo.versionNumber}/`))}async function checkVersionMainBranchHasNotMerged(){await gitCheckoutBranch(versionInfo.versionMainBranch),await gitPull();const u=(await execCommand("git",["branch","-a","--no-merged"])).split(RegResultSplitToArr);try{const F=[];if(u.forEach(d=>{if(checkBranchIsProjectMainBranch(d)||q(d)){const B=d.replace(`remotes/${e$1.useRemote}/`,"");F.includes(B)||F.push(B)}}),F.length)throw new Error(`\u5206\u652F [${l__namespace.green(F.join("\uFF0C"))}] \u8FD8\u6CA1\u5408\u5E76\uFF0C\u8BF7\u5148\u5408\u5E76\u540E\u518D \u53D1\u5E03/\u6253\u5305`)}catch(F){s$1(F),await backToOriginalBranch(),versionInfo.originBranch!==await gitGetCurrentBranch()&&await deleteLocalVersionOriginMain(),await exitWithError()}}async function startBuild(u=!0){if(await chooseIsBuild(u)){r$1("\u5F00\u59CB\u6253\u5305...");try{return await execCommand("npm",["run","build"],{stdio:"inherit"}),g("\u7F16\u8BD1\u5B8C\u6210!"),!0}catch{return s$1("\u7F16\u8BD1\u5931\u8D25!"),!1}}return!1}async function E(u=!0){u&&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 u=await chooseBuildEnv();switch(u){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$1(`Error:${u}`)}}async function N(){const u=await chooseOfficialBuildProject();await execCommand("npm",["run",`build:${u}`],{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 u=`${versionInfo.versionNumber}/publish/${b__default().format("YY/M/D")}`;await execCommand("git",["tag","-f",u]),await execCommand("git",["push","-f",e$1.useRemote,u]),r$1(`\u7248\u672C\u589E\u52A0tag${u}`)}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 u=await checkFunBranchExist();await backToOriginalBranch(),u&&await exitWithError();const F=`${versionInfo.originBranch.split("/")[0]}/main`,d=await versionInfo.getFuncFullName();await execCommand("git",["branch","-m",versionInfo.originBranch,d]),gitPush(),r$1(`\u4FEE\u6539\u5206\u652F ${versionInfo.originBranch} \u4E3A ${d}`);const{remoteExist:B}=await checkBranch(F);await gitDeleteBranch(versionInfo.originBranch,{deleteRemote:B,deleteLocal:!1}),B&&n$2(`\u5220\u9664\u8FDC\u7A0B\u5206\u652F ${versionInfo.originBranch}`);const{remoteExist:y,localExist:v}=await checkBranch(F);if(y||v)try{await gitDeleteBranch(F,{deleteRemote:y,deleteLocal:v,showLog:!1})}catch(k){if(JSON.stringify(k).includes("delete protected branches using")){if(!await gitlabApiDeleteBranch(F))return}else{s$1(k);return}}await checkVersionMainBranch(F),await gitCheckoutBranch(d)}async function gitlabApiDeleteBranch(u){try{const F=await getGitlabProjectId();if(!await initGitToken())return!1;const d=await readGitlabToken();return await new axios.Axios({headers:{"PRIVATE-TOKEN":d}}).delete(`http://git.rantron.biz:3002/api/v4/projects/${F}/repository/branches/${encodeURIComponent(u)}`),await execCommand("git",["remote","update",e$1.useRemote,"--prune"]),!0}catch(F){r$1(`\u5220\u9664\u8FDC\u7A0B ${u} \u5206\u652F\u9519\u8BEF error ${F}`)}return!1}async function createFixBranch(){const u="fixOnline";versionInfo.setFuncName(u);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:u}=await gitProject.branch(["-r"]),F=u.filter(d=>d.includes(`${e$1.useRemote}/${versionInfo.versionNumber}/`)&&!d.endsWith(`${e$1.useRemote}/${versionInfo.originBranch}`)).sort((d,B)=>d.includes("main")&&!B.includes("main")?-1:!d.includes("main")&&B.includes("main")?1:0);if(!F.length)throw await backToOriginalBranch(),new Error("\u6CA1\u6709\u5176\u4ED6\u7248\u672C\u5206\u652F");return(await chooseMergeRequestTargetBranch(F)).replace(`${e$1.useRemote}/`,"")}const getMergeRquestOriginBranch=async u=>{const F=`${versionInfo.originBranch}_temp_merge`;let d=versionInfo.originBranch,B=!0;try{await execCommand("git",["merge",`${e$1.useRemote}/${u}`,"--no-commit"]),gitProject.merge(["--abort"]),B=!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,F]),execCommand("git",["branch","-d",F])])}catch{}return B&&(d=F,await execCommand("git",["checkout","-b",F]),await gitPush(),await mergeAToB(u,F)),d},w$1=/^(\d{1,3}\.){3}\d{1,3}$/,A$2=/^([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,5})$/,o$2=u=>w$1.test(u),p=u=>A$2.test(u),P=u=>o$2(u)||p(u),m=async(u="\u8BF7\u8F93\u5165ip/\u57DF\u540D",F="\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip/\u57DF\u540D",d=1)=>o__default.prompt([{name:"ip",type:"text",message:u,required:!0,validate(B){return d===1?P(B)||F:d===2?o$2(B)||F:p(B)||F}}]),R$1=u=>p(u)?new Promise(F=>{f__default.lookup(`${u}`,(d,B)=>{F(d?"":`\u5BF9\u5E94\u7684IP\u5730\u5740:${l__namespace.lightCyan(B)}`)})}):Promise.resolve(""),I=u=>new Promise(F=>{ping.sys.probe(u,d=>{const B=d?l__namespace.green("alive"):l__namespace.red("dead");F(`${l__namespace.lightBlue(u)} is ${B}`)})}),b$1=u=>Promise.resolve(""),h$1=async u=>{const[F,d,B]=await Promise.all([I(u),R$1(u),b$1()]);return`${F} ${d} ${B}`};async function PingPort(u,F=""){if(u){let d="",B=F;if(!o$2(B)){const{ip:L}=await m("\u8BF7\u8F93\u5165\u8303\u56F4\u8D77\u59CB\u7684ip","\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip",2);B=L}const{ip:y}=await m("\u8BF7\u8F93\u5165\u8303\u56F4\u7ED3\u675F\u7684ip","\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip",2);d=y;const v=B.split(".").map(Number),k=d.split(".").map(Number),x=[];for(let L=v[3];L<=k[3];L+=1){const U=[...v];U[3]=L,x.push(I(U.join(".")))}terminalLog.start("\u6B63\u5728\u75AF\u72C2ping\u4E2D");const j=await Promise.all(x);console.log(` ------------------- ${j.join(` `)} -------------------`),terminalLog.SuccessEnd("ping\u5B8C\u6210\u5566")}else{let d="";if(P(F)&&(d=F),!d){const{ip:y}=await m();d=y}const B=await h$1(d);console.log(` ------------------- ${B} -------------------`)}}const PromptMap={inputVersion:{name:"version",type:"text",message:"\u8BF7\u8F93\u5165\u7248\u672C\u53F7",required:!0,validate(u){return verifyVersion(u)||"\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u7248\u672C\u53F7 ps: 1.0.0 | project1.0.0"}}},mergePromptOptions=(u,F={})=>({...u,...F}),c=()=>{const u=__dirname.split(/(\\|\/)/);for(;u.length&&!/^(dist|src)$/.test(u[u.length-1]);)u.pop();return u.join("/")},readStaticFile=(u="")=>{const F=c(),d=r$2.join(F,"./static/",u);try{return fs.readFileSync(d).toString()}catch{s$1(`Error:\u6587\u4EF6\u4E0D\u5B58\u5728${d}`)}return!1},readStaticTemplateFileSync=(u="")=>readStaticFile(r$2.join("./template",u));var o$1=Object.defineProperty,a$1=(u,F,d)=>F in u?o$1(u,F,{enumerable:!0,configurable:!0,writable:!0,value:d}):u[F]=d,i$1=(u,F,d)=>(a$1(u,typeof F!="symbol"?F+"":F,d),d);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 F=await import("ora");this.spinner=await F.default({color:"green",spinner:r,prefixText:"start"})}setSpinnerStyle(F,d){this.spinner&&Object.assign(this.spinner,{prefixText:d,spinner:F})}start(F="waiting",d="waiting **s"){this.showDesc=l__namespace.red(F),this.index=0,this.preTextFormat=d,this.spinner?.start(this.showDesc),this.startNow=Date.now(),this.circle()}SuccessEnd(F){this.spinner&&this.spinner.succeed(`${F}\u{1F604}`),this.end()}FailEnd(F){this.spinner&&this.spinner.fail(`${F}\u{1F604}`),this.end()}end(){clearInterval(this.timer),this.setSpinnerStyle(r,"")}circle(){this.timer=setInterval(()=>{const F=this.getLoadingSeconds();if(this.spinner&&this.shapeList.length){F%3||(this.index=(this.index+1)%this.shapeList.length);const d=this.preTextFormat.replace("**",`${F}`);this.setSpinnerStyle(this.shapeList[this.index],l__namespace.blue(l__namespace.bgGreen(d)))}},1e3)}getLoadingSeconds(){return Math.ceil((Date.now()-this.startNow)/1e3)}}const terminalLog=new h,sleep=(u=1e3)=>new Promise(F=>{setTimeout(()=>{F("\u7761\u7720\u5B8C\u6210")},u)});function exitWithSuccess(u=!0){return u?new Promise(F=>{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",()=>{F("\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((u,F)=>{process.stdin.setRawMode(!0),process.stdin.resume(),s$1("cli\u6267\u884C\u5931\u8D25\uFF0C\u6309\u4EFB\u610F\u952E\u9000\u51FA\uFF01"),process.stdin.on("data",()=>{F(new Error("Program Exit")),process.exit()})})}function watchProcessAccident(u,F=!1){process.on("exit",async d=>{d!==0&&(F&&await u(),s$1(`\u8FDB\u7A0B\u9000\u51FA\u7F16\u7801:${d}`))}),process.on("SIGINT",async()=>{await u(),process.exit(0)})}const getPackageJsonAttr=async u=>{const F={};if(u.packageJson){const d=(Array.isArray(u.packageJson)?u.packageJson:[typeof u.packageJson=="string"?u.packageJson:u.name]).filter(y=>y&&typeof y=="string"),B=await pkgTypes.readPackageJSON(u.cwd).catch(y=>{});if(B){const y={};d.forEach(v=>{B[v]&&(y[v]=B[v])}),Object.assign(F,y)}}return F},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(u,F=process.cwd()){const d={overrides:u,name:"ppg",defaults:a,cwd:F,packageJson:["name"]},{config:B}=await c12.loadConfig(d),y=await getPackageJsonAttr(d);return Object.assign(B||{},y)}const version="0.0.31";async function gitCommit(u,F){const d=u.map(([k,x])=>{const j=`${`${k}:`.padEnd(12)}${x}`;return{name:k,message:j}}),B=F.map(([k,x])=>({name:k,message:`${k.padEnd(12)} (${x})`})),y=await o__default.prompt([{name:"types",type:"select",message:"\u8BF7\u9009\u62E9\u63D0\u4EA4\u7C7B\u578B",choices:d},{name:"scopes",type:"select",message:"\u9009\u62E9\u4E00\u4E2Ascope",choices:B},{name:"description",type:"text",message:"\u8BF7\u8F93\u5165\u63D0\u4EA4\u63CF\u8FF0",required:!0}]),v=`${y.types}(${y.scopes}): ${y.description}`;execCommand("git",["commit","-m",v],{stdio:"inherit"})}async function openStore(u=""){let F=u;if(F||(F=await execCommand("git",["remote","get-url",e$1.useRemote])),!F)return s$1("\u6CA1\u6709\u53EF\u6253\u5F00\u7684\u7F51\u5740(\uFF3E\uFF0D\uFF3E)");const d=await import("open");r$1(`\u6253\u5F00\u5730\u5740: ${F}`);try{await d.default(F,{wait:!0}),g("Default browser opened successfully.")}catch(B){s$1(`Unable to open the default browser:${B}`)}return!0}const A$1=async()=>{if(await checkInvalidBranch(),await versionInfo.setVersionNumber(),!await initGitToken())return;await gitPullMainNewCode();const u=await getMergeRequestTargetBranch();await mergeAToB(versionInfo.projectMainBranch,versionInfo.originBranch),await backToOriginalBranch();const F=readGitlabToken();if(!F)return;const d=await getMergeRquestOriginBranch(u),B=await getGitlabProjectId();await getGitlabLaunchMergeRequestByProjectId({projectId:B,gitlabToken:F,originBranch:d,targetBranch:u}),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$1(`\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=async()=>{await checkInvalidBranch(),await versionInfo.setVersionNumber(),await checkVersionMainBranchHasNotMerged(),await mergeAToB(versionInfo.versionMainBranch,"test"),await handleMoreProjectBuildByTest(),await backToOriginalBranch(),await gitDeleteBranch(versionInfo.versionMainBranch)};async function getVersion(u){await versionInfo.init();const F=await chooseActionType(u);switch(F){case EGitVersionActionType.mq:await A$1();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();break;default:s$1(`\u6CA1\u6709\u4EFB\u4F55\u811A\u672C\u53EF\u6267\u884C ${F}`)}await exitWithSuccess(!1)}async function gitCommitVerify(){const u=await execCommand("git",["rev-parse"]),F=r__default.join(u,".git","COMMIT_EDITMSG"),d=fs.readFileSync(F,{encoding:"utf8"});if(!/(?[a-z]+)(\((?[a-z]+)\))?(?!)?:(?.+)/i.test(d))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({files:["**/package.json","!**/node_modules"],all:!0,tag:!0,commit:"chore(projects): release v%s",push:!0})}var EPlatForm=(u=>(u[u.WEChAT=0]="WEChAT",u[u.ALIPAY=1]="ALIPAY",u[u.STATIC=2]="STATIC",u[u.PL_OPERATOR=3]="PL_OPERATOR",u[u.SAAS_MERCHANT=4]="SAAS_MERCHANT",u))(EPlatForm||{});const getUploadInfoRoot=()=>{const u=process.env.HOME;if(!u)return s$1("\u6CA1\u6709\u627E\u5230\u7CFB\u7EDF\u9ED8\u8BA4\u8DEF\u5F84"),"";const F=r__default.join(u,"fhdUploadFile.json");return n__default.existsSync(F)||n__default.writeJSONSync(F,{}),F},initUploadInfo=()=>{const u=getUploadInfoRoot();return n__default.readJsonSync(u)},R={0:"wxFileRoot",1:"aliFileRoot",2:"staticFileRoot",3:"ploperatorFileRoot",4:"saasMerchantFileRoot"},getFileRoot=async(u,F)=>{const d=getUploadInfoRoot(),B=n__default.readJsonSync(d),y=R[u];if(F&&n__default.existsSync(r$2.resolve(F))?B[y]=r$2.resolve(F):F&&s$1(`\u8DEF\u5F84\u4E0D\u5B58\u5728 ${F}`),!B[y]){const{pathRoot:v}=await o__default.prompt([{name:"pathRoot",type:"text",message:"\u8BF7\u8F93\u5165\u8DEF\u5F84",required:!0}]);return getFileRoot(u,v)}return B[y]},ChcZipName="chc\u6821\u9A8C\u6587\u4EF6.zip",StaticZipName="static.zip",SaasZipName="saas.zip",prepareDirFileZip=async(u,F)=>{const d=r__default.join(u,".."),B=r__default.resolve(u);if(!fs.existsSync(B))return s$1(`${B}\u4E0D\u5B58\u5728`),!1;const y=fs.createWriteStream(r__default.join(d,F)),v=f__default$1("zip",{zlib:{level:9}});if(v.on("error",k=>{throw s$1(` archiveSaas error-> ${JSON.stringify(k)}`),k}),y.on("close",()=>{g(`\u6587\u4EF6 \u538B\u7F29\u5305\u521B\u5EFA\u5B8C\u6210\uFF0C\u6587\u4EF6\u5927\u5C0F: ${v.pointer()} \u5B57\u8282`)}),y.on("error",k=>{throw s$1(` archive zip error-> ${JSON.stringify(k)}`),k}),v.pipe(y),!F.split(".")[0])throw"\u6CA1\u6709\u6587\u4EF6\u540D\u79F0";v.directory(B,F.split(".")[0]),v.finalize(),await sleep()},prepareAliZipFile=async u=>{const F=r__default.join(u,".."),d=r__default.resolve(u);if(!fs.existsSync(d))return s$1(`${d}\u4E0D\u5B58\u5728`),!1;const B=fs.createWriteStream(r__default.join(F,ChcZipName)),y=f__default$1("zip",{zlib:{level:9}});B.on("close",()=>{g(`\u6821\u9A8C\u6587\u4EF6 \u538B\u7F29\u5305\u521B\u5EFA\u5B8C\u6210\uFF0C\u6587\u4EF6\u5927\u5C0F: ${y.pointer()} \u5B57\u8282`)}),y.on("error",x=>{throw s$1(` archiveCheck error-> ${JSON.stringify(x)}`),x});const v=new Set;function k(x){fs.readdirSync(x).forEach(j=>{const L=r__default.join(x,j);if(fs.statSync(L).isDirectory())k(L);else if([".html",".txt"].includes(r__default.extname(j))){if(v.has(j))return;v.add(j),y.append(fs.createReadStream(L),{name:r__default.basename(j)})}})}k(d),y.pipe(B),y.finalize(),await sleep()};var n=Object.defineProperty,i=(u,F,d)=>F in u?n(u,F,{enumerable:!0,configurable:!0,writable:!0,value:d}):u[F]=d,e=(u,F,d)=>(i(u,typeof F!="symbol"?F+"":F,d),d);class FileUploadAxios{constructor(){e(this,"token",""),e(this,"axiosInstance"),this.axiosInstance=new axios.Axios({}),this.axiosInstance.interceptors.request.use(F=>{const d=F.data instanceof c__default;if(F.method==="post"&&!d){const B=F.data||{};B.token=B.token||this.token,B.referer="mgrapi",F.data=querystring.stringify(B)}else if(F.method==="get"){const B={...F.params||{}};F.params={...B,token:B.token||this.token,referer:"mgrapi"}}return F}),this.axiosInstance.interceptors.response.use(F=>{const d=JSON.parse(F.data||"{}"),B=d.rcode===0;return{...F,data:{...d||{},isSuccess:B}}})}setToken(F=""){this.token=F}}new FileUploadAxios;var Z=Object.defineProperty,b=(u,F,d)=>F in u?Z(u,F,{enumerable:!0,configurable:!0,writable:!0,value:d}):u[F]=d,s=(u,F,d)=>(b(u,typeof F!="symbol"?F+"":F,d),d);const A={[EPlatForm.WEChAT]:[49,48,41],[EPlatForm.ALIPAY]:[49,48],[EPlatForm.STATIC]:[36],[EPlatForm.PL_OPERATOR]:[52],[EPlatForm.SAAS_MERCHANT]:[41]},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:""}];class M{constructor(F){s(this,"uploadRequest",new FileUploadAxios),s(this,"localUploadInfo",initUploadInfo()),s(this,"publishFileRoot",""),s(this,"configFilePath",getUploadInfoRoot()),s(this,"uploadInfoList",[]),s(this,"currentPlatfrom"),s(this,"initUploadInfoList",async()=>{const{data:{data:d,isSuccess:B}}=await this.uploadRequest.axiosInstance.get("https://mgrapi.fhd001.com/mgr/rdc/staticResource/getUserStaticResourceDirectoryList.do");if(!B)throw s$1(JSON.stringify(d)),new Error("\u83B7\u53D6\u4E0A\u4F20\u914D\u7F6E\u5931\u8D25");const y=w.map(v=>{const k=d.find(L=>L.id===v.id);if(!k?.lastStaticResourcePublishLog?.version)throw new Error(`${v.name} \u7EBF\u4E0A\u914D\u7F6E\u4E0D\u5B58\u5728`);const{version:x}=k?.lastStaticResourcePublishLog||{},j=semver.inc(x,"patch")||"";return{...v,oldPublishVersion:x,newPublishVersion:j}});this.uploadInfoList=y}),s(this,"publicZip",async d=>{const{data:{data:B,isSuccess:y}}=await this.uploadRequest.axiosInstance.post("https://mgrapi.fhd001.com/mgr/common/upload/createUploadToken",{fileName:d.uploadZipFileName,isPrivate:!0});if(!y)throw s$1(`${d.name} \u83B7\u53D6\u4E0A\u4F20token errorinfo -> ${JSON.stringify(B)}`),new Error("\u4E0A\u4F20\u5931\u8D25");const v=new c__default;if(!d.uploadZipFileName.trim())throw new Error("\u6587\u4EF6\u540D\u4E3A\u7A7A");const k=r__default.join(this.publishFileRoot,d.uploadZipFileName),x=n$3.readFileSync(k);v.append("files[]",x,{filename:d.uploadZipFileName.split(".")[0]}),v.append("token",B);const j={headers:{Referer:"https://oss.fhd001.com/",Origin:"https://oss.fhd001.com"}},{data:{data:L,isSuccess:U}}=await this.uploadRequest.axiosInstance.post("https://download.fhd001.com/upload",v,j);if(U)g(`${d.name} \u4E0A\u4F20\u6210\u529F`);else throw s$1(`${d.name} \u4E0A\u4F20\u5931\u8D25 errorinfo -> ${JSON.stringify(L)}`),console.log("\u{1F3F7}\uFE0F index.ts ~ error => ",L),new Error("\u4E0A\u4F20\u5931\u8D25");const{data:{data:J,isSuccess:V}}=await this.uploadRequest.axiosInstance.post("https://mgrapi.fhd001.com/mgr/rdc/staticResource/staticResourcePublish.do",{staticResourceDirectoryId:d.id,version:d.newPublishVersion,description:d.uploadDesc,ossFilePath:L});if(!V)throw s$1(`${d.name} \u53D1\u5E03\u5931\u8D25 errorinfo -> ${JSON.stringify(J)}`),new Error("\u53D1\u5E03\u5931\u8D25");g(`${d.name} \u53D1\u5E03\u6210\u529F`)}),s(this,"uploadEntry",async()=>{await this.initUploadInfoList();const d=A[this.currentPlatfrom],B=this.uploadInfoList.filter(y=>d.includes(y.id));await Promise.all(B.map(y=>this.publicZip(y)))}),s(this,"initToken",async d=>{if(d){const{data:{isSuccess:y}}=await this.uploadRequest.axiosInstance.get("https://mgrapi.fhd001.com/mgr/rdc/staticResource/getUserStaticResourceDirectoryList.do",{params:{token:d}});if(y)return g("token \u6821\u9A8C\u901A\u8FC7"),this.uploadRequest.setToken(d),this.localUploadInfo.token=d,this.writeConfigFile(),d;s$1("token \u65E0\u6548\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165")}const{inputToken:B}=await o__default.prompt([{name:"inputToken",type:"text",message:"\u8BF7\u8F93\u5165\u706B\u82B1\u6D3Etoken",required:!0}]);return this.initToken(B)}),this.currentPlatfrom=F}writeConfigFile(){n$3.writeJson(this.configFilePath,this.localUploadInfo)}async wxMain(F){this.localUploadInfo.wxFileRoot=await getFileRoot(this.currentPlatfrom,F),this.publishFileRoot=r__default.join(this.localUploadInfo.wxFileRoot,".."),await prepareDirFileZip(this.localUploadInfo.wxFileRoot,SaasZipName),await prepareAliZipFile(this.localUploadInfo.wxFileRoot);const d=getUploadInfoRoot(),B=n__default.readJsonSync(d);await this.initToken(B.token),await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async aliMain(F){this.localUploadInfo.aliFileRoot=await getFileRoot(this.currentPlatfrom,F),this.publishFileRoot=r__default.join(this.localUploadInfo.aliFileRoot,".."),await prepareAliZipFile(this.localUploadInfo.aliFileRoot);const d=getUploadInfoRoot(),B=n__default.readJsonSync(d);await this.initToken(B.token),await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async staticMain(F){this.localUploadInfo.staticFileRoot=await getFileRoot(this.currentPlatfrom,F),this.publishFileRoot=r__default.join(this.localUploadInfo.aliFileRoot,".."),await prepareDirFileZip(this.localUploadInfo.staticFileRoot,StaticZipName);const d=getUploadInfoRoot(),B=n__default.readJsonSync(d);await this.initToken(B.token);const y=w.find(k=>k.id===36);if(!y)throw new Error("\u672A\u627E\u5230\u9759\u6001\u8D44\u6E90\u9879\u76EE");const{desc:v}=await o__default.prompt([{name:"desc",type:"text",message:"\u8BF7\u8F93\u5165\u4E0A\u4F20\u63CF\u8FF0\u4FE1\u606F",required:!0,initial:y.uploadDesc}]);y.uploadDesc=v,await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async plOperatorMain(F){this.localUploadInfo.ploperatorFileRoot=await getFileRoot(this.currentPlatfrom,F);const d=n$3.readdirSync(r__default.resolve(this.localUploadInfo.ploperatorFileRoot));if(!d.length)return s$1(`${this.localUploadInfo.ploperatorFileRoot} \u76EE\u5F55\u4E0B\u6CA1\u6709\u6587\u4EF6`);this.publishFileRoot=r__default.resolve(this.localUploadInfo.ploperatorFileRoot);const B=getUploadInfoRoot(),y=n__default.readJsonSync(B);await this.initToken(y.token);const v=w.find(j=>j.id===52);if(!v)throw new Error("\u672A\u627E\u5230\u9759\u6001\u8D44\u6E90\u9879\u76EE");const{fileName:k,desc:x}=await o__default.prompt([{name:"fileName",type:"select",message:"\u8BF7\u9009\u62E9\u4E0A\u4F20\u7684\u538B\u7F29\u5305",required:!0,choices:d},{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"}]);v.uploadDesc=x,v.uploadZipFileName=k,await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}async saasMerchantMain(F){this.localUploadInfo.saasMerchantFileRoot=await getFileRoot(this.currentPlatfrom,F);const d=n$3.readdirSync(r__default.resolve(this.localUploadInfo.saasMerchantFileRoot));if(!d.length)return s$1(`${this.localUploadInfo.saasMerchantFileRoot} \u76EE\u5F55\u4E0B\u6CA1\u6709\u6587\u4EF6`);this.publishFileRoot=r__default.resolve(this.localUploadInfo.saasMerchantFileRoot);const B=getUploadInfoRoot(),y=n__default.readJsonSync(B);await this.initToken(y.token);const v=w.find(j=>j.id===41);if(!v)throw new Error("\u672A\u627E\u5230\u9759\u6001\u8D44\u6E90\u9879\u76EE");const{fileName:k,desc:x}=await o__default.prompt([{name:"fileName",type:"select",message:"\u8BF7\u9009\u62E9\u4E0A\u4F20\u7684\u538B\u7F29\u5305",required:!0,choices:d},{name:"desc",type:"text",message:"\u8BF7\u8F93\u5165\u53D1\u5E03\u63CF\u8FF0\u4FE1\u606F",required:!0,initial:"\u53D1\u5E03SaaS\u5546\u6237\u540E\u53F0"}]);v.uploadDesc=x,v.uploadZipFileName=k,await this.uploadEntry(),r$1("\u4E0A\u4F20\u5B8C\u6210\u4E86!")}}async function T(){const u=await loadCliOptions(),F=f__default$2("ppg");F.version(version).help();const d={"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(u.gitCommitTypes,u.gitCommitScopes)}catch{exitWithError()}}},"git-version [actionType]":{desc:"\u7248\u672C\u5206\u652F\u64CD\u4F5C",alias:"gv",action:async B=>{try{await getVersion(B)}catch(y){backToOriginalBranch(),n$2(JSON.stringify(y)),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(B,y)=>{await PingPort(y.more,B)}},"delete-tag [tagName]":{desc:"\u5220\u9664\u8FDC\u7A0Btag",alias:"dt",action:async B=>{await deleteTag(B)}},"public-verify-vx [fileRoot]":{desc:"\u5C06\u6821\u9A8C\u6587\u4EF6\u53D1\u5E03\u5230\u8FDC\u7A0B-\u5FAE\u4FE1",alias:"pvv",action:async B=>{await new M(EPlatForm.WEChAT).wxMain(B)}},"public-verify-ali [fileRoot]":{desc:"\u5C06\u6821\u9A8C\u6587\u4EF6\u53D1\u5E03\u5230\u8FDC\u7A0B-\u652F\u4ED8\u5B9D/\u6296\u97F3",alias:"pva",action:async B=>{await new M(EPlatForm.ALIPAY).aliMain(B)}},"public-static [fileRoot]":{desc:"\u5C06\u5BC4\u9012\u9759\u6001\u8D44\u6E90\u53D1\u5E03\u5230\u8FDC\u7A0B",alias:"ps",action:async B=>{await new M(EPlatForm.STATIC).staticMain(B)}},"public-ploperator [fileRoot]":{desc:"\u90E8\u7F72\u7EFC\u5408\u8FD0\u8425\u7CFB\u7EDF",alias:"ppl",action:async B=>{await new M(EPlatForm.PL_OPERATOR).plOperatorMain(B)}},"public-merchant [fileRoot]":{desc:"\u90E8\u7F72SaaS\u5546\u6237\u540E\u53F0",alias:"ppm",action:async B=>{await new M(EPlatForm.SAAS_MERCHANT).saasMerchantMain(B)}},open:{desc:"\u5728\u6D4F\u89C8\u5668\u6253\u5F00\u5F53\u524D\u4ED3\u5E93",alias:"o",action:async()=>{await openStore()}},release:{desc:"\u53D1\u5E03\uFF1A\u66F4\u65B0\u7248\u672C\u53F7\u3001\u751F\u6210changelog\u3001\u63D0\u4EA4\u4EE3\u7801",alias:"r",action:async()=>{await release()}}};for await(const[B,{options:y,desc:v,action:k,alias:x=B.replace(/\s.+/gi,"")}]of Object.entries(d)){const j=F.command(B,v).action(k).alias(x);y&&y.length&&y.forEach(L=>{j.option(...L)})}F.command("test","\u8FD9\u662F\u4E00\u4E2A\u63CF\u8FF0").alias("tt").option("-r, --recursive","Remove recursively",{default:!1}).action((B,y)=>{console.log(B,y)}),F.parse()}T();