@@ -21,39 +21,40 @@ function runExportData(filePath, logger) {
2121 process . exit ( 1 ) ;
2222 } ) ;
2323}
24- const logger = util . getAppLogger ( ) ;
25- const filePath =
26- process . argv [ 2 ] === '--file' && process . argv [ 3 ]
27- ? process . argv [ 3 ]
28- : 'data/demo-data.json' ;
29- logger . info ( 'Script will export data to file:' , filePath ) ;
30- // check if file exists
31- if ( fs . existsSync ( filePath ) ) {
32- // We delay question for overwrite file, because the question overlaps with a warning message from sequelize module
33- Promise . delay ( 1 ) . then ( ( ) => {
34- const rl = readline . createInterface ( {
35- input : process . stdin ,
36- output : process . stdout ,
37- } ) ;
38- // confirm overwritting to file
39- rl . question (
40- 'File already exists, Are you sure to overwrite it? [Y] to overwrite: ' ,
41- ( answer ) => {
42- rl . close ( ) ;
43- if ( answer . toLowerCase ( ) === 'y' ) {
44- logger . info ( 'File will be overwritten.' ) ;
45- runExportData ( filePath , logger ) ;
46- } else {
47- logger . info ( 'Exit without exporting any data' ) ;
48- process . exit ( 0 ) ;
49- }
50- } ,
51- ) ; // question()
24+
25+ const logger = util . getAppLogger ( ) ;
26+ const filePath =
27+ process . argv [ 2 ] === '--file' && process . argv [ 3 ]
28+ ? process . argv [ 3 ]
29+ : 'data/demo-data.json' ;
30+ logger . info ( 'Script will export data to file:' , filePath ) ;
31+ // check if file exists
32+ if ( fs . existsSync ( filePath ) ) {
33+ // We delay question for overwrite file, because the question overlaps with a warning message from sequelize module
34+ Promise . delay ( 1 ) . then ( ( ) => {
35+ const rl = readline . createInterface ( {
36+ input : process . stdin ,
37+ output : process . stdout ,
5238 } ) ;
53- } else {
54- // get base directory of the file
55- const baseDir = path . resolve ( filePath , '..' ) ;
56- // create directory recursively if it does not exist
57- util . mkdirSyncRecursive ( baseDir ) ;
58- runExportData ( filePath , logger ) ;
59- }
39+ // confirm overwritting to file
40+ rl . question (
41+ 'File already exists, Are you sure to overwrite it? [Y] to overwrite: ' ,
42+ ( answer ) => {
43+ rl . close ( ) ;
44+ if ( answer . toLowerCase ( ) === 'y' ) {
45+ logger . info ( 'File will be overwritten.' ) ;
46+ runExportData ( filePath , logger ) ;
47+ } else {
48+ logger . info ( 'Exit without exporting any data' ) ;
49+ process . exit ( 0 ) ;
50+ }
51+ } ,
52+ ) ; // question()
53+ } ) ;
54+ } else {
55+ // get base directory of the file
56+ const baseDir = path . resolve ( filePath , '..' ) ;
57+ // create directory recursively if it does not exist
58+ util . mkdirSyncRecursive ( baseDir ) ;
59+ runExportData ( filePath , logger ) ;
60+ }
0 commit comments