@@ -7,6 +7,21 @@ import { sentenceCase } from 'change-case'
7
7
const packagesRoot = path . resolve ( __dirname , '../packages' )
8
8
const playgroundRoot = path . resolve ( __dirname , '../playground/src' )
9
9
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
+
10
25
const ignorePaths = [ 'core' , 'nuxt' ]
11
26
12
27
/** Read all base directories and return array paths */
@@ -108,7 +123,7 @@ baseRoutes.map((basePath) => {
108
123
// 404 Route
109
124
routes . push ( NotFoundRoute )
110
125
111
- fs . writeFileSync (
126
+ writeFileSyncRecursive (
112
127
path . join ( playgroundRoot , './.generated/routes.json' ) ,
113
128
JSON . stringify ( routes , null , 2 ) ,
114
129
'utf8'
@@ -131,15 +146,15 @@ const componentLookup = flatten(routes, (route) => route.component!)
131
146
} )
132
147
. join ( '\n' )
133
148
134
- fs . writeFileSync (
149
+ writeFileSyncRecursive (
135
150
path . join ( playgroundRoot , './.generated/imports.js' ) ,
136
151
`${ componentLookup } \n\nexport default {\n${ Object . entries ( routesMap )
137
152
. map ( ( [ path , name ] ) => ` "${ path } ": ${ name } ` )
138
153
. join ( ',\n' ) } \n}`,
139
154
'utf8'
140
155
)
141
156
142
- fs . writeFileSync (
157
+ writeFileSyncRecursive (
143
158
path . join ( playgroundRoot , './.generated/resolver.js' ) ,
144
159
`/* Package components resolver only used in development mode */
145
160
export default {\n${ baseRoutes
0 commit comments