-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseSizes.js
More file actions
33 lines (29 loc) · 1.08 KB
/
parseSizes.js
File metadata and controls
33 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//https://www.digitalocean.com/community/tutorials/how-to-read-and-write-csv-files-in-node-js-using-node-csv
const fs = require('fs');
const csv = require("csv-parse");
const builder = require('xmlbuilder');
const data = [];
fs.createReadStream('./input/sizes.csv')
.pipe(csv.parse({ delimiter: ";", from_line: 2 }))
.on("data", row => {
data.push(row);
})
.on('end', () => {
var xml = builder.create('catalog')
.dec({'encoding': 'UTF-8'})
.att('catalog-id', 'goodwill-master')
.att('xmlns', 'http://www.demandware.com/xml/impex/catalog/2006-10-31');
data.forEach((row) => {
xml.ele('product')
.att('product-id', row[1])
.ele('custom-attributes')
.ele('custom-attribute')
.att('attribute-id', 'size')
.text(row[4]);
});
fs.writeFile('./output/catalog-sizes.xml', xml.end({ pretty: true }), "utf-8", err => {
if (err) {
console.error(err);
}
});
});