@remotex-labs/xbuild 2.2.3 → 2.2.4

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/bash.js CHANGED
@@ -21,7 +21,7 @@ __ _| |_/ /_ _ _| | __| |
21
21
  /_/\\_\\____/ \\__,_|_|_|\\__,_|
22
22
  `;function Dt(){return`
23
23
  \r${ot.burntOrange(ui)}
24
- \rVersion: ${ot.brightPink("2.2.3")}
24
+ \rVersion: ${ot.brightPink("2.2.4")}
25
25
  \r`}function O(){return ot.lightCoral("[xBuild]")}import{readdir as di,stat as mi,readFile as gi}from"fs/promises";import{xterm as Pe}from"@remotex-labs/xansi/xterm.component";var Ee=class{constructor(e,t){this.config=e;this.rootDir=I(t),this.config.port||=0,this.config.host||="localhost"}server;rootDir;framework=u(E);async start(){if(this.config.https)return await this.startHttpsServer();await this.startHttpServer()}async stop(){if(!this.server){console.log(O(),Pe.gray("No server is currently running."));return}await new Promise((e,t)=>{this.server.close(i=>{i?t(i):e()})}),console.log(O(),Pe.dim("Server stopped.")),this.server=void 0}async restart(){console.log(O(),Pe.burntOrange("Restarting server...")),await this.stop(),await this.start()}setActualPort(){if(this.config.port===0){let e=this.server.address();e&&typeof e=="object"&&e.port&&(this.config.port=e.port)}}startHttpServer(){return new Promise(e=>{this.server=Ht.createServer((t,i)=>{this.handleRequest(t,i,()=>this.defaultResponse(t,i))}),this.server.listen(this.config.port,this.config.host,()=>{this.setActualPort(),this.config.onStart?.({host:this.config.host,port:this.config.port,url:`http://${this.config.host}:${this.config.port}`}),e()})})}startHttpsServer(){return new Promise(e=>{let t={key:Lt(this.config.key??v(this.framework.distPath,"..","certs","server.key")),cert:Lt(this.config.cert??v(this.framework.distPath,"..","certs","server.crt"))};this.server=_t.createServer(t,(i,o)=>{this.handleRequest(i,o,()=>this.defaultResponse(i,o))}),this.server.listen(this.config.port,this.config.host,()=>{this.setActualPort(),this.config.onStart?.({host:this.config.host,port:this.config.port,url:`https://${this.config.host}:${this.config.port}`}),e()})})}handleRequest(e,t,i){try{this.config.verbose&&console.log(`${O()} Request ${Pe.lightCoral(e.url?.toString()??"")}`),this.config.onRequest?this.config.onRequest(e,t,i):i()}catch(o){this.sendError(t,o)}}getContentType(e){return{html:"text/html",css:"text/css",js:"application/javascript",cjs:"application/javascript",mjs:"application/javascript",ts:"text/plain",map:"application/json",json:"application/json",png:"image/png",jpg:"image/jpeg",gif:"image/gif",txt:"text/plain"}[e]||"application/octet-stream"}async defaultResponse(e,t){let i=e.url==="/"?"":e.url?.replace(/^\/+/,"")||"",o=v(this.rootDir,i);if(!o.startsWith(this.rootDir)){t.statusCode=403,t.end();return}try{let n=await mi(o);n.isDirectory()?await this.handleDirectory(o,i,t):n.isFile()&&await this.handleFile(o,t)}catch(n){let s=n.message;s.includes("favicon")||console.log(O(),s),this.sendNotFound(t)}}async handleDirectory(e,t,i){let n=(await di(e)).map(l=>{let p=v(t,l),f=jt(l).slice(1)||"folder";return f==="folder"?`
26
26
  <a href="/${p}" class="folder-row">
27
27
  <div class="icon"><i class="fa-solid fa-folder"></i></div>