nuxt-openapi-hyperfetch 0.1.0-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 -0
- package/.prettierignore +17 -0
- package/.prettierrc.json +12 -0
- package/CONTRIBUTING.md +292 -0
- package/INSTRUCTIONS.md +327 -0
- package/LICENSE +202 -0
- package/README.md +202 -0
- package/dist/cli/config.d.ts +57 -0
- package/dist/cli/config.js +85 -0
- package/dist/cli/logger.d.ts +44 -0
- package/dist/cli/logger.js +58 -0
- package/dist/cli/logo.d.ts +6 -0
- package/dist/cli/logo.js +21 -0
- package/dist/cli/messages.d.ts +65 -0
- package/dist/cli/messages.js +86 -0
- package/dist/cli/prompts.d.ts +30 -0
- package/dist/cli/prompts.js +118 -0
- package/dist/cli/types.d.ts +43 -0
- package/dist/cli/types.js +4 -0
- package/dist/cli/utils.d.ts +26 -0
- package/dist/cli/utils.js +45 -0
- package/dist/generate.d.ts +6 -0
- package/dist/generate.js +48 -0
- package/dist/generators/nuxt-server/bff-templates.d.ts +25 -0
- package/dist/generators/nuxt-server/bff-templates.js +737 -0
- package/dist/generators/nuxt-server/generator.d.ts +7 -0
- package/dist/generators/nuxt-server/generator.js +206 -0
- package/dist/generators/nuxt-server/parser.d.ts +5 -0
- package/dist/generators/nuxt-server/parser.js +5 -0
- package/dist/generators/nuxt-server/templates.d.ts +35 -0
- package/dist/generators/nuxt-server/templates.js +412 -0
- package/dist/generators/nuxt-server/types.d.ts +5 -0
- package/dist/generators/nuxt-server/types.js +5 -0
- package/dist/generators/shared/parsers/heyapi-parser.d.ts +11 -0
- package/dist/generators/shared/parsers/heyapi-parser.js +248 -0
- package/dist/generators/shared/parsers/official-parser.d.ts +5 -0
- package/dist/generators/shared/parsers/official-parser.js +5 -0
- package/dist/generators/shared/runtime/apiHelpers.d.ts +183 -0
- package/dist/generators/shared/runtime/apiHelpers.js +268 -0
- package/dist/generators/shared/templates/api-callbacks-plugin.d.ts +178 -0
- package/dist/generators/shared/templates/api-callbacks-plugin.js +338 -0
- package/dist/generators/shared/types.d.ts +25 -0
- package/dist/generators/shared/types.js +4 -0
- package/dist/generators/tanstack-query/generator.d.ts +5 -0
- package/dist/generators/tanstack-query/generator.js +11 -0
- package/dist/generators/use-async-data/generator.d.ts +5 -0
- package/dist/generators/use-async-data/generator.js +156 -0
- package/dist/generators/use-async-data/parser.d.ts +5 -0
- package/dist/generators/use-async-data/parser.js +5 -0
- package/dist/generators/use-async-data/runtime/useApiAsyncData.d.ts +38 -0
- package/dist/generators/use-async-data/runtime/useApiAsyncData.js +122 -0
- package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.d.ts +54 -0
- package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.js +126 -0
- package/dist/generators/use-async-data/templates.d.ts +20 -0
- package/dist/generators/use-async-data/templates.js +191 -0
- package/dist/generators/use-async-data/types.d.ts +4 -0
- package/dist/generators/use-async-data/types.js +4 -0
- package/dist/generators/use-fetch/generator.d.ts +5 -0
- package/dist/generators/use-fetch/generator.js +131 -0
- package/dist/generators/use-fetch/parser.d.ts +9 -0
- package/dist/generators/use-fetch/parser.js +282 -0
- package/dist/generators/use-fetch/runtime/useApiRequest.d.ts +46 -0
- package/dist/generators/use-fetch/runtime/useApiRequest.js +158 -0
- package/dist/generators/use-fetch/templates.d.ts +16 -0
- package/dist/generators/use-fetch/templates.js +169 -0
- package/dist/generators/use-fetch/types.d.ts +5 -0
- package/dist/generators/use-fetch/types.js +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +213 -0
- package/docs/API-REFERENCE.md +887 -0
- package/docs/ARCHITECTURE.md +649 -0
- package/docs/DEVELOPMENT.md +918 -0
- package/docs/QUICK-START.md +323 -0
- package/docs/README.md +155 -0
- package/docs/TROUBLESHOOTING.md +881 -0
- package/eslint.config.js +72 -0
- package/package.json +65 -0
- package/src/cli/config.ts +140 -0
- package/src/cli/logger.ts +66 -0
- package/src/cli/logo.ts +25 -0
- package/src/cli/messages.ts +97 -0
- package/src/cli/prompts.ts +143 -0
- package/src/cli/types.ts +50 -0
- package/src/cli/utils.ts +49 -0
- package/src/generate.ts +57 -0
- package/src/generators/nuxt-server/bff-templates.ts +754 -0
- package/src/generators/nuxt-server/generator.ts +270 -0
- package/src/generators/nuxt-server/parser.ts +5 -0
- package/src/generators/nuxt-server/templates.ts +483 -0
- package/src/generators/nuxt-server/types.ts +5 -0
- package/src/generators/shared/parsers/heyapi-parser.ts +307 -0
- package/src/generators/shared/parsers/official-parser.ts +5 -0
- package/src/generators/shared/runtime/apiHelpers.ts +466 -0
- package/src/generators/shared/templates/api-callbacks-plugin.ts +352 -0
- package/src/generators/shared/types.ts +27 -0
- package/src/generators/tanstack-query/generator.ts +11 -0
- package/src/generators/use-async-data/generator.ts +204 -0
- package/src/generators/use-async-data/parser.ts +5 -0
- package/src/generators/use-async-data/runtime/useApiAsyncData.ts +220 -0
- package/src/generators/use-async-data/runtime/useApiAsyncDataRaw.ts +236 -0
- package/src/generators/use-async-data/templates.ts +250 -0
- package/src/generators/use-async-data/types.ts +4 -0
- package/src/generators/use-fetch/generator.ts +169 -0
- package/src/generators/use-fetch/parser.ts +341 -0
- package/src/generators/use-fetch/runtime/useApiRequest.ts +223 -0
- package/src/generators/use-fetch/templates.ts +214 -0
- package/src/generators/use-fetch/types.ts +5 -0
- package/src/index.ts +265 -0
- package/tsconfig.json +15 -0
package/eslint.config.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import eslint from '@eslint/js';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
import prettierConfig from 'eslint-config-prettier';
|
|
5
|
+
import prettierPlugin from 'eslint-plugin-prettier';
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
eslint.configs.recommended,
|
|
9
|
+
...tseslint.configs.recommendedTypeChecked,
|
|
10
|
+
prettierConfig,
|
|
11
|
+
{
|
|
12
|
+
plugins: {
|
|
13
|
+
prettier: prettierPlugin,
|
|
14
|
+
},
|
|
15
|
+
languageOptions: {
|
|
16
|
+
parserOptions: {
|
|
17
|
+
project: './tsconfig.json',
|
|
18
|
+
tsconfigRootDir: import.meta.dirname,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
rules: {
|
|
22
|
+
'prettier/prettier': 'error',
|
|
23
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
24
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
25
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
26
|
+
'@typescript-eslint/no-unused-vars': [
|
|
27
|
+
'error',
|
|
28
|
+
{
|
|
29
|
+
argsIgnorePattern: '^_',
|
|
30
|
+
varsIgnorePattern: '^_',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
34
|
+
'@typescript-eslint/no-misused-promises': 'error',
|
|
35
|
+
'@typescript-eslint/no-unsafe-assignment': 'warn',
|
|
36
|
+
'@typescript-eslint/no-unsafe-member-access': 'warn',
|
|
37
|
+
'@typescript-eslint/no-unsafe-call': 'warn',
|
|
38
|
+
'@typescript-eslint/no-unsafe-return': 'warn',
|
|
39
|
+
'@typescript-eslint/no-unsafe-argument': 'warn',
|
|
40
|
+
'@typescript-eslint/restrict-template-expressions': 'warn',
|
|
41
|
+
'@typescript-eslint/ban-ts-comment': [
|
|
42
|
+
'error',
|
|
43
|
+
{
|
|
44
|
+
'ts-nocheck': 'allow-with-description',
|
|
45
|
+
minimumDescriptionLength: 10,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
'no-console': 'off',
|
|
49
|
+
'prefer-const': 'error',
|
|
50
|
+
'no-var': 'error',
|
|
51
|
+
'no-useless-escape': 'warn',
|
|
52
|
+
eqeqeq: ['error', 'always'],
|
|
53
|
+
curly: ['error', 'all'],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
ignores: [
|
|
58
|
+
'dist/**',
|
|
59
|
+
'node_modules/**',
|
|
60
|
+
'swagger/**',
|
|
61
|
+
'test-*/**',
|
|
62
|
+
'index.ts',
|
|
63
|
+
// Ignore runtime files - they run in user's project with different rules
|
|
64
|
+
'src/generators/*/runtime/**',
|
|
65
|
+
'src/generators/shared/runtime/**',
|
|
66
|
+
'src/generators/shared/templates/**',
|
|
67
|
+
'*.js',
|
|
68
|
+
'*.mjs',
|
|
69
|
+
'*.cjs',
|
|
70
|
+
],
|
|
71
|
+
}
|
|
72
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nuxt-openapi-hyperfetch",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Nuxt useFetch, useAsyncData and Nuxt server OpenAPI generator",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"docs",
|
|
12
|
+
"src",
|
|
13
|
+
".editorconfig",
|
|
14
|
+
".prettierignore",
|
|
15
|
+
".prettierrc.json",
|
|
16
|
+
"CONTRIBUTING.md",
|
|
17
|
+
"eslint.config.js",
|
|
18
|
+
"index.ts",
|
|
19
|
+
"INSTRUCTIONS.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"README.md",
|
|
22
|
+
"tsconfig.json"
|
|
23
|
+
],
|
|
24
|
+
"bin": {
|
|
25
|
+
"nxh": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"start": "tsc && node ./dist/index.js",
|
|
30
|
+
"generator": "nxh generate -i ./swagger.yaml -o ./swagger",
|
|
31
|
+
"lint": "eslint . --ext .ts",
|
|
32
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
33
|
+
"format": "prettier --write \"**/*.{ts,json,md,yaml,yml}\"",
|
|
34
|
+
"format:check": "prettier --check \"**/*.{ts,json,md,yaml,yml}\"",
|
|
35
|
+
"type-check": "tsc --noEmit",
|
|
36
|
+
"validate": "npm run type-check && npm run lint && npm run format:check"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@eslint/js": "^10.0.1",
|
|
40
|
+
"@types/fs-extra": "^11.0.4",
|
|
41
|
+
"@types/gradient-string": "^1.1.6",
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
|
44
|
+
"@typescript-eslint/parser": "^8.57.1",
|
|
45
|
+
"eslint": "^10.1.0",
|
|
46
|
+
"eslint-config-prettier": "^10.1.8",
|
|
47
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
48
|
+
"ts-node": "^10.9.2",
|
|
49
|
+
"typescript": "^5.9.3",
|
|
50
|
+
"typescript-eslint": "^8.57.1"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@clack/prompts": "^1.1.0",
|
|
54
|
+
"@hey-api/openapi-ts": "0.94.4",
|
|
55
|
+
"@openapitools/openapi-generator-cli": "2.30.2",
|
|
56
|
+
"change-case": "^5.4.4",
|
|
57
|
+
"commander": "^14.0.3",
|
|
58
|
+
"fs-extra": "^11.3.4",
|
|
59
|
+
"globby": "^16.1.1",
|
|
60
|
+
"gradient-string": "^3.0.0",
|
|
61
|
+
"prettier": "^3.8.1",
|
|
62
|
+
"ts-morph": "^27.0.2"
|
|
63
|
+
},
|
|
64
|
+
"keywords": []
|
|
65
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,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
|
+
}
|
package/src/cli/logo.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import gradient from 'gradient-string';
|
|
2
|
+
|
|
3
|
+
const NUXT_LOGO = `███╗ ██╗██╗ ██╗██╗ ██╗████████╗
|
|
4
|
+
████╗ ██║██║ ██║╚██╗██╔╝╚══██╔══╝
|
|
5
|
+
██╔██╗ ██║██║ ██║ ╚███╔╝ ██║
|
|
6
|
+
██║╚██╗██║██║ ██║ ██╔██╗ ██║
|
|
7
|
+
██║ ╚████║╚██████╔╝██╔╝ ██╗ ██║
|
|
8
|
+
╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝`;
|
|
9
|
+
|
|
10
|
+
const SUBTITLE = ' Swagger OpenAPI Generator v1.0';
|
|
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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized messages and text content for CLI
|
|
3
|
+
*/
|
|
4
|
+
import type { GeneratorBackend } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Main messages used throughout the CLI
|
|
8
|
+
*/
|
|
9
|
+
export const MESSAGES = {
|
|
10
|
+
// Intro/Outro messages
|
|
11
|
+
intro: '🎨 Nuxt Swagger Generator',
|
|
12
|
+
outro: {
|
|
13
|
+
success: '🎉 All done! Your files are ready.',
|
|
14
|
+
cancelled: '👋 Operation cancelled.',
|
|
15
|
+
noComposables: '✓ OpenAPI files generated successfully!\nNo composables selected.',
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
// Prompt messages
|
|
19
|
+
prompts: {
|
|
20
|
+
selectBackend: 'Select the OpenAPI code generator:',
|
|
21
|
+
inputPath: 'Enter the path to your OpenAPI/Swagger file:',
|
|
22
|
+
outputPath: 'Enter the output directory for generated files:',
|
|
23
|
+
selectComposables: 'Select which composables you want to generate:',
|
|
24
|
+
serverPath: 'Where do you want to generate server routes?',
|
|
25
|
+
customPath: 'Enter custom server route path:',
|
|
26
|
+
enableBff: 'Enable BFF (Backend for Frontend) with transformers and auth?',
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
// Process step messages
|
|
30
|
+
steps: {
|
|
31
|
+
generatingOpenApi: 'Generating OpenAPI files',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Predefined choices for select/multiselect prompts
|
|
37
|
+
*/
|
|
38
|
+
export const CHOICES = {
|
|
39
|
+
// Generator backend options
|
|
40
|
+
backends: [
|
|
41
|
+
{
|
|
42
|
+
value: 'official' as const,
|
|
43
|
+
label: 'OpenAPI Generator (official)',
|
|
44
|
+
hint: 'Requires Java 11+',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
value: 'heyapi' as const,
|
|
48
|
+
label: '@hey-api/openapi-ts (Node.js)',
|
|
49
|
+
hint: 'No Java required',
|
|
50
|
+
},
|
|
51
|
+
] satisfies { value: GeneratorBackend; label: string; hint: string }[],
|
|
52
|
+
|
|
53
|
+
// Composables selection
|
|
54
|
+
composables: [
|
|
55
|
+
{
|
|
56
|
+
value: 'useFetch',
|
|
57
|
+
label: 'useFetch - Nuxt useFetch composables',
|
|
58
|
+
hint: 'Recommended for most use cases',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
value: 'useAsyncData',
|
|
62
|
+
label: 'useAsyncData - Nuxt useAsyncData composables',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
value: 'nuxtServer',
|
|
66
|
+
label: 'Nuxt Server Routes - Generate server/api/* proxy routes',
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
|
|
70
|
+
// Server path options
|
|
71
|
+
serverPaths: [
|
|
72
|
+
{
|
|
73
|
+
value: 'server/api',
|
|
74
|
+
label: 'server/api (recommended)',
|
|
75
|
+
hint: 'Standard Nuxt server directory',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: 'src/server/api',
|
|
79
|
+
label: 'src/server/api',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: 'custom',
|
|
83
|
+
label: 'Custom path...',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Default values for prompts
|
|
90
|
+
*/
|
|
91
|
+
export const DEFAULTS = {
|
|
92
|
+
inputPath: './swagger.yaml',
|
|
93
|
+
outputPath: './swagger',
|
|
94
|
+
serverPath: 'server/api',
|
|
95
|
+
customPath: './server/api',
|
|
96
|
+
enableBff: true,
|
|
97
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All CLI prompts using @clack/prompts
|
|
3
|
+
* Each function handles a specific prompt flow and returns typed data
|
|
4
|
+
*/
|
|
5
|
+
import * as p from '@clack/prompts';
|
|
6
|
+
import { checkCancellation, validateNonEmpty } from './utils.js';
|
|
7
|
+
import { MESSAGES, CHOICES, DEFAULTS } from './messages.js';
|
|
8
|
+
import type {
|
|
9
|
+
InitialInputs,
|
|
10
|
+
ComposablesSelection,
|
|
11
|
+
BffConfig,
|
|
12
|
+
ComposableType,
|
|
13
|
+
GeneratorBackend,
|
|
14
|
+
} from './types.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Ask which OpenAPI generator backend to use
|
|
18
|
+
*/
|
|
19
|
+
export async function promptGeneratorBackend(
|
|
20
|
+
provided?: GeneratorBackend
|
|
21
|
+
): Promise<GeneratorBackend> {
|
|
22
|
+
if (provided) {
|
|
23
|
+
return provided;
|
|
24
|
+
}
|
|
25
|
+
const result = await p.select({
|
|
26
|
+
message: MESSAGES.prompts.selectBackend,
|
|
27
|
+
options: CHOICES.backends,
|
|
28
|
+
initialValue: 'official' as const,
|
|
29
|
+
});
|
|
30
|
+
checkCancellation(result);
|
|
31
|
+
return result as GeneratorBackend;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Ask for input and output paths
|
|
36
|
+
* Only asks for paths that weren't provided via CLI arguments
|
|
37
|
+
*/
|
|
38
|
+
export async function promptInitialInputs(
|
|
39
|
+
inputProvided?: string,
|
|
40
|
+
outputProvided?: string
|
|
41
|
+
): Promise<InitialInputs> {
|
|
42
|
+
let inputPath = inputProvided;
|
|
43
|
+
let outputPath = outputProvided;
|
|
44
|
+
|
|
45
|
+
// Ask for input path if not provided
|
|
46
|
+
if (!inputPath) {
|
|
47
|
+
const result = await p.text({
|
|
48
|
+
message: MESSAGES.prompts.inputPath,
|
|
49
|
+
placeholder: DEFAULTS.inputPath,
|
|
50
|
+
defaultValue: DEFAULTS.inputPath,
|
|
51
|
+
});
|
|
52
|
+
checkCancellation(result);
|
|
53
|
+
inputPath = result as string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Ask for output path if not provided
|
|
57
|
+
if (!outputPath) {
|
|
58
|
+
const result = await p.text({
|
|
59
|
+
message: MESSAGES.prompts.outputPath,
|
|
60
|
+
placeholder: DEFAULTS.outputPath,
|
|
61
|
+
defaultValue: DEFAULTS.outputPath,
|
|
62
|
+
});
|
|
63
|
+
checkCancellation(result);
|
|
64
|
+
outputPath = result as string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { inputPath, outputPath };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Ask for the input path only (used when only nuxtServer is selected)
|
|
72
|
+
*/
|
|
73
|
+
export async function promptInputPath(provided?: string): Promise<string> {
|
|
74
|
+
if (provided) {
|
|
75
|
+
return provided;
|
|
76
|
+
}
|
|
77
|
+
const result = await p.text({
|
|
78
|
+
message: MESSAGES.prompts.inputPath,
|
|
79
|
+
placeholder: DEFAULTS.inputPath,
|
|
80
|
+
defaultValue: DEFAULTS.inputPath,
|
|
81
|
+
});
|
|
82
|
+
checkCancellation(result);
|
|
83
|
+
return result as string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Ask which composables to generate (multiselect)
|
|
88
|
+
* Allows user to select none, one, or multiple composables
|
|
89
|
+
*/
|
|
90
|
+
export async function promptComposablesSelection(): Promise<ComposablesSelection> {
|
|
91
|
+
const result = await p.multiselect({
|
|
92
|
+
message: MESSAGES.prompts.selectComposables,
|
|
93
|
+
options: CHOICES.composables,
|
|
94
|
+
initialValues: ['useFetch'], // useFetch checked by default
|
|
95
|
+
required: false, // Allow empty selection
|
|
96
|
+
});
|
|
97
|
+
checkCancellation(result);
|
|
98
|
+
|
|
99
|
+
return { composables: result as ComposableType[] };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Ask for server route path
|
|
104
|
+
* If user selects 'custom', prompts for custom path
|
|
105
|
+
* Returns the final path to use
|
|
106
|
+
*/
|
|
107
|
+
export async function promptServerRoutePath(): Promise<string> {
|
|
108
|
+
// First, ask for the path type
|
|
109
|
+
const pathResult = await p.select({
|
|
110
|
+
message: MESSAGES.prompts.serverPath,
|
|
111
|
+
options: CHOICES.serverPaths,
|
|
112
|
+
initialValue: DEFAULTS.serverPath,
|
|
113
|
+
});
|
|
114
|
+
checkCancellation(pathResult);
|
|
115
|
+
|
|
116
|
+
// If custom selected, ask for custom path
|
|
117
|
+
if (pathResult === 'custom') {
|
|
118
|
+
const customResult = await p.text({
|
|
119
|
+
message: MESSAGES.prompts.customPath,
|
|
120
|
+
placeholder: DEFAULTS.customPath,
|
|
121
|
+
defaultValue: DEFAULTS.customPath,
|
|
122
|
+
validate: validateNonEmpty,
|
|
123
|
+
});
|
|
124
|
+
checkCancellation(customResult);
|
|
125
|
+
return customResult as string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return pathResult as string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Ask about BFF (Backend for Frontend) support
|
|
133
|
+
* Returns whether BFF should be enabled
|
|
134
|
+
*/
|
|
135
|
+
export async function promptBffConfig(): Promise<BffConfig> {
|
|
136
|
+
const result = await p.confirm({
|
|
137
|
+
message: MESSAGES.prompts.enableBff,
|
|
138
|
+
initialValue: DEFAULTS.enableBff,
|
|
139
|
+
});
|
|
140
|
+
checkCancellation(result);
|
|
141
|
+
|
|
142
|
+
return { enableBff: result as boolean };
|
|
143
|
+
}
|
package/src/cli/types.ts
ADDED
|
@@ -0,0 +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';
|