Created
July 25, 2019 22:21
-
-
Save rjhilgefort/0118d3086874319399a7b2450ea97eef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
const _ = require('lodash') | |
const parser = require('csv-parse/lib/sync') | |
const JsonStringify = x => JSON.stringify(x, null, 2) | |
const SRC_DIR = path.join(__dirname, '..', 'src') | |
_.forEach( | |
[ | |
{ | |
workingDir: path.join(SRC_DIR, 'foo'), | |
source: 'foo-file.csv', | |
dest: 'foo-file.csv.json', | |
}, | |
], | |
({ workingDir, source, dest }) => { | |
const sourceCsv = fs.readFileSync(path.join(workingDir, source)) | |
const sourceJson = parser(sourceCsv, { delimiter: ',', columns: true }) | |
const outputFile = path.join(workingDir, dest) | |
console.log(`Writing ${outputFile.replace(SRC_DIR, '')}`) | |
fs.writeFileSync(outputFile, JsonStringify(sourceJson)) | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment