@geekmidas/cli 0.0.8 → 0.0.9
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-HqXSd7ux.mjs → build-CE77jmn4.mjs} +17 -13
- package/dist/{build-BOIEItQ4.cjs → build-DGJAXiy_.cjs} +16 -12
- package/dist/build.cjs +4 -2
- package/dist/build.mjs +4 -2
- package/dist/{cli-8JB9d4XW.mjs → cli-CTfdNl5c.mjs} +2 -2
- package/dist/{cli-8aXEWjpV.cjs → cli-aXPCpkGS.cjs} +2 -2
- package/dist/cli.cjs +6 -4
- package/dist/cli.mjs +6 -4
- package/dist/config-D-b45V57.cjs +41 -0
- package/dist/config-Nd751N3o.mjs +35 -0
- package/dist/config.cjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/helpers/pathResolver.cjs +6 -0
- package/dist/helpers/pathResolver.mjs +4 -0
- package/dist/index.cjs +6 -4
- package/dist/index.mjs +6 -4
- package/dist/{openapi-DD-MfKrj.cjs → openapi-C84tyelp.cjs} +1 -1
- package/dist/{openapi-CVu3aUU8.mjs → openapi-UIMy3Lzi.mjs} +1 -1
- package/dist/openapi.cjs +2 -2
- package/dist/openapi.mjs +2 -2
- package/dist/pathResolver-B6y4yoWk.cjs +47 -0
- package/dist/pathResolver-DaMnbf26.mjs +29 -0
- package/dist/tsconfig-83amrDAp.cjs +94 -0
- package/dist/tsconfig-BtO228Cz.mjs +70 -0
- package/dist/tsconfig.cjs +6 -0
- package/dist/tsconfig.mjs +3 -0
- package/package.json +4 -3
- package/src/build.ts +46 -8
- package/src/cli.ts +3 -1
- package/src/config.ts +27 -5
- package/src/helpers/pathResolver.ts +46 -0
- package/src/tsconfig.ts +132 -0
- package/src/types.ts +1 -0
- package/dist/config-D8AyiwBU.cjs +0 -23
- package/dist/config-DV1Lwdkx.mjs +0 -17
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { loadConfig } from "./config-
|
|
1
|
+
import { loadConfig } from "./config-Nd751N3o.mjs";
|
|
2
2
|
import { loadEndpoints } from "./loadEndpoints-BL8q2rTO.mjs";
|
|
3
|
+
import { loadTsConfig } from "./tsconfig-BtO228Cz.mjs";
|
|
4
|
+
import { resolveModuleSpecifier } from "./pathResolver-DaMnbf26.mjs";
|
|
3
5
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
-
import {
|
|
6
|
+
import { join, relative } from "path";
|
|
5
7
|
|
|
6
8
|
//#region src/build.ts
|
|
7
9
|
const logger = console;
|
|
@@ -10,6 +12,8 @@ async function buildCommand(options) {
|
|
|
10
12
|
const config = await loadConfig();
|
|
11
13
|
logger.log(`Loading routes from: ${config.routes}`);
|
|
12
14
|
logger.log(`Using envParser: ${config.envParser}`);
|
|
15
|
+
const tsConfig = config.tsconfig ? loadTsConfig(config.tsconfig) : loadTsConfig();
|
|
16
|
+
if (tsConfig) logger.log(`Using TypeScript config from: ${tsConfig.configPath}`);
|
|
13
17
|
const [envParserPath, envParserName] = config.envParser.split("#");
|
|
14
18
|
const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
|
|
15
19
|
const [loggerPath, loggerName] = config.logger.split("#");
|
|
@@ -39,7 +43,7 @@ async function buildCommand(options) {
|
|
|
39
43
|
await mkdir(outputDir, { recursive: true });
|
|
40
44
|
logger.log(`\nGenerating handlers for provider: ${provider}`);
|
|
41
45
|
if (provider === "server") {
|
|
42
|
-
const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern);
|
|
46
|
+
const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig);
|
|
43
47
|
routes.push({
|
|
44
48
|
path: "*",
|
|
45
49
|
method: "ALL",
|
|
@@ -47,7 +51,7 @@ async function buildCommand(options) {
|
|
|
47
51
|
});
|
|
48
52
|
logger.log(`Generated server app with ${allEndpoints.length} endpoints`);
|
|
49
53
|
} else for (const { file, exportName, routeInfo } of allEndpoints) {
|
|
50
|
-
const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern);
|
|
54
|
+
const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern, tsConfig);
|
|
51
55
|
routes.push({
|
|
52
56
|
...routeInfo,
|
|
53
57
|
handler: relative(process.cwd(), handlerFile).replace(/\.ts$/, ".handler")
|
|
@@ -61,18 +65,18 @@ async function buildCommand(options) {
|
|
|
61
65
|
logger.log(`Routes manifest: ${relative(process.cwd(), manifestPath)}`);
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
|
-
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern) {
|
|
68
|
+
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig) {
|
|
65
69
|
const serverFileName = "app.ts";
|
|
66
70
|
const serverPath = join(outputDir, serverFileName);
|
|
67
71
|
const importsByFile = /* @__PURE__ */ new Map();
|
|
68
72
|
for (const { file, exportName } of endpoints) {
|
|
69
|
-
const
|
|
70
|
-
const importPath =
|
|
73
|
+
const absoluteFilePath = join(process.cwd(), file);
|
|
74
|
+
const importPath = resolveModuleSpecifier(serverPath, absoluteFilePath, tsConfig);
|
|
71
75
|
if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
|
|
72
76
|
importsByFile.get(importPath).push(exportName);
|
|
73
77
|
}
|
|
74
|
-
const relativeEnvParserPath =
|
|
75
|
-
const relativeLoggerPath =
|
|
78
|
+
const relativeEnvParserPath = resolveModuleSpecifier(serverPath, envParserPath, tsConfig);
|
|
79
|
+
const relativeLoggerPath = resolveModuleSpecifier(serverPath, loggerPath, tsConfig);
|
|
76
80
|
const imports = Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n");
|
|
77
81
|
const allExportNames = endpoints.map(({ exportName }) => exportName);
|
|
78
82
|
const content = `import { HonoEndpoint } from '@geekmidas/api/hono';
|
|
@@ -106,12 +110,12 @@ export default createApp;
|
|
|
106
110
|
await writeFile(serverPath, content);
|
|
107
111
|
return serverPath;
|
|
108
112
|
}
|
|
109
|
-
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
|
|
113
|
+
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern, tsConfig) {
|
|
110
114
|
const handlerFileName = `${exportName}.ts`;
|
|
111
115
|
const handlerPath = join(outputDir, handlerFileName);
|
|
112
|
-
const
|
|
113
|
-
const importPath =
|
|
114
|
-
const relativeEnvParserPath =
|
|
116
|
+
const absoluteSourcePath = join(process.cwd(), sourceFile);
|
|
117
|
+
const importPath = resolveModuleSpecifier(handlerPath, absoluteSourcePath, tsConfig);
|
|
118
|
+
const relativeEnvParserPath = resolveModuleSpecifier(handlerPath, envParserPath, tsConfig);
|
|
115
119
|
let content;
|
|
116
120
|
switch (provider) {
|
|
117
121
|
case "aws-apigatewayv1":
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_config = require('./config-
|
|
2
|
+
const require_config = require('./config-D-b45V57.cjs');
|
|
3
3
|
const require_loadEndpoints = require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
|
+
const require_tsconfig = require('./tsconfig-83amrDAp.cjs');
|
|
5
|
+
const require_pathResolver = require('./pathResolver-B6y4yoWk.cjs');
|
|
4
6
|
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
5
7
|
const path = require_chunk.__toESM(require("path"));
|
|
6
8
|
|
|
@@ -11,6 +13,8 @@ async function buildCommand(options) {
|
|
|
11
13
|
const config = await require_config.loadConfig();
|
|
12
14
|
logger.log(`Loading routes from: ${config.routes}`);
|
|
13
15
|
logger.log(`Using envParser: ${config.envParser}`);
|
|
16
|
+
const tsConfig = config.tsconfig ? require_tsconfig.loadTsConfig(config.tsconfig) : require_tsconfig.loadTsConfig();
|
|
17
|
+
if (tsConfig) logger.log(`Using TypeScript config from: ${tsConfig.configPath}`);
|
|
14
18
|
const [envParserPath, envParserName] = config.envParser.split("#");
|
|
15
19
|
const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
|
|
16
20
|
const [loggerPath, loggerName] = config.logger.split("#");
|
|
@@ -40,7 +44,7 @@ async function buildCommand(options) {
|
|
|
40
44
|
await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
|
|
41
45
|
logger.log(`\nGenerating handlers for provider: ${provider}`);
|
|
42
46
|
if (provider === "server") {
|
|
43
|
-
const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern);
|
|
47
|
+
const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig);
|
|
44
48
|
routes.push({
|
|
45
49
|
path: "*",
|
|
46
50
|
method: "ALL",
|
|
@@ -48,7 +52,7 @@ async function buildCommand(options) {
|
|
|
48
52
|
});
|
|
49
53
|
logger.log(`Generated server app with ${allEndpoints.length} endpoints`);
|
|
50
54
|
} else for (const { file, exportName, routeInfo } of allEndpoints) {
|
|
51
|
-
const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern);
|
|
55
|
+
const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern, tsConfig);
|
|
52
56
|
routes.push({
|
|
53
57
|
...routeInfo,
|
|
54
58
|
handler: (0, path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler")
|
|
@@ -62,18 +66,18 @@ async function buildCommand(options) {
|
|
|
62
66
|
logger.log(`Routes manifest: ${(0, path.relative)(process.cwd(), manifestPath)}`);
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
|
-
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern) {
|
|
69
|
+
async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig) {
|
|
66
70
|
const serverFileName = "app.ts";
|
|
67
71
|
const serverPath = (0, path.join)(outputDir, serverFileName);
|
|
68
72
|
const importsByFile = /* @__PURE__ */ new Map();
|
|
69
73
|
for (const { file, exportName } of endpoints) {
|
|
70
|
-
const
|
|
71
|
-
const importPath =
|
|
74
|
+
const absoluteFilePath = (0, path.join)(process.cwd(), file);
|
|
75
|
+
const importPath = require_pathResolver.resolveModuleSpecifier(serverPath, absoluteFilePath, tsConfig);
|
|
72
76
|
if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
|
|
73
77
|
importsByFile.get(importPath).push(exportName);
|
|
74
78
|
}
|
|
75
|
-
const relativeEnvParserPath =
|
|
76
|
-
const relativeLoggerPath =
|
|
79
|
+
const relativeEnvParserPath = require_pathResolver.resolveModuleSpecifier(serverPath, envParserPath, tsConfig);
|
|
80
|
+
const relativeLoggerPath = require_pathResolver.resolveModuleSpecifier(serverPath, loggerPath, tsConfig);
|
|
77
81
|
const imports = Array.from(importsByFile.entries()).map(([importPath, exports$1]) => `import { ${exports$1.join(", ")} } from '${importPath}';`).join("\n");
|
|
78
82
|
const allExportNames = endpoints.map(({ exportName }) => exportName);
|
|
79
83
|
const content = `import { HonoEndpoint } from '@geekmidas/api/hono';
|
|
@@ -107,12 +111,12 @@ export default createApp;
|
|
|
107
111
|
await (0, node_fs_promises.writeFile)(serverPath, content);
|
|
108
112
|
return serverPath;
|
|
109
113
|
}
|
|
110
|
-
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
|
|
114
|
+
async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern, tsConfig) {
|
|
111
115
|
const handlerFileName = `${exportName}.ts`;
|
|
112
116
|
const handlerPath = (0, path.join)(outputDir, handlerFileName);
|
|
113
|
-
const
|
|
114
|
-
const importPath =
|
|
115
|
-
const relativeEnvParserPath =
|
|
117
|
+
const absoluteSourcePath = (0, path.join)(process.cwd(), sourceFile);
|
|
118
|
+
const importPath = require_pathResolver.resolveModuleSpecifier(handlerPath, absoluteSourcePath, tsConfig);
|
|
119
|
+
const relativeEnvParserPath = require_pathResolver.resolveModuleSpecifier(handlerPath, envParserPath, tsConfig);
|
|
116
120
|
let content;
|
|
117
121
|
switch (provider) {
|
|
118
122
|
case "aws-apigatewayv1":
|
package/dist/build.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
require('./config-
|
|
1
|
+
require('./config-D-b45V57.cjs');
|
|
2
2
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
3
|
-
|
|
3
|
+
require('./tsconfig-83amrDAp.cjs');
|
|
4
|
+
require('./pathResolver-B6y4yoWk.cjs');
|
|
5
|
+
const require_build = require('./build-DGJAXiy_.cjs');
|
|
4
6
|
|
|
5
7
|
exports.buildCommand = require_build.buildCommand;
|
package/dist/build.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import "./config-
|
|
1
|
+
import "./config-Nd751N3o.mjs";
|
|
2
2
|
import "./loadEndpoints-BL8q2rTO.mjs";
|
|
3
|
-
import
|
|
3
|
+
import "./tsconfig-BtO228Cz.mjs";
|
|
4
|
+
import "./pathResolver-DaMnbf26.mjs";
|
|
5
|
+
import { buildCommand } from "./build-CE77jmn4.mjs";
|
|
4
6
|
|
|
5
7
|
export { buildCommand };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { buildCommand } from "./build-
|
|
2
|
-
import { openapiCommand } from "./openapi-
|
|
1
|
+
import { buildCommand } from "./build-CE77jmn4.mjs";
|
|
2
|
+
import { openapiCommand } from "./openapi-UIMy3Lzi.mjs";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
|
|
5
5
|
//#region src/cli.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
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-DGJAXiy_.cjs');
|
|
3
|
+
const require_openapi = require('./openapi-C84tyelp.cjs');
|
|
4
4
|
const commander = require_chunk.__toESM(require("commander"));
|
|
5
5
|
|
|
6
6
|
//#region src/cli.ts
|
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
require('./config-
|
|
2
|
+
require('./config-D-b45V57.cjs');
|
|
3
3
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
|
-
require('./
|
|
5
|
-
require('./
|
|
6
|
-
require('./
|
|
4
|
+
require('./tsconfig-83amrDAp.cjs');
|
|
5
|
+
require('./pathResolver-B6y4yoWk.cjs');
|
|
6
|
+
require('./build-DGJAXiy_.cjs');
|
|
7
|
+
require('./openapi-C84tyelp.cjs');
|
|
8
|
+
require('./cli-aXPCpkGS.cjs');
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import "./config-
|
|
2
|
+
import "./config-Nd751N3o.mjs";
|
|
3
3
|
import "./loadEndpoints-BL8q2rTO.mjs";
|
|
4
|
-
import "./
|
|
5
|
-
import "./
|
|
6
|
-
import "./
|
|
4
|
+
import "./tsconfig-BtO228Cz.mjs";
|
|
5
|
+
import "./pathResolver-DaMnbf26.mjs";
|
|
6
|
+
import "./build-CE77jmn4.mjs";
|
|
7
|
+
import "./openapi-UIMy3Lzi.mjs";
|
|
8
|
+
import "./cli-CTfdNl5c.mjs";
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
|
|
5
|
+
//#region src/config.ts
|
|
6
|
+
async function loadConfig() {
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const configExtensions = [
|
|
9
|
+
".ts",
|
|
10
|
+
".js",
|
|
11
|
+
".json"
|
|
12
|
+
];
|
|
13
|
+
let configPath = null;
|
|
14
|
+
for (const ext of configExtensions) {
|
|
15
|
+
const path$1 = (0, path.join)(cwd, `gkm.config${ext}`);
|
|
16
|
+
if ((0, fs.existsSync)(path$1)) {
|
|
17
|
+
configPath = path$1;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!configPath) throw new Error("gkm.config.{ts,js,json} not found. Please create a configuration file.");
|
|
22
|
+
try {
|
|
23
|
+
const ext = (0, path.extname)(configPath);
|
|
24
|
+
if (ext === ".ts") {
|
|
25
|
+
const config$1 = await import(configPath);
|
|
26
|
+
return config$1.default || config$1;
|
|
27
|
+
}
|
|
28
|
+
const config = await import(configPath);
|
|
29
|
+
return config.default || config;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new Error(`Failed to load ${configPath}: ${error.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
Object.defineProperty(exports, 'loadConfig', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return loadConfig;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { extname, join } from "path";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
|
|
4
|
+
//#region src/config.ts
|
|
5
|
+
async function loadConfig() {
|
|
6
|
+
const cwd = process.cwd();
|
|
7
|
+
const configExtensions = [
|
|
8
|
+
".ts",
|
|
9
|
+
".js",
|
|
10
|
+
".json"
|
|
11
|
+
];
|
|
12
|
+
let configPath = null;
|
|
13
|
+
for (const ext of configExtensions) {
|
|
14
|
+
const path = join(cwd, `gkm.config${ext}`);
|
|
15
|
+
if (existsSync(path)) {
|
|
16
|
+
configPath = path;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!configPath) throw new Error("gkm.config.{ts,js,json} not found. Please create a configuration file.");
|
|
21
|
+
try {
|
|
22
|
+
const ext = extname(configPath);
|
|
23
|
+
if (ext === ".ts") {
|
|
24
|
+
const config$1 = await import(configPath);
|
|
25
|
+
return config$1.default || config$1;
|
|
26
|
+
}
|
|
27
|
+
const config = await import(configPath);
|
|
28
|
+
return config.default || config;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(`Failed to load ${configPath}: ${error.message}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { loadConfig };
|
package/dist/config.cjs
CHANGED
package/dist/config.mjs
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
require('../tsconfig-83amrDAp.cjs');
|
|
2
|
+
const require_pathResolver = require('../pathResolver-B6y4yoWk.cjs');
|
|
3
|
+
|
|
4
|
+
exports.convertToJsExtension = require_pathResolver.convertToJsExtension;
|
|
5
|
+
exports.resolveImportPath = require_pathResolver.resolveImportPath;
|
|
6
|
+
exports.resolveModuleSpecifier = require_pathResolver.resolveModuleSpecifier;
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
require('./config-
|
|
2
|
+
require('./config-D-b45V57.cjs');
|
|
3
3
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
|
-
require('./
|
|
5
|
-
require('./
|
|
6
|
-
require('./
|
|
4
|
+
require('./tsconfig-83amrDAp.cjs');
|
|
5
|
+
require('./pathResolver-B6y4yoWk.cjs');
|
|
6
|
+
require('./build-DGJAXiy_.cjs');
|
|
7
|
+
require('./openapi-C84tyelp.cjs');
|
|
8
|
+
require('./cli-aXPCpkGS.cjs');
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
import "./config-
|
|
2
|
+
import "./config-Nd751N3o.mjs";
|
|
3
3
|
import "./loadEndpoints-BL8q2rTO.mjs";
|
|
4
|
-
import "./
|
|
5
|
-
import "./
|
|
6
|
-
import "./
|
|
4
|
+
import "./tsconfig-BtO228Cz.mjs";
|
|
5
|
+
import "./pathResolver-DaMnbf26.mjs";
|
|
6
|
+
import "./build-CE77jmn4.mjs";
|
|
7
|
+
import "./openapi-UIMy3Lzi.mjs";
|
|
8
|
+
import "./cli-CTfdNl5c.mjs";
|
|
@@ -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-D-b45V57.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"));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadConfig } from "./config-
|
|
1
|
+
import { loadConfig } from "./config-Nd751N3o.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";
|
package/dist/openapi.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
require('./config-
|
|
2
|
+
require('./config-D-b45V57.cjs');
|
|
3
3
|
require('./loadEndpoints-CYFwuPZr.cjs');
|
|
4
|
-
const require_openapi = require('./openapi-
|
|
4
|
+
const require_openapi = require('./openapi-C84tyelp.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-Nd751N3o.mjs";
|
|
3
3
|
import "./loadEndpoints-BL8q2rTO.mjs";
|
|
4
|
-
import { openapiCommand } from "./openapi-
|
|
4
|
+
import { openapiCommand } from "./openapi-UIMy3Lzi.mjs";
|
|
5
5
|
|
|
6
6
|
export { openapiCommand };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_tsconfig = require('./tsconfig-83amrDAp.cjs');
|
|
3
|
+
const path = require_chunk.__toESM(require("path"));
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/pathResolver.ts
|
|
6
|
+
/**
|
|
7
|
+
* Resolve import paths considering TypeScript path mappings
|
|
8
|
+
*/
|
|
9
|
+
function resolveImportPath(fromFile, toFile, tsConfig) {
|
|
10
|
+
const resolvedToFile = tsConfig ? require_tsconfig.resolvePathMapping(toFile, tsConfig) : toFile;
|
|
11
|
+
const relativePath = (0, path.relative)((0, path.dirname)(fromFile), resolvedToFile);
|
|
12
|
+
if (!relativePath.startsWith(".")) return `./${relativePath}`;
|
|
13
|
+
return relativePath;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert TypeScript file extensions to JavaScript
|
|
17
|
+
*/
|
|
18
|
+
function convertToJsExtension(filePath) {
|
|
19
|
+
return filePath.replace(/\.ts$/, ".js");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolve module specifier for imports
|
|
23
|
+
*/
|
|
24
|
+
function resolveModuleSpecifier(fromFile, toFile, tsConfig) {
|
|
25
|
+
const importPath = resolveImportPath(fromFile, toFile, tsConfig);
|
|
26
|
+
return convertToJsExtension(importPath);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
Object.defineProperty(exports, 'convertToJsExtension', {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return convertToJsExtension;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, 'resolveImportPath', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return resolveImportPath;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, 'resolveModuleSpecifier', {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return resolveModuleSpecifier;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { resolvePathMapping } from "./tsconfig-BtO228Cz.mjs";
|
|
2
|
+
import { dirname, relative } from "path";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/pathResolver.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolve import paths considering TypeScript path mappings
|
|
7
|
+
*/
|
|
8
|
+
function resolveImportPath(fromFile, toFile, tsConfig) {
|
|
9
|
+
const resolvedToFile = tsConfig ? resolvePathMapping(toFile, tsConfig) : toFile;
|
|
10
|
+
const relativePath = relative(dirname(fromFile), resolvedToFile);
|
|
11
|
+
if (!relativePath.startsWith(".")) return `./${relativePath}`;
|
|
12
|
+
return relativePath;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Convert TypeScript file extensions to JavaScript
|
|
16
|
+
*/
|
|
17
|
+
function convertToJsExtension(filePath) {
|
|
18
|
+
return filePath.replace(/\.ts$/, ".js");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve module specifier for imports
|
|
22
|
+
*/
|
|
23
|
+
function resolveModuleSpecifier(fromFile, toFile, tsConfig) {
|
|
24
|
+
const importPath = resolveImportPath(fromFile, toFile, tsConfig);
|
|
25
|
+
return convertToJsExtension(importPath);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { convertToJsExtension, resolveImportPath, resolveModuleSpecifier };
|
|
@@ -0,0 +1,94 @@
|
|
|
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 typescript = require_chunk.__toESM(require("typescript"));
|
|
5
|
+
|
|
6
|
+
//#region src/tsconfig.ts
|
|
7
|
+
/**
|
|
8
|
+
* Find and parse the nearest tsconfig.json file
|
|
9
|
+
*/
|
|
10
|
+
function loadTsConfig(searchPath = process.cwd()) {
|
|
11
|
+
const configPath = typescript.default.findConfigFile(searchPath, fs.existsSync);
|
|
12
|
+
if (!configPath) return null;
|
|
13
|
+
const configFile = typescript.default.readConfigFile(configPath, typescript.default.sys.readFile);
|
|
14
|
+
if (configFile.error) throw new Error(`Error reading tsconfig.json: ${typescript.default.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`);
|
|
15
|
+
const parsedConfig = typescript.default.parseJsonConfigFileContent(configFile.config, typescript.default.sys, (0, path.dirname)(configPath));
|
|
16
|
+
if (parsedConfig.errors.length > 0) {
|
|
17
|
+
const errors = parsedConfig.errors.map((error) => typescript.default.flattenDiagnosticMessageText(error.messageText, "\n")).join("\n");
|
|
18
|
+
throw new Error(`Error parsing tsconfig.json: ${errors}`);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
configPath,
|
|
22
|
+
config: parsedConfig,
|
|
23
|
+
compilerOptions: parsedConfig.options
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a module path using TypeScript's module resolution
|
|
28
|
+
*/
|
|
29
|
+
function resolveModulePath(moduleName, containingFile, tsConfig) {
|
|
30
|
+
const compilerOptions = tsConfig?.compilerOptions || {};
|
|
31
|
+
const result = typescript.default.resolveModuleName(moduleName, containingFile, compilerOptions, typescript.default.sys);
|
|
32
|
+
if (result.resolvedModule) return result.resolvedModule.resolvedFileName;
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the output path for a TypeScript file based on tsconfig
|
|
37
|
+
*/
|
|
38
|
+
function getOutputPath(filePath, tsConfig) {
|
|
39
|
+
if (!tsConfig) return filePath.replace(/\.ts$/, ".js");
|
|
40
|
+
const { compilerOptions, configPath } = tsConfig;
|
|
41
|
+
const configDir = (0, path.dirname)(configPath);
|
|
42
|
+
if (compilerOptions.outDir) {
|
|
43
|
+
const rootDir = compilerOptions.rootDir || configDir;
|
|
44
|
+
const relativePath = filePath.startsWith(rootDir) ? filePath.slice(rootDir.length) : filePath;
|
|
45
|
+
const outputPath = (0, path.join)(compilerOptions.outDir, relativePath);
|
|
46
|
+
return outputPath.replace(/\.ts$/, ".js");
|
|
47
|
+
}
|
|
48
|
+
return filePath.replace(/\.ts$/, ".js");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Apply path mappings from tsconfig paths
|
|
52
|
+
*/
|
|
53
|
+
function resolvePathMapping(importPath, tsConfig) {
|
|
54
|
+
if (!tsConfig || !tsConfig.compilerOptions.paths) return importPath;
|
|
55
|
+
const { paths, baseUrl } = tsConfig.compilerOptions;
|
|
56
|
+
const configDir = (0, path.dirname)(tsConfig.configPath);
|
|
57
|
+
const resolvedBaseUrl = baseUrl ? (0, path.resolve)(configDir, baseUrl) : configDir;
|
|
58
|
+
for (const [pattern, replacements] of Object.entries(paths)) {
|
|
59
|
+
const regex = new RegExp("^" + pattern.replace("*", "(.*)") + "$");
|
|
60
|
+
const match = importPath.match(regex);
|
|
61
|
+
if (match && replacements.length > 0) {
|
|
62
|
+
const replacement = replacements[0];
|
|
63
|
+
const resolvedPath = replacement.replace("*", match[1] || "");
|
|
64
|
+
return (0, path.resolve)(resolvedBaseUrl, resolvedPath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return importPath;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
Object.defineProperty(exports, 'getOutputPath', {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () {
|
|
74
|
+
return getOutputPath;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(exports, 'loadTsConfig', {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return loadTsConfig;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, 'resolveModulePath', {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () {
|
|
86
|
+
return resolveModulePath;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, 'resolvePathMapping', {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () {
|
|
92
|
+
return resolvePathMapping;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { dirname, join, resolve } from "path";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
//#region src/tsconfig.ts
|
|
6
|
+
/**
|
|
7
|
+
* Find and parse the nearest tsconfig.json file
|
|
8
|
+
*/
|
|
9
|
+
function loadTsConfig(searchPath = process.cwd()) {
|
|
10
|
+
const configPath = ts.findConfigFile(searchPath, existsSync);
|
|
11
|
+
if (!configPath) return null;
|
|
12
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
13
|
+
if (configFile.error) throw new Error(`Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`);
|
|
14
|
+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, dirname(configPath));
|
|
15
|
+
if (parsedConfig.errors.length > 0) {
|
|
16
|
+
const errors = parsedConfig.errors.map((error) => ts.flattenDiagnosticMessageText(error.messageText, "\n")).join("\n");
|
|
17
|
+
throw new Error(`Error parsing tsconfig.json: ${errors}`);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
configPath,
|
|
21
|
+
config: parsedConfig,
|
|
22
|
+
compilerOptions: parsedConfig.options
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a module path using TypeScript's module resolution
|
|
27
|
+
*/
|
|
28
|
+
function resolveModulePath(moduleName, containingFile, tsConfig) {
|
|
29
|
+
const compilerOptions = tsConfig?.compilerOptions || {};
|
|
30
|
+
const result = ts.resolveModuleName(moduleName, containingFile, compilerOptions, ts.sys);
|
|
31
|
+
if (result.resolvedModule) return result.resolvedModule.resolvedFileName;
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the output path for a TypeScript file based on tsconfig
|
|
36
|
+
*/
|
|
37
|
+
function getOutputPath(filePath, tsConfig) {
|
|
38
|
+
if (!tsConfig) return filePath.replace(/\.ts$/, ".js");
|
|
39
|
+
const { compilerOptions, configPath } = tsConfig;
|
|
40
|
+
const configDir = dirname(configPath);
|
|
41
|
+
if (compilerOptions.outDir) {
|
|
42
|
+
const rootDir = compilerOptions.rootDir || configDir;
|
|
43
|
+
const relativePath = filePath.startsWith(rootDir) ? filePath.slice(rootDir.length) : filePath;
|
|
44
|
+
const outputPath = join(compilerOptions.outDir, relativePath);
|
|
45
|
+
return outputPath.replace(/\.ts$/, ".js");
|
|
46
|
+
}
|
|
47
|
+
return filePath.replace(/\.ts$/, ".js");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Apply path mappings from tsconfig paths
|
|
51
|
+
*/
|
|
52
|
+
function resolvePathMapping(importPath, tsConfig) {
|
|
53
|
+
if (!tsConfig || !tsConfig.compilerOptions.paths) return importPath;
|
|
54
|
+
const { paths, baseUrl } = tsConfig.compilerOptions;
|
|
55
|
+
const configDir = dirname(tsConfig.configPath);
|
|
56
|
+
const resolvedBaseUrl = baseUrl ? resolve(configDir, baseUrl) : configDir;
|
|
57
|
+
for (const [pattern, replacements] of Object.entries(paths)) {
|
|
58
|
+
const regex = new RegExp("^" + pattern.replace("*", "(.*)") + "$");
|
|
59
|
+
const match = importPath.match(regex);
|
|
60
|
+
if (match && replacements.length > 0) {
|
|
61
|
+
const replacement = replacements[0];
|
|
62
|
+
const resolvedPath = replacement.replace("*", match[1] || "");
|
|
63
|
+
return resolve(resolvedBaseUrl, resolvedPath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return importPath;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { getOutputPath, loadTsConfig, resolveModulePath, resolvePathMapping };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const require_tsconfig = require('./tsconfig-83amrDAp.cjs');
|
|
2
|
+
|
|
3
|
+
exports.getOutputPath = require_tsconfig.getOutputPath;
|
|
4
|
+
exports.loadTsConfig = require_tsconfig.loadTsConfig;
|
|
5
|
+
exports.resolveModulePath = require_tsconfig.resolveModulePath;
|
|
6
|
+
exports.resolvePathMapping = require_tsconfig.resolvePathMapping;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"commander": "~14.0.0",
|
|
22
|
+
"fast-glob": "~3.3.3",
|
|
22
23
|
"lodash.get": "~4.4.2",
|
|
23
24
|
"lodash.set": "~4.3.2",
|
|
25
|
+
"typescript": "~5.8.3",
|
|
24
26
|
"zod": "~3.25.67",
|
|
25
|
-
"
|
|
26
|
-
"@geekmidas/api": "0.0.18"
|
|
27
|
+
"@geekmidas/api": "0.0.22"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/lodash.get": "~4.4.9",
|
package/src/build.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { mkdir, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import { dirname, join, relative } from 'path';
|
|
3
3
|
import { loadConfig } from './config.js';
|
|
4
4
|
import { loadEndpoints } from './loadEndpoints.js';
|
|
5
|
+
import { loadTsConfig, getOutputPath } from './tsconfig.js';
|
|
6
|
+
import { resolveModuleSpecifier } from './helpers/pathResolver.js';
|
|
5
7
|
import type {
|
|
6
8
|
BuildOptions,
|
|
7
9
|
Provider,
|
|
@@ -17,6 +19,14 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
|
|
|
17
19
|
logger.log(`Loading routes from: ${config.routes}`);
|
|
18
20
|
logger.log(`Using envParser: ${config.envParser}`);
|
|
19
21
|
|
|
22
|
+
// Load tsconfig if available
|
|
23
|
+
const tsConfig = config.tsconfig
|
|
24
|
+
? loadTsConfig(config.tsconfig)
|
|
25
|
+
: loadTsConfig();
|
|
26
|
+
if (tsConfig) {
|
|
27
|
+
logger.log(`Using TypeScript config from: ${tsConfig.configPath}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
// Parse envParser configuration
|
|
21
31
|
const [envParserPath, envParserName] = config.envParser.split('#');
|
|
22
32
|
const envParserImportPattern = !envParserName
|
|
@@ -80,6 +90,7 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
|
|
|
80
90
|
envParserImportPattern,
|
|
81
91
|
loggerPath,
|
|
82
92
|
loggerImportPattern,
|
|
93
|
+
tsConfig,
|
|
83
94
|
);
|
|
84
95
|
|
|
85
96
|
routes.push({
|
|
@@ -100,6 +111,7 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
|
|
|
100
111
|
routeInfo,
|
|
101
112
|
envParserPath,
|
|
102
113
|
envParserImportPattern,
|
|
114
|
+
tsConfig,
|
|
103
115
|
);
|
|
104
116
|
|
|
105
117
|
routes.push({
|
|
@@ -110,7 +122,9 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
|
|
|
110
122
|
),
|
|
111
123
|
});
|
|
112
124
|
|
|
113
|
-
logger.log(
|
|
125
|
+
logger.log(
|
|
126
|
+
`Generated handler for ${routeInfo.method} ${routeInfo.path}`,
|
|
127
|
+
);
|
|
114
128
|
}
|
|
115
129
|
}
|
|
116
130
|
|
|
@@ -138,6 +152,7 @@ async function generateServerFile(
|
|
|
138
152
|
envParserImportPattern: string,
|
|
139
153
|
loggerPath: string,
|
|
140
154
|
loggerImportPattern: string,
|
|
155
|
+
tsConfig: ReturnType<typeof loadTsConfig>,
|
|
141
156
|
): Promise<string> {
|
|
142
157
|
const serverFileName = 'app.ts';
|
|
143
158
|
const serverPath = join(outputDir, serverFileName);
|
|
@@ -146,8 +161,13 @@ async function generateServerFile(
|
|
|
146
161
|
const importsByFile = new Map<string, string[]>();
|
|
147
162
|
|
|
148
163
|
for (const { file, exportName } of endpoints) {
|
|
149
|
-
const
|
|
150
|
-
|
|
164
|
+
const absoluteFilePath = join(process.cwd(), file);
|
|
165
|
+
// Use path resolver to handle tsconfig paths
|
|
166
|
+
const importPath = resolveModuleSpecifier(
|
|
167
|
+
serverPath,
|
|
168
|
+
absoluteFilePath,
|
|
169
|
+
tsConfig,
|
|
170
|
+
);
|
|
151
171
|
|
|
152
172
|
if (!importsByFile.has(importPath)) {
|
|
153
173
|
importsByFile.set(importPath, []);
|
|
@@ -155,8 +175,16 @@ async function generateServerFile(
|
|
|
155
175
|
importsByFile.get(importPath)!.push(exportName);
|
|
156
176
|
}
|
|
157
177
|
|
|
158
|
-
const relativeEnvParserPath =
|
|
159
|
-
|
|
178
|
+
const relativeEnvParserPath = resolveModuleSpecifier(
|
|
179
|
+
serverPath,
|
|
180
|
+
envParserPath,
|
|
181
|
+
tsConfig,
|
|
182
|
+
);
|
|
183
|
+
const relativeLoggerPath = resolveModuleSpecifier(
|
|
184
|
+
serverPath,
|
|
185
|
+
loggerPath,
|
|
186
|
+
tsConfig,
|
|
187
|
+
);
|
|
160
188
|
|
|
161
189
|
// Generate import statements
|
|
162
190
|
const imports = Array.from(importsByFile.entries())
|
|
@@ -209,14 +237,24 @@ async function generateHandlerFile(
|
|
|
209
237
|
_routeInfo: RouteInfo,
|
|
210
238
|
envParserPath: string,
|
|
211
239
|
envParserImportPattern: string,
|
|
240
|
+
tsConfig: ReturnType<typeof loadTsConfig>,
|
|
212
241
|
): Promise<string> {
|
|
213
242
|
const handlerFileName = `${exportName}.ts`;
|
|
214
243
|
const handlerPath = join(outputDir, handlerFileName);
|
|
215
244
|
|
|
216
|
-
const
|
|
217
|
-
|
|
245
|
+
const absoluteSourcePath = join(process.cwd(), sourceFile);
|
|
246
|
+
// Use path resolver to handle tsconfig paths
|
|
247
|
+
const importPath = resolveModuleSpecifier(
|
|
248
|
+
handlerPath,
|
|
249
|
+
absoluteSourcePath,
|
|
250
|
+
tsConfig,
|
|
251
|
+
);
|
|
218
252
|
|
|
219
|
-
const relativeEnvParserPath =
|
|
253
|
+
const relativeEnvParserPath = resolveModuleSpecifier(
|
|
254
|
+
handlerPath,
|
|
255
|
+
envParserPath,
|
|
256
|
+
tsConfig,
|
|
257
|
+
);
|
|
220
258
|
|
|
221
259
|
let content: string;
|
|
222
260
|
|
package/src/cli.ts
CHANGED
|
@@ -27,7 +27,9 @@ program
|
|
|
27
27
|
if (globalOptions.cwd) {
|
|
28
28
|
process.chdir(globalOptions.cwd);
|
|
29
29
|
}
|
|
30
|
-
const providerList = [
|
|
30
|
+
const providerList = [
|
|
31
|
+
...new Set(options.providers.split(',').map((p) => p.trim())),
|
|
32
|
+
] as Provider[];
|
|
31
33
|
await buildCommand({ providers: providerList });
|
|
32
34
|
} catch (error) {
|
|
33
35
|
console.error('Build failed:', (error as Error).message);
|
package/src/config.ts
CHANGED
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
import { existsSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
2
|
+
import { join, extname } from 'path';
|
|
3
3
|
import type { GkmConfig } from './types.js';
|
|
4
4
|
|
|
5
5
|
export async function loadConfig(): Promise<GkmConfig> {
|
|
6
|
-
const
|
|
6
|
+
const cwd = process.cwd();
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// Try to find config file with different extensions
|
|
9
|
+
const configExtensions = ['.ts', '.js', '.json'];
|
|
10
|
+
let configPath: string | null = null;
|
|
11
|
+
|
|
12
|
+
for (const ext of configExtensions) {
|
|
13
|
+
const path = join(cwd, `gkm.config${ext}`);
|
|
14
|
+
if (existsSync(path)) {
|
|
15
|
+
configPath = path;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!configPath) {
|
|
9
21
|
throw new Error(
|
|
10
|
-
'gkm.config.json not found. Please create a configuration file.',
|
|
22
|
+
'gkm.config.{ts,js,json} not found. Please create a configuration file.',
|
|
11
23
|
);
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
try {
|
|
27
|
+
const ext = extname(configPath);
|
|
28
|
+
|
|
29
|
+
// For TypeScript files, ensure tsx can handle them
|
|
30
|
+
if (ext === '.ts') {
|
|
31
|
+
// tsx handles TypeScript files automatically
|
|
32
|
+
const config = await import(configPath);
|
|
33
|
+
return config.default || config;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// For JS and JSON files
|
|
15
37
|
const config = await import(configPath);
|
|
16
38
|
return config.default || config;
|
|
17
39
|
} catch (error) {
|
|
18
40
|
throw new Error(
|
|
19
|
-
`Failed to load
|
|
41
|
+
`Failed to load ${configPath}: ${(error as Error).message}`,
|
|
20
42
|
);
|
|
21
43
|
}
|
|
22
44
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { relative, dirname } from 'path';
|
|
2
|
+
import type { TsConfigResult } from '../tsconfig.js';
|
|
3
|
+
import { resolvePathMapping } from '../tsconfig.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolve import paths considering TypeScript path mappings
|
|
7
|
+
*/
|
|
8
|
+
export function resolveImportPath(
|
|
9
|
+
fromFile: string,
|
|
10
|
+
toFile: string,
|
|
11
|
+
tsConfig?: TsConfigResult | null,
|
|
12
|
+
): string {
|
|
13
|
+
// Apply path mappings if tsconfig is available
|
|
14
|
+
const resolvedToFile = tsConfig
|
|
15
|
+
? resolvePathMapping(toFile, tsConfig)
|
|
16
|
+
: toFile;
|
|
17
|
+
|
|
18
|
+
// Calculate relative path
|
|
19
|
+
const relativePath = relative(dirname(fromFile), resolvedToFile);
|
|
20
|
+
|
|
21
|
+
// Ensure proper relative path format
|
|
22
|
+
if (!relativePath.startsWith('.')) {
|
|
23
|
+
return `./${relativePath}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return relativePath;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Convert TypeScript file extensions to JavaScript
|
|
31
|
+
*/
|
|
32
|
+
export function convertToJsExtension(filePath: string): string {
|
|
33
|
+
return filePath.replace(/\.ts$/, '.js');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Resolve module specifier for imports
|
|
38
|
+
*/
|
|
39
|
+
export function resolveModuleSpecifier(
|
|
40
|
+
fromFile: string,
|
|
41
|
+
toFile: string,
|
|
42
|
+
tsConfig?: TsConfigResult | null,
|
|
43
|
+
): string {
|
|
44
|
+
const importPath = resolveImportPath(fromFile, toFile, tsConfig);
|
|
45
|
+
return convertToJsExtension(importPath);
|
|
46
|
+
}
|
package/src/tsconfig.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { join, dirname, resolve } from 'path';
|
|
4
|
+
|
|
5
|
+
export interface TsConfigResult {
|
|
6
|
+
configPath: string;
|
|
7
|
+
config: ts.ParsedCommandLine;
|
|
8
|
+
compilerOptions: ts.CompilerOptions;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Find and parse the nearest tsconfig.json file
|
|
13
|
+
*/
|
|
14
|
+
export function loadTsConfig(
|
|
15
|
+
searchPath: string = process.cwd(),
|
|
16
|
+
): TsConfigResult | null {
|
|
17
|
+
const configPath = ts.findConfigFile(searchPath, existsSync);
|
|
18
|
+
|
|
19
|
+
if (!configPath) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
24
|
+
|
|
25
|
+
if (configFile.error) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, '\n')}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const parsedConfig = ts.parseJsonConfigFileContent(
|
|
32
|
+
configFile.config,
|
|
33
|
+
ts.sys,
|
|
34
|
+
dirname(configPath),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (parsedConfig.errors.length > 0) {
|
|
38
|
+
const errors = parsedConfig.errors
|
|
39
|
+
.map((error) => ts.flattenDiagnosticMessageText(error.messageText, '\n'))
|
|
40
|
+
.join('\n');
|
|
41
|
+
throw new Error(`Error parsing tsconfig.json: ${errors}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
configPath,
|
|
46
|
+
config: parsedConfig,
|
|
47
|
+
compilerOptions: parsedConfig.options,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve a module path using TypeScript's module resolution
|
|
53
|
+
*/
|
|
54
|
+
export function resolveModulePath(
|
|
55
|
+
moduleName: string,
|
|
56
|
+
containingFile: string,
|
|
57
|
+
tsConfig?: TsConfigResult,
|
|
58
|
+
): string | null {
|
|
59
|
+
const compilerOptions = tsConfig?.compilerOptions || {};
|
|
60
|
+
|
|
61
|
+
const result = ts.resolveModuleName(
|
|
62
|
+
moduleName,
|
|
63
|
+
containingFile,
|
|
64
|
+
compilerOptions,
|
|
65
|
+
ts.sys,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (result.resolvedModule) {
|
|
69
|
+
return result.resolvedModule.resolvedFileName;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get the output path for a TypeScript file based on tsconfig
|
|
77
|
+
*/
|
|
78
|
+
export function getOutputPath(
|
|
79
|
+
filePath: string,
|
|
80
|
+
tsConfig?: TsConfigResult,
|
|
81
|
+
): string {
|
|
82
|
+
if (!tsConfig) {
|
|
83
|
+
// Default: replace .ts with .js
|
|
84
|
+
return filePath.replace(/\.ts$/, '.js');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const { compilerOptions, configPath } = tsConfig;
|
|
88
|
+
const configDir = dirname(configPath);
|
|
89
|
+
|
|
90
|
+
// Handle outDir option
|
|
91
|
+
if (compilerOptions.outDir) {
|
|
92
|
+
const rootDir = compilerOptions.rootDir || configDir;
|
|
93
|
+
const relativePath = filePath.startsWith(rootDir)
|
|
94
|
+
? filePath.slice(rootDir.length)
|
|
95
|
+
: filePath;
|
|
96
|
+
|
|
97
|
+
const outputPath = join(compilerOptions.outDir, relativePath);
|
|
98
|
+
return outputPath.replace(/\.ts$/, '.js');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Default: in-place compilation
|
|
102
|
+
return filePath.replace(/\.ts$/, '.js');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Apply path mappings from tsconfig paths
|
|
107
|
+
*/
|
|
108
|
+
export function resolvePathMapping(
|
|
109
|
+
importPath: string,
|
|
110
|
+
tsConfig?: TsConfigResult,
|
|
111
|
+
): string {
|
|
112
|
+
if (!tsConfig || !tsConfig.compilerOptions.paths) {
|
|
113
|
+
return importPath;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const { paths, baseUrl } = tsConfig.compilerOptions;
|
|
117
|
+
const configDir = dirname(tsConfig.configPath);
|
|
118
|
+
const resolvedBaseUrl = baseUrl ? resolve(configDir, baseUrl) : configDir;
|
|
119
|
+
|
|
120
|
+
for (const [pattern, replacements] of Object.entries(paths)) {
|
|
121
|
+
const regex = new RegExp('^' + pattern.replace('*', '(.*)') + '$');
|
|
122
|
+
const match = importPath.match(regex);
|
|
123
|
+
|
|
124
|
+
if (match && replacements.length > 0) {
|
|
125
|
+
const replacement = replacements[0];
|
|
126
|
+
const resolvedPath = replacement.replace('*', match[1] || '');
|
|
127
|
+
return resolve(resolvedBaseUrl, resolvedPath);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return importPath;
|
|
132
|
+
}
|
package/src/types.ts
CHANGED
package/dist/config-D8AyiwBU.cjs
DELETED
|
@@ -1,23 +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
|
-
|
|
5
|
-
//#region src/config.ts
|
|
6
|
-
async function loadConfig() {
|
|
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
|
-
try {
|
|
10
|
-
const config = await import(configPath);
|
|
11
|
-
return config.default || config;
|
|
12
|
-
} catch (error) {
|
|
13
|
-
throw new Error(`Failed to load gkm.config.ts: ${error.message}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
Object.defineProperty(exports, 'loadConfig', {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return loadConfig;
|
|
22
|
-
}
|
|
23
|
-
});
|
package/dist/config-DV1Lwdkx.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { join } from "path";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
|
|
4
|
-
//#region src/config.ts
|
|
5
|
-
async function loadConfig() {
|
|
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
|
-
try {
|
|
9
|
-
const config = await import(configPath);
|
|
10
|
-
return config.default || config;
|
|
11
|
-
} catch (error) {
|
|
12
|
-
throw new Error(`Failed to load gkm.config.ts: ${error.message}`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
export { loadConfig };
|