@@ -67,7 +67,10 @@ const generateFile = options => new Promise((resolve, reject) => {
6767const generateOperationFile = ( config , operation , operation_name ) => new Promise ( ( resolve , reject ) => {
6868 fs . readFile ( path . join ( config . root , config . file_name ) , 'utf8' , ( err , data ) => {
6969 if ( err ) return reject ( err ) ;
70- const subdir = config . root . replace ( new RegExp ( `${ config . templates_dir } [/]?` ) , '' ) ;
70+ const subdir = config . root
71+ . replace ( new RegExp ( `${ config . templates_dir } [/]?` ) , '' )
72+ . replace ( "$$path$$" , _ . kebabCase ( operation_name ) ) ;
73+
7174 const new_filename = config . file_name . replace ( '$$path$$' , operation_name ) . replace ( / .h b s $ / , '' ) ;
7275 const target_file = path . resolve ( config . target_dir , subdir , new_filename ) ;
7376 const template = Handlebars . compile ( data . toString ( ) ) ;
@@ -79,6 +82,7 @@ const generateOperationFile = (config, operation, operation_name) => new Promise
7982 openapi : config . data . openapi
8083 } ) ;
8184
85+ xfs . mkdirpSync ( path . dirname ( target_file ) ) ;
8286 fs . writeFile ( target_file , content , 'utf8' , ( err ) => {
8387 if ( err ) return reject ( err ) ;
8488 resolve ( ) ;
@@ -137,7 +141,7 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
137141
138142 walker . on ( 'file' , async ( root , stats , next ) => {
139143 try {
140- if ( stats . name . includes ( '$$path$$' ) ) {
144+ if ( stats . name . includes ( '$$path$$' ) || root . includes ( "$$path$$" ) ) {
141145 // this file should be handled for each in openapi.paths
142146 await generateOperationFiles ( {
143147 root,
@@ -170,7 +174,13 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
170174 walker . on ( 'directory' , async ( root , stats , next ) => {
171175 try {
172176 const dir_path = path . resolve ( target_dir , path . relative ( templates_dir , path . resolve ( root , stats . name ) ) ) ;
173- if ( stats . name !== PARTIALS_DIRNAME && stats . name !== HELPERS_DIRNAME ) xfs . mkdirpSync ( dir_path ) ;
177+ if (
178+ stats . name !== PARTIALS_DIRNAME &&
179+ stats . name !== HELPERS_DIRNAME &&
180+ ! stats . name . includes ( "$$path$$" )
181+ ) {
182+ xfs . mkdirpSync ( dir_path ) ;
183+ }
174184 next ( ) ;
175185 } catch ( e ) {
176186 reject ( e ) ;
0 commit comments