@geekmidas/cli 0.0.26 → 0.1.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/FUNCTION_CRON_SUPPORT.md +266 -0
- package/README.md +21 -4
- package/dist/CronGenerator-ClbRcmz_.mjs +53 -0
- package/dist/CronGenerator-ClbRcmz_.mjs.map +1 -0
- package/dist/CronGenerator-Ctl4USy4.cjs +59 -0
- package/dist/CronGenerator-Ctl4USy4.cjs.map +1 -0
- package/dist/EndpointGenerator-Dj7AumHi.cjs +164 -0
- package/dist/EndpointGenerator-Dj7AumHi.cjs.map +1 -0
- package/dist/EndpointGenerator-uBA1ixUw.mjs +158 -0
- package/dist/EndpointGenerator-uBA1ixUw.mjs.map +1 -0
- package/dist/FunctionGenerator-DN681IUn.cjs +58 -0
- package/dist/FunctionGenerator-DN681IUn.cjs.map +1 -0
- package/dist/FunctionGenerator-crAa-JC7.mjs +52 -0
- package/dist/FunctionGenerator-crAa-JC7.mjs.map +1 -0
- package/dist/Generator-C3tYSTQY.cjs +47 -0
- package/dist/Generator-C3tYSTQY.cjs.map +1 -0
- package/dist/Generator-CDt4pB3W.mjs +41 -0
- package/dist/Generator-CDt4pB3W.mjs.map +1 -0
- package/dist/__tests__/config.spec.cjs +98 -0
- package/dist/__tests__/config.spec.cjs.map +1 -0
- package/dist/__tests__/config.spec.mjs +97 -0
- package/dist/__tests__/config.spec.mjs.map +1 -0
- package/dist/__tests__/test-helpers.cjs +14 -0
- package/dist/__tests__/test-helpers.mjs +4 -0
- package/dist/build/__tests__/index-new.spec.cjs +286 -0
- package/dist/build/__tests__/index-new.spec.cjs.map +1 -0
- package/dist/build/__tests__/index-new.spec.mjs +285 -0
- package/dist/build/__tests__/index-new.spec.mjs.map +1 -0
- package/dist/build/index.cjs +11 -0
- package/dist/build/index.mjs +11 -0
- package/dist/build/manifests.cjs +3 -0
- package/dist/build/manifests.mjs +3 -0
- package/dist/build/providerResolver.cjs +5 -0
- package/dist/build/providerResolver.mjs +3 -0
- package/dist/build/types.cjs +0 -0
- package/dist/build/types.mjs +0 -0
- package/dist/build-BZdwxCLW.mjs +64 -0
- package/dist/build-BZdwxCLW.mjs.map +1 -0
- package/dist/build-BfQFnU5-.cjs +70 -0
- package/dist/build-BfQFnU5-.cjs.map +1 -0
- package/dist/{chunk-CUT6urMc.cjs → chunk-CsX-DzYB.cjs} +12 -0
- package/dist/config-CXxYmz_o.mjs +30 -0
- package/dist/config-CXxYmz_o.mjs.map +1 -0
- package/dist/config-RcNESK0T.cjs +36 -0
- package/dist/config-RcNESK0T.cjs.map +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/esm-9eeZntth.mjs +3777 -0
- package/dist/esm-9eeZntth.mjs.map +1 -0
- package/dist/esm-Crmo4h9t.cjs +4392 -0
- package/dist/esm-Crmo4h9t.cjs.map +1 -0
- package/dist/esm-CsJbr7gi.mjs +3 -0
- package/dist/esm-w09tAC4l.cjs +8 -0
- package/dist/generators/CronGenerator.cjs +4 -0
- package/dist/generators/CronGenerator.mjs +4 -0
- package/dist/generators/EndpointGenerator.cjs +4 -0
- package/dist/generators/EndpointGenerator.mjs +4 -0
- package/dist/generators/FunctionGenerator.cjs +4 -0
- package/dist/generators/FunctionGenerator.mjs +4 -0
- package/dist/generators/Generator.cjs +3 -0
- package/dist/generators/Generator.mjs +3 -0
- package/dist/generators/__tests__/CronGenerator.spec.cjs +216 -0
- package/dist/generators/__tests__/CronGenerator.spec.cjs.map +1 -0
- package/dist/generators/__tests__/CronGenerator.spec.mjs +215 -0
- package/dist/generators/__tests__/CronGenerator.spec.mjs.map +1 -0
- package/dist/generators/__tests__/EndpointGenerator.spec.cjs +182 -0
- package/dist/generators/__tests__/EndpointGenerator.spec.cjs.map +1 -0
- package/dist/generators/__tests__/EndpointGenerator.spec.mjs +181 -0
- package/dist/generators/__tests__/EndpointGenerator.spec.mjs.map +1 -0
- package/dist/generators/__tests__/FunctionGenerator.spec.cjs +152 -0
- package/dist/generators/__tests__/FunctionGenerator.spec.cjs.map +1 -0
- package/dist/generators/__tests__/FunctionGenerator.spec.mjs +151 -0
- package/dist/generators/__tests__/FunctionGenerator.spec.mjs.map +1 -0
- package/dist/generators/index.cjs +10 -0
- package/dist/generators/index.mjs +7 -0
- package/dist/generators-CsLujGXs.mjs +0 -0
- package/dist/generators-_pY7sHy1.cjs +0 -0
- package/dist/index.cjs +68 -26
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +67 -25
- package/dist/index.mjs.map +1 -0
- package/dist/manifests-BTtfDMX8.cjs +26 -0
- package/dist/manifests-BTtfDMX8.cjs.map +1 -0
- package/dist/manifests-HX4z4kkz.mjs +20 -0
- package/dist/manifests-HX4z4kkz.mjs.map +1 -0
- package/dist/{openapi-CksVdkh2.mjs → openapi-BivnatiC.mjs} +8 -6
- package/dist/openapi-BivnatiC.mjs.map +1 -0
- package/dist/{openapi-D4QQJUPY.cjs → openapi-DW-qF3oW.cjs} +9 -7
- package/dist/openapi-DW-qF3oW.cjs.map +1 -0
- package/dist/{openapi-react-query-C1JLYUOs.cjs → openapi-react-query-J0BzBHhN.cjs} +4 -3
- package/dist/openapi-react-query-J0BzBHhN.cjs.map +1 -0
- package/dist/{openapi-react-query-DpT3XHFC.mjs → openapi-react-query-lgS7AVEz.mjs} +3 -2
- package/dist/openapi-react-query-lgS7AVEz.mjs.map +1 -0
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +4 -3
- package/dist/openapi.mjs +4 -3
- package/dist/providerResolver-B_TjNF0_.mjs +96 -0
- package/dist/providerResolver-B_TjNF0_.mjs.map +1 -0
- package/dist/providerResolver-Cs-0YCaP.cjs +114 -0
- package/dist/providerResolver-Cs-0YCaP.cjs.map +1 -0
- package/dist/test-helpers-ARd8GDgx.cjs +199 -0
- package/dist/test-helpers-ARd8GDgx.cjs.map +1 -0
- package/dist/test-helpers-DdVBk23F.mjs +133 -0
- package/dist/test-helpers-DdVBk23F.mjs.map +1 -0
- package/examples/cron-example.ts +45 -0
- package/examples/function-example.ts +40 -0
- package/examples/gkm.config.json +22 -0
- package/examples/gkm.minimal.config.json +7 -0
- package/examples/gkm.production.config.json +27 -0
- package/package.json +35 -14
- package/src/__tests__/config.spec.ts +110 -0
- package/src/__tests__/test-helpers.ts +178 -0
- package/src/build/__tests__/index-new.spec.ts +578 -0
- package/src/build/index.ts +136 -0
- package/src/build/manifests.ts +32 -0
- package/src/build/providerResolver.ts +184 -0
- package/src/build/types.ts +37 -0
- package/src/config.ts +14 -6
- package/src/generators/CronGenerator.ts +97 -0
- package/src/generators/EndpointGenerator.ts +290 -0
- package/src/generators/FunctionGenerator.ts +96 -0
- package/src/generators/Generator.ts +95 -0
- package/src/generators/__tests__/CronGenerator.spec.ts +445 -0
- package/src/generators/__tests__/EndpointGenerator.spec.ts +372 -0
- package/src/generators/__tests__/FunctionGenerator.spec.ts +257 -0
- package/src/generators/index.ts +8 -0
- package/src/index.ts +57 -22
- package/src/openapi.ts +4 -3
- package/src/types.ts +73 -2
- package/dist/build-BTggTCYL.cjs +0 -176
- package/dist/build-Ca4P6_lY.mjs +0 -170
- package/dist/build.cjs +0 -5
- package/dist/build.mjs +0 -5
- package/dist/config-BNqUMsvc.cjs +0 -24
- package/dist/config-BciAdY6_.mjs +0 -18
- package/dist/loadEndpoints-BBIavB9h.cjs +0 -37
- package/dist/loadEndpoints-DAZ53Og2.mjs +0 -31
- package/dist/loadEndpoints.cjs +0 -3
- package/dist/loadEndpoints.mjs +0 -3
- package/src/build.ts +0 -305
- package/src/loadEndpoints.ts +0 -48
package/src/index.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import pkg from '../package.json' assert { type: 'json' };
|
|
5
|
-
import { buildCommand } from './build.ts';
|
|
5
|
+
import { buildCommand } from './build/index.ts';
|
|
6
6
|
import { generateReactQueryCommand } from './openapi-react-query.ts';
|
|
7
7
|
import { openapiCommand } from './openapi.ts';
|
|
8
|
-
import type {
|
|
8
|
+
import type { LegacyProvider, MainProvider } from './types.ts';
|
|
9
9
|
|
|
10
10
|
const program = new Command();
|
|
11
11
|
|
|
@@ -17,34 +17,69 @@ program
|
|
|
17
17
|
|
|
18
18
|
program
|
|
19
19
|
.command('build')
|
|
20
|
-
.description('Build
|
|
20
|
+
.description('Build handlers from endpoints, functions, and crons')
|
|
21
|
+
.option(
|
|
22
|
+
'--provider <provider>',
|
|
23
|
+
'Target provider for generated handlers (aws, server)',
|
|
24
|
+
)
|
|
21
25
|
.option(
|
|
22
26
|
'--providers <providers>',
|
|
23
|
-
'Target providers for generated handlers (comma-separated)',
|
|
24
|
-
'aws-apigatewayv1',
|
|
27
|
+
'[DEPRECATED] Use --provider instead. Target providers for generated handlers (comma-separated)',
|
|
25
28
|
)
|
|
26
29
|
.option(
|
|
27
30
|
'--enable-openapi',
|
|
28
31
|
'Enable OpenAPI documentation generation for server builds',
|
|
29
32
|
)
|
|
30
|
-
.action(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
.action(
|
|
34
|
+
async (options: {
|
|
35
|
+
provider?: string;
|
|
36
|
+
providers?: string;
|
|
37
|
+
enableOpenapi?: boolean;
|
|
38
|
+
}) => {
|
|
39
|
+
try {
|
|
40
|
+
const globalOptions = program.opts();
|
|
41
|
+
if (globalOptions.cwd) {
|
|
42
|
+
process.chdir(globalOptions.cwd);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Handle new single provider option
|
|
46
|
+
if (options.provider) {
|
|
47
|
+
if (!['aws', 'server'].includes(options.provider)) {
|
|
48
|
+
console.error(
|
|
49
|
+
`Invalid provider: ${options.provider}. Must be 'aws' or 'server'.`,
|
|
50
|
+
);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
await buildCommand({
|
|
54
|
+
provider: options.provider as MainProvider,
|
|
55
|
+
enableOpenApi: options.enableOpenapi || false,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Handle legacy providers option
|
|
59
|
+
else if (options.providers) {
|
|
60
|
+
console.warn(
|
|
61
|
+
'⚠️ --providers flag is deprecated. Use --provider instead.',
|
|
62
|
+
);
|
|
63
|
+
const providerList = [
|
|
64
|
+
...new Set(options.providers.split(',').map((p) => p.trim())),
|
|
65
|
+
] as LegacyProvider[];
|
|
66
|
+
await buildCommand({
|
|
67
|
+
providers: providerList,
|
|
68
|
+
enableOpenApi: options.enableOpenapi || false,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Default to config-driven build
|
|
72
|
+
else {
|
|
73
|
+
await buildCommand({
|
|
74
|
+
enableOpenApi: options.enableOpenapi || false,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error('Build failed:', (error as Error).message);
|
|
79
|
+
process.exit(1);
|
|
35
80
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
] as Provider[];
|
|
39
|
-
await buildCommand({
|
|
40
|
-
providers: providerList,
|
|
41
|
-
enableOpenApi: options.enableOpenapi || false,
|
|
42
|
-
});
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error('Build failed:', (error as Error).message);
|
|
45
|
-
process.exit(1);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
81
|
+
},
|
|
82
|
+
);
|
|
48
83
|
|
|
49
84
|
program
|
|
50
85
|
.command('cron')
|
package/src/openapi.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { mkdir, writeFile } from 'node:fs/promises';
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { Endpoint } from '@geekmidas/api/server';
|
|
6
6
|
import { loadConfig } from './config.js';
|
|
7
|
-
import {
|
|
7
|
+
import { EndpointGenerator } from './generators/EndpointGenerator.js';
|
|
8
8
|
|
|
9
9
|
interface OpenAPIOptions {
|
|
10
10
|
output?: string;
|
|
@@ -18,9 +18,10 @@ export async function openapiCommand(
|
|
|
18
18
|
try {
|
|
19
19
|
// Load config using existing function
|
|
20
20
|
const config = await loadConfig();
|
|
21
|
+
const generator = new EndpointGenerator();
|
|
21
22
|
|
|
22
23
|
// Load all endpoints using the refactored function
|
|
23
|
-
const loadedEndpoints = await
|
|
24
|
+
const loadedEndpoints = await generator.load(config.routes);
|
|
24
25
|
|
|
25
26
|
if (loadedEndpoints.length === 0) {
|
|
26
27
|
logger.log('No valid endpoints found');
|
|
@@ -28,7 +29,7 @@ export async function openapiCommand(
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
// Extract just the endpoint instances for OpenAPI generation
|
|
31
|
-
const endpoints = loadedEndpoints.map(({
|
|
32
|
+
const endpoints = loadedEndpoints.map(({ construct }) => construct);
|
|
32
33
|
|
|
33
34
|
// Generate OpenAPI spec using built-in method
|
|
34
35
|
const spec = await Endpoint.buildOpenApiSchema(endpoints, {
|
package/src/types.ts
CHANGED
|
@@ -1,15 +1,57 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type MainProvider = 'aws' | 'server';
|
|
2
|
+
export type LegacyProvider =
|
|
3
|
+
| 'server'
|
|
4
|
+
| 'aws-apigatewayv1'
|
|
5
|
+
| 'aws-apigatewayv2'
|
|
6
|
+
| 'aws-lambda';
|
|
2
7
|
|
|
3
8
|
export type Routes = string | string[];
|
|
4
9
|
|
|
10
|
+
export interface ProviderConfig {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
outputDir?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AWSApiGatewayConfig extends ProviderConfig {
|
|
16
|
+
// Additional AWS API Gateway specific options
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AWSLambdaConfig extends ProviderConfig {
|
|
20
|
+
// Additional AWS Lambda specific options
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ServerConfig extends ProviderConfig {
|
|
24
|
+
enableOpenApi?: boolean;
|
|
25
|
+
port?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ProvidersConfig {
|
|
29
|
+
aws?: {
|
|
30
|
+
apiGateway?: {
|
|
31
|
+
v1?: boolean | AWSApiGatewayConfig;
|
|
32
|
+
v2?: boolean | AWSApiGatewayConfig;
|
|
33
|
+
};
|
|
34
|
+
lambda?: {
|
|
35
|
+
functions?: boolean | AWSLambdaConfig;
|
|
36
|
+
crons?: boolean | AWSLambdaConfig;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
server?: boolean | ServerConfig;
|
|
40
|
+
}
|
|
41
|
+
|
|
5
42
|
export interface GkmConfig {
|
|
6
43
|
routes: Routes;
|
|
44
|
+
functions?: Routes;
|
|
45
|
+
crons?: Routes;
|
|
7
46
|
envParser: string;
|
|
8
47
|
logger: string;
|
|
48
|
+
providers?: ProvidersConfig;
|
|
9
49
|
}
|
|
10
50
|
|
|
11
51
|
export interface BuildOptions {
|
|
12
|
-
|
|
52
|
+
provider?: MainProvider;
|
|
53
|
+
// Legacy support - will be deprecated
|
|
54
|
+
providers?: LegacyProvider[];
|
|
13
55
|
enableOpenApi?: boolean;
|
|
14
56
|
}
|
|
15
57
|
|
|
@@ -19,6 +61,35 @@ export interface RouteInfo {
|
|
|
19
61
|
handler: string;
|
|
20
62
|
}
|
|
21
63
|
|
|
64
|
+
export interface FunctionInfo {
|
|
65
|
+
name: string;
|
|
66
|
+
handler: string;
|
|
67
|
+
timeout?: number;
|
|
68
|
+
memorySize?: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface CronInfo {
|
|
72
|
+
name: string;
|
|
73
|
+
handler: string;
|
|
74
|
+
schedule: string;
|
|
75
|
+
timeout?: number;
|
|
76
|
+
memorySize?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
22
79
|
export interface RoutesManifest {
|
|
23
80
|
routes: RouteInfo[];
|
|
24
81
|
}
|
|
82
|
+
|
|
83
|
+
export interface FunctionsManifest {
|
|
84
|
+
functions: FunctionInfo[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface CronsManifest {
|
|
88
|
+
crons: CronInfo[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface BuildManifest {
|
|
92
|
+
routes: RouteInfo[];
|
|
93
|
+
functions: FunctionInfo[];
|
|
94
|
+
crons: CronInfo[];
|
|
95
|
+
}
|
package/dist/build-BTggTCYL.cjs
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_config = require('./config-BNqUMsvc.cjs');
|
|
3
|
-
const require_loadEndpoints = require('./loadEndpoints-BBIavB9h.cjs');
|
|
4
|
-
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
5
|
-
const path = require_chunk.__toESM(require("path"));
|
|
6
|
-
|
|
7
|
-
//#region src/build.ts
|
|
8
|
-
const logger = console;
|
|
9
|
-
async function buildCommand(options) {
|
|
10
|
-
logger.log(`Building with providers: ${options.providers.join(", ")}`);
|
|
11
|
-
const config = await require_config.loadConfig();
|
|
12
|
-
logger.log(`Loading routes from: ${config.routes}`);
|
|
13
|
-
logger.log(`Using envParser: ${config.envParser}`);
|
|
14
|
-
const [envParserPath, envParserName] = config.envParser.split("#");
|
|
15
|
-
const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
|
|
16
|
-
const [loggerPath, loggerName] = config.logger.split("#");
|
|
17
|
-
const loggerImportPattern = !loggerName ? "logger" : loggerName === "logger" ? "{ logger }" : `{ ${loggerName} as logger }`;
|
|
18
|
-
const loadedEndpoints = await require_loadEndpoints.loadEndpoints(config.routes);
|
|
19
|
-
if (loadedEndpoints.length === 0) {
|
|
20
|
-
logger.log("No endpoints found to process");
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const allEndpoints = loadedEndpoints.map(({ name, endpoint, file }) => {
|
|
24
|
-
const routeInfo = {
|
|
25
|
-
path: endpoint._path,
|
|
26
|
-
method: endpoint.method,
|
|
27
|
-
handler: ""
|
|
28
|
-
};
|
|
29
|
-
logger.log(`Found endpoint: ${name} - ${routeInfo.method} ${routeInfo.path}`);
|
|
30
|
-
return {
|
|
31
|
-
file: (0, path.relative)(process.cwd(), file),
|
|
32
|
-
exportName: name,
|
|
33
|
-
endpoint,
|
|
34
|
-
routeInfo
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
for (const provider of options.providers) {
|
|
38
|
-
const routes = [];
|
|
39
|
-
const outputDir = (0, path.join)(process.cwd(), ".gkm", provider);
|
|
40
|
-
await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
|
|
41
|
-
logger.log(`\nGenerating handlers for provider: ${provider}`);
|
|
42
|
-
if (provider === "server") {
|
|
43
|
-
const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, options.enableOpenApi || false);
|
|
44
|
-
routes.push({
|
|
45
|
-
path: "*",
|
|
46
|
-
method: "ALL",
|
|
47
|
-
handler: (0, path.relative)(process.cwd(), serverFile)
|
|
48
|
-
});
|
|
49
|
-
logger.log(`Generated server app with ${allEndpoints.length} endpoints${options.enableOpenApi ? " (OpenAPI enabled)" : ""}`);
|
|
50
|
-
} else for (const { file, exportName, routeInfo } of allEndpoints) {
|
|
51
|
-
const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern);
|
|
52
|
-
routes.push({
|
|
53
|
-
...routeInfo,
|
|
54
|
-
handler: (0, path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler")
|
|
55
|
-
});
|
|
56
|
-
logger.log(`Generated handler for ${routeInfo.method} ${routeInfo.path}`);
|
|
57
|
-
}
|
|
58
|
-
const manifest = { routes };
|
|
59
|
-
const manifestPath = (0, path.join)(outputDir, "routes.json");
|
|
60
|
-
await (0, node_fs_promises.writeFile)(manifestPath, JSON.stringify(manifest, null, 2));
|
|
61
|
-
logger.log(`Generated ${routes.length} handlers in ${(0, path.relative)(process.cwd(), outputDir)}`);
|
|
62
|
-
logger.log(`Routes manifest: ${(0, path.relative)(process.cwd(), manifestPath)}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, enableOpenApi) {
|
|
66
|
-
const serverFileName = "app.ts";
|
|
67
|
-
const serverPath = (0, path.join)(outputDir, serverFileName);
|
|
68
|
-
const importsByFile = /* @__PURE__ */ new Map();
|
|
69
|
-
for (const { file, exportName } of endpoints) {
|
|
70
|
-
const relativePath = (0, path.relative)((0, path.dirname)(serverPath), file);
|
|
71
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
72
|
-
if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
|
|
73
|
-
importsByFile.get(importPath).push(exportName);
|
|
74
|
-
}
|
|
75
|
-
const relativeEnvParserPath = (0, path.relative)((0, path.dirname)(serverPath), envParserPath);
|
|
76
|
-
const relativeLoggerPath = (0, path.relative)((0, path.dirname)(serverPath), loggerPath);
|
|
77
|
-
const imports = Array.from(importsByFile.entries()).map(([importPath, exports$1]) => `import { ${exports$1.join(", ")} } from '${importPath}';`).join("\n");
|
|
78
|
-
const allExportNames = endpoints.map(({ exportName }) => exportName);
|
|
79
|
-
const content = `import { HonoEndpoint } from '@geekmidas/api/hono';
|
|
80
|
-
import { Endpoint } from '@geekmidas/api/server';
|
|
81
|
-
import { ServiceDiscovery } from '@geekmidas/api/services';
|
|
82
|
-
import { Hono } from 'hono';
|
|
83
|
-
import ${envParserImportPattern} from '${relativeEnvParserPath}';
|
|
84
|
-
import ${loggerImportPattern} from '${relativeLoggerPath}';
|
|
85
|
-
${imports}
|
|
86
|
-
|
|
87
|
-
export function createApp(app?: Hono, enableOpenApi: boolean = ${enableOpenApi}): Hono {
|
|
88
|
-
const honoApp = app || new Hono();
|
|
89
|
-
|
|
90
|
-
const endpoints: Endpoint<any, any, any, any, any, any, any>[] = [
|
|
91
|
-
${allExportNames.join(",\n ")}
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
const serviceDiscovery = ServiceDiscovery.getInstance(
|
|
95
|
-
logger,
|
|
96
|
-
envParser
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// Configure OpenAPI options based on enableOpenApi flag
|
|
100
|
-
const openApiOptions: any = enableOpenApi ? {
|
|
101
|
-
docsPath: '/docs',
|
|
102
|
-
openApiOptions: {
|
|
103
|
-
title: 'API Documentation',
|
|
104
|
-
version: '1.0.0',
|
|
105
|
-
description: 'Generated API documentation'
|
|
106
|
-
}
|
|
107
|
-
} : { docsPath: false };
|
|
108
|
-
|
|
109
|
-
HonoEndpoint.addRoutes(endpoints, serviceDiscovery, honoApp, openApiOptions);
|
|
110
|
-
|
|
111
|
-
return honoApp;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Default export for convenience
|
|
115
|
-
export default createApp;
|
|
116
|
-
`;
|
|
117
|
-
await (0, node_fs_promises.writeFile)(serverPath, content);
|
|
118
|
-
return serverPath;
|
|
119
|
-
}
|
|
120
|
-
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
|
|
121
|
-
const handlerFileName = `${exportName}.ts`;
|
|
122
|
-
const handlerPath = (0, path.join)(outputDir, handlerFileName);
|
|
123
|
-
const relativePath = (0, path.relative)((0, path.dirname)(handlerPath), sourceFile);
|
|
124
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
125
|
-
const relativeEnvParserPath = (0, path.relative)((0, path.dirname)(handlerPath), envParserPath);
|
|
126
|
-
let content;
|
|
127
|
-
switch (provider) {
|
|
128
|
-
case "aws-apigatewayv1":
|
|
129
|
-
content = generateAWSApiGatewayV1Handler(importPath, exportName, relativeEnvParserPath, envParserImportPattern);
|
|
130
|
-
break;
|
|
131
|
-
case "aws-apigatewayv2":
|
|
132
|
-
content = generateAWSApiGatewayV2Handler(importPath, exportName, relativeEnvParserPath, envParserImportPattern);
|
|
133
|
-
break;
|
|
134
|
-
case "server":
|
|
135
|
-
content = generateServerHandler(importPath, exportName);
|
|
136
|
-
break;
|
|
137
|
-
default: throw new Error(`Unsupported provider: ${provider}`);
|
|
138
|
-
}
|
|
139
|
-
await (0, node_fs_promises.writeFile)(handlerPath, content);
|
|
140
|
-
return handlerPath;
|
|
141
|
-
}
|
|
142
|
-
function generateAWSApiGatewayV1Handler(importPath, exportName, envParserPath, envParserImportPattern) {
|
|
143
|
-
return `import { AmazonApiGatewayV1Endpoint } from '@geekmidas/api/aws-apigateway';
|
|
144
|
-
import { ${exportName} } from '${importPath}';
|
|
145
|
-
import ${envParserImportPattern} from '${envParserPath}';
|
|
146
|
-
|
|
147
|
-
const adapter = new AmazonApiGatewayV1Endpoint(envParser, ${exportName});
|
|
148
|
-
|
|
149
|
-
export const handler = adapter.handler;
|
|
150
|
-
`;
|
|
151
|
-
}
|
|
152
|
-
function generateAWSApiGatewayV2Handler(importPath, exportName, envParserPath, envParserImportPattern) {
|
|
153
|
-
return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/api/aws-apigateway';
|
|
154
|
-
import { ${exportName} } from '${importPath}';
|
|
155
|
-
import ${envParserImportPattern} from '${envParserPath}';
|
|
156
|
-
|
|
157
|
-
const adapter = new AmazonApiGatewayV2Endpoint(envParser, ${exportName});
|
|
158
|
-
|
|
159
|
-
export const handler = adapter.handler;
|
|
160
|
-
`;
|
|
161
|
-
}
|
|
162
|
-
function generateServerHandler(importPath, exportName) {
|
|
163
|
-
return `import { ${exportName} } from '${importPath}';
|
|
164
|
-
|
|
165
|
-
// Server handler - implement based on your server framework
|
|
166
|
-
export const handler = ${exportName};
|
|
167
|
-
`;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
//#endregion
|
|
171
|
-
Object.defineProperty(exports, 'buildCommand', {
|
|
172
|
-
enumerable: true,
|
|
173
|
-
get: function () {
|
|
174
|
-
return buildCommand;
|
|
175
|
-
}
|
|
176
|
-
});
|
package/dist/build-Ca4P6_lY.mjs
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from "./config-BciAdY6_.mjs";
|
|
2
|
-
import { loadEndpoints } from "./loadEndpoints-DAZ53Og2.mjs";
|
|
3
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
-
import { dirname, join, relative } from "path";
|
|
5
|
-
|
|
6
|
-
//#region src/build.ts
|
|
7
|
-
const logger = console;
|
|
8
|
-
async function buildCommand(options) {
|
|
9
|
-
logger.log(`Building with providers: ${options.providers.join(", ")}`);
|
|
10
|
-
const config = await loadConfig();
|
|
11
|
-
logger.log(`Loading routes from: ${config.routes}`);
|
|
12
|
-
logger.log(`Using envParser: ${config.envParser}`);
|
|
13
|
-
const [envParserPath, envParserName] = config.envParser.split("#");
|
|
14
|
-
const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
|
|
15
|
-
const [loggerPath, loggerName] = config.logger.split("#");
|
|
16
|
-
const loggerImportPattern = !loggerName ? "logger" : loggerName === "logger" ? "{ logger }" : `{ ${loggerName} as logger }`;
|
|
17
|
-
const loadedEndpoints = await loadEndpoints(config.routes);
|
|
18
|
-
if (loadedEndpoints.length === 0) {
|
|
19
|
-
logger.log("No endpoints found to process");
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const allEndpoints = loadedEndpoints.map(({ name, endpoint, file }) => {
|
|
23
|
-
const routeInfo = {
|
|
24
|
-
path: endpoint._path,
|
|
25
|
-
method: endpoint.method,
|
|
26
|
-
handler: ""
|
|
27
|
-
};
|
|
28
|
-
logger.log(`Found endpoint: ${name} - ${routeInfo.method} ${routeInfo.path}`);
|
|
29
|
-
return {
|
|
30
|
-
file: relative(process.cwd(), file),
|
|
31
|
-
exportName: name,
|
|
32
|
-
endpoint,
|
|
33
|
-
routeInfo
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
for (const provider of options.providers) {
|
|
37
|
-
const routes = [];
|
|
38
|
-
const outputDir = join(process.cwd(), ".gkm", provider);
|
|
39
|
-
await mkdir(outputDir, { recursive: true });
|
|
40
|
-
logger.log(`\nGenerating handlers for provider: ${provider}`);
|
|
41
|
-
if (provider === "server") {
|
|
42
|
-
const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, options.enableOpenApi || false);
|
|
43
|
-
routes.push({
|
|
44
|
-
path: "*",
|
|
45
|
-
method: "ALL",
|
|
46
|
-
handler: relative(process.cwd(), serverFile)
|
|
47
|
-
});
|
|
48
|
-
logger.log(`Generated server app with ${allEndpoints.length} endpoints${options.enableOpenApi ? " (OpenAPI enabled)" : ""}`);
|
|
49
|
-
} else for (const { file, exportName, routeInfo } of allEndpoints) {
|
|
50
|
-
const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern);
|
|
51
|
-
routes.push({
|
|
52
|
-
...routeInfo,
|
|
53
|
-
handler: relative(process.cwd(), handlerFile).replace(/\.ts$/, ".handler")
|
|
54
|
-
});
|
|
55
|
-
logger.log(`Generated handler for ${routeInfo.method} ${routeInfo.path}`);
|
|
56
|
-
}
|
|
57
|
-
const manifest = { routes };
|
|
58
|
-
const manifestPath = join(outputDir, "routes.json");
|
|
59
|
-
await writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
60
|
-
logger.log(`Generated ${routes.length} handlers in ${relative(process.cwd(), outputDir)}`);
|
|
61
|
-
logger.log(`Routes manifest: ${relative(process.cwd(), manifestPath)}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, enableOpenApi) {
|
|
65
|
-
const serverFileName = "app.ts";
|
|
66
|
-
const serverPath = join(outputDir, serverFileName);
|
|
67
|
-
const importsByFile = /* @__PURE__ */ new Map();
|
|
68
|
-
for (const { file, exportName } of endpoints) {
|
|
69
|
-
const relativePath = relative(dirname(serverPath), file);
|
|
70
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
71
|
-
if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
|
|
72
|
-
importsByFile.get(importPath).push(exportName);
|
|
73
|
-
}
|
|
74
|
-
const relativeEnvParserPath = relative(dirname(serverPath), envParserPath);
|
|
75
|
-
const relativeLoggerPath = relative(dirname(serverPath), loggerPath);
|
|
76
|
-
const imports = Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n");
|
|
77
|
-
const allExportNames = endpoints.map(({ exportName }) => exportName);
|
|
78
|
-
const content = `import { HonoEndpoint } from '@geekmidas/api/hono';
|
|
79
|
-
import { Endpoint } from '@geekmidas/api/server';
|
|
80
|
-
import { ServiceDiscovery } from '@geekmidas/api/services';
|
|
81
|
-
import { Hono } from 'hono';
|
|
82
|
-
import ${envParserImportPattern} from '${relativeEnvParserPath}';
|
|
83
|
-
import ${loggerImportPattern} from '${relativeLoggerPath}';
|
|
84
|
-
${imports}
|
|
85
|
-
|
|
86
|
-
export function createApp(app?: Hono, enableOpenApi: boolean = ${enableOpenApi}): Hono {
|
|
87
|
-
const honoApp = app || new Hono();
|
|
88
|
-
|
|
89
|
-
const endpoints: Endpoint<any, any, any, any, any, any, any>[] = [
|
|
90
|
-
${allExportNames.join(",\n ")}
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
const serviceDiscovery = ServiceDiscovery.getInstance(
|
|
94
|
-
logger,
|
|
95
|
-
envParser
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// Configure OpenAPI options based on enableOpenApi flag
|
|
99
|
-
const openApiOptions: any = enableOpenApi ? {
|
|
100
|
-
docsPath: '/docs',
|
|
101
|
-
openApiOptions: {
|
|
102
|
-
title: 'API Documentation',
|
|
103
|
-
version: '1.0.0',
|
|
104
|
-
description: 'Generated API documentation'
|
|
105
|
-
}
|
|
106
|
-
} : { docsPath: false };
|
|
107
|
-
|
|
108
|
-
HonoEndpoint.addRoutes(endpoints, serviceDiscovery, honoApp, openApiOptions);
|
|
109
|
-
|
|
110
|
-
return honoApp;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Default export for convenience
|
|
114
|
-
export default createApp;
|
|
115
|
-
`;
|
|
116
|
-
await writeFile(serverPath, content);
|
|
117
|
-
return serverPath;
|
|
118
|
-
}
|
|
119
|
-
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
|
|
120
|
-
const handlerFileName = `${exportName}.ts`;
|
|
121
|
-
const handlerPath = join(outputDir, handlerFileName);
|
|
122
|
-
const relativePath = relative(dirname(handlerPath), sourceFile);
|
|
123
|
-
const importPath = relativePath.replace(/\.ts$/, ".js");
|
|
124
|
-
const relativeEnvParserPath = relative(dirname(handlerPath), envParserPath);
|
|
125
|
-
let content;
|
|
126
|
-
switch (provider) {
|
|
127
|
-
case "aws-apigatewayv1":
|
|
128
|
-
content = generateAWSApiGatewayV1Handler(importPath, exportName, relativeEnvParserPath, envParserImportPattern);
|
|
129
|
-
break;
|
|
130
|
-
case "aws-apigatewayv2":
|
|
131
|
-
content = generateAWSApiGatewayV2Handler(importPath, exportName, relativeEnvParserPath, envParserImportPattern);
|
|
132
|
-
break;
|
|
133
|
-
case "server":
|
|
134
|
-
content = generateServerHandler(importPath, exportName);
|
|
135
|
-
break;
|
|
136
|
-
default: throw new Error(`Unsupported provider: ${provider}`);
|
|
137
|
-
}
|
|
138
|
-
await writeFile(handlerPath, content);
|
|
139
|
-
return handlerPath;
|
|
140
|
-
}
|
|
141
|
-
function generateAWSApiGatewayV1Handler(importPath, exportName, envParserPath, envParserImportPattern) {
|
|
142
|
-
return `import { AmazonApiGatewayV1Endpoint } from '@geekmidas/api/aws-apigateway';
|
|
143
|
-
import { ${exportName} } from '${importPath}';
|
|
144
|
-
import ${envParserImportPattern} from '${envParserPath}';
|
|
145
|
-
|
|
146
|
-
const adapter = new AmazonApiGatewayV1Endpoint(envParser, ${exportName});
|
|
147
|
-
|
|
148
|
-
export const handler = adapter.handler;
|
|
149
|
-
`;
|
|
150
|
-
}
|
|
151
|
-
function generateAWSApiGatewayV2Handler(importPath, exportName, envParserPath, envParserImportPattern) {
|
|
152
|
-
return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/api/aws-apigateway';
|
|
153
|
-
import { ${exportName} } from '${importPath}';
|
|
154
|
-
import ${envParserImportPattern} from '${envParserPath}';
|
|
155
|
-
|
|
156
|
-
const adapter = new AmazonApiGatewayV2Endpoint(envParser, ${exportName});
|
|
157
|
-
|
|
158
|
-
export const handler = adapter.handler;
|
|
159
|
-
`;
|
|
160
|
-
}
|
|
161
|
-
function generateServerHandler(importPath, exportName) {
|
|
162
|
-
return `import { ${exportName} } from '${importPath}';
|
|
163
|
-
|
|
164
|
-
// Server handler - implement based on your server framework
|
|
165
|
-
export const handler = ${exportName};
|
|
166
|
-
`;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
//#endregion
|
|
170
|
-
export { buildCommand };
|
package/dist/build.cjs
DELETED
package/dist/build.mjs
DELETED
package/dist/config-BNqUMsvc.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const path = require_chunk.__toESM(require("path"));
|
|
3
|
-
const fs = require_chunk.__toESM(require("fs"));
|
|
4
|
-
const fs_promises = require_chunk.__toESM(require("fs/promises"));
|
|
5
|
-
|
|
6
|
-
//#region src/config.ts
|
|
7
|
-
async function loadConfig() {
|
|
8
|
-
const configPath = (0, path.join)(process.cwd(), "gkm.config.json");
|
|
9
|
-
if (!(0, fs.existsSync)(configPath)) throw new Error("gkm.config.json not found. Please create a configuration file.");
|
|
10
|
-
try {
|
|
11
|
-
const config = await (0, fs_promises.readFile)(configPath, "utf-8");
|
|
12
|
-
return JSON.parse(config);
|
|
13
|
-
} catch (error) {
|
|
14
|
-
throw new Error(`Failed to load gkm.config.json: ${error.message}`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
Object.defineProperty(exports, 'loadConfig', {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return loadConfig;
|
|
23
|
-
}
|
|
24
|
-
});
|
package/dist/config-BciAdY6_.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { join } from "path";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { readFile } from "fs/promises";
|
|
4
|
-
|
|
5
|
-
//#region src/config.ts
|
|
6
|
-
async function loadConfig() {
|
|
7
|
-
const configPath = join(process.cwd(), "gkm.config.json");
|
|
8
|
-
if (!existsSync(configPath)) throw new Error("gkm.config.json not found. Please create a configuration file.");
|
|
9
|
-
try {
|
|
10
|
-
const config = await readFile(configPath, "utf-8");
|
|
11
|
-
return JSON.parse(config);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
throw new Error(`Failed to load gkm.config.json: ${error.message}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { loadConfig };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const __geekmidas_api_server = require_chunk.__toESM(require("@geekmidas/api/server"));
|
|
3
|
-
const fast_glob = require_chunk.__toESM(require("fast-glob"));
|
|
4
|
-
|
|
5
|
-
//#region src/loadEndpoints.ts
|
|
6
|
-
async function loadEndpoints(routes) {
|
|
7
|
-
const logger = console;
|
|
8
|
-
const files = await fast_glob.default.stream(routes, {
|
|
9
|
-
cwd: process.cwd(),
|
|
10
|
-
absolute: true
|
|
11
|
-
});
|
|
12
|
-
const endpoints = [];
|
|
13
|
-
for await (const f of files) try {
|
|
14
|
-
const file = f.toString();
|
|
15
|
-
const module$1 = await import(file);
|
|
16
|
-
for (const [exportName, exportValue] of Object.entries(module$1)) if (__geekmidas_api_server.Endpoint.isEndpoint(exportValue)) {
|
|
17
|
-
exportValue.operationId = exportName;
|
|
18
|
-
endpoints.push({
|
|
19
|
-
name: exportName,
|
|
20
|
-
endpoint: exportValue,
|
|
21
|
-
file
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
} catch (error) {
|
|
25
|
-
logger.warn(`Failed to load ${f}:`, error.message);
|
|
26
|
-
throw new Error("Failed to load endpoints. Please check the logs for details.");
|
|
27
|
-
}
|
|
28
|
-
return endpoints;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
Object.defineProperty(exports, 'loadEndpoints', {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return loadEndpoints;
|
|
36
|
-
}
|
|
37
|
-
});
|