-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
141 lines (124 loc) · 3.84 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Trello release notes generator
*
* Author: Norbert Eder <[email protected]>
*/
var options = require('optimist')
.usage('Generate release notes from Trello cards.\n\nUsage: $0')
.alias('g', 'generate')
.describe('g', 'Generate from list names')
.string('g')
.alias('b', 'boardid')
.describe('b', 'The board id from Trello')
.string('b')
.alias('l', 'list')
.describe('l', 'Show lists of given board. Default: all. Possible: open, closed, all')
.string('l')
.alias('v', 'version')
.describe('v', 'Product version')
.string('v');
var optionArgs = options.argv;
var path = require('path');
var fs = require('fs');
var TrelloReceiver = require('./lib/cardreceiver');
var Converter = require('./lib/converter');
var Generator = require('./lib/datagenerator');
// read settings
global.settings = require('./settings');
fs.exists(settings.exportPath, function(exists) {
if (exists) {
settings.root = settings.exportPath;
}
else {
settings.root = path.join(__dirname.replace(/\/+$/, ""), "export");
var exists = fs.existsSync(settings.root);
if (!exists) {
fs.mkdirSync(settings.root, 0666);
}
}
});
var lists = optionArgs.g;
var boardId = optionArgs.b;
var showLists = optionArgs.l;
var version = optionArgs.v;
if (version){
if (version.length) {
console.log("Taking other version than configured ...");
settings.strings.version_number = version;
} else {
console.log("Option for version defined, but no version given. Taking from settings.");
}
}
if (boardId) {
if (boardId.length) {
console.log("Taking other board id than configured ...");
settings.boardId = boardId;
} else {
console.log("Option for board id defined, but no id given. Taking from settings.");
}
}
if (showLists) {
if (showLists.length) {
getLists(showLists);
} else {
getLists('all');
}
} else if (lists && lists.length) {
start();
} else if (lists && !lists.length) {
console.log('Option -g has no defined list names');
console.log('');
example();
} else {
options.showHelp();
}
function example() {
console.log('Example:');
console.log(' index.js -g MyList');
console.log(' index.js -g "Version 2.9, Version 3.0"');
console.log(' index.js -g "Version 2.9, Version 3.0" -b "theboardid"');
}
function getLists(filter) {
var receiver = new TrelloReceiver(settings.applicationKey, settings.userToken, settings.boardId);
receiver.getLists(filter, function(error,data) {
if (error) {
console.log(error instanceof Error ? error.message : error);
} else {
if (data) {
for (var i = 0; i < data.length; i++) {
console.log((data[i].closed ? '[closed] ' : '[open] ') + data[i].id + ' ' + data[i].name);
}
}
}
});
}
function start() {
var receiver = new TrelloReceiver(settings.applicationKey, settings.userToken, settings.boardId);
receiver.receive(lists.split(','), function(err, cards) {
if (err) {
console.log(err instanceof Error ? err.message : err);
return;
}
if (cards.length > 0) {
var converter = new Converter(path.join(__dirname, "templates"));
var data = Generator.generateData(cards);
converter.convert(data, settings.template, function(convertError, data) {
if (convertError) {
console.log(convertError instanceof Error ? convertError.message : convertError);
}
else {
save(data);
}
});
} else {
console.log("No cards having release notes found.");
}
});
}
function save(content) {
var filename = path.join(settings.root, settings.strings.product.replace(' ', '_') + "_" + settings.strings.version_number.replace(/\./gi,'_') + '.markdown');
fs.writeFile(filename, content, function(err) {
if (err) throw err;
console.log("Release notes exported successfully");
});
}