kuwan-expresspack-core 0.1.18 → 0.1.19
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.d.ts +24 -1
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -67,12 +67,35 @@ declare function loadKernel({ app }: {
|
|
|
67
67
|
|
|
68
68
|
declare function createRouter(options?: RouterOptions): Router;
|
|
69
69
|
|
|
70
|
+
interface DefineRouteMiddlewareContext {
|
|
71
|
+
app?: Express;
|
|
72
|
+
router: Router;
|
|
73
|
+
}
|
|
74
|
+
interface DefineRouterMiddlewareReturn {
|
|
75
|
+
(app?: Express): Router;
|
|
76
|
+
}
|
|
70
77
|
/**
|
|
71
78
|
* Utility to define a router middleware using a callback.
|
|
72
79
|
* @param fn Callback to register routes on the router
|
|
73
80
|
* @returns Express Router instance
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* const routerMiddleware = defineRouterMiddleware(({ router, app }) => {
|
|
86
|
+
* router.get('/hello', (req, res) => {
|
|
87
|
+
* res.send('Hello from router middleware!');
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* app.use(controller);
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* // In your main app file
|
|
94
|
+
* const app = express();
|
|
95
|
+
* app.use(middlewares);
|
|
96
|
+
* routerMiddleware(app);
|
|
74
97
|
*/
|
|
75
|
-
declare function defineRouterMiddleware(fn: (
|
|
98
|
+
declare function defineRouterMiddleware(fn: (context: DefineRouteMiddlewareContext) => void, options?: RouterOptions): DefineRouterMiddlewareReturn;
|
|
76
99
|
|
|
77
100
|
/**
|
|
78
101
|
* Load all configurations from the config directory
|
package/dist/index.mjs
CHANGED
|
@@ -3,13 +3,13 @@ import { a as a$1 } from './chunk-JKH5TYED.mjs';
|
|
|
3
3
|
import { a as a$2 } from './chunk-VSPZT4K6.mjs';
|
|
4
4
|
import { a, f } from './chunk-XWAHBJNF.mjs';
|
|
5
5
|
import { Router } from 'express';
|
|
6
|
-
import
|
|
6
|
+
import O, { relative, join } from 'path';
|
|
7
7
|
import { existsSync } from 'fs';
|
|
8
8
|
import { glob } from 'tinyglobby';
|
|
9
9
|
import { pathToFileURL } from 'url';
|
|
10
10
|
|
|
11
|
-
function A(
|
|
12
|
-
${
|
|
13
|
-
`)}`);for(let p of
|
|
11
|
+
function A(e$1,t,r){return e$1.listen(t,async()=>{r&&(a.debug("Executing onStart hook..."),await r().catch(s=>{a.error("Error during onStart hook:",s);})),a.box({message:`Server is running at http://localhost:${t}`,style:{borderColor:"cyan"},level:"info"});try{await e.emit("app:mounted",{app:e$1});}catch(s){a.error("Error during app:mounted event:",s);}finally{f();}})}function F(e,t){process.on("SIGINT",async()=>{a.info("Received SIGINT. Shutting down gracefully..."),await new Promise(r=>{e.close(async i=>i instanceof Error?(a.error("Error shutting down server:",i),r()):(t&&await t().catch(s=>{a.error("Error during shutdown hook:",s);}),a.info("Server has been shut down."),r()));}),process.exit(0);});}function T(e){return e}function M(e){return e}async function $({app:e},t){a.debug("Loading kernel...");let{kernel:r,kernel2:i,listener:s,appBootstrap:l}=t,p=i;if(r&&typeof r=="function"&&(p=r),p&&typeof p=="function")try{let n=await p(),d=typeof n=="object"&&n!==null&&"default"in n?n.default:n;typeof d=="function"?(await d({app:e}),a.debug("Middleware kernel loaded.")):a.warn("Middleware kernel setup function not found.");}catch(n){throw a.error("Error loading middleware kernel:",n),n}if(s&&typeof s=="function")try{await a$1(s);}catch(n){throw a.error("Error loading listener:",n),n}if(l&&typeof l=="function")try{await l({app:e});}catch(n){throw a.error("Error during boot process:",n),n}a.debug("Kernel loaded.");}function g(e){return Router(e)}function D(e,t){return r=>{let i=g(t);return e({app:r,router:i}),i}}function P(e){let t=join(e,"expresspack.config"),r=join(e,"app"),i=join(e,"config"),s=join(i,"app"),l=join(i,"body-parser"),p=join(r,"controllers"),n=join(r,"services"),d=join(r,"errors"),m=join(r,"middlewares"),u=join(r,"routes");return {rc:t,root:e,app:r,middlewareFilePath:m,routesFilePath:u,config:{base:i,bodyParserFile:l,appConfigFile:s},controllers:{base:p},services:{base:n},errors:{base:d}}}var b=e=>{let t=["ts","mts","js","mjs","cjs","cts"];for(let r of t){let i=`${e}.${r}`;if(existsSync(i))return i}return null},C=e=>existsSync(e)?e:null;function k(e){if(!e)return "";let t=O.sep;return e.endsWith(t)?e:e+t}var N="*.{js,ts,mjs,cjs,mts,cts}",I=["!*.d.{ts,mts,mjs,cts}","!*.map"];async function S(e){let t=await glob([N,...I],{cwd:e}),r=new Set;return t.forEach(i=>{let s=i.replace(/\.(js|ts|mjs|cjs|mts|cts)$/,"");r.add(s);}),Array.from(r)}async function U(e){let{config:t}=P(e),r=t.base;if(a.debug("Loading all configurations from: `"+k(relative(e,t.base)+"`")),!C(r)){a.debug("No config directory found. Looked for:",r);return}let s=await S(r);a.debug(`Found ${s.length} config files: %s`,`
|
|
12
|
+
${s.join(`
|
|
13
|
+
`)}`);for(let p of s){let n=b(join(r,p));if(!n){a.warn(`No config file found for topic: ${p}`);continue}try{let m=await import(pathToFileURL(n).href),u=m.default||m;typeof u=="function"&&(u=await u());let x=p.replace(/[-_](\w)/g,(H,w)=>w?w.toUpperCase():"");a$2[x]=u;let j=relative(e,n);a.debug(`Loaded config: \`${x}\` from \`${j}\``);}catch(d){a.error(`Failed to load config ${p}:`,d);}}}
|
|
14
14
|
|
|
15
|
-
export { U as configLoader, g as createRouter, T as defineKernel,
|
|
15
|
+
export { U as configLoader, g as createRouter, T as defineKernel, M as defineMiddlewareKernel, D as defineRouterMiddleware, A as gracefulHTTPStart, F as gracefulShutdown, $ as loadKernel };
|