-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
249 lines (237 loc) · 6.86 KB
/
cli.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
const readLine = require('readline')
const clc = require('cli-color')
const fs = require('fs')
const open = require('open')
const TrelloCSV = require('./lib/trello-csv')
// color設定
const inf = clc.xterm(83)
const st = clc.xterm(50)
const er = clc.xterm(204)
let config
try {
config = require('./config.json')
} catch (err) {
console.error(er('cannot find config.json file'))
process.exit()
}
const NOW = Date.now()
// Debugの出力を抑止
console.debug = () => {}
const readUserInput = (question, initialInput) => {
const rl = readLine.createInterface({
input: process.stdin,
output: process.stdout,
})
return new Promise((resolve, reject) => {
rl.question(question, (answer) => {
resolve(answer)
rl.close()
})
if (initialInput) {
rl.write(initialInput)
}
})
}
const inputText = async (questionText, re, initialInput) => {
while (true) {
let a = await readUserInput(questionText, initialInput)
if (a.match(re)) {
return a
} else {
console.log(er('error: invalid input'))
}
}
}
const writeList = (trelloCsv, list) => {
let csv = trelloCsv.makeCsv(list)
console.log(csv)
const {
total,
totalPoint,
totalResultTime,
totalReviewTime,
} = trelloCsv.makeStatistics(list)
console.log(`total: ${total} hrs`)
console.log(`total point: ${totalPoint}`)
console.log('-----')
console.log(`total result time: ${totalResultTime} hrs`)
console.log(`total review time ${totalReviewTime} hrs`)
}
const writeListGroup = (trelloCsv, list, groupby) => {
let {
total,
totalPoint,
totalByGroup,
pointsByGroup,
resultTimeByGroup,
reviewTimeByGroup,
doneByGroup,
} = trelloCsv.makeStatisticsUseGroupBy(list, groupby)
let csv = trelloCsv.makeCsvUseGroupBy(
groupby,
totalByGroup,
pointsByGroup,
resultTimeByGroup,
reviewTimeByGroup,
doneByGroup
)
console.log(csv)
console.log(`total: ${total} hrs`)
console.log(`total point: ${totalPoint}`)
}
const writePointCountList = (trelloCsv, allDaysCountList, groupValues) => {
let csv = trelloCsv.makePointCountCsvForBurndown(
allDaysCountList,
groupValues
)
console.log(csv)
fs.writeFileSync(
'chart-html/data/pointsCountData.csv.js',
'const pointsCountDataCSV = `' + csv + '`'
)
}
const writeIssueCountList = (trelloCsv, allDaysCountList, groupValues) => {
let csv = trelloCsv.makeIssueCountCsvForBurndown(
allDaysCountList,
groupValues
)
console.log(csv)
fs.writeFileSync(
'chart-html/data/issuesCountData.csv.js',
'const issuesCountDataCSV = `' + csv + '`'
)
}
const main = async () => {
try {
const trelloCsv = new TrelloCSV(config)
// Board一覧取得
let boardList = await trelloCsv.loadBoards()
console.debug('boardList:', JSON.stringify(boardList, true, ' '))
// Board一覧表示
let num = 1
let re = ''
for (const item of boardList) {
re += num === 1 ? '' : '|'
re += `^${num}$`
console.log(inf(`${num++}: ${item.name}`))
}
// Board選択
let i = await inputText('select board by number: ', re)
const selectedBoard = boardList[Number(i - 1)]
// Trelloからボードに関するデータを取得しパース
let list = await trelloCsv.parseBoard(selectedBoard)
// 出力内容選択
let initialFilterCondition = ''
let initialCountCondition = ''
let groupby = ''
let showingList = [
'cardId',
'number',
'title',
'point',
'listName',
'currentListName',
'inDate',
'outDate',
'resultTime',
'reviewTime',
'labelPink',
'labelGreen',
'member',
]
while (true) {
console.log(inf('----------'))
console.log(inf('1: set "group by"'))
console.log(inf('2: input filter and show data'))
console.log(inf('3: remaining number of issues and points'))
console.log(st(`current group by: ${groupby}`))
const type = await inputText('select: ', `^[1-3]$`)
if (type === '1') {
console.log(
inf('specify variable name, empty string means no group by')
)
console.log(inf(` variable names: ${showingList.toString()}`))
groupbyText = await inputText('group by: ', `.*`, groupby)
try {
const cardId = 'cardId',
number = 'number',
title = 'title',
point = 'point',
listName = 'listName',
currentListName = 'currentListName',
inDate = 'inDate',
outDate = 'outDate',
resultTime = 'resultTime',
reviewTime = 'reviewTime',
labelPink = 'labelPink',
labelGreen = 'labelGreen',
member = 'member',
totalResultTime = 'totalResultTime',
totalReviewTime = 'totalReviewTime',
totalTime = 'totalTime'
if (groupbyText === '') {
groupbyText = '""'
}
groupby = eval(groupbyText)
} catch (err) {
console.error(er(err))
}
} else if (type === '2') {
console.log(
inf(
'specify filter by javascript condition, the following variables are available, "true" means showing all data'
)
)
console.log(inf(` variable names: ${showingList.toString()}`))
const condition = await inputText(
'input condition: ',
`.+`,
initialFilterCondition
)
console.log(inf('----------'))
let newList
try {
newList = trelloCsv.searchListByCondition(condition)
} catch (err) {
console.error(er(err))
}
if (groupby !== '') {
writeListGroup(trelloCsv, newList, groupby)
} else {
writeList(trelloCsv, newList, showingList)
}
initialFilterCondition = condition
} else if (type === '3') {
console.log(
inf(
'specify filter by javascript condition, the following variables are available, "true" means showing all data'
)
)
// console.log(inf(` variable names: ${showingList.toString()}`))
const condition = await inputText(
'input condition: ',
`.+`,
initialCountCondition
)
console.log(inf('----------'))
try {
let newList = trelloCsv.searchListByCondition(condition)
let {
allDaysCountList,
groupValues,
} = trelloCsv.makeStatisticsForBurndown(newList, groupby, NOW)
writeIssueCountList(trelloCsv, allDaysCountList, groupValues)
console.log(inf('----------'))
writePointCountList(trelloCsv, allDaysCountList, groupValues)
} catch (err) {
console.error(er(err))
}
initialCountCondition = condition
await open('chart-html/index.html')
}
}
} catch (err) {
console.error(er(err))
}
}
main()