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/cli/config.ts
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import * as p from '@clack/prompts';
|
|
4
|
-
import type { GeneratorBackend, ConfigGenerator } from './types.js';
|
|
5
|
-
|
|
6
|
-
const { existsSync } = fs;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Configuration options for the generator
|
|
10
|
-
*/
|
|
11
|
-
export interface GeneratorConfig {
|
|
12
|
-
/** Path or URL to OpenAPI specification */
|
|
13
|
-
input?: string;
|
|
14
|
-
/** Output directory for generated files */
|
|
15
|
-
output?: string;
|
|
16
|
-
/** Base URL for API requests */
|
|
17
|
-
baseUrl?: string;
|
|
18
|
-
/** Generation mode: client or server */
|
|
19
|
-
mode?: 'client' | 'server';
|
|
20
|
-
/** Generate only specific tags */
|
|
21
|
-
tags?: string[];
|
|
22
|
-
/** Exclude specific tags */
|
|
23
|
-
excludeTags?: string[];
|
|
24
|
-
/** Overwrite existing files without prompting */
|
|
25
|
-
overwrite?: boolean;
|
|
26
|
-
/** Preview changes without writing files */
|
|
27
|
-
dryRun?: boolean;
|
|
28
|
-
/** Enable verbose logging */
|
|
29
|
-
verbose?: boolean;
|
|
30
|
-
/** Watch mode - regenerate on file changes */
|
|
31
|
-
watch?: boolean;
|
|
32
|
-
/** Generator types to use */
|
|
33
|
-
generators?: ('useFetch' | 'useAsyncData' | 'nuxtServer')[];
|
|
34
|
-
/** Server route path (for nuxtServer mode) */
|
|
35
|
-
serverRoutePath?: string;
|
|
36
|
-
/** Enable BFF pattern (for nuxtServer mode) */
|
|
37
|
-
enableBff?: boolean;
|
|
38
|
-
/** Generator backend: official (Java) or heyapi (Node.js) */
|
|
39
|
-
backend?: GeneratorBackend;
|
|
40
|
-
/**
|
|
41
|
-
* Generation engine to use.
|
|
42
|
-
* - 'openapi': @openapitools/openapi-generator-cli (requires Java 11+)
|
|
43
|
-
* - 'heyapi': @hey-api/openapi-ts (Node.js native, no Java required)
|
|
44
|
-
* When set, the CLI will not ask which engine to use.
|
|
45
|
-
*/
|
|
46
|
-
generator?: ConfigGenerator;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Load configuration from nxh.config.js, nuxt-openapi-generator.config.js, or package.json
|
|
51
|
-
*/
|
|
52
|
-
export async function loadConfig(cwd: string = process.cwd()): Promise<GeneratorConfig | null> {
|
|
53
|
-
// Try different config file names
|
|
54
|
-
const configFiles = [
|
|
55
|
-
'nxh.config.js',
|
|
56
|
-
'nxh.config.mjs',
|
|
57
|
-
'nuxt-openapi-hyperfetch.js',
|
|
58
|
-
'nuxt-openapi-hyperfetch.mjs',
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
for (const configFile of configFiles) {
|
|
62
|
-
const configPath = join(cwd, configFile);
|
|
63
|
-
if (existsSync(configPath)) {
|
|
64
|
-
try {
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
66
|
-
const config = await import(`file://${configPath}`);
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
68
|
-
const exportedConfig = config.default || config;
|
|
69
|
-
return exportedConfig as GeneratorConfig;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
p.log.warn(`Failed to load config from ${configFile}: ${String(error)}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Try package.json
|
|
77
|
-
const packageJsonPath = join(cwd, 'package.json');
|
|
78
|
-
if (existsSync(packageJsonPath)) {
|
|
79
|
-
try {
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
81
|
-
const packageJson = await import(`file://${packageJsonPath}`, {
|
|
82
|
-
assert: { type: 'json' },
|
|
83
|
-
});
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
85
|
-
if (packageJson.default?.['nuxt-openapi-hyperfetch']) {
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
87
|
-
return packageJson.default['nuxt-openapi-hyperfetch'] as GeneratorConfig;
|
|
88
|
-
}
|
|
89
|
-
} catch {
|
|
90
|
-
// Silently ignore package.json errors
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Merge CLI options with config file, CLI takes precedence
|
|
99
|
-
*/
|
|
100
|
-
export function mergeConfig(
|
|
101
|
-
fileConfig: GeneratorConfig | null,
|
|
102
|
-
cliOptions: Partial<GeneratorConfig>
|
|
103
|
-
): GeneratorConfig {
|
|
104
|
-
return {
|
|
105
|
-
...fileConfig,
|
|
106
|
-
...cliOptions,
|
|
107
|
-
// Handle arrays specially - CLI should override completely
|
|
108
|
-
tags: cliOptions.tags || fileConfig?.tags,
|
|
109
|
-
excludeTags: cliOptions.excludeTags || fileConfig?.excludeTags,
|
|
110
|
-
generators: cliOptions.generators || fileConfig?.generators,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Parse comma-separated tags string into array
|
|
116
|
-
*/
|
|
117
|
-
export function parseTags(tagsString?: string): string[] | undefined {
|
|
118
|
-
if (!tagsString) {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
return tagsString
|
|
122
|
-
.split(',')
|
|
123
|
-
.map((t) => t.trim())
|
|
124
|
-
.filter(Boolean);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Parse generators string into array
|
|
129
|
-
*/
|
|
130
|
-
export function parseGenerators(
|
|
131
|
-
generatorsString?: string
|
|
132
|
-
): ('useFetch' | 'useAsyncData' | 'nuxtServer')[] | undefined {
|
|
133
|
-
if (!generatorsString) {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
const parts = generatorsString.split(',').map((g) => g.trim());
|
|
137
|
-
return parts.filter((g): g is 'useFetch' | 'useAsyncData' | 'nuxtServer' =>
|
|
138
|
-
['useFetch', 'useAsyncData', 'nuxtServer'].includes(g)
|
|
139
|
-
);
|
|
140
|
-
}
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import * as p from '@clack/prompts';
|
|
4
|
+
import type { GeneratorBackend, ConfigGenerator } from './types.js';
|
|
5
|
+
|
|
6
|
+
const { existsSync } = fs;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Configuration options for the generator
|
|
10
|
+
*/
|
|
11
|
+
export interface GeneratorConfig {
|
|
12
|
+
/** Path or URL to OpenAPI specification */
|
|
13
|
+
input?: string;
|
|
14
|
+
/** Output directory for generated files */
|
|
15
|
+
output?: string;
|
|
16
|
+
/** Base URL for API requests */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Generation mode: client or server */
|
|
19
|
+
mode?: 'client' | 'server';
|
|
20
|
+
/** Generate only specific tags */
|
|
21
|
+
tags?: string[];
|
|
22
|
+
/** Exclude specific tags */
|
|
23
|
+
excludeTags?: string[];
|
|
24
|
+
/** Overwrite existing files without prompting */
|
|
25
|
+
overwrite?: boolean;
|
|
26
|
+
/** Preview changes without writing files */
|
|
27
|
+
dryRun?: boolean;
|
|
28
|
+
/** Enable verbose logging */
|
|
29
|
+
verbose?: boolean;
|
|
30
|
+
/** Watch mode - regenerate on file changes */
|
|
31
|
+
watch?: boolean;
|
|
32
|
+
/** Generator types to use */
|
|
33
|
+
generators?: ('useFetch' | 'useAsyncData' | 'nuxtServer')[];
|
|
34
|
+
/** Server route path (for nuxtServer mode) */
|
|
35
|
+
serverRoutePath?: string;
|
|
36
|
+
/** Enable BFF pattern (for nuxtServer mode) */
|
|
37
|
+
enableBff?: boolean;
|
|
38
|
+
/** Generator backend: official (Java) or heyapi (Node.js) */
|
|
39
|
+
backend?: GeneratorBackend;
|
|
40
|
+
/**
|
|
41
|
+
* Generation engine to use.
|
|
42
|
+
* - 'openapi': @openapitools/openapi-generator-cli (requires Java 11+)
|
|
43
|
+
* - 'heyapi': @hey-api/openapi-ts (Node.js native, no Java required)
|
|
44
|
+
* When set, the CLI will not ask which engine to use.
|
|
45
|
+
*/
|
|
46
|
+
generator?: ConfigGenerator;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Load configuration from nxh.config.js, nuxt-openapi-generator.config.js, or package.json
|
|
51
|
+
*/
|
|
52
|
+
export async function loadConfig(cwd: string = process.cwd()): Promise<GeneratorConfig | null> {
|
|
53
|
+
// Try different config file names
|
|
54
|
+
const configFiles = [
|
|
55
|
+
'nxh.config.js',
|
|
56
|
+
'nxh.config.mjs',
|
|
57
|
+
'nuxt-openapi-hyperfetch.js',
|
|
58
|
+
'nuxt-openapi-hyperfetch.mjs',
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
for (const configFile of configFiles) {
|
|
62
|
+
const configPath = join(cwd, configFile);
|
|
63
|
+
if (existsSync(configPath)) {
|
|
64
|
+
try {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
66
|
+
const config = await import(`file://${configPath}`);
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
68
|
+
const exportedConfig = config.default || config;
|
|
69
|
+
return exportedConfig as GeneratorConfig;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
p.log.warn(`Failed to load config from ${configFile}: ${String(error)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Try package.json
|
|
77
|
+
const packageJsonPath = join(cwd, 'package.json');
|
|
78
|
+
if (existsSync(packageJsonPath)) {
|
|
79
|
+
try {
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
81
|
+
const packageJson = await import(`file://${packageJsonPath}`, {
|
|
82
|
+
assert: { type: 'json' },
|
|
83
|
+
});
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
85
|
+
if (packageJson.default?.['nuxt-openapi-hyperfetch']) {
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
87
|
+
return packageJson.default['nuxt-openapi-hyperfetch'] as GeneratorConfig;
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
// Silently ignore package.json errors
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Merge CLI options with config file, CLI takes precedence
|
|
99
|
+
*/
|
|
100
|
+
export function mergeConfig(
|
|
101
|
+
fileConfig: GeneratorConfig | null,
|
|
102
|
+
cliOptions: Partial<GeneratorConfig>
|
|
103
|
+
): GeneratorConfig {
|
|
104
|
+
return {
|
|
105
|
+
...fileConfig,
|
|
106
|
+
...cliOptions,
|
|
107
|
+
// Handle arrays specially - CLI should override completely
|
|
108
|
+
tags: cliOptions.tags || fileConfig?.tags,
|
|
109
|
+
excludeTags: cliOptions.excludeTags || fileConfig?.excludeTags,
|
|
110
|
+
generators: cliOptions.generators || fileConfig?.generators,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Parse comma-separated tags string into array
|
|
116
|
+
*/
|
|
117
|
+
export function parseTags(tagsString?: string): string[] | undefined {
|
|
118
|
+
if (!tagsString) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return tagsString
|
|
122
|
+
.split(',')
|
|
123
|
+
.map((t) => t.trim())
|
|
124
|
+
.filter(Boolean);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Parse generators string into array
|
|
129
|
+
*/
|
|
130
|
+
export function parseGenerators(
|
|
131
|
+
generatorsString?: string
|
|
132
|
+
): ('useFetch' | 'useAsyncData' | 'nuxtServer')[] | undefined {
|
|
133
|
+
if (!generatorsString) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
const parts = generatorsString.split(',').map((g) => g.trim());
|
|
137
|
+
return parts.filter((g): g is 'useFetch' | 'useAsyncData' | 'nuxtServer' =>
|
|
138
|
+
['useFetch', 'useAsyncData', 'nuxtServer'].includes(g)
|
|
139
|
+
);
|
|
140
|
+
}
|
package/src/cli/logger.ts
CHANGED
|
@@ -1,66 +1,124 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized logging utilities using @clack/prompts
|
|
3
|
-
* Re-exports @clack for easy use across the project
|
|
4
|
-
*/
|
|
5
|
-
import * as p from '@clack/prompts';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Re-export @clack/prompts for consistent usage
|
|
9
|
-
*/
|
|
10
|
-
export { p };
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create and manage a spinner for long operations
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* const spinner = createSpinner();
|
|
17
|
-
* spinner.start('Processing files');
|
|
18
|
-
* // do work
|
|
19
|
-
* spinner.stop('Files processed');
|
|
20
|
-
*/
|
|
21
|
-
export function createSpinner() {
|
|
22
|
-
return p.spinner();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Log a success message (replaces console.log with ✓)
|
|
27
|
-
*/
|
|
28
|
-
export function logSuccess(message: string) {
|
|
29
|
-
p.log.success(message);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Log an error message
|
|
34
|
-
*/
|
|
35
|
-
export function logError(message: string) {
|
|
36
|
-
p.log.error(message);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Log a warning message
|
|
41
|
-
*/
|
|
42
|
-
export function logWarning(message: string) {
|
|
43
|
-
p.log.warn(message);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Log an info message
|
|
48
|
-
*/
|
|
49
|
-
export function logInfo(message: string) {
|
|
50
|
-
p.log.info(message);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Display a note/box with multiple lines of information
|
|
55
|
-
* Great for "Next steps" sections
|
|
56
|
-
*/
|
|
57
|
-
export function logNote(message: string, title?: string) {
|
|
58
|
-
p.note(message, title);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Display section separator
|
|
63
|
-
*/
|
|
64
|
-
export function logStep(message: string) {
|
|
65
|
-
p.log.step(message);
|
|
66
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Centralized logging utilities using @clack/prompts
|
|
3
|
+
* Re-exports @clack for easy use across the project
|
|
4
|
+
*/
|
|
5
|
+
import * as p from '@clack/prompts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Re-export @clack/prompts for consistent usage
|
|
9
|
+
*/
|
|
10
|
+
export { p };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create and manage a spinner for long operations
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const spinner = createSpinner();
|
|
17
|
+
* spinner.start('Processing files');
|
|
18
|
+
* // do work
|
|
19
|
+
* spinner.stop('Files processed');
|
|
20
|
+
*/
|
|
21
|
+
export function createSpinner() {
|
|
22
|
+
return p.spinner();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Log a success message (replaces console.log with ✓)
|
|
27
|
+
*/
|
|
28
|
+
export function logSuccess(message: string) {
|
|
29
|
+
p.log.success(message);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Log an error message
|
|
34
|
+
*/
|
|
35
|
+
export function logError(message: string) {
|
|
36
|
+
p.log.error(message);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Log a warning message
|
|
41
|
+
*/
|
|
42
|
+
export function logWarning(message: string) {
|
|
43
|
+
p.log.warn(message);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Log an info message
|
|
48
|
+
*/
|
|
49
|
+
export function logInfo(message: string) {
|
|
50
|
+
p.log.info(message);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Display a note/box with multiple lines of information
|
|
55
|
+
* Great for "Next steps" sections
|
|
56
|
+
*/
|
|
57
|
+
export function logNote(message: string, title?: string) {
|
|
58
|
+
p.note(message, title);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Display section separator
|
|
63
|
+
*/
|
|
64
|
+
export function logStep(message: string) {
|
|
65
|
+
p.log.step(message);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// Logger abstraction — allows generators to run in both CLI and Nuxt module
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Abstract logger interface used by generators.
|
|
74
|
+
* Decouples generator output from @clack/prompts so the same generators work
|
|
75
|
+
* in the interactive CLI and in the Nuxt module (where clack is irrelevant).
|
|
76
|
+
*/
|
|
77
|
+
export interface Logger {
|
|
78
|
+
spinner(): { start(msg: string): void; stop(msg: string): void };
|
|
79
|
+
log: {
|
|
80
|
+
warn(msg: string): void;
|
|
81
|
+
info(msg: string): void;
|
|
82
|
+
success(msg: string): void;
|
|
83
|
+
error(msg: string): void;
|
|
84
|
+
};
|
|
85
|
+
note(msg: string, title?: string): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creates a Logger backed by @clack/prompts — used by the CLI.
|
|
90
|
+
*/
|
|
91
|
+
export function createClackLogger(): Logger {
|
|
92
|
+
return {
|
|
93
|
+
spinner: () => p.spinner(),
|
|
94
|
+
log: {
|
|
95
|
+
warn: (msg) => p.log.warn(msg),
|
|
96
|
+
info: (msg) => p.log.info(msg),
|
|
97
|
+
success: (msg) => p.log.success(msg),
|
|
98
|
+
error: (msg) => p.log.error(msg),
|
|
99
|
+
},
|
|
100
|
+
note: (msg, title) => p.note(msg, title),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates a Logger backed by console — used by the Nuxt module.
|
|
106
|
+
*/
|
|
107
|
+
export function createConsoleLogger(): Logger {
|
|
108
|
+
const prefix = '[nuxt-openapi-hyperfetch]';
|
|
109
|
+
return {
|
|
110
|
+
spinner() {
|
|
111
|
+
return {
|
|
112
|
+
start: (msg: string) => console.log(`${prefix} ⏳ ${msg}`),
|
|
113
|
+
stop: (msg: string) => console.log(`${prefix} ✓ ${msg}`),
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
log: {
|
|
117
|
+
warn: (msg) => console.warn(`${prefix} ⚠ ${msg}`),
|
|
118
|
+
info: (msg) => console.info(`${prefix} ℹ ${msg}`),
|
|
119
|
+
success: (msg) => console.log(`${prefix} ✓ ${msg}`),
|
|
120
|
+
error: (msg) => console.error(`${prefix} ✗ ${msg}`),
|
|
121
|
+
},
|
|
122
|
+
note: (msg, title) => console.log(title ? `\n${prefix} ${title}:\n${msg}\n` : `\n${msg}\n`),
|
|
123
|
+
};
|
|
124
|
+
}
|
package/src/cli/logo.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import gradient from 'gradient-string';
|
|
2
|
-
|
|
3
|
-
const NUXT_LOGO = `███╗ ██╗██╗ ██╗██╗ ██╗████████╗
|
|
4
|
-
████╗ ██║██║ ██║╚██╗██╔╝╚══██╔══╝
|
|
5
|
-
██╔██╗ ██║██║ ██║ ╚███╔╝ ██║
|
|
6
|
-
██║╚██╗██║██║ ██║ ██╔██╗ ██║
|
|
7
|
-
██║ ╚████║╚██████╔╝██╔╝ ██╗ ██║
|
|
8
|
-
╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝`;
|
|
9
|
-
|
|
10
|
-
const SUBTITLE = 'Nuxt OpenAPI Generator - useFetch, useAsyncData & Nuxt server';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Display the Nuxt logo with gradient colors
|
|
14
|
-
* - Green gradient for Nuxt logo (official Nuxt color #00DC82)
|
|
15
|
-
* - Blue gradient for Swagger subtitle
|
|
16
|
-
*/
|
|
17
|
-
export function displayLogo(): void {
|
|
18
|
-
const nuxtGradient = gradient('#00DC82', '#00E090');
|
|
19
|
-
const swaggerGradient = gradient('#3B82F6', '#0EA5E9');
|
|
20
|
-
|
|
21
|
-
console.log('\n');
|
|
22
|
-
console.log(nuxtGradient(NUXT_LOGO));
|
|
23
|
-
console.log(swaggerGradient(SUBTITLE));
|
|
24
|
-
console.log('\n');
|
|
25
|
-
}
|
|
1
|
+
import gradient from 'gradient-string';
|
|
2
|
+
|
|
3
|
+
const NUXT_LOGO = `███╗ ██╗██╗ ██╗██╗ ██╗████████╗
|
|
4
|
+
████╗ ██║██║ ██║╚██╗██╔╝╚══██╔══╝
|
|
5
|
+
██╔██╗ ██║██║ ██║ ╚███╔╝ ██║
|
|
6
|
+
██║╚██╗██║██║ ██║ ██╔██╗ ██║
|
|
7
|
+
██║ ╚████║╚██████╔╝██╔╝ ██╗ ██║
|
|
8
|
+
╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝`;
|
|
9
|
+
|
|
10
|
+
const SUBTITLE = 'Nuxt OpenAPI Generator - useFetch, useAsyncData & Nuxt server';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Display the Nuxt logo with gradient colors
|
|
14
|
+
* - Green gradient for Nuxt logo (official Nuxt color #00DC82)
|
|
15
|
+
* - Blue gradient for Swagger subtitle
|
|
16
|
+
*/
|
|
17
|
+
export function displayLogo(): void {
|
|
18
|
+
const nuxtGradient = gradient('#00DC82', '#00E090');
|
|
19
|
+
const swaggerGradient = gradient('#3B82F6', '#0EA5E9');
|
|
20
|
+
|
|
21
|
+
console.log('\n');
|
|
22
|
+
console.log(nuxtGradient(NUXT_LOGO));
|
|
23
|
+
console.log(swaggerGradient(SUBTITLE));
|
|
24
|
+
console.log('\n');
|
|
25
|
+
}
|
package/src/cli/types.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeScript types for CLI prompts and responses
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generator backend selector (internal)
|
|
7
|
-
*/
|
|
8
|
-
export type GeneratorBackend = 'official' | 'heyapi';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Generator engine value for nxh.config — user-facing alias
|
|
12
|
-
* 'openapi' maps to the official Java-based OpenAPI Generator
|
|
13
|
-
* 'heyapi' maps to @hey-api/openapi-ts (Node.js native)
|
|
14
|
-
*/
|
|
15
|
-
export type ConfigGenerator = 'openapi' | 'heyapi';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Initial input and output paths
|
|
19
|
-
*/
|
|
20
|
-
export interface InitialInputs {
|
|
21
|
-
inputPath: string;
|
|
22
|
-
outputPath: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Composables selection (checkbox response)
|
|
27
|
-
*/
|
|
28
|
-
export interface ComposablesSelection {
|
|
29
|
-
composables: Array<'useFetch' | 'useAsyncData' | 'nuxtServer'>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Server route path configuration
|
|
34
|
-
*/
|
|
35
|
-
export interface ServerRouteConfig {
|
|
36
|
-
serverPath: string;
|
|
37
|
-
customPath?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* BFF (Backend for Frontend) configuration
|
|
42
|
-
*/
|
|
43
|
-
export interface BffConfig {
|
|
44
|
-
enableBff: boolean;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Valid composable types
|
|
49
|
-
*/
|
|
50
|
-
export type ComposableType = 'useFetch' | 'useAsyncData' | 'nuxtServer';
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for CLI prompts and responses
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generator backend selector (internal)
|
|
7
|
+
*/
|
|
8
|
+
export type GeneratorBackend = 'official' | 'heyapi';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generator engine value for nxh.config — user-facing alias
|
|
12
|
+
* 'openapi' maps to the official Java-based OpenAPI Generator
|
|
13
|
+
* 'heyapi' maps to @hey-api/openapi-ts (Node.js native)
|
|
14
|
+
*/
|
|
15
|
+
export type ConfigGenerator = 'openapi' | 'heyapi';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Initial input and output paths
|
|
19
|
+
*/
|
|
20
|
+
export interface InitialInputs {
|
|
21
|
+
inputPath: string;
|
|
22
|
+
outputPath: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Composables selection (checkbox response)
|
|
27
|
+
*/
|
|
28
|
+
export interface ComposablesSelection {
|
|
29
|
+
composables: Array<'useFetch' | 'useAsyncData' | 'nuxtServer'>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Server route path configuration
|
|
34
|
+
*/
|
|
35
|
+
export interface ServerRouteConfig {
|
|
36
|
+
serverPath: string;
|
|
37
|
+
customPath?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* BFF (Backend for Frontend) configuration
|
|
42
|
+
*/
|
|
43
|
+
export interface BffConfig {
|
|
44
|
+
enableBff: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Valid composable types
|
|
49
|
+
*/
|
|
50
|
+
export type ComposableType = 'useFetch' | 'useAsyncData' | 'nuxtServer';
|