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