@geekmidas/cli 0.9.0 → 0.12.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.
Files changed (146) hide show
  1. package/README.md +525 -0
  2. package/dist/bundler-DRXCw_YR.mjs +70 -0
  3. package/dist/bundler-DRXCw_YR.mjs.map +1 -0
  4. package/dist/bundler-WsEvH_b2.cjs +71 -0
  5. package/dist/bundler-WsEvH_b2.cjs.map +1 -0
  6. package/dist/{config-CFls09Ey.cjs → config-AmInkU7k.cjs} +10 -8
  7. package/dist/config-AmInkU7k.cjs.map +1 -0
  8. package/dist/{config-Bq72aj8e.mjs → config-DYULeEv8.mjs} +6 -4
  9. package/dist/config-DYULeEv8.mjs.map +1 -0
  10. package/dist/config.cjs +1 -1
  11. package/dist/config.d.cts +2 -1
  12. package/dist/config.d.cts.map +1 -0
  13. package/dist/config.d.mts +2 -1
  14. package/dist/config.d.mts.map +1 -0
  15. package/dist/config.mjs +1 -1
  16. package/dist/encryption-C8H-38Yy.mjs +42 -0
  17. package/dist/encryption-C8H-38Yy.mjs.map +1 -0
  18. package/dist/encryption-Dyf_r1h-.cjs +44 -0
  19. package/dist/encryption-Dyf_r1h-.cjs.map +1 -0
  20. package/dist/index.cjs +2125 -184
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.mjs +2143 -197
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/{openapi--vOy9mo4.mjs → openapi-BfFlOBCG.mjs} +812 -49
  25. package/dist/openapi-BfFlOBCG.mjs.map +1 -0
  26. package/dist/{openapi-CHhTPief.cjs → openapi-Bt_1FDpT.cjs} +805 -42
  27. package/dist/openapi-Bt_1FDpT.cjs.map +1 -0
  28. package/dist/{openapi-react-query-o5iMi8tz.cjs → openapi-react-query-B-sNWHFU.cjs} +5 -5
  29. package/dist/openapi-react-query-B-sNWHFU.cjs.map +1 -0
  30. package/dist/{openapi-react-query-CcciaVu5.mjs → openapi-react-query-B6XTeGqS.mjs} +5 -5
  31. package/dist/openapi-react-query-B6XTeGqS.mjs.map +1 -0
  32. package/dist/openapi-react-query.cjs +1 -1
  33. package/dist/openapi-react-query.d.cts.map +1 -0
  34. package/dist/openapi-react-query.d.mts.map +1 -0
  35. package/dist/openapi-react-query.mjs +1 -1
  36. package/dist/openapi.cjs +2 -2
  37. package/dist/openapi.d.cts +1 -1
  38. package/dist/openapi.d.cts.map +1 -0
  39. package/dist/openapi.d.mts +1 -1
  40. package/dist/openapi.d.mts.map +1 -0
  41. package/dist/openapi.mjs +2 -2
  42. package/dist/storage-BUYQJgz7.cjs +4 -0
  43. package/dist/storage-BXoJvmv2.cjs +149 -0
  44. package/dist/storage-BXoJvmv2.cjs.map +1 -0
  45. package/dist/storage-C9PU_30f.mjs +101 -0
  46. package/dist/storage-C9PU_30f.mjs.map +1 -0
  47. package/dist/storage-DLJAYxzJ.mjs +3 -0
  48. package/dist/{types-b-vwGpqc.d.cts → types-BR0M2v_c.d.mts} +100 -1
  49. package/dist/types-BR0M2v_c.d.mts.map +1 -0
  50. package/dist/{types-DXgiA1sF.d.mts → types-BhkZc-vm.d.cts} +100 -1
  51. package/dist/types-BhkZc-vm.d.cts.map +1 -0
  52. package/examples/cron-example.ts +27 -27
  53. package/examples/env.ts +27 -27
  54. package/examples/function-example.ts +31 -31
  55. package/examples/gkm.config.json +20 -20
  56. package/examples/gkm.config.ts +8 -8
  57. package/examples/gkm.minimal.config.json +5 -5
  58. package/examples/gkm.production.config.json +25 -25
  59. package/examples/logger.ts +2 -2
  60. package/package.json +6 -6
  61. package/src/__tests__/EndpointGenerator.hooks.spec.ts +191 -191
  62. package/src/__tests__/config.spec.ts +55 -55
  63. package/src/__tests__/loadEnvFiles.spec.ts +93 -93
  64. package/src/__tests__/normalizeHooksConfig.spec.ts +58 -58
  65. package/src/__tests__/openapi-react-query.spec.ts +497 -497
  66. package/src/__tests__/openapi.spec.ts +428 -428
  67. package/src/__tests__/test-helpers.ts +77 -76
  68. package/src/auth/__tests__/credentials.spec.ts +204 -0
  69. package/src/auth/__tests__/index.spec.ts +168 -0
  70. package/src/auth/credentials.ts +187 -0
  71. package/src/auth/index.ts +226 -0
  72. package/src/build/__tests__/index-new.spec.ts +474 -474
  73. package/src/build/__tests__/manifests.spec.ts +333 -333
  74. package/src/build/bundler.ts +141 -0
  75. package/src/build/endpoint-analyzer.ts +236 -0
  76. package/src/build/handler-templates.ts +1253 -0
  77. package/src/build/index.ts +250 -179
  78. package/src/build/manifests.ts +52 -52
  79. package/src/build/providerResolver.ts +145 -145
  80. package/src/build/types.ts +64 -43
  81. package/src/config.ts +39 -37
  82. package/src/deploy/__tests__/docker.spec.ts +111 -0
  83. package/src/deploy/__tests__/dokploy.spec.ts +245 -0
  84. package/src/deploy/__tests__/init.spec.ts +662 -0
  85. package/src/deploy/docker.ts +128 -0
  86. package/src/deploy/dokploy.ts +204 -0
  87. package/src/deploy/index.ts +136 -0
  88. package/src/deploy/init.ts +484 -0
  89. package/src/deploy/types.ts +48 -0
  90. package/src/dev/__tests__/index.spec.ts +266 -266
  91. package/src/dev/index.ts +647 -593
  92. package/src/docker/__tests__/compose.spec.ts +531 -0
  93. package/src/docker/__tests__/templates.spec.ts +280 -0
  94. package/src/docker/compose.ts +273 -0
  95. package/src/docker/index.ts +230 -0
  96. package/src/docker/templates.ts +446 -0
  97. package/src/generators/CronGenerator.ts +72 -72
  98. package/src/generators/EndpointGenerator.ts +699 -398
  99. package/src/generators/FunctionGenerator.ts +84 -84
  100. package/src/generators/Generator.ts +72 -72
  101. package/src/generators/OpenApiTsGenerator.ts +589 -589
  102. package/src/generators/SubscriberGenerator.ts +124 -124
  103. package/src/generators/__tests__/CronGenerator.spec.ts +433 -433
  104. package/src/generators/__tests__/EndpointGenerator.spec.ts +532 -382
  105. package/src/generators/__tests__/FunctionGenerator.spec.ts +244 -244
  106. package/src/generators/__tests__/SubscriberGenerator.spec.ts +397 -382
  107. package/src/generators/index.ts +4 -4
  108. package/src/index.ts +628 -206
  109. package/src/init/__tests__/generators.spec.ts +334 -334
  110. package/src/init/__tests__/init.spec.ts +332 -332
  111. package/src/init/__tests__/utils.spec.ts +89 -89
  112. package/src/init/generators/config.ts +175 -175
  113. package/src/init/generators/docker.ts +41 -41
  114. package/src/init/generators/env.ts +72 -72
  115. package/src/init/generators/index.ts +1 -1
  116. package/src/init/generators/models.ts +64 -64
  117. package/src/init/generators/monorepo.ts +161 -161
  118. package/src/init/generators/package.ts +71 -71
  119. package/src/init/generators/source.ts +6 -6
  120. package/src/init/index.ts +203 -208
  121. package/src/init/templates/api.ts +115 -115
  122. package/src/init/templates/index.ts +75 -75
  123. package/src/init/templates/minimal.ts +98 -98
  124. package/src/init/templates/serverless.ts +89 -89
  125. package/src/init/templates/worker.ts +98 -98
  126. package/src/init/utils.ts +54 -56
  127. package/src/openapi-react-query.ts +194 -194
  128. package/src/openapi.ts +63 -63
  129. package/src/secrets/__tests__/encryption.spec.ts +226 -0
  130. package/src/secrets/__tests__/generator.spec.ts +319 -0
  131. package/src/secrets/__tests__/index.spec.ts +91 -0
  132. package/src/secrets/__tests__/storage.spec.ts +403 -0
  133. package/src/secrets/encryption.ts +91 -0
  134. package/src/secrets/generator.ts +164 -0
  135. package/src/secrets/index.ts +383 -0
  136. package/src/secrets/storage.ts +134 -0
  137. package/src/secrets/types.ts +53 -0
  138. package/src/types.ts +295 -176
  139. package/tsconfig.json +9 -0
  140. package/tsdown.config.ts +11 -8
  141. package/dist/config-Bq72aj8e.mjs.map +0 -1
  142. package/dist/config-CFls09Ey.cjs.map +0 -1
  143. package/dist/openapi--vOy9mo4.mjs.map +0 -1
  144. package/dist/openapi-CHhTPief.cjs.map +0 -1
  145. package/dist/openapi-react-query-CcciaVu5.mjs.map +0 -1
  146. package/dist/openapi-react-query-o5iMi8tz.cjs.map +0 -1
