@geekmidas/cli 0.23.0 → 0.25.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,7 +1,7 @@
1
1
  #!/usr/bin/env -S npx tsx
2
2
  import { __require, getAppBuildOrder, getDependencyEnvVars, getDeployTargetError, isDeployTargetSupported } from "./workspace-CPLEZDZf.mjs";
3
- import { loadConfig, loadWorkspaceConfig, parseModuleConfig } from "./config-BaYqrF3n.mjs";
4
- import { ConstructGenerator, EndpointGenerator, OPENAPI_OUTPUT_PATH, OpenApiTsGenerator, generateOpenApi, openapiCommand, resolveOpenApiConfig } from "./openapi-CgqR6Jkw.mjs";
3
+ import { getAppNameFromCwd, loadAppConfig, loadConfig, loadWorkspaceConfig, parseModuleConfig } from "./config-BogU0_oQ.mjs";
4
+ import { ConstructGenerator, EndpointGenerator, OPENAPI_OUTPUT_PATH, OpenApiTsGenerator, generateOpenApi, openapiCommand, resolveOpenApiConfig } from "./openapi-DNbXfhXE.mjs";
5
5
  import { getKeyPath, maskPassword, readStageSecrets, secretsExist, setCustomSecret, toEmbeddableSecrets, writeStageSecrets } from "./storage-Dhst7BhI.mjs";
6
6
  import { DokployApi } from "./dokploy-api-B9qR2Yn1.mjs";
7
7
  import { generateReactQueryCommand } from "./openapi-react-query-5rSortLH.mjs";
@@ -26,7 +26,7 @@ import prompts from "prompts";
26
26
 
27
27
  //#region package.json
28
28
  var name = "@geekmidas/cli";
29
- var version = "0.23.0";
29
+ var version = "0.25.0";
30
30
  var description = "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs";
31
31
  var private$1 = false;
32
32
  var type = "module";
