Skip to content

Commit 270ea17

Browse files
authored
fix: generator config (no such file or directory) (#308)
fix #173 (comment)
1 parent e3900bc commit 270ea17

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/core/ctx.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ export function createContext(options: Options = {}, root = process.cwd()) {
8282

8383
const writeConfigFilesThrottled = throttle(500, writeConfigFiles, { noLeading: false })
8484

85+
async function writeFile(filePath: string, content: string) {
86+
await fs.mkdir(dirname(filePath), { recursive: true })
87+
return await fs.writeFile(filePath, content, 'utf-8')
88+
}
89+
8590
let lastDTS: string | undefined
8691
let lastESLint: string | undefined
8792
async function writeConfigFiles() {
@@ -91,7 +96,7 @@ export function createContext(options: Options = {}, root = process.cwd()) {
9196
generateDTS(dts).then((content) => {
9297
if (content !== lastDTS) {
9398
lastDTS = content
94-
return fs.writeFile(dts, content, 'utf-8')
99+
return writeFile(dts, content)
95100
}
96101
}),
97102
)
@@ -101,7 +106,7 @@ export function createContext(options: Options = {}, root = process.cwd()) {
101106
generateESLint().then((content) => {
102107
if (content !== lastESLint) {
103108
lastESLint = content
104-
return fs.writeFile(eslintrc.filepath!, content, 'utf-8')
109+
return writeFile(eslintrc.filepath!, content)
105110
}
106111
}),
107112
)

0 commit comments

Comments
 (0)