@@ -1,68 +1,68 @@
1
1
  import type {
2
- GeneratedFile,
3
- TemplateConfig,
4
- TemplateOptions,
2
+ GeneratedFile,
3
+ TemplateConfig,
4
+ TemplateOptions,
5
5
  } from './index.js';
6
6
 
7
7
  export const workerTemplate: TemplateConfig = {
8
- name: 'worker',
9
- description: 'Background job processing',
10
-
11
- dependencies: {
12
- '@geekmidas/constructs': 'workspace:*',
13
- '@geekmidas/envkit': 'workspace:*',
14
- '@geekmidas/logger': 'workspace:*',
15
- '@geekmidas/events': 'workspace:*',
16
- hono: '~4.8.2',
17
- pino: '~9.6.0',
18
- },
19
-
20
- devDependencies: {
21
- '@biomejs/biome': '~1.9.4',
22
- '@geekmidas/cli': 'workspace:*',
23
- '@types/node': '~22.0.0',
24
- tsx: '~4.20.0',
25
- turbo: '~2.3.0',
26
- typescript: '~5.8.2',
27
- vitest: '~4.0.0',
28
- },
29
-
30
- scripts: {
31
- dev: 'gkm dev',
32
- build: 'gkm build',
33
- test: 'vitest',
34
- 'test:once': 'vitest run',
35
- typecheck: 'tsc --noEmit',
36
- lint: 'biome lint .',
37
- fmt: 'biome format . --write',
38
- 'fmt:check': 'biome format .',
39
- },
40
-
41
- files: (options: TemplateOptions): GeneratedFile[] => {
42
- const { loggerType, routesStructure } = options;
43
-
44
- const loggerContent = `import { createLogger } from '@geekmidas/logger/${loggerType}';
8
+ name: 'worker',
9
+ description: 'Background job processing',
10
+
11
+ dependencies: {
12
+ '@geekmidas/constructs': 'workspace:*',
13
+ '@geekmidas/envkit': 'workspace:*',
14
+ '@geekmidas/logger': 'workspace:*',
15
+ '@geekmidas/events': 'workspace:*',
16
+ hono: '~4.8.2',
17
+ pino: '~9.6.0',
18
+ },
19
+
20
+ devDependencies: {
21
+ '@biomejs/biome': '~1.9.4',
22
+ '@geekmidas/cli': 'workspace:*',
23
+ '@types/node': '~22.0.0',
24
+ tsx: '~4.20.0',
25
+ turbo: '~2.3.0',
26
+ typescript: '~5.8.2',
27
+ vitest: '~4.0.0',
28
+ },
29
+
30
+ scripts: {
31
+ dev: 'gkm dev',
32
+ build: 'gkm build',
33
+ test: 'vitest',
34
+ 'test:once': 'vitest run',
35
+ typecheck: 'tsc --noEmit',
36
+ lint: 'biome lint .',
37
+ fmt: 'biome format . --write',
38
+ 'fmt:check': 'biome format .',
39
+ },
40
+
41
+ files: (options: TemplateOptions): GeneratedFile[] => {
42
+ const { loggerType, routesStructure } = options;
43
+
44
+ const loggerContent = `import { createLogger } from '@geekmidas/logger/${loggerType}';
45
45
 
46
46
  export const logger = createLogger();
47
47
  `;
48
48
 
49
- // Get route path based on structure
50
- const getRoutePath = (file: string) => {
51
- switch (routesStructure) {
52
- case 'centralized-endpoints':
53
- return `src/endpoints/${file}`;
54
- case 'centralized-routes':
55
- return `src/routes/${file}`;
56
- case 'domain-based':
57
- return `src/${file.replace('.ts', '')}/routes/index.ts`;
58
- }
59
- };
60
-
61
- const files: GeneratedFile[] = [
62
- // src/config/env.ts
63
- {
64
- path: 'src/config/env.ts',
65
- content: `import { EnvironmentParser } from '@geekmidas/envkit';
49
+ // Get route path based on structure
50
+ const getRoutePath = (file: string) => {
51
+ switch (routesStructure) {
52
+ case 'centralized-endpoints':
53
+ return `src/endpoints/${file}`;
54
+ case 'centralized-routes':
55
+ return `src/routes/${file}`;
56
+ case 'domain-based':
57
+ return `src/${file.replace('.ts', '')}/routes/index.ts`;
58
+ }
59
+ };
60
+
61
+ const files: GeneratedFile[] = [
62
+ // src/config/env.ts
63
+ {
64
+ path: 'src/config/env.ts',
65
+ content: `import { EnvironmentParser } from '@geekmidas/envkit';
66
66
 
67
67
  export const envParser = new EnvironmentParser(process.env);
68
68
 
@@ -73,28 +73,28 @@ export const config = envParser
73
73
  rabbitmq: {
74
74
  url: get('RABBITMQ_URL').string().default('amqp://localhost:5672'),
75
75
  },${
76
- options.database
77
- ? `
76
+ options.database
77
+ ? `
78
78
  database: {
79
79
  url: get('DATABASE_URL').string().default('postgresql://localhost:5432/mydb'),
80
80
  },`
81
- : ''
82
- }
81
+ : ''
82
+ }
83
83
  }))
