Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 73d993d

Browse files
committed
build(playground): added createdir if doesn't exist
1 parent 652e499 commit 73d993d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scripts/parse-routes.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ import { sentenceCase } from 'change-case'
77
const packagesRoot = path.resolve(__dirname, '../packages')
88
const playgroundRoot = path.resolve(__dirname, '../playground/src')
99

10+
function writeFileSyncRecursive(filename, content, charset) {
11+
const folders = filename.split(path.sep).slice(0, -1)
12+
if (folders.length) {
13+
// create folder path if it doesn't exist
14+
folders.reduce((last, folder) => {
15+
const folderPath = last ? last + path.sep + folder : folder
16+
if (!fs.existsSync(folderPath)) {
17+
fs.mkdirSync(folderPath)
18+
}
19+
return folderPath
20+
})
21+
}
22+
fs.writeFileSync(filename, content, charset)
23+
}
24+
1025
const ignorePaths = ['core', 'nuxt']
1126

1227
/** Read all base directories and return array paths */
@@ -108,7 +123,7 @@ baseRoutes.map((basePath) => {
108123
// 404 Route
109124
routes.push(NotFoundRoute)
110125

111-
fs.writeFileSync(
126+
writeFileSyncRecursive(
112127
path.join(playgroundRoot, './.generated/routes.json'),
113128
JSON.stringify(routes, null, 2),
114129
'utf8'
@@ -131,15 +146,15 @@ const componentLookup = flatten(routes, (route) => route.component!)
131146
})
132147
.join('\n')
133148

134-
fs.writeFileSync(
149+
writeFileSyncRecursive(
135150
path.join(playgroundRoot, './.generated/imports.js'),
136151
`${componentLookup}\n\nexport default {\n${Object.entries(routesMap)
137152
.map(([path, name]) => ` "${path}": ${name}`)
138153
.join(',\n')}\n}`,
139154
'utf8'
140155
)
141156

142-
fs.writeFileSync(
157+
writeFileSyncRecursive(
143158
path.join(playgroundRoot, './.generated/resolver.js'),
144159
`/* Package components resolver only used in development mode */
145160
export default {\n${baseRoutes

0 commit comments

Comments
 (0)