@herodevs/cli 0.1.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -330
- package/dist/commands/{committer/get-all.d.ts → report/committers.d.ts} +3 -3
- package/dist/commands/{committer/get-all.js → report/committers.js} +16 -25
- package/dist/commands/tracker/init.d.ts +8 -0
- package/dist/commands/tracker/init.js +16 -0
- package/dist/commands/tracker/run.d.ts +13 -0
- package/dist/commands/tracker/run.js +38 -0
- package/dist/package.json +25 -10
- package/dist/shared/command/base-command.d.ts +1 -1
- package/dist/shared/lib/version-update.js +11 -6
- package/dist/shared/tracker/default-config.d.ts +3 -0
- package/dist/shared/tracker/default-config.js +19 -0
- package/dist/shared/tracker/initialize.d.ts +1 -0
- package/dist/shared/tracker/initialize.js +15 -0
- package/dist/shared/tracker/models/aggregate-result.d.ts +4 -0
- package/dist/shared/tracker/models/aggregate-result.js +2 -0
- package/dist/shared/tracker/models/category-result.d.ts +7 -0
- package/dist/shared/tracker/models/category-result.js +2 -0
- package/dist/shared/tracker/models/category.d.ts +9 -0
- package/dist/shared/tracker/models/category.js +2 -0
- package/dist/shared/tracker/models/chart-config.d.ts +24 -0
- package/dist/shared/tracker/models/chart-config.js +81 -0
- package/dist/shared/tracker/models/config.d.ts +8 -0
- package/dist/shared/tracker/models/config.js +2 -0
- package/dist/shared/tracker/models/file-result.d.ts +5 -0
- package/dist/shared/tracker/models/file-result.js +2 -0
- package/dist/shared/tracker/models/process-result.d.ts +6 -0
- package/dist/shared/tracker/models/process-result.js +2 -0
- package/dist/shared/tracker/models/result.d.ts +11 -0
- package/dist/shared/tracker/models/result.js +2 -0
- package/dist/shared/tracker/models/total-result.d.ts +4 -0
- package/dist/shared/tracker/models/total-result.js +2 -0
- package/dist/shared/tracker/models/viz-dataset.d.ts +4 -0
- package/dist/shared/tracker/models/viz-dataset.js +2 -0
- package/dist/shared/tracker/models/viz-labels-datasets.d.ts +5 -0
- package/dist/shared/tracker/models/viz-labels-datasets.js +2 -0
- package/dist/shared/tracker/process-category.d.ts +3 -0
- package/dist/shared/tracker/process-category.js +155 -0
- package/dist/shared/tracker/process-config.d.ts +3 -0
- package/dist/shared/tracker/process-config.js +16 -0
- package/dist/shared/tracker/tracker-chart.d.ts +14 -0
- package/dist/shared/tracker/tracker-chart.js +158 -0
- package/dist/shared/tracker/util.d.ts +20 -0
- package/dist/shared/tracker/util.js +92 -0
- package/oclif.manifest.json +41 -31
- package/package.json +25 -10
- package/dist/commands/committer/index.d.ts +0 -9
- package/dist/commands/committer/index.js +0 -15
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const defaultConfig = {
|
|
4
|
+
categories: {
|
|
5
|
+
legacy: {
|
|
6
|
+
fileTypes: ['js', 'ts', 'html', 'css', 'scss', 'less'],
|
|
7
|
+
includes: ['./legacy'],
|
|
8
|
+
jsTsPairs: 'js',
|
|
9
|
+
},
|
|
10
|
+
modern: {
|
|
11
|
+
fileTypes: ['ts', 'html', 'css', 'scss', 'less'],
|
|
12
|
+
includes: ['./modern'],
|
|
13
|
+
jsTsPairs: 'ts',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
ignorePatterns: ['node_modules'],
|
|
17
|
+
outputDir: 'hd-tracker',
|
|
18
|
+
};
|
|
19
|
+
exports.default = defaultConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initialize(rootDir: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initialize = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const default_config_1 = require("./default-config");
|
|
7
|
+
function initialize(rootDir) {
|
|
8
|
+
const output = JSON.stringify(default_config_1.default, null, 2);
|
|
9
|
+
const dir = (0, path_1.join)(rootDir, "hd-tracker");
|
|
10
|
+
if (!(0, fs_1.existsSync)(dir)) {
|
|
11
|
+
(0, fs_1.mkdirSync)(dir);
|
|
12
|
+
}
|
|
13
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(dir, "config.json"), output);
|
|
14
|
+
}
|
|
15
|
+
exports.initialize = initialize;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class ChartConfig {
|
|
2
|
+
private _cliOptions;
|
|
3
|
+
private _perCategoryAndFileType;
|
|
4
|
+
private _perCategoryTotals;
|
|
5
|
+
private _width;
|
|
6
|
+
private _height;
|
|
7
|
+
private _bg;
|
|
8
|
+
private _title;
|
|
9
|
+
private _xAxisLabel;
|
|
10
|
+
private _yAxisLabel;
|
|
11
|
+
private _overwrite;
|
|
12
|
+
private _outFile;
|
|
13
|
+
get perCategoryAndFileType(): boolean;
|
|
14
|
+
get perCategoryTotals(): boolean;
|
|
15
|
+
get width(): number;
|
|
16
|
+
get height(): number;
|
|
17
|
+
get bg(): string;
|
|
18
|
+
get title(): string;
|
|
19
|
+
get xAxisLabel(): string;
|
|
20
|
+
get yAxisLabel(): string;
|
|
21
|
+
get overwrite(): boolean;
|
|
22
|
+
get outFile(): string;
|
|
23
|
+
constructor(_cliOptions?: ChartConfig);
|
|
24
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChartConfig = void 0;
|
|
4
|
+
class ChartConfig {
|
|
5
|
+
get perCategoryAndFileType() {
|
|
6
|
+
// if false, use false; false !== undefined
|
|
7
|
+
return this._cliOptions.perCategoryAndFileType !== undefined ?
|
|
8
|
+
this._cliOptions.perCategoryAndFileType :
|
|
9
|
+
this._perCategoryAndFileType;
|
|
10
|
+
}
|
|
11
|
+
get perCategoryTotals() {
|
|
12
|
+
// if false, use false; false !== undefined
|
|
13
|
+
return this._cliOptions.perCategoryTotals !== undefined ?
|
|
14
|
+
this._cliOptions.perCategoryTotals :
|
|
15
|
+
this._perCategoryTotals;
|
|
16
|
+
}
|
|
17
|
+
get width() {
|
|
18
|
+
// if set and non-numeric
|
|
19
|
+
if (this._cliOptions.width !== undefined && isNaN(Number(this._cliOptions.width))) {
|
|
20
|
+
throw Error('--chart.width must be a number');
|
|
21
|
+
}
|
|
22
|
+
// if unset or numeric
|
|
23
|
+
return this._cliOptions.width !== undefined ?
|
|
24
|
+
this._cliOptions.width :
|
|
25
|
+
this._width;
|
|
26
|
+
}
|
|
27
|
+
get height() {
|
|
28
|
+
// if set and non-numeric
|
|
29
|
+
if (this._cliOptions.height !== undefined && isNaN(Number(this._cliOptions.height))) {
|
|
30
|
+
throw Error('--chart.height must be a number');
|
|
31
|
+
}
|
|
32
|
+
// if unset or numeric
|
|
33
|
+
return this._cliOptions.height !== undefined ?
|
|
34
|
+
this._cliOptions.height :
|
|
35
|
+
this._height;
|
|
36
|
+
}
|
|
37
|
+
get bg() {
|
|
38
|
+
return this._cliOptions.bg ?
|
|
39
|
+
this._cliOptions.bg :
|
|
40
|
+
this._bg;
|
|
41
|
+
}
|
|
42
|
+
get title() {
|
|
43
|
+
return this._cliOptions.title ?
|
|
44
|
+
this._cliOptions.title :
|
|
45
|
+
this._title;
|
|
46
|
+
}
|
|
47
|
+
get xAxisLabel() {
|
|
48
|
+
return this._cliOptions.xAxisLabel ?
|
|
49
|
+
this._cliOptions.xAxisLabel :
|
|
50
|
+
this._xAxisLabel;
|
|
51
|
+
}
|
|
52
|
+
get yAxisLabel() {
|
|
53
|
+
return this._cliOptions.yAxisLabel ?
|
|
54
|
+
this._cliOptions.yAxisLabel :
|
|
55
|
+
this._yAxisLabel;
|
|
56
|
+
}
|
|
57
|
+
get overwrite() {
|
|
58
|
+
return this._cliOptions.overwrite !== undefined ?
|
|
59
|
+
this._cliOptions.overwrite :
|
|
60
|
+
this._overwrite;
|
|
61
|
+
}
|
|
62
|
+
get outFile() {
|
|
63
|
+
return this._cliOptions.outFile ?
|
|
64
|
+
this._cliOptions.outFile :
|
|
65
|
+
this._outFile;
|
|
66
|
+
}
|
|
67
|
+
constructor(_cliOptions = {}) {
|
|
68
|
+
this._cliOptions = _cliOptions;
|
|
69
|
+
this._perCategoryAndFileType = false;
|
|
70
|
+
this._perCategoryTotals = true;
|
|
71
|
+
this._width = 1200;
|
|
72
|
+
this._height = 800;
|
|
73
|
+
this._bg = 'white';
|
|
74
|
+
this._title = 'Migration Progress LOC';
|
|
75
|
+
this._xAxisLabel = 'Date';
|
|
76
|
+
this._yAxisLabel = 'Totals';
|
|
77
|
+
this._overwrite = true;
|
|
78
|
+
this._outFile = 'viz.png';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.ChartConfig = ChartConfig;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processCategory = void 0;
|
|
4
|
+
const sloc = require("sloc");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
function processCategory(rootDirectory, category, ignorePatterns) {
|
|
8
|
+
console.log(`Processing "${category.name}"...`);
|
|
9
|
+
const allFiles = category.includes.reduce((acc, include) => {
|
|
10
|
+
return [...acc, ...findAllFilesInDirectory((0, path_1.join)(rootDirectory, include))];
|
|
11
|
+
}, []);
|
|
12
|
+
const includedFiles = findIncludedFiles(category, ignorePatterns, allFiles);
|
|
13
|
+
console.log(` ${includedFiles.length} files...`);
|
|
14
|
+
const results = includedFiles.map(getFileStats);
|
|
15
|
+
const resultMap = aggregateResults(results);
|
|
16
|
+
const aggregatedResults = Object.values(resultMap).map((val) => val);
|
|
17
|
+
const totals = aggregatedResults.reduce((totals, curr) => ({
|
|
18
|
+
fileCount: totals.fileCount + curr.fileCount,
|
|
19
|
+
total: totals.total + curr.total,
|
|
20
|
+
source: totals.source + curr.source,
|
|
21
|
+
comment: totals.comment + curr.comment,
|
|
22
|
+
single: totals.single + curr.single,
|
|
23
|
+
block: totals.block + curr.block,
|
|
24
|
+
mixed: totals.mixed + curr.mixed,
|
|
25
|
+
empty: totals.empty + curr.empty,
|
|
26
|
+
todo: totals.todo + curr.todo,
|
|
27
|
+
blockEmpty: totals.blockEmpty + curr.blockEmpty,
|
|
28
|
+
}), {
|
|
29
|
+
fileCount: 0,
|
|
30
|
+
total: 0,
|
|
31
|
+
source: 0,
|
|
32
|
+
comment: 0,
|
|
33
|
+
single: 0,
|
|
34
|
+
block: 0,
|
|
35
|
+
mixed: 0,
|
|
36
|
+
empty: 0,
|
|
37
|
+
todo: 0,
|
|
38
|
+
blockEmpty: 0,
|
|
39
|
+
});
|
|
40
|
+
const final = {
|
|
41
|
+
name: category.name,
|
|
42
|
+
totals: totals,
|
|
43
|
+
fileTypes: aggregatedResults,
|
|
44
|
+
};
|
|
45
|
+
console.log(` ${final.totals.total} total lines`);
|
|
46
|
+
return final;
|
|
47
|
+
}
|
|
48
|
+
exports.processCategory = processCategory;
|
|
49
|
+
function aggregateResults(results) {
|
|
50
|
+
return results.reduce((acc, result) => {
|
|
51
|
+
const fileTypeResults = acc[result.fileType];
|
|
52
|
+
if (!fileTypeResults) {
|
|
53
|
+
acc[result.fileType] = {
|
|
54
|
+
fileType: result.fileType,
|
|
55
|
+
fileCount: 1,
|
|
56
|
+
total: result.total,
|
|
57
|
+
source: result.source,
|
|
58
|
+
comment: result.comment,
|
|
59
|
+
single: result.single,
|
|
60
|
+
block: result.block,
|
|
61
|
+
mixed: result.mixed,
|
|
62
|
+
empty: result.empty,
|
|
63
|
+
todo: result.todo,
|
|
64
|
+
blockEmpty: result.blockEmpty,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
acc[result.fileType] = {
|
|
69
|
+
fileType: result.fileType,
|
|
70
|
+
fileCount: fileTypeResults.fileCount + 1,
|
|
71
|
+
total: fileTypeResults.total + result.total,
|
|
72
|
+
source: fileTypeResults.source + result.source,
|
|
73
|
+
comment: fileTypeResults.comment + result.comment,
|
|
74
|
+
single: fileTypeResults.single + result.single,
|
|
75
|
+
block: fileTypeResults.block + result.block,
|
|
76
|
+
mixed: fileTypeResults.mixed + result.mixed,
|
|
77
|
+
empty: fileTypeResults.empty + result.empty,
|
|
78
|
+
todo: fileTypeResults.todo + result.todo,
|
|
79
|
+
blockEmpty: fileTypeResults.blockEmpty + result.blockEmpty,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
83
|
+
}, {});
|
|
84
|
+
}
|
|
85
|
+
function getFileStats(file) {
|
|
86
|
+
const contents = (0, fs_1.readFileSync)(file).toString('utf-8');
|
|
87
|
+
const fileType = getFileExt(file);
|
|
88
|
+
const stats = sloc(contents, fileType);
|
|
89
|
+
return {
|
|
90
|
+
path: file,
|
|
91
|
+
fileType: fileType,
|
|
92
|
+
...stats,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function findIncludedFiles(category, ignorePatterns, allFiles) {
|
|
96
|
+
return allFiles
|
|
97
|
+
.filter((file) => {
|
|
98
|
+
var _a;
|
|
99
|
+
const ext = getFileExt(file);
|
|
100
|
+
let shouldBeIncluded = !!category.fileTypes.find((fileType) => fileType === ext);
|
|
101
|
+
if (shouldBeIncluded) {
|
|
102
|
+
ignorePatterns === null || ignorePatterns === void 0 ? void 0 : ignorePatterns.forEach((ignorePattern) => {
|
|
103
|
+
if (file.indexOf(ignorePattern) !== -1) {
|
|
104
|
+
shouldBeIncluded = false;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (shouldBeIncluded) {
|
|
109
|
+
(_a = category.excludes) === null || _a === void 0 ? void 0 : _a.forEach((exclude) => {
|
|
110
|
+
if (file.indexOf(exclude) !== -1) {
|
|
111
|
+
shouldBeIncluded = false;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return shouldBeIncluded;
|
|
116
|
+
})
|
|
117
|
+
.filter((file, _index, files) => {
|
|
118
|
+
if (category.jsTsPairs === 'ignore' || category.jsTsPairs === undefined) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
const fileExtToKeep = category.jsTsPairs;
|
|
122
|
+
const ext = getFileExt(file);
|
|
123
|
+
const fileExtToDiscard = fileExtToKeep === 'js' ? 'ts' : 'js';
|
|
124
|
+
// if it is the extension to keep
|
|
125
|
+
// or if it is not the one to discard, we keep those files
|
|
126
|
+
if (fileExtToKeep === ext || fileExtToDiscard !== ext) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
// get the counterpart's extension
|
|
130
|
+
const counterpartExt = ext === 'js' ? 'ts' : 'js';
|
|
131
|
+
const parts = file.split('.');
|
|
132
|
+
parts[parts.length - 1] = counterpartExt;
|
|
133
|
+
const counterpartExists = files.filter((f) => f === parts.join('.')).length !== 0;
|
|
134
|
+
if (counterpartExists) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function findAllFilesInDirectory(directory) {
|
|
141
|
+
const results = (0, fs_1.readdirSync)(directory);
|
|
142
|
+
const subfiles = results
|
|
143
|
+
.filter((result) => (0, fs_1.lstatSync)((0, path_1.join)(directory, result)).isDirectory())
|
|
144
|
+
.reduce((acc, subdir) => {
|
|
145
|
+
const files = findAllFilesInDirectory((0, path_1.join)(directory, subdir));
|
|
146
|
+
return [...acc, ...files];
|
|
147
|
+
}, []);
|
|
148
|
+
const files = results
|
|
149
|
+
.filter((result) => (0, fs_1.lstatSync)((0, path_1.join)(directory, result)).isFile())
|
|
150
|
+
.map((fileName) => (0, path_1.join)(directory, fileName));
|
|
151
|
+
return [...files, ...subfiles];
|
|
152
|
+
}
|
|
153
|
+
function getFileExt(file) {
|
|
154
|
+
return (0, path_1.extname)(file).replace(/\./g, '');
|
|
155
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processConfig = void 0;
|
|
4
|
+
const process_category_1 = require("./process-category");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
async function processConfig(config, rootDirectory) {
|
|
7
|
+
console.log(`Starting...`);
|
|
8
|
+
const categoryResults = Object.entries(config.categories).map(([name, category]) => (0, process_category_1.processCategory)(rootDirectory, { ...category, name }, config.ignorePatterns || []));
|
|
9
|
+
const commit = await (0, util_1.getGitCommit)();
|
|
10
|
+
return {
|
|
11
|
+
timestamp: commit.timestamp,
|
|
12
|
+
hash: commit.hash,
|
|
13
|
+
categories: categoryResults,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.processConfig = processConfig;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AggregateResult } from './models/aggregate-result';
|
|
2
|
+
import { ChartConfig } from './models/chart-config';
|
|
3
|
+
import { ProcessResult } from './models/process-result';
|
|
4
|
+
export declare class TrackerChart {
|
|
5
|
+
private _config;
|
|
6
|
+
private _allProcessResults;
|
|
7
|
+
private _dateFormat;
|
|
8
|
+
constructor(_config: ChartConfig, _allProcessResults: ProcessResult[], _dateFormat: string);
|
|
9
|
+
private getDataAndLabels;
|
|
10
|
+
private getTotalsPerFileTypePerCategory;
|
|
11
|
+
private getTotalsPerCategory;
|
|
12
|
+
private generateGraphImageFile;
|
|
13
|
+
writeTo(parentDirectory: string, graphablePropertyName?: keyof AggregateResult): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrackerChart = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const date_fns_1 = require("date-fns");
|
|
7
|
+
const chartjs_node_canvas_1 = require("chartjs-node-canvas");
|
|
8
|
+
const ChartDataLabels = require("chartjs-plugin-datalabels");
|
|
9
|
+
const autocolors = require("chartjs-plugin-autocolors");
|
|
10
|
+
class TrackerChart {
|
|
11
|
+
constructor(_config, _allProcessResults, _dateFormat) {
|
|
12
|
+
this._config = _config;
|
|
13
|
+
this._allProcessResults = _allProcessResults;
|
|
14
|
+
this._dateFormat = _dateFormat;
|
|
15
|
+
}
|
|
16
|
+
getDataAndLabels(allJsonData, propName) {
|
|
17
|
+
if (this._config.perCategoryTotals) {
|
|
18
|
+
return this.getTotalsPerCategory(allJsonData, propName);
|
|
19
|
+
}
|
|
20
|
+
if (this._config.perCategoryAndFileType) {
|
|
21
|
+
return this.getTotalsPerFileTypePerCategory(allJsonData, propName);
|
|
22
|
+
}
|
|
23
|
+
return this.getTotalsPerCategory(allJsonData, propName);
|
|
24
|
+
}
|
|
25
|
+
getTotalsPerFileTypePerCategory(allJsonData, propName) {
|
|
26
|
+
const runs = {};
|
|
27
|
+
const allTypes = {};
|
|
28
|
+
allJsonData.forEach((jsonData, i) => {
|
|
29
|
+
runs[jsonData.hash] = jsonData.timestamp;
|
|
30
|
+
jsonData.categories.forEach((category) => {
|
|
31
|
+
category.fileTypes.forEach((t) => {
|
|
32
|
+
const label = `${category.name}: ${t.fileType}`;
|
|
33
|
+
if (!allTypes[label]) {
|
|
34
|
+
allTypes[label] = {
|
|
35
|
+
label,
|
|
36
|
+
data: []
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
allTypes[label].data[i] = t[propName];
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
const labels = Object.values(runs);
|
|
44
|
+
const datasets = Object.values(allTypes).map((t) => {
|
|
45
|
+
return {
|
|
46
|
+
...t,
|
|
47
|
+
fill: false,
|
|
48
|
+
tension: .1
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
labels,
|
|
53
|
+
datasets,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
getTotalsPerCategory(allJsonData, propName) {
|
|
57
|
+
const runs = {};
|
|
58
|
+
const allTypes = {};
|
|
59
|
+
allJsonData.forEach((jsonData, i) => {
|
|
60
|
+
runs[jsonData.hash] = jsonData.timestamp;
|
|
61
|
+
jsonData.categories.forEach((category) => {
|
|
62
|
+
const label = category.name;
|
|
63
|
+
if (!allTypes[label]) {
|
|
64
|
+
allTypes[label] = {
|
|
65
|
+
label,
|
|
66
|
+
data: []
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
allTypes[label].data[i] = category.totals[propName];
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
const labels = Object.values(runs);
|
|
73
|
+
const datasets = Object.values(allTypes).map((t) => {
|
|
74
|
+
return {
|
|
75
|
+
...t,
|
|
76
|
+
fill: false,
|
|
77
|
+
tension: .1
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
labels,
|
|
82
|
+
datasets,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async generateGraphImageFile(parentDirectory, vizData) {
|
|
86
|
+
const outFile = (0, path_1.join)(parentDirectory, this._config.outFile);
|
|
87
|
+
if (this._config.overwrite && (0, fs_1.existsSync)(outFile)) {
|
|
88
|
+
(0, fs_1.rmSync)(outFile);
|
|
89
|
+
}
|
|
90
|
+
const dateFmt = this._dateFormat;
|
|
91
|
+
const configuration = {
|
|
92
|
+
type: 'line',
|
|
93
|
+
data: vizData,
|
|
94
|
+
options: {
|
|
95
|
+
elements: {
|
|
96
|
+
point: {
|
|
97
|
+
radius: 0
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
plugins: {
|
|
101
|
+
title: {
|
|
102
|
+
display: true,
|
|
103
|
+
text: this._config.title
|
|
104
|
+
},
|
|
105
|
+
autocolors: {
|
|
106
|
+
enabled: true,
|
|
107
|
+
mode: 'data',
|
|
108
|
+
},
|
|
109
|
+
scales: {
|
|
110
|
+
x: {
|
|
111
|
+
type: 'timeseries',
|
|
112
|
+
time: {
|
|
113
|
+
minUnit: 'week',
|
|
114
|
+
},
|
|
115
|
+
parsing: false,
|
|
116
|
+
title: {
|
|
117
|
+
display: true,
|
|
118
|
+
text: this._config.xAxisLabel
|
|
119
|
+
},
|
|
120
|
+
ticks: {
|
|
121
|
+
source: 'data',
|
|
122
|
+
callback: function (val) {
|
|
123
|
+
return (0, date_fns_1.format)((0, date_fns_1.parse)(this.getLabelForValue(val), dateFmt, new Date()), 'yyyy-MM-dd');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
y: {
|
|
128
|
+
title: {
|
|
129
|
+
display: true,
|
|
130
|
+
text: this._config.yAxisLabel
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
try {
|
|
138
|
+
const pieChart = new chartjs_node_canvas_1.ChartJSNodeCanvas({
|
|
139
|
+
width: this._config.width,
|
|
140
|
+
height: this._config.height,
|
|
141
|
+
backgroundColour: this._config.bg,
|
|
142
|
+
plugins: {
|
|
143
|
+
modern: [ChartDataLabels, autocolors],
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
const result = await pieChart.renderToBuffer(configuration);
|
|
147
|
+
(0, fs_1.writeFileSync)(outFile, result);
|
|
148
|
+
}
|
|
149
|
+
catch (exc) {
|
|
150
|
+
console.error(exc);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
writeTo(parentDirectory, graphablePropertyName = 'total') {
|
|
154
|
+
const vizData = this.getDataAndLabels(this._allProcessResults, graphablePropertyName);
|
|
155
|
+
return this.generateGraphImageFile(parentDirectory, vizData);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.TrackerChart = TrackerChart;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Config } from './models/config';
|
|
2
|
+
import { ProcessResult } from './models/process-result';
|
|
3
|
+
import { AggregateResult } from './models/aggregate-result';
|
|
4
|
+
import { ChartConfig } from './models/chart-config';
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* exported alphabetized util functions ->
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDataVizIn(chartConfig: ChartConfig, parentDirectory: string, allJsonData: ProcessResult[], graphablePropertyName?: keyof AggregateResult): Promise<void>;
|
|
13
|
+
export declare function getData(localRootDir: string, outputDir: string): any;
|
|
14
|
+
export declare function getGitCommit(): Promise<{
|
|
15
|
+
hash: string;
|
|
16
|
+
timestamp: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function getTheRootDirectory(directory: string): string;
|
|
19
|
+
export declare function readConfig(rootDirectory: string, optionsPath?: string): Config;
|
|
20
|
+
export declare function saveResults(localRootDir: string, outputDir: string, results: ProcessResult): void;
|