84
84
  .parse();
85
85
  `,
86
- },
86
+ },
87
87
 
88
- // src/config/logger.ts
89
- {
90
- path: 'src/config/logger.ts',
91
- content: loggerContent,
92
- },
88
+ // src/config/logger.ts
89
+ {
90
+ path: 'src/config/logger.ts',
91
+ content: loggerContent,
92
+ },
93
93
 
94
- // health endpoint
95
- {
96
- path: getRoutePath('health.ts'),
97
- content: `import { e } from '@geekmidas/constructs/endpoints';
94
+ // health endpoint
95
+ {
96
+ path: getRoutePath('health.ts'),
97
+ content: `import { e } from '@geekmidas/constructs/endpoints';
98
98
 
99
99
  export default e
100
100
  .get('/health')
@@ -103,12 +103,12 @@ export default e
103
103
  timestamp: new Date().toISOString(),
104
104
  }));
105
105
  `,
106
- },
106
+ },
107
107
 
108
- // src/events/types.ts
109
- {
110
- path: 'src/events/types.ts',
111
- content: `import type { PublishableMessage } from '@geekmidas/events';
108
+ // src/events/types.ts
109
+ {
110
+ path: 'src/events/types.ts',
111
+ content: `import type { PublishableMessage } from '@geekmidas/events';
112
112
 
113
113
  // Define your event types here
114
114
  export type AppEvents =
@@ -116,12 +116,12 @@ export type AppEvents =
116
116
  | PublishableMessage<'user.updated', { userId: string; changes: Record<string, unknown> }>
117
117
  | PublishableMessage<'order.placed', { orderId: string; userId: string; total: number }>;
118
118
  `,
119
- },
119
+ },
120
120
 
121
- // src/subscribers/user-events.ts
122
- {
123
- path: 'src/subscribers/user-events.ts',
124
- content: `import { s } from '@geekmidas/constructs/subscribers';
121
+ // src/subscribers/user-events.ts
122
+ {
123
+ path: 'src/subscribers/user-events.ts',
124
+ content: `import { s } from '@geekmidas/constructs/subscribers';
125
125
  import type { AppEvents } from '../events/types.js';
126
126
 
127
127
  export default s<AppEvents>()
@@ -141,12 +141,12 @@ export default s<AppEvents>()
141
141
  }
142
142
  });
143
143
  `,
144
- },
144
+ },
145
145
 
