@signal24/vue-foundation 4.2.4 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/vite-plugins/vite-openapi-plugin.cli.js +11 -7
- package/dist/src/vite-plugins/vite-openapi-plugin.d.ts +3 -2
- package/dist/src/vite-plugins/vite-openapi-plugin.js +40 -12
- package/package.json +1 -1
- package/src/vite-plugins/vite-openapi-plugin.cli.ts +12 -9
- package/src/vite-plugins/vite-openapi-plugin.ts +44 -16
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
-
import {
|
|
4
|
-
if (
|
|
5
|
-
|
|
3
|
+
import { generateConfiguredOpenapiClients, generateOpenapiClient } from './vite-openapi-plugin.js';
|
|
4
|
+
if (process.argv[2]) {
|
|
5
|
+
if (process.argv[2] === '--help') {
|
|
6
|
+
throw new Error('Usage: vf-generate-openapi-client [<openapi-yaml-path> [<openapi-output-path>]]');
|
|
7
|
+
}
|
|
8
|
+
if (!existsSync(process.argv[2])) {
|
|
9
|
+
throw new Error(`OpenAPI YAML file not found: ${process.argv[2]}`);
|
|
10
|
+
}
|
|
11
|
+
await generateOpenapiClient(process.argv[2], process.argv[3]);
|
|
6
12
|
}
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
else {
|
|
14
|
+
generateConfiguredOpenapiClients();
|
|
9
15
|
}
|
|
10
|
-
loadOpenapiOverrides();
|
|
11
|
-
await generateOpenapiClient(process.argv[2], process.argv[3]);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function openapiClientGeneratorPlugin(
|
|
1
|
+
export declare function loadOpenapiConfig(): void;
|
|
2
|
+
export declare function openapiClientGeneratorPlugin(): {
|
|
3
3
|
name: string;
|
|
4
4
|
apply: 'serve';
|
|
5
5
|
buildStart(): void;
|
|
6
6
|
closeBundle(): void;
|
|
7
7
|
};
|
|
8
|
+
export declare function generateConfiguredOpenapiClients(): Promise<void>;
|
|
8
9
|
export declare function generateOpenapiClient(openapiYamlPath: string, outPath?: string): Promise<void>;
|
|
@@ -4,9 +4,27 @@ import { rm } from 'node:fs/promises';
|
|
|
4
4
|
import * as OpenAPI from 'openapi-typescript-codegen';
|
|
5
5
|
const DEFAULT_OUT_PATH = './src/openapi-client-generated';
|
|
6
6
|
let generatedHash = null;
|
|
7
|
+
let generatorMap = {};
|
|
7
8
|
let overridesMap = null;
|
|
8
9
|
let overridesInverseMap = null;
|
|
9
|
-
export function
|
|
10
|
+
export function loadOpenapiConfig() {
|
|
11
|
+
loadGeneratorMap();
|
|
12
|
+
loadOverridesMap();
|
|
13
|
+
}
|
|
14
|
+
function loadGeneratorMap() {
|
|
15
|
+
if (!existsSync('./openapi-specs.json')) {
|
|
16
|
+
console.error('openapi-specs.json not found. Cannot generate OpenAPI client.');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const specsContent = readFileSync('./openapi-specs.json', 'utf8');
|
|
21
|
+
generatorMap = JSON.parse(specsContent);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error('Failed to load openapi-specs.json:', e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function loadOverridesMap() {
|
|
10
28
|
if (!existsSync('./openapi-specs.dev.json')) {
|
|
11
29
|
return;
|
|
12
30
|
}
|
|
@@ -19,24 +37,31 @@ export function loadOpenapiOverrides() {
|
|
|
19
37
|
console.error('Failed to load openapi-specs.dev.json:', e);
|
|
20
38
|
}
|
|
21
39
|
}
|
|
22
|
-
export function openapiClientGeneratorPlugin(
|
|
23
|
-
let
|
|
40
|
+
export function openapiClientGeneratorPlugin() {
|
|
41
|
+
let generators = null;
|
|
24
42
|
return {
|
|
25
43
|
name: 'openapi-types-generator',
|
|
26
44
|
apply: 'serve',
|
|
27
45
|
buildStart() {
|
|
28
46
|
// apply a slight delay so any output doesn't get pushed off screen
|
|
29
47
|
setTimeout(() => {
|
|
30
|
-
|
|
31
|
-
generator = getGenerator(openapiYamlPath, outPath);
|
|
48
|
+
generators = createWatchfulGenerators();
|
|
32
49
|
}, 250);
|
|
33
50
|
},
|
|
34
51
|
closeBundle() {
|
|
35
|
-
|
|
52
|
+
if (generators) {
|
|
53
|
+
for (const generator of generators) {
|
|
54
|
+
generator?.close();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
36
57
|
}
|
|
37
58
|
};
|
|
38
59
|
}
|
|
39
|
-
function
|
|
60
|
+
function createWatchfulGenerators() {
|
|
61
|
+
loadOpenapiConfig();
|
|
62
|
+
return Object.entries(generatorMap).map(([openapiYamlPath, outPath]) => createWatchfulGenerator(openapiYamlPath, outPath));
|
|
63
|
+
}
|
|
64
|
+
function createWatchfulGenerator(openapiYamlPath, outPath) {
|
|
40
65
|
const resolvedPath = overridesMap?.[openapiYamlPath] ?? openapiYamlPath;
|
|
41
66
|
if (!existsSync(resolvedPath)) {
|
|
42
67
|
console.log(`OpenAPI YAML file not found: ${resolvedPath}`);
|
|
@@ -54,7 +79,14 @@ function getGenerator(openapiYamlPath, outPath) {
|
|
|
54
79
|
}
|
|
55
80
|
};
|
|
56
81
|
}
|
|
57
|
-
async function
|
|
82
|
+
export async function generateConfiguredOpenapiClients() {
|
|
83
|
+
loadOpenapiConfig();
|
|
84
|
+
for (const [openapiYamlPath, outPath] of Object.entries(generatorMap)) {
|
|
85
|
+
const resolvedPath = overridesMap?.[openapiYamlPath] ?? openapiYamlPath;
|
|
86
|
+
await generateOpenapiClient(resolvedPath, outPath);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function generateOpenapiClient(openapiYamlPath, outPath = DEFAULT_OUT_PATH) {
|
|
58
90
|
const yaml = readFileSync(openapiYamlPath, 'utf8');
|
|
59
91
|
const hash = createHash('sha256').update(yaml).digest('hex');
|
|
60
92
|
if (hash === generatedHash) {
|
|
@@ -84,7 +116,3 @@ async function generateOpenapiClientInternal(openapiYamlPath, outPath = DEFAULT_
|
|
|
84
116
|
console.error(`[${new Date().toISOString()}] Error generating client from ${openapiYamlPath}:`, err);
|
|
85
117
|
}
|
|
86
118
|
}
|
|
87
|
-
export async function generateOpenapiClient(openapiYamlPath, outPath = DEFAULT_OUT_PATH) {
|
|
88
|
-
const resolvedPath = overridesMap?.[openapiYamlPath] ?? openapiYamlPath;
|
|
89
|
-
return generateOpenapiClientInternal(resolvedPath, outPath);
|
|
90
|
-
}
|
package/package.json
CHANGED
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { generateConfiguredOpenapiClients, generateOpenapiClient } from './vite-openapi-plugin.js';
|
|
6
6
|
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
if (process.argv[2]) {
|
|
8
|
+
if (process.argv[2] === '--help') {
|
|
9
|
+
throw new Error('Usage: vf-generate-openapi-client [<openapi-yaml-path> [<openapi-output-path>]]');
|
|
10
|
+
}
|
|
10
11
|
|
|
11
|
-
if (!existsSync(process.argv[2])) {
|
|
12
|
-
|
|
13
|
-
}
|
|
12
|
+
if (!existsSync(process.argv[2])) {
|
|
13
|
+
throw new Error(`OpenAPI YAML file not found: ${process.argv[2]}`);
|
|
14
|
+
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
await generateOpenapiClient(process.argv[2], process.argv[3]);
|
|
17
|
+
} else {
|
|
18
|
+
generateConfiguredOpenapiClients();
|
|
19
|
+
}
|
|
@@ -7,10 +7,30 @@ import * as OpenAPI from 'openapi-typescript-codegen';
|
|
|
7
7
|
const DEFAULT_OUT_PATH = './src/openapi-client-generated';
|
|
8
8
|
|
|
9
9
|
let generatedHash: string | null = null;
|
|
10
|
+
let generatorMap: Record<string, string> = {};
|
|
10
11
|
let overridesMap: Record<string, string> | null = null;
|
|
11
12
|
let overridesInverseMap: Record<string, string> | null = null;
|
|
12
13
|
|
|
13
|
-
export function
|
|
14
|
+
export function loadOpenapiConfig() {
|
|
15
|
+
loadGeneratorMap();
|
|
16
|
+
loadOverridesMap();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function loadGeneratorMap() {
|
|
20
|
+
if (!existsSync('./openapi-specs.json')) {
|
|
21
|
+
console.error('openapi-specs.json not found. Cannot generate OpenAPI client.');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const specsContent = readFileSync('./openapi-specs.json', 'utf8');
|
|
27
|
+
generatorMap = JSON.parse(specsContent);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.error('Failed to load openapi-specs.json:', e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function loadOverridesMap() {
|
|
14
34
|
if (!existsSync('./openapi-specs.dev.json')) {
|
|
15
35
|
return;
|
|
16
36
|
}
|
|
@@ -24,16 +44,13 @@ export function loadOpenapiOverrides() {
|
|
|
24
44
|
}
|
|
25
45
|
}
|
|
26
46
|
|
|
27
|
-
export function openapiClientGeneratorPlugin(
|
|
28
|
-
openapiYamlPath: string,
|
|
29
|
-
outPath: string = DEFAULT_OUT_PATH
|
|
30
|
-
): {
|
|
47
|
+
export function openapiClientGeneratorPlugin(): {
|
|
31
48
|
name: string;
|
|
32
49
|
apply: 'serve';
|
|
33
50
|
buildStart(): void;
|
|
34
51
|
closeBundle(): void;
|
|
35
52
|
} {
|
|
36
|
-
let
|
|
53
|
+
let generators: ReturnType<typeof createWatchfulGenerators> | null = null;
|
|
37
54
|
|
|
38
55
|
return {
|
|
39
56
|
name: 'openapi-types-generator',
|
|
@@ -42,18 +59,26 @@ export function openapiClientGeneratorPlugin(
|
|
|
42
59
|
buildStart() {
|
|
43
60
|
// apply a slight delay so any output doesn't get pushed off screen
|
|
44
61
|
setTimeout(() => {
|
|
45
|
-
|
|
46
|
-
generator = getGenerator(openapiYamlPath, outPath);
|
|
62
|
+
generators = createWatchfulGenerators();
|
|
47
63
|
}, 250);
|
|
48
64
|
},
|
|
49
65
|
|
|
50
66
|
closeBundle() {
|
|
51
|
-
|
|
67
|
+
if (generators) {
|
|
68
|
+
for (const generator of generators) {
|
|
69
|
+
generator?.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
52
72
|
}
|
|
53
73
|
};
|
|
54
74
|
}
|
|
55
75
|
|
|
56
|
-
function
|
|
76
|
+
function createWatchfulGenerators() {
|
|
77
|
+
loadOpenapiConfig();
|
|
78
|
+
return Object.entries(generatorMap).map(([openapiYamlPath, outPath]) => createWatchfulGenerator(openapiYamlPath, outPath));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function createWatchfulGenerator(openapiYamlPath: string, outPath: string) {
|
|
57
82
|
const resolvedPath = overridesMap?.[openapiYamlPath] ?? openapiYamlPath;
|
|
58
83
|
|
|
59
84
|
if (!existsSync(resolvedPath)) {
|
|
@@ -76,7 +101,15 @@ function getGenerator(openapiYamlPath: string, outPath: string) {
|
|
|
76
101
|
};
|
|
77
102
|
}
|
|
78
103
|
|
|
79
|
-
async function
|
|
104
|
+
export async function generateConfiguredOpenapiClients() {
|
|
105
|
+
loadOpenapiConfig();
|
|
106
|
+
for (const [openapiYamlPath, outPath] of Object.entries(generatorMap)) {
|
|
107
|
+
const resolvedPath = overridesMap?.[openapiYamlPath] ?? openapiYamlPath;
|
|
108
|
+
await generateOpenapiClient(resolvedPath, outPath);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function generateOpenapiClient(openapiYamlPath: string, outPath: string = DEFAULT_OUT_PATH) {
|
|
80
113
|
const yaml = readFileSync(openapiYamlPath, 'utf8');
|
|
81
114
|
const hash = createHash('sha256').update(yaml).digest('hex');
|
|
82
115
|
|
|
@@ -110,8 +143,3 @@ async function generateOpenapiClientInternal(openapiYamlPath: string, outPath: s
|
|
|
110
143
|
console.error(`[${new Date().toISOString()}] Error generating client from ${openapiYamlPath}:`, err);
|
|
111
144
|
}
|
|
112
145
|
}
|
|
113
|
-
|
|
114
|
-
export async function generateOpenapiClient(openapiYamlPath: string, outPath: string = DEFAULT_OUT_PATH) {
|
|
115
|
-
const resolvedPath = overridesMap?.[openapiYamlPath] ?? openapiYamlPath;
|
|
116
|
-
return generateOpenapiClientInternal(resolvedPath, outPath);
|
|
117
|
-
}
|