11import * as fs from 'fs' ;
22import * as path from 'path' ;
33import * as readline from 'readline' ;
4+ import Promise from 'bluebird' ;
45import util from '../../../src/util' ;
56import { exportData } from './exportData' ;
67/**
@@ -12,24 +13,24 @@ import { exportData } from './exportData';
1213function runExportData ( filePath , logger ) {
1314 exportData ( filePath , logger )
1415 . then ( ( ) => {
15- logger . log ( 'Successfully exported data' ) ;
16+ logger . info ( 'Successfully exported data' ) ;
1617 process . exit ( 0 ) ;
1718 } )
1819 . catch ( ( err ) => {
1920 logger . error ( 'Failed to export data, ERROR:' , err . message || err ) ;
2021 process . exit ( 1 ) ;
2122 } ) ;
2223}
23-
24- setTimeout ( ( ) => {
25- const logger = console ;
24+ const logger = util . getAppLogger ( ) ;
2625 const filePath =
2726 process . argv [ 2 ] === '--file' && process . argv [ 3 ]
2827 ? process . argv [ 3 ]
2928 : 'data/demo-data.json' ;
30- logger . log ( '\nScript will export data to file:', filePath ) ;
29+ logger . info ( 'Script will export data to file:', filePath ) ;
3130 // check if file exists
3231 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 ( ( ) => {
3334 const rl = readline . createInterface ( {
3435 input : process . stdin ,
3536 output : process . stdout ,
@@ -40,19 +41,19 @@ setTimeout(() => {
4041 ( answer ) => {
4142 rl . close ( ) ;
4243 if ( answer . toLowerCase ( ) === 'y' ) {
43- logger . log ( 'File will be overwritten.' ) ;
44+ logger . info ( 'File will be overwritten.' ) ;
4445 runExportData ( filePath , logger ) ;
4546 } else {
46- logger . log ( 'Exit without exporting any data' ) ;
47+ logger . info ( 'Exit without exporting any data' ) ;
4748 process . exit ( 0 ) ;
4849 }
4950 } ,
5051 ) ; // question()
52+ } ) ;
5153 } else {
5254 // get base directory of the file
5355 const baseDir = path . resolve ( filePath , '..' ) ;
5456 // create directory recursively if it does not exist
5557 util . mkdirSyncRecursive ( baseDir ) ;
5658 runExportData ( filePath , logger ) ;
5759 }
58- } ) ;
0 commit comments