@eternalheart/x-cli
Advanced tools
Comparing version 1.0.1 to 1.0.2
90
bin/x.js
#!/usr/bin/env node | ||
import{program as b}from"commander";var v=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as It,spawn as Tt}from"child_process";import $e from"chalk";var q=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var V=(...e)=>{let t=0;return e.reduce((o,[r,n])=>{let i=typeof n=="number"?t=n&&t++:n??t++;return o[r]=i,o[i]=r,o},{})};var re=class{_TypeBg=V(["info","bgBlueBright"],["warn","bgYellow"],["error","bgRedBright"]);_logo=t=>$e.bgBlueBright($e[this._TypeBg[t]](` x-cli => ${t} `));isOn=!0;constructor(t){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...t){this.forbidden||console.log(this._logo("info"),...t)}warn(...t){this.forbidden||console.log(this._logo("warn"),...t)}error(...t){this.forbidden||console.log(this._logo("error"),...t)}},a=new re(q());import Mt from"ora";var Ce=e=>{let t=Mt(e),o=setTimeout(()=>{t.start()},1500);return{stop:()=>{clearTimeout(o),t.stop()},text:r=>{t.text=r},succeed:r=>{clearTimeout(o),t.succeed(` ${r}`)},fail:r=>{clearTimeout(o),t.fail(` ${r}`)},warn:r=>{clearTimeout(o),t.warn(` ${r}`)},info:r=>{clearTimeout(o),t.info(` ${r}`)}}};var d=e=>{if(!e)return Promise.reject("Not a standard command.");a.info(e);let t=Ce(e);return new Promise(o=>{It(e,(r,n,i)=>{r&&o(!1),o(n)})}).finally(()=>t.stop())},y=e=>e?(a.info(e),new Promise((t,o)=>{let[r,...n]=e.split(/\s+/).filter(s=>s);Tt(r,n,{stdio:"inherit",shell:!0}).on("close",s=>{s===0?t(!0):o(s)})})):Promise.reject("Not a standard command."),x=(...e)=>Promise.allSettled(e);var Pe=()=>d("curl -fsSL https://get.pnpm.io/install.sh | sh -"),Ae=(e,t=!1,o=!1,r={})=>{let n="pnpm",i="add";t?i="add --save-dev":o&&(i="add --global"),e||(i="install");let s=`${n} ${i} ${v(e)} ${Object.entries(r).map(([g,R])=>`--${g}=${R}`).join(" ")}`;return d(s)},be=(e,t=!1,o={})=>{if(!e)return Promise.reject("packageName is required");let n=`${t?"pnpm remove -g":"pnpm remove"} ${v(e)} ${Object.keys(o).map(i=>`--${i}=${o[i]}`).join(" ")}`;return d(n)},ke=(e,t={})=>{let o=`pnpm ${e} ${Object.keys(t).map(r=>`--${r}=${t[r]}`).join(" ")}`;return y(o)},De=e=>y(`pnpx -y ${e}`);import{exec as Ie}from"child_process";var D=(e,t=!1,o=!1,r={})=>{let n="npm",i="install";t?i="install --save-dev":o?(n="npm",i="install -g"):n="npm";let s=`${n} ${i} ${v(e)} ${Object.keys(r).map(g=>`--${g}=${r[g]}`).join(" ")}`;return d(s)},Ee=(e,t=!1,o={})=>{if(!e)return Promise.reject("packageName is required");let n=`${t?"npm uninstall -g":"npm uninstall"} ${v(e)} ${Object.keys(o).map(i=>`--${i}=${o[i]}`).join(" ")}`;return d(n)},Me=(e,t={})=>{let o=`npm run ${e} ${Object.keys(t).map(r=>`--${r}=${t[r]}`).join(" ")}`;return y(o)},W=async(e,t=!1)=>{let o=`npm list ${v(e)} ${t?"-g":""} --depth=0`;a.off();let r=await d(`${o} | grep ${e}`);return a.on(),typeof r=="boolean"?r:r.toString()?.trim()?.includes(e)},Y=e=>y(`npx -y ${e} `);var Te=[{name:"pnpm",check:()=>new Promise((e,t)=>{Ie("pnpm -v",(o,r,n)=>{o&&e(!1),e(!!r.includes("."))})}),install:Pe},{name:"nx",check:()=>new Promise(e=>{Ie("nx --version",(t,o,r)=>{t&&e(!1),e(!!o.includes("."))})}),install:async()=>{await D("nx",!1,!0)}}];var je=` | ||
import{program as k}from"commander";var w=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as _t,spawn as St}from"child_process";import ne from"chalk";var W=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var Y=(...e)=>{let t=0;return e.reduce((o,[r,i])=>{let n=typeof i=="number"?t=i&&t++:i??t++;return o[r]=n,o[n]=r,o},{})};var ie=class{_TypeBg=Y(["info","bgBlue"],["warn","bgYellow"],["error","bgRedBright"]);_logo=t=>ne.bgBlueBright(ne.whiteBright(" X-CLI "))+ne[this._TypeBg[t]](` ${t.toUpperCase()} `);isOn=!0;constructor(t){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...t){this.forbidden||console.log(this._logo("info"),...t)}warn(...t){this.forbidden||console.log(this._logo("warn"),...t)}error(...t){this.forbidden||console.log(this._logo("error"),...t)}},a=new ie(W());import jt from"ora";var Pe=e=>{let t=jt(e),o=setTimeout(()=>{t.start()},1500);return{stop:()=>{clearTimeout(o),t.stop()},text:r=>{t.text=r},succeed:r=>{clearTimeout(o),t.succeed(` ${r}`)},fail:r=>{clearTimeout(o),t.fail(` ${r}`)},warn:r=>{clearTimeout(o),t.warn(` ${r}`)},info:r=>{clearTimeout(o),t.info(` ${r}`)}}};var g=e=>{if(!e)return Promise.reject("Not a standard command.");a.info(e);let t=Pe(e);return new Promise(o=>{_t(e,(r,i,n)=>{r&&o(!1),o(i)})}).finally(()=>t.stop())},y=e=>e?(a.info(e),new Promise((t,o)=>{let[r,...i]=e.split(/\s+/).filter(s=>s);St(r,i,{stdio:"inherit",shell:!0}).on("close",s=>{s===0?t(!0):o(s)})})):Promise.reject("Not a standard command."),x=(...e)=>Promise.allSettled(e);var be=()=>g("curl -fsSL https://get.pnpm.io/install.sh | sh -"),Ae=(e,t=!1,o=!1,r={})=>{let i="pnpm",n="add";t?n="add --save-dev":o&&(n="add --global"),e||(n="install");let s=`${i} ${n} ${w(e)} ${Object.entries(r).map(([l,P])=>`--${l}=${P}`).join(" ")}`;return g(s)},ke=(e,t=!1,o={})=>{if(!e)return Promise.reject("packageName is required");let i=`${t?"pnpm remove -g":"pnpm remove"} ${w(e)} ${Object.keys(o).map(n=>`--${n}=${o[n]}`).join(" ")}`;return g(i)},De=(e,t={})=>{let o=`pnpm ${e} ${Object.keys(t).map(r=>`--${r}=${t[r]}`).join(" ")}`;return y(o)},Te=e=>y(`pnpx -y ${e}`);import{exec as Ee}from"child_process";var E=(e,t=!1,o=!1,r={})=>{let i="npm",n="install";t?n="install --save-dev":o?(i="npm",n="install -g"):i="npm";let s=`${i} ${n} ${w(e)} ${Object.keys(r).map(l=>`--${l}=${r[l]}`).join(" ")}`;return g(s)},Ie=(e,t=!1,o={})=>{if(!e)return Promise.reject("packageName is required");let i=`${t?"npm uninstall -g":"npm uninstall"} ${w(e)} ${Object.keys(o).map(n=>`--${n}=${o[n]}`).join(" ")}`;return g(i)},Me=(e,t={})=>{let o=`npm run ${e} ${Object.keys(t).map(r=>`--${r}=${t[r]}`).join(" ")}`;return y(o)},K=async(e,t=!1)=>{let o=`npm list ${w(e)} ${t?"-g":""} --depth=0`;a.off();let r=await g(`${o} | grep ${e}`);return a.on(),typeof r=="boolean"?r:r.toString()?.trim()?.includes(e)},Z=e=>y(`npx -y ${e} `);var je=[{name:"pnpm",check:()=>new Promise((e,t)=>{Ee("pnpm -v",(o,r,i)=>{o&&e(!1),e(!!r.includes("."))})}),install:be},{name:"nx",check:()=>new Promise(e=>{Ee("nx --version",(t,o,r)=>{t&&e(!1),e(!!o.includes("."))})}),install:async()=>{await E("nx",!1,!0)}}];var _e=` | ||
Examples: | ||
@@ -51,4 +51,4 @@ # Initialize a new project | ||
$ xr build | ||
`;import _e from"inquirer";var A=(e,t=null,o="input",r=()=>!0)=>new Promise((n,i)=>{_e.prompt([{type:o,name:"answer",message:e,default:t,validate:s=>r(s)?!0:"Invalid input, please try again."}],null).then(s=>{n(s.answer)}).catch(s=>{i(s)})}),Re=(e,t=null,o=[])=>new Promise((r,n)=>{_e.prompt([{type:"list",name:"answer",message:e,choices:o,default:t}],null).then(i=>{r(i.answer)}).catch(i=>{n(i)})});var jt=async()=>{let e=await A("\u8BBE\u7F6E\u4ED3\u5E93\u6E90:","https://registry.npmmirror.com");a.info("[init]\u5F00\u59CB\u68C0\u67E5\u4F9D\u8D56\u9879...");try{await d(`npm config set registry ${e}`),await d(`yarn config set registry ${e}`),await d(`pnpm config set registry ${e}`);for(let t of Te)await t?.check()||(a.info(`[init]\u672A\u5B89\u88C5\u4F9D\u8D56\u9879[${t.name}],\u6B63\u5728\u5B89\u88C5...`),await t?.install?.())}catch{}a.info("[init]\u4F9D\u8D56\u9879\u68C0\u67E5\u5B8C\u6210.")},Se=async()=>{await jt()};import{mkdir as _t,writeFile as Fe,readFile as Rt,appendFile as St}from"node:fs/promises";import{existsSync as Ft}from"node:fs";var S=async e=>{if(!(!e||Ft(e)))try{a.info(`creating dir: ${e}`),await _t(e,{recursive:!0})}catch(t){a.error(`Failed to create directory: ${t}`)}},u=async(e,t)=>{a.info(`creating file:${e}`);let o=e.substring(0,e.lastIndexOf("/"));await S(o),await Fe(e,t)},F=async(e,t)=>{a.info(`updating file:${e}`),await St(e,` | ||
`+t)},l=async(e,t,o)=>{a.info(`replacing file:${e}`);let n=(await U(e)).replace(t,o);a.off(),await Fe(e,n),a.on()},U=async e=>(a.info(`loading file:${e}`),await Rt(e,"utf-8"));var m=async(e,t)=>{let o;typeof t=="object"||t===null?o=JSON.stringify(t,null,2):o=t,await u(e,o)},E=async e=>{if(!e)return a.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let t=await U(e);return JSON.parse(t)};import{existsSync as Ne}from"node:fs";import{rm as Le}from"node:fs/promises";var p=async e=>{if(!Ne(e))return"\u4E0D\u5B58\u5728\u6B64\u6587\u4EF6";await Le(e,{recursive:!0,force:!0})},z=async e=>{if(!Ne(e))return"\u4E0D\u5B58\u5728\u6B64\u76EE\u5F55";await Le(e,{recursive:!0,force:!0})};var Oe=(e,t=!1,o=!1,r={})=>{let n="yarn",i="add";t?i="add --dev":o?(n="yarn global",i="add"):n="yarn",e||(i="");let s=`${n} ${i} ${v(e)} ${Object.keys(r).map(g=>`--${g}=${r[g]}`).join(" ")}`;return d(s)},Ue=(e,t=!1,o={})=>{if(!e)return Promise.reject("packageName is required");let n=`${t?"yarn global remove":"yarn remove"} ${v(e)} ${Object.keys(o).map(i=>`--${i}=${o[i]}`).join(" ")}`;return d(n)},ze=(e,t={})=>{let o=`yarn run ${e} ${Object.keys(t).map(r=>`--${r}=${t[r]}`).join(" ")}`;return y(o)},Be=e=>y(`yarn create -y ${e}`);import{dirname as Nt,sep as Je}from"path";import{readdir as Lt}from"node:fs/promises";var B=async()=>{let e=process.cwd();try{for(;e!==Je&&!(await Lt(e)).includes(".xrc");)e=Nt(e);return e===Je&&new Error("Not in a x project."),e}catch(t){throw a.error(t),t}},K=async()=>{try{return await B()!=="/"}catch{return!1}};import{resolve as Ot}from"node:path";var f=async()=>{try{let e=await B();return await E(Ot(e,".xrc"))}catch{return{}}},J=(e,t)=>e?Object.keys(e.projects).filter(o=>e.projects[o].type===t):[];import{readdir as Ut}from"node:fs/promises";import{resolve as zt}from"node:path";var Xe=["package-lock.json","pnpm-lock.yaml","yarn.lock"],He=V(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var N=e=>{switch(e){case"pnpm":return{has:W,install:Ae,uninstall:be,run:ke,npx:De};case"yarn":return{has:W,install:Oe,uninstall:Ue,run:ze,npx:Be};case"npm":default:return{has:W,install:D,uninstall:Ee,run:Me,npx:Y}}},Bt=async()=>{try{let e=await f(),{packageManager:t}=e;return t}catch{return}},Jt=async()=>{let t=(await Ut(zt("."))).filter(o=>Xe.includes(o));if(t.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[o="package-lock.json"]=t;return He[o]}},ne=async()=>{let e=await Bt();return e||await Jt()},h=async(...e)=>{await N(await ne()).has(...e)},$=async(...e)=>{await N(await ne()).install(...e)},C=async(...e)=>{await N(await ne()).uninstall(...e)};var Xt={extends:["@commitlint/config-conventional"]},Ht={path:"cz-conventional-changelog"},qe={check:()=>h("@commitlint/config-conventional","commitizen"),install:()=>x($(["commitizen","commitlint","@commitlint/cli","@commitlint/config-conventional"],!0),d("commitizen init cz-conventional-changelog --save-dev --save-exact"),m(".commitlintrc",Xt),m(".czrc",Ht)),uninstall:()=>x(C(["@commitlint/cli","@commitlint/config-conventional","commitizen"]),p(".commitlintrc"),p(".czrc"))};var qt={env:{browser:!0,es2021:!0},extends:["eslint:recommended","plugin:@typescript-eslint/recommended","prettier"],parser:"@typescript-eslint/parser",parserOptions:{ecmaVersion:"latest",sourceType:"module"},plugins:["@typescript-eslint","unused-imports"],rules:{"no-case-declarations":"off","unused-imports/no-unused-imports":"error","@typescript-eslint/no-explicit-any":"off","@typescript-eslint/no-unused-vars":"off","@typescript-eslint/no-this-alias":"off","@typescript-eslint/ban-types":["error",{types:{Function:!1}}],"@typescript-eslint/prefer-readonly-parameter-types":"off"}},Ve={check:()=>h("eslint"),install:()=>x($(["eslint-plugin-unused-imports","@typescript-eslint/eslint-plugin@latest","@typescript-eslint/parser@latest","eslint@latest","eslint-config-prettier"],!0),m(".eslintrc",qt)),uninstall:()=>x(C(["eslint-plugin-unused-imports","@typescript-eslint/eslint-plugin@latest","@typescript-eslint/parser@latest","eslint@latest","eslint-config-prettier"]),p(".eslintrc"))};import{exists as Vt}from"node:fs";var Wt=`# Compiled output | ||
`;import Se from"inquirer";var b=(e,t=null,o="input",r=()=>!0)=>new Promise((i,n)=>{Se.prompt([{type:o,name:"answer",message:e,default:t,validate:s=>r(s)?!0:"Invalid input, please try again."}],null).then(s=>{i(s.answer)}).catch(s=>{n(s)})}),Re=(e,t=null,o=[])=>new Promise((r,i)=>{Se.prompt([{type:"list",name:"answer",message:e,choices:o,default:t}],null).then(n=>{r(n.answer)}).catch(n=>{i(n)})});var Rt=async()=>{let e=await b("\u8BBE\u7F6E\u4ED3\u5E93\u6E90:","https://registry.npmmirror.com");a.info("[init]\u5F00\u59CB\u68C0\u67E5\u4F9D\u8D56\u9879...");try{await g(`npm config set registry ${e}`),await g(`yarn config set registry ${e}`),await g(`pnpm config set registry ${e}`);for(let t of je)await t?.check()||(a.info(`[init]\u672A\u5B89\u88C5\u4F9D\u8D56\u9879[${t.name}],\u6B63\u5728\u5B89\u88C5...`),await t?.install?.())}catch{}a.info("[init]\u4F9D\u8D56\u9879\u68C0\u67E5\u5B8C\u6210.")},Fe=async()=>{await Rt()};import{mkdir as Ft,writeFile as Ne,readFile as Nt,appendFile as Ot}from"node:fs/promises";import{existsSync as Lt}from"node:fs";var F=async e=>{if(!(!e||Lt(e)))try{a.info(`creating dir: ${e}`),await Ft(e,{recursive:!0})}catch(t){a.error(`Failed to create directory: ${t}`)}},f=async(e,t)=>{a.info(`creating file:${e}`);let o=e.substring(0,e.lastIndexOf("/"));await F(o),await Ne(e,t)},N=async(e,t)=>{a.info(`updating file:${e}`),await Ot(e,` | ||
`+t)},u=async(e,t,o=null)=>{a.info(`replacing file:${e}`);let r=[];Array.isArray(t)?r=t:r=[[t,o]];let n=await z(e);for(let[s,l]of r)n=n.replaceAll(s,l);a.warn(e,t,"===>",n),await Ne(e,n,"utf8")},z=async e=>(a.info(`loading file:${e}`),await Nt(e,"utf-8"));var m=async(e,t)=>{let o;typeof t=="object"||t===null?o=JSON.stringify(t,null,2):o=t,await f(e,o)},T=async e=>{if(!e)return a.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let t=await z(e);return JSON.parse(t)};import{existsSync as Oe}from"node:fs";import{rm as Le}from"node:fs/promises";var p=async e=>{if(!Oe(e))return"\u4E0D\u5B58\u5728\u6B64\u6587\u4EF6";await Le(e,{recursive:!0,force:!0})},J=async e=>{if(!Oe(e))return"\u4E0D\u5B58\u5728\u6B64\u76EE\u5F55";await Le(e,{recursive:!0,force:!0})};var Be=(e,t=!1,o=!1,r={})=>{let i="yarn",n="add";t?n="add --dev":o?(i="yarn global",n="add"):i="yarn",e||(n="");let s=`${i} ${n} ${w(e)} ${Object.keys(r).map(l=>`--${l}=${r[l]}`).join(" ")}`;return g(s)},Ue=(e,t=!1,o={})=>{if(!e)return Promise.reject("packageName is required");let i=`${t?"yarn global remove":"yarn remove"} ${w(e)} ${Object.keys(o).map(n=>`--${n}=${o[n]}`).join(" ")}`;return g(i)},ze=(e,t={})=>{let o=`yarn run ${e} ${Object.keys(t).map(r=>`--${r}=${t[r]}`).join(" ")}`;return y(o)},Je=e=>y(`yarn create -y ${e}`);import{dirname as Bt,sep as Xe}from"path";import{readdir as Ut}from"node:fs/promises";var X=async()=>{let e=process.cwd();try{for(;e!==Xe&&!(await Ut(e)).includes(".xrc");)e=Bt(e);return e===Xe&&new Error("Not in a x project."),e}catch(t){throw a.error(t),t}},Q=async()=>{try{return await X()!=="/"}catch{return!1}};import{resolve as zt}from"node:path";var d=async()=>{try{let e=await X();return await T(zt(e,".xrc"))}catch{return{}}},H=(e,t)=>e?Object.keys(e.projects).filter(o=>e.projects[o].type===t):[];import{readdir as Jt}from"node:fs/promises";import{resolve as Xt}from"node:path";var He=["package-lock.json","pnpm-lock.yaml","yarn.lock"],qe=Y(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var O=e=>{switch(e){case"pnpm":return{has:K,install:Ae,uninstall:ke,run:De,npx:Te};case"yarn":return{has:K,install:Be,uninstall:Ue,run:ze,npx:Je};case"npm":default:return{has:K,install:E,uninstall:Ie,run:Me,npx:Z}}},Ht=async()=>{try{let e=await d(),{packageManager:t}=e;return t}catch{return}},qt=async()=>{let t=(await Jt(Xt("."))).filter(o=>He.includes(o));if(t.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[o="package-lock.json"]=t;return qe[o]}},se=async()=>{let e=await Ht();return e||await qt()},v=async(...e)=>{await O(await se()).has(...e)},h=async(...e)=>{await O(await se()).install(...e)},$=async(...e)=>{await O(await se()).uninstall(...e)};var Vt={extends:["@commitlint/config-conventional"]},Wt={path:"cz-conventional-changelog"},Ve={check:()=>v("@commitlint/config-conventional","commitizen"),install:()=>x(h(["commitizen","commitlint","@commitlint/cli","@commitlint/config-conventional"],!0),g("commitizen init cz-conventional-changelog --save-dev --save-exact"),m(".commitlintrc",Vt),m(".czrc",Wt)),uninstall:()=>x($(["@commitlint/cli","@commitlint/config-conventional","commitizen"]),p(".commitlintrc"),p(".czrc"))};var Yt={env:{browser:!0,es2021:!0},extends:["eslint:recommended","plugin:@typescript-eslint/recommended","prettier"],parser:"@typescript-eslint/parser",parserOptions:{ecmaVersion:"latest",sourceType:"module"},plugins:["@typescript-eslint","unused-imports"],rules:{"no-case-declarations":"off","unused-imports/no-unused-imports":"error","@typescript-eslint/no-explicit-any":"off","@typescript-eslint/no-unused-vars":"off","@typescript-eslint/no-this-alias":"off","@typescript-eslint/ban-types":["error",{types:{Function:!1}}],"@typescript-eslint/prefer-readonly-parameter-types":"off"}},We={check:()=>v("eslint"),install:()=>x(h(["eslint-plugin-unused-imports","@typescript-eslint/eslint-plugin@latest","@typescript-eslint/parser@latest","eslint@latest","eslint-config-prettier"],!0),m(".eslintrc",Yt)),uninstall:()=>x($(["eslint-plugin-unused-imports","@typescript-eslint/eslint-plugin@latest","@typescript-eslint/parser@latest","eslint@latest","eslint-config-prettier"]),p(".eslintrc"))};import{exists as Kt}from"node:fs";var Zt=`# Compiled output | ||
dist | ||
@@ -90,3 +90,3 @@ tmp | ||
package-lock.json | ||
pnpm-lock.yaml`,We={check:()=>new Promise(e=>Vt(".gitignore",t=>e(t))),install:()=>m(".gitignore",Wt),uninstall:()=>p(".gitignore")};var Yt=`#!/usr/bin/env sh | ||
pnpm-lock.yaml`,Ye={check:()=>new Promise(e=>Kt(".gitignore",t=>e(t))),install:()=>m(".gitignore",Zt),uninstall:()=>p(".gitignore")};var Qt=`#!/usr/bin/env sh | ||
# \u5BFC\u5165 Husky \u811A\u672C | ||
@@ -99,15 +99,11 @@ . "$(dirname -- "$0")/_/husky.sh" | ||
# \u4E0D\u7BA1\u662F\u5426\u901A\u8FC7 \u90FD\u5141\u8BB8\u6267\u884C | ||
exit 0;`,Kt=`#!/usr/bin/env sh | ||
exit 0;`,Gt=`#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
npx --no -- commitlint --edit $1`,Ye={check:()=>h("husky"),install:async()=>{await $("husky",!0),await d("npx husky init"),await m(".husky/pre-commit",Yt),await m(".husky/commit-msg",Kt)},uninstall:()=>x(C("husky"),z("./husky"))};import{fileURLToPath as Zt}from"node:url";import{dirname as Qt}from"node:path";import{resolve as Ke}from"path";var Gt=Zt(import.meta.url),Ze=Qt(Gt),M=q()==="dev"?Ke(Ze,"../../../"):Ke(Ze,"../");import{copyFile as eo,rm as to}from"node:fs/promises";import{resolve as L}from"node:path";import{existsSync as Qe}from"node:fs";var Ge={check:async()=>Qe(L(M,"resources","settings.zip"))?Qe(L(process.cwd(),"settings.zip")):!1,install:async()=>{a.info(`\u6587\u4EF6\u4E0B\u8F7D\u81F3: file://${L(process.cwd(),"settings.zip")} | ||
npx --no -- commitlint --edit $1`,Ke={check:()=>v("husky"),install:async()=>{await h("husky",!0),await g("npx husky init"),await m(".husky/pre-commit",Qt),await m(".husky/commit-msg",Gt)},uninstall:()=>x($("husky"),J("./husky"))};import{fileURLToPath as eo}from"node:url";import{dirname as to}from"node:path";import{resolve as Ze}from"path";var oo=eo(import.meta.url),Qe=to(oo),j=W()==="dev"?Ze(Qe,"../../../"):Ze(Qe,"../");import{copyFile as ro,rm as no}from"node:fs/promises";import{resolve as L}from"node:path";import{existsSync as Ge}from"node:fs";var et={check:async()=>Ge(L(j,"resources","settings.zip"))?Ge(L(process.cwd(),"settings.zip")):!1,install:async()=>{a.info(`\u6587\u4EF6\u4E0B\u8F7D\u81F3: file://${L(process.cwd(),"settings.zip")} | ||
\u8BF7\u6309\u7167\u64CD\u4F5C\u8DEF\u5F84\u8FDB\u884C\u5BFC\u5165: | ||
\u6587\u4EF6->\u7BA1\u7406IDE\u8BBE\u7F6E->\u5BFC\u5165\u8BBE\u7F6E->\u9009\u62E9settings.zip\u6587\u4EF6->\u786E\u8BA4\u5BFC\u5165`),await eo(L(M,"resources","settings.zip"),L(process.cwd(),"settings.zip"))},uninstall:async()=>{await to(L(process.cwd(),"settings.zip"))}};var oo={singleQuote:!0,experimentalTernaries:!1,semi:!0,tabWidth:4,trailingComma:"none",printWidth:360,quoteProps:"consistent",bracketSpacing:!0,bracketSameLine:!0,arrowParens:"always",htmlWhitespaceSensitivity:"css",endOfLine:"lf",singleAttributePerLine:!0},et={check:()=>h("prettier"),install:()=>x($("prettier",!0),m(".prettierrc",oo)),uninstall:()=>x(C("prettier"),p(".prettierrc"))};var ro={"*.{js,ts,jsx,tsx,vue}":["prettier --write","eslint --fix"],"*.{html,css,scss,less,json}":["prettier --write"]},tt={check:()=>h("lint-staged"),install:()=>x($("lint-staged",!0),m(".lintstagedrc",ro)),uninstall:()=>x(C("lint-staged"),p(".lintstagedrc"))};var ot=async(e,t)=>{if(!["install","uninstall","list"].includes(e))throw a.warn("Not correct action! You can use install/uninstall/list command with plugin."),"Not correct action.";e==="list"?await no():t?await X?.[t]?.[e]?.():await x(...Object.keys(X).map(o=>X[o][e]()))},no=async()=>{let e=Object.keys(X).map(t=>(async()=>{let o=await X[t]?.check?.();a.info(`[${o?"+":"-"}] ${t} - ${o?"installed":"uninstalled"}`)})());return await Promise.allSettled(e)},X={gitignore:We,comment:Ge,lintStaged:tt,husky:Ye,commitLint:qe,eslint:Ve,prettier:et};import{resolve as io}from"node:path";import{readFileSync as so}from"node:fs";var rt=()=>{try{return JSON.parse(so(io(M,"package.json"),"utf-8"))}catch{return{}}};var nt=async()=>{let{name:e}=await rt();await D(e,!1,!0)};var it="export default {};";import{resolve as I}from"node:path";var st=`import type {StorybookConfig} from '@storybook/angular'; | ||
\u6587\u4EF6->\u7BA1\u7406IDE\u8BBE\u7F6E->\u5BFC\u5165\u8BBE\u7F6E->\u9009\u62E9settings.zip\u6587\u4EF6->\u786E\u8BA4\u5BFC\u5165`),await ro(L(j,"resources","settings.zip"),L(process.cwd(),"settings.zip"))},uninstall:async()=>{await no(L(process.cwd(),"settings.zip"))}};var io={singleQuote:!0,experimentalTernaries:!1,semi:!0,tabWidth:4,trailingComma:"none",printWidth:360,quoteProps:"consistent",bracketSpacing:!0,bracketSameLine:!0,arrowParens:"always",htmlWhitespaceSensitivity:"css",endOfLine:"lf",singleAttributePerLine:!0},tt={check:()=>v("prettier"),install:()=>x(h("prettier",!0),m(".prettierrc",io)),uninstall:()=>x($("prettier"),p(".prettierrc"))};var so={"*.{js,ts,jsx,tsx,vue}":["prettier --write","eslint --fix"],"*.{html,css,scss,less,json}":["prettier --write"]},ot={check:()=>v("lint-staged"),install:()=>x(h("lint-staged",!0),m(".lintstagedrc",so)),uninstall:()=>x($("lint-staged"),p(".lintstagedrc"))};var rt=async(e,t)=>{if(!["install","uninstall","list"].includes(e))throw a.warn("Not correct action! You can use install/uninstall/list command with plugin."),"Not correct action.";e==="list"?await ao():t?await q?.[t]?.[e]?.():await x(...Object.keys(q).map(o=>q[o][e]()))},ao=async()=>{let e=Object.keys(q).map(t=>(async()=>{let o=await q[t]?.check?.();a.info(`[${o?"+":"-"}] ${t} - ${o?"installed":"uninstalled"}`)})());return await Promise.allSettled(e)},q={gitignore:Ye,comment:et,lintStaged:ot,husky:Ke,commitLint:Ve,eslint:We,prettier:tt};import{resolve as co}from"node:path";import{readFileSync as po}from"node:fs";var nt=()=>{try{return JSON.parse(po(co(j,"package.json"),"utf-8"))}catch{return{}}};var it=async()=>{let{name:e}=await nt();await E(e,!1,!0)};var st="export default {};";import{resolve as A}from"node:path";var at=`import type {StorybookConfig} from '@storybook/angular'; | ||
const config: StorybookConfig = { | ||
stories: ['../src/**/*.mdx', '../**/*.stories.@(js|jsx|ts|tsx|mdx)'], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-interactions", | ||
"@storybook/addon-actions", | ||
"@storybook/addon-controls", | ||
"@storybook/addon-essentials" | ||
], | ||
@@ -128,4 +124,3 @@ // typescript: { | ||
core: { | ||
// @ts-ignore | ||
builder: 'webpack5', | ||
builder: '@storybook/builder-webpack5', | ||
}, | ||
@@ -135,13 +130,18 @@ }; | ||
export default config; | ||
`;import{existsSync as ao}from"node:fs";var k=e=>(e=e.replace(/([A-Z]+)(?=[A-Z][a-z])/g,t=>t.toLowerCase()+"-"),e?.replace(/([A-Z])/g,(t,o,r)=>`${r>0?"-":""}${t.toLowerCase()}`).replace(/^./,t=>t.toLowerCase()));var at=async e=>{if(ao(I(process.cwd(),e)))if(await A("\u53D1\u73B0\u540C\u540D\u9879\u76EE,\u662F\u5426\u786E\u8BA4\u5220\u9664\u6B64\u9879\u76EE\u4EE5\u521B\u5EFA\u65B0\u9879\u76EE?",null,"confirm"))await p(I(process.cwd(),e));else throw new Error("\u7528\u6237\u62D2\u7EDD\u4E86\u521B\u5EFA\u9879\u76EE!")},ct=async({projectName:e,packageManager:t,prefix:o,componentLibName:r,demoLibName:n})=>{await Y(`create-nx-workspace@16.10.0 ${e} --preset=apps --framework=none --packageManager=${t} --nxCloud=skip --e2eTestRunner=none --workspaceType=integrated `),process.chdir(e);let i=N(t);await i.install("@nx/angular@16.10.0",!0),await i.has("nx",!0)||await i.install("nx",!0),await y(`nx g @nx/angular:library ${r} --buildable=true --publishable=true --prefix=${o??""} --importPath=${e} --skipTests=true`),await y(`nx g @nx/angular:storybook-configuration ${r} --interactionTests=false --generateStories=false --configureStaticServe=false`),await y(`nx g @nx/angular:application ${n} --routing=true --standalone=true`)},pt=async({componentLibName:e,demoLibName:t})=>{let o=["components","directives","pipes"],r=I(`${e}/src/lib/styles/variables/public.scss`),n=I(`${e}/src/lib/styles/public.scss`),i=I(`${e}/src/document/readme.mdx`),s=`${e}/.storybook/preview.ts`,g=`${e}/documentation.json`,R=`${e}/tsconfig.json`,H=await E(R);H.compilerOptions.resolveJsonModule=!0;let oe=`${e}/.storybook/main.ts`;await x(p(`${e}/src/lib/${e}.module.ts`),p(`${e}/src/test-setup.ts`),...o.map(w=>{let O=`${e}/src/lib/${w}/index.ts`;return m(O,it)}),m(`${e}/src/index.ts`,o.reduce((w,O)=>w+=`export * from "./lib/${O}"; | ||
`,"")),m(r,`@mixin variables() { | ||
`;import{existsSync as mo}from"node:fs";var I=e=>(e=e.replace(/([A-Z]+)(?=[A-Z][a-z])/g,t=>t.toLowerCase()+"-"),e?.replace(/([A-Z])/g,(t,o,r)=>`${r>0?"-":""}${t.toLowerCase()}`).replace(/^./,t=>t.toLowerCase()));var ct=`import { Meta } from '@storybook/addon-docs/blocks'; | ||
<Meta title="\u8BF4\u660E" /> | ||
# \u8BF4\u660E | ||
\u5185\u5BB9 | ||
`;var pt=`import { setCompodocJson } from '@storybook/addon-docs/angular'; | ||
import docJson from '../documentation.json'; | ||
setCompodocJson(docJson);`;var mt=async e=>{if(mo(A(process.cwd(),e)))if(await b("\u53D1\u73B0\u540C\u540D\u9879\u76EE,\u662F\u5426\u786E\u8BA4\u5220\u9664\u6B64\u9879\u76EE\u4EE5\u521B\u5EFA\u65B0\u9879\u76EE?",null,"confirm"))await p(A(process.cwd(),e));else throw new Error("\u7528\u6237\u62D2\u7EDD\u4E86\u521B\u5EFA\u9879\u76EE!")},lt=async({projectName:e,packageManager:t,prefix:o,componentLibName:r,demoLibName:i})=>{await Z(`create-nx-workspace@16.10.0 ${e} --preset=apps --framework=none --packageManager=${t} --nxCloud=skip --e2eTestRunner=none --workspaceType=integrated `),process.chdir(e);let n=O(t);await n.install("@nx/angular@16.10.0",!0),await n.has("nx",!0)||await n.install("nx",!0),await y(`nx g @nx/angular:library ${r} --buildable=true --publishable=true --prefix=${o??""} --importPath=${e} --skipTests=true`),await y(`nx g @nx/angular:storybook-configuration ${r} --interactionTests=false --generateStories=false --configureStaticServe=false`),await y(`nx g @nx/angular:application ${i} --routing=true --standalone=true`)},ut=async({projectName:e,componentLibName:t,demoLibName:o})=>{let r=["components","directives","pipes"],i=A(`${t}/src/lib/styles/variables/public.scss`),n=A(`${t}/src/lib/styles/public.scss`),s=A(`${t}/src/document/readme.mdx`),l=`${t}/.storybook/preview.ts`,P=`${t}/documentation.json`,M=`${t}/tsconfig.json`,V=await T(M);V.compilerOptions.resolveJsonModule=!0;let D=`${t}/.storybook/main.ts`;await x(p(`${t}/src/lib/${t}.module.ts`),p(`${t}/src/test-setup.ts`),...r.map(B=>{let U=`${t}/src/lib/${B}/index.ts`;return m(U,st)}),m(`${t}/src/index.ts`,r.reduce((B,U)=>B+=`export * from "./lib/${U}"; | ||
`,"")),m(i,`@mixin variables() { | ||
}`),m(n,`@import "./variables/public"; | ||
@include variables();`),u(i,`import { Meta, Controls } from '@storybook/blocks'; | ||
<Meta title="\u6587\u6863/README" /> | ||
# README`),m(g,""),m(s,`import { setCompodocJson } from '@storybook/addon-docs/angular'; | ||
import docJson from '../documentation.json'; | ||
setCompodocJson(docJson);`),m(R,H),u(oe,st),...o.map(w=>{let O=`${t}/src/${w}`;return S(O)}),p(`${t}/src/app/nx-welcome.component.ts`),p(`${t}/src/app/app.component.spec.ts`),p(`${t}/src/app/app.component.css`),u(`${t}/src/app/app.component.scss`),l(`${t}/src/app/app.component.html`,`<${e}-nx-welcome></${e}-nx-welcome> `,""),l(`${t}/src/app/app.component.ts`,"import { NxWelcomeComponent } from './nx-welcome.component'",""))},mt=async({packageManager:e,componentLibName:t})=>{await N(e).install("@compodoc/compodoc",!0);let o=I(`${t}/.storybook/tsconfig.json`),r=await E(o);r?.include?.push("../src/**/*.ts"),await m(o,r);let n=I(`${t}/project.json`),i=await E(n),s={compodoc:!0,compodocArgs:["-e","json","-d",`${t}/src`,"--u","--disablePrivate","--disableInternal","--disableProtected","--disableLifeCycleHooks"],styles:[`${t}/src/lib/styles/public.scss`]};Object.assign(i.targets?.storybook.options,s),Object.assign(i.targets?.["build-storybook"]?.options,s),await m(n,i)},lt=async({projectName:e,componentLibName:t,demoLibName:o,registry:r})=>{let n="package.json",i=await E(n);Object.assign(i.scripts,{"fix:nx":"rm -rf .nx && rm -rf .angular",clean:"rm -rf dist && rm -rf node_modules",play:`nx run ${o??"play"}:serve`,"doc:serve":`nx run ${t??"ui"}:storybook`,"doc:build":`nx run ${t??"ui"}:build-storybook`,"ui:build":`nx run ${t??"ui"}:build`,"ui:unpublish":`npm unpublish ${e} --force --registry ${r}`,"ui:publish":`pnpm build && cd dist/${e} && npm publish --registry ${r}`}),await m(n,i)},ut=async({projectName:e,packageManager:t,prefix:o,componentLibName:r,demoLibName:n})=>{let i=".xrc",s={version:"1.0.1",name:e,prefix:o,projects:{[r]:{type:"component"},[n]:{type:"demo"}},packageManager:t};await m(i,s)};var ft=async e=>{await at(k(e));let t=await A("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u5E93\u7684\u540D\u79F0(\u56DE\u8F66\u786E\u8BA4)","ui"),o=await A("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u5E93\u4F7F\u7528\u7684\u7EC4\u4EF6\u524D\u7F00[prefix](\u56DE\u8F66\u786E\u8BA4)",k(t)),r=await A("\u8BF7\u8F93\u5165demo\u5E93\u7684\u540D\u79F0(\u56DE\u8F66\u786E\u8BA4)","play"),n=await Re("\u9009\u62E9\u4F60\u7684\u5305\u7BA1\u7406\u5668(\u56DE\u8F66\u786E\u8BA4)","pnpm",["pnpm","npm","yarn"]),i=await A("\u6307\u5B9A\u4ED3\u5E93\u6E90(\u56DE\u8F66\u786E\u8BA4)","https://registry.npmjs.com"),s={projectName:k(e),componentLibName:k(t),demoLibName:k(r),packageManager:n,registry:i,prefix:o};try{await ct(s),await pt(s),await mt(s),await lt(s),await ut(s),await d(`git init && git add . && git commit -m "chore: init project ${e}"`)}catch(g){a.error(g)}};import{resolve as T}from"node:path";import{resolve as P}from"node:path";var dt=e=>e.toString().split("-").map((t,o)=>o===0?t:t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("");var ie={upper:e=>e.toString().toUpperCase(),lower:e=>e.toString().toLowerCase(),capital:e=>{let t=e.toString();return t.at(0).toUpperCase()+t.slice(1)},camel:dt,kebabcase:k},co=Object.keys(ie),po=new RegExp(`{@[0-9a-zA-Z]+(?:__(${co.join("|")}))?}`,"img"),mo=e=>e.toString().split("__")[0]?.toLowerCase().replace(/[@{}]+/g,""),lo=e=>e.toString().split("__").slice(1).map(t=>t.toLowerCase().replace(/[@{}]+/g,"")),gt=(e,t)=>{let o=Object.keys(e).filter(r=>r.toLowerCase()===t)?.[0];return e[o]},c=(e,t)=>e.replace(po,o=>{let r=lo(o),n=mo(o);return gt(t,n)?r.reduce((i,s)=>Object.hasOwn(ie,s)?ie[s](i):i,gt(t,n)):o});var se=async(e,t,{needExport:o=!1}={})=>{let{prefix:r}=await f(),n=P(t,e),i=P(t,"index.ts"),s=P(n,`${e}.component.html`),g=P(n,`${e}.component.scss`),R=P(n,`${e}.component.ts`),H=P(n,`${e}.stories.ts`),oe=P(n,"index.ts");await S(n);let w={name:e,prefix:r};await x(u(s,c(uo,w)),u(g,c(fo,w)),u(R,c(go,w)),u(H,c(xo,w)),u(oe,c(yo,w))),o&&await F(i,c(ae,w))},xt=async(e,t)=>{let{prefix:o,name:r}=await f(),n=P(t,e),i=P(n,`${e}.component.ts`),s=P(t,"../app","app.routes.ts"),g={name:e,project:r,prefix:o};await S(n),await u(i,c(wo,g)),await l(s,"/router';",`/router'; | ||
${c(ce,g)} | ||
`),await l(s,"Route[] = [",`Route[] = [ | ||
${c(pe,g)}`)},uo="<!-- {@PREFIX}-{@NAME} -->",fo="",go=` | ||
@include variables();`),f(s,ct),m(P,"{}"),m(l,pt),m(M,V),f(D,at),...r.map(B=>{let U=`${o}/src/${B}`;return F(U)}),p(`${o}/src/app/nx-welcome.component.ts`),p(`${o}/src/app/app.component.spec.ts`),p(`${o}/src/app/app.component.css`),f(`${o}/src/app/app.component.scss`),u(`${o}/src/app/app.component.html`,`<${e}-nx-welcome></${e}-nx-welcome> `,""),u(`${o}/src/app/app.component.ts`,[["import { NxWelcomeComponent } from './nx-welcome.component';",""],["NxWelcomeComponent, ",""],["'./app.component.css'",""]]))},ft=async({packageManager:e,componentLibName:t})=>{await O(e).install(["@compodoc/compodoc","@storybook/addon-essentials","@storybook/addon-docs","@storybook/react-dom-shim","@storybook/builder-webpack5","esbuild@^0.19.2"],!0);let o=A(`${t}/.storybook/tsconfig.json`),r=await T(o);r?.include?.push("../src/**/*.ts"),await m(o,r);let i=A("tsconfig.base.json"),n=await T(i);n.compilerOptions.resolveJsonModule=!0,n.compilerOptions.allowSyntheticDefaultImports=!0,await m(i,n);let s=A(`${t}/.storybook/main.ts`),l=A(`${t}/project.json`),P=await T(l),M={compodoc:!0,compodocArgs:["-e","json","-d",`${t}/src`,"-p",`${t}/tsconfig.json`,"--disablePrivate","--disableInternal","--disableProtected","--disableLifeCycleHooks"],styles:[`${t}/src/lib/styles/public.scss`]};Object.assign(P.targets?.storybook.options,M),Object.assign(P.targets?.["build-storybook"]?.options,M),await m(l,P)},dt=async({projectName:e,componentLibName:t,demoLibName:o,registry:r})=>{let i="package.json",n=await T(i);Object.assign(n.scripts,{"fix:nx":"rm -rf .nx && rm -rf .angular",clean:"rm -rf dist && rm -rf node_modules",play:`nx run ${o??"play"}:serve`,"doc:serve":`nx run ${t??"ui"}:storybook`,"doc:build":`nx run ${t??"ui"}:build-storybook`,"ui:build":`nx run ${t??"ui"}:build`,"ui:unpublish":`npm unpublish ${e} --force --registry ${r}`,"ui:publish":`pnpm build && cd dist/${e} && npm publish --registry ${r}`}),await m(i,n)},gt=async({projectName:e,packageManager:t,prefix:o,componentLibName:r,demoLibName:i})=>{let n=".xrc",s={version:"1.0.2",name:e,prefix:o,projects:{[r]:{type:"component"},[i]:{type:"demo"}},packageManager:t};await m(n,s)};var xt=async e=>{await mt(I(e));let t=await b("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u5E93\u7684\u540D\u79F0(\u56DE\u8F66\u786E\u8BA4)","ui"),o=await b("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u5E93\u4F7F\u7528\u7684\u7EC4\u4EF6\u524D\u7F00[prefix](\u56DE\u8F66\u786E\u8BA4)",I(t)),r=await b("\u8BF7\u8F93\u5165demo\u5E93\u7684\u540D\u79F0(\u56DE\u8F66\u786E\u8BA4)","play"),i=await Re("\u9009\u62E9\u4F60\u7684\u5305\u7BA1\u7406\u5668(\u56DE\u8F66\u786E\u8BA4)","pnpm",["pnpm","npm","yarn"]),n=await b("\u6307\u5B9A\u4ED3\u5E93\u6E90(\u56DE\u8F66\u786E\u8BA4)","https://registry.npmjs.com"),s={projectName:I(e),componentLibName:I(t),demoLibName:I(r),packageManager:i,registry:n,prefix:o};try{await lt(s),await ut(s),await ft(s),await dt(s),await gt(s),await g(`git init && git add . && git commit -m "chore: init project ${e}"`)}catch(l){a.error(l)}};import{resolve as _}from"node:path";import{resolve as C}from"node:path";var yt=e=>e.toString().split("-").map((t,o)=>o===0?t:t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("");var ae={upper:e=>e.toString().toUpperCase(),lower:e=>e.toString().toLowerCase(),capital:e=>{let t=e.toString();return t.at(0).toUpperCase()+t.slice(1)},camel:yt,kebabcase:I},lo=Object.keys(ae),uo=new RegExp(`{@[0-9a-zA-Z]+(?:__(${lo.join("|")}))?}`,"img"),fo=e=>e.toString().split("__")[0]?.toLowerCase().replace(/[@{}]+/g,""),go=e=>e.toString().split("__").slice(1).map(t=>t.toLowerCase().replace(/[@{}]+/g,"")),wt=(e,t)=>{let o=Object.keys(e).filter(r=>r.toLowerCase()===t)?.[0];return e[o]},c=(e,t)=>e.replace(uo,o=>{let r=go(o),i=fo(o);return wt(t,i)?r.reduce((n,s)=>Object.hasOwn(ae,s)?ae[s](n):n,wt(t,i)):o});var ce=async(e,t,{needExport:o=!1}={})=>{let{prefix:r}=await d(),i=C(t,e),n=C(t,"index.ts"),s=C(i,`${e}.component.html`),l=C(i,`${e}.component.scss`),P=C(i,`${e}.component.ts`),M=C(i,`${e}.stories.ts`),V=C(i,"index.ts");await F(i);let D={name:e,prefix:r};await x(f(s,c(xo,D)),f(l,c(yo,D)),f(P,c(wo,D)),f(M,c(vo,D)),f(V,c(ho,D))),o&&await N(n,c(pe,D))},vt=async(e,t)=>{let{prefix:o,name:r}=await d(),i=C(t,e),n=C(i,`${e}.component.ts`),s=C(t,"../app","app.routes.ts"),l={name:e,project:r,prefix:o};await F(i),await f(n,c($o,l)),await u(s,"/router';",`/router'; | ||
${c(me,l)} | ||
`),await u(s,"Route[] = [",`Route[] = [ | ||
${c(le,l)}`)},xo="<!-- {@PREFIX}-{@NAME} -->",yo="",wo=` | ||
import { Component } from '@angular/core'; | ||
@@ -159,3 +159,3 @@ import { CommonModule } from '@angular/common'; | ||
export class {@NAME__CAPITAL}Component {} | ||
`,xo=`import type { Meta, StoryObj } from '@storybook/angular'; | ||
`,vo=`import type { Meta, StoryObj } from '@storybook/angular'; | ||
import {{@NAME__CAPITAL}Component} from './{@NAME}.component'; | ||
@@ -176,3 +176,3 @@ | ||
}; | ||
`,yo='export * from "./{@NAME}.component"',ae='export * from "./{@NAME}";',wo=`import { Component } from '@angular/core'; | ||
`,ho='export * from "./{@NAME}.component"',pe='export * from "./{@NAME}";',$o=`import { Component } from '@angular/core'; | ||
import { CommonModule } from "@angular/common" | ||
@@ -193,6 +193,6 @@ import { FormsModule } from "@angular/forms" | ||
} | ||
`,ce='import { {@NAME__CAPITAL}DemoComponent } from "../components/{@NAME}/{@NAME}.component";',pe=` { | ||
`,me='import { {@NAME__CAPITAL}DemoComponent } from "../components/{@NAME}/{@NAME}.component";',le=` { | ||
path: '{@NAME}-demo', | ||
loadComponent: () => {@NAME__CAPITAL}DemoComponent | ||
},`;import{resolve as vo}from"node:path";var yt=async(e,t)=>{let o=vo(t,`${e}.service.ts`);await u(o,c(ho,{name:e}))},ho=`import {Injectable} from "@angular/core" | ||
},`;import{resolve as Co}from"node:path";var ht=async(e,t)=>{let o=Co(t,`${e}.service.ts`);await f(o,c(Po,{name:e}))},Po=`import {Injectable} from "@angular/core" | ||
@Injectable({ | ||
@@ -204,8 +204,8 @@ providedIn: "root" | ||
} | ||
`;import{resolve as $o}from"node:path";var wt=async(e,t)=>{let o=$o(t,`${e}.mdx`);await u(o,c(Co,{name:e}))},Co=`import { Meta, Controls } from '@storybook/blocks'; | ||
`;import{resolve as bo}from"node:path";var $t=async(e,t)=>{let o=bo(t,`${e}.mdx`);await f(o,c(Ao,{name:e}))},Ao=`import { Meta, Controls } from '@storybook/blocks'; | ||
<Meta title="{@NAME}" /> | ||
# {@NAME__UPPER}`;var vt=async()=>{try{let e=await B();process.chdir(e),a.info(`\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF1A${e}`)}catch{}};import{resolve as Z}from"node:path";var me=async(e,t,{needExport:o=!1}={})=>{let r=await f(),[n]=J(r,"component"),i=Z(t,`${e}.directive.ts`),s=Z(t,"index.ts"),g={name:e,prefix:r.prefix,project:n};await u(i,c(Po,g)),o&&await F(s,c(le,g))},ht=async(e,t)=>{let{prefix:o,name:r}=await f(),n=Z(t,`${e}.directive.ts`),i=Z(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await u(n,c(Ao,s)),await l(i,"/router';",`/router'; | ||
${c(ue,s)} | ||
`),await l(i,"Route[] = [",`Route[] = [ | ||
${c(fe,s)}`)},Po=`import { Directive } from '@angular/core'; | ||
# {@NAME__UPPER}`;var Ct=async()=>{try{let e=await X();process.chdir(e),a.info(`\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF1A${e}`)}catch{}};import{resolve as G}from"node:path";var ue=async(e,t,{needExport:o=!1}={})=>{let r=await d(),[i]=H(r,"component"),n=G(t,`${e}.directive.ts`),s=G(t,"index.ts"),l={name:e,prefix:r.prefix,project:i};await f(n,c(ko,l)),o&&await N(s,c(fe,l))},Pt=async(e,t)=>{let{prefix:o,name:r}=await d(),i=G(t,`${e}.directive.ts`),n=G(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await f(i,c(Do,s)),await u(n,"/router';",`/router'; | ||
${c(de,s)} | ||
`),await u(n,"Route[] = [",`Route[] = [ | ||
${c(ge,s)}`)},ko=`import { Directive } from '@angular/core'; | ||
@@ -219,3 +219,3 @@ @Directive({ | ||
} | ||
`,le='export * from "./{@NAME}.directive";',Ao=`import { Component } from '@angular/core'; | ||
`,fe='export * from "./{@NAME}.directive";',Do=`import { Component } from '@angular/core'; | ||
import { CommonModule } from "@angular/common" | ||
@@ -234,9 +234,9 @@ import { FormsModule } from "@angular/forms" | ||
export class {@NAME__CAPITAL}DirectiveDemoComponent { | ||
}`,ue='import { {@NAME__CAPITAL}DirectiveDemoComponent } from "../directives/{@NAME}.directive";',fe=` { | ||
}`,de='import { {@NAME__CAPITAL}DirectiveDemoComponent } from "../directives/{@NAME}.directive";',ge=` { | ||
path: '{@NAME}-directive-demo', | ||
loadComponent: () => {@NAME__CAPITAL}DirectiveDemoComponent | ||
},`;import{resolve as Q}from"node:path";var de=async(e,t,{needExport:o=!1}={})=>{let{prefix:r}=await f(),n=Q(t,`${e}.pipe.ts`),i=Q(t,"index.ts"),s={name:e,prefix:r};await u(n,c(bo,s)),o&&await F(i,c(ge,s))},$t=async(e,t)=>{let{prefix:o,name:r}=await f(),n=Q(t,`${e}.pipe.ts`),i=Q(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await u(n,c(ko,s)),await l(i,"/router';",`/router'; | ||
${c(xe,s)} | ||
`),await l(i,"Route[] = [",`Route[] = [ | ||
${c(ye,s)}`)},bo=`import { Pipe, PipeTransform } from '@angular/core'; | ||
},`;import{resolve as ee}from"node:path";var xe=async(e,t,{needExport:o=!1}={})=>{let{prefix:r}=await d(),i=ee(t,`${e}.pipe.ts`),n=ee(t,"index.ts"),s={name:e,prefix:r};await f(i,c(To,s)),o&&await N(n,c(ye,s))},bt=async(e,t)=>{let{prefix:o,name:r}=await d(),i=ee(t,`${e}.pipe.ts`),n=ee(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await f(i,c(Io,s)),await u(n,"/router';",`/router'; | ||
${c(we,s)} | ||
`),await u(n,"Route[] = [",`Route[] = [ | ||
${c(ve,s)}`)},To=`import { Pipe, PipeTransform } from '@angular/core'; | ||
@@ -252,3 +252,3 @@ @Pipe({ | ||
} | ||
`,ge='export * from "./{@NAME}.pipe";',ko=`import { Component } from '@angular/core'; | ||
`,ye='export * from "./{@NAME}.pipe";',Io=`import { Component } from '@angular/core'; | ||
import { CommonModule } from "@angular/common" | ||
@@ -267,8 +267,8 @@ import { FormsModule } from "@angular/forms" | ||
export class {@NAME__CAPITAL}PipeDemoComponent { | ||
}`,xe='import { {@NAME__CAPITAL}PipeDemoComponent } from "../pipes/{@NAME}.pipe";',ye=` { | ||
}`,we='import { {@NAME__CAPITAL}PipeDemoComponent } from "../pipes/{@NAME}.pipe";',ve=` { | ||
path: '{@NAME}-pipe-demo', | ||
loadComponent: () => {@NAME__CAPITAL}PipeDemoComponent | ||
},`;var Ct=async(e,t,o,r)=>{if(!await K()){let s="\u5F53\u524D\u9879\u76EE\u4E0D\u662F x \u9879\u76EE";throw a.warn(s),new Error(s)}let n=!o&&["component","directive","pipe"].includes(e),i=T(process.cwd(),o??"");await Do[e](t,i,n,r)},Do={component:async(e,t,o,r)=>{await j(o,async(n,i)=>{await se(e,T(`${n}/src/lib/components`),{bind:r,needExport:!0}),await xt(e,T(`${i}/src/components`))},async()=>{await se(e,t,{bind:r,needExport:!1})})},directive:async(e,t,o,r)=>{await j(o,async(n,i)=>{await me(e,T(`${n}/src/lib/directives`),{bind:r,needExport:!0}),await ht(e,T(`${i}/src/directives`))},async()=>{await me(e,t,{bind:r,needExport:!1})})},pipe:async(e,t,o,r)=>{await j(o,async(n,i)=>{await de(e,T(`${n}/src/lib/pipes`),{bind:r,needExport:!0}),await $t(e,T(`${i}/src/pipes`))},async()=>{await de(e,t,{bind:r,needExport:!1})})},service:async(e,t,o,r)=>{await yt(e,t,{bind:r})},doc:async(e,t,o,r)=>{await wt(e,t,{bind:r})}},j=async(e,t,o)=>{if(e){let r=await f(),[n]=J(r,"component"),[i]=J(r,"demo");await vt(),await t?.(n,i)}else await o()};import{resolve as _}from"node:path";import{resolve as G}from"node:path";var we=async(e,t,{needExport:o=!1}={})=>{let{prefix:r}=await f(),n={name:e,prefix:r},i=G(t,e),s=G(t,"index.ts");await z(i),await l(s,` | ||
`+c(ae,n),"")},Pt=async(e,t)=>{let{prefix:o,name:r}=await f(),n=G(t,e),i=G(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await z(n),await l(i,c(ce,s),""),await l(i,c(pe,s),"")};import{resolve as ee}from"node:path";var ve=async(e,t)=>{let{prefix:o}=await f(),r={name:e,prefix:o},n=ee(t,`${e}.directive.ts`),i=ee(t,"index.ts");await p(n),await l(i,` | ||
`+c(le,r),"")},At=async(e,t)=>{let{prefix:o,name:r}=await f(),n=ee(t,`${e}.directive.ts`),i=ee(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await p(n),await l(i,c(ue,s),""),await l(i,c(fe,s),"")};import{resolve as te}from"node:path";var he=async(e,t)=>{let{prefix:o}=await f(),r={name:e,prefix:o},n=te(t,`${e}.pipe.ts`),i=te(t,"index.ts");await p(n),await l(i,` | ||
`+c(ge,r),"")},bt=async(e,t)=>{let{prefix:o,name:r}=await f(),n=te(t,`${e}.pipe.ts`),i=te(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await p(n),await l(i,c(xe,s),""),await l(i,c(ye,s),"")};import{resolve as Eo}from"node:path";var kt=async(e,t)=>{let o=Eo(t,`${e}.mdx`);await p(o)};import{resolve as Mo}from"node:path";var Dt=async(e,t)=>{let o=Mo(t,`${e}.service.ts`);await p(o)};var Et=async(e,t,o)=>{if(!await K()){let i="\u5F53\u524D\u9879\u76EE\u4E0D\u662F x \u9879\u76EE";throw a.warn(i),new Error(i)}let r=!o&&["component","directive","pipe"].includes(e),n=_(process.cwd(),o??"");await Io[e](t,n,r)},Io={component:async(e,t,o)=>{await j(o,async(r,n)=>{await we(e,_(`${r}/src/lib/components`),{needExport:!0}),await Pt(e,_(`${n}/src/components`))},async()=>{await we(e,t,{needExport:!1})})},directive:async(e,t,o)=>{await j(o,async(r,n)=>{await ve(e,_(`${r}/src/lib/directives`)),await At(e,_(`${n}/src/directives`))},async()=>{await ve(e,t)})},pipe:async(e,t,o)=>{await j(o,async(r,n)=>{await he(e,_(`${r}/src/lib/pipes`)),await bt(e,_(`${n}/src/pipes`))},async()=>{await he(e,t)})},service:async(e,t)=>{await Dt(e,t)},doc:async(e,t)=>{await kt(e,t)}};import{resolve as To}from"node:path";var jo="1.0.1";b.version(jo).description("A cli for any create standard project.").allowUnknownOption().on("command:*",e=>{a.error(`Invalid command: ${e}`),process.exit(1)}).on("--help",()=>{console.log(je),process.exit(0)});b.command("init").description("Initialize cli dependencies").action(()=>{a.info("Initializing cli dependencies"),Se().then(()=>{a.info("Initialized cli dependencies"),process.exit(0)}).catch(()=>process.exit(1))});b.command("new <projectName>").description("Initialize a new project").action(e=>{a.info(`Initializing new project: ${e}`),ft(e).then(()=>{a.info(`Initialized new project: ${e}.`),process.exit(0)}).catch(()=>process.exit(1))});b.command("create <type> <name>").option("-d,--directory [directory]","Specify a directory").option("-b,--bind [bind]","Create with binding.").description("Create a new component, directive, pipe, service, or documentation").action((e,t,{directory:o,bind:r})=>{a.info(`Creating ${e} named ${t} ${o?"in "+o:""}`),Ct(e,t,o,r).then(()=>{a.info(`Created ${e} named ${t}.`),process.exit(0)}).catch(()=>{process.exit(1)})});b.command("remove <type> <name>").option("-d,--directory [directory]","Specify a directory").description("Remove an existing component, directive, pipe, service, or documentation").action((e,t,{directory:o})=>{a.info(`Removing ${e} named ${t}`,o),Et(e,t,o).then(()=>{a.info(`Removed ${e} named ${t}.`),process.exit(0)}).catch(()=>{process.exit(1)})});b.command("plugin <install|uninstall|list> [pluginName]").description("Manage plugins by adding, removing, or listing them").action((e,t)=>{ot(e,t).then(()=>{a.info(`The ${t??"plugins"} has been ${e}ed.`),process.exit(0)}).catch(()=>process.exit(1))});b.command("update").description("Update x-cli to lts.").action(()=>{a.info("Updating..."),nt().then(()=>{a.info("Updated."),process.exit(0)}).catch(()=>{process.exit(1)})});b.command("doc").description("Display the documentation.").action(()=>{a.off(),U(To(M,"readme.md")).then(e=>{a.on(),console.info(e),process.exit(0)}).catch(()=>process.exit(1))});b.parse(process.argv); | ||
},`;var At=async(e,t,o,r)=>{if(!await Q()){let s="\u5F53\u524D\u9879\u76EE\u4E0D\u662F x \u9879\u76EE";throw a.warn(s),new Error(s)}let i=!o&&["component","directive","pipe"].includes(e),n=_(process.cwd(),o??"");await Mo[e](t,n,i,r)},Mo={component:async(e,t,o,r)=>{await S(o,async(i,n)=>{await ce(e,_(`${i}/src/lib/components`),{bind:r,needExport:!0}),await vt(e,_(`${n}/src/components`))},async()=>{await ce(e,t,{bind:r,needExport:!1})})},directive:async(e,t,o,r)=>{await S(o,async(i,n)=>{await ue(e,_(`${i}/src/lib/directives`),{bind:r,needExport:!0}),await Pt(e,_(`${n}/src/directives`))},async()=>{await ue(e,t,{bind:r,needExport:!1})})},pipe:async(e,t,o,r)=>{await S(o,async(i,n)=>{await xe(e,_(`${i}/src/lib/pipes`),{bind:r,needExport:!0}),await bt(e,_(`${n}/src/pipes`))},async()=>{await xe(e,t,{bind:r,needExport:!1})})},service:async(e,t,o,r)=>{await ht(e,t,{bind:r})},doc:async(e,t,o,r)=>{await $t(e,t,{bind:r})}},S=async(e,t,o)=>{if(e){let r=await d(),[i]=H(r,"component"),[n]=H(r,"demo");await Ct(),await t?.(i,n)}else await o()};import{resolve as R}from"node:path";import{resolve as te}from"node:path";var he=async(e,t,{needExport:o=!1}={})=>{let{prefix:r}=await d(),i={name:e,prefix:r},n=te(t,e),s=te(t,"index.ts");await J(n),await u(s,` | ||
`+c(pe,i),"")},kt=async(e,t)=>{let{prefix:o,name:r}=await d(),i=te(t,e),n=te(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await J(i),await u(n,c(me,s),""),await u(n,c(le,s),"")};import{resolve as oe}from"node:path";var $e=async(e,t)=>{let{prefix:o}=await d(),r={name:e,prefix:o},i=oe(t,`${e}.directive.ts`),n=oe(t,"index.ts");await p(i),await u(n,` | ||
`+c(fe,r),"")},Dt=async(e,t)=>{let{prefix:o,name:r}=await d(),i=oe(t,`${e}.directive.ts`),n=oe(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await p(i),await u(n,c(de,s),""),await u(n,c(ge,s),"")};import{resolve as re}from"node:path";var Ce=async(e,t)=>{let{prefix:o}=await d(),r={name:e,prefix:o},i=re(t,`${e}.pipe.ts`),n=re(t,"index.ts");await p(i),await u(n,` | ||
`+c(ye,r),"")},Tt=async(e,t)=>{let{prefix:o,name:r}=await d(),i=re(t,`${e}.pipe.ts`),n=re(t,"../app","app.routes.ts"),s={name:e,project:r,prefix:o};await p(i),await u(n,c(we,s),""),await u(n,c(ve,s),"")};import{resolve as Eo}from"node:path";var It=async(e,t)=>{let o=Eo(t,`${e}.mdx`);await p(o)};import{resolve as jo}from"node:path";var Mt=async(e,t)=>{let o=jo(t,`${e}.service.ts`);await p(o)};var Et=async(e,t,o)=>{if(!await Q()){let n="\u5F53\u524D\u9879\u76EE\u4E0D\u662F x \u9879\u76EE";throw a.warn(n),new Error(n)}let r=!o&&["component","directive","pipe"].includes(e),i=R(process.cwd(),o??"");await _o[e](t,i,r)},_o={component:async(e,t,o)=>{await S(o,async(r,i)=>{await he(e,R(`${r}/src/lib/components`),{needExport:!0}),await kt(e,R(`${i}/src/components`))},async()=>{await he(e,t,{needExport:!1})})},directive:async(e,t,o)=>{await S(o,async(r,i)=>{await $e(e,R(`${r}/src/lib/directives`)),await Dt(e,R(`${i}/src/directives`))},async()=>{await $e(e,t)})},pipe:async(e,t,o)=>{await S(o,async(r,i)=>{await Ce(e,R(`${r}/src/lib/pipes`)),await Tt(e,R(`${i}/src/pipes`))},async()=>{await Ce(e,t)})},service:async(e,t)=>{await Mt(e,t)},doc:async(e,t)=>{await It(e,t)}};import{resolve as So}from"node:path";var Ro="1.0.2";k.version(Ro).description("A cli for any create standard project.").allowUnknownOption().on("command:*",e=>{a.error(`Invalid command: ${e}`),process.exit(1)}).on("--help",()=>{console.log(_e),process.exit(0)});k.command("init").description("Initialize cli dependencies").action(()=>{a.info("Initializing cli dependencies"),Fe().then(()=>{a.info("Initialized cli dependencies"),process.exit(0)}).catch(()=>process.exit(1))});k.command("new <projectName>").description("Initialize a new project").action(e=>{a.info(`Initializing new project: ${e}`),xt(e).then(()=>{a.info(`Initialized new project: ${e}.`),process.exit(0)}).catch(()=>process.exit(1))});k.command("create <type> <name>").option("-d,--directory [directory]","Specify a directory").option("-b,--bind [bind]","Create with binding.").description("Create a new component, directive, pipe, service, or documentation").action((e,t,{directory:o,bind:r})=>{a.info(`Creating ${e} named ${t} ${o?"in "+o:""}`),At(e,t,o,r).then(()=>{a.info(`Created ${e} named ${t}.`),process.exit(0)}).catch(()=>{process.exit(1)})});k.command("remove <type> <name>").option("-d,--directory [directory]","Specify a directory").description("Remove an existing component, directive, pipe, service, or documentation").action((e,t,{directory:o})=>{a.info(`Removing ${e} named ${t}`,o),Et(e,t,o).then(()=>{a.info(`Removed ${e} named ${t}.`),process.exit(0)}).catch(()=>{process.exit(1)})});k.command("plugin <install|uninstall|list> [pluginName]").description("Manage plugins by adding, removing, or listing them").action((e,t)=>{rt(e,t).then(()=>{a.info(`The ${t??"plugins"} has been ${e}ed.`),process.exit(0)}).catch(()=>process.exit(1))});k.command("update").description("Update x-cli to lts.").action(()=>{a.info("Updating..."),it().then(()=>{a.info("Updated."),process.exit(0)}).catch(()=>{process.exit(1)})});k.command("doc").description("Display the documentation.").action(()=>{a.off(),z(So(j,"readme.md")).then(e=>{a.on(),console.info(e),process.exit(0)}).catch(()=>process.exit(1))});k.parse(process.argv); |
#!/usr/bin/env node | ||
import{program as H}from"commander";var c=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as q,spawn as J}from"child_process";import y from"chalk";var x=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var f=(...e)=>{let r=0;return e.reduce((t,[n,a])=>{let o=typeof a=="number"?r=a&&r++:a??r++;return t[n]=o,t[o]=n,t},{})};var g=class{_TypeBg=f(["info","bgBlueBright"],["warn","bgYellow"],["error","bgRedBright"]);_logo=r=>y.bgBlueBright(y[this._TypeBg[r]](` x-cli => ${r} `));isOn=!0;constructor(r){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...r){this.forbidden||console.log(this._logo("info"),...r)}warn(...r){this.forbidden||console.log(this._logo("warn"),...r)}error(...r){this.forbidden||console.log(this._logo("error"),...r)}},s=new g(x());import X from"ora";var w=e=>{let r=X(e),t=setTimeout(()=>{r.start()},1500);return{stop:()=>{clearTimeout(t),r.stop()},text:n=>{r.text=n},succeed:n=>{clearTimeout(t),r.succeed(` ${n}`)},fail:n=>{clearTimeout(t),r.fail(` ${n}`)},warn:n=>{clearTimeout(t),r.warn(` ${n}`)},info:n=>{clearTimeout(t),r.info(` ${n}`)}}};var l=e=>{if(!e)return Promise.reject("Not a standard command.");s.info(e);let r=w(e);return new Promise(t=>{q(e,(n,a,o)=>{n&&t(!1),t(a)})}).finally(()=>r.stop())},m=e=>e?(s.info(e),new Promise((r,t)=>{let[n,...a]=e.split(/\s+/).filter(i=>i);J(n,a,{stdio:"inherit",shell:!0}).on("close",i=>{i===0?r(!0):t(i)})})):Promise.reject("Not a standard command.");var $=(e,r=!1,t=!1,n={})=>{let a="pnpm",o="add";r?o="add --save-dev":t&&(o="add --global"),e||(o="install");let i=`${a} ${o} ${c(e)} ${Object.entries(n).map(([p,V])=>`--${p}=${V}`).join(" ")}`;return l(i)},h=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"pnpm remove -g":"pnpm remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},j=(e,r={})=>{let t=`pnpm ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},v=e=>m(`pnpx -y ${e}`);var u=(e,r=!1,t=!1,n={})=>{let a="npm",o="install";r?o="install --save-dev":t?(a="npm",o="install -g"):a="npm";let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},b=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"npm uninstall -g":"npm uninstall"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},k=(e,r={})=>{let t=`npm run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},d=async(e,r=!1)=>{let t=`npm list ${c(e)} ${r?"-g":""} --depth=0`;s.off();let n=await l(`${t} | grep ${e}`);return s.on(),typeof n=="boolean"?n:n.toString()?.trim()?.includes(e)},I=e=>m(`npx -y ${e} `);var C=(e,r=!1,t=!1,n={})=>{let a="yarn",o="add";r?o="add --dev":t?(a="yarn global",o="add"):a="yarn",e||(o="");let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},N=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"yarn global remove":"yarn remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},T=(e,r={})=>{let t=`yarn run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},L=e=>m(`yarn create -y ${e}`);import{dirname as Y,sep as O}from"path";import{readdir as W}from"node:fs/promises";var M=async()=>{let e=process.cwd();try{for(;e!==O&&!(await W(e)).includes(".xrc");)e=Y(e);return e===O&&new Error("Not in a x project."),e}catch(r){throw s.error(r),r}};import{mkdir as Be,writeFile as Pe,readFile as z,appendFile as De}from"node:fs/promises";var S=async e=>(s.info(`loading file:${e}`),await z(e,"utf-8"));var F=async e=>{if(!e)return s.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let r=await S(e);return JSON.parse(r)};import{resolve as K}from"node:path";var _=async()=>{try{let e=await M();return await F(K(e,".xrc"))}catch{return{}}};import{readdir as Q}from"node:fs/promises";import{resolve as Z}from"node:path";var R="npm",B=["package-lock.json","pnpm-lock.yaml","yarn.lock"],P=f(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var D=e=>{switch(e){case"pnpm":return{has:d,install:$,uninstall:h,run:j,npx:v};case"yarn":return{has:d,install:C,uninstall:N,run:T,npx:L};case"npm":default:return{has:d,install:u,uninstall:b,run:k,npx:I}}},G=async()=>{try{let e=await _(),{packageManager:r}=e;return r}catch{return}},ee=async()=>{let r=(await Q(Z("."))).filter(t=>B.includes(t));if(r.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[t="package-lock.json"]=r;return P[t]}},A=async()=>{let e=await G();return e||await ee()};var E=async e=>{let r;try{s.off(),r=await A(),s.on()}catch{r=R}finally{await e?.(D(r))}};var U=async(e,r,t)=>{await E(async({has:n,install:a})=>{if(e)if(await n(e)){let o=`${e} has been installed.`;s.warn(o)}else await a(e,r,t);else await a()})};var re="1.0.1";H.version(re).arguments("[packageName]").option("-D,--save-dev","Save as development dependency").option("-g,--global","Save as global dependency").description("Install or uninstall a dependency in the project.").action((e,{saveDev:r,global:t})=>{U(e,r,t).then(()=>{s.info(`The ${e??"packages"} has been installed successfully.`),process.exit(0)}).catch(()=>process.exit(1))});H.parse(process.argv); | ||
import{program as X}from"commander";var l=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as q,spawn as J}from"child_process";import g from"chalk";var y=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var f=(...e)=>{let r=0;return e.reduce((t,[n,a])=>{let o=typeof a=="number"?r=a&&r++:a??r++;return t[n]=o,t[o]=n,t},{})};var x=class{_TypeBg=f(["info","bgBlue"],["warn","bgYellow"],["error","bgRedBright"]);_logo=r=>g.bgBlueBright(g.whiteBright(" X-CLI "))+g[this._TypeBg[r]](` ${r.toUpperCase()} `);isOn=!0;constructor(r){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...r){this.forbidden||console.log(this._logo("info"),...r)}warn(...r){this.forbidden||console.log(this._logo("warn"),...r)}error(...r){this.forbidden||console.log(this._logo("error"),...r)}},s=new x(y());import V from"ora";var w=e=>{let r=V(e),t=setTimeout(()=>{r.start()},1500);return{stop:()=>{clearTimeout(t),r.stop()},text:n=>{r.text=n},succeed:n=>{clearTimeout(t),r.succeed(` ${n}`)},fail:n=>{clearTimeout(t),r.fail(` ${n}`)},warn:n=>{clearTimeout(t),r.warn(` ${n}`)},info:n=>{clearTimeout(t),r.info(` ${n}`)}}};var c=e=>{if(!e)return Promise.reject("Not a standard command.");s.info(e);let r=w(e);return new Promise(t=>{q(e,(n,a,o)=>{n&&t(!1),t(a)})}).finally(()=>r.stop())},m=e=>e?(s.info(e),new Promise((r,t)=>{let[n,...a]=e.split(/\s+/).filter(i=>i);J(n,a,{stdio:"inherit",shell:!0}).on("close",i=>{i===0?r(!0):t(i)})})):Promise.reject("Not a standard command.");var $=(e,r=!1,t=!1,n={})=>{let a="pnpm",o="add";r?o="add --save-dev":t&&(o="add --global"),e||(o="install");let i=`${a} ${o} ${l(e)} ${Object.entries(n).map(([p,H])=>`--${p}=${H}`).join(" ")}`;return c(i)},h=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"pnpm remove -g":"pnpm remove"} ${l(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return c(a)},j=(e,r={})=>{let t=`pnpm ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},v=e=>m(`pnpx -y ${e}`);var u=(e,r=!1,t=!1,n={})=>{let a="npm",o="install";r?o="install --save-dev":t?(a="npm",o="install -g"):a="npm";let i=`${a} ${o} ${l(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return c(i)},b=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"npm uninstall -g":"npm uninstall"} ${l(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return c(a)},k=(e,r={})=>{let t=`npm run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},d=async(e,r=!1)=>{let t=`npm list ${l(e)} ${r?"-g":""} --depth=0`;s.off();let n=await c(`${t} | grep ${e}`);return s.on(),typeof n=="boolean"?n:n.toString()?.trim()?.includes(e)},C=e=>m(`npx -y ${e} `);var I=(e,r=!1,t=!1,n={})=>{let a="yarn",o="add";r?o="add --dev":t?(a="yarn global",o="add"):a="yarn",e||(o="");let i=`${a} ${o} ${l(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return c(i)},N=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"yarn global remove":"yarn remove"} ${l(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return c(a)},L=(e,r={})=>{let t=`yarn run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},T=e=>m(`yarn create -y ${e}`);import{dirname as Y,sep as O}from"path";import{readdir as W}from"node:fs/promises";var M=async()=>{let e=process.cwd();try{for(;e!==O&&!(await W(e)).includes(".xrc");)e=Y(e);return e===O&&new Error("Not in a x project."),e}catch(r){throw s.error(r),r}};import{mkdir as Re,writeFile as Ae,readFile as z,appendFile as Pe}from"node:fs/promises";var S=async e=>(s.info(`loading file:${e}`),await z(e,"utf-8"));var F=async e=>{if(!e)return s.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let r=await S(e);return JSON.parse(r)};import{resolve as K}from"node:path";var _=async()=>{try{let e=await M();return await F(K(e,".xrc"))}catch{return{}}};import{readdir as Q}from"node:fs/promises";import{resolve as Z}from"node:path";var B="npm",R=["package-lock.json","pnpm-lock.yaml","yarn.lock"],A=f(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var P=e=>{switch(e){case"pnpm":return{has:d,install:$,uninstall:h,run:j,npx:v};case"yarn":return{has:d,install:I,uninstall:N,run:L,npx:T};case"npm":default:return{has:d,install:u,uninstall:b,run:k,npx:C}}},G=async()=>{try{let e=await _(),{packageManager:r}=e;return r}catch{return}},ee=async()=>{let r=(await Q(Z("."))).filter(t=>R.includes(t));if(r.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[t="package-lock.json"]=r;return A[t]}},D=async()=>{let e=await G();return e||await ee()};var U=async e=>{let r;try{s.off(),r=await D(),s.on()}catch{r=B}finally{await e?.(P(r))}};var E=async(e,r,t)=>{await U(async({has:n,install:a})=>{e?await a(e,r,t):await a()})};var re="1.0.2";X.version(re).arguments("[packageName]").option("-D,--save-dev","Save as development dependency").option("-g,--global","Save as global dependency").description("Install or uninstall a dependency in the project.").action((e,{saveDev:r,global:t})=>{E(e,r,t).then(()=>{s.info(`The ${e??"packages"} has been installed successfully.`),process.exit(0)}).catch(()=>process.exit(1))});X.parse(process.argv); |
#!/usr/bin/env node | ||
import{program as X}from"commander";import y from"chalk";var x=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var f=(...e)=>{let r=0;return e.reduce((t,[n,a])=>{let o=typeof a=="number"?r=a&&r++:a??r++;return t[n]=o,t[o]=n,t},{})};var g=class{_TypeBg=f(["info","bgBlueBright"],["warn","bgYellow"],["error","bgRedBright"]);_logo=r=>y.bgBlueBright(y[this._TypeBg[r]](` x-cli => ${r} `));isOn=!0;constructor(r){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...r){this.forbidden||console.log(this._logo("info"),...r)}warn(...r){this.forbidden||console.log(this._logo("warn"),...r)}error(...r){this.forbidden||console.log(this._logo("error"),...r)}},s=new g(x());var c=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as q,spawn as J}from"child_process";import V from"ora";var w=e=>{let r=V(e),t=setTimeout(()=>{r.start()},1500);return{stop:()=>{clearTimeout(t),r.stop()},text:n=>{r.text=n},succeed:n=>{clearTimeout(t),r.succeed(` ${n}`)},fail:n=>{clearTimeout(t),r.fail(` ${n}`)},warn:n=>{clearTimeout(t),r.warn(` ${n}`)},info:n=>{clearTimeout(t),r.info(` ${n}`)}}};var l=e=>{if(!e)return Promise.reject("Not a standard command.");s.info(e);let r=w(e);return new Promise(t=>{q(e,(n,a,o)=>{n&&t(!1),t(a)})}).finally(()=>r.stop())},m=e=>e?(s.info(e),new Promise((r,t)=>{let[n,...a]=e.split(/\s+/).filter(i=>i);J(n,a,{stdio:"inherit",shell:!0}).on("close",i=>{i===0?r(!0):t(i)})})):Promise.reject("Not a standard command.");var $=(e,r=!1,t=!1,n={})=>{let a="pnpm",o="add";r?o="add --save-dev":t&&(o="add --global"),e||(o="install");let i=`${a} ${o} ${c(e)} ${Object.entries(n).map(([p,H])=>`--${p}=${H}`).join(" ")}`;return l(i)},h=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"pnpm remove -g":"pnpm remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},j=(e,r={})=>{let t=`pnpm ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},b=e=>m(`pnpx -y ${e}`);var u=(e,r=!1,t=!1,n={})=>{let a="npm",o="install";r?o="install --save-dev":t?(a="npm",o="install -g"):a="npm";let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},v=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"npm uninstall -g":"npm uninstall"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},k=(e,r={})=>{let t=`npm run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},d=async(e,r=!1)=>{let t=`npm list ${c(e)} ${r?"-g":""} --depth=0`;s.off();let n=await l(`${t} | grep ${e}`);return s.on(),typeof n=="boolean"?n:n.toString()?.trim()?.includes(e)},N=e=>m(`npx -y ${e} `);var C=(e,r=!1,t=!1,n={})=>{let a="yarn",o="add";r?o="add --dev":t?(a="yarn global",o="add"):a="yarn",e||(o="");let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},I=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"yarn global remove":"yarn remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},T=(e,r={})=>{let t=`yarn run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},L=e=>m(`yarn create -y ${e}`);import{dirname as Y,sep as O}from"path";import{readdir as W}from"node:fs/promises";var M=async()=>{let e=process.cwd();try{for(;e!==O&&!(await W(e)).includes(".xrc");)e=Y(e);return e===O&&new Error("Not in a x project."),e}catch(r){throw s.error(r),r}};import{mkdir as Pe,writeFile as Be,readFile as z,appendFile as Ae}from"node:fs/promises";var F=async e=>(s.info(`loading file:${e}`),await z(e,"utf-8"));var R=async e=>{if(!e)return s.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let r=await F(e);return JSON.parse(r)};import{resolve as K}from"node:path";var S=async()=>{try{let e=await M();return await R(K(e,".xrc"))}catch{return{}}};import{readdir as Q}from"node:fs/promises";import{resolve as Z}from"node:path";var _="npm",P=["package-lock.json","pnpm-lock.yaml","yarn.lock"],B=f(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var A=e=>{switch(e){case"pnpm":return{has:d,install:$,uninstall:h,run:j,npx:b};case"yarn":return{has:d,install:C,uninstall:I,run:T,npx:L};case"npm":default:return{has:d,install:u,uninstall:v,run:k,npx:N}}},G=async()=>{try{let e=await S(),{packageManager:r}=e;return r}catch{return}},ee=async()=>{let r=(await Q(Z("."))).filter(t=>P.includes(t));if(r.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[t="package-lock.json"]=r;return B[t]}},D=async()=>{let e=await G();return e||await ee()};var E=async e=>{let r;try{s.off(),r=await D(),s.on()}catch{r=_}finally{await e?.(A(r))}};var U=async e=>{if(!e){let r="[X] Please enter the script name.";throw s.warn(r),new Error(r)}await E(async({run:r})=>{await r(e)})};var re="1.0.1";X.version(re).arguments("[script]").description("Run the specified script by correctly.").action(e=>{s.info(`The script ${e} is running...`),U(e).then(()=>{s.info(`The ${e} has been executed successfully.`),process.exit(0)}).catch(()=>{process.exit(1)})});X.parse(process.argv); | ||
import{program as y}from"commander";import g from"chalk";var w=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var f=(...e)=>{let r=0;return e.reduce((t,[n,a])=>{let o=typeof a=="number"?r=a&&r++:a??r++;return t[n]=o,t[o]=n,t},{})};var x=class{_TypeBg=f(["info","bgBlue"],["warn","bgYellow"],["error","bgRedBright"]);_logo=r=>g.bgBlueBright(g.whiteBright(" X-CLI "))+g[this._TypeBg[r]](` ${r.toUpperCase()} `);isOn=!0;constructor(r){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...r){this.forbidden||console.log(this._logo("info"),...r)}warn(...r){this.forbidden||console.log(this._logo("warn"),...r)}error(...r){this.forbidden||console.log(this._logo("error"),...r)}},s=new x(w());var c=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as q,spawn as J}from"child_process";import V from"ora";var $=e=>{let r=V(e),t=setTimeout(()=>{r.start()},1500);return{stop:()=>{clearTimeout(t),r.stop()},text:n=>{r.text=n},succeed:n=>{clearTimeout(t),r.succeed(` ${n}`)},fail:n=>{clearTimeout(t),r.fail(` ${n}`)},warn:n=>{clearTimeout(t),r.warn(` ${n}`)},info:n=>{clearTimeout(t),r.info(` ${n}`)}}};var l=e=>{if(!e)return Promise.reject("Not a standard command.");s.info(e);let r=$(e);return new Promise(t=>{q(e,(n,a,o)=>{n&&t(!1),t(a)})}).finally(()=>r.stop())},m=e=>e?(s.info(e),new Promise((r,t)=>{let[n,...a]=e.split(/\s+/).filter(i=>i);J(n,a,{stdio:"inherit",shell:!0}).on("close",i=>{i===0?r(!0):t(i)})})):Promise.reject("Not a standard command.");var h=(e,r=!1,t=!1,n={})=>{let a="pnpm",o="add";r?o="add --save-dev":t&&(o="add --global"),e||(o="install");let i=`${a} ${o} ${c(e)} ${Object.entries(n).map(([p,H])=>`--${p}=${H}`).join(" ")}`;return l(i)},j=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"pnpm remove -g":"pnpm remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},b=(e,r={})=>{let t=`pnpm ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},v=e=>m(`pnpx -y ${e}`);var u=(e,r=!1,t=!1,n={})=>{let a="npm",o="install";r?o="install --save-dev":t?(a="npm",o="install -g"):a="npm";let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},k=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"npm uninstall -g":"npm uninstall"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},C=(e,r={})=>{let t=`npm run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},d=async(e,r=!1)=>{let t=`npm list ${c(e)} ${r?"-g":""} --depth=0`;s.off();let n=await l(`${t} | grep ${e}`);return s.on(),typeof n=="boolean"?n:n.toString()?.trim()?.includes(e)},N=e=>m(`npx -y ${e} `);var I=(e,r=!1,t=!1,n={})=>{let a="yarn",o="add";r?o="add --dev":t?(a="yarn global",o="add"):a="yarn",e||(o="");let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},O=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"yarn global remove":"yarn remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},T=(e,r={})=>{let t=`yarn run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},L=e=>m(`yarn create -y ${e}`);import{dirname as Y,sep as M}from"path";import{readdir as W}from"node:fs/promises";var F=async()=>{let e=process.cwd();try{for(;e!==M&&!(await W(e)).includes(".xrc");)e=Y(e);return e===M&&new Error("Not in a x project."),e}catch(r){throw s.error(r),r}};import{mkdir as Be,writeFile as Pe,readFile as z,appendFile as Ae}from"node:fs/promises";var R=async e=>(s.info(`loading file:${e}`),await z(e,"utf-8"));var S=async e=>{if(!e)return s.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let r=await R(e);return JSON.parse(r)};import{resolve as K}from"node:path";var _=async()=>{try{let e=await F();return await S(K(e,".xrc"))}catch{return{}}};import{readdir as Q}from"node:fs/promises";import{resolve as Z}from"node:path";var B="npm",P=["package-lock.json","pnpm-lock.yaml","yarn.lock"],A=f(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var U=e=>{switch(e){case"pnpm":return{has:d,install:h,uninstall:j,run:b,npx:v};case"yarn":return{has:d,install:I,uninstall:O,run:T,npx:L};case"npm":default:return{has:d,install:u,uninstall:k,run:C,npx:N}}},G=async()=>{try{let e=await _(),{packageManager:r}=e;return r}catch{return}},ee=async()=>{let r=(await Q(Z("."))).filter(t=>P.includes(t));if(r.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[t="package-lock.json"]=r;return A[t]}},D=async()=>{let e=await G();return e||await ee()};var E=async e=>{let r;try{s.off(),r=await D(),s.on()}catch{r=B}finally{await e?.(U(r))}};var X=async e=>{if(!e){let r="[X] Please enter the script name.";throw s.warn(r),new Error(r)}await E(async({run:r})=>{await r(e)})};var re="1.0.2";y.version(re).arguments("[script]").allowUnknownOption(!0).description("Run the specified script by correctly.").action(e=>{s.info(`The script ${e} is running...`);let r=y.args.slice(1).join(" "),t=`${e} ${r}`;X(t).then(()=>{s.info(`The ${e} has been executed successfully.`),process.exit(0)}).catch(()=>{process.exit(1)})});y.parse(process.argv); |
#!/usr/bin/env node | ||
import{program as q}from"commander";var c=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as X,spawn as J}from"child_process";import y from"chalk";var x=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var f=(...e)=>{let r=0;return e.reduce((t,[n,a])=>{let o=typeof a=="number"?r=a&&r++:a??r++;return t[n]=o,t[o]=n,t},{})};var g=class{_TypeBg=f(["info","bgBlueBright"],["warn","bgYellow"],["error","bgRedBright"]);_logo=r=>y.bgBlueBright(y[this._TypeBg[r]](` x-cli => ${r} `));isOn=!0;constructor(r){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...r){this.forbidden||console.log(this._logo("info"),...r)}warn(...r){this.forbidden||console.log(this._logo("warn"),...r)}error(...r){this.forbidden||console.log(this._logo("error"),...r)}},s=new g(x());import V from"ora";var w=e=>{let r=V(e),t=setTimeout(()=>{r.start()},1500);return{stop:()=>{clearTimeout(t),r.stop()},text:n=>{r.text=n},succeed:n=>{clearTimeout(t),r.succeed(` ${n}`)},fail:n=>{clearTimeout(t),r.fail(` ${n}`)},warn:n=>{clearTimeout(t),r.warn(` ${n}`)},info:n=>{clearTimeout(t),r.info(` ${n}`)}}};var l=e=>{if(!e)return Promise.reject("Not a standard command.");s.info(e);let r=w(e);return new Promise(t=>{X(e,(n,a,o)=>{n&&t(!1),t(a)})}).finally(()=>r.stop())},m=e=>e?(s.info(e),new Promise((r,t)=>{let[n,...a]=e.split(/\s+/).filter(i=>i);J(n,a,{stdio:"inherit",shell:!0}).on("close",i=>{i===0?r(!0):t(i)})})):Promise.reject("Not a standard command.");var $=(e,r=!1,t=!1,n={})=>{let a="pnpm",o="add";r?o="add --save-dev":t&&(o="add --global"),e||(o="install");let i=`${a} ${o} ${c(e)} ${Object.entries(n).map(([p,H])=>`--${p}=${H}`).join(" ")}`;return l(i)},h=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"pnpm remove -g":"pnpm remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},j=(e,r={})=>{let t=`pnpm ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},b=e=>m(`pnpx -y ${e}`);var u=(e,r=!1,t=!1,n={})=>{let a="npm",o="install";r?o="install --save-dev":t?(a="npm",o="install -g"):a="npm";let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},v=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"npm uninstall -g":"npm uninstall"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},k=(e,r={})=>{let t=`npm run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},d=async(e,r=!1)=>{let t=`npm list ${c(e)} ${r?"-g":""} --depth=0`;s.off();let n=await l(`${t} | grep ${e}`);return s.on(),typeof n=="boolean"?n:n.toString()?.trim()?.includes(e)},C=e=>m(`npx -y ${e} `);var I=(e,r=!1,t=!1,n={})=>{let a="yarn",o="add";r?o="add --dev":t?(a="yarn global",o="add"):a="yarn",e||(o="");let i=`${a} ${o} ${c(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return l(i)},N=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"yarn global remove":"yarn remove"} ${c(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return l(a)},T=(e,r={})=>{let t=`yarn run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},L=e=>m(`yarn create -y ${e}`);import{dirname as Y,sep as O}from"path";import{readdir as W}from"node:fs/promises";var M=async()=>{let e=process.cwd();try{for(;e!==O&&!(await W(e)).includes(".xrc");)e=Y(e);return e===O&&new Error("Not in a x project."),e}catch(r){throw s.error(r),r}};import{mkdir as Be,writeFile as Pe,readFile as z,appendFile as Ue}from"node:fs/promises";var F=async e=>(s.info(`loading file:${e}`),await z(e,"utf-8"));var R=async e=>{if(!e)return s.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let r=await F(e);return JSON.parse(r)};import{resolve as K}from"node:path";var S=async()=>{try{let e=await M();return await R(K(e,".xrc"))}catch{return{}}};import{readdir as Q}from"node:fs/promises";import{resolve as Z}from"node:path";var _="npm",B=["package-lock.json","pnpm-lock.yaml","yarn.lock"],P=f(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var U=e=>{switch(e){case"pnpm":return{has:d,install:$,uninstall:h,run:j,npx:b};case"yarn":return{has:d,install:I,uninstall:N,run:T,npx:L};case"npm":default:return{has:d,install:u,uninstall:v,run:k,npx:C}}},G=async()=>{try{let e=await S(),{packageManager:r}=e;return r}catch{return}},ee=async()=>{let r=(await Q(Z("."))).filter(t=>B.includes(t));if(r.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[t="package-lock.json"]=r;return P[t]}},A=async()=>{let e=await G();return e||await ee()};var D=async e=>{let r;try{s.off(),r=await A(),s.on()}catch{r=_}finally{await e?.(U(r))}};var E=async(e,r)=>{if(!e){let t="Require a packageName.";throw s.warn(t),new Error(t)}await D(async({has:t,uninstall:n})=>{e&&(await t(e)?await n(e,r):s.warn(`${e} not found`))})};var re="1.0.1";q.version(re).arguments("[packageName]").option("-g,--global","Uninstall the global dependency").description("Uninstall a dependency in the project.").action((e,{global:r})=>{E(e,r).then(()=>{s.info(`The ${e} has been uninstalled successfully.`),process.exit(0)}).catch(()=>process.exit(1))});q.parse(process.argv); | ||
import{program as X}from"commander";var l=e=>e?Array.isArray(e)?e.join(" "):e:"";import{exec as V,spawn as J}from"child_process";import g from"chalk";var y=()=>import.meta.url?.endsWith("env.js")?"dev":"prod";var f=(...e)=>{let r=0;return e.reduce((t,[n,a])=>{let o=typeof a=="number"?r=a&&r++:a??r++;return t[n]=o,t[o]=n,t},{})};var x=class{_TypeBg=f(["info","bgBlue"],["warn","bgYellow"],["error","bgRedBright"]);_logo=r=>g.bgBlueBright(g.whiteBright(" X-CLI "))+g[this._TypeBg[r]](` ${r.toUpperCase()} `);isOn=!0;constructor(r){}on(){this.isOn=!0}off(){this.isOn=!1}get forbidden(){return!this.isOn}info(...r){this.forbidden||console.log(this._logo("info"),...r)}warn(...r){this.forbidden||console.log(this._logo("warn"),...r)}error(...r){this.forbidden||console.log(this._logo("error"),...r)}},s=new x(y());import H from"ora";var w=e=>{let r=H(e),t=setTimeout(()=>{r.start()},1500);return{stop:()=>{clearTimeout(t),r.stop()},text:n=>{r.text=n},succeed:n=>{clearTimeout(t),r.succeed(` ${n}`)},fail:n=>{clearTimeout(t),r.fail(` ${n}`)},warn:n=>{clearTimeout(t),r.warn(` ${n}`)},info:n=>{clearTimeout(t),r.info(` ${n}`)}}};var c=e=>{if(!e)return Promise.reject("Not a standard command.");s.info(e);let r=w(e);return new Promise(t=>{V(e,(n,a,o)=>{n&&t(!1),t(a)})}).finally(()=>r.stop())},m=e=>e?(s.info(e),new Promise((r,t)=>{let[n,...a]=e.split(/\s+/).filter(i=>i);J(n,a,{stdio:"inherit",shell:!0}).on("close",i=>{i===0?r(!0):t(i)})})):Promise.reject("Not a standard command.");var $=(e,r=!1,t=!1,n={})=>{let a="pnpm",o="add";r?o="add --save-dev":t&&(o="add --global"),e||(o="install");let i=`${a} ${o} ${l(e)} ${Object.entries(n).map(([p,q])=>`--${p}=${q}`).join(" ")}`;return c(i)},h=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"pnpm remove -g":"pnpm remove"} ${l(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return c(a)},j=(e,r={})=>{let t=`pnpm ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},b=e=>m(`pnpx -y ${e}`);var u=(e,r=!1,t=!1,n={})=>{let a="npm",o="install";r?o="install --save-dev":t?(a="npm",o="install -g"):a="npm";let i=`${a} ${o} ${l(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return c(i)},v=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"npm uninstall -g":"npm uninstall"} ${l(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return c(a)},k=(e,r={})=>{let t=`npm run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},d=async(e,r=!1)=>{let t=`npm list ${l(e)} ${r?"-g":""} --depth=0`;s.off();let n=await c(`${t} | grep ${e}`);return s.on(),typeof n=="boolean"?n:n.toString()?.trim()?.includes(e)},C=e=>m(`npx -y ${e} `);var I=(e,r=!1,t=!1,n={})=>{let a="yarn",o="add";r?o="add --dev":t?(a="yarn global",o="add"):a="yarn",e||(o="");let i=`${a} ${o} ${l(e)} ${Object.keys(n).map(p=>`--${p}=${n[p]}`).join(" ")}`;return c(i)},N=(e,r=!1,t={})=>{if(!e)return Promise.reject("packageName is required");let a=`${r?"yarn global remove":"yarn remove"} ${l(e)} ${Object.keys(t).map(o=>`--${o}=${t[o]}`).join(" ")}`;return c(a)},L=(e,r={})=>{let t=`yarn run ${e} ${Object.keys(r).map(n=>`--${n}=${r[n]}`).join(" ")}`;return m(t)},T=e=>m(`yarn create -y ${e}`);import{dirname as Y,sep as O}from"path";import{readdir as W}from"node:fs/promises";var M=async()=>{let e=process.cwd();try{for(;e!==O&&!(await W(e)).includes(".xrc");)e=Y(e);return e===O&&new Error("Not in a x project."),e}catch(r){throw s.error(r),r}};import{mkdir as Be,writeFile as Ae,readFile as z,appendFile as Pe}from"node:fs/promises";var F=async e=>(s.info(`loading file:${e}`),await z(e,"utf-8"));var R=async e=>{if(!e)return s.warn("\u8BF7\u8F93\u5165\u6587\u4EF6\u540D"),null;let r=await F(e);return JSON.parse(r)};import{resolve as K}from"node:path";var S=async()=>{try{let e=await M();return await R(K(e,".xrc"))}catch{return{}}};import{readdir as Q}from"node:fs/promises";import{resolve as Z}from"node:path";var _="npm",B=["package-lock.json","pnpm-lock.yaml","yarn.lock"],A=f(["npm","package-lock.json"],["pnpm","pnpm-lock.yaml"],["yarn","yarn.lock"]);var P=e=>{switch(e){case"pnpm":return{has:d,install:$,uninstall:h,run:j,npx:b};case"yarn":return{has:d,install:I,uninstall:N,run:L,npx:T};case"npm":default:return{has:d,install:u,uninstall:v,run:k,npx:C}}},G=async()=>{try{let e=await S(),{packageManager:r}=e;return r}catch{return}},ee=async()=>{let r=(await Q(Z("."))).filter(t=>B.includes(t));if(r.length>1)throw new Error("There are multiple lock files in the project, please remove one of them");{let[t="package-lock.json"]=r;return A[t]}},U=async()=>{let e=await G();return e||await ee()};var D=async e=>{let r;try{s.off(),r=await U(),s.on()}catch{r=_}finally{await e?.(P(r))}};var E=async(e,r)=>{if(!e){let t="Require a packageName.";throw s.warn(t),new Error(t)}await D(async({has:t,uninstall:n})=>{e&&await n(e,r)})};var re="1.0.2";X.version(re).arguments("[packageName]").option("-g,--global","Uninstall the global dependency").description("Uninstall a dependency in the project.").action((e,{global:r})=>{E(e,r).then(()=>{s.info(`The ${e} has been uninstalled successfully.`),process.exit(0)}).catch(()=>process.exit(1))});X.parse(process.argv); |
@@ -1,1 +0,1 @@ | ||
{"name":"@eternalheart/x-cli","version":"1.0.1","type":"module","description":"A cli for project to create all needed.","bin":{"x":"bin/x.js","xi":"bin/xi.js","xu":"bin/xu.js","xr":"bin/xr.js"},"publishConfig":{"access":"public"},"author":"EternalHeart","license":"ISC","dependencies":{"chalk":"^5.3.0","commander":"^12.0.0","inquirer":"^9.2.17","ora":"^8.0.1"}} | ||
{"name":"@eternalheart/x-cli","version":"1.0.2","type":"module","description":"A cli for project to create all needed.","bin":{"x":"bin/x.js","xi":"bin/xi.js","xu":"bin/xu.js","xr":"bin/xr.js"},"publishConfig":{"access":"public"},"author":"EternalHeart","license":"ISC","dependencies":{"chalk":"^5.3.0","commander":"^12.0.0","d":"^1.0.2","inquirer":"^9.2.17","ora":"^8.0.1"}} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
50828
384
5
6
+ Addedd@^1.0.2
+ Addedd@1.0.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedtype@2.7.3(transitive)