11import { dirname , isAbsolute , relative } from 'path'
22import { existsSync } from 'fs'
3- import { readFile , writeFile } from 'fs/promises'
3+ import { mkdir , readFile , writeFile as writeFile_ } from 'fs/promises'
44import { notNullish , slash } from '@antfu/utils'
55import type { ComponentInfo } from '../../dist'
66import type { Options } from '../types'
@@ -145,6 +145,11 @@ ${head}`
145145 return code
146146}
147147
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+
148153export async function writeDeclaration ( ctx : Context , filepath : string , removeUnused = false ) {
149154 const originalContent = existsSync ( filepath ) ? await readFile ( filepath , 'utf-8' ) : ''
150155 const originalImports = removeUnused ? undefined : parseDeclaration ( originalContent )
@@ -154,5 +159,5 @@ export async function writeDeclaration(ctx: Context, filepath: string, removeUnu
154159 return
155160
156161 if ( code !== originalContent )
157- await writeFile ( filepath , code , 'utf-8' )
162+ await writeFile ( filepath , code )
158163}
0 commit comments