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