@@ -13,7 +13,7 @@ const { createApiConfig } = require("./apiConfig");
1313const { prepareModelType } = require ( "./modelTypes" ) ;
1414const { getSwaggerObject, fixSwaggerScheme, convertSwaggerObject } = require ( "./swagger" ) ;
1515const { createComponentsMap, filterComponentsMap } = require ( "./components" ) ;
16- const { createFile, pathIsExist } = require ( "./files" ) ;
16+ const { createFile, pathIsExist, pathIsDir , createDir , cleanDir } = require ( "./files" ) ;
1717const { addToConfig, config } = require ( "./config" ) ;
1818const { getTemplates } = require ( "./templates" ) ;
1919const constants = require ( "./constants" ) ;
@@ -41,6 +41,7 @@ module.exports = {
4141 extraTemplates,
4242 enumNamesAsValues,
4343 disableStrictSSL = config . disableStrictSSL ,
44+ cleanOutput,
4445 } ) =>
4546 new Promise ( ( resolve , reject ) => {
4647 addToConfig ( {
@@ -57,6 +58,7 @@ module.exports = {
5758 hooks : _ . merge ( config . hooks , rawHooks || { } ) ,
5859 enumNamesAsValues,
5960 disableStrictSSL,
61+ cleanOutput,
6062 } ) ;
6163 ( spec ? convertSwaggerObject ( spec ) : getSwaggerObject ( input , url , disableStrictSSL ) )
6264 . then ( ( { usageSchema, originalSchema } ) => {
@@ -110,14 +112,24 @@ module.exports = {
110112
111113 const configuration = config . hooks . onPrepareConfig ( rawConfiguration ) || rawConfiguration ;
112114
115+ if ( pathIsExist ( output ) ) {
116+ if ( cleanOutput ) {
117+ cleanDir ( output ) ;
118+ }
119+ } else {
120+ createDir ( output ) ;
121+ }
122+
113123 const files = generateOutputFiles ( {
114124 modular,
115125 templatesToRender,
116126 configuration,
117127 } ) ;
118128
129+ const isDirPath = pathIsDir ( output ) ;
130+
119131 const generatedFiles = files . map ( ( file ) => {
120- if ( ! pathIsExist ( output ) ) return file ;
132+ if ( ! isDirPath ) return file ;
121133
122134 if ( translateToJavaScript ) {
123135 createFile ( output , file . name , file . content ) ;
0 commit comments