2
2
//dependencies
3
3
const commandLineArgs = require ( 'command-line-args' ) ;
4
4
const Chance = require ( 'chance' ) ;
5
- const fs = require ( 'fs' ) ;
6
5
const dayjs = require ( 'dayjs' ) ;
7
6
const readline = require ( 'readline' ) ;
8
7
const {
@@ -94,7 +93,7 @@ const {
94
93
95
94
function log ( data , silent = options . silent ) {
96
95
if ( ! silent ) {
97
- console . log ( data ) ;
96
+ process . stderr . write ( data ) ;
98
97
}
99
98
}
100
99
@@ -113,11 +112,11 @@ const banner = `
113
112
'8888888P' .8' '8. '88888. 8 8888 '88. '8.' 8 8888 'Y8888P ,88P'
114
113
` ;
115
114
log ( banner ) ;
116
- log ( '... maker of CSV files... and more!' ) ;
117
- log ( 'by AK' ) ;
118
-
119
- log ( '\n' ) ;
120
- track ( 'start' , { runId, ...options } )
115
+ log ( '\n ... maker of CSV files... and more!' ) ;
116
+ log ( '\n by AK' ) ;
117
+
118
+ log ( '\n\n ' ) ;
119
+ track ( 'start' , { runId, ...options } ) ;
121
120
122
121
123
122
if ( help ) {
@@ -427,8 +426,8 @@ function noMoreThan(num) {
427
426
428
427
//helper for status bar
429
428
function showProgress ( p ) {
430
- readline . cursorTo ( process . stdout , 0 ) ;
431
- process . stdout . write ( `generated ${ p - 1 } records...` ) ;
429
+ readline . cursorTo ( process . stderr , 0 ) ;
430
+ process . stderr . write ( `\tgenerated ${ u . comma ( p - 1 ) } records...` ) ;
432
431
}
433
432
434
433
//helper to open the finder
@@ -470,36 +469,26 @@ else {
470
469
}
471
470
472
471
//cool ... write the data
473
- fs . writeFileSync ( path . resolve ( `${ currentDirectory } /${ fileName } ` ) , dataToWrite , function ( err ) {
474
- if ( err ) {
475
- return console . log ( err ) ;
472
+ const directory = u . mkdir ( './carvis-data' ) ;
473
+ const filePath = `${ directory } /${ fileName } ` ;
474
+ u . touch ( filePath , dataToWrite ) . then ( ( ) => {
475
+ //tell the user what happened
476
+ log ( `\n\nfinished writing ${ rows } records across ${ numUsers } users for ${ days } days with columns:\n` ) ;
477
+ log ( ` ${ columns . map ( col => col . header ) . join ( ' \n ' ) } ` ) ;
478
+ log ( '\n' ) ;
479
+ log ( `\n...data written to ./carvis-data/${ fileName } ` ) ;
480
+ log ( '\n\n' ) ;
481
+ const outputMsg = path . resolve ( filePath ) + '\n' ;
482
+ if ( ! silent ) {
483
+ //attempt to reveal the data folder in finder
484
+ try {
485
+ openExplorerinMac ( currentDirectory ) ;
486
+ } catch ( e ) {
487
+ console . error ( 'revealing files only works on a mac; sorry!' ) ;
488
+ }
489
+
476
490
}
477
- } ) ;
478
-
479
-
480
- //tell the user what happened
481
- log ( `\n\nfinished writing ${ rows } records across ${ numUsers } users for ${ days } days with columns:` ) ;
482
- log ( ` ${ columns . map ( col => col . header ) . join ( ' \n ' ) } ` ) ;
483
- log ( '\n' ) ;
484
- log ( `data written to ./data/${ fileName } ` ) ;
485
- log ( '\n' ) ;
486
- log ( 'all finished!' ) ;
487
- log ( '\n' ) ;
488
- if ( silent ) {
489
- const outputMsg = path . resolve ( `${ currentDirectory } /${ fileName } ` ) + '\n' ;
490
491
process . stdout . write ( outputMsg ) ;
491
- //process.exit(0);
492
- }
493
492
494
-
495
- if ( ! silent ) {
496
- //attempt to reveal the data folder in finder
497
- try {
498
- openExplorerinMac ( currentDirectory ) ;
499
- } catch ( e ) {
500
- console . error ( 'revealing files only works on a mac; sorry!' ) ;
501
- }
502
- }
503
-
504
- track ( 'end' , { runId, ...options } )
505
- //process.exit(0);
493
+ track ( 'end' , { runId, ...options } ) ;
494
+ } ) ;
0 commit comments