mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
19 lines
449 B
TypeScript
19 lines
449 B
TypeScript
import path from 'path'
|
|
import fs from 'fs'
|
|
|
|
export const writeFile = async (filepath: string, content: string): Promise<void> => {
|
|
const dirname = path.dirname(filepath)
|
|
if (!fs.existsSync(dirname)) {
|
|
fs.mkdirSync(dirname, { recursive: true })
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
fs.writeFile(filepath, content, 'utf-8', (err) => {
|
|
if (err) {
|
|
reject(err)
|
|
} else {
|
|
resolve()
|
|
}
|
|
})
|
|
})
|
|
}
|