@@ -96,7 +96,10 @@ const generateFile = options => new Promise((resolve, reject) => {
96
96
const generateOperationFile = ( config , operation , operation_name ) => new Promise ( ( resolve , reject ) => {
97
97
fs . readFile ( path . join ( config . root , config . file_name ) , 'utf8' , ( err , data ) => {
98
98
if ( err ) return reject ( err ) ;
99
- const subdir = config . root . replace ( new RegExp ( `${ config . templates_dir } [/]?` ) , '' ) ;
99
+ const subdir = config . root
100
+ . replace ( new RegExp ( `${ config . templates_dir } [/]?` ) , '' )
101
+ . replace ( "$$path$$" , _ . kebabCase ( operation_name ) ) ;
102
+
100
103
const new_filename = config . file_name . replace ( '$$path$$' , operation_name ) . replace ( / .h b s $ / , '' ) ;
101
104
const target_file = path . resolve ( config . target_dir , subdir , new_filename ) ;
102
105
const template = Handlebars . compile ( data . toString ( ) ) ;
@@ -108,6 +111,7 @@ const generateOperationFile = (config, operation, operation_name) => new Promise
108
111
openapi : config . data . openapi
109
112
} ) ;
110
113
114
+ xfs . mkdirpSync ( path . dirname ( target_file ) ) ;
111
115
fs . writeFile ( target_file , content , 'utf8' , ( err ) => {
112
116
if ( err ) return reject ( err ) ;
113
117
resolve ( ) ;
@@ -166,7 +170,7 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
166
170
167
171
walker . on ( 'file' , async ( root , stats , next ) => {
168
172
try {
169
- if ( stats . name . includes ( '$$path$$' ) ) {
173
+ if ( stats . name . includes ( '$$path$$' ) || root . includes ( "$$path$$" ) ) {
170
174
// this file should be handled for each in openapi.paths
171
175
await generateOperationFiles ( {
172
176
root,
@@ -199,7 +203,13 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
199
203
walker . on ( 'directory' , async ( root , stats , next ) => {
200
204
try {
201
205
const dir_path = path . resolve ( target_dir , path . relative ( templates_dir , path . resolve ( root , stats . name ) ) ) ;
202
- if ( stats . name !== PARTIALS_DIRNAME && stats . name !== HELPERS_DIRNAME ) xfs . mkdirpSync ( dir_path ) ;
206
+ if (
207
+ stats . name !== PARTIALS_DIRNAME &&
208
+ stats . name !== HELPERS_DIRNAME &&
209
+ ! stats . name . includes ( "$$path$$" )
210
+ ) {
211
+ xfs . mkdirpSync ( dir_path ) ;
212
+ }
203
213
next ( ) ;
204
214
} catch ( e ) {
205
215
reject ( e ) ;
0 commit comments