@@ -96,7 +96,10 @@ const generateFile = options => new Promise((resolve, reject) => {
9696const generateOperationFile = ( config , operation , operation_name ) => new Promise ( ( resolve , reject ) => {
9797 fs . readFile ( path . join ( config . root , config . file_name ) , 'utf8' , ( err , data ) => {
9898 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+
100103 const new_filename = config . file_name . replace ( '$$path$$' , operation_name ) . replace ( / .h b s $ / , '' ) ;
101104 const target_file = path . resolve ( config . target_dir , subdir , new_filename ) ;
102105 const template = Handlebars . compile ( data . toString ( ) ) ;
@@ -108,6 +111,7 @@ const generateOperationFile = (config, operation, operation_name) => new Promise
108111 openapi : config . data . openapi
109112 } ) ;
110113
114+ xfs . mkdirpSync ( path . dirname ( target_file ) ) ;
111115 fs . writeFile ( target_file , content , 'utf8' , ( err ) => {
112116 if ( err ) return reject ( err ) ;
113117 resolve ( ) ;
@@ -166,7 +170,7 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
166170
167171 walker . on ( 'file' , async ( root , stats , next ) => {
168172 try {
169- if ( stats . name . includes ( '$$path$$' ) ) {
173+ if ( stats . name . includes ( '$$path$$' ) || root . includes ( "$$path$$" ) ) {
170174 // this file should be handled for each in openapi.paths
171175 await generateOperationFiles ( {
172176 root,
@@ -199,7 +203,13 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
199203 walker . on ( 'directory' , async ( root , stats , next ) => {
200204 try {
201205 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+ }
203213 next ( ) ;
204214 } catch ( e ) {
205215 reject ( e ) ;
0 commit comments