1
1
import { dirname , isAbsolute , relative } from 'path'
2
2
import { existsSync } from 'fs'
3
- import { readFile , writeFile } from 'fs/promises'
3
+ import { mkdir , readFile , writeFile as writeFile_ } from 'fs/promises'
4
4
import { notNullish , slash } from '@antfu/utils'
5
5
import type { ComponentInfo } from '../../dist'
6
6
import type { Options } from '../types'
@@ -145,6 +145,11 @@ ${head}`
145
145
return code
146
146
}
147
147
148
+ async function writeFile ( filePath : string , content : string ) {
149
+ await mkdir ( dirname ( filePath ) , { recursive : true } )
150
+ return await writeFile_ ( filePath , content , 'utf-8' )
151
+ }
152
+
148
153
export async function writeDeclaration ( ctx : Context , filepath : string , removeUnused = false ) {
149
154
const originalContent = existsSync ( filepath ) ? await readFile ( filepath , 'utf-8' ) : ''
150
155
const originalImports = removeUnused ? undefined : parseDeclaration ( originalContent )
@@ -154,5 +159,5 @@ export async function writeDeclaration(ctx: Context, filepath: string, removeUnu
154
159
return
155
160
156
161
if ( code !== originalContent )
157
- await writeFile ( filepath , code , 'utf-8' )
162
+ await writeFile ( filepath , code )
158
163
}
0 commit comments