-
Notifications
You must be signed in to change notification settings - Fork 89
/
export.js
36 lines (28 loc) · 1.12 KB
/
export.js
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
"use strict";
const path = require("path");
const FileHelper = require("./file-helper");
const Parameters = require("./parameters").get();
const WalletType = require("./wallet-type");
const objectToCsv = require("csv-writer").createObjectCsvWriter;
module.exports.exportBalances = async (symbol, balances, format) => {
const withType = await WalletType.addType(balances);
const writeCsv = () => {
const file = Parameters.outputFileNameCSV.replace(/{token}/g, symbol);
FileHelper.ensureDirectory(path.dirname(file));
const writer = objectToCsv({
path: file,
header: [{ id: "wallet", title: "Wallet" }, { id: "balance", title: "Balance" }, { id: "type", title: "Type" }]
});
console.log("Exporting CSV");
writer.writeRecords(withType).then(() => console.log("CSV export done!"));
};
if (["csv", "both"].indexOf(format.toLowerCase()) > -1) {
writeCsv();
if (format.toLowerCase() === "csv") {
return;
}
}
console.log("Exporting JSON");
await FileHelper.writeFile(Parameters.outputFileNameJSON.replace(/{token}/g, symbol), withType);
console.log("JSON export done!");
};