#!/usr/bin/env node
/*!
  * @ldesign/cli v0.7.23
  * (c) 2023 ldesign
  * Released under the MIT License.
  */
import Z from"cac";var P=class{cli;constructor(e){this.cli=Z("ldesign").version(e,"latest").help(),this.cli.on("global-install",()=>{console.log("\u6B22\u8FCE\u5B89\u88C5\u4F7F\u7528LDesign\u811A\u624B\u67B6\u5DE5\u5177")})}registerCommand(e,t,i){return this.cli.command(e,t).action(i)}};import*as K from"dotenv";import*as D from"fs";import*as A from"path";import{dirname as ee}from"path";import{fileURLToPath as te}from"url";var u=class{config;__dirname;constructor(){let e=te(import.meta.url);this.__dirname=ee(e);let t=A.resolve(this.__dirname,"..",".env");this.config=K.parse(D.readFileSync(t))}getValue(e){return this.config[e]}setValue(e,t){this.config[e]=t,this.saveConfig()}updateValue(e,t){this.config.hasOwnProperty(e)&&(this.config[e]=t,this.saveConfig())}getAllValues(){return this.config}clearConfig(){this.config={},this.saveConfig()}saveConfig(){let e=A.resolve(".env"),t="";for(let i in this.config)t+=`${i}=${this.config[i]}
`;D.writeFileSync(e,t)}};import{exec as ie}from"child_process";var w=class{static async execute(e){return new Promise((t,i)=>{ie(e,(s,n,a)=>{s?(console.error(`Command '${e}' execution failed: ${s.message}`),t({stdout:n,stderr:a})):t({stdout:n,stderr:a})}).on("error",s=>{s.code==="ENOENT"?(console.error(`Command '${e}' not found.`),t({stdout:"",stderr:""})):i(s)})})}};import m from"fs-extra";import h from"path";var o=class{static async directoryExists(e){let t=h.resolve(process.cwd(),e);try{return(await m.stat(t)).isDirectory()}catch{return!1}}static async fileExists(e){let t=h.resolve(process.cwd(),e);try{return(await m.stat(t)).isFile()}catch{return!1}}static async readFileContents(e){let t=h.resolve(process.cwd(),e);try{return await m.readFile(t,"utf-8")}catch{throw new Error(`Unable to read file: ${t}`)}}static async deleteFile(e){let t=h.resolve(process.cwd(),e);if(await this.fileExists(t))try{await m.unlink(t)}catch{throw new Error(`Unable to delete file: ${t}`)}}static async deleteDirectory(e){let t=h.resolve(process.cwd(),e);if(await this.directoryExists(t))try{await m.remove(t)}catch{throw new Error(`Unable to delete directory: ${t}`)}}static async compareFiles(e,t){let i=h.resolve(process.cwd(),e),r=h.resolve(process.cwd(),t),s=await this.readFileContents(i),n=await this.readFileContents(r);return s===n}static async compareDirectories(e,t){let i=h.resolve(process.cwd(),e),r=h.resolve(process.cwd(),t),s=await m.readdir(i),n=await m.readdir(r);if(s.length!==n.length)return!1;for(let a of s){let c=h.join(i,a),p=h.join(r,a),f=await this.fileExists(c),z=await this.fileExists(p),W=await this.directoryExists(c),H=await this.directoryExists(p);if(f&&!z||W&&!H||f&&z&&!await this.compareFiles(c,p)||W&&H&&!await this.compareDirectories(c,p))return!1}return!0}static async createDirectory(e){let t=h.resolve(process.cwd(),e);try{await m.ensureDir(t)}catch{throw new Error(`Unable to create directory: ${t}`)}}static async createFileWithContent(e,t,i=!1){let r=h.resolve(process.cwd(),e);try{await m.ensureFile(r),await m.writeFile(r,t,"utf-8"),i&&m.chmodSync(r,"444")}catch{throw new Error(`Unable to create file: ${r}`)}}static async emptyDirectory(e){let t=h.resolve(process.cwd(),e);try{await m.emptyDir(t,{force:!0})}catch{throw new Error(`Unable to empty directory: ${t}`)}}static async copyDirectory(e,t,i){let r=h.resolve(e),s=h.resolve(process.cwd(),t);try{await m.ensureDir(s);let n=await m.readdir(r);for(let a of n){let c=h.join(r,a),p=h.join(s,a);if(i!=null&&i.filter&&!i.filter(c))continue;(await m.stat(c)).isDirectory()?await this.copyDirectory(c,p,i):await m.copyFile(c,p)}}catch{throw new Error(`Unable to copy directory: ${r}`)}}static async findFiles(e){let t=process.cwd(),i=[];async function r(s){let n=await m.readdir(s);for(let a of n){let c=h.join(s,a),p=await m.stat(c);p.isFile()&&a.endsWith(`.${e}`)?i.push(c):p.isDirectory()&&await r(c)}}return await r(t),i}};import F from"fs-extra";import O from"path";import k from"crypto";import{Buffer as J}from"buffer";var re="longrise-leap",se=16,x=class{algorithm;key;constructor(){this.algorithm="aes-256-cbc",this.key=k.createHash("sha256").update(re).digest()}encrypt(e){let t=k.randomBytes(se),i=k.createCipheriv(this.algorithm,this.key,t),r=new Uint8Array(i.update(e,"utf8")),s=new Uint8Array(i.final()),n=new Uint8Array(r.length+s.length);return n.set(r),n.set(s,r.length),`${J.from(n).toString("hex")}.${t.toString("hex")}`}decrypt(e){let[t,i]=e.split("."),r=new Uint8Array(J.from(i,"hex")),s=k.createDecipheriv(this.algorithm,this.key,r),n=new Uint8Array(J.from(t,"hex")),a=new Uint8Array(s.update(n)),c=new Uint8Array(s.final()),p=new Uint8Array(a.length+c.length);return p.set(a),p.set(c,a.length),new TextDecoder().decode(p)}};import ne from"boxen";import C from"chalk";var g=class{filePath;secret;constructor(e="license"){this.filePath=e,this.secret=new x}async generateLicenseFile(e){let t=O.resolve(process.cwd(),this.filePath),i=this.secret.encrypt(JSON.stringify(e));await F.writeFile(t,i,"utf-8")}async readLicenseFile(){let e=O.resolve(process.cwd(),this.filePath),t=await F.readFile(e,"utf-8"),i=this.secret.decrypt(t);return JSON.parse(i)}async modifyLicenseFile(e){let t=O.resolve(process.cwd(),this.filePath),i=await F.readFile(t,"utf-8"),r=this.secret.decrypt(i),s=JSON.parse(r)||{};s=e(s);let n=this.secret.encrypt(JSON.stringify(s));await F.writeFile(t,n,"utf-8")}async addDependency(e,t,i="dependencies"){await this.modifyLicenseFile(r=>(r[i]=r[i]||{},r[i][e]=t,r))}async removeDependency(e,t="dependencies"){await this.modifyLicenseFile(i=>(i[t]&&i[t][e]&&delete i[t][e],i))}async updateDependencyVersion(e,t,i="dependencies"){await this.modifyLicenseFile(r=>(r[i]=r[i]||{},r[i][e]=t,r))}async printDependencies(){let e=await this.readLicenseFile();console.log(ne(`\u9879\u76EE\u540D\u79F0\uFF1A${C.green(e.name)}
\u7248\u672C\uFF1A${C.green(e.version)}

${C.bold.green("\u751F\u4EA7\u4F9D\u8D56")}\uFF1A
${this.resolveDependencies(e.dependencies)}
${C.bold.yellow("\u5F00\u53D1\u4F9D\u8D56")}\uFF1A
${this.resolveDependencies(e.devDependencies)}`,{title:"\u9879\u76EE\u4FE1\u606F",padding:1,margin:{top:1,bottom:1},borderStyle:"round",borderColor:"cyan",width:70}))}resolveDependencies(e){let t="";return Object.keys(e).forEach(i=>{t+=`${i}: ${e[i]}
`}),t}};import{promisify as ae}from"util";import{exec as ce}from"child_process";import le from"axios";import oe from"ora";var d=class{spinner;constructor(e){this.spinner=oe(e)}start(e){e&&(this.spinner.text=e),this.spinner.start()}succeed(e){this.spinner.succeed(e)}fail(e){this.spinner.fail(e)}text(e){this.spinner.text=e}warn(e){this.spinner.warn(e)}info(e){this.spinner.info(e)}};import pe from"npm-cli-login";var E=ae(ce),y=class{source;spinner;constructor(e){this.source=e,this.spinner=new d}async isSourceLoggedIn(){try{let{stdout:e}=await E(`npm whoami --registry=${this.source}`);return e.trim()!=="npm ERR! code ENEEDAUTH"}catch{return!1}}async logoutFromSource(){try{return await E(`npm logout --registry=${this.source}`),!0}catch{return!1}}async loginByApi(e,t){try{this.spinner.start(`\u5F00\u59CB\u767B\u5F55npm,${this.source}`);let i=await le.post(`${this.source}-/verdaccio/sec/login`,{username:e,password:t},{headers:{"Content-Type":"application/json"}});this.spinner.text("\u8BA4\u8BC1\u6210\u529F\uFF01");let r=this.source.replace("http:","");return await w.execute(`npm config set ${r}:_authToken=${i.data.token}`),this.spinner.succeed("\u767B\u5F55\u6210\u529F"),!0}catch{return!1}}async loginByToken(e,t){try{await pe(e,t,"979741120@qq.com",this.source),console.log("\u6210\u529F")}catch(i){console.log(i)}}async getLoggedInUsername(){try{let{stdout:e}=await E("npm whoami");return e.trim()}catch{return null}}static async getLoggedInSources(){var e;try{let{stdout:t}=await E('npm config ls -l | grep "^@.*:registry="');return((e=t.match(/@.*:registry=/g))==null?void 0:e.map(r=>r.replace(/[@:registry=]/g,"")))||[]}catch{return[]}}};var S=class{licence;spinner;npm;env;constructor(){this.licence=new g("./license"),this.spinner=new d,this.env=new u,this.npm=new y(this.env.getValue("NPM_HOST")||"")}async add(e,t,i){let r=i.D?"devDependencies":"dependencies";await this.licence.addDependency(e,`^${t}`,r)}async remove(e,t){let i=t.D?"devDependencies":"dependencies",[r]=e.split("@");await this.licence.removeDependency(r,i)}async install(){await this.hasLogined()||console.log("\u5C1A\u672A\u767B\u5F55");let t=await this.licence.readLicenseFile(),i=JSON.stringify(t,null,2);await o.createFileWithContent("package.json",i,!0),this.spinner.start("\u5F00\u59CB\u5B89\u88C5\u4F9D\u8D56"),await w.execute("pnpm i"),this.spinner.succeed("\u5B89\u88C5\u6210\u529F"),await o.deleteFile("package.json")}async hasLogined(){return await this.npm.isSourceLoggedIn()}async all(){let e=await this.licence.readLicenseFile();console.log(e)}extractPackageInfo(e){let t=/^([^@]+)@(.+)$/,i=e.match(t);if(i&&i.length===3){let r=i[1],s=i[2];return{packageName:r,version:s}}return{}}};var V=[{title:"vue3\u684C\u9762\u7AEF\u6A21\u677F",git:743,dir:"desktop-next"},{title:"\u6587\u6863\u7CFB\u7EDF",git:858,dir:"doc"}];import{Gitlab as M}from"@gitbeaker/rest";import{exec as B}from"child_process";import he from"simple-git";var v=class{git;constructor(e,t){this.git=he(e,t)}async clone(e,t){try{return await this.git.clone(e,t,["--depth","1"]),!0}catch(i){return console.error("\u514B\u9686\u5931\u8D25\uFF1A",i),!1}}async checkout(e){try{return await this.git.checkout(e),!0}catch(t){return console.error("\u5207\u6362\u5931\u8D25\uFF1A",t),!1}}async pull(){try{return await this.git.pull(),!0}catch(e){return console.error("\u62C9\u53D6\u5931\u8D25\uFF1A",e),!1}}async add(e){try{return await this.git.add(e),!0}catch(t){return console.error("\u6DFB\u52A0\u5931\u8D25\uFF1A",t),!1}}async commit(e){try{return await this.git.commit(e),!0}catch(t){return console.error("\u63D0\u4EA4\u5931\u8D25\uFF1A",t),!1}}async push(){try{return await this.git.push(["--set-upstream","origin","master"]),!0}catch(e){return console.error("\u63A8\u9001\u5931\u8D25\uFF1A",e),!1}}async isGitLabLoggedIn(){try{return!!(await this.git.raw(["config","--get","gitlab.user"])).trim()}catch(e){return console.error("\u68C0\u67E5GitLab\u767B\u5F55\u72B6\u6001\u65F6\u51FA\u9519\uFF1A",e),!1}}async loginToGitLab(e,t){try{return await this.git.raw(["config","--global","gitlab.user",e]),await this.git.raw(["config","--global","gitlab.password",t]),!0}catch(i){return console.error("GitLab\u767B\u5F55\u5931\u8D25\uFF1A",i),!1}}async logoutFromGitLab(){try{return await this.git.raw(["config","--global","--unset","gitlab.user"]),await this.git.raw(["config","--global","--unset","gitlab.password"]),!0}catch(e){return console.error("GitLab\u6CE8\u9500\u5931\u8D25\uFF1A",e),!1}}async deleteRemoteRepository(e){try{return e?await this.git.raw(["remote","rm","origin"]):await this.git.removeRemote("origin"),!0}catch(t){return console.error("\u5220\u9664\u8FDC\u7A0B\u4ED3\u5E93\u5931\u8D25\uFF1A",t),!1}}async createRemoteRepository(e){try{return await this.git.raw(["remote","add","origin",e]),!0}catch(t){return console.error("\u521B\u5EFA\u8FDC\u7A0B\u4ED3\u5E93\u5931\u8D25\uFF1A",t),!1}}async fetch(){try{return await this.git.fetch(),!0}catch(e){return console.error("\u83B7\u53D6\u4EE3\u7801\u5931\u8D25\uFF1A",e),!1}}async deleteLocalRepository(e){try{return await this.git.raw(["rm","-rf",".git"]),!0}catch(t){if(console.error("\u5220\u9664\u672C\u5730\u4ED3\u5E93\u5931\u8D25\uFF1A",t),!e)return!1;try{return await this.git.raw(["rm","-r","-f",".git"]),!0}catch(i){return console.error("\u5F3A\u5236\u5220\u9664\u672C\u5730\u4ED3\u5E93\u5931\u8D25\uFF1A",i),!1}}}async initLocalRepository(){try{return await this.git.init(),!0}catch(e){return console.error("\u521D\u59CB\u5316\u672C\u5730\u4ED3\u5E93\u5931\u8D25\uFF1A",e),!1}}async deleteAllCommits(){try{return await this.git.raw(["checkout","--orphan","temp_branch"]),await this.git.raw(["add","-A"]),await this.git.raw(["commit","-am","Delete all commits"]),await this.git.raw(["branch","-D","main"]),await this.git.raw(["branch","-m","main"]),await this.git.raw(["push","-f","origin","main"]),!0}catch(e){return console.error("\u5220\u9664\u63D0\u4EA4\u8BB0\u5F55\u5931\u8D25\uFF1A",e),!1}}};var U=class{constructor(e,t){this.token=e;this.baseUrl=t;this.gitlab=new M({token:this.token,host:this.baseUrl}),this.git=new v,this.spinner=new d}gitlab;git;spinner;async createRepository(e,t,i){try{this.spinner.start("\u5F00\u59CB\u68C0\u67E5\u662F\u5426\u53EF\u7528"),await this.isRepositoryExist(e)&&(this.spinner.warn("\u5DF2\u5B58\u5728\u540C\u540D\u4ED3\u5E93\uFF0C\u8BF7\u66F4\u6362\u540D\u79F0\uFF01"),process.exit()),this.spinner.text("\u5F00\u59CB\u521B\u5EFA\u8FDC\u7A0B\u4ED3\u5E93");let s=await this.gitlab.Projects.create({name:e,visibility:t,namespace_id:i});return this.spinner.succeed("\u4ED3\u5E93\u521B\u5EFA\u6210\u529F"),s}catch{throw new Error("Unable to create repository")}}async isRepositoryExist(e){return(await this.gitlab.Projects.search(e)).find(r=>r.name===e)}async getAllRepositories(){try{return await this.gitlab.Projects.all()}catch{throw new Error("Unable to get repositories")}}async getAllOrganizations(){try{return await this.gitlab.Groups.all()}catch{throw new Error("Unable to get organizations")}}async getOrganizationsWithCreatePermission(){try{return await this.gitlab.Groups.all({owned:!0})}catch{throw new Error("Unable to get organizations")}}async commit(e,t,i,r,s){try{await this.gitlab.RepositoryFiles.create(e,i,t,{commit_message:r,content:s}),console.log("File committed successfully")}catch{throw new Error("Unable to commit file")}}async pull(e,t,i){try{let r=await this.gitlab.RepositoryFiles.show(e,i,t);if(r)return r.content;throw new Error("Unable to pull file")}catch{throw new Error("Unable to pull file")}}async checkPermissions(){try{return!!await this.gitlab.Users.showCurrentUser()}catch(e){return console.error("Error checking user permissions:",e),!1}}login(e){this.gitlab=new M({token:e,host:this.baseUrl})}logout(){this.gitlab=new M({token:"",host:this.baseUrl})}async downloadRepositoryArchive(e,t){try{let i=await this.gitlab.Projects.show(e),{web_url:r}=i;await this.git.clone(r,t),await this.deleteRemoteGit(t)}catch{throw new Error("Unable to download repository")}}async deleteRemoteGit(e){await new Promise((t,i)=>{let r="origin",s={cwd:e};B(`git remote remove ${r}`,s,n=>{n?i(n):t(!0)})})}async addRemote(e,t,i,r){try{let s=await this.gitlab.Projects.show(e),{path_with_namespace:n}=s,a={cwd:r};this.spinner.start("\u5F00\u59CB\u5173\u8054\u8FDC\u7A0B\u4ED3\u5E93"),await new Promise((c,p)=>{B(`git remote add ${t} ${i}`,a,f=>{f?p(f):c(!0)})}),this.spinner.succeed("\u8FDC\u7A0B\u4ED3\u5E93\u5173\u8054\u6210\u529F")}catch{throw new Error("Unable to add remote repository")}}async checkoutDefaultBranch(e,t){try{let i=await this.gitlab.Projects.show(e),{path_with_namespace:r,default_branch:s}=i,n={cwd:t};await new Promise((a,c)=>{B(`git checkout ${s}`,n,p=>{p?c(p):a(!0)})}),console.log(`Checked out '${s}' branch in '${r}' successfully`)}catch{throw new Error("Unable to checkout default branch")}}async updateRemote(e,t,i){try{let r=await this.gitlab.Projects.show(e),{path_with_namespace:s}=r;await this.gitlab.Projects.edit(e,{[`${t}_url`]:i}),console.log(`Remote '${t}' in '${s}' updated successfully`)}catch{throw new Error("Unable to update remote repository")}}};import Q from"jsonfile";import{dirname as me,resolve as de}from"path";import{fileURLToPath as ge}from"url";var G=class{filePath;packageJson;__dirname;constructor(e){let t=ge(import.meta.url);this.__dirname=me(t),this.filePath=de(process.cwd(),"package.json"),this.packageJson=Q.readFileSync(e)}getAllData(){return this.packageJson}getDependencies(){return this.packageJson.dependencies||{}}getDevDependencies(){return this.packageJson.devDependencies||{}}getDependencyVersion(e,t=!1){return(t?this.getDevDependencies():this.getDependencies())[e]||null}hasDependency(e,t=!1){return(t?this.getDevDependencies():this.getDependencies()).hasOwnProperty(e)}updateDependencyVersion(e,t,i=!1){let r=i?this.getDevDependencies():this.getDependencies();r[e]=t,i?this.packageJson.devDependencies=r:this.packageJson.dependencies=r,this.saveChanges()}addDependency(e,t,i=!1){let r=i?this.getDevDependencies():this.getDependencies();r[e]=t,i?this.packageJson.devDependencies=r:this.packageJson.dependencies=r,this.saveChanges()}removeDependency(e,t=!1){let i=t?this.getDevDependencies():this.getDependencies();delete i[e],t?this.packageJson.devDependencies=i:this.packageJson.dependencies=i,this.saveChanges()}compareVersions(e,t){let i=e.split("."),r=t.split(".");for(let s=0;s<Math.max(i.length,r.length);s++){let n=parseInt(i[s]||"0",10),a=parseInt(r[s]||"0",10);if(n>a)return 1;if(n<a)return-1}return 0}getField(e){return this.packageJson[e]||null}setField(e,t){this.packageJson[e]=t,this.saveChanges()}removeField(e){delete this.packageJson[e],this.saveChanges()}saveChanges(){try{Q.writeFileSync(this.filePath,this.packageJson,{spaces:2})}catch(e){throw new Error(`Unable to save changes to package.json: ${e}`)}}};import ue from"inquirer";var L=class{constructor(){}async ask(e){return await ue.prompt(e)}async confirm(e,t=!0){let i={type:"confirm",name:"confirm",message:e,default:t};return(await this.ask(i)).confirm}async input(e,t=""){let i={type:"input",name:"input",message:e,default:t};return(await this.ask(i)).input}async list(e,t,i=0){let r={type:"list",name:"list",message:e,choices:t,default:i,loop:!1};return(await this.ask(r)).list}async checkbox(e,t){let i={type:"checkbox",name:"checkbox",message:e,choices:t,loop:!1};return(await this.ask(i)).checkbox}async password(e){let t={type:"password",name:"password",message:e};return(await this.ask(t)).password}async number(e,t=0){let i={type:"number",name:"number",message:e,default:t};return(await this.ask(i)).number}};import{resolve as we}from"path";import $ from"fs";import{promisify as T}from"util";import{transformSync as fe}from"esbuild";var At=T($.readdir),ye=T($.readFile),ve=T($.writeFile),be=T($.unlink),_=class l{filePath;constructor(e){this.filePath=we(process.cwd(),e)}static async convertToJavaScript(e){await new l(e).convertToJavaScript()}static async convertAllToJavaScript(){(await o.findFiles("ts")).forEach(async t=>{await l.convertToJavaScript(t)})}async convertToJavaScript(){let e=/\/\*\* Delete below \*\/([\s\S]*?)\/\*\* End \*\//,t=/(.*)(\r?\n\s*\/\*\* 正式环境使用下面的地址 \*\/)/g,i=await ye(this.filePath,"utf8");this.filePath.includes("vite.config")&&(i=i.replace(e,"").trim().replace(/^\s*$\n/gm,"")),this.filePath.includes("main")&&(i=i.replace(t,"").replace(/\/\/\W/g,""));let s=fe(i,{loader:"ts",target:"esnext"}).code||"",n=this.filePath.replace(/\.ts$/,".js");await ve(n,s),await be(this.filePath)}};import Pe from"boxen";import q from"chalk";import De,{dirname as ke,resolve as I}from"path";import{fileURLToPath as xe}from"url";var j=class{name;dir;isExist;env;gitlab;isPermission;prompt;spinner;openTs;openEslint;openGit;groups;currentGroup;reporitory;git;template;__dirname;pkg;licence;constructor(e=""){this.name=e||De.basename(process.cwd()),this.env=new u,this.prompt=new L,this.spinner=new d;let t=xe(import.meta.url);this.__dirname=ke(t),this.gitlab=new U(this.env.getValue("GITLAB_TOKEN"),this.env.getValue("GITLAB_HOST")),this.licence=new g("./license"),this.init(e)}async init(e){this.isExist=this.dir?await this.checkIsExist(e):!1,this.isPermission=await this.isGitlabPermission(),this.dir=await this.createDirectory(e),this.git=new v(this.dir),this.openTs=await this.askTypescript(),this.openEslint=await this.askEslint(),this.openGit=await this.askGit(),this.currentGroup=await this.askGitGroups(),this.reporitory=await this.createRemoteRepository(),this.template=await this.askTemplate(),await this.initTemplate(),this.pkg=new G("./package.json"),await this.deleteUselessFiles(),await this.resolveEslint(),await this.resolveTypescript(),await this.generateLicence(),await this.generateNpmRc(),this.openGit&&(await this.initGit(),await this.addLocalToRemote(),await this.firstPush()),this.writeNotice()}writeNotice(){var e;console.log(Pe(`\u3010${(e=this.template)==null?void 0:e.title}\u3011\u9879\u76EE\u521D\u59CB\u5316\u5B8C\u6210\uFF0C\u8BF7\u6309\u7167\u4E0B\u9762\u7684\u6B65\u9AA4\u5F00\u59CB\u5427\uFF01

1\u3001\u5B89\u88C5\u4F9D\u8D56\uFF1A${q.green("ldesign")} i

2\u3001\u542F\u52A8\u670D\u52A1\uFF1A${q.green("ldesign")} dev

3\u3001\u9879\u76EE\u6253\u5305\uFF1A${q.green("ldesign")} build`,{padding:1,title:"\u6B22\u8FCE\u4F7F\u7528LDesign\u811A\u624B\u67B6",titleAlignment:"left",borderColor:"#254ce4",borderStyle:"round",dimBorder:!0,margin:{top:1,bottom:1},width:80}))}async generateNpmRc(){await o.createFileWithContent(".npmrc",`@ldesign:registry=http://npm.longrise.cn:6286/
registry=https://registry.npm.taobao.org/`)}async firstPush(){this.spinner.start("\u5F00\u59CB\u7B2C\u4E00\u6B21\u540C\u6B65\uFF01"),await this.git.add("."),this.spinner.text("\u5F00\u59CBcommit"),await this.git.commit(`[init]: \u521D\u59CB\u5316\u9879\u76EE\uFF0C\u6765\u81EA\u6A21\u677F[${this.template.title}]`),this.spinner.text("\u5F00\u59CB\u63A8\u9001\u5230\u8FDC\u7A0B\u4ED3\u5E93"),await this.git.push(),this.spinner.succeed("\u5B8C\u6210\u7B2C\u4E00\u6B21\u540C\u6B65")}async generateLicence(){let e=this.pkg.getAllData(),{template:t,openTs:i,openEslint:r,openGit:s,currentGroup:n,reporitory:a}=this;e.config={template:t,openTs:i,openEslint:r,openGit:s,currentGroup:n,reporitory:(a==null?void 0:a.id)||null},await this.licence.generateLicenseFile(e),await o.deleteFile("package.json")}async deleteUselessFiles(){await o.deleteFile("vite.config.ts"),await o.deleteFile("README.md"),await this.pkg.removeField("scripts"),await this.pkg.removeField("private"),await this.pkg.setField("name",this.name)}async resolveEslint(){this.openEslint||(await this.pkg.removeDependency("eslint",!0),await this.pkg.removeDependency("@antfu/eslint-config",!0),await o.deleteFile(".eslintrc.cjs"))}async resolveTypescript(){if(!this.openTs){await this.pkg.removeDependency("@types/node",!0),await this.pkg.removeDependency("@vue/tsconfig",!0),await this.pkg.removeDependency("typescript",!0),await this.pkg.removeDependency("vue-tsc",!0),await o.deleteFile("env.d.ts"),await o.deleteFile("tsconfig.json"),await o.deleteFile("tsconfig.node.json"),await o.deleteFile("src/env.d.ts"),await o.deleteFile("shims.d.ts"),await _.convertAllToJavaScript();let e=await o.readFileContents("index.html");await o.createFileWithContent("index.html",e.replaceAll(".ts",".js"))}}async initGit(){this.openGit&&await this.git.initLocalRepository()}async initTemplate(){let e=I(this.__dirname,"..","templates",this.template.dir),t=I(this.dir);this.spinner.start(`\u5F00\u59CB\u521D\u59CB\u5316\uFF0C${this.template.title}`),await o.copyDirectory(e,t,{filter:i=>!i.includes(".git")}),this.spinner.succeed("\u521D\u59CB\u5316\u6210\u529F")}async addLocalToRemote(){let{id:e,http_url_to_repo:t}=this.reporitory;await this.gitlab.addRemote(e,"origin",t,this.dir)}async askGitGroups(){if(!this.openGit)return;this.groups=await this.getGitGroups();let e=await this.groups.map((i,r)=>`[${r+1}]${i.name}`),t=await this.prompt.list("\u9009\u62E9\u5206\u7EC4",["[0]\u6211\u7684\u4ED3\u5E93",...e]);return this.groups.find((i,r)=>`[${r+1}]${i.name}`===t)}async getGitGroups(){return this.gitlab.getOrganizationsWithCreatePermission()}async createRemoteRepository(){if(!this.openGit)return null;let e=this.currentGroup?this.currentGroup.id:"";return await this.gitlab.createRepository(this.name,"public",e)}async askGit(){return await this.prompt.confirm("\u662F\u5426\u521B\u5EFA\u8FDC\u7A0B\u4ED3\u5E93\uFF1F",!1)}async askEslint(){return await this.prompt.confirm("\u662F\u5426\u5F00\u542Feslint\uFF1F",!1)}async askTypescript(){return await this.prompt.confirm("\u662F\u5426\u542F\u52A8typescript\uFF1F",!1)}async askTemplate(){let e=V.map(i=>i.title)||[],t=await this.prompt.list("\u8BF7\u9009\u62E9",e,0);return V.find(i=>i.title===t)}async createDirectory(e){return this.spinner.start("\u6B63\u5728\u505A\u521D\u59CB\u5316\u51C6\u5907"),e?await o.directoryExists(e)?await o.emptyDirectory(e):await o.createDirectory(e):await o.emptyDirectory(e),this.spinner.succeed("\u521D\u59CB\u5316\u5B8C\u6210"),I(process.cwd(),e)}async checkIsExist(e){return await o.directoryExists(e)}async isGitlabPermission(){return await this.gitlab.checkPermissions()}};var R=class{env;npm;constructor(){this.env=new u,this.npm=new y(this.env.getValue("NPM_HOST")||"")}async logout(){await this.npm.logoutFromSource()}async login(){let e=this.env.getValue("NPM_USERNAME")||"",t=this.env.getValue("NPM_PASSWORD")||"";await this.npm.loginByApi(e,t)}};import{LDesignViteConfig as Fe}from"@ldesign/vite-config";import{createServer as Ce,build as Ee}from"vite";var b=class{constructor(e,t){this.type=e;this.mode=t;this.type=e,this.mode=t,this.spinner=new d,this.vite=new Fe(e,t),this.licence=new g("license"),this.config=this.vite.generate()}vite;server;config;spinner;licence;async dev(){this.server=await Ce(this.config),this.server.listen().then(e=>{var i;let{port:t}=(i=this.server.httpServer)==null?void 0:i.address();console.log(`\u6210\u529F\u542F\u52A8${t}\u7AEF\u53E3`)})}async build(){await this.buildDist(),await this.buildJava()}async buildDist(){var t,i;let e=(i=(t=this.config)==null?void 0:t.build)==null?void 0:i.outDir.split("/")[0];this.spinner.start("\u5F00\u59CB\u6253\u5305\u9759\u6001\u8D44\u6E90"),await o.deleteDirectory(`./${e}`),await Ee({...this.config,logLevel:"error"}),this.spinner.succeed("\u9759\u6001\u8D44\u6E90\u6253\u5305\u5B8C\u6210")}async buildJava(){var i,r;let t=`jar -cvf ./Leap.jar ./${(r=(i=this.config)==null?void 0:i.build)==null?void 0:r.outDir.split("/")[0]}`;this.spinner.start("\u5F00\u59CB\u6253\u5305jar"),await w.execute(t),this.spinner.succeed("jar\u6587\u4EF6\u6253\u5305\u5B8C\u6210")}};var N=class{cac;init;dependencies;npm;licence;_initcommand;_addcommand;_removecommand;_installcommand;_npmcommand;constructor(e){this.cac=new P(e),this.dependencies=new S,this.npm=new R,this.licence=new g,this.cac.cli.option("-v, --version","\u663E\u793A\u7248\u672C\u53F7"),this._initcommand=this.cac.registerCommand("init [dir]","\u521D\u59CB\u5316\u9879\u76EE",t=>{this.initCommand(t)}),this._addcommand=this.cac.registerCommand("add [dependencies] <version>","\u5B89\u88C5\u4F9D\u8D56",(t,i,r)=>{this.addDependencies(t,i,r)}),this._addcommand.option("-D, [dev]","\u6DFB\u52A0\u5230devDependencies"),this._removecommand=this.cac.registerCommand("remove [dependencies]","\u5220\u9664\u4F9D\u8D56",(t,i)=>{this.removeDependencies(t,i)}),this._removecommand.option("-D, [dev]","\u5220\u9664devDependencies"),this._installcommand=this.cac.registerCommand("install","\u5B89\u88C5\u4F9D\u8D56",()=>{this.installDependencies()}),this._installcommand.alias("i"),this.cac.registerCommand("logout","\u9000\u51FAnpm\u767B\u5F55",()=>{this.logoutNpm()}),this.cac.registerCommand("login","\u767B\u5F55NPM",()=>{this.loginNpm()}),this.cac.registerCommand("deps","\u67E5\u770B\u9879\u76EE\u4F9D\u8D56",async()=>{this.dependencies.all()}),this.cac.registerCommand("dev","\u542F\u52A8\u670D\u52A1",async()=>{let t=await this.licence.readLicenseFile(),i=t==null?void 0:t.config.template.dir;new b(i,"development").dev()}),this.cac.registerCommand("build","\u6253\u5305\u670D\u52A1",async()=>{let t=await this.licence.readLicenseFile(),i=t==null?void 0:t.config.template.dir;new b(i,"production").build()}),this.cac.registerCommand("deps","\u67E5\u770B\u9879\u76EE\u4F9D\u8D56\u9879",async()=>{this.licence.printDependencies()}),this.cac.cli.parse()}initCommand(e){this.init=new j(e)}addDependencies(e,t,i){this.dependencies.add(e,t,i)}removeDependencies(e,t){this.dependencies.remove(e,t)}installDependencies(){this.dependencies.install()}logoutNpm(){this.npm.logout()}loginNpm(){this.npm.login()}};var X="0.7.23";var ki=new N(X);
