aklry-cli
Version:
aklry-cli 脚手架
2 lines (1 loc) • 8.2 kB
JavaScript
;var e=require("./vendor-CYtbyVsW.js");require("node:tty");var o=require("node:path"),r=require("node:fs"),n=require("node:child_process");function t(e,o,r,n){return new(r||(r=Promise))(function(t,i){function s(e){try{l(n.next(e))}catch(e){i(e)}}function c(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r(function(e){e(o)})).then(s,c)}l((n=n.apply(e,o||[])).next())})}require("node:events"),require("node:process"),require("node:string_decoder"),require("node:readline"),require("node:async_hooks"),require("node:stream"),require("node:os"),require("node:constants"),require("node:assert"),require("node:buffer"),require("node:crypto"),require("node:net"),require("node:tls"),require("node:dns"),require("node:util"),require("node:http"),require("node:https"),require("node:zlib"),require("node:url"),require("node:fs/promises"),"function"==typeof SuppressedError&&SuppressedError;const i=new class{info(o){console.log(e.logSymbols.info,o)}success(o){console.log(e.logSymbols.success,o)}error(o){console.log(e.logSymbols.error,o)}warning(o){console.log(e.logSymbols.warning,o)}};e.figlet.parseFont("Standard",e.standard);const s=e.createLogger({spinner:{interval:80,frames:["-","-","-","-"].map(o=>e.chalk.green(o))}}),c={baseDir:process.cwd(),binary:"git",maxConcurrentProcesses:6},l=(o,r,n)=>t(void 0,void 0,void 0,function*(){const t=e.esm_default(c);try{yield s(t.clone(o,r,n),"正在下载模板",{estimate:5e4}),console.log(),i.success(e.chalk.blueBright("==================================")),i.success(e.chalk.blueBright("=== 欢迎使用 yuan-cli 脚手架 ===")),i.info(e.chalk.blueBright(`=== cd ${r} ===`)),i.info(e.chalk.blueBright("=== pnpm install ===")),i.info(e.chalk.blueBright("=== pnpm run dev ===")),i.success(e.chalk.blueBright("==================================")),e.figlet.text("aklry-cli",{font:"Standard"},(o,r)=>{o?console.log(o):console.log(e.chalk.green(r))})}catch(e){i.error(e)}}),a=(e,o,r={})=>{const t=process.platform;return new Promise((i,s)=>{const c=n.spawn(e,o,Object.assign({shell:"win32"===t,stdio:"inherit"},r));c.on("close",e=>{0===e?i(!0):s(new Error(`Command failed with exit code ${e}`))}),c.on("error",e=>{s(e)})})};var d,u=(d=new class{constructor(){this.ssh=new e.NodeSSH}connect(o,r,n,t){return new Promise((s,c)=>{this.ssh.connect({host:o,username:r,password:n,port:t}).then(()=>{i.success(e.chalk.green("连接成功")),s(void 0)}).catch(o=>{i.error(e.chalk.red(`连接失败:${o}`)),c(o)})})}disconnect(){return t(this,void 0,void 0,function*(){this.ssh.dispose()})}runCommander(e,o){return new Promise(r=>{this.ssh.execCommand(e,{cwd:o}).then(e=>{r(e)})})}compressFile(o,n){return new Promise(t=>{const s=r.createWriteStream(n),c=e.archiver("zip",{zlib:{level:9}});c.pipe(s),c.directory(o,"dist"),c.finalize(),c.on("close",()=>{i.success(e.chalk.green(`压缩文件成功:${(c.pointer()/1024/1024).toFixed(2)}MB`)),t(void 0)})})}uploadFile(o,r){return new Promise(n=>{this.ssh.putFile(o,r).then(()=>{i.success(e.chalk.green("上传文件成功")),n(void 0)}).catch(o=>{i.error(e.chalk.red(`上传文件失败:${o}`))})})}},new Proxy(d,{get(e,o){const r=e[o];return"function"==typeof r?r.bind(d):r}})),p="0.4.1",m=p;const h=new Map([["Vue3 + Vite + TypeScript + Element Plus-template-01",{name:"Vue3 + Vite + TypeScript + Element Plus",downloadUrl:"https://github.com/aklry/admin-pro.git",description:"Vue3 + Vite + TypeScript企业级中后台模板",branch:"master"}],["Vue3 + Vite + TypeScript + Element Plus-template-02",{name:"Vue3 + Vite + TypeScript + Element Plus",downloadUrl:"https://gitee.com/liu-ruiyuan/cms.git",description:"Vue3 + Vite + TypeScript企业级中后台模板",branch:"master"}],["Vue3 + Vite + TypeScript + Vant-H5_template",{name:"Vue3 + Vite + TypeScript + Vant",downloadUrl:"https://gitee.com/liu-ruiyuan/ry-seek-friend_fronted.git",description:"Vue3 + Vite + TypeScript H5模板",branch:"template"}],["Vue3 + Vite + TypeScript + uview-plus_template",{name:"Vue3 + Vite + TypeScript + uview-plus",downloadUrl:"https://github.com/aklry/uni-template.git",description:"uniapp 移动端模板",branch:"master"}]]),g=o=>t(void 0,void 0,void 0,function*(){const{data:r}=yield(o=>t(void 0,void 0,void 0,function*(){const r=`https://registry.npmjs.org/${o}`;let n={};try{n=yield e.axios.get(r)}catch(e){i.error(e)}return n}))(o);return r["dist-tags"].latest}),y=r=>t(void 0,void 0,void 0,function*(){const n=Array.from(h).map(e=>{const[o,r]=e;return{name:o,value:o,description:r.description}});r||(r=yield e.input({message:"请输入项目名称"}));const s=o.resolve(process.cwd(),r);if(e.fs.existsSync(s)){const o=yield(o=>t(void 0,void 0,void 0,function*(){return yield e.select({message:`当前目录已存在${o},是否覆盖?`,choices:[{name:"覆盖",value:!0},{name:"取消",value:!1}]})}))(r);if(!o)return;yield e.fs.remove(s)}yield((o,r)=>t(void 0,void 0,void 0,function*(){const n=yield g(o),t=e.lodashExports.gt(n,r);return t&&(i.warning(`当前版本${e.chalk.blueBright(r)},最新版本${e.chalk.greenBright(n)},请及时更新`),i.info(`更新命令:${e.chalk.greenBright(`npm install -g ${o}@latest`)} 或者${e.chalk.greenBright("yuan update")}`)),t}))("aklry-cli",p);const c=yield e.select({message:"请选择模板",choices:n}),a=h.get(c);a&&l(a.downloadUrl,r,["-b",a.branch])}),v=e.ora({text:"Updating...",spinner:{interval:80,frames:["-","-","-","-"].map(o=>e.chalk.blue(o))},color:"yellow"}),f=(n,i)=>t(void 0,void 0,void 0,function*(){const t=o.resolve(__dirname,"./templates/component.ejs"),s=yield(c=t,l={cpnName:n,lowerCaseCpnName:n.toLowerCase()},new Promise((o,r)=>{e.ejs.renderFile(c,l,(e,n)=>{if(e)return console.error("模板编译失败"),void r(e);o(n)})}));var c,l;const a=i.opts().dest||"src/components",d=o.resolve(process.cwd(),a),u=o.resolve(d,`./${n}.vue`);var p,m;yield(p=u,m=s,r.promises.writeFile(p,m))}),w=new e.Command("yuan");(e=>{e.version(m,"-v, --version","output the current version"),e.option("-d, --dest <dest>","a destination folder, for example: -d src/components"),e.on("--help",()=>{console.log(""),console.log("Examples:"),console.log(" $ yuan add-cpn my-component -d src/components"),console.log(" $ yuan create my-project"),console.log(" $ yuan update")})})(w),w.command("update").description("更新脚手架 aklry-cli").action(()=>t(void 0,void 0,void 0,function*(){yield t(void 0,void 0,void 0,function*(){v.start(),n.exec("npm install aklry-cli@latest -g",o=>{v.stop(),o?console.error(e.chalk.redBright(o)):console.log(e.chalk.greenBright("更新成功"))})})})),w.command("create").description("创建一个项目").argument("name","项目名称").action(e=>t(void 0,void 0,void 0,function*(){e?y(e):console.log(e)})),w.command("add-cpn <cpnname> [...others]").description("add a new vue component to the project, for example: yuan add-cpn my-component -d src/components").action(e=>f(e,w)),w.command("run").description("ci/cd is executing").action(()=>t(void 0,void 0,void 0,function*(){try{yield a("npm",["run","lint"]),yield a("npm",["run","build"]),i.info(e.chalk.blue("Running continuous integration checks and deployment..."));const{host:r,username:n,password:s,port:c,remotePath:l,releasePath:d}=yield t(void 0,void 0,void 0,function*(){const o=yield e.input({message:"请输入服务器地址",default:"127.0.0.1"}),r=yield e.input({message:"请输入用户名",default:"root"}),n=yield e.password({message:"请输入密码",mask:"*"}),t=yield e.input({message:"请输入端口",default:"22"}),i=yield e.input({message:"请输入远程部署目录",default:"/www/wwwroot/"}),s=yield e.input({message:"请输入发布目录",default:"release"});return{host:o,username:r,password:n,port:Number(t),remotePath:i,releasePath:s}}),{compressFile:p,connect:m,runCommander:h,uploadFile:g,disconnect:y}=u,v=o.resolve(process.cwd(),"dist"),f=o.resolve(process.cwd(),"dist.zip");yield p(v,f),yield m(r,n,s,c),yield h(`rm -rf ${d}`,l),yield g(f,`${l}${d}`),yield h(`unzip -o ${d} -d ${l}`,l),yield h(`rm -rf ${d}`,l),yield h(`mv dist ${d}`,l),yield y(),i.success(e.chalk.green("部署成功"))}catch(o){i.error(e.chalk.red(`Error occurred during CI:${o}`))}})),w.parse(process.argv);