kuwan-expresspack-core 0.1.4 → 0.1.6
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/bin/config-typegen-cmd-NHEFXKH4.mjs +20 -0
- package/dist/bin/expresspack-api.mjs +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +7 -20
- package/package.json +1 -1
- package/bin/expresspack.mjs +0 -40
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import a, { existsSync } from 'fs';
|
|
2
|
+
import o from 'path';
|
|
3
|
+
import { glob } from 'tinyglobby';
|
|
4
|
+
|
|
5
|
+
var w="*.{js,ts,mjs,cjs,mts,cts}",x=["!*.d.{ts,mts,mjs,cts}","!*.map"];async function d(t){let r=await glob([w,...x],{cwd:t}),n=new Set;return r.forEach(s=>{let e=s.replace(/\.(js|ts|mjs|cjs|mts|cts)$/,"");n.add(e);}),Array.from(n)}var m=t=>{let r=["ts","mts","js","mjs","cjs","cts"];for(let n of r){let s=`${t}.${n}`;if(existsSync(s))return s}return null};var j=t=>`
|
|
6
|
+
// This file is auto-generated. Do not edit directly.
|
|
7
|
+
declare module 'kuwan-expresspack-core/config' {
|
|
8
|
+
const config: AppConfig;
|
|
9
|
+
export default config;
|
|
10
|
+
export function getAppConfig<K extends keyof AppConfig>(key: K): AppConfig[K];
|
|
11
|
+
|
|
12
|
+
export interface AppConfig {
|
|
13
|
+
${t.join(`\r
|
|
14
|
+
`)}
|
|
15
|
+
}
|
|
16
|
+
}`.trim(),v=(t,r)=>`${t}: typeof import('${r}').default;`;async function $(t){let r=await d(t.configDir);console.log(`Found ${r.length} config files:
|
|
17
|
+
${r.join(`
|
|
18
|
+
`)}`);let n=[];for(let e of r){let i=m(o.join(t.configDir,e));if(!i){console.warn(`No config file found for topic: ${e}`);continue}try{let c=o.normalize(o.resolve(t.cwd,i)),u=o.normalize(o.resolve(t.cwd,t.output)),p=o.posix.relative(o.dirname(u),c),y=e.replace(/[-_](\w)/g,(b,f)=>f?f.toUpperCase():""),C=v(y,p.startsWith(".")?p:`./${p}`);n.push(C);}catch(c){console.warn(`Failed to process config file for topic: ${e}`,c);}}let s=j(n);try{let e=o.normalize(o.resolve(t.cwd,t.output));console.log("Output path resolved to:",e);let i=o.dirname(e);a.existsSync(i)||(a.mkdirSync(i,{recursive:!1}),console.log("Created directory:",i)),a.writeFileSync(e,s),console.log("Generated types at:",e);}catch(e){console.error("Failed to generate config types.",e),process.exit(1);}}
|
|
19
|
+
|
|
20
|
+
export { $ as default };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { defineCommand, runMain } from 'citty';
|
|
3
|
-
import
|
|
3
|
+
import e, { dirname, resolve } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import m from 'dayjs';
|
|
6
|
+
import d from 'dayjs/plugin/utc.js';
|
|
7
7
|
import { execa } from 'execa';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
m.extend(d);var f=defineCommand({meta:{name:"expresspack-api",version:"1.0.0"},subCommands:{"db-pull":()=>defineCommand({async run({rawArgs:o}){console.log("Running db-pull command with args:",o);let t=fileURLToPath(import.meta.url),n=dirname(t),r=resolve(n,e.join("..","..","node_modules",".bin","drizzle-kit"));await execa({stdout:["pipe","inherit"]})`${r} pull ${o.join(" ")}`;}}),"config-typegen":()=>defineCommand({meta:{name:"config-typegen",description:"Generate TypeScript definitions for files in the config directory"},args:{configDir:{type:"string",alias:"c",description:"Path of the `config` folder",default:e.join("./","src","config")},output:{type:"string",alias:"o",description:"Output directory for the generated types",required:true}},async run({args:o}){o?.output||(console.error("Error: Output directory is required. Use -o or --output to specify the path."),process.exit(1));let{default:t}=await import('./config-typegen-cmd-NHEFXKH4.mjs');await t({configDir:o.configDir,output:o.output,cwd:process.cwd()});}})}});runMain(f);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Express, Router } from 'express';
|
|
1
|
+
import { Express, RouterOptions, Router } from 'express';
|
|
2
2
|
import { Server } from 'node:http';
|
|
3
3
|
|
|
4
4
|
declare function gracefulHTTPStart(app: Express, port: number, onStart?: () => Promise<void>): Server;
|
|
@@ -49,14 +49,14 @@ declare function loadKernel({ app }: {
|
|
|
49
49
|
app: any;
|
|
50
50
|
}, { kernel, listener, appBootstrap, }: LoadKernelOptions): Promise<void>;
|
|
51
51
|
|
|
52
|
-
declare function createRouter(): Router;
|
|
52
|
+
declare function createRouter(options?: RouterOptions): Router;
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Utility to define a router middleware using a callback.
|
|
56
56
|
* @param fn Callback to register routes on the router
|
|
57
57
|
* @returns Express Router instance
|
|
58
58
|
*/
|
|
59
|
-
declare function defineRouterMiddleware(fn: (router: Router) => void): Router;
|
|
59
|
+
declare function defineRouterMiddleware(fn: (router: Router) => void, options?: RouterOptions): Router;
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Load all configurations from the config directory
|
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
import { a } from './chunk-VSPZT4K6.mjs';
|
|
2
2
|
import { c } from './chunk-CRIPGIHI.mjs';
|
|
3
|
-
import
|
|
3
|
+
import L from 'consola';
|
|
4
4
|
import { Router } from 'express';
|
|
5
|
-
import
|
|
5
|
+
import $, { relative, join } from 'path';
|
|
6
|
+
import { existsSync } from 'fs';
|
|
6
7
|
import { glob } from 'tinyglobby';
|
|
7
|
-
import x, { existsSync } from 'fs';
|
|
8
|
-
import { fileURLToPath } from 'url';
|
|
9
|
-
import 'module';
|
|
10
8
|
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export default config;
|
|
15
|
-
export function getAppConfig<K extends keyof AppConfig>(key: K): AppConfig[K];
|
|
9
|
+
var w=process.env.EXPRESSPACK_LOG_LEVEL,N=L.create({level:Number.isNaN(Number(w))?3:Number(w)}),t=N;function j(r,n,e){return r.listen(n,async()=>{e&&(t.debug("Executing onStart hook..."),await e().catch(o=>{t.error("Error during onStart hook:",o);})),t.box({message:`Server is running at http://localhost:${n}`,style:{borderColor:"cyan"},level:"info"}),c.emit("app:mounted");})}function F(r,n){process.on("SIGINT",async()=>{t.info("Received SIGINT. Shutting down gracefully..."),await new Promise(e=>{r.close(async i=>i instanceof Error?(t.error("Error shutting down server:",i),e()):(n&&await n().catch(o=>{t.error("Error during shutdown hook:",o);}),t.info("Server has been shut down."),e()));}),process.exit(0);});}function k(r){return r}async function A({app:r},{kernel:n,listener:e,appBootstrap:i}){t.debug("Loading kernel...");try{let o=await n();await(o?.default||o)({app:r});}catch(o){throw t.error("Error loading kernel:",o),o}if(e&&typeof e=="function")try{let o=await e(),a=o?.default||o;a===void 0||typeof a!="function"?t.warn("No listener setup function found"):await a();}catch(o){throw t.error("Error loading listener:",o),o}if(i&&typeof i=="function")try{await i({app:r});}catch(o){throw t.error("Error during boot process:",o),o}t.debug("Kernel loaded.");}function g(r){return Router(r)}function T(r,n){let e=g(n);return r(e),e}function E(r){let n=join(r,"expresspack.config"),e=join(r,"app"),i=join(r,"config"),o=join(i,"app"),a=join(i,"body-parser"),f=join(e,"controllers"),d=join(e,"services"),u=join(e,"errors"),l=join(e,"middlewares"),m=join(e,"routes");return {rc:n,root:r,app:e,middlewareFilePath:l,routesFilePath:m,config:{base:i,bodyParserFile:a,appConfigFile:o},controllers:{base:f},services:{base:d},errors:{base:u}}}var b=r=>{let n=["ts","mts","js","mjs","cjs","cts"];for(let e of n){let i=`${r}.${e}`;if(existsSync(i))return i}return null},P=r=>existsSync(r)?r:null;function R(r){if(!r)return "";let n=$.sep;return r.endsWith(n)?r:r+n}var _="*.{js,ts,mjs,cjs,mts,cts}",G=["!*.d.{ts,mts,mjs,cts}","!*.map"];async function S(r){let n=await glob([_,...G],{cwd:r}),e=new Set;return n.forEach(i=>{let o=i.replace(/\.(js|ts|mjs|cjs|mts|cts)$/,"");e.add(o);}),Array.from(e)}async function B(r){let{config:n}=E(r),e=n.base;if(t.debug("Loading all configurations from: "+R(relative(r,n.base))),!P(e)){t.debug("No config directory found. Looked for:",e);return}let o=await S(e);t.debug(`Found ${o.length} config files: %s`,`
|
|
10
|
+
${o.join(`
|
|
11
|
+
`)}`);for(let f of o){let d=b(join(e,f));if(!d){t.warn(`No config file found for topic: ${f}`);continue}try{let u=await import(d),l=u.default||u;typeof l=="function"&&(l=await l());let m=f.replace(/[-_](\w)/g,(M,x)=>x?x.toUpperCase():"");a[m]=l;let C=d.split("/").pop();t.debug(`Loaded config: ${m} from ${C}`);}catch(u){t.error(`Failed to load config ${f}:`,u);}}}
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
${o.map(c=>`${c.topic}: typeof import('${c.configPath}').default;`).join(`
|
|
19
|
-
`)}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
`.trim(),p=A,n=u.join(p,".types");y.debug({modulesPath:A,generatedTypesDir:n});try{x.existsSync(p)&&(x.existsSync(n)||(x.mkdirSync(n,{recursive:!1}),y.debug("Created directory:",n)),x.writeFileSync(u.join(n,"config.d.ts"),s),y.debug("Generated types at:",u.join(n,"config.d.ts")));}catch(c){y.debug("Failed to generate config types. This warning can be ignored.",c);}}var W="*.{js,ts,mjs,cjs,mts,cts}",q=["!*.d.{ts,mts,mjs,cts}","!*.map"];async function X(e){let o=await glob([W,...q],{cwd:e}),r=new Set;return o.forEach(s=>{let t=s.replace(/\.(js|ts|mjs|cjs|mts|cts)$/,"");r.add(t);}),Array.from(r)}async function Q(e){let{config:o}=k(e),r=o.base;if(i.debug("Loading all configurations from: "+N(relative(e,o.base))),!C(r)){i.debug("No config directory found. Looked for:",r);return}let t=await X(r);i.debug(`Found ${t.length} config files: %s`,`
|
|
23
|
-
${t.join(`
|
|
24
|
-
`)}`);let p=new Set;for(let n of t){let c=S(join(r,n));if(!c){i.warn(`No config file found for topic: ${n}`);continue}try{let m=await import(c),l=m.default||m;typeof l=="function"&&(l=await l());let g=n.replace(/[-_](\w)/g,(Y,v)=>v?v.toUpperCase():"");a[g]=l;let T=c.split("/").pop();i.debug(`Loaded config: ${g} from ${T}`),process.env.NODE_ENV!=="production"&&p.add({topic:g,configPath:c});}catch(m){i.error(`Failed to load config ${n}:`,m);}}process.env.NODE_ENV!=="production"&&(i.debug("Generating type definitions for config files..."),b(e,Array.from(p)));}
|
|
25
|
-
|
|
26
|
-
export { Q as configLoader, h as createRouter, D as defineKernel, G as defineRouterMiddleware, K as gracefulHTTPStart, $ as gracefulShutdown, _ as loadKernel };
|
|
13
|
+
export { B as configLoader, g as createRouter, k as defineKernel, T as defineRouterMiddleware, j as gracefulHTTPStart, F as gracefulShutdown, A as loadKernel };
|
package/package.json
CHANGED
package/bin/expresspack.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { defineCommand, runMain } from "citty";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import dayjs from 'dayjs';
|
|
5
|
-
import utc from "dayjs/plugin/utc.js";
|
|
6
|
-
dayjs.extend(utc);
|
|
7
|
-
|
|
8
|
-
const main = defineCommand({
|
|
9
|
-
meta: {
|
|
10
|
-
name: "expresspack",
|
|
11
|
-
version: "1.0.0"
|
|
12
|
-
},
|
|
13
|
-
subCommands: {
|
|
14
|
-
auth: () => defineCommand({
|
|
15
|
-
async run({ rawArgs }) {
|
|
16
|
-
console.log("Running auth command with args:", rawArgs);
|
|
17
|
-
const originalArgv = process.argv;
|
|
18
|
-
rawArgs.push(...[
|
|
19
|
-
'--output',
|
|
20
|
-
path.join(
|
|
21
|
-
'src', 'db', 'auth_migrations',
|
|
22
|
-
dayjs().utc().format('YYYY-MM-DDTHH-mm-ss.SSS') + '.sql'
|
|
23
|
-
),
|
|
24
|
-
])
|
|
25
|
-
process.argv = ['node', 'better-auth',
|
|
26
|
-
...rawArgs];
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
// Import and execute better-auth CLI directly
|
|
30
|
-
await import('@better-auth/cli');
|
|
31
|
-
} finally {
|
|
32
|
-
// Restore original argv
|
|
33
|
-
process.argv = originalArgv;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
runMain(main);
|