nuxt-openapi-hyperfetch 0.1.7-alpha.1 → 0.2.7-alpha.1
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/CONTRIBUTING.md +291 -292
- package/INSTRUCTIONS.md +327 -327
- package/LICENSE +202 -202
- package/README.md +231 -227
- package/dist/cli/logger.d.ts +26 -0
- package/dist/cli/logger.js +36 -0
- package/dist/cli/logo.js +5 -5
- package/dist/generators/components/connector-generator/generator.d.ts +12 -0
- package/dist/generators/components/connector-generator/generator.js +116 -0
- package/dist/generators/components/connector-generator/templates.d.ts +18 -0
- package/dist/generators/components/connector-generator/templates.js +222 -0
- package/dist/generators/components/connector-generator/types.d.ts +32 -0
- package/dist/generators/components/connector-generator/types.js +7 -0
- package/dist/generators/components/schema-analyzer/index.d.ts +17 -0
- package/dist/generators/components/schema-analyzer/index.js +20 -0
- package/dist/generators/components/schema-analyzer/intent-detector.d.ts +17 -0
- package/dist/generators/components/schema-analyzer/intent-detector.js +143 -0
- package/dist/generators/components/schema-analyzer/openapi-reader.d.ts +11 -0
- package/dist/generators/components/schema-analyzer/openapi-reader.js +76 -0
- package/dist/generators/components/schema-analyzer/resource-grouper.d.ts +6 -0
- package/dist/generators/components/schema-analyzer/resource-grouper.js +132 -0
- package/dist/generators/components/schema-analyzer/schema-field-mapper.d.ts +35 -0
- package/dist/generators/components/schema-analyzer/schema-field-mapper.js +220 -0
- package/dist/generators/components/schema-analyzer/types.d.ts +156 -0
- package/dist/generators/components/schema-analyzer/types.js +7 -0
- package/dist/generators/nuxt-server/generator.d.ts +2 -1
- package/dist/generators/nuxt-server/generator.js +21 -21
- package/dist/generators/shared/runtime/apiHelpers.d.ts +81 -41
- package/dist/generators/shared/runtime/apiHelpers.js +97 -104
- package/dist/generators/shared/runtime/pagination.d.ts +168 -0
- package/dist/generators/shared/runtime/pagination.js +179 -0
- package/dist/generators/shared/runtime/useDeleteConnector.d.ts +16 -0
- package/dist/generators/shared/runtime/useDeleteConnector.js +93 -0
- package/dist/generators/shared/runtime/useDetailConnector.d.ts +14 -0
- package/dist/generators/shared/runtime/useDetailConnector.js +50 -0
- package/dist/generators/shared/runtime/useFormConnector.d.ts +19 -0
- package/dist/generators/shared/runtime/useFormConnector.js +113 -0
- package/dist/generators/shared/runtime/useListConnector.d.ts +25 -0
- package/dist/generators/shared/runtime/useListConnector.js +125 -0
- package/dist/generators/shared/runtime/zod-error-merger.d.ts +23 -0
- package/dist/generators/shared/runtime/zod-error-merger.js +106 -0
- package/dist/generators/shared/templates/api-callbacks-plugin.js +54 -11
- package/dist/generators/shared/templates/api-pagination-plugin.d.ts +51 -0
- package/dist/generators/shared/templates/api-pagination-plugin.js +152 -0
- package/dist/generators/use-async-data/generator.d.ts +2 -1
- package/dist/generators/use-async-data/generator.js +14 -14
- package/dist/generators/use-async-data/runtime/useApiAsyncData.js +114 -13
- package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.js +88 -10
- package/dist/generators/use-async-data/templates.js +17 -17
- package/dist/generators/use-fetch/generator.d.ts +2 -1
- package/dist/generators/use-fetch/generator.js +12 -12
- package/dist/generators/use-fetch/runtime/useApiRequest.js +149 -40
- package/dist/generators/use-fetch/templates.js +14 -14
- package/dist/index.js +25 -0
- package/dist/module/index.d.ts +4 -0
- package/dist/module/index.js +93 -0
- package/dist/module/types.d.ts +27 -0
- package/dist/module/types.js +1 -0
- package/docs/API-REFERENCE.md +886 -887
- package/docs/generated-components.md +615 -0
- package/docs/headless-composables-ui.md +569 -0
- package/eslint.config.js +13 -0
- package/package.json +29 -2
- package/src/cli/config.ts +140 -140
- package/src/cli/logger.ts +124 -66
- package/src/cli/logo.ts +25 -25
- package/src/cli/types.ts +50 -50
- package/src/generators/components/connector-generator/generator.ts +138 -0
- package/src/generators/components/connector-generator/templates.ts +254 -0
- package/src/generators/components/connector-generator/types.ts +34 -0
- package/src/generators/components/schema-analyzer/index.ts +44 -0
- package/src/generators/components/schema-analyzer/intent-detector.ts +187 -0
- package/src/generators/components/schema-analyzer/openapi-reader.ts +96 -0
- package/src/generators/components/schema-analyzer/resource-grouper.ts +166 -0
- package/src/generators/components/schema-analyzer/schema-field-mapper.ts +268 -0
- package/src/generators/components/schema-analyzer/types.ts +177 -0
- package/src/generators/nuxt-server/generator.ts +272 -270
- package/src/generators/shared/runtime/apiHelpers.ts +535 -507
- package/src/generators/shared/runtime/pagination.ts +323 -0
- package/src/generators/shared/runtime/useDeleteConnector.ts +109 -0
- package/src/generators/shared/runtime/useDetailConnector.ts +64 -0
- package/src/generators/shared/runtime/useFormConnector.ts +139 -0
- package/src/generators/shared/runtime/useListConnector.ts +148 -0
- package/src/generators/shared/runtime/zod-error-merger.ts +119 -0
- package/src/generators/shared/templates/api-callbacks-plugin.ts +399 -352
- package/src/generators/shared/templates/api-pagination-plugin.ts +158 -0
- package/src/generators/use-async-data/generator.ts +205 -204
- package/src/generators/use-async-data/runtime/useApiAsyncData.ts +329 -229
- package/src/generators/use-async-data/runtime/useApiAsyncDataRaw.ts +324 -245
- package/src/generators/use-async-data/templates.ts +257 -257
- package/src/generators/use-fetch/generator.ts +170 -169
- package/src/generators/use-fetch/runtime/useApiRequest.ts +354 -234
- package/src/generators/use-fetch/templates.ts +214 -214
- package/src/index.ts +303 -265
- package/src/module/index.ts +133 -0
- package/src/module/types.ts +31 -0
- package/src/generators/tanstack-query/generator.ts +0 -11
package/src/index.ts
CHANGED
|
@@ -1,265 +1,303 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import * as p from '@clack/prompts';
|
|
4
|
-
import { generateOpenApiFiles, generateHeyApiFiles, checkJavaInstalled } from './generate.js';
|
|
5
|
-
import { generateUseFetchComposables } from './generators/use-fetch/generator.js';
|
|
6
|
-
import { generateUseAsyncDataComposables } from './generators/use-async-data/generator.js';
|
|
7
|
-
import { generateNuxtServerRoutes } from './generators/nuxt-server/generator.js';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
.
|
|
45
|
-
.option('-
|
|
46
|
-
.option('
|
|
47
|
-
.option('--
|
|
48
|
-
.option('--
|
|
49
|
-
.option('--
|
|
50
|
-
.option('--
|
|
51
|
-
.option('--
|
|
52
|
-
.option('-
|
|
53
|
-
.option('--
|
|
54
|
-
.option('--
|
|
55
|
-
.option('--
|
|
56
|
-
.option('--
|
|
57
|
-
.option('--
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
//
|
|
102
|
-
// config.generator
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
'
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
let
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
let
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
s.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
spinner.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
.
|
|
250
|
-
.
|
|
251
|
-
.option('-
|
|
252
|
-
.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import * as p from '@clack/prompts';
|
|
4
|
+
import { generateOpenApiFiles, generateHeyApiFiles, checkJavaInstalled } from './generate.js';
|
|
5
|
+
import { generateUseFetchComposables } from './generators/use-fetch/generator.js';
|
|
6
|
+
import { generateUseAsyncDataComposables } from './generators/use-async-data/generator.js';
|
|
7
|
+
import { generateNuxtServerRoutes } from './generators/nuxt-server/generator.js';
|
|
8
|
+
import { generateConnectors } from './generators/components/connector-generator/generator.js';
|
|
9
|
+
import {
|
|
10
|
+
promptInitialInputs,
|
|
11
|
+
promptInputPath,
|
|
12
|
+
promptComposablesSelection,
|
|
13
|
+
promptServerRoutePath,
|
|
14
|
+
promptBffConfig,
|
|
15
|
+
promptGeneratorBackend,
|
|
16
|
+
} from './cli/prompts.js';
|
|
17
|
+
import { MESSAGES } from './cli/messages.js';
|
|
18
|
+
import { displayLogo } from './cli/logo.js';
|
|
19
|
+
import { loadConfig, mergeConfig, parseTags, parseGenerators } from './cli/config.js';
|
|
20
|
+
|
|
21
|
+
const program = new Command();
|
|
22
|
+
|
|
23
|
+
program.name('nxh').description('Nuxt OpenAPI Hyperfetch generator').version('1.0.0');
|
|
24
|
+
|
|
25
|
+
interface GenerateOptions {
|
|
26
|
+
input?: string;
|
|
27
|
+
output?: string;
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
mode?: 'client' | 'server';
|
|
30
|
+
tags?: string;
|
|
31
|
+
excludeTags?: string;
|
|
32
|
+
overwrite?: boolean;
|
|
33
|
+
dryRun?: boolean;
|
|
34
|
+
verbose?: boolean;
|
|
35
|
+
watch?: boolean;
|
|
36
|
+
generators?: string;
|
|
37
|
+
serverRoutePath?: string;
|
|
38
|
+
enableBff?: boolean;
|
|
39
|
+
backend?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
program
|
|
43
|
+
.command('generate')
|
|
44
|
+
.description('Generate all nuxt files and composables from OpenAPI spec')
|
|
45
|
+
.option('-i, --input <path>', 'OpenAPI file path or URL')
|
|
46
|
+
.option('-o, --output <path>', 'Output directory')
|
|
47
|
+
.option('--base-url <url>', 'Base URL for API requests')
|
|
48
|
+
.option('--mode <mode>', 'Generation mode: client or server', 'client')
|
|
49
|
+
.option('--tags <tags>', 'Generate only specific tags (comma-separated)')
|
|
50
|
+
.option('--exclude-tags <tags>', 'Exclude specific tags (comma-separated)')
|
|
51
|
+
.option('--overwrite', 'Overwrite existing files without prompting', false)
|
|
52
|
+
.option('--dry-run', 'Preview changes without writing files', false)
|
|
53
|
+
.option('-v, --verbose', 'Enable verbose logging', false)
|
|
54
|
+
.option('--watch', 'Watch mode - regenerate on file changes', false)
|
|
55
|
+
.option('--generators <types>', 'Generators to use: useFetch,useAsyncData,nuxtServer')
|
|
56
|
+
.option('--server-route-path <path>', 'Server route path (for nuxtServer mode)')
|
|
57
|
+
.option('--enable-bff', 'Enable BFF pattern (for nuxtServer mode)', false)
|
|
58
|
+
.option('--backend <type>', 'Generator backend: official (Java) or heyapi (Node.js)')
|
|
59
|
+
.action(async (options: GenerateOptions) => {
|
|
60
|
+
try {
|
|
61
|
+
// Load config file
|
|
62
|
+
const fileConfig = await loadConfig();
|
|
63
|
+
|
|
64
|
+
if (options.verbose && fileConfig) {
|
|
65
|
+
p.log.info('Loaded configuration from file');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Parse and merge configuration
|
|
69
|
+
const config = mergeConfig(fileConfig, {
|
|
70
|
+
input: options.input,
|
|
71
|
+
output: options.output,
|
|
72
|
+
baseUrl: options.baseUrl,
|
|
73
|
+
mode: options.mode,
|
|
74
|
+
tags: parseTags(options.tags),
|
|
75
|
+
excludeTags: parseTags(options.excludeTags),
|
|
76
|
+
overwrite: options.overwrite,
|
|
77
|
+
dryRun: options.dryRun,
|
|
78
|
+
verbose: options.verbose,
|
|
79
|
+
watch: options.watch,
|
|
80
|
+
generators: parseGenerators(options.generators),
|
|
81
|
+
serverRoutePath: options.serverRoutePath,
|
|
82
|
+
enableBff: options.enableBff,
|
|
83
|
+
backend:
|
|
84
|
+
options.backend === 'official' || options.backend === 'heyapi'
|
|
85
|
+
? options.backend
|
|
86
|
+
: undefined,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (config.verbose) {
|
|
90
|
+
console.log('Configuration:', config);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Show logo and intro
|
|
94
|
+
displayLogo();
|
|
95
|
+
p.intro(MESSAGES.intro);
|
|
96
|
+
|
|
97
|
+
if (config.dryRun) {
|
|
98
|
+
p.log.warn('🔍 DRY RUN MODE - No files will be written');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 0. Select generator engine (first question)
|
|
102
|
+
// Resolve engine from config.generator (user-facing) or config.backend (CLI flag)
|
|
103
|
+
// config.generator: 'openapi' | 'heyapi' → map 'openapi' to internal 'official'
|
|
104
|
+
const resolvedBackend =
|
|
105
|
+
config.generator === 'openapi'
|
|
106
|
+
? 'official'
|
|
107
|
+
: config.generator === 'heyapi'
|
|
108
|
+
? 'heyapi'
|
|
109
|
+
: config.backend;
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
111
|
+
const backend = await promptGeneratorBackend(resolvedBackend);
|
|
112
|
+
|
|
113
|
+
// Check Java availability when official backend is selected
|
|
114
|
+
if (backend === 'official' && !checkJavaInstalled()) {
|
|
115
|
+
p.log.error(
|
|
116
|
+
'Java not found. The OpenAPI Generator requires Java 11 or higher.\n' +
|
|
117
|
+
'Install it from: https://adoptium.net\n' +
|
|
118
|
+
'Or switch to @hey-api/openapi-ts which requires no Java.'
|
|
119
|
+
);
|
|
120
|
+
p.outro('Aborted.');
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 1. Determine composables to generate FIRST
|
|
125
|
+
let composables: ('useFetch' | 'useAsyncData' | 'nuxtServer')[];
|
|
126
|
+
|
|
127
|
+
if (config.generators) {
|
|
128
|
+
composables = config.generators;
|
|
129
|
+
if (config.verbose) {
|
|
130
|
+
console.log(`Using generators from config: ${composables.join(', ')}`);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
const result = await promptComposablesSelection();
|
|
134
|
+
composables = result.composables;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (composables.length === 0) {
|
|
138
|
+
p.outro(MESSAGES.outro.noComposables);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 2. Ask for paths based on which generators were selected
|
|
143
|
+
const needsComposables = composables.some((c) => c === 'useFetch' || c === 'useAsyncData');
|
|
144
|
+
const needsNuxtServer = composables.includes('nuxtServer');
|
|
145
|
+
|
|
146
|
+
let inputPath: string;
|
|
147
|
+
let outputPath: string;
|
|
148
|
+
|
|
149
|
+
if (needsComposables) {
|
|
150
|
+
// useFetch/useAsyncData: ask for both input (OpenAPI spec) and output (composables dir)
|
|
151
|
+
const inputs = await promptInitialInputs(config.input, config.output);
|
|
152
|
+
inputPath = inputs.inputPath;
|
|
153
|
+
outputPath = inputs.outputPath;
|
|
154
|
+
} else {
|
|
155
|
+
// nuxtServer only: ask just for the OpenAPI spec, use default/config for output
|
|
156
|
+
inputPath = await promptInputPath(config.input);
|
|
157
|
+
outputPath = config.output ?? './swagger';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 3. Ask for server route path if nuxtServer is selected
|
|
161
|
+
let serverRoutePath = config.serverRoutePath || '';
|
|
162
|
+
let enableBff = config.enableBff || false;
|
|
163
|
+
|
|
164
|
+
if (needsNuxtServer && !config.serverRoutePath) {
|
|
165
|
+
serverRoutePath = await promptServerRoutePath();
|
|
166
|
+
const bffConfig = await promptBffConfig();
|
|
167
|
+
enableBff = bffConfig.enableBff;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Generate OpenAPI files
|
|
171
|
+
const s = p.spinner();
|
|
172
|
+
s.start(MESSAGES.steps.generatingOpenApi);
|
|
173
|
+
|
|
174
|
+
if (!config.dryRun) {
|
|
175
|
+
if (backend === 'heyapi') {
|
|
176
|
+
await generateHeyApiFiles(inputPath, outputPath);
|
|
177
|
+
} else {
|
|
178
|
+
generateOpenApiFiles(inputPath, outputPath);
|
|
179
|
+
}
|
|
180
|
+
s.stop('OpenAPI files generated');
|
|
181
|
+
} else {
|
|
182
|
+
s.stop('Would generate OpenAPI files (skipped in dry-run)');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Generate selected composables
|
|
186
|
+
const composablesOutputDir = `${outputPath}/composables`;
|
|
187
|
+
|
|
188
|
+
for (const composable of composables) {
|
|
189
|
+
const spinner = p.spinner();
|
|
190
|
+
spinner.start(`Generating ${composable}...`);
|
|
191
|
+
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
193
|
+
const generateOptions = { baseUrl: config.baseUrl, backend };
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
switch (composable) {
|
|
197
|
+
case 'useFetch':
|
|
198
|
+
if (!config.dryRun) {
|
|
199
|
+
await generateUseFetchComposables(
|
|
200
|
+
outputPath,
|
|
201
|
+
`${composablesOutputDir}/use-fetch`,
|
|
202
|
+
generateOptions
|
|
203
|
+
);
|
|
204
|
+
spinner.stop(`✓ Generated useFetch composables`);
|
|
205
|
+
} else {
|
|
206
|
+
spinner.stop(`Would generate useFetch composables (dry-run)`);
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
case 'useAsyncData':
|
|
210
|
+
if (!config.dryRun) {
|
|
211
|
+
await generateUseAsyncDataComposables(
|
|
212
|
+
outputPath,
|
|
213
|
+
`${composablesOutputDir}/use-async-data`,
|
|
214
|
+
generateOptions
|
|
215
|
+
);
|
|
216
|
+
spinner.stop(`✓ Generated useAsyncData composables`);
|
|
217
|
+
} else {
|
|
218
|
+
spinner.stop(`Would generate useAsyncData composables (dry-run)`);
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case 'nuxtServer':
|
|
222
|
+
if (!config.dryRun) {
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
224
|
+
await generateNuxtServerRoutes(outputPath, serverRoutePath, { enableBff, backend });
|
|
225
|
+
spinner.stop(`✓ Generated Nuxt server routes`);
|
|
226
|
+
} else {
|
|
227
|
+
spinner.stop(`Would generate Nuxt server routes (dry-run)`);
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
} catch (error) {
|
|
232
|
+
spinner.stop(`✗ Failed to generate ${composable}`);
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (config.dryRun) {
|
|
238
|
+
p.outro('🔍 Dry run complete - no files were modified');
|
|
239
|
+
} else {
|
|
240
|
+
p.outro(MESSAGES.outro.success);
|
|
241
|
+
}
|
|
242
|
+
} catch (error) {
|
|
243
|
+
p.log.error(`Error: ${String(error)}`);
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
program
|
|
249
|
+
.command('use-fetch')
|
|
250
|
+
.description('Generate Nuxt useFetch composables from OpenAPI generated files')
|
|
251
|
+
.option('-i, --input <path>', 'OpenAPI generated files directory')
|
|
252
|
+
.option('-o, --output <path>', 'Output directory for composables')
|
|
253
|
+
.action(async (options: { input?: string; output?: string }) => {
|
|
254
|
+
if (!options.input || !options.output) {
|
|
255
|
+
p.log.error('Error: You must provide both --input and --output');
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
await generateUseFetchComposables(options.input, options.output);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
p.log.error(`Error: ${String(error)}`);
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
program
|
|
267
|
+
.command('connectors')
|
|
268
|
+
.description('Generate headless connector composables from an OpenAPI spec')
|
|
269
|
+
.requiredOption('-i, --input <path>', 'Path to OpenAPI YAML or JSON spec')
|
|
270
|
+
.requiredOption('-o, --output <path>', 'Output directory for connector composables')
|
|
271
|
+
.option(
|
|
272
|
+
'--composables-dir <relPath>',
|
|
273
|
+
'Relative path from output dir to useAsyncData composables (default: ../use-async-data)'
|
|
274
|
+
)
|
|
275
|
+
.option(
|
|
276
|
+
'--runtime-dir <relPath>',
|
|
277
|
+
'Relative path from output dir where runtime helpers are copied (default: ../runtime)'
|
|
278
|
+
)
|
|
279
|
+
.action(
|
|
280
|
+
async (options: {
|
|
281
|
+
input: string;
|
|
282
|
+
output: string;
|
|
283
|
+
composablesDir?: string;
|
|
284
|
+
runtimeDir?: string;
|
|
285
|
+
}) => {
|
|
286
|
+
try {
|
|
287
|
+
displayLogo();
|
|
288
|
+
p.intro('Generating connector composables…');
|
|
289
|
+
await generateConnectors({
|
|
290
|
+
inputSpec: options.input,
|
|
291
|
+
outputDir: options.output,
|
|
292
|
+
composablesRelDir: options.composablesDir,
|
|
293
|
+
runtimeRelDir: options.runtimeDir,
|
|
294
|
+
});
|
|
295
|
+
p.outro('Done!');
|
|
296
|
+
} catch (error) {
|
|
297
|
+
p.log.error(`Error: ${String(error)}`);
|
|
298
|
+
process.exit(1);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
program.parse();
|