#!/usr/bin/env node "use strict";var l=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var h=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of u(e))!g.call(t,i)&&i!==s&&c(t,i,{get:()=>e[i],enumerable:!(o=p(e,i))||o.enumerable});return t};var d=(t,e,s)=>(s=t!=null?l(f(t)):{},h(e||!t||!t.__esModule?c(s,"default",{value:t,enumerable:!0}):s,t));var r=d(require("fs")),n=d(require("path")),a=class t{static{this.Init="init"}static{this.args=process.argv.slice(2)}static{this.command=t.args[0]}static{this.cwd=process.cwd()}static{this.configPath=n.join(t.cwd,"config.json")}static{this.srcPath=n.join(t.cwd,"src")}static{this.middlewaresPath=n.join(t.srcPath,"middlewares")}static{this.routesPath=n.join(t.srcPath,"routes")}static exitWithError(e){return console.error(e),process.exit(1)}static loadConfig(){r.existsSync(t.configPath)||t.exitWithError("config.json not found in current directory");try{let e=r.readFileSync(t.configPath,"utf-8");return JSON.parse(e)}catch(e){let s=e instanceof Error?e.message:String(e);t.exitWithError(`Failed to read config.json: ${s}`)}}static getDefaultConfig(){return{port:3e3,middlewaresPath:"./src/middlewares",routesPath:"./src/routes",json:!1,urlencoded:!1,sessions:!1}}static init(){if(r.existsSync(t.configPath))return console.log("config.json already exists");let e=`import { Server as ExtressServer } from 'extress'; class Server { public static async start(): Promise { return new ExtressServer().init().then((server: Server) => { return server.start(), server; }); } } export default Server;`,s=`import Server from './Server'; Server.start();`,o=`import { Middleware, NextFunction, Request, Response } from 'extress'; class DefaultMiddleware extends Middleware { protected action = (req: Request, res: Response, next: NextFunction) => { next(); }; protected order: number = 0; protected route: string | null = null; } export default DefaultMiddleware;`,i=`import { Route, Request, Response, HttpMethod } from 'extress'; class GetIndex extends Route { protected action = (req: Request, res: Response) => { res.status(200).send('Welcome to Extress!'); }; protected route: string | null = '/'; protected method: HttpMethod = HttpMethod.GET; } export default GetIndex;`;r.mkdirSync(t.srcPath),r.mkdirSync(t.middlewaresPath),r.mkdirSync(t.routesPath),r.writeFileSync(n.join(t.middlewaresPath,"DefaultMiddleware.ts"),o),r.writeFileSync(n.join(t.routesPath,"GetIndex.ts"),i),r.writeFileSync(n.join(t.srcPath,"Server.ts"),e),r.writeFileSync(n.join(t.srcPath,"index.ts"),s),r.writeFileSync(t.configPath,JSON.stringify(t.getDefaultConfig(),null,2),"utf-8"),console.log("Project initialized successfully.")}static printUsage(){console.log(`Usage: extress init`)}static run(){return t.command===t.Init?t.init():t.printUsage()}};a.run();