-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (34 loc) · 1.07 KB
/
app.js
File metadata and controls
42 lines (34 loc) · 1.07 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
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const xmlToJs = require('xml-js');
const toCSV = require('array-to-csv');
const { get } = require('lodash');
const ObjectParser = require('./src/parser');
const configs = require('./configs/config');
const processingDir = './data';
const filesToBeProcessed = fs.readdirSync(processingDir);
if (filesToBeProcessed.length === 0) {
console.warn('No files available to be processed');
process.exit();
}
const parser = new ObjectParser(configs);
const fileContent = fs.readFileSync(`${processingDir}/${filesToBeProcessed[1]}`);
const header = configs.fieldsToGrab.map(({ mapFieldTo }) => mapFieldTo);
if (fileContent) {
const js = xmlToJs.xml2js(fileContent, {
compact: true,
textFn(text) {
return text.replace(/"/g, '\'');
}
});
const list = parser.parse(js);
// const addedColumns = parser.columnsToAdd;
// const list = [
// header,
// ...newArray
// ];
debugger;
const csvData = toCSV(list);
if (csvData) {
fs.writeFileSync(`${processingDir}/processed_${filesToBeProcessed[1].split('.')[0]}.csv`, csvData);
}
}