@geekmidas/cli 0.10.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.
- package/README.md +525 -0
- package/dist/bundler-DRXCw_YR.mjs +70 -0
- package/dist/bundler-DRXCw_YR.mjs.map +1 -0
- package/dist/bundler-WsEvH_b2.cjs +71 -0
- package/dist/bundler-WsEvH_b2.cjs.map +1 -0
- package/dist/{config-C9aXOHBe.cjs → config-AmInkU7k.cjs} +8 -8
- package/dist/config-AmInkU7k.cjs.map +1 -0
- package/dist/{config-BrkUalUh.mjs → config-DYULeEv8.mjs} +3 -3
- package/dist/config-DYULeEv8.mjs.map +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/encryption-C8H-38Yy.mjs +42 -0
- package/dist/encryption-C8H-38Yy.mjs.map +1 -0
- package/dist/encryption-Dyf_r1h-.cjs +44 -0
- package/dist/encryption-Dyf_r1h-.cjs.map +1 -0
- package/dist/index.cjs +2116 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2134 -192
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-CZLI4QTr.mjs → openapi-BfFlOBCG.mjs} +801 -38
- package/dist/openapi-BfFlOBCG.mjs.map +1 -0
- package/dist/{openapi-BeHLKcwP.cjs → openapi-Bt_1FDpT.cjs} +794 -31
- package/dist/openapi-Bt_1FDpT.cjs.map +1 -0
- package/dist/{openapi-react-query-o5iMi8tz.cjs → openapi-react-query-B-sNWHFU.cjs} +5 -5
- package/dist/openapi-react-query-B-sNWHFU.cjs.map +1 -0
- package/dist/{openapi-react-query-CcciaVu5.mjs → openapi-react-query-B6XTeGqS.mjs} +5 -5
- package/dist/openapi-react-query-B6XTeGqS.mjs.map +1 -0
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.d.cts.map +1 -1
- package/dist/openapi-react-query.d.mts.map +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +2 -2
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +2 -2
- package/dist/storage-BUYQJgz7.cjs +4 -0
- package/dist/storage-BXoJvmv2.cjs +149 -0
- package/dist/storage-BXoJvmv2.cjs.map +1 -0
- package/dist/storage-C9PU_30f.mjs +101 -0
- package/dist/storage-C9PU_30f.mjs.map +1 -0
- package/dist/storage-DLJAYxzJ.mjs +3 -0
- package/dist/{types-b-vwGpqc.d.cts → types-BR0M2v_c.d.mts} +100 -1
- package/dist/types-BR0M2v_c.d.mts.map +1 -0
- package/dist/{types-DXgiA1sF.d.mts → types-BhkZc-vm.d.cts} +100 -1
- package/dist/types-BhkZc-vm.d.cts.map +1 -0
- package/examples/cron-example.ts +27 -27
- package/examples/env.ts +27 -27
- package/examples/function-example.ts +31 -31
- package/examples/gkm.config.json +20 -20
- package/examples/gkm.config.ts +8 -8
- package/examples/gkm.minimal.config.json +5 -5
- package/examples/gkm.production.config.json +25 -25
- package/examples/logger.ts +2 -2
- package/package.json +6 -6
- package/src/__tests__/EndpointGenerator.hooks.spec.ts +191 -191
- package/src/__tests__/config.spec.ts +55 -55
- package/src/__tests__/loadEnvFiles.spec.ts +93 -93
- package/src/__tests__/normalizeHooksConfig.spec.ts +58 -58
- package/src/__tests__/openapi-react-query.spec.ts +497 -497
- package/src/__tests__/openapi.spec.ts +428 -428
- package/src/__tests__/test-helpers.ts +76 -76
- package/src/auth/__tests__/credentials.spec.ts +204 -0
- package/src/auth/__tests__/index.spec.ts +168 -0
- package/src/auth/credentials.ts +187 -0
- package/src/auth/index.ts +226 -0
- package/src/build/__tests__/index-new.spec.ts +474 -474
- package/src/build/__tests__/manifests.spec.ts +333 -333
- package/src/build/bundler.ts +141 -0
- package/src/build/endpoint-analyzer.ts +236 -0
- package/src/build/handler-templates.ts +1253 -0
- package/src/build/index.ts +250 -179
- package/src/build/manifests.ts +52 -52
- package/src/build/providerResolver.ts +145 -145
- package/src/build/types.ts +64 -43
- package/src/config.ts +39 -39
- package/src/deploy/__tests__/docker.spec.ts +111 -0
- package/src/deploy/__tests__/dokploy.spec.ts +245 -0
- package/src/deploy/__tests__/init.spec.ts +662 -0
- package/src/deploy/docker.ts +128 -0
- package/src/deploy/dokploy.ts +204 -0
- package/src/deploy/index.ts +136 -0
- package/src/deploy/init.ts +484 -0
- package/src/deploy/types.ts +48 -0
- package/src/dev/__tests__/index.spec.ts +266 -266
- package/src/dev/index.ts +647 -601
- package/src/docker/__tests__/compose.spec.ts +531 -0
- package/src/docker/__tests__/templates.spec.ts +280 -0
- package/src/docker/compose.ts +273 -0
- package/src/docker/index.ts +230 -0
- package/src/docker/templates.ts +446 -0
- package/src/generators/CronGenerator.ts +72 -72
- package/src/generators/EndpointGenerator.ts +699 -398
- package/src/generators/FunctionGenerator.ts +84 -84
- package/src/generators/Generator.ts +72 -72
- package/src/generators/OpenApiTsGenerator.ts +577 -577
- package/src/generators/SubscriberGenerator.ts +124 -124
- package/src/generators/__tests__/CronGenerator.spec.ts +433 -433
- package/src/generators/__tests__/EndpointGenerator.spec.ts +532 -382
- package/src/generators/__tests__/FunctionGenerator.spec.ts +244 -244
- package/src/generators/__tests__/SubscriberGenerator.spec.ts +397 -382
- package/src/generators/index.ts +4 -4
- package/src/index.ts +623 -201
- package/src/init/__tests__/generators.spec.ts +334 -334
- package/src/init/__tests__/init.spec.ts +332 -332
- package/src/init/__tests__/utils.spec.ts +89 -89
- package/src/init/generators/config.ts +175 -175
- package/src/init/generators/docker.ts +41 -41
- package/src/init/generators/env.ts +72 -72
- package/src/init/generators/index.ts +1 -1
- package/src/init/generators/models.ts +64 -64
- package/src/init/generators/monorepo.ts +161 -161
- package/src/init/generators/package.ts +71 -71
- package/src/init/generators/source.ts +6 -6
- package/src/init/index.ts +203 -208
- package/src/init/templates/api.ts +115 -115
- package/src/init/templates/index.ts +75 -75
- package/src/init/templates/minimal.ts +98 -98
- package/src/init/templates/serverless.ts +89 -89
- package/src/init/templates/worker.ts +98 -98
- package/src/init/utils.ts +54 -56
- package/src/openapi-react-query.ts +194 -194
- package/src/openapi.ts +63 -63
- package/src/secrets/__tests__/encryption.spec.ts +226 -0
- package/src/secrets/__tests__/generator.spec.ts +319 -0
- package/src/secrets/__tests__/index.spec.ts +91 -0
- package/src/secrets/__tests__/storage.spec.ts +403 -0
- package/src/secrets/encryption.ts +91 -0
- package/src/secrets/generator.ts +164 -0
- package/src/secrets/index.ts +383 -0
- package/src/secrets/storage.ts +134 -0
- package/src/secrets/types.ts +53 -0
- package/src/types.ts +295 -176
- package/tsdown.config.ts +11 -8
- package/dist/config-BrkUalUh.mjs.map +0 -1
- package/dist/config-C9aXOHBe.cjs.map +0 -1
- package/dist/openapi-BeHLKcwP.cjs.map +0 -1
- package/dist/openapi-CZLI4QTr.mjs.map +0 -1
- package/dist/openapi-react-query-CcciaVu5.mjs.map +0 -1
- package/dist/openapi-react-query-o5iMi8tz.cjs.map +0 -1
- package/dist/types-DXgiA1sF.d.mts.map +0 -1
- package/dist/types-b-vwGpqc.d.cts.map +0 -1
|
@@ -10,195 +10,195 @@ import type { GeneratedConstruct } from '../generators/Generator';
|
|
|
10
10
|
const mockEndpoint = e.get('/test').handle(async () => ({ ok: true }));
|
|
11
11
|
|
|
12
12
|
describe('EndpointGenerator hooks generation', () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
13
|
+
const testOutputDir = join(process.cwd(), '.test-output');
|
|
14
|
+
let generator: EndpointGenerator;
|
|
15
|
+
|
|
16
|
+
// Mock endpoint construct for testing
|
|
17
|
+
const mockConstruct: GeneratedConstruct<typeof mockEndpoint> = {
|
|
18
|
+
key: 'testEndpoint',
|
|
19
|
+
construct: mockEndpoint,
|
|
20
|
+
path: {
|
|
21
|
+
relative: '/project/src/endpoints/test.ts',
|
|
22
|
+
absolute: '/project/src/endpoints/test.ts',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
generator = new EndpointGenerator();
|
|
28
|
+
await mkdir(testOutputDir, { recursive: true });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(async () => {
|
|
32
|
+
await rm(testOutputDir, { recursive: true, force: true });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const baseContext: BuildContext = {
|
|
36
|
+
envParserPath: '/project/src/config/env.ts',
|
|
37
|
+
envParserImportPattern: '{ envParser }',
|
|
38
|
+
loggerPath: '/project/src/config/logger.ts',
|
|
39
|
+
loggerImportPattern: 'logger',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe('generateAppFile', () => {
|
|
43
|
+
it('should not include hooks when hooks config is undefined', async () => {
|
|
44
|
+
await generator.build(baseContext, [mockConstruct], testOutputDir, {
|
|
45
|
+
provider: 'server',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const appContent = await readFile(join(testOutputDir, 'app.ts'), 'utf-8');
|
|
49
|
+
|
|
50
|
+
expect(appContent).not.toContain('serverHooks');
|
|
51
|
+
expect(appContent).not.toContain('beforeSetup');
|
|
52
|
+
expect(appContent).not.toContain('afterSetup');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should include hooks imports when hooks config is provided', async () => {
|
|
56
|
+
const contextWithHooks: BuildContext = {
|
|
57
|
+
...baseContext,
|
|
58
|
+
hooks: {
|
|
59
|
+
serverHooksPath: '/project/src/config/hooks.ts',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
await generator.build(contextWithHooks, [mockConstruct], testOutputDir, {
|
|
64
|
+
provider: 'server',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const appContent = await readFile(join(testOutputDir, 'app.ts'), 'utf-8');
|
|
68
|
+
|
|
69
|
+
expect(appContent).toContain('import * as serverHooks from');
|
|
70
|
+
expect(appContent).toContain('hooks.ts');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should include beforeSetup hook call', async () => {
|
|
74
|
+
const contextWithHooks: BuildContext = {
|
|
75
|
+
...baseContext,
|
|
76
|
+
hooks: {
|
|
77
|
+
serverHooksPath: '/project/src/config/hooks.ts',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
await generator.build(contextWithHooks, [mockConstruct], testOutputDir, {
|
|
82
|
+
provider: 'server',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const appContent = await readFile(join(testOutputDir, 'app.ts'), 'utf-8');
|
|
86
|
+
|
|
87
|
+
expect(appContent).toContain(
|
|
88
|
+
"if (typeof serverHooks.beforeSetup === 'function')",
|
|
89
|
+
);
|
|
90
|
+
expect(appContent).toContain(
|
|
91
|
+
'await serverHooks.beforeSetup(honoApp, { envParser, logger })',
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should include afterSetup hook call', async () => {
|
|
96
|
+
const contextWithHooks: BuildContext = {
|
|
97
|
+
...baseContext,
|
|
98
|
+
hooks: {
|
|
99
|
+
serverHooksPath: '/project/src/config/hooks.ts',
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
await generator.build(contextWithHooks, [mockConstruct], testOutputDir, {
|
|
104
|
+
provider: 'server',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const appContent = await readFile(join(testOutputDir, 'app.ts'), 'utf-8');
|
|
108
|
+
|
|
109
|
+
expect(appContent).toContain(
|
|
110
|
+
"if (typeof serverHooks.afterSetup === 'function')",
|
|
111
|
+
);
|
|
112
|
+
expect(appContent).toContain(
|
|
113
|
+
'await serverHooks.afterSetup(honoApp, { envParser, logger })',
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should place telescope before beforeSetup, and beforeSetup before endpoints', async () => {
|
|
118
|
+
const contextWithHooks: BuildContext = {
|
|
119
|
+
...baseContext,
|
|
120
|
+
hooks: {
|
|
121
|
+
serverHooksPath: '/project/src/config/hooks.ts',
|
|
122
|
+
},
|
|
123
|
+
telescope: {
|
|
124
|
+
enabled: true,
|
|
125
|
+
path: '/__telescope',
|
|
126
|
+
maxEntries: 100,
|
|
127
|
+
recordBody: true,
|
|
128
|
+
ignore: [],
|
|
129
|
+
websocket: false,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
await generator.build(contextWithHooks, [mockConstruct], testOutputDir, {
|
|
134
|
+
provider: 'server',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const appContent = await readFile(join(testOutputDir, 'app.ts'), 'utf-8');
|
|
138
|
+
|
|
139
|
+
// Use specific patterns to find the actual calls (not imports/comments)
|
|
140
|
+
const telescopeIndex = appContent.indexOf('createMiddleware(telescope)');
|
|
141
|
+
const beforeSetupCallIndex = appContent.indexOf(
|
|
142
|
+
'serverHooks.beforeSetup(honoApp',
|
|
143
|
+
);
|
|
144
|
+
const setupEndpointsIndex = appContent.indexOf(
|
|
145
|
+
'await setupEndpoints(honoApp',
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
expect(telescopeIndex).toBeGreaterThan(0);
|
|
149
|
+
expect(beforeSetupCallIndex).toBeGreaterThan(0);
|
|
150
|
+
expect(setupEndpointsIndex).toBeGreaterThan(0);
|
|
151
|
+
// Telescope middleware first (to capture all requests)
|
|
152
|
+
expect(telescopeIndex).toBeLessThan(beforeSetupCallIndex);
|
|
153
|
+
// Then beforeSetup hook
|
|
154
|
+
expect(beforeSetupCallIndex).toBeLessThan(setupEndpointsIndex);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should place afterSetup after setupEndpoints', async () => {
|
|
158
|
+
const contextWithHooks: BuildContext = {
|
|
159
|
+
...baseContext,
|
|
160
|
+
hooks: {
|
|
161
|
+
serverHooksPath: '/project/src/config/hooks.ts',
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
await generator.build(contextWithHooks, [mockConstruct], testOutputDir, {
|
|
166
|
+
provider: 'server',
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const appContent = await readFile(join(testOutputDir, 'app.ts'), 'utf-8');
|
|
170
|
+
|
|
171
|
+
// Use specific patterns to find the actual calls (not imports/comments)
|
|
172
|
+
const setupEndpointsIndex = appContent.indexOf(
|
|
173
|
+
'await setupEndpoints(honoApp',
|
|
174
|
+
);
|
|
175
|
+
const afterSetupCallIndex = appContent.indexOf(
|
|
176
|
+
'serverHooks.afterSetup(honoApp',
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(setupEndpointsIndex).toBeGreaterThan(0);
|
|
180
|
+
expect(afterSetupCallIndex).toBeGreaterThan(0);
|
|
181
|
+
expect(afterSetupCallIndex).toBeGreaterThan(setupEndpointsIndex);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should generate correct relative import path for hooks', async () => {
|
|
185
|
+
const contextWithHooks: BuildContext = {
|
|
186
|
+
...baseContext,
|
|
187
|
+
hooks: {
|
|
188
|
+
serverHooksPath: join(testOutputDir, '../../src/config/hooks.ts'),
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
await generator.build(contextWithHooks, [mockConstruct], testOutputDir, {
|
|
193
|
+
provider: 'server',
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const appContent = await readFile(join(testOutputDir, 'app.ts'), 'utf-8');
|
|
197
|
+
|
|
198
|
+
// Should have a relative import path
|
|
199
|
+
expect(appContent).toMatch(
|
|
200
|
+
/import \* as serverHooks from '\.\.\/.*hooks\.ts'/,
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
204
|
});
|
|
@@ -5,22 +5,22 @@ import { loadConfig } from '../config';
|
|
|
5
5
|
import { cleanupDir, createTempDir } from './test-helpers';
|
|
6
6
|
|
|
7
7
|
describe('loadConfig', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
let tempDir: string;
|
|
9
|
+
let originalCwd: string;
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
tempDir = await createTempDir();
|
|
13
|
+
originalCwd = process.cwd();
|
|
14
|
+
process.chdir(tempDir);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(async () => {
|
|
18
|
+
process.chdir(originalCwd);
|
|
19
|
+
await cleanupDir(tempDir);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should load configuration from gkm.config.ts', async () => {
|
|
23
|
+
const configContent = `
|
|
24
24
|
export default {
|
|
25
25
|
routes: './src/endpoints/**/*.ts',
|
|
26
26
|
functions: './src/functions/**/*.ts',
|
|
@@ -29,82 +29,82 @@ export default {
|
|
|
29
29
|
logger: './src/config/logger',
|
|
30
30
|
};
|
|
31
31
|
`;
|
|
32
|
-
|
|
32
|
+
await writeFile(join(tempDir, 'gkm.config.ts'), configContent);
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
const config = await loadConfig();
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
expect(config).toEqual({
|
|
37
|
+
routes: './src/endpoints/**/*.ts',
|
|
38
|
+
functions: './src/functions/**/*.ts',
|
|
39
|
+
crons: './src/crons/**/*.ts',
|
|
40
|
+
envParser: './src/config/env',
|
|
41
|
+
logger: './src/config/logger',
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
it('should load configuration from gkm.config.js', async () => {
|
|
46
|
+
const configContent = `
|
|
47
47
|
module.exports = {
|
|
48
48
|
routes: './api/**/*.js',
|
|
49
49
|
envParser: './config/environment',
|
|
50
50
|
logger: './config/logging',
|
|
51
51
|
};
|
|
52
52
|
`;
|
|
53
|
-
|
|
53
|
+
await writeFile(join(tempDir, 'gkm.config.js'), configContent);
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const config = await loadConfig();
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
expect(config.routes).toBe('./api/**/*.js');
|
|
58
|
+
expect(config.envParser).toBe('./config/environment');
|
|
59
|
+
expect(config.logger).toBe('./config/logging');
|
|
60
|
+
});
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
it('should handle configuration with only envParser override', async () => {
|
|
63
|
+
const configContent = `
|
|
64
64
|
export default {
|
|
65
65
|
envParser: './my-env#myEnvParser',
|
|
66
66
|
logger: './my-logger#myLogger',
|
|
67
67
|
};
|
|
68
68
|
`;
|
|
69
|
-
|
|
69
|
+
await writeFile(join(tempDir, 'gkm.config.ts'), configContent);
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
const config = await loadConfig();
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
expect(config.envParser).toBe('./my-env#myEnvParser');
|
|
74
|
+
expect(config.logger).toBe('./my-logger#myLogger');
|
|
75
|
+
});
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
it('should handle malformed config file gracefully', async () => {
|
|
78
|
+
const invalidConfigContent = `
|
|
79
79
|
export default {
|
|
80
80
|
routes: './endpoints/**/*.ts'
|
|
81
81
|
// Missing comma - syntax error
|
|
82
82
|
functions: './functions/**/*.ts'
|
|
83
83
|
};
|
|
84
84
|
`;
|
|
85
|
-
|
|
85
|
+
await writeFile(join(tempDir, 'gkm.config.ts'), invalidConfigContent);
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
// Should fall back to defaults when config file has syntax errors
|
|
88
|
+
await expect(loadConfig()).rejects.toThrow();
|
|
89
|
+
});
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
it('should prefer .ts config over .js config', async () => {
|
|
92
|
+
const jsConfigContent = `
|
|
93
93
|
module.exports = {
|
|
94
94
|
routes: './js-routes/**/*.js',
|
|
95
95
|
};
|
|
96
96
|
`;
|
|
97
|
-
|
|
97
|
+
const tsConfigContent = `
|
|
98
98
|
export default {
|
|
99
99
|
routes: './ts-routes/**/*.ts',
|
|
100
100
|
};
|
|
101
101
|
`;
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
await writeFile(join(tempDir, 'gkm.config.js'), jsConfigContent);
|
|
104
|
+
await writeFile(join(tempDir, 'gkm.config.ts'), tsConfigContent);
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
const config = await loadConfig();
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
expect(config.routes).toBe('./ts-routes/**/*.ts');
|
|
109
|
+
});
|
|
110
110
|
});
|