@geekmidas/cli 0.0.13 → 0.0.14
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/cli.cjs +93 -5
- package/dist/cli.mjs +92 -5
- package/dist/{openapi-react-query-BWpdwBix.cjs → openapi-react-query-C1JLYUOs.cjs} +2 -2
- package/dist/{openapi-react-query-DuNQ8DwF.mjs → openapi-react-query-DpT3XHFC.mjs} +2 -2
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/package.json +3 -10
- package/src/cli.ts +23 -26
- package/src/openapi-react-query.ts +56 -34
- package/tsdown.config.ts +3 -1
- package/dist/cli-CNAOwWIn.cjs +0 -98
- package/dist/cli-jxBvJiFq.mjs +0 -97
- package/dist/index.cjs +0 -7
- package/dist/index.mjs +0 -7
- package/src/index.ts +0 -6
package/dist/cli.cjs
CHANGED
|
@@ -1,7 +1,95 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
3
|
require('./config-D8AyiwBU.cjs');
|
|
3
4
|
require('./loadEndpoints-Dh-dSqZX.cjs');
|
|
4
|
-
require('./build-CTKUZTHx.cjs');
|
|
5
|
-
require('./
|
|
6
|
-
require('./openapi-DrPYAlJ_.cjs');
|
|
7
|
-
require(
|
|
5
|
+
const require_build = require('./build-CTKUZTHx.cjs');
|
|
6
|
+
const require_openapi_react_query = require('./openapi-react-query-C1JLYUOs.cjs');
|
|
7
|
+
const require_openapi = require('./openapi-DrPYAlJ_.cjs');
|
|
8
|
+
const commander = require_chunk.__toESM(require("commander"));
|
|
9
|
+
|
|
10
|
+
//#region package.json
|
|
11
|
+
var name = "@geekmidas/cli";
|
|
12
|
+
var version = "0.0.14";
|
|
13
|
+
var private$1 = false;
|
|
14
|
+
var type = "module";
|
|
15
|
+
var bin = { "gkm": "./dist/cli.cjs" };
|
|
16
|
+
var publishConfig = {
|
|
17
|
+
"registry": "https://registry.npmjs.org/",
|
|
18
|
+
"access": "public"
|
|
19
|
+
};
|
|
20
|
+
var dependencies = {
|
|
21
|
+
"commander": "~14.0.0",
|
|
22
|
+
"lodash.get": "~4.4.2",
|
|
23
|
+
"lodash.set": "~4.3.2",
|
|
24
|
+
"zod": "~3.25.67",
|
|
25
|
+
"fast-glob": "~3.3.3",
|
|
26
|
+
"@geekmidas/api": "workspace:*"
|
|
27
|
+
};
|
|
28
|
+
var devDependencies = {
|
|
29
|
+
"@types/lodash.get": "~4.4.9",
|
|
30
|
+
"@types/lodash.set": "~4.3.9"
|
|
31
|
+
};
|
|
32
|
+
var package_default = {
|
|
33
|
+
name,
|
|
34
|
+
version,
|
|
35
|
+
private: private$1,
|
|
36
|
+
type,
|
|
37
|
+
bin,
|
|
38
|
+
publishConfig,
|
|
39
|
+
dependencies,
|
|
40
|
+
devDependencies
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/cli.ts
|
|
45
|
+
const program = new commander.Command();
|
|
46
|
+
program.name("gkm").description("GeekMidas backend framework CLI").version(package_default.version).option("--cwd <path>", "Change working directory");
|
|
47
|
+
program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
|
|
48
|
+
try {
|
|
49
|
+
const globalOptions = program.opts();
|
|
50
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
51
|
+
const providerList = [...new Set(options.providers.split(",").map((p) => p.trim()))];
|
|
52
|
+
await require_build.buildCommand({ providers: providerList });
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("Build failed:", error.message);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
program.command("cron").description("Manage cron jobs").action(() => {
|
|
59
|
+
const globalOptions = program.opts();
|
|
60
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
61
|
+
process.stdout.write("Cron management - coming soon\n");
|
|
62
|
+
});
|
|
63
|
+
program.command("function").description("Manage serverless functions").action(() => {
|
|
64
|
+
const globalOptions = program.opts();
|
|
65
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
66
|
+
process.stdout.write("Serverless function management - coming soon\n");
|
|
67
|
+
});
|
|
68
|
+
program.command("api").description("Manage REST API endpoints").action(() => {
|
|
69
|
+
const globalOptions = program.opts();
|
|
70
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
71
|
+
process.stdout.write("REST API management - coming soon\n");
|
|
72
|
+
});
|
|
73
|
+
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) => {
|
|
74
|
+
try {
|
|
75
|
+
const globalOptions = program.opts();
|
|
76
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
77
|
+
await require_openapi.openapiCommand(options);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error("OpenAPI generation failed:", error.message);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
program.command("generate:react-query").description("Generate React Query hooks from OpenAPI specification").option("--input <path>", "Input OpenAPI spec file path", "openapi.json").option("--output <path>", "Output file path for generated hooks", "src/api/hooks.ts").option("--name <name>", "API name prefix for generated code", "API").action(async (options) => {
|
|
84
|
+
try {
|
|
85
|
+
const globalOptions = program.opts();
|
|
86
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
87
|
+
await require_openapi_react_query.generateReactQueryCommand(options);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error("React Query generation failed:", error.message);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
program.parse();
|
|
94
|
+
|
|
95
|
+
//#endregion
|
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,94 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
2
|
import "./config-DV1Lwdkx.mjs";
|
|
3
3
|
import "./loadEndpoints-DKaw6Eqm.mjs";
|
|
4
|
-
import "./build-DgeiXkH-.mjs";
|
|
5
|
-
import "./
|
|
6
|
-
import "./openapi-DgLItZw-.mjs";
|
|
7
|
-
import "
|
|
4
|
+
import { buildCommand } from "./build-DgeiXkH-.mjs";
|
|
5
|
+
import { generateReactQueryCommand } from "./openapi-react-query-DpT3XHFC.mjs";
|
|
6
|
+
import { openapiCommand } from "./openapi-DgLItZw-.mjs";
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
|
|
9
|
+
//#region package.json
|
|
10
|
+
var name = "@geekmidas/cli";
|
|
11
|
+
var version = "0.0.14";
|
|
12
|
+
var private$1 = false;
|
|
13
|
+
var type = "module";
|
|
14
|
+
var bin = { "gkm": "./dist/cli.cjs" };
|
|
15
|
+
var publishConfig = {
|
|
16
|
+
"registry": "https://registry.npmjs.org/",
|
|
17
|
+
"access": "public"
|
|
18
|
+
};
|
|
19
|
+
var dependencies = {
|
|
20
|
+
"commander": "~14.0.0",
|
|
21
|
+
"lodash.get": "~4.4.2",
|
|
22
|
+
"lodash.set": "~4.3.2",
|
|
23
|
+
"zod": "~3.25.67",
|
|
24
|
+
"fast-glob": "~3.3.3",
|
|
25
|
+
"@geekmidas/api": "workspace:*"
|
|
26
|
+
};
|
|
27
|
+
var devDependencies = {
|
|
28
|
+
"@types/lodash.get": "~4.4.9",
|
|
29
|
+
"@types/lodash.set": "~4.3.9"
|
|
30
|
+
};
|
|
31
|
+
var package_default = {
|
|
32
|
+
name,
|
|
33
|
+
version,
|
|
34
|
+
private: private$1,
|
|
35
|
+
type,
|
|
36
|
+
bin,
|
|
37
|
+
publishConfig,
|
|
38
|
+
dependencies,
|
|
39
|
+
devDependencies
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/cli.ts
|
|
44
|
+
const program = new Command();
|
|
45
|
+
program.name("gkm").description("GeekMidas backend framework CLI").version(package_default.version).option("--cwd <path>", "Change working directory");
|
|
46
|
+
program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
|
|
47
|
+
try {
|
|
48
|
+
const globalOptions = program.opts();
|
|
49
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
50
|
+
const providerList = [...new Set(options.providers.split(",").map((p) => p.trim()))];
|
|
51
|
+
await buildCommand({ providers: providerList });
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error("Build failed:", error.message);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
program.command("cron").description("Manage cron jobs").action(() => {
|
|
58
|
+
const globalOptions = program.opts();
|
|
59
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
60
|
+
process.stdout.write("Cron management - coming soon\n");
|
|
61
|
+
});
|
|
62
|
+
program.command("function").description("Manage serverless functions").action(() => {
|
|
63
|
+
const globalOptions = program.opts();
|
|
64
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
65
|
+
process.stdout.write("Serverless function management - coming soon\n");
|
|
66
|
+
});
|
|
67
|
+
program.command("api").description("Manage REST API endpoints").action(() => {
|
|
68
|
+
const globalOptions = program.opts();
|
|
69
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
70
|
+
process.stdout.write("REST API management - coming soon\n");
|
|
71
|
+
});
|
|
72
|
+
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) => {
|
|
73
|
+
try {
|
|
74
|
+
const globalOptions = program.opts();
|
|
75
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
76
|
+
await openapiCommand(options);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error("OpenAPI generation failed:", error.message);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
program.command("generate:react-query").description("Generate React Query hooks from OpenAPI specification").option("--input <path>", "Input OpenAPI spec file path", "openapi.json").option("--output <path>", "Output file path for generated hooks", "src/api/hooks.ts").option("--name <name>", "API name prefix for generated code", "API").action(async (options) => {
|
|
83
|
+
try {
|
|
84
|
+
const globalOptions = program.opts();
|
|
85
|
+
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
86
|
+
await generateReactQueryCommand(options);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error("React Query generation failed:", error.message);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
program.parse();
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
2
|
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
3
|
-
const node_path = require_chunk.__toESM(require("node:path"));
|
|
4
|
-
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
5
3
|
const node_child_process = require_chunk.__toESM(require("node:child_process"));
|
|
4
|
+
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
5
|
+
const node_path = require_chunk.__toESM(require("node:path"));
|
|
6
6
|
const node_util = require_chunk.__toESM(require("node:util"));
|
|
7
7
|
|
|
8
8
|
//#region src/openapi-react-query.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
2
|
import { exec } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
|
|
7
7
|
//#region src/openapi-react-query.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
|
-
const require_openapi_react_query = require('./openapi-react-query-
|
|
2
|
+
const require_openapi_react_query = require('./openapi-react-query-C1JLYUOs.cjs');
|
|
3
3
|
|
|
4
4
|
exports.generateReactQueryCommand = require_openapi_react_query.generateReactQueryCommand;
|
package/package.json
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"gkm": "./
|
|
8
|
-
},
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"import": "./dist/index.mjs",
|
|
12
|
-
"require": "./dist/index.cjs",
|
|
13
|
-
"types": "./src/index.ts"
|
|
14
|
-
}
|
|
7
|
+
"gkm": "./dist/cli.cjs"
|
|
15
8
|
},
|
|
16
9
|
"publishConfig": {
|
|
17
10
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -23,7 +16,7 @@
|
|
|
23
16
|
"lodash.set": "~4.3.2",
|
|
24
17
|
"zod": "~3.25.67",
|
|
25
18
|
"fast-glob": "~3.3.3",
|
|
26
|
-
"@geekmidas/api": "0.0.
|
|
19
|
+
"@geekmidas/api": "0.0.31"
|
|
27
20
|
},
|
|
28
21
|
"devDependencies": {
|
|
29
22
|
"@types/lodash.get": "~4.4.9",
|
package/src/cli.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import pkg from '../package.json' assert { type: 'json' };
|
|
5
|
-
import { buildCommand } from './build.
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import type { Provider } from './types.
|
|
5
|
+
import { buildCommand } from './build.ts';
|
|
6
|
+
import { generateReactQueryCommand } from './openapi-react-query.ts';
|
|
7
|
+
import { openapiCommand } from './openapi.ts';
|
|
8
|
+
import type { Provider } from './types.ts';
|
|
9
9
|
|
|
10
10
|
const program = new Command();
|
|
11
11
|
|
|
@@ -96,32 +96,29 @@ program
|
|
|
96
96
|
program
|
|
97
97
|
.command('generate:react-query')
|
|
98
98
|
.description('Generate React Query hooks from OpenAPI specification')
|
|
99
|
-
.option(
|
|
100
|
-
'--input <path>',
|
|
101
|
-
'Input OpenAPI spec file path',
|
|
102
|
-
'openapi.json',
|
|
103
|
-
)
|
|
99
|
+
.option('--input <path>', 'Input OpenAPI spec file path', 'openapi.json')
|
|
104
100
|
.option(
|
|
105
101
|
'--output <path>',
|
|
106
102
|
'Output file path for generated hooks',
|
|
107
103
|
'src/api/hooks.ts',
|
|
108
104
|
)
|
|
109
|
-
.option(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
105
|
+
.option('--name <name>', 'API name prefix for generated code', 'API')
|
|
106
|
+
.action(
|
|
107
|
+
async (options: { input?: string; output?: string; name?: string }) => {
|
|
108
|
+
try {
|
|
109
|
+
const globalOptions = program.opts();
|
|
110
|
+
if (globalOptions.cwd) {
|
|
111
|
+
process.chdir(globalOptions.cwd);
|
|
112
|
+
}
|
|
113
|
+
await generateReactQueryCommand(options);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(
|
|
116
|
+
'React Query generation failed:',
|
|
117
|
+
(error as Error).message,
|
|
118
|
+
);
|
|
119
|
+
process.exit(1);
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
console.error('React Query generation failed:', (error as Error).message);
|
|
123
|
-
process.exit(1);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
121
|
+
},
|
|
122
|
+
);
|
|
126
123
|
|
|
127
124
|
program.parse();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
2
|
|
|
3
|
-
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
4
|
-
import { join, dirname } from 'node:path';
|
|
5
|
-
import { existsSync } from 'node:fs';
|
|
6
3
|
import { exec } from 'node:child_process';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
7
|
import { promisify } from 'node:util';
|
|
8
8
|
|
|
9
9
|
const execAsync = promisify(exec);
|
|
@@ -31,33 +31,41 @@ export async function generateReactQueryCommand(
|
|
|
31
31
|
try {
|
|
32
32
|
// Read OpenAPI spec
|
|
33
33
|
const inputPath = options.input || join(process.cwd(), 'openapi.json');
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
if (!existsSync(inputPath)) {
|
|
36
|
-
throw new Error(
|
|
36
|
+
throw new Error(
|
|
37
|
+
`OpenAPI spec not found at ${inputPath}. Run 'npx @geekmidas/cli openapi' first.`,
|
|
38
|
+
);
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
const specContent = await readFile(inputPath, 'utf-8');
|
|
40
42
|
const spec: OpenAPISpec = JSON.parse(specContent);
|
|
41
43
|
|
|
42
44
|
// Generate TypeScript types from OpenAPI spec
|
|
43
|
-
const outputDir = dirname(
|
|
45
|
+
const outputDir = dirname(
|
|
46
|
+
options.output || join(process.cwd(), 'src', 'api', 'hooks.ts'),
|
|
47
|
+
);
|
|
44
48
|
const typesPath = join(outputDir, 'openapi-types.d.ts');
|
|
45
|
-
|
|
49
|
+
|
|
46
50
|
logger.log('Generating TypeScript types from OpenAPI spec...');
|
|
47
|
-
|
|
51
|
+
|
|
48
52
|
try {
|
|
49
53
|
// Use npx to run openapi-typescript
|
|
50
54
|
await execAsync(
|
|
51
55
|
`npx openapi-typescript "${inputPath}" -o "${typesPath}"`,
|
|
52
|
-
{ cwd: process.cwd() }
|
|
56
|
+
{ cwd: process.cwd() },
|
|
53
57
|
);
|
|
54
58
|
logger.log(`TypeScript types generated: ${typesPath}`);
|
|
55
59
|
} catch (error) {
|
|
56
|
-
logger.warn(
|
|
60
|
+
logger.warn(
|
|
61
|
+
'Could not generate types with openapi-typescript. Install it for better type inference.',
|
|
62
|
+
);
|
|
57
63
|
logger.warn('Run: npm install -D openapi-typescript');
|
|
58
|
-
|
|
64
|
+
|
|
59
65
|
// Generate basic types file
|
|
60
|
-
await writeFile(
|
|
66
|
+
await writeFile(
|
|
67
|
+
typesPath,
|
|
68
|
+
`// Auto-generated placeholder types
|
|
61
69
|
export interface paths {
|
|
62
70
|
[path: string]: {
|
|
63
71
|
[method: string]: {
|
|
@@ -68,24 +76,32 @@ export interface paths {
|
|
|
68
76
|
};
|
|
69
77
|
};
|
|
70
78
|
}
|
|
71
|
-
|
|
79
|
+
`,
|
|
80
|
+
);
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
// Extract operation info
|
|
75
84
|
const operations = extractOperations(spec);
|
|
76
|
-
|
|
85
|
+
|
|
77
86
|
// Generate TypeScript code
|
|
78
|
-
const code = generateReactQueryCode(
|
|
87
|
+
const code = generateReactQueryCode(
|
|
88
|
+
spec,
|
|
89
|
+
operations,
|
|
90
|
+
options.name || 'API',
|
|
91
|
+
);
|
|
79
92
|
|
|
80
93
|
// Write output
|
|
81
|
-
const outputPath =
|
|
94
|
+
const outputPath =
|
|
95
|
+
options.output || join(process.cwd(), 'src', 'api', 'hooks.ts');
|
|
82
96
|
await mkdir(dirname(outputPath), { recursive: true });
|
|
83
97
|
await writeFile(outputPath, code);
|
|
84
98
|
|
|
85
99
|
logger.log(`React Query hooks generated: ${outputPath}`);
|
|
86
100
|
logger.log(`Generated ${operations.length} hooks`);
|
|
87
101
|
} catch (error) {
|
|
88
|
-
throw new Error(
|
|
102
|
+
throw new Error(
|
|
103
|
+
`React Query generation failed: ${(error as Error).message}`,
|
|
104
|
+
);
|
|
89
105
|
}
|
|
90
106
|
}
|
|
91
107
|
|
|
@@ -137,7 +153,7 @@ function extractResponseType(operation: any): string {
|
|
|
137
153
|
|
|
138
154
|
function schemaToTypeString(schema: any): string {
|
|
139
155
|
if (!schema) return 'unknown';
|
|
140
|
-
|
|
156
|
+
|
|
141
157
|
switch (schema.type) {
|
|
142
158
|
case 'string':
|
|
143
159
|
return 'string';
|
|
@@ -151,7 +167,10 @@ function schemaToTypeString(schema: any): string {
|
|
|
151
167
|
case 'object':
|
|
152
168
|
if (schema.properties) {
|
|
153
169
|
const props = Object.entries(schema.properties)
|
|
154
|
-
.map(
|
|
170
|
+
.map(
|
|
171
|
+
([key, value]: [string, any]) =>
|
|
172
|
+
`${key}: ${schemaToTypeString(value)}`,
|
|
173
|
+
)
|
|
155
174
|
.join('; ');
|
|
156
175
|
return `{ ${props} }`;
|
|
157
176
|
}
|
|
@@ -178,13 +197,13 @@ export const ${apiName.toLowerCase()} = createTypedQueryClient<paths>({
|
|
|
178
197
|
`;
|
|
179
198
|
|
|
180
199
|
const queryHooks = operations
|
|
181
|
-
.filter(op => op.method === 'GET')
|
|
182
|
-
.map(op => generateQueryHook(op, apiName))
|
|
200
|
+
.filter((op) => op.method === 'GET')
|
|
201
|
+
.map((op) => generateQueryHook(op, apiName))
|
|
183
202
|
.join('\n\n');
|
|
184
203
|
|
|
185
204
|
const mutationHooks = operations
|
|
186
|
-
.filter(op => op.method !== 'GET')
|
|
187
|
-
.map(op => generateMutationHook(op, apiName))
|
|
205
|
+
.filter((op) => op.method !== 'GET')
|
|
206
|
+
.map((op) => generateMutationHook(op, apiName))
|
|
188
207
|
.join('\n\n');
|
|
189
208
|
|
|
190
209
|
const typeExports = generateTypeExports(operations);
|
|
@@ -207,18 +226,21 @@ export { ${apiName.toLowerCase()} };
|
|
|
207
226
|
function generateQueryHook(op: OperationInfo, apiName: string): string {
|
|
208
227
|
const hookName = `use${capitalize(op.operationId)}`;
|
|
209
228
|
const endpoint = op.endpoint;
|
|
210
|
-
const hasParams = op.parameters?.some(p => p.in === 'path');
|
|
211
|
-
const hasQuery = op.parameters?.some(p => p.in === 'query');
|
|
212
|
-
|
|
229
|
+
const hasParams = op.parameters?.some((p) => p.in === 'path');
|
|
230
|
+
const hasQuery = op.parameters?.some((p) => p.in === 'query');
|
|
231
|
+
|
|
213
232
|
// Generate properly typed hook
|
|
214
233
|
let params = '';
|
|
215
234
|
let args = '';
|
|
216
|
-
|
|
235
|
+
|
|
217
236
|
if (hasParams || hasQuery) {
|
|
218
237
|
const paramParts: string[] = [];
|
|
219
238
|
if (hasParams) {
|
|
220
|
-
const pathParams =
|
|
221
|
-
|
|
239
|
+
const pathParams =
|
|
240
|
+
op.parameters?.filter((p) => p.in === 'path').map((p) => p.name) || [];
|
|
241
|
+
paramParts.push(
|
|
242
|
+
`params: { ${pathParams.map((p) => `${p}: string`).join('; ')} }`,
|
|
243
|
+
);
|
|
222
244
|
}
|
|
223
245
|
if (hasQuery) {
|
|
224
246
|
paramParts.push(`query?: Record<string, any>`);
|
|
@@ -226,7 +248,7 @@ function generateQueryHook(op: OperationInfo, apiName: string): string {
|
|
|
226
248
|
params = `config: { ${paramParts.join('; ')} }, `;
|
|
227
249
|
args = ', config';
|
|
228
250
|
}
|
|
229
|
-
|
|
251
|
+
|
|
230
252
|
return `export const ${hookName} = (
|
|
231
253
|
${params}options?: Parameters<typeof ${apiName.toLowerCase()}.useQuery>[2]
|
|
232
254
|
) => {
|
|
@@ -237,7 +259,7 @@ function generateQueryHook(op: OperationInfo, apiName: string): string {
|
|
|
237
259
|
function generateMutationHook(op: OperationInfo, apiName: string): string {
|
|
238
260
|
const hookName = `use${capitalize(op.operationId)}`;
|
|
239
261
|
const endpoint = op.endpoint;
|
|
240
|
-
|
|
262
|
+
|
|
241
263
|
return `export const ${hookName} = (
|
|
242
264
|
options?: Parameters<typeof ${apiName.toLowerCase()}.useMutation>[1]
|
|
243
265
|
) => {
|
|
@@ -246,10 +268,10 @@ function generateMutationHook(op: OperationInfo, apiName: string): string {
|
|
|
246
268
|
}
|
|
247
269
|
|
|
248
270
|
function generateTypeExports(operations: OperationInfo[]): string {
|
|
249
|
-
const exports = operations.map(op => {
|
|
271
|
+
const exports = operations.map((op) => {
|
|
250
272
|
const typeName = capitalize(op.operationId);
|
|
251
273
|
const isQuery = op.method === 'GET';
|
|
252
|
-
|
|
274
|
+
|
|
253
275
|
if (isQuery) {
|
|
254
276
|
return `export type ${typeName}Response = Awaited<ReturnType<ReturnType<typeof use${typeName}>['data']>>;`;
|
|
255
277
|
} else {
|
|
@@ -262,4 +284,4 @@ function generateTypeExports(operations: OperationInfo[]): string {
|
|
|
262
284
|
|
|
263
285
|
function capitalize(str: string): string {
|
|
264
286
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
265
|
-
}
|
|
287
|
+
}
|
package/tsdown.config.ts
CHANGED
package/dist/cli-CNAOwWIn.cjs
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_build = require('./build-CTKUZTHx.cjs');
|
|
3
|
-
const require_openapi = require('./openapi-DrPYAlJ_.cjs');
|
|
4
|
-
const require_openapi_react_query = require('./openapi-react-query-BWpdwBix.cjs');
|
|
5
|
-
const commander = require_chunk.__toESM(require("commander"));
|
|
6
|
-
|
|
7
|
-
//#region package.json
|
|
8
|
-
var name = "@geekmidas/cli";
|
|
9
|
-
var version = "0.0.13";
|
|
10
|
-
var private$1 = false;
|
|
11
|
-
var type = "module";
|
|
12
|
-
var bin = { "gkm": "./src/index.ts" };
|
|
13
|
-
var exports$1 = { ".": {
|
|
14
|
-
"import": "./dist/index.mjs",
|
|
15
|
-
"require": "./dist/index.cjs",
|
|
16
|
-
"types": "./src/index.ts"
|
|
17
|
-
} };
|
|
18
|
-
var publishConfig = {
|
|
19
|
-
"registry": "https://registry.npmjs.org/",
|
|
20
|
-
"access": "public"
|
|
21
|
-
};
|
|
22
|
-
var dependencies = {
|
|
23
|
-
"commander": "~14.0.0",
|
|
24
|
-
"lodash.get": "~4.4.2",
|
|
25
|
-
"lodash.set": "~4.3.2",
|
|
26
|
-
"zod": "~3.25.67",
|
|
27
|
-
"fast-glob": "~3.3.3",
|
|
28
|
-
"@geekmidas/api": "workspace:*"
|
|
29
|
-
};
|
|
30
|
-
var devDependencies = {
|
|
31
|
-
"@types/lodash.get": "~4.4.9",
|
|
32
|
-
"@types/lodash.set": "~4.3.9"
|
|
33
|
-
};
|
|
34
|
-
var package_default = {
|
|
35
|
-
name,
|
|
36
|
-
version,
|
|
37
|
-
private: private$1,
|
|
38
|
-
type,
|
|
39
|
-
bin,
|
|
40
|
-
exports: exports$1,
|
|
41
|
-
publishConfig,
|
|
42
|
-
dependencies,
|
|
43
|
-
devDependencies
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/cli.ts
|
|
48
|
-
const program = new commander.Command();
|
|
49
|
-
program.name("gkm").description("GeekMidas backend framework CLI").version(package_default.version).option("--cwd <path>", "Change working directory");
|
|
50
|
-
program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
|
|
51
|
-
try {
|
|
52
|
-
const globalOptions = program.opts();
|
|
53
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
54
|
-
const providerList = [...new Set(options.providers.split(",").map((p) => p.trim()))];
|
|
55
|
-
await require_build.buildCommand({ providers: providerList });
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error("Build failed:", error.message);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
program.command("cron").description("Manage cron jobs").action(() => {
|
|
62
|
-
const globalOptions = program.opts();
|
|
63
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
64
|
-
process.stdout.write("Cron management - coming soon\n");
|
|
65
|
-
});
|
|
66
|
-
program.command("function").description("Manage serverless functions").action(() => {
|
|
67
|
-
const globalOptions = program.opts();
|
|
68
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
69
|
-
process.stdout.write("Serverless function management - coming soon\n");
|
|
70
|
-
});
|
|
71
|
-
program.command("api").description("Manage REST API endpoints").action(() => {
|
|
72
|
-
const globalOptions = program.opts();
|
|
73
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
74
|
-
process.stdout.write("REST API management - coming soon\n");
|
|
75
|
-
});
|
|
76
|
-
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) => {
|
|
77
|
-
try {
|
|
78
|
-
const globalOptions = program.opts();
|
|
79
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
80
|
-
await require_openapi.openapiCommand(options);
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error("OpenAPI generation failed:", error.message);
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
program.command("generate:react-query").description("Generate React Query hooks from OpenAPI specification").option("--input <path>", "Input OpenAPI spec file path", "openapi.json").option("--output <path>", "Output file path for generated hooks", "src/api/hooks.ts").option("--name <name>", "API name prefix for generated code", "API").action(async (options) => {
|
|
87
|
-
try {
|
|
88
|
-
const globalOptions = program.opts();
|
|
89
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
90
|
-
await require_openapi_react_query.generateReactQueryCommand(options);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.error("React Query generation failed:", error.message);
|
|
93
|
-
process.exit(1);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
program.parse();
|
|
97
|
-
|
|
98
|
-
//#endregion
|
package/dist/cli-jxBvJiFq.mjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { buildCommand } from "./build-DgeiXkH-.mjs";
|
|
2
|
-
import { openapiCommand } from "./openapi-DgLItZw-.mjs";
|
|
3
|
-
import { generateReactQueryCommand } from "./openapi-react-query-DuNQ8DwF.mjs";
|
|
4
|
-
import { Command } from "commander";
|
|
5
|
-
|
|
6
|
-
//#region package.json
|
|
7
|
-
var name = "@geekmidas/cli";
|
|
8
|
-
var version = "0.0.13";
|
|
9
|
-
var private$1 = false;
|
|
10
|
-
var type = "module";
|
|
11
|
-
var bin = { "gkm": "./src/index.ts" };
|
|
12
|
-
var exports = { ".": {
|
|
13
|
-
"import": "./dist/index.mjs",
|
|
14
|
-
"require": "./dist/index.cjs",
|
|
15
|
-
"types": "./src/index.ts"
|
|
16
|
-
} };
|
|
17
|
-
var publishConfig = {
|
|
18
|
-
"registry": "https://registry.npmjs.org/",
|
|
19
|
-
"access": "public"
|
|
20
|
-
};
|
|
21
|
-
var dependencies = {
|
|
22
|
-
"commander": "~14.0.0",
|
|
23
|
-
"lodash.get": "~4.4.2",
|
|
24
|
-
"lodash.set": "~4.3.2",
|
|
25
|
-
"zod": "~3.25.67",
|
|
26
|
-
"fast-glob": "~3.3.3",
|
|
27
|
-
"@geekmidas/api": "workspace:*"
|
|
28
|
-
};
|
|
29
|
-
var devDependencies = {
|
|
30
|
-
"@types/lodash.get": "~4.4.9",
|
|
31
|
-
"@types/lodash.set": "~4.3.9"
|
|
32
|
-
};
|
|
33
|
-
var package_default = {
|
|
34
|
-
name,
|
|
35
|
-
version,
|
|
36
|
-
private: private$1,
|
|
37
|
-
type,
|
|
38
|
-
bin,
|
|
39
|
-
exports,
|
|
40
|
-
publishConfig,
|
|
41
|
-
dependencies,
|
|
42
|
-
devDependencies
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/cli.ts
|
|
47
|
-
const program = new Command();
|
|
48
|
-
program.name("gkm").description("GeekMidas backend framework CLI").version(package_default.version).option("--cwd <path>", "Change working directory");
|
|
49
|
-
program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
|
|
50
|
-
try {
|
|
51
|
-
const globalOptions = program.opts();
|
|
52
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
53
|
-
const providerList = [...new Set(options.providers.split(",").map((p) => p.trim()))];
|
|
54
|
-
await buildCommand({ providers: providerList });
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error("Build failed:", error.message);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
program.command("cron").description("Manage cron jobs").action(() => {
|
|
61
|
-
const globalOptions = program.opts();
|
|
62
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
63
|
-
process.stdout.write("Cron management - coming soon\n");
|
|
64
|
-
});
|
|
65
|
-
program.command("function").description("Manage serverless functions").action(() => {
|
|
66
|
-
const globalOptions = program.opts();
|
|
67
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
68
|
-
process.stdout.write("Serverless function management - coming soon\n");
|
|
69
|
-
});
|
|
70
|
-
program.command("api").description("Manage REST API endpoints").action(() => {
|
|
71
|
-
const globalOptions = program.opts();
|
|
72
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
73
|
-
process.stdout.write("REST API management - coming soon\n");
|
|
74
|
-
});
|
|
75
|
-
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) => {
|
|
76
|
-
try {
|
|
77
|
-
const globalOptions = program.opts();
|
|
78
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
79
|
-
await openapiCommand(options);
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error("OpenAPI generation failed:", error.message);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
program.command("generate:react-query").description("Generate React Query hooks from OpenAPI specification").option("--input <path>", "Input OpenAPI spec file path", "openapi.json").option("--output <path>", "Output file path for generated hooks", "src/api/hooks.ts").option("--name <name>", "API name prefix for generated code", "API").action(async (options) => {
|
|
86
|
-
try {
|
|
87
|
-
const globalOptions = program.opts();
|
|
88
|
-
if (globalOptions.cwd) process.chdir(globalOptions.cwd);
|
|
89
|
-
await generateReactQueryCommand(options);
|
|
90
|
-
} catch (error) {
|
|
91
|
-
console.error("React Query generation failed:", error.message);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
program.parse();
|
|
96
|
-
|
|
97
|
-
//#endregion
|
package/dist/index.cjs
DELETED
package/dist/index.mjs
DELETED