@empjs/cli 3.0.0-alpha.23 → 3.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,6 +4,6 @@ var $e=Object.defineProperty;var p=(o,e)=>()=>(o&&(e=o(o=0)),e);var k=(o,e)=>{fo
4
4
  `)};green=e=>{console.log(`${m.white.bgGreen(this.pname)}${m.green.bgWhite(` ${e} `)}
5
5
  `)};yellow=e=>{console.log(`${m.white.bgYellow(this.pname)}${m.yellow.bgWhite(` ${e} `)}
6
6
  `)};red=e=>{console.log(`${m.white.bgRed(this.pname)}${m.red.bgWhite(` ${e} `)}
7
- `)};link=e=>m.hex("#3498db")(e);tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(e){this.tableData.push(e)}tableOutput(){console.log(Ge(this.tableData,this.tableConfig))}},a=new F});import Me from"node:fs";var L,ie,ne=p(()=>{"use strict";L=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},{...e,...t}}async setup(e){this.store=e,await this.syncEmpOptions();let{appSrc:t,base:s,appEntry:r}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),r&&(this.appEntry=r)}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&await Promise.all(this.store.empOptions.plugins)}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!1,showRsconfig:!1},this.store.empOptions.debug)}get build(){return this.assign({outDir:"dist",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev},this.store.empOptions.build)}get html(){return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,meta:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"}},files:{css:[],js:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){return this.assign({host:"0.0.0.0",port:8e3,open:!1,hot:!0,allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}},this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js"},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!Me.existsSync(e))return;let{default:t}=await import(e);typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let e={and:[/(node_modules|bower_components)/]},{moduleTransform:t}=this.store.empOptions;return t?.exclude&&(e.and=t.exclude),t?.include&&(e.not=t.include),e}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}},ie=new L});var A,ae,pe=p(()=>{"use strict";A=class{js(e){let{isDev:t}=e,s={test:/\.(jsx?|tsx?)$/,use:[{loader:"builtin:swc-loader",options:{sourceMap:!0,jsc:{parser:{syntax:"typescript",tsx:!0},transform:{react:{runtime:"automatic",development:t,refresh:t}}}}}]};e.rsConfig.module?.rules?.push(s)}},ae=new A});var G,le,ce=p(()=>{"use strict";pe();G=class{async afterChain(e){ae.js(e)}},le=new G});import g from"node:path";import He from"webpack-chain";var M,i,u=p(()=>{"use strict";J();re();v();ne();ce();M=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=import.meta.resolve("@empjs/cli").replace("/dist/index.js","").replace("file://","");empSource=g.resolve(this.empRoot,"dist");resolve=e=>g.isAbsolute(e)?e:g.resolve(this.root,e);empResolve=e=>g.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(e,t){await this.initVars(e,t),this.empConfig=ie,await this.empConfig.setup(this),this.initPaths(),this.chain=new He,await oe.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(e,t){this.cliOptions=t||{},this.cliMode="prod",this.mode=e==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await P(this.empResolve("package.json")),r=await P(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...r},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=g.join(this.empRoot,"resource"),this.resource.cert=g.join(this.resource.dir,"emp.cert"),this.resource.key=g.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),a.setup({pname:` EMP v${this.empPkg.version} ${this.cliMode==="dev"?"DEV ":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e){return import.meta.resolve(e).replace("file://","")}toConfig(){this.rsConfig=this.chain.toConfig(),le.afterChain(this)}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},i=new M});function me(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}var he=p(()=>{"use strict"});import ue from"node:fs/promises";var f,S=p(()=>{"use strict";v();u();he();f=class{async setup(e,t){await i.setup(e,t),i.empConfig.debug.clearLog&&me(),a.blue(`${e} Running`),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=i.rsConfig.devServer||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([ue.readFile(i.resource.key),ue.readFile(i.resource.cert)])}}});import Ne from"net";import Ie from"os";async function E(o,e="localhost"){if(o!==Ue&&(o<fe||o>H))throw new Error(`Port number must lie between ${fe} and ${H}`);let t=o,s=Be(),r;e&&!s.has(e)?r=new Set([e]):r=s;let n=new Set(["EADDRINUSE","EACCES"]);for(;t<=H;)try{return await _e(t,r)}catch(c){if(!n.has(c.code))throw c;t+=1}throw new Error("No available ports found")}var fe,H,Ue,Be,We,_e,N=p(()=>{"use strict";fe=1024,H=65535,Ue=443,Be=()=>{let o=Ie.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(o))if(t)for(let s of t)e.add(s.address);return e},We=(o,e)=>new Promise((t,s)=>{let r=Ne.createServer();r.unref(),r.on("error",s),r.listen(o,e,()=>{let{port:n}=r.address();r.close(()=>{t(n)})})}),_e=async(o,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await We(o,s)}catch(r){if(!t.has(r.code))throw r}return o}});var ge={};k(ge,{default:()=>Ve});import{rspack as ze}from"@rspack/core";import{RspackDevServer as Je}from"@rspack/dev-server";var I,Ve,de=p(()=>{"use strict";u();S();v();N();I=class extends f{async run(){let e=ze(i.rsConfig);if(!i.rsConfig.devServer){a.error("devServer is not defined in config");return}let t={...i.rsConfig.devServer},{host:s,port:r}=t;if(this.isHttps&&(t.https===!0&&delete t.https,!t.server)){let[h,l]=await this.getcert();t.server={type:"https",options:{key:h,cert:l}}}let n=await E(Number(r),s);n!==r&&(i.rsConfig.devServer.port=n,t.port=n),new Je(t,e).start()}},Ve=new I});var ye={};k(ye,{default:()=>Qe});import{rspack as qe}from"@rspack/core";var U,Qe,be=p(()=>{"use strict";v();u();S();U=class extends f{async run(){qe(i.rsConfig,(e,t)=>{if(e!==null){a.error(e.stack||e),e.message&&a.error(e.message);return}if(!t){a.red("Stats is Undefined.");return}let s=t.toString({all:!1,colors:!0,assets:!0,chunks:!1,entrypoints:!0,timings:!0,version:!0});t.hasErrors()&&(a.error(s),a.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(s)),a.info(s),a.green("Compiled successfully.")})}},Qe=new U});import ve from"url";import we from"chalk";import{ip as Xe}from"address";import{gateway4sync as Ye}from"default-gateway";function Ce(o,e,t,s="/"){let r=b=>ve.format({protocol:o,hostname:b,port:t,pathname:s}),n=b=>ve.format({protocol:o,hostname:b,port:we.bold(t),pathname:s}),c=e==="0.0.0.0"||e==="::",h,l,y=we.gray("unavailable");if(c){h="localhost";try{let{int:b}=Ye();l=Xe(b||""),l&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(l)?y=n(l):l=void 0)}catch{}}else h=e,l=e,y=n(l);let w=n(h),z=r(h);return{lanUrlForConfig:l,lanUrlForTerminal:y,localUrlForTerminal:w,localUrlForBrowser:z}}var xe=p(()=>{"use strict"});var Ee={};k(Ee,{default:()=>ot});import Se from"express";import Ke from"cors";import Ze from"compression";import et from"https";import tt from"path";import st from"node:fs/promises";var B,ot,ke=p(()=>{"use strict";N();xe();u();v();S();B=class extends f{app;startLogger({host:e,port:t,publicPath:s}){if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))a.info(`- Network: ${a.link(s)}`);else{let r=this.isHttps?"https":"http",c=Ce(r,e||"0.0.0.0",t,s);a.info(`- Local: ${a.link(c.localUrlForTerminal)}`),a.info(`- Network: ${a.link(c.lanUrlForTerminal)}`)}}async run(){let e=Se();e.use(Ze()),e.use(Ke()),this.app=e;let t=i.resolve(i.rsConfig.output?.path);this.app.use(Se.static(t));let s=await st.readFile(tt.join(t,"index.html"),"utf8");this.app.get("*",(y,w)=>w.send(s));let r={...i.rsConfig.devServer},{host:n,port:c}=r,h=i.rsConfig.output?.publicPath==="auto"?"/":i.rsConfig.output?.publicPath,l=await E(Number(c),n);if(this.isHttps){let[y,w]=await this.getcert();et.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:y,cert:w},this.app).listen(l,()=>{this.startLogger({host:n,port:l,publicPath:h})})}else this.app.listen(l,()=>{this.startLogger({host:n,port:l,publicPath:h})})}},ot=new B});u();u();import{program as d}from"commander";function Pe(){d.version(i.empPkg.version,"-v, --version").usage("<command> [options]"),d.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async o=>{let{default:e}=await Promise.resolve().then(()=>(de(),ge));await e.setup("dev",o)}),d.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async o=>{let{default:e}=await Promise.resolve().then(()=>(be(),ye));await e.setup("build",o)}),d.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async o=>{let{default:e}=await Promise.resolve().then(()=>(ke(),Ee));await e.setup("serve",o)}),d.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(o=>{}),d.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(o=>{}),d.parse(process.argv)}u();import rt from"fast-glob";import Oe from"node:fs/promises";import W from"node:path";var it=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,nt=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,at=/import\(['"]([^;\n]+?)['"]\)/,_=class{list=[];outDir=i.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await rt(["dist/**/*.d.ts"]);let e=[];this.list.map(s=>{s=i.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await Oe.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(it,r=>{let n=r.match(nt);if(n||(n=r.match(at)),n&&n[1]){let c=n[1];if(!c.startsWith("."))return r;let h=W.resolve(W.dirname(e),c).replace(this.outDir,this.aliasName);return r.replace(n[1],h)}return r});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
7
+ `)};link=e=>m.hex("#3498db")(e);tableData=[];tableConfig={border:{topBody:"\u2500",topJoin:"\u252C",topLeft:"\u250C",topRight:"\u2510",bottomBody:"\u2500",bottomJoin:"\u2534",bottomLeft:"\u2514",bottomRight:"\u2518",bodyLeft:"\u2502",bodyRight:"\u2502",bodyJoin:"\u2502",joinBody:"\u2500",joinLeft:"\u251C",joinRight:"\u2524",joinJoin:"\u253C"}};tableInput(e){this.tableData.push(e)}tableOutput(){console.log(Ge(this.tableData,this.tableConfig))}},a=new F});import Me from"node:fs";var L,ie,ne=p(()=>{"use strict";L=class{store;appSrc="src";appEntry="";base="";assign(e,t){return t=t||{},{...e,...t}}async setup(e){this.store=e,await this.syncEmpOptions();let{appSrc:t,base:s,appEntry:r}=this.store.empOptions;t&&(this.appSrc=t),s&&(this.base=s),r&&(this.appEntry=r)}async chain(){this.store.empOptions.chain&&await this.store.empOptions.chain(this.store.chain)}async plugins(){this.store.empOptions.plugins&&Array.isArray(this.store.empOptions.plugins)&&this.store.empOptions.plugins.length>0&&await Promise.all(this.store.empOptions.plugins)}get debug(){return this.assign({loggerLevel:"info",clearLog:!0,progress:!1,showRsconfig:!1},this.store.empOptions.debug)}get build(){return this.assign({outDir:"dist",publicDir:"public",chunkIds:this.store.isDev?"named":"deterministic",sourcemap:!0,minify:!this.store.isDev},this.store.empOptions.build)}get html(){return this.assign({lang:"zh-CN",title:"EMP",inject:"body",minify:!this.store.isDev,meta:{charset:{charset:"utf-8"},"http-equiv":{"http-equiv":"X-UA-Compatible",content:"IE=edge"},viewport:{content:"width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"}},files:{css:[],js:[]},tags:{headTags:[],bodyTags:[]}},this.store.empOptions.html)}get entries(){return this.store.empOptions.entries?this.store.empOptions.entries:{}}get react(){return this.assign({hmr:!0,svgr:!1},this.store.empOptions.react)}get server(){return this.assign({host:"0.0.0.0",port:8e3,open:!1,hot:!0,allowedHosts:["all"],historyApiFallback:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}},this.store.empOptions.server)}get empShare(){return this.assign({name:"",filename:"emp.js"},this.store.empOptions.empShare)}get css(){return this.assign({postcss:[]},this.store.empOptions.css)}async syncEmpOptions(){let e=this.store.resolve("emp-config.js");if(!Me.existsSync(e))return;let{default:t}=await import(e);typeof t=="function"?this.store.empOptions=await t(this.store):this.store.empOptions=t||{}}get moduleTransformRule(){let e={and:[/(node_modules|bower_components)/]},{moduleTransform:t}=this.store.empOptions;return t?.exclude&&(e.and=t.exclude),t?.include&&(e.not=t.include),e}get cacheDir(){return this.store.empOptions.cacheDir?this.store.empOptions.cacheDir:"node_modules/.emp-cache"}},ie=new L});var A,ae,pe=p(()=>{"use strict";A=class{js(e){let{isDev:t}=e,s={test:/\.(jsx?|tsx?)$/,use:[{loader:"builtin:swc-loader",options:{sourceMap:!0,jsc:{parser:{syntax:"typescript",tsx:!0},transform:{react:{runtime:"automatic",development:t,refresh:t}}}}}]};e.rsConfig.module?.rules?.push(s)}},ae=new A});var G,le,ce=p(()=>{"use strict";pe();G=class{async afterChain(e){ae.js(e)}},le=new G});import g from"node:path";import He from"webpack-chain";var M,i,u=p(()=>{"use strict";J();re();v();ne();ce();M=class{empPkg={dependencies:{},devDependencies:{},version:"2.0.0",name:""};pkg={dependencies:{},devDependencies:{},version:"0.0.0",name:""};root=process.cwd();empRoot=import.meta.resolve("@empjs/cli").replace("/dist/index.js","").replace("file://","");empSource=g.resolve(this.empRoot,"dist");resolve=e=>g.isAbsolute(e)?e:g.resolve(this.root,e);empResolve=e=>g.resolve(this.empRoot,e);appSrc="";outDir="";publicDir="";resource={dir:"",key:"",cert:""};cacheDir="";mode="development";cliMode="dev";isDev=!0;reactVersion=void 0;cliOptions;chain;rsConfig;empOptions={};empConfig;async setup(e,t){await this.initVars(e,t),this.empConfig=ie,await this.empConfig.setup(this),this.initPaths(),this.chain=new He,await oe.setup(this),this.setLogger(),this.toConfig(),this.logConfig()}async initVars(e,t){this.cliOptions=t||{},this.cliMode="prod",this.mode=e==="dev"?"development":"production",this.isDev=this.mode==="development";let s=await P(this.empResolve("package.json")),r=await P(this.resolve("package.json"));this.empPkg={...this.empPkg,...s},this.pkg={...this.pkg,...r},this.reactVersion=this.pkg.dependencies.react||this.pkg.devDependencies.react}initPaths(){this.appSrc=this.resolve(this.empConfig.appSrc),this.outDir=this.resolve(this.empConfig.build.outDir),this.publicDir=this.resolve(this.empConfig.build.publicDir),this.cacheDir=this.resolve(this.empConfig.cacheDir),this.resource.dir=g.join(this.empRoot,"resource"),this.resource.cert=g.join(this.resource.dir,"emp.cert"),this.resource.key=g.join(this.resource.dir,"emp.key")}setLogger(){let e=this.cliMode==="dev"?"debug":"info";this.empConfig.debug.loggerLevel&&(e=this.empConfig.debug.loggerLevel),a.setup({pname:` EMP v${this.empPkg.version} ${this.cliMode==="dev"?"DEV ":""}`,logLevel:e})}merge(e){this.chain.merge(e)}importResolve(e){return import.meta.resolve(e).replace("file://","")}toConfig(){this.rsConfig=this.chain.toConfig(),le.afterChain(this)}logConfig(){this.empConfig.debug.showRsconfig&&console.log("[ChainConfig]",JSON.stringify(this.rsConfig,null,2))}},i=new M});function me(){process.stdout.write(process.platform==="win32"?"\x1B[2J\x1B[0f":"\x1B[2J\x1B[3J\x1B[H")}var he=p(()=>{"use strict"});import ue from"node:fs/promises";var f,S=p(()=>{"use strict";v();u();he();f=class{async setup(e,t){await i.setup(e,t),i.empConfig.debug.clearLog&&me(),a.blue(`${e} Running`),await this.run()}async run(){}get isHttps(){let{server:e,https:t}=i.rsConfig.devServer||{};return e==="https"||typeof e=="object"&&e.type==="https"||t===!0}getcert(){return Promise.all([ue.readFile(i.resource.key),ue.readFile(i.resource.cert)])}}});import Ne from"net";import Ie from"os";async function E(o,e="localhost"){if(o!==Ue&&(o<fe||o>H))throw new Error(`Port number must lie between ${fe} and ${H}`);let t=o,s=Be(),r;e&&!s.has(e)?r=new Set([e]):r=s;let n=new Set(["EADDRINUSE","EACCES"]);for(;t<=H;)try{return await _e(t,r)}catch(c){if(!n.has(c.code))throw c;t+=1}throw new Error("No available ports found")}var fe,H,Ue,Be,We,_e,N=p(()=>{"use strict";fe=1024,H=65535,Ue=443,Be=()=>{let o=Ie.networkInterfaces(),e=new Set([void 0,"0.0.0.0"]);for(let t of Object.values(o))if(t)for(let s of t)e.add(s.address);return e},We=(o,e)=>new Promise((t,s)=>{let r=Ne.createServer();r.unref(),r.on("error",s),r.listen(o,e,()=>{let{port:n}=r.address();r.close(()=>{t(n)})})}),_e=async(o,e)=>{let t=new Set(["EADDRNOTAVAIL","EINVAL"]);for(let s of e)try{await We(o,s)}catch(r){if(!t.has(r.code))throw r}return o}});var ge={};k(ge,{default:()=>Ve});import{rspack as ze}from"@rspack/core";import{RspackDevServer as Je}from"@rspack/dev-server";var I,Ve,de=p(()=>{"use strict";u();S();v();N();I=class extends f{async run(){let e=ze(i.rsConfig);if(!i.rsConfig.devServer){a.error("devServer is not defined in config");return}let t={...i.rsConfig.devServer},{host:s,port:r}=t;if(this.isHttps&&(t.https===!0&&delete t.https,!t.server)){let[h,l]=await this.getcert();t.server={type:"https",options:{key:h,cert:l}}}let n=await E(Number(r),s);n!==r&&(i.rsConfig.devServer.port=n,t.port=n),new Je(t,e).start()}},Ve=new I});var ye={};k(ye,{default:()=>Qe});import{rspack as qe}from"@rspack/core";var U,Qe,be=p(()=>{"use strict";v();u();S();U=class extends f{async run(){qe(i.rsConfig,(e,t)=>{if(e!==null){a.error(e.stack||e),e.message&&a.error(e.message);return}if(!t){a.red("Stats is Undefined.");return}let s=t.toString({all:!1,colors:!0,assets:!0,chunks:!1,entrypoints:!0,timings:!0,version:!0});t.hasErrors()&&(a.error(s),a.red("Failed to compile."),process.exit(1)),t.hasWarnings()&&(a.yellow("Compiled with warnings."),a.warn(s)),a.info(s),a.green("Compiled successfully.")})}},Qe=new U});import ve from"url";import we from"chalk";import{ip as Xe}from"address";import{gateway4sync as Ye}from"default-gateway";function Ce(o,e,t,s="/"){let r=b=>ve.format({protocol:o,hostname:b,port:t,pathname:s}),n=b=>ve.format({protocol:o,hostname:b,port:we.bold(t),pathname:s}),c=e==="0.0.0.0"||e==="::",h,l,y=we.gray("unavailable");if(c){h="localhost";try{let{int:b}=Ye();l=Xe(b||""),l&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(l)?y=n(l):l=void 0)}catch{}}else h=e,l=e,y=n(l);let w=n(h),z=r(h);return{lanUrlForConfig:l,lanUrlForTerminal:y,localUrlForTerminal:w,localUrlForBrowser:z}}var xe=p(()=>{"use strict"});var Ee={};k(Ee,{default:()=>ot});import Se from"express";import Ke from"cors";import Ze from"compression";import et from"https";import tt from"path";import st from"node:fs/promises";var B,ot,ke=p(()=>{"use strict";N();xe();u();v();S();B=class extends f{app;startLogger({host:e,port:t,publicPath:s}){if(s&&(s.indexOf("http://")>-1||s.indexOf("https://")>-1))a.info(`- Network: ${a.link(s)}`);else{let r=this.isHttps?"https":"http",c=Ce(r,e||"0.0.0.0",t,s);a.info(`- Local: ${a.link(c.localUrlForTerminal)}`),a.info(`- Network: ${a.link(c.lanUrlForTerminal)}`)}}async run(){let e=Se();e.use(Ze()),e.use(Ke()),this.app=e;let t=i.resolve(i.rsConfig.output?.path);this.app.use(Se.static(t));let s=await st.readFile(tt.join(t,"index.html"),"utf8");this.app.get("*",(y,w)=>w.send(s));let r={...i.rsConfig.devServer},{host:n,port:c}=r,h=i.rsConfig.output?.publicPath==="auto"?"/":i.rsConfig.output?.publicPath,l=await E(Number(c),n);if(this.isHttps){let[y,w]=await this.getcert();et.createServer(typeof this.isHttps!="boolean"?this.isHttps:{key:y,cert:w},this.app).listen(l,()=>{this.startLogger({host:n,port:l,publicPath:h})})}else this.app.listen(l,()=>{this.startLogger({host:n,port:l,publicPath:h})})}},ot=new B});u();u();import{program as d}from"commander";function Pe(){d.version(i.empPkg.version,"-v, --version").usage("<command> [options]"),d.command("dev").description("Dev \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-h, --hot","\u662F\u5426\u4F7F\u7528\u70ED\u66F4\u65B0 \u9ED8\u8BA4\u542F\u52A8").option("-o, --open","\u662F\u5426\u6253\u5F00\u8C03\u8BD5\u9875\u9762 \u9ED8\u8BA4\u4E0D\u6253\u5F00").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async o=>{let{default:e}=await Promise.resolve().then(()=>(de(),ge));await e.setup("dev",o)}),d.command("build").description("Build \u6A21\u5F0F").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").option("-a, --analyze","\u751F\u6210\u5206\u6790\u62A5\u544A \u9ED8\u8BA4\u4E3A false").option("-t, --ts","\u751F\u6210\u7C7B\u578B\u6587\u4EF6 \u9ED8\u8BA4\u4E3A false").option("-pr, --profile","\u7EDF\u8BA1\u6A21\u5757\u6D88\u8017").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async o=>{let{default:e}=await Promise.resolve().then(()=>(be(),ye));await e.setup("build",o)}),d.command("serve").description("Server \u6A21\u5F0F").option("-cl, --clearLog <clearLog>","\u6E05\u7A7A\u65E5\u5FD7 \u9ED8\u8BA4\u4E3A true").action(async o=>{let{default:e}=await Promise.resolve().then(()=>(ke(),Ee));await e.setup("serve",o)}),d.command("dts").description("\u62C9\u53D6 remote \u9879\u76EE\u7684 d.ts").option("-p, --typingsPath <typingsPath>","\u4E0B\u8F7D\u76EE\u5F55").option("-e, --env <env>","\u90E8\u7F72\u73AF\u5883 dev\u3001test\u3001prod").action(o=>{}),d.command("init").description("\u521D\u59CB\u5316 emp \u9879\u76EE").option("-d, --data [data]","JSON\u6570\u636E http\u5730\u5740 \u6216\u8005 \u6587\u4EF6\u8DEF\u5F84\u76F8\u5BF9\u3001\u7EDD\u5BF9\u8DEF\u5F84").action(o=>{}),d.parse(process.argv)}u();import rt from"fast-glob";import Oe from"node:fs/promises";import W from"node:path";var it=/(?:(?:import|export)\s?(?:type)?\s?(?:(?:\{[^;\n]+\})|(?:[^;\n]+))\s?from\s?['"][^;\n]+['"])|(?:import\(['"][^;\n]+?['"]\))/g,nt=/(?:import|export)\s?(?:type)?\s?\{?.+\}?\s?from\s?['"](.+)['"]/,at=/import\(['"]([^;\n]+?)['"]\)/,_=class{list=[];outDir=i.resolve("dist");aliasName="@empjs/cli";async setup(e,t){e&&(this.outDir=e),t&&(this.aliasName=t);let s=await this.readDts();await this.writeCode(s)}async readDts(){this.list=await rt(["dist/**/*.d.ts"]);let e=[];this.list.map(s=>{s=i.resolve(s),e.push(this.readFile(s))});let t=await Promise.all(e);return t=t.map(s=>this.replaceAliasPath(s)),t}async readFile(e){let t=await Oe.readFile(e,{encoding:"utf-8"});return{src:e,code:t}}replaceAliasPath({src:e,code:t}){t=t.replace(it,r=>{let n=r.match(nt);if(n||(n=r.match(at)),n&&n[1]){let c=n[1];if(!c.startsWith("."))return r;let h=W.resolve(W.dirname(e),c).replace(this.outDir,this.aliasName);return r.replace(n[1],h)}return r});let s=e.replace(this.outDir,this.aliasName).replace(".d.ts","");return s.endsWith("/index")&&(s=s.replace("/index","")),t=this.warpDeclareModule(s,t),{code:t,src:e,mod:s}}warpDeclareModule(e,t){return`declare module '${e}' {\r
8
8
  ${t}}\r
9
9
  `}async writeCode(e){let t="";e.map(s=>{t+=s.code}),await Oe.writeFile(W.join(this.outDir.replace("dist","types"),"type.d.ts"),t)}},pt=new _;function Bs(o){return o}export{Bs as defineConfig,pt as dts,Pe as runScript,i as store};
@@ -86,6 +86,13 @@ export interface HtmlType extends HtmlRspackPluginOptions {
86
86
  */
87
87
  js?: string[];
88
88
  };
89
+ /**
90
+ * 自定义 头部脚步内容 headTags[] bodyTags[]
91
+ */
92
+ tags?: {
93
+ headTags?: any[];
94
+ bodyTags?: any[];
95
+ };
89
96
  }
90
97
  export type EntriesType = {
91
98
  [entryFilename: string]: HtmlType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empjs/cli",
3
- "version": "3.0.0-alpha.23",
3
+ "version": "3.0.0-alpha.24",
4
4
  "description": "emp",
5
5
  "license": "MIT",
6
6
  "type": "module",