@@ -976,10 +976,10 @@ function normalizeStudioConfig(config$1) {
976
976
  * Normalize hooks configuration
977
977
  * @internal Exported for testing
978
978
  */
979
- function normalizeHooksConfig(config$1) {
979
+ function normalizeHooksConfig(config$1, cwd = process.cwd()) {
980
980
  if (!config$1?.server) return void 0;
981
981
  const serverPath = config$1.server.endsWith(".ts") ? config$1.server : `${config$1.server}.ts`;
982
- const resolvedPath = resolve(process.cwd(), serverPath);
982
+ const resolvedPath = resolve(cwd, serverPath);
983
983
  return { serverHooksPath: resolvedPath };
984
984
  }
985
985
  /**
@@ -1013,14 +1013,32 @@ function getProductionConfigFromGkm(config$1) {
1013
1013
  async function devCommand(options) {
1014
1014
  const defaultEnv = loadEnvFiles(".env");
1015
1015
  if (defaultEnv.loaded.length > 0) logger$8.log(`📦 Loaded env: ${defaultEnv.loaded.join(", ")}`);
1016
- const loadedConfig = await loadWorkspaceConfig();
1017
- if (loadedConfig.type === "workspace") {
1018
- logger$8.log("📦 Detected workspace configuration");
1019
- return workspaceDevCommand(loadedConfig.workspace, options);
1016
+ const appName = getAppNameFromCwd();
1017
+ let config$1;
1018
+ let appRoot = process.cwd();
1019
+ if (appName) try {
1020
+ const appConfig = await loadAppConfig();
1021
+ config$1 = appConfig.gkmConfig;
1022
+ appRoot = appConfig.appRoot;
1023
+ logger$8.log(`📦 Running app: ${appConfig.appName}`);
1024
+ } catch {
1025
+ const loadedConfig = await loadWorkspaceConfig();
1026
+ if (loadedConfig.type === "workspace") {
1027
+ logger$8.log("📦 Detected workspace configuration");
1028
+ return workspaceDevCommand(loadedConfig.workspace, options);
1029
+ }
1030
+ config$1 = loadedConfig.raw;
1031
+ }
1032
+ else {
1033
+ const loadedConfig = await loadWorkspaceConfig();
1034
+ if (loadedConfig.type === "workspace") {
1035
+ logger$8.log("📦 Detected workspace configuration");
1036
+ return workspaceDevCommand(loadedConfig.workspace, options);
1037
+ }
1038
+ config$1 = loadedConfig.raw;
1020
1039
  }
1021
- const config$1 = loadedConfig.raw;
1022
1040
  if (config$1.env) {
1023
- const { loaded, missing } = loadEnvFiles(config$1.env);
1041
+ const { loaded, missing } = loadEnvFiles(config$1.env, appRoot);
1024
1042
  if (loaded.length > 0) logger$8.log(`📦 Loaded env: ${loaded.join(", ")}`);
1025
1043
  if (missing.length > 0) logger$8.warn(`⚠️ Missing env files: ${missing.join(", ")}`);
1026
1044
  }
@@ -1037,7 +1055,7 @@ async function devCommand(options) {
1037
1055
  if (telescope) logger$8.log(`🔭 Telescope enabled at ${telescope.path}`);
1038
1056
  const studio = normalizeStudioConfig(config$1.studio);
1039
1057
  if (studio) logger$8.log(`🗄️ Studio enabled at ${studio.path}`);
1040
- const hooks = normalizeHooksConfig(config$1.hooks);
1058
+ const hooks = normalizeHooksConfig(config$1.hooks, appRoot);
1041
1059
  if (hooks) logger$8.log(`🪝 Server hooks enabled from ${config$1.hooks?.server}`);
1042
1060
  const openApiConfig = resolveOpenApiConfig(config$1);
1043
1061
  const enableOpenApi = openApiConfig.enabled || resolved.enableOpenApi;
@@ -1051,10 +1069,10 @@ async function devCommand(options) {
1051
1069
  studio,
1052
1070
  hooks
1053
1071
  };
1054
- await buildServer(config$1, buildContext, resolved.providers[0], enableOpenApi);
1072
+ await buildServer(config$1, buildContext, resolved.providers[0], enableOpenApi, appRoot);
1055
1073
  if (enableOpenApi) await generateOpenApi(config$1);
1056
1074
  const runtime = config$1.runtime ?? "node";
1057
- const devServer = new DevServer(resolved.providers[0], options.port || 3e3, options.portExplicit ?? false, enableOpenApi, telescope, studio, runtime);
1075
+ const devServer = new DevServer(resolved.providers[0], options.port || 3e3, options.portExplicit ?? false, enableOpenApi, telescope, studio, runtime, appRoot);
1058
1076
  await devServer.start();
1059
1077
  const envParserFile = config$1.envParser.split("#")[0] ?? config$1.envParser;
1060
1078
  const loggerFile = config$1.logger.split("#")[0] ?? config$1.logger;
@@ -1072,7 +1090,7 @@ async function devCommand(options) {
1072
1090
  const normalizedPatterns = watchPatterns.map((p) => p.startsWith("./") ? p.slice(2) : p);
1073
1091
  logger$8.log(`👀 Watching for changes in: ${normalizedPatterns.join(", ")}`);
1074
1092
  const resolvedFiles = await fg(normalizedPatterns, {
1075
- cwd: process.cwd(),
1093
+ cwd: appRoot,
1076
1094
  absolute: false,
1077
1095
  onlyFiles: true
1078
1096
  });
@@ -1085,7 +1103,7 @@ async function devCommand(options) {
1085
1103
  ignored: /(^|[/\\])\../,
1086
1104
  persistent: true,
1087
1105
  ignoreInitial: true,
1088
- cwd: process.cwd()
1106
+ cwd: appRoot
1089
1107
  });
1090
1108
  watcher.on("ready", () => {
1091
1109
  logger$8.log("🔍 File watcher ready");
@@ -1100,7 +1118,7 @@ async function devCommand(options) {
1100
1118
  rebuildTimeout = setTimeout(async () => {
1101
1119
  try {
1102
1120
  logger$8.log("🔄 Rebuilding...");
1103
- await buildServer(config$1, buildContext, resolved.providers[0], enableOpenApi);
1121
+ await buildServer(config$1, buildContext, resolved.providers[0], enableOpenApi, appRoot);
1104
1122
  if (enableOpenApi) await generateOpenApi(config$1, { silent: true });
1105
1123
  logger$8.log("✅ Rebuild complete, restarting server...");
1106
1124
  await devServer.restart();
@@ -1322,11 +1340,25 @@ async function workspaceDevCommand(workspace, options) {
1322
1340
  const deps = app.dependencies.length > 0 ? ` (depends on: ${app.dependencies.join(", ")})` : "";
1323
1341
  logger$8.log(` ${app.type === "backend" ? "🔧" : "🌐"} ${appName} → http://localhost:${app.port}${deps}`);
1324
1342
  }
1343
+ const configFiles = [
1344
+ "gkm.config.ts",
1345
+ "gkm.config.js",
1346
+ "gkm.config.json"
1347
+ ];
1348
+ let configPath = "";
1349
+ for (const file of configFiles) {
1350
+ const fullPath = join(workspace.root, file);
1351
+ if (existsSync(fullPath)) {
1352
+ configPath = fullPath;
1353
+ break;
1354
+ }
1355
+ }
1325
1356
  const turboEnv = {
1326
1357
  ...process.env,
1327
1358
  ...secretsEnv,
1328
1359
  ...dependencyEnv,
1329
- NODE_ENV: "development"
1360
+ NODE_ENV: "development",
1361
+ ...configPath ? { GKM_CONFIG_PATH: configPath } : {}
1330
1362
  };
1331
1363
  logger$8.log("\n🏃 Starting turbo run dev...\n");
1332
1364
  const turboProcess = spawn("pnpm", [
@@ -1429,18 +1461,18 @@ async function workspaceDevCommand(workspace, options) {
1429
1461
  });
1430
1462
  });
1431
1463
  }
1432
- async function buildServer(config$1, context, provider, enableOpenApi) {
1464
+ async function buildServer(config$1, context, provider, enableOpenApi, appRoot = process.cwd()) {
1433
1465
  const endpointGenerator = new EndpointGenerator();
1434
1466
  const functionGenerator = new FunctionGenerator();
1435
1467
  const cronGenerator = new CronGenerator();
1436
1468
  const subscriberGenerator = new SubscriberGenerator();
1437
1469
  const [allEndpoints, allFunctions, allCrons, allSubscribers] = await Promise.all([
1438
- endpointGenerator.load(config$1.routes),
1439
- config$1.functions ? functionGenerator.load(config$1.functions) : [],
1440
- config$1.crons ? cronGenerator.load(config$1.crons) : [],
1441
- config$1.subscribers ? subscriberGenerator.load(config$1.subscribers) : []
1470
+ endpointGenerator.load(config$1.routes, appRoot),
1471
+ config$1.functions ? functionGenerator.load(config$1.functions, appRoot) : [],
1472
+ config$1.crons ? cronGenerator.load(config$1.crons, appRoot) : [],
1473
+ config$1.subscribers ? subscriberGenerator.load(config$1.subscribers, appRoot) : []
1442
1474
  ]);
1443
- const outputDir = join(process.cwd(), ".gkm", provider);
1475
+ const outputDir = join(appRoot, ".gkm", provider);
1444
1476
  await mkdir(outputDir, { recursive: true });
1445
1477
  await Promise.all([
1446
1478
  endpointGenerator.build(context, allEndpoints, outputDir, {
@@ -1456,7 +1488,7 @@ var DevServer = class {
1456
1488
  serverProcess = null;
1457
1489
  isRunning = false;
1458
1490
  actualPort;
1459
- constructor(provider, requestedPort, portExplicit, enableOpenApi, telescope, studio, runtime = "node") {
1491
+ constructor(provider, requestedPort, portExplicit, enableOpenApi, telescope, studio, runtime = "node", appRoot = process.cwd()) {
1460
1492
  this.provider = provider;
1461
1493
  this.requestedPort = requestedPort;
1462
1494
  this.portExplicit = portExplicit;
@@ -1464,6 +1496,7 @@ var DevServer = class {
1464
1496
  this.telescope = telescope;
1465
1497
  this.studio = studio;
1466
1498
  this.runtime = runtime;
1499
+ this.appRoot = appRoot;
1467
1500
  this.actualPort = requestedPort;
1468
1501
  }
1469
1502
  async start() {
@@ -1476,7 +1509,7 @@ var DevServer = class {
1476
1509
  this.actualPort = await findAvailablePort(this.requestedPort);
1477
1510
  if (this.actualPort !== this.requestedPort) logger$8.log(`ℹ️ Port ${this.requestedPort} was in use, using port ${this.actualPort} instead`);
1478
1511
  }
1479
- const serverEntryPath = join(process.cwd(), ".gkm", this.provider, "server.ts");
1512
+ const serverEntryPath = join(this.appRoot, ".gkm", this.provider, "server.ts");
1480
1513
  await this.createServerEntry();
1481
1514
  logger$8.log(`\n✨ Starting server on port ${this.actualPort}...`);
1482
1515
  this.serverProcess = spawn("npx", [
@@ -1544,7 +1577,7 @@ var DevServer = class {
1544
1577
  async createServerEntry() {
1545
1578
  const { writeFile: writeFile$1 } = await import("node:fs/promises");
1546
1579
  const { relative: relative$1, dirname: dirname$1 } = await import("node:path");
1547
- const serverPath = join(process.cwd(), ".gkm", this.provider, "server.ts");
1580
+ const serverPath = join(this.appRoot, ".gkm", this.provider, "server.ts");
1548
1581
  const relativeAppPath = relative$1(dirname$1(serverPath), join(dirname$1(serverPath), "app.js"));
1549
1582
  const serveCode = this.runtime === "bun" ? `Bun.serve({
1550
1583
  port,
@@ -3069,7 +3102,7 @@ async function workspaceDockerCommand(workspace, options) {
3069
3102
  * Get app name from package.json in the current working directory
3070
3103
  * Used for Dokploy app/project naming
3071
3104
  */
3072
- function getAppNameFromCwd() {
3105
+ function getAppNameFromCwd$1() {
3073
3106
  const packageJsonPath = join(process.cwd(), "package.json");
3074
3107
  if (!existsSync(packageJsonPath)) return void 0;
3075
3108
  try {
@@ -3187,7 +3220,7 @@ async function deployDocker(options) {
3187
3220
  */
3188
3221
  function resolveDockerConfig(config$1) {
3189
3222
  const projectName = getAppNameFromPackageJson() ?? "app";
3190
- const appName = getAppNameFromCwd() ?? projectName;
3223
+ const appName = getAppNameFromCwd$1() ?? projectName;
3191
3224
  const imageName = config$1.docker?.imageName ?? appName;
3192
3225
  return {
3193
3226
  registry: config$1.docker?.registry,
@@ -4223,7 +4256,14 @@ function rotateServicePassword(secrets, service) {
4223
4256
  //#endregion
4224
4257
  //#region src/init/versions.ts
4225
4258
  const require$1 = createRequire(import.meta.url);
4226
- const pkg = require$1("../package.json");
4259
+ function loadPackageJson() {
4260
+ try {
4261
+ return require$1("../package.json");
4262
+ } catch {
4263
+ return require$1("../../package.json");
4264
+ }
4265
+ }
4266
+ const pkg = loadPackageJson();
4227
4267
  /**
4228
4268
  * CLI version from package.json (used for scaffolded projects)
4229
4269
  */
@@ -4324,7 +4364,7 @@ export const logger = createLogger();
4324
4364
  `;
4325
4365
  const authTs = `import { betterAuth } from 'better-auth';
4326
4366
  import { magicLink } from 'better-auth/plugins';
4327
- import { Pool } from 'pg';
4367
+ import pg from 'pg';
4328
4368
  import { envParser } from './config/env.js';
4329
4369
  import { logger } from './config/logger.js';
4330
4370
 
@@ -4339,7 +4379,7 @@ const authConfig = envParser
4339
4379
  .parse();
4340
4380
 
4341
4381
  export const auth = betterAuth({
4342
- database: new Pool({
4382
+ database: new pg.Pool({
4343
4383
  connectionString: authConfig.databaseUrl,
4344
4384
  }),
4345
4385
  baseURL: authConfig.baseUrl,
@@ -4753,7 +4793,7 @@ function generateDockerFiles(options, template, dbApps) {
4753
4793
  retries: 5`);
4754
4794
  volumes.push(" rabbitmq_data:");
4755
4795
  }
4756
- if (options.services.mail) services.push(` mailpit:
4796
+ if (options.services?.mail) services.push(` mailpit:
4757
4797
  image: axllent/mailpit:latest
4758
4798
  container_name: ${options.name}-mailpit
4759
4799
  restart: unless-stopped
@@ -5304,10 +5344,12 @@ const apiTemplate = {
5304
5344
  dependencies: {
5305
5345
  "@geekmidas/constructs": GEEKMIDAS_VERSIONS["@geekmidas/constructs"],
5306
5346
  "@geekmidas/envkit": GEEKMIDAS_VERSIONS["@geekmidas/envkit"],
5347
+ "@geekmidas/events": GEEKMIDAS_VERSIONS["@geekmidas/events"],
5307
5348
  "@geekmidas/logger": GEEKMIDAS_VERSIONS["@geekmidas/logger"],
5308
5349
  "@geekmidas/services": GEEKMIDAS_VERSIONS["@geekmidas/services"],
5309
5350
  "@geekmidas/errors": GEEKMIDAS_VERSIONS["@geekmidas/errors"],
5310
5351
  "@geekmidas/auth": GEEKMIDAS_VERSIONS["@geekmidas/auth"],
5352
+ "@hono/node-server": "~1.14.1",
5311
5353
  hono: "~4.8.2",
5312
5354
  pino: "~9.6.0"
5313
5355
  },
@@ -5509,6 +5551,7 @@ const minimalTemplate = {
5509
5551
  "@geekmidas/constructs": GEEKMIDAS_VERSIONS["@geekmidas/constructs"],
5510
5552
  "@geekmidas/envkit": GEEKMIDAS_VERSIONS["@geekmidas/envkit"],
5511
5553
  "@geekmidas/logger": GEEKMIDAS_VERSIONS["@geekmidas/logger"],
5554
+ "@hono/node-server": "~1.14.1",
5512
5555
  hono: "~4.8.2",
5513
5556
  pino: "~9.6.0"
5514
5557
  },
@@ -5673,6 +5716,7 @@ const serverlessTemplate = {
5673
5716
  "@geekmidas/envkit": GEEKMIDAS_VERSIONS["@geekmidas/envkit"],
5674
5717
  "@geekmidas/logger": GEEKMIDAS_VERSIONS["@geekmidas/logger"],
5675
5718
  "@geekmidas/cloud": GEEKMIDAS_VERSIONS["@geekmidas/cloud"],
5719
+ "@hono/node-server": "~1.14.1",
5676
5720
  hono: "~4.8.2",
5677
5721
  pino: "~9.6.0"
5678
5722
  },
@@ -5784,6 +5828,7 @@ const workerTemplate = {
5784
5828
  "@geekmidas/envkit": GEEKMIDAS_VERSIONS["@geekmidas/envkit"],
5785
5829
  "@geekmidas/logger": GEEKMIDAS_VERSIONS["@geekmidas/logger"],
5786
5830
  "@geekmidas/events": GEEKMIDAS_VERSIONS["@geekmidas/events"],
5831
+ "@hono/node-server": "~1.14.1",
5787
5832
  hono: "~4.8.2",
5788
5833
  pino: "~9.6.0"
5789
5834
  },