forked from deshanm/trello-json-to-csv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (62 loc) · 2.21 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fastCSV = require('fast-csv');
const fs = require('fs')
const INPUT_FOLDER_PATH = './input-folder/';
const OUTPUT_FOLDER_PATH = './output-folder/';
function writeToFile(file, newList) {
console.log('start to writeToFile', file)
var csvStream = fastCSV.format({ headers: true }),
writableStream = fs.createWriteStream(`./${OUTPUT_FOLDER_PATH}/${file}.csv`);
writableStream.on("finish", function () {
console.log("DONE!");
});
csvStream.pipe(writableStream);
newList.forEach((item) => {
csvStream.write(item);
})
csvStream.end();
}
function convertToCSVFile(file) {
console.log('start to convertToCSVFile', file)
const trelloJson = require(`./${INPUT_FOLDER_PATH}/${file}`);
var cards = trelloJson.cards;
var lists = trelloJson.lists;
var members = trelloJson.members;
var comments = trelloJson.actions.filter(a => a.type === "commentCard");
var maxComments = cards.reduce((acc,card) => card.badges.comments > acc ? card.badges.comments : 0, 0);
const newList = [];
cards.forEach(card => {
const listName = lists.find(list => list.id === card.idList).name;
let member = null;
if (card.idMembers[0]) {
member = members.find(member => member.id === card.idMembers[0]).fullName;
}
const cardData = {
listName: listName,
title: card.name,
desc: card.desc,
shortUrl: card.shortUrl,
url: card.url,
member: member,
}
const cardComments = comments.filter(c => c.data.card.id === card.id);
for (let i = 0; i < maxComments; i++) {
cardData['comment' + i.toString()] = cardComments[i] ? cardComments[i].data.text : '';
}
newList.push(cardData);
});
writeToFile(file, newList)
}
function getFilesList() {
console.log('-------getFilesList()');
const fs = require('fs');
return fs.readdirSync(INPUT_FOLDER_PATH);
}
(function main() {
console.log('-------app starting ----------');
const files = getFilesList();
for (let i = 0; i < files.length; i++) {
const file = files[i];
convertToCSVFile(file);
}
console.log('-------app finishing ----------');
})();