146
- // src/crons/cleanup.ts
147
- {
148
- path: 'src/crons/cleanup.ts',
149
- content: `import { cron } from '@geekmidas/constructs/crons';
146
+ // src/crons/cleanup.ts
147
+ {
148
+ path: 'src/crons/cleanup.ts',
149
+ content: `import { cron } from '@geekmidas/constructs/crons';
150
150
 
151
151
  // Run every day at midnight
152
152
  export default cron('0 0 * * *')
@@ -159,14 +159,14 @@ export default cron('0 0 * * *')
159
159
  logger.info('Cleanup job completed');
160
160
  });
161
161
  `,
162
- },
163
- ];
164
-
165
- // Add Telescope config if enabled
166
- if (options.telescope) {
167
- files.push({
168
- path: 'src/config/telescope.ts',
169
- content: `import { Telescope } from '@geekmidas/telescope';
162
+ },
163
+ ];
164
+
165
+ // Add Telescope config if enabled
166
+ if (options.telescope) {
167
+ files.push({
168
+ path: 'src/config/telescope.ts',
169
+ content: `import { Telescope } from '@geekmidas/telescope';
170
170
  import { InMemoryStorage } from '@geekmidas/telescope/storage/memory';
171
171
 
172
172
  export const telescope = new Telescope({
@@ -174,9 +174,9 @@ export const telescope = new Telescope({
174
174
  enabled: process.env.NODE_ENV === 'development',
175
175
  });
176
176
  `,
177
- });
178
- }
177
+ });
178
+ }
179
179
 
