@@ -67,7 +67,10 @@ const generateFile = options => new Promise((resolve, reject) => {
67
67
const generateOperationFile = ( config , operation , operation_name ) => new Promise ( ( resolve , reject ) => {
68
68
fs . readFile ( path . join ( config . root , config . file_name ) , 'utf8' , ( err , data ) => {
69
69
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
+
71
74
const new_filename = config . file_name . replace ( '$$path$$' , operation_name ) . replace ( / .h b s $ / , '' ) ;
72
75
const target_file = path . resolve ( config . target_dir , subdir , new_filename ) ;
73
76
const template = Handlebars . compile ( data . toString ( ) ) ;
@@ -79,6 +82,7 @@ const generateOperationFile = (config, operation, operation_name) => new Promise
79
82
openapi : config . data . openapi
80
83
} ) ;
81
84
85
+ xfs . mkdirpSync ( path . dirname ( target_file ) ) ;
82
86
fs . writeFile ( target_file , content , 'utf8' , ( err ) => {
83
87
if ( err ) return reject ( err ) ;
84
88
resolve ( ) ;
@@ -137,7 +141,7 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
137
141
138
142
walker . on ( 'file' , async ( root , stats , next ) => {
139
143
try {
140
- if ( stats . name . includes ( '$$path$$' ) ) {
144
+ if ( stats . name . includes ( '$$path$$' ) || root . includes ( "$$path$$" ) ) {
141
145
// this file should be handled for each in openapi.paths
142
146
await generateOperationFiles ( {
143
147
root,
@@ -170,7 +174,13 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
170
174
walker . on ( 'directory' , async ( root , stats , next ) => {
171
175
try {
172
176
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
+ }
174
184
next ( ) ;
175
185
} catch ( e ) {
176
186
reject ( e ) ;
0 commit comments