@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/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-Mwy2_R4W.mjs";
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.7.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: ${openApiConfig.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
- const shutdown = async () => {
674
+ let isShuttingDown = false;
675
+ const shutdown = () => {
676
+ if (isShuttingDown) return;
677
+ isShuttingDown = true;
660
678
  logger$2.log("\n🛑 Shutting down...");
661
- await watcher.close();
662
- await devServer.stop();
663
- process.exit(0);
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, "SIGTERM");
745
- } catch {}
746
- await new Promise((resolve$1) => {
747
- const timeout = setTimeout(() => {
748
- if (pid) try {
749
- process.kill(-pid, "SIGKILL");
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),