File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ export default class Export extends Command {
6060
6161 // (FIXME) Step 5 - Aggregate data
6262 // (FIXME) Step 6 - Save data
63+ await tools . utils . saveFile ( data , params )
6364 }
6465
6566 /**
Original file line number Diff line number Diff line change 1+ import * as fs from 'fs'
12import * as moment from 'moment'
23import { EOL } from 'os'
34
@@ -41,6 +42,25 @@ export default class ExportUtils {
4142 }
4243 }
4344
45+ /**
46+ * Save file on disk
47+ */
48+ public saveFile ( data : Array < any > , params : any ) {
49+ // #neurodecisions$2019-01-12$2019-12-12.csv
50+ const fromDate = params . from . replace ( / - / g, '' )
51+ const toDate = params . to . replace ( / - / g, '' )
52+ const project = params . project . replace ( / [ ^ a - z A - Z ] / g, '' )
53+ const filename = `${ project } -${ fromDate } -${ toDate } .${ params . format } `
54+ const writeData = ( params . format === 'json' ) ? JSON . stringify ( data ) : data
55+ try {
56+ fs . writeFileSync ( filename , writeData )
57+ return true
58+ } catch ( err ) {
59+ // FIXME handle error
60+ console . error ( err )
61+ }
62+ }
63+
4464 /**
4565 * Format error message
4666 */
You can’t perform that action at this time.
0 commit comments