|
1 | 1 | const _ = require('underscore'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
2 | 4 | const Csv = require('csv-string'); |
3 | 5 |
|
4 | 6 | const Base = require('./base'); |
@@ -43,15 +45,47 @@ class csv extends Base { |
43 | 45 | this.csvRecords = Csv.stringify(times); |
44 | 46 | } |
45 | 47 |
|
| 48 | + toFile(file) { |
| 49 | + let fileName = path.basename(file); |
| 50 | + let extName = path.extname(file); |
| 51 | + |
| 52 | + if (this.config.get('report').includes('stats')) { |
| 53 | + fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.stats${extName}`)), this.csvStats); |
| 54 | + } |
| 55 | + |
| 56 | + if (this.config.get('report').includes('issues')) { |
| 57 | + fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.issues${extName}`)), this.csvIssues); |
| 58 | + } |
| 59 | + |
| 60 | + if (this.config.get('report').includes('merge_requests')) { |
| 61 | + fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.mergeRequests${extName}`)), this.csvMergeRequests); |
| 62 | + } |
| 63 | + |
| 64 | + if (this.config.get('report').includes('records')) { |
| 65 | + fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.records${extName}`)), this.csvRecords); |
| 66 | + } |
| 67 | + } |
| 68 | + |
46 | 69 | toStdOut() { |
47 | | - this.headline('STATS'); |
48 | | - this.write(this.csvStats); |
49 | | - this.headline('ISSUES'); |
50 | | - this.write(this.csvIssues); |
51 | | - this.headline('MERGE REQUESTS'); |
52 | | - this.write(this.csvMergeRequests); |
53 | | - this.headline('TIME RECORDS'); |
54 | | - this.write(this.csvRecords); |
| 70 | + if (this.config.get('report').includes('state')) { |
| 71 | + this.headline('STATS'); |
| 72 | + this.write(this.csvStats); |
| 73 | + } |
| 74 | + |
| 75 | + if (this.config.get('report').includes('issues')) { |
| 76 | + this.headline('ISSUES'); |
| 77 | + this.write(this.csvIssues); |
| 78 | + } |
| 79 | + |
| 80 | + if (this.config.get('report').includes('merge_requests')) { |
| 81 | + this.headline('MERGE REQUESTS'); |
| 82 | + this.write(this.csvMergeRequests); |
| 83 | + } |
| 84 | + |
| 85 | + if (this.config.get('report').includes('records')) { |
| 86 | + this.headline('TIME RECORDS'); |
| 87 | + this.write(this.csvRecords); |
| 88 | + } |
55 | 89 |
|
56 | 90 | super.toStdOut(); |
57 | 91 | } |
|
0 commit comments