@geekmidas/cli 0.10.0 → 0.13.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-B1qy9b-j.cjs +112 -0
- package/dist/bundler-B1qy9b-j.cjs.map +1 -0
- package/dist/bundler-DskIqW2t.mjs +111 -0
- package/dist/bundler-DskIqW2t.mjs.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 +2123 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2141 -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-BOOpAF8N.cjs +5 -0
- package/dist/storage-Bj1E26lU.cjs +187 -0
- package/dist/storage-Bj1E26lU.cjs.map +1 -0
- package/dist/storage-kSxTjkNb.mjs +133 -0
- package/dist/storage-kSxTjkNb.mjs.map +1 -0
- package/dist/storage-tgZSUnKl.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__/bundler.spec.ts +444 -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 +210 -0
- package/src/build/endpoint-analyzer.ts +236 -0
- package/src/build/handler-templates.ts +1253 -0
- package/src/build/index.ts +260 -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 +611 -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 +192 -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
|
@@ -4,102 +4,102 @@ import { Function } from '@geekmidas/constructs/functions';
|
|
|
4
4
|
import type { BuildContext } from '../build/types';
|
|
5
5
|
import type { FunctionInfo } from '../types';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
ConstructGenerator,
|
|
8
|
+
type GeneratedConstruct,
|
|
9
|
+
type GeneratorOptions,
|
|
10
10
|
} from './Generator';
|
|
11
11
|
|
|
12
12
|
export class FunctionGenerator extends ConstructGenerator<
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
Function<any, any, any, any, any, any, any, any, any, any, any, any>,
|
|
14
|
+
FunctionInfo[]
|
|
15
15
|
> {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
isConstruct(
|
|
17
|
+
value: any,
|
|
18
|
+
): value is Function<
|
|
19
|
+
any,
|
|
20
|
+
any,
|
|
21
|
+
any,
|
|
22
|
+
any,
|
|
23
|
+
any,
|
|
24
|
+
any,
|
|
25
|
+
any,
|
|
26
|
+
any,
|
|
27
|
+
any,
|
|
28
|
+
any,
|
|
29
|
+
any,
|
|
30
|
+
any
|
|
31
|
+
> {
|
|
32
|
+
return Function.isFunction(value);
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
async build(
|
|
36
|
+
context: BuildContext,
|
|
37
|
+
constructs: GeneratedConstruct<
|
|
38
|
+
Function<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
39
|
+
>[],
|
|
40
|
+
outputDir: string,
|
|
41
|
+
options?: GeneratorOptions,
|
|
42
|
+
): Promise<FunctionInfo[]> {
|
|
43
|
+
const provider = options?.provider || 'aws-lambda';
|
|
44
|
+
const logger = console;
|
|
45
|
+
const functionInfos: FunctionInfo[] = [];
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
if (constructs.length === 0 || provider !== 'aws-lambda') {
|
|
48
|
+
return functionInfos;
|
|
49
|
+
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// Create functions subdirectory
|
|
52
|
+
const functionsDir = join(outputDir, 'functions');
|
|
53
|
+
await mkdir(functionsDir, { recursive: true });
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
// Generate function handlers
|
|
56
|
+
for (const { key, construct, path } of constructs) {
|
|
57
|
+
const handlerFile = await this.generateFunctionHandler(
|
|
58
|
+
functionsDir,
|
|
59
|
+
path.relative,
|
|
60
|
+
key,
|
|
61
|
+
context,
|
|
62
|
+
);
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
functionInfos.push({
|
|
65
|
+
name: key,
|
|
66
|
+
handler: relative(process.cwd(), handlerFile).replace(
|
|
67
|
+
/\.ts$/,
|
|
68
|
+
'.handler',
|
|
69
|
+
),
|
|
70
|
+
timeout: construct.timeout,
|
|
71
|
+
memorySize: construct.memorySize,
|
|
72
|
+
environment: await construct.getEnvironment(),
|
|
73
|
+
});
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
logger.log(`Generated function handler: ${key}`);
|
|
76
|
+
}
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
return functionInfos;
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
private async generateFunctionHandler(
|
|
82
|
+
outputDir: string,
|
|
83
|
+
sourceFile: string,
|
|
84
|
+
exportName: string,
|
|
85
|
+
context: BuildContext,
|
|
86
|
+
): Promise<string> {
|
|
87
|
+
const handlerFileName = `${exportName}.ts`;
|
|
88
|
+
const handlerPath = join(outputDir, handlerFileName);
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const relativePath = relative(dirname(handlerPath), sourceFile);
|
|
91
|
+
const importPath = relativePath.replace(/\.ts$/, '.js');
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
const relativeEnvParserPath = relative(
|
|
94
|
+
dirname(handlerPath),
|
|
95
|
+
context.envParserPath,
|
|
96
|
+
);
|
|
97
|
+
const relativeLoggerPath = relative(
|
|
98
|
+
dirname(handlerPath),
|
|
99
|
+
context.loggerPath,
|
|
100
|
+
);
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
const content = `import { AWSLambdaFunction } from '@geekmidas/constructs/functions';
|
|
103
103
|
import { ${exportName} } from '${importPath}';
|
|
104
104
|
import ${context.envParserImportPattern} from '${relativeEnvParserPath}';
|
|
105
105
|
import ${context.loggerImportPattern} from '${relativeLoggerPath}';
|
|
@@ -109,7 +109,7 @@ const adapter = new AWSLambdaFunction(envParser, ${exportName});
|
|
|
109
109
|
export const handler = adapter.handler;
|
|
110
110
|
`;
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
await writeFile(handlerPath, content);
|
|
113
|
+
return handlerPath;
|
|
114
|
+
}
|
|
115
115
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relative } from 'path';
|
|
1
|
+
import { relative } from 'node:path';
|
|
2
2
|
import type { Construct } from '@geekmidas/constructs';
|
|
3
3
|
import fg from 'fast-glob';
|
|
4
4
|
import kebabCase from 'lodash.kebabcase';
|
|
@@ -6,90 +6,90 @@ import type { BuildContext } from '../build/types';
|
|
|
6
6
|
import type { LegacyProvider, Routes } from '../types';
|
|
7
7
|
|
|
8
8
|
export interface GeneratorOptions {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
provider?: LegacyProvider;
|
|
10
|
+
[key: string]: any;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export abstract class ConstructGenerator<T extends Construct, R = void> {
|
|
14
|
-
|
|
14
|
+
abstract isConstruct(value: any): value is T;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
static async build<T extends Construct, R = void>(
|
|
17
|
+
context: BuildContext,
|
|
18
|
+
outputDir: string,
|
|
19
|
+
generator: ConstructGenerator<T, R>,
|
|
20
|
+
patterns?: Routes,
|
|
21
|
+
options?: GeneratorOptions,
|
|
22
|
+
): Promise<R> {
|
|
23
|
+
const constructs = await generator.load(patterns);
|
|
24
|
+
return generator.build(context, constructs, outputDir, options);
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
abstract build(
|
|
28
|
+
context: BuildContext,
|
|
29
|
+
constructs: GeneratedConstruct<T>[],
|
|
30
|
+
outputDir: string,
|
|
31
|
+
options?: GeneratorOptions,
|
|
32
|
+
): Promise<R>;
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
async load(
|
|
35
|
+
patterns?: Routes,
|
|
36
|
+
cwd = process.cwd(),
|
|
37
|
+
): Promise<GeneratedConstruct<T>[]> {
|
|
38
|
+
const logger = console;
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
// Normalize patterns to array
|
|
41
|
+
const globPatterns = Array.isArray(patterns)
|
|
42
|
+
? patterns
|
|
43
|
+
: patterns
|
|
44
|
+
? [patterns]
|
|
45
|
+
: [];
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
// Find all files
|
|
48
|
+
const files = fg.stream(globPatterns, {
|
|
49
|
+
cwd,
|
|
50
|
+
absolute: true,
|
|
51
|
+
});
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// Load constructs
|
|
54
|
+
const constructs: GeneratedConstruct<T>[] = [];
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
for await (const f of files) {
|
|
57
|
+
try {
|
|
58
|
+
const file = f.toString();
|
|
59
|
+
const module = await import(file);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
// Check all exports for constructs
|
|
62
|
+
for (const [key, construct] of Object.entries(module)) {
|
|
63
|
+
if (this.isConstruct(construct)) {
|
|
64
|
+
constructs.push({
|
|
65
|
+
key,
|
|
66
|
+
name: kebabCase(key),
|
|
67
|
+
construct,
|
|
68
|
+
path: {
|
|
69
|
+
absolute: file,
|
|
70
|
+
relative: relative(process.cwd(), file),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
logger.warn(`Failed to load ${f}:`, (error as Error).message);
|
|
77
|
+
throw new Error(
|
|
78
|
+
'Failed to load constructs. Please check the logs for details.',
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
return constructs;
|
|
84
|
+
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export interface GeneratedConstruct<T extends Construct> {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
key: string;
|
|
89
|
+
name: string;
|
|
90
|
+
construct: T;
|
|
91
|
+
path: {
|
|
92
|
+
absolute: string;
|
|
93
|
+
relative: string;
|
|
94
|
+
};
|
|
95
95
|
}
|