Last active
July 20, 2021 09:13
-
-
Save lamenath/abf6c80a9f2e355feec625c73627ef71 to your computer and use it in GitHub Desktop.
This takes a list of products in a CSV file as an input and generates one Prismic JSON import file for each raw
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 = []; | |
fs.createReadStream('source.csv') | |
.pipe(csv()) | |
.on('data', (data) => results.push(data)) | |
.on('end', () => { | |
results.forEach(function (result, i) { | |
console.log(result); | |
console.log(i); | |
const importfile = {}; | |
const product_pim_mapping = "csvjson--catalog~" + result.sku; | |
importfile.product_name = result.product_name; | |
importfile.uid = result.sku; | |
importfile.product_pim_mapping = product_pim_mapping; | |
importfile.type = "product"; | |
importfile.lang = "en-gb"; | |
console.log(importfile); | |
fs.writeFile (result.sku + ".json", JSON.stringify(importfile), function(err) { | |
if (err) throw err; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment