@@ -2,7 +2,7 @@ import SwaggerParser from "@apidevtools/swagger-parser";
2
2
import type { OpenAPIObject } from "openapi3-ts/oas31" ;
3
3
import { basename , join , dirname } from "pathe" ;
4
4
import { type } from "arktype" ;
5
- import { writeFile } from "fs/promises" ;
5
+ import { mkdir , writeFile } from "fs/promises" ;
6
6
import { allowedRuntimes , generateFile } from "./generator.ts" ;
7
7
import { mapOpenApiEndpoints } from "./map-openapi-endpoints.ts" ;
8
8
import { generateTanstackQueryFile } from "./tanstack-query.generator.ts" ;
@@ -11,6 +11,14 @@ import { prettify } from "./format.ts";
11
11
const cwd = process . cwd ( ) ;
12
12
const now = new Date ( ) ;
13
13
14
+ async function ensureDir ( dirPath : string ) : Promise < void > {
15
+ try {
16
+ await mkdir ( dirPath , { recursive : true } ) ;
17
+ } catch ( error ) {
18
+ console . error ( `Error ensuring directory: ${ ( error as Error ) . message } ` ) ;
19
+ }
20
+ }
21
+
14
22
export const optionsSchema = type ( {
15
23
"output?" : "string" ,
16
24
runtime : allowedRuntimes ,
@@ -35,6 +43,7 @@ export async function generateClientFiles(input: string, options: typeof options
35
43
) ;
36
44
37
45
console . log ( "Generating client..." , outputPath ) ;
46
+ await ensureDir ( dirname ( outputPath ) ) ;
38
47
await writeFile ( outputPath , content ) ;
39
48
40
49
if ( options . tanstack ) {
@@ -44,6 +53,7 @@ export async function generateClientFiles(input: string, options: typeof options
44
53
} ) ;
45
54
const tanstackOutputPath = join ( dirname ( outputPath ) , typeof options . tanstack === "string" ? options . tanstack : `tanstack.client.ts` ) ;
46
55
console . log ( "Generating tanstack client..." , tanstackOutputPath ) ;
56
+ await ensureDir ( dirname ( tanstackOutputPath ) ) ;
47
57
await writeFile ( tanstackOutputPath , tanstackContent ) ;
48
58
}
49
59
0 commit comments