180
- return files;
181
- },
180
+ return files;
181
+ },
182
182
  };
package/src/init/utils.ts CHANGED
@@ -7,92 +7,90 @@ export type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
7
7
  * Detect the package manager being used based on lockfiles or npm_config_user_agent
8
8
  */
9
9
  export function detectPackageManager(
10
- cwd: string = process.cwd(),
10
+ cwd: string = process.cwd(),
11
11
  ): PackageManager {
12
- // Check for lockfiles in cwd
13
- if (existsSync(join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
14
- if (existsSync(join(cwd, 'yarn.lock'))) return 'yarn';
15
- if (existsSync(join(cwd, 'bun.lockb'))) return 'bun';
16
- if (existsSync(join(cwd, 'package-lock.json'))) return 'npm';
12
+ // Check for lockfiles in cwd
13
+ if (existsSync(join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
14
+ if (existsSync(join(cwd, 'yarn.lock'))) return 'yarn';
15
+ if (existsSync(join(cwd, 'bun.lockb'))) return 'bun';
16
+ if (existsSync(join(cwd, 'package-lock.json'))) return 'npm';
17
17
 
18
- // Check npm_config_user_agent (set when running via npx/pnpm dlx/etc)
19
- const userAgent = process.env.npm_config_user_agent || '';
20
- if (userAgent.includes('pnpm')) return 'pnpm';
21
- if (userAgent.includes('yarn')) return 'yarn';
22
- if (userAgent.includes('bun')) return 'bun';
18
+ // Check npm_config_user_agent (set when running via npx/pnpm dlx/etc)
19
+ const userAgent = process.env.npm_config_user_agent || '';
20
+ if (userAgent.includes('pnpm')) return 'pnpm';
21
+ if (userAgent.includes('yarn')) return 'yarn';
22
+ if (userAgent.includes('bun')) return 'bun';
23
23
 
24
- return 'npm';
24
+ return 'npm';
25
25
  }
26
26
 
27
27
  /**
28
28
  * Validate project name for npm package naming conventions
29
29
  */
30
30
  export function validateProjectName(name: string): boolean | string {
31
- if (!name) {
32
- return 'Project name is required';
33
- }
31
+ if (!name) {
32
+ return 'Project name is required';
33
+ }
34
34
 
35
- // Check for valid npm package name characters
36
- if (!/^[a-z0-9-_@/.]+$/i.test(name)) {
37
- return 'Project name can only contain letters, numbers, hyphens, underscores, @, /, and .';
38
- }
35
+ // Check for valid npm package name characters
36
+ if (!/^[a-z0-9-_@/.]+$/i.test(name)) {
37
+ return 'Project name can only contain letters, numbers, hyphens, underscores, @, /, and .';
38
+ }
39
39
 
40
- // Check for reserved names
41
- const reserved = ['node_modules', '.git', 'package.json', 'src'];
42
- if (reserved.includes(name.toLowerCase())) {
43
- return `"${name}" is a reserved name`;
44
- }
40
+ // Check for reserved names
41
+ const reserved = ['node_modules', '.git', 'package.json', 'src'];
42
+ if (reserved.includes(name.toLowerCase())) {
43
+ return `"${name}" is a reserved name`;
44
+ }
45
45
 
46
- return true;
46
+ return true;
47
47
  }
48
48
 
49
49
  /**
50
50
  * Check if a directory already exists at the target path
51
51
  */
52
52
  export function checkDirectoryExists(
53
- name: string,
54
- cwd: string = process.cwd(),
53
+ name: string,
54
+ cwd: string = process.cwd(),
55
55
  ): boolean | string {
56
- const targetPath = join(cwd, name);
57
- if (existsSync(targetPath)) {
58
- return `Directory "${name}" already exists`;
59
- }
60
- return true;
56
+ const targetPath = join(cwd, name);
57
+ if (existsSync(targetPath)) {
58
+ return `Directory "${name}" already exists`;
59
+ }
60
+ return true;
61
61
  }
62
62
 
63
63
  /**
64
64
  * Get the install command for a package manager
65
65
  */
66
66
  export function getInstallCommand(pkgManager: PackageManager): string {
67
- switch (pkgManager) {
68
- case 'pnpm':
69
- return 'pnpm install';
70
- case 'yarn':
71
- return 'yarn';
72
- case 'bun':
73
- return 'bun install';
74
- case 'npm':
75
- default:
76
- return 'npm install';
77
- }
67
+ switch (pkgManager) {
68
+ case 'pnpm':
69
+ return 'pnpm install';
70
+ case 'yarn':
71
+ return 'yarn';
72
+ case 'bun':
73
+ return 'bun install';
74
+ default:
75
+ return 'npm install';
76
+ }
78
77
  }
79
78
 
80
79
  /**
81
80
  * Get the dev command for a package manager
82
81
  */
83
82
  export function getRunCommand(
84
- pkgManager: PackageManager,
85
- script: string,
83
+ pkgManager: PackageManager,
84
+ script: string,
86
85
  ): string {
87
- switch (pkgManager) {
88
- case 'pnpm':
89
- return `pnpm ${script}`;
90
- case 'yarn':
91
- return `yarn ${script}`;
92
- case 'bun':
93
- return `bun run ${script}`;
94
- case 'npm':
95
- default:
96
- return `npm run ${script}`;
97
- }
86
+ switch (pkgManager) {
87
+ case 'pnpm':
88
+ return `pnpm ${script}`;
89
+ case 'yarn':
90
+ return `yarn ${script}`;
91
+ case 'bun':
92
+ return `bun run ${script}`;
93
+ default:
94
+ return `npm run ${script}`;
95
+ }
98
96
  }