@geekmidas/cli 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-DNUd8HBL.cjs → build-BOIEItQ4.cjs} +29 -26
- package/dist/{build-SdnSQPW7.mjs → build-HqXSd7ux.mjs} +29 -26
- package/dist/build.cjs +2 -2
- package/dist/build.mjs +2 -2
- package/dist/{cli-CfgR8d0p.mjs → cli-8JB9d4XW.mjs} +16 -5
- package/dist/{cli-DkqbpY0m.cjs → cli-8aXEWjpV.cjs} +16 -5
- package/dist/cli.cjs +4 -4
- package/dist/cli.mjs +4 -4
- package/dist/{config-B-D8cs7V.cjs → config-D8AyiwBU.cjs} +2 -2
- package/dist/{config-Bzzc89wR.mjs → config-DV1Lwdkx.mjs} +2 -2
- package/dist/config.cjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{openapi-DLix_iqn.mjs → openapi-CVu3aUU8.mjs} +1 -1
- package/dist/{openapi-BKjcm03Q.cjs → openapi-DD-MfKrj.cjs} +1 -1
- package/dist/openapi.cjs +2 -2
- package/dist/openapi.mjs +2 -2
- package/package.json +1 -1
- package/src/build.ts +54 -49
- package/src/cli.ts +27 -5
- package/src/config.ts +2 -2
- package/src/types.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_config = require('./config-
|
|
2
|
+
const require_config = require('./config-D8AyiwBU.cjs');
|
|
3
3
|
const require_loadEndpoints = require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
4
|
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
5
5
|
const path = require_chunk.__toESM(require("path"));
|
|
@@ -7,7 +7,7 @@ const path = require_chunk.__toESM(require("path"));
|
|
|
7
7
|
//#region src/build.ts
|
|
8
8
|
const logger = console;
|
|
9
9
|
async function buildCommand(options) {
|
|
10
|
-
logger.log(`Building with
|
|
10
|
+
logger.log(`Building with providers: ${options.providers.join(", ")}`);
|
|
11
11
|
const config = await require_config.loadConfig();
|
|
12
12
|
logger.log(`Loading routes from: ${config.routes}`);
|
|
13
13
|
logger.log(`Using envParser: ${config.envParser}`);
|
|
@@ -15,9 +15,6 @@ async function buildCommand(options) {
|
|
|
15
15
|
const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
|
|
16
16
|
const [loggerPath, loggerName] = config.logger.split("#");
|
|
17
17
|
const loggerImportPattern = !loggerName ? "logger" : loggerName === "logger" ? "{ logger }" : `{ ${loggerName} as logger }`;
|
|
18
|
-
const routes = [];
|
|
19
|
-
const outputDir = (0, path.join)(process.cwd(), ".gkm", options.provider);
|
|
20
|
-
await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
|
|
21
18
|
const loadedEndpoints = await require_loadEndpoints.loadEndpoints(config.routes);
|
|
22
19
|
if (loadedEndpoints.length === 0) {
|
|
23
20
|
logger.log("No endpoints found to process");
|
|
@@ -37,27 +34,33 @@ async function buildCommand(options) {
|
|
|
37
34
|
routeInfo
|
|
38
35
|
};
|
|
39
36
|
});
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
|
|
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);
|
|
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`);
|
|
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)}`);
|
|
55
63
|
}
|
|
56
|
-
const manifest = { routes };
|
|
57
|
-
const manifestPath = (0, path.join)(outputDir, "routes.json");
|
|
58
|
-
await (0, node_fs_promises.writeFile)(manifestPath, JSON.stringify(manifest, null, 2));
|
|
59
|
-
logger.log(`Generated ${routes.length} handlers in ${(0, path.relative)(process.cwd(), outputDir)}`);
|
|
60
|
-
logger.log(`Routes manifest: ${(0, path.relative)(process.cwd(), manifestPath)}`);
|
|
61
64
|
}
|
|
62
65
|
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern) {
|
|
63
66
|
const serverFileName = "app.ts";
|
|
@@ -104,7 +107,7 @@ export default createApp;
|
|
|
104
107
|
await (0, node_fs_promises.writeFile)(serverPath, content);
|
|
105
108
|
return serverPath;
|
|
106
109
|
}
|
|
107
|
-
async function generateHandlerFile(outputDir, sourceFile, exportName, provider,
|
|
110
|
+
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
|
|
108
111
|
const handlerFileName = `${exportName}.ts`;
|
|
109
112
|
const handlerPath = (0, path.join)(outputDir, handlerFileName);
|
|
110
113
|
const relativePath = (0, path.relative)((0, path.dirname)(handlerPath), sourceFile);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadConfig } from "./config-
|
|
1
|
+
import { loadConfig } from "./config-DV1Lwdkx.mjs";
|
|
2
2
|
import { loadEndpoints } from "./loadEndpoints-BL8q2rTO.mjs";
|
|
3
3
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, join, relative } from "path";
|
|
@@ -6,7 +6,7 @@ import { dirname, join, relative } from "path";
|
|
|
6
6
|
//#region src/build.ts
|
|
7
7
|
const logger = console;
|
|
8
8
|
async function buildCommand(options) {
|
|
9
|
-
logger.log(`Building with
|
|
9
|
+
logger.log(`Building with providers: ${options.providers.join(", ")}`);
|
|
10
10
|
const config = await loadConfig();
|
|
11
11
|
logger.log(`Loading routes from: ${config.routes}`);
|
|
12
12
|
logger.log(`Using envParser: ${config.envParser}`);
|
|
@@ -14,9 +14,6 @@ async function buildCommand(options) {
|
|
|
14
14
|
const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
|
|
15
15
|
const [loggerPath, loggerName] = config.logger.split("#");
|
|
16
16
|
const loggerImportPattern = !loggerName ? "logger" : loggerName === "logger" ? "{ logger }" : `{ ${loggerName} as logger }`;
|
|
17
|
-
const routes = [];
|
|
18
|
-
const outputDir = join(process.cwd(), ".gkm", options.provider);
|
|
19
|
-
await mkdir(outputDir, { recursive: true });
|
|
20
17
|
const loadedEndpoints = await loadEndpoints(config.routes);
|
|
21
18
|
if (loadedEndpoints.length === 0) {
|
|
22
19
|
logger.log("No endpoints found to process");
|
|
@@ -36,27 +33,33 @@ async function buildCommand(options) {
|
|
|
36
33
|
routeInfo
|
|
37
34
|
};
|
|
38
35
|
});
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
-
|
|
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);
|
|
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`);
|
|
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)}`);
|
|
54
62
|
}
|
|
55
|
-
const manifest = { routes };
|
|
56
|
-
const manifestPath = join(outputDir, "routes.json");
|
|
57
|
-
await writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
58
|
-
logger.log(`Generated ${routes.length} handlers in ${relative(process.cwd(), outputDir)}`);
|
|
59
|
-
logger.log(`Routes manifest: ${relative(process.cwd(), manifestPath)}`);
|
|
60
63
|
}
|
|
61
64
|
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern) {
|
|
62
65
|
const serverFileName = "app.ts";
|
|
@@ -103,7 +106,7 @@ export default createApp;
|
|
|
103
106
|
await writeFile(serverPath, content);
|
|
104
107
|
return serverPath;
|
|
105
108
|
}
|
|
106
|
-
async function generateHandlerFile(outputDir, sourceFile, exportName, provider,
|
|
109
|
+
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
|
|
107
110
|
const handlerFileName = `${exportName}.ts`;
|
|
108
111
|
const handlerPath = join(outputDir, handlerFileName);
|
|
109
112
|
const relativePath = relative(dirname(handlerPath), sourceFile);
|
package/dist/build.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require('./config-
|
|
1
|
+
require('./config-D8AyiwBU.cjs');
|
|
2
2
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
3
|
-
const require_build = require('./build-
|
|
3
|
+
const require_build = require('./build-BOIEItQ4.cjs');
|
|
4
4
|
|
|
5
5
|
exports.buildCommand = require_build.buildCommand;
|
package/dist/build.mjs
CHANGED
|
@@ -1,29 +1,40 @@
|
|
|
1
|
-
import { buildCommand } from "./build-
|
|
2
|
-
import { openapiCommand } from "./openapi-
|
|
1
|
+
import { buildCommand } from "./build-HqXSd7ux.mjs";
|
|
2
|
+
import { openapiCommand } from "./openapi-CVu3aUU8.mjs";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
|
|
5
5
|
//#region src/cli.ts
|
|
6
6
|
const program = new Command();
|
|
7
|
-
program.name("gkm").description("GeekMidas backend framework CLI").version("0.0.2");
|
|
8
|
-
program.command("build").description("Build API handlers from endpoints").option("--
|
|
7
|
+
program.name("gkm").description("GeekMidas backend framework CLI").version("0.0.2").option("--cwd <path>", "Change working directory");
|
|
8
|
+
program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
|
|
9
9
|
try {
|
|
10
|
-
|
|
10
|
+
const globalOptions = program.opts();
|
|
11
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
12
|
+
const providerList = [...new Set(options.providers.split(",").map((p) => p.trim()))];
|
|
13
|
+
await buildCommand({ providers: providerList });
|
|
11
14
|
} catch (error) {
|
|
12
15
|
console.error("Build failed:", error.message);
|
|
13
16
|
process.exit(1);
|
|
14
17
|
}
|
|
15
18
|
});
|
|
16
19
|
program.command("cron").description("Manage cron jobs").action(() => {
|
|
20
|
+
const globalOptions = program.opts();
|
|
21
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
17
22
|
process.stdout.write("Cron management - coming soon\n");
|
|
18
23
|
});
|
|
19
24
|
program.command("function").description("Manage serverless functions").action(() => {
|
|
25
|
+
const globalOptions = program.opts();
|
|
26
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
20
27
|
process.stdout.write("Serverless function management - coming soon\n");
|
|
21
28
|
});
|
|
22
29
|
program.command("api").description("Manage REST API endpoints").action(() => {
|
|
30
|
+
const globalOptions = program.opts();
|
|
31
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
23
32
|
process.stdout.write("REST API management - coming soon\n");
|
|
24
33
|
});
|
|
25
34
|
program.command("openapi").description("Generate OpenAPI 3.0 specification from endpoints").option("--output <path>", "Output file path for the OpenAPI spec", "openapi.json").action(async (options) => {
|
|
26
35
|
try {
|
|
36
|
+
const globalOptions = program.opts();
|
|
37
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
27
38
|
await openapiCommand(options);
|
|
28
39
|
} catch (error) {
|
|
29
40
|
console.error("OpenAPI generation failed:", error.message);
|
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_build = require('./build-
|
|
3
|
-
const require_openapi = require('./openapi-
|
|
2
|
+
const require_build = require('./build-BOIEItQ4.cjs');
|
|
3
|
+
const require_openapi = require('./openapi-DD-MfKrj.cjs');
|
|
4
4
|
const commander = require_chunk.__toESM(require("commander"));
|
|
5
5
|
|
|
6
6
|
//#region src/cli.ts
|
|
7
7
|
const program = new commander.Command();
|
|
8
|
-
program.name("gkm").description("GeekMidas backend framework CLI").version("0.0.2");
|
|
9
|
-
program.command("build").description("Build API handlers from endpoints").option("--
|
|
8
|
+
program.name("gkm").description("GeekMidas backend framework CLI").version("0.0.2").option("--cwd <path>", "Change working directory");
|
|
9
|
+
program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
const globalOptions = program.opts();
|
|
12
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
13
|
+
const providerList = [...new Set(options.providers.split(",").map((p) => p.trim()))];
|
|
14
|
+
await require_build.buildCommand({ providers: providerList });
|
|
12
15
|
} catch (error) {
|
|
13
16
|
console.error("Build failed:", error.message);
|
|
14
17
|
process.exit(1);
|
|
15
18
|
}
|
|
16
19
|
});
|
|
17
20
|
program.command("cron").description("Manage cron jobs").action(() => {
|
|
21
|
+
const globalOptions = program.opts();
|
|
22
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
18
23
|
process.stdout.write("Cron management - coming soon\n");
|
|
19
24
|
});
|
|
20
25
|
program.command("function").description("Manage serverless functions").action(() => {
|
|
26
|
+
const globalOptions = program.opts();
|
|
27
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
21
28
|
process.stdout.write("Serverless function management - coming soon\n");
|
|
22
29
|
});
|
|
23
30
|
program.command("api").description("Manage REST API endpoints").action(() => {
|
|
31
|
+
const globalOptions = program.opts();
|
|
32
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
24
33
|
process.stdout.write("REST API management - coming soon\n");
|
|
25
34
|
});
|
|
26
35
|
program.command("openapi").description("Generate OpenAPI 3.0 specification from endpoints").option("--output <path>", "Output file path for the OpenAPI spec", "openapi.json").action(async (options) => {
|
|
27
36
|
try {
|
|
37
|
+
const globalOptions = program.opts();
|
|
38
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
28
39
|
await require_openapi.openapiCommand(options);
|
|
29
40
|
} catch (error) {
|
|
30
41
|
console.error("OpenAPI generation failed:", error.message);
|
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
require('./config-
|
|
2
|
+
require('./config-D8AyiwBU.cjs');
|
|
3
3
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
|
-
require('./build-
|
|
5
|
-
require('./openapi-
|
|
6
|
-
require('./cli-
|
|
4
|
+
require('./build-BOIEItQ4.cjs');
|
|
5
|
+
require('./openapi-DD-MfKrj.cjs');
|
|
6
|
+
require('./cli-8aXEWjpV.cjs');
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import "./config-
|
|
2
|
+
import "./config-DV1Lwdkx.mjs";
|
|
3
3
|
import "./loadEndpoints-BL8q2rTO.mjs";
|
|
4
|
-
import "./build-
|
|
5
|
-
import "./openapi-
|
|
6
|
-
import "./cli-
|
|
4
|
+
import "./build-HqXSd7ux.mjs";
|
|
5
|
+
import "./openapi-CVu3aUU8.mjs";
|
|
6
|
+
import "./cli-8JB9d4XW.mjs";
|
|
@@ -4,8 +4,8 @@ const fs = require_chunk.__toESM(require("fs"));
|
|
|
4
4
|
|
|
5
5
|
//#region src/config.ts
|
|
6
6
|
async function loadConfig() {
|
|
7
|
-
const configPath = (0, path.join)(process.cwd(), "gkm.config.
|
|
8
|
-
if (!(0, fs.existsSync)(configPath)) throw new Error("gkm.config.
|
|
7
|
+
const configPath = (0, path.join)(process.cwd(), "gkm.config.json");
|
|
8
|
+
if (!(0, fs.existsSync)(configPath)) throw new Error("gkm.config.json not found. Please create a configuration file.");
|
|
9
9
|
try {
|
|
10
10
|
const config = await import(configPath);
|
|
11
11
|
return config.default || config;
|
|
@@ -3,8 +3,8 @@ import { existsSync } from "fs";
|
|
|
3
3
|
|
|
4
4
|
//#region src/config.ts
|
|
5
5
|
async function loadConfig() {
|
|
6
|
-
const configPath = join(process.cwd(), "gkm.config.
|
|
7
|
-
if (!existsSync(configPath)) throw new Error("gkm.config.
|
|
6
|
+
const configPath = join(process.cwd(), "gkm.config.json");
|
|
7
|
+
if (!existsSync(configPath)) throw new Error("gkm.config.json not found. Please create a configuration file.");
|
|
8
8
|
try {
|
|
9
9
|
const config = await import(configPath);
|
|
10
10
|
return config.default || config;
|
package/dist/config.cjs
CHANGED
package/dist/config.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
require('./config-
|
|
2
|
+
require('./config-D8AyiwBU.cjs');
|
|
3
3
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
|
-
require('./build-
|
|
5
|
-
require('./openapi-
|
|
6
|
-
require('./cli-
|
|
4
|
+
require('./build-BOIEItQ4.cjs');
|
|
5
|
+
require('./openapi-DD-MfKrj.cjs');
|
|
6
|
+
require('./cli-8aXEWjpV.cjs');
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
import "./config-
|
|
2
|
+
import "./config-DV1Lwdkx.mjs";
|
|
3
3
|
import "./loadEndpoints-BL8q2rTO.mjs";
|
|
4
|
-
import "./build-
|
|
5
|
-
import "./openapi-
|
|
6
|
-
import "./cli-
|
|
4
|
+
import "./build-HqXSd7ux.mjs";
|
|
5
|
+
import "./openapi-CVu3aUU8.mjs";
|
|
6
|
+
import "./cli-8JB9d4XW.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadConfig } from "./config-
|
|
1
|
+
import { loadConfig } from "./config-DV1Lwdkx.mjs";
|
|
2
2
|
import { loadEndpoints } from "./loadEndpoints-BL8q2rTO.mjs";
|
|
3
3
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
4
|
import { Endpoint } from "@geekmidas/api/server";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_config = require('./config-
|
|
2
|
+
const require_config = require('./config-D8AyiwBU.cjs');
|
|
3
3
|
const require_loadEndpoints = require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
4
|
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
5
5
|
const __geekmidas_api_server = require_chunk.__toESM(require("@geekmidas/api/server"));
|
package/dist/openapi.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
require('./config-
|
|
2
|
+
require('./config-D8AyiwBU.cjs');
|
|
3
3
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
|
-
const require_openapi = require('./openapi-
|
|
4
|
+
const require_openapi = require('./openapi-DD-MfKrj.cjs');
|
|
5
5
|
|
|
6
6
|
exports.openapiCommand = require_openapi.openapiCommand;
|
package/dist/openapi.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
import "./config-
|
|
2
|
+
import "./config-DV1Lwdkx.mjs";
|
|
3
3
|
import "./loadEndpoints-BL8q2rTO.mjs";
|
|
4
|
-
import { openapiCommand } from "./openapi-
|
|
4
|
+
import { openapiCommand } from "./openapi-CVu3aUU8.mjs";
|
|
5
5
|
|
|
6
6
|
export { openapiCommand };
|
package/package.json
CHANGED
package/src/build.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
|
|
12
12
|
const logger = console;
|
|
13
13
|
export async function buildCommand(options: BuildOptions): Promise<void> {
|
|
14
|
-
logger.log(`Building with
|
|
14
|
+
logger.log(`Building with providers: ${options.providers.join(', ')}`);
|
|
15
15
|
|
|
16
16
|
const config = await loadConfig();
|
|
17
17
|
logger.log(`Loading routes from: ${config.routes}`);
|
|
@@ -33,12 +33,6 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
|
|
|
33
33
|
? '{ logger }'
|
|
34
34
|
: `{ ${loggerName} as logger }`;
|
|
35
35
|
|
|
36
|
-
const routes: RouteInfo[] = [];
|
|
37
|
-
const outputDir = join(process.cwd(), '.gkm', options.provider);
|
|
38
|
-
|
|
39
|
-
// Ensure output directory exists
|
|
40
|
-
await mkdir(outputDir, { recursive: true });
|
|
41
|
-
|
|
42
36
|
// Load all endpoints using the refactored function
|
|
43
37
|
const loadedEndpoints = await loadEndpoints(config.routes);
|
|
44
38
|
|
|
@@ -66,59 +60,70 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
|
|
|
66
60
|
};
|
|
67
61
|
});
|
|
68
62
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
outputDir,
|
|
74
|
-
allEndpoints,
|
|
75
|
-
envParserPath,
|
|
76
|
-
envParserImportPattern,
|
|
77
|
-
loggerPath,
|
|
78
|
-
loggerImportPattern,
|
|
79
|
-
);
|
|
63
|
+
// Process each provider
|
|
64
|
+
for (const provider of options.providers) {
|
|
65
|
+
const routes: RouteInfo[] = [];
|
|
66
|
+
const outputDir = join(process.cwd(), '.gkm', provider);
|
|
80
67
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for (const { file, exportName, routeInfo } of allEndpoints) {
|
|
91
|
-
const handlerFile = await generateHandlerFile(
|
|
68
|
+
// Ensure output directory exists
|
|
69
|
+
await mkdir(outputDir, { recursive: true });
|
|
70
|
+
|
|
71
|
+
logger.log(`\nGenerating handlers for provider: ${provider}`);
|
|
72
|
+
|
|
73
|
+
// Generate handlers based on provider
|
|
74
|
+
if (provider === 'server') {
|
|
75
|
+
// Generate single server file with all endpoints
|
|
76
|
+
const serverFile = await generateServerFile(
|
|
92
77
|
outputDir,
|
|
93
|
-
|
|
94
|
-
exportName,
|
|
95
|
-
options.provider,
|
|
96
|
-
routeInfo,
|
|
78
|
+
allEndpoints,
|
|
97
79
|
envParserPath,
|
|
98
80
|
envParserImportPattern,
|
|
81
|
+
loggerPath,
|
|
82
|
+
loggerImportPattern,
|
|
99
83
|
);
|
|
100
84
|
|
|
101
85
|
routes.push({
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
'.handler',
|
|
106
|
-
),
|
|
86
|
+
path: '*',
|
|
87
|
+
method: 'ALL',
|
|
88
|
+
handler: relative(process.cwd(), serverFile),
|
|
107
89
|
});
|
|
108
90
|
|
|
109
|
-
logger.log(`Generated
|
|
91
|
+
logger.log(`Generated server app with ${allEndpoints.length} endpoints`);
|
|
92
|
+
} else {
|
|
93
|
+
// Generate individual handler files for AWS providers
|
|
94
|
+
for (const { file, exportName, routeInfo } of allEndpoints) {
|
|
95
|
+
const handlerFile = await generateHandlerFile(
|
|
96
|
+
outputDir,
|
|
97
|
+
file,
|
|
98
|
+
exportName,
|
|
99
|
+
provider,
|
|
100
|
+
routeInfo,
|
|
101
|
+
envParserPath,
|
|
102
|
+
envParserImportPattern,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
routes.push({
|
|
106
|
+
...routeInfo,
|
|
107
|
+
handler: relative(process.cwd(), handlerFile).replace(
|
|
108
|
+
/\.ts$/,
|
|
109
|
+
'.handler',
|
|
110
|
+
),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
logger.log(`Generated handler for ${routeInfo.method} ${routeInfo.path}`);
|
|
114
|
+
}
|
|
110
115
|
}
|
|
111
|
-
}
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
// Generate routes.json
|
|
118
|
+
const manifest: RoutesManifest = { routes };
|
|
119
|
+
const manifestPath = join(outputDir, 'routes.json');
|
|
120
|
+
await writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
117
121
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
logger.log(
|
|
123
|
+
`Generated ${routes.length} handlers in ${relative(process.cwd(), outputDir)}`,
|
|
124
|
+
);
|
|
125
|
+
logger.log(`Routes manifest: ${relative(process.cwd(), manifestPath)}`);
|
|
126
|
+
}
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
async function generateServerFile(
|
|
@@ -201,7 +206,7 @@ async function generateHandlerFile(
|
|
|
201
206
|
sourceFile: string,
|
|
202
207
|
exportName: string,
|
|
203
208
|
provider: Provider,
|
|
204
|
-
|
|
209
|
+
_routeInfo: RouteInfo,
|
|
205
210
|
envParserPath: string,
|
|
206
211
|
envParserImportPattern: string,
|
|
207
212
|
): Promise<string> {
|
package/src/cli.ts
CHANGED
|
@@ -10,19 +10,25 @@ const program = new Command();
|
|
|
10
10
|
program
|
|
11
11
|
.name('gkm')
|
|
12
12
|
.description('GeekMidas backend framework CLI')
|
|
13
|
-
.version('0.0.2')
|
|
13
|
+
.version('0.0.2')
|
|
14
|
+
.option('--cwd <path>', 'Change working directory');
|
|
14
15
|
|
|
15
16
|
program
|
|
16
17
|
.command('build')
|
|
17
18
|
.description('Build API handlers from endpoints')
|
|
18
19
|
.option(
|
|
19
|
-
'--
|
|
20
|
-
'Target
|
|
20
|
+
'--providers <providers>',
|
|
21
|
+
'Target providers for generated handlers (comma-separated)',
|
|
21
22
|
'aws-apigatewayv1',
|
|
22
23
|
)
|
|
23
|
-
.action(async (options: {
|
|
24
|
+
.action(async (options: { providers: string }) => {
|
|
24
25
|
try {
|
|
25
|
-
|
|
26
|
+
const globalOptions = program.opts();
|
|
27
|
+
if (globalOptions.cwd) {
|
|
28
|
+
process.chdir(globalOptions.cwd);
|
|
29
|
+
}
|
|
30
|
+
const providerList = [...new Set(options.providers.split(',').map(p => p.trim()))] as Provider[];
|
|
31
|
+
await buildCommand({ providers: providerList });
|
|
26
32
|
} catch (error) {
|
|
27
33
|
console.error('Build failed:', (error as Error).message);
|
|
28
34
|
process.exit(1);
|
|
@@ -33,6 +39,10 @@ program
|
|
|
33
39
|
.command('cron')
|
|
34
40
|
.description('Manage cron jobs')
|
|
35
41
|
.action(() => {
|
|
42
|
+
const globalOptions = program.opts();
|
|
43
|
+
if (globalOptions.cwd) {
|
|
44
|
+
process.chdir(globalOptions.cwd);
|
|
45
|
+
}
|
|
36
46
|
process.stdout.write('Cron management - coming soon\n');
|
|
37
47
|
});
|
|
38
48
|
|
|
@@ -40,6 +50,10 @@ program
|
|
|
40
50
|
.command('function')
|
|
41
51
|
.description('Manage serverless functions')
|
|
42
52
|
.action(() => {
|
|
53
|
+
const globalOptions = program.opts();
|
|
54
|
+
if (globalOptions.cwd) {
|
|
55
|
+
process.chdir(globalOptions.cwd);
|
|
56
|
+
}
|
|
43
57
|
process.stdout.write('Serverless function management - coming soon\n');
|
|
44
58
|
});
|
|
45
59
|
|
|
@@ -47,6 +61,10 @@ program
|
|
|
47
61
|
.command('api')
|
|
48
62
|
.description('Manage REST API endpoints')
|
|
49
63
|
.action(() => {
|
|
64
|
+
const globalOptions = program.opts();
|
|
65
|
+
if (globalOptions.cwd) {
|
|
66
|
+
process.chdir(globalOptions.cwd);
|
|
67
|
+
}
|
|
50
68
|
process.stdout.write('REST API management - coming soon\n');
|
|
51
69
|
});
|
|
52
70
|
|
|
@@ -60,6 +78,10 @@ program
|
|
|
60
78
|
)
|
|
61
79
|
.action(async (options: { output?: string }) => {
|
|
62
80
|
try {
|
|
81
|
+
const globalOptions = program.opts();
|
|
82
|
+
if (globalOptions.cwd) {
|
|
83
|
+
process.chdir(globalOptions.cwd);
|
|
84
|
+
}
|
|
63
85
|
await openapiCommand(options);
|
|
64
86
|
} catch (error) {
|
|
65
87
|
console.error('OpenAPI generation failed:', (error as Error).message);
|
package/src/config.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { join } from 'path';
|
|
|
3
3
|
import type { GkmConfig } from './types.js';
|
|
4
4
|
|
|
5
5
|
export async function loadConfig(): Promise<GkmConfig> {
|
|
6
|
-
const configPath = join(process.cwd(), 'gkm.config.
|
|
6
|
+
const configPath = join(process.cwd(), 'gkm.config.json');
|
|
7
7
|
|
|
8
8
|
if (!existsSync(configPath)) {
|
|
9
9
|
throw new Error(
|
|
10
|
-
'gkm.config.
|
|
10
|
+
'gkm.config.json not found. Please create a configuration file.',
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|