diff --git a/output/.gitkeep b/output/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 1733449..83b22d5 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "cli-table3": "^0.6.0", "cli-welcome": "^1.4.0", "comma-number": "^2.0.1", + "csv-writer": "^1.6.0", "lodash.orderby": "^4.6.0", "log-symbols": "^4.0.0", "meow": "^6.1.0", diff --git a/utils/getStates.js b/utils/getStates.js index b258268..731732e 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -6,6 +6,7 @@ const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); const sortStatesValidation = require('./sortStatesValidation.js'); +const createCsvWriter = require('csv-writer').createObjectCsvWriter; module.exports = async ( spinner, @@ -49,6 +50,21 @@ module.exports = async ( if (!json) { spinner.info(`${cyan(`Sorted by:`)} ${sortBy}${isRev}`); } + + const csvWriter = createCsvWriter({ + path: 'output/chart.csv', + header: [ + {id: 'state', title: 'State'}, + {id: 'cases', title: 'Cases'}, + {id: 'todayCases', title: 'Cases (today)'}, + {id: 'deaths', title: 'Deaths'}, + {id: 'todayDeaths', title: 'Deaths (today)'}, + {id: 'active', title: 'Active'}, + ] + }); + + csvWriter.writeRecords(allStates); + console.log(output.toString()); } };