11import * as fs from 'fs-extra' ;
2- import * as path from 'path ' ;
2+ import { config } from './models/config.model ' ;
33import { argumentsInstance } from './services/arguments.service' ;
44import { FileReaderService } from './services/parsers/file-reader.service' ;
55import { APIParserService } from './services/parsers/open-api-v3/api-parser.service' ;
@@ -8,36 +8,34 @@ import { ApiWritterService } from './services/writters/api-writter.service';
88import { ModelWritterService } from './services/writters/model-writter.service' ;
99import { Store } from './stores/entities.store' ;
1010
11- // FOLDERS INFORMATION
12- const OUTPUT_PATH = argumentsInstance . outputFolder + path . sep ;
11+ config . parseYargs ( argumentsInstance ) ;
1312
14- const GENERATED_FOLDER = OUTPUT_PATH + 'generated' + path . sep ;
15- const OUTPUT_FOLDERS = {
16- OUTPUT_PATH : OUTPUT_PATH ,
17- BASE_FOLDER : GENERATED_FOLDER ,
18- MODELS : GENERATED_FOLDER + 'models' ,
19- APIS : GENERATED_FOLDER + 'api' ,
20- } ;
13+ // FOLDERS INFORMATION
2114console . info ( 'Output folders:' ) ;
22- console . table ( OUTPUT_FOLDERS ) ;
23-
24- console . log ( '' ) ;
25- if ( argumentsInstance . clean ) {
26- console . log ( 'Removing previously generated data...' ) ;
27- fs . removeSync ( GENERATED_FOLDER ) ;
28- } else {
29- console . log ( 'no-clean flag recevived, clean folder skipped' ) ;
30- }
31- console . log ( '' ) ;
15+ console . table ( {
16+ OUTPUT_PATH : config . outputPath ,
17+ BASE_FOLDER : config . exportPath ,
18+ MODELS : config . exportPath ,
19+ APIS : config . exportPath ,
20+ } ) ;
3221
3322// Read the file
3423async function run ( ) {
3524 try {
25+ // Check if the template does not exist
26+ config . templatePath ;
27+
28+ console . log ( '' ) ;
29+ if ( argumentsInstance . clean ) {
30+ console . log ( 'Removing previously generated data...' ) ;
31+ fs . removeSync ( config . exportPath ) ;
32+ } else {
33+ console . log ( 'no-clean flag recevived, clean folder skipped' ) ;
34+ }
35+ console . log ( '' ) ;
36+
3637 console . log ( 'Opening file:' , argumentsInstance . file ) ;
37- const fileParser = new FileReaderService (
38- argumentsInstance . file ,
39- OUTPUT_FOLDERS ,
40- ) ;
38+ const fileParser = new FileReaderService ( argumentsInstance . file , config ) ;
4139 console . log ( 'Parsing file...' ) ;
4240 console . log ( '' ) ;
4341 const documentParsed = await fileParser . readFile ( ) ;
@@ -51,9 +49,9 @@ async function run() {
5149
5250 console . info ( '' ) ;
5351 console . info ( 'Generating files' ) ;
54- const modelWritter = new ModelWritterService ( OUTPUT_FOLDERS , Store ) ;
52+ const modelWritter = new ModelWritterService ( Store , config ) ;
5553 modelWritter . write ( ) ;
56- const apiWritter = new ApiWritterService ( OUTPUT_FOLDERS , Store ) ;
54+ const apiWritter = new ApiWritterService ( Store , config ) ;
5755 apiWritter . write ( ) ;
5856 console . info ( 'Files generation finished' ) ;
5957
0 commit comments