@geekmidas/cli 0.7.0 → 0.8.0
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/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/index.cjs +49 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +49 -27
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-Mwy2_R4W.mjs → openapi--vOy9mo4.mjs} +23 -2
- package/dist/openapi--vOy9mo4.mjs.map +1 -0
- package/dist/{openapi-tAIbJJU_.cjs → openapi-CHhTPief.cjs} +23 -2
- package/dist/openapi-CHhTPief.cjs.map +1 -0
- package/dist/openapi.cjs +1 -1
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.mjs +1 -1
- package/dist/{types-B3TXoj7v.d.mts → types-DXgiA1sF.d.mts} +38 -1
- package/dist/{types-C0hwnSjm.d.cts → types-b-vwGpqc.d.cts} +38 -1
- package/package.json +4 -4
- package/src/__tests__/EndpointGenerator.hooks.spec.ts +204 -0
- package/src/__tests__/normalizeHooksConfig.spec.ts +63 -0
- package/src/build/index.ts +8 -1
- package/src/build/types.ts +6 -0
- package/src/dev/index.ts +82 -29
- package/src/generators/EndpointGenerator.ts +27 -1
- package/src/types.ts +38 -0
- package/dist/openapi-Mwy2_R4W.mjs.map +0 -1
- package/dist/openapi-tAIbJJU_.cjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
2
|
import { loadConfig, parseModuleConfig } from "./config-Bq72aj8e.mjs";
|
|
3
|
-
import { ConstructGenerator, EndpointGenerator, generateOpenApi, openapiCommand, resolveOpenApiConfig } from "./openapi
|
|
3
|
+
import { ConstructGenerator, EndpointGenerator, OPENAPI_OUTPUT_PATH, generateOpenApi, openapiCommand, resolveOpenApiConfig } from "./openapi--vOy9mo4.mjs";
|
|
4
4
|
import { generateReactQueryCommand } from "./openapi-react-query-CcciaVu5.mjs";
|
|
5
5
|
import { join, relative } from "path";
|
|
6
6
|
import { Command } from "commander";
|
|
@@ -19,7 +19,7 @@ import prompts from "prompts";
|
|
|
19
19
|
|
|
20
20
|
//#region package.json
|
|
21
21
|
var name = "@geekmidas/cli";
|
|
22
|
-
var version = "0.
|
|
22
|
+
var version = "0.8.0";
|
|
23
23
|
var description = "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs";
|
|
24
24
|
var private$1 = false;
|
|
25
25
|
var type = "module";
|
|
@@ -571,6 +571,16 @@ function normalizeStudioConfig(config$1) {
|
|
|
571
571
|
schema: studioConfig.schema ?? "public"
|
|
572
572
|
};
|
|
573
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Normalize hooks configuration
|
|
576
|
+
* @internal Exported for testing
|
|
577
|
+
*/
|
|
578
|
+
function normalizeHooksConfig(config$1) {
|
|
579
|
+
if (!config$1?.server) return void 0;
|
|
580
|
+
const serverPath = config$1.server.endsWith(".ts") ? config$1.server : `${config$1.server}.ts`;
|
|
581
|
+
const resolvedPath = resolve(process.cwd(), serverPath);
|
|
582
|
+
return { serverHooksPath: resolvedPath };
|
|
583
|
+
}
|
|
574
584
|
async function devCommand(options) {
|
|
575
585
|
const defaultEnv = loadEnvFiles(".env");
|
|
576
586
|
if (defaultEnv.loaded.length > 0) logger$2.log(`📦 Loaded env: ${defaultEnv.loaded.join(", ")}`);
|
|
@@ -593,16 +603,19 @@ async function devCommand(options) {
|
|
|
593
603
|
if (telescope) logger$2.log(`🔭 Telescope enabled at ${telescope.path}`);
|
|
594
604
|
const studio = normalizeStudioConfig(config$1.studio);
|
|
595
605
|
if (studio) logger$2.log(`🗄️ Studio enabled at ${studio.path}`);
|
|
606
|
+
const hooks = normalizeHooksConfig(config$1.hooks);
|
|
607
|
+
if (hooks) logger$2.log(`🪝 Server hooks enabled from ${config$1.hooks?.server}`);
|
|
596
608
|
const openApiConfig = resolveOpenApiConfig(config$1);
|
|
597
609
|
const enableOpenApi = openApiConfig.enabled || resolved.enableOpenApi;
|
|
598
|
-
if (enableOpenApi) logger$2.log(`📄 OpenAPI output: ${
|
|
610
|
+
if (enableOpenApi) logger$2.log(`📄 OpenAPI output: ${OPENAPI_OUTPUT_PATH}`);
|
|
599
611
|
const buildContext = {
|
|
600
612
|
envParserPath,
|
|
601
613
|
envParserImportPattern,
|
|
602
614
|
loggerPath,
|
|
603
615
|
loggerImportPattern,
|
|
604
616
|
telescope,
|
|
605
|
-
studio
|
|
617
|
+
studio,
|
|
618
|
+
hooks
|
|
606
619
|
};
|
|
607
620
|
await buildServer(config$1, buildContext, resolved.providers[0], enableOpenApi);
|
|
608
621
|
if (enableOpenApi) await generateOpenApi(config$1);
|
|
@@ -611,13 +624,15 @@ async function devCommand(options) {
|
|
|
611
624
|
await devServer.start();
|
|
612
625
|
const envParserFile = config$1.envParser.split("#")[0];
|
|
613
626
|
const loggerFile = config$1.logger.split("#")[0];
|
|
627
|
+
const hooksFile = config$1.hooks?.server?.split("#")[0];
|
|
614
628
|
const watchPatterns = [
|
|
615
629
|
config$1.routes,
|
|
616
630
|
...config$1.functions ? [config$1.functions] : [],
|
|
617
631
|
...config$1.crons ? [config$1.crons] : [],
|
|
618
632
|
...config$1.subscribers ? [config$1.subscribers] : [],
|
|
619
633
|
envParserFile.endsWith(".ts") ? envParserFile : `${envParserFile}.ts`,
|
|
620
|
-
loggerFile.endsWith(".ts") ? loggerFile : `${loggerFile}.ts
|
|
634
|
+
loggerFile.endsWith(".ts") ? loggerFile : `${loggerFile}.ts`,
|
|
635
|
+
...hooksFile ? [hooksFile.endsWith(".ts") ? hooksFile : `${hooksFile}.ts`] : []
|
|
621
636
|
].flat();
|
|
622
637
|
const normalizedPatterns = watchPatterns.map((p) => p.startsWith("./") ? p.slice(2) : p);
|
|
623
638
|
logger$2.log(`👀 Watching for changes in: ${normalizedPatterns.join(", ")}`);
|
|
@@ -656,11 +671,16 @@ async function devCommand(options) {
|
|
|
656
671
|
}
|
|
657
672
|
}, 300);
|
|
658
673
|
});
|
|
659
|
-
|
|
674
|
+
let isShuttingDown = false;
|
|
675
|
+
const shutdown = () => {
|
|
676
|
+
if (isShuttingDown) return;
|
|
677
|
+
isShuttingDown = true;
|
|
660
678
|
logger$2.log("\n🛑 Shutting down...");
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
679
|
+
Promise.all([watcher.close(), devServer.stop()]).catch((err) => {
|
|
680
|
+
logger$2.error("Error during shutdown:", err);
|
|
681
|
+
}).finally(() => {
|
|
682
|
+
process.exit(0);
|
|
683
|
+
});
|
|
664
684
|
};
|
|
665
685
|
process.on("SIGINT", shutdown);
|
|
666
686
|
process.on("SIGTERM", shutdown);
|
|
@@ -738,26 +758,25 @@ var DevServer = class {
|
|
|
738
758
|
}
|
|
739
759
|
}
|
|
740
760
|
async stop() {
|
|
761
|
+
const port = this.actualPort;
|
|
741
762
|
if (this.serverProcess && this.isRunning) {
|
|
742
763
|
const pid = this.serverProcess.pid;
|
|
743
764
|
if (pid) try {
|
|
744
|
-
process.kill(-pid, "
|
|
745
|
-
} catch {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
} catch {}
|
|
751
|
-
resolve$1();
|
|
752
|
-
}, 3e3);
|
|
753
|
-
this.serverProcess?.on("exit", () => {
|
|
754
|
-
clearTimeout(timeout);
|
|
755
|
-
resolve$1();
|
|
756
|
-
});
|
|
757
|
-
});
|
|
765
|
+
process.kill(-pid, "SIGKILL");
|
|
766
|
+
} catch {
|
|
767
|
+
try {
|
|
768
|
+
process.kill(pid, "SIGKILL");
|
|
769
|
+
} catch {}
|
|
770
|
+
}
|
|
758
771
|
this.serverProcess = null;
|
|
759
772
|
this.isRunning = false;
|
|
760
773
|
}
|
|
774
|
+
this.killProcessesOnPort(port);
|
|
775
|
+
}
|
|
776
|
+
killProcessesOnPort(port) {
|
|
777
|
+
try {
|
|
778
|
+
execSync(`lsof -ti tcp:${port} | xargs kill -9 2>/dev/null || true`, { stdio: "ignore" });
|
|
779
|
+
} catch {}
|
|
761
780
|
}
|
|
762
781
|
async restart() {
|
|
763
782
|
const portToReuse = this.actualPort;
|
|
@@ -898,12 +917,15 @@ async function buildCommand(options) {
|
|
|
898
917
|
const { path: loggerPath, importPattern: loggerImportPattern } = parseModuleConfig(config$1.logger, "logger");
|
|
899
918
|
const telescope = normalizeTelescopeConfig(config$1.telescope);
|
|
900
919
|
if (telescope) logger.log(`🔭 Telescope enabled at ${telescope.path}`);
|
|
920
|
+
const hooks = normalizeHooksConfig(config$1.hooks);
|
|
921
|
+
if (hooks) logger.log(`🪝 Server hooks enabled`);
|
|
901
922
|
const buildContext = {
|
|
902
923
|
envParserPath,
|
|
903
924
|
envParserImportPattern,
|
|
904
925
|
loggerPath,
|
|
905
926
|
loggerImportPattern,
|
|
906
|
-
telescope
|
|
927
|
+
telescope,
|
|
928
|
+
hooks
|
|
907
929
|
};
|
|
908
930
|
const endpointGenerator = new EndpointGenerator();
|
|
909
931
|
const functionGenerator = new FunctionGenerator();
|
|
@@ -2282,7 +2304,7 @@ export const telescope = new Telescope({
|
|
|
2282
2304
|
/**
|
|
2283
2305
|
* OpenAPI output path (fixed, not configurable)
|
|
2284
2306
|
*/
|
|
2285
|
-
const OPENAPI_OUTPUT_PATH = "./.gkm/openapi.ts";
|
|
2307
|
+
const OPENAPI_OUTPUT_PATH$1 = "./.gkm/openapi.ts";
|
|
2286
2308
|
/**
|
|
2287
2309
|
* All available templates
|
|
2288
2310
|
*/
|
|
@@ -2399,8 +2421,8 @@ function generatePackageJson(options, template) {
|
|
|
2399
2421
|
private: true,
|
|
2400
2422
|
type: "module",
|
|
2401
2423
|
exports: { "./client": {
|
|
2402
|
-
types: OPENAPI_OUTPUT_PATH,
|
|
2403
|
-
import: OPENAPI_OUTPUT_PATH
|
|
2424
|
+
types: OPENAPI_OUTPUT_PATH$1,
|
|
2425
|
+
import: OPENAPI_OUTPUT_PATH$1
|
|
2404
2426
|
} },
|
|
2405
2427
|
scripts: scripts$1,
|
|
2406
2428
|
dependencies: sortObject(dependencies$1),
|