File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ program
34
34
. option ( '-t, --templates <templateDir>' , 'directory where templates are located (defaults to internal nodejs templates)' )
35
35
. option ( '-b, --basedir <baseDir>' , 'directory to use as the base when resolving local file references (defaults to OpenAPI file directory)' )
36
36
. option ( '-c, --curl' , 'generate a curl scripts' , false )
37
+ . option ( '-s, --skipExistingFiles' , 'skip existing files' )
37
38
. parse ( process . argv ) ;
38
39
39
40
if ( ! openapiFile ) {
@@ -48,7 +49,7 @@ generator.generate({
48
49
templates : program . templates ? path . resolve ( process . cwd ( ) , program . templates ) : undefined ,
49
50
curl : program . curl ,
50
51
template,
51
- } ) . then ( ( ) => {
52
+ skipExistingFiles : program . skipExistingFiles
52
53
console . log ( green ( 'Done! ✨' ) ) ;
53
54
console . log ( yellow ( 'Check out your shiny new API at ' ) + magenta ( program . output ) + yellow ( '.' ) ) ;
54
55
} ) . catch ( err => {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const xfs = require('fs.extra');
13
13
const randomName = require ( 'project-name-generator' ) ;
14
14
const registerPartial = require ( './register-partial' ) ;
15
15
const bundler = require ( './bundler' ) ;
16
+ const yellow = text => `\x1b[33m${ text } \x1b[0m` ;
16
17
17
18
const codegen = module . exports ;
18
19
@@ -46,10 +47,19 @@ const generateFile = options => new Promise((resolve, reject) => {
46
47
const parsed_content = template ( data ) ;
47
48
const template_path = path . relative ( templates_dir , path . resolve ( root , file_name ) ) ;
48
49
const generated_path = path . resolve ( target_dir , template_path ) . replace ( / .h b s $ / , '' ) ;
49
- fs . writeFile ( generated_path , parsed_content , 'utf8' , ( err ) => {
50
- if ( err ) return reject ( err ) ;
50
+ // WIP check here for existing?
51
+ const skipFile = data . skipExistingFiles && fs . existsSync ( generated_path ) ;
52
+ if ( ! skipFile ) {
53
+ fs . writeFile ( generated_path , parsed_content , 'utf8' , ( err ) => {
54
+ if ( err ) return reject ( err ) ;
55
+ resolve ( ) ;
56
+ } ) ;
57
+ }
58
+ else {
59
+ console . warn ( yellow ( `Skipping file: ${ generated_path } ` ) ) ;
51
60
resolve ( ) ;
52
- } ) ;
61
+ }
62
+
53
63
} catch ( e ) {
54
64
reject ( e ) ;
55
65
}
You can’t perform that action at this time.
0 commit comments