Last active
May 15, 2021 21:24
-
-
Save lamenath/ce18cbd5c52b624610d448a44a71e339 to your computer and use it in GitHub Desktop.
CSV to Prismic IF endpoint mock
This file contains hidden or 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 csv = require('csv-parser') | |
const fs = require('fs') | |
const results = []; | |
const catalog = { | |
"results_size": 50, | |
"results": [] | |
}; | |
fs.createReadStream('source-if.csv') | |
.pipe(csv()) | |
.on('data', (data) => results.push(data)) | |
.on('end', () => { | |
results.forEach(function (result, i) { | |
const product = {}; | |
product.id = result.sku; | |
product.title = result.product_name; | |
product.description = result.description; | |
product.last_update = 1509364426938; | |
product.blob = result; | |
catalog.results.push(product); | |
fs.writeFile ("if.json", JSON.stringify(catalog), function(err) { | |
if (err) throw err; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment