@herodevs/cli 0.2.1 → 0.2.2
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/dist/commands/tracker/init.d.ts +8 -0
- package/dist/commands/tracker/init.js +16 -0
- package/dist/commands/tracker/run.d.ts +11 -0
- package/dist/commands/tracker/run.js +37 -0
- package/dist/package.json +4 -1
- 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 +65 -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 +0 -0
- package/dist/shared/tracker/tracker-chart.js +156 -0
- package/dist/shared/tracker/util.d.ts +17 -0
- package/dist/shared/tracker/util.js +98 -0
- package/oclif.manifest.json +46 -3
- package/package.json +4 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrackerInit = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const initialize_1 = require("../../shared/tracker/initialize");
|
|
6
|
+
const util_1 = require("../../shared/tracker/util");
|
|
7
|
+
class TrackerInit extends core_1.Command {
|
|
8
|
+
async run() {
|
|
9
|
+
(0, initialize_1.initialize)((0, util_1.getTheRootDirectory)(global.process.cwd()));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.TrackerInit = TrackerInit;
|
|
13
|
+
TrackerInit.description = 'Initialize the tracker configuration';
|
|
14
|
+
TrackerInit.examples = ['<%= config.bin %> <%= command.id %>'];
|
|
15
|
+
TrackerInit.flags = {};
|
|
16
|
+
TrackerInit.args = {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export declare class TrackerRun extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
root: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
};
|
|
9
|
+
static args: {};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrackerRun = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const util_1 = require("../../shared/tracker/util");
|
|
7
|
+
const process_config_1 = require("../../shared/tracker/process-config");
|
|
8
|
+
// import { ChartConfig } from '../../shared/tracker/models/chart-config';
|
|
9
|
+
class TrackerRun extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const { flags } = await this.parse(TrackerRun);
|
|
12
|
+
const localRootDir = (0, util_1.getTheRootDirectory)(global.process.cwd());
|
|
13
|
+
const rootDirectory = flags.root ? (0, path_1.resolve)(flags.root) : localRootDir;
|
|
14
|
+
const config = (0, util_1.readConfig)(localRootDir, flags.config);
|
|
15
|
+
const results = await (0, process_config_1.processConfig)(config, rootDirectory);
|
|
16
|
+
(0, util_1.saveResults)(localRootDir, config.outputDir, results);
|
|
17
|
+
const allData = (0, util_1.getData)(localRootDir, config.outputDir);
|
|
18
|
+
const parentDir = (0, path_1.resolve)(localRootDir, config.outputDir);
|
|
19
|
+
// const chartConfig = new ChartConfig(flags.chart);
|
|
20
|
+
// try {
|
|
21
|
+
// await createDataVizIn(chartConfig, parentDir, allData);
|
|
22
|
+
// } catch (error) {
|
|
23
|
+
// console.log('Error creating visualization');
|
|
24
|
+
// }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TrackerRun = TrackerRun;
|
|
28
|
+
TrackerRun.description = 'Run the tracker';
|
|
29
|
+
TrackerRun.examples = ['<%= config.bin %> <%= command.id %>'];
|
|
30
|
+
TrackerRun.flags = {
|
|
31
|
+
root: core_1.Flags.string({ char: 'r', description: 'root dir of the project' }),
|
|
32
|
+
config: core_1.Flags.string({ char: 'c', description: 'path to config file' }),
|
|
33
|
+
// chart: Flags.custom<ChartConfig>({
|
|
34
|
+
// description: 'chart configuration',
|
|
35
|
+
// })(),
|
|
36
|
+
};
|
|
37
|
+
TrackerRun.args = {};
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herodevs/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "HeroDevs CLI",
|
|
5
5
|
"author": "@herodevs",
|
|
6
6
|
"bin": {
|
|
@@ -56,6 +56,9 @@
|
|
|
56
56
|
"topics": {
|
|
57
57
|
"report": {
|
|
58
58
|
"description": "Run reports for the current project (commands: committers)"
|
|
59
|
+
},
|
|
60
|
+
"tracker": {
|
|
61
|
+
"description": "Track project progress based upon lines of code (commands: init, run)"
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
},
|
|
@@ -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,65 @@
|
|
|
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 ? this._cliOptions.width : this._width;
|
|
24
|
+
}
|
|
25
|
+
get height() {
|
|
26
|
+
// if set and non-numeric
|
|
27
|
+
if (this._cliOptions.height !== undefined && isNaN(Number(this._cliOptions.height))) {
|
|
28
|
+
throw Error('--chart.height must be a number');
|
|
29
|
+
}
|
|
30
|
+
// if unset or numeric
|
|
31
|
+
return this._cliOptions.height !== undefined ? this._cliOptions.height : this._height;
|
|
32
|
+
}
|
|
33
|
+
get bg() {
|
|
34
|
+
return this._cliOptions.bg ? this._cliOptions.bg : this._bg;
|
|
35
|
+
}
|
|
36
|
+
get title() {
|
|
37
|
+
return this._cliOptions.title ? this._cliOptions.title : this._title;
|
|
38
|
+
}
|
|
39
|
+
get xAxisLabel() {
|
|
40
|
+
return this._cliOptions.xAxisLabel ? this._cliOptions.xAxisLabel : this._xAxisLabel;
|
|
41
|
+
}
|
|
42
|
+
get yAxisLabel() {
|
|
43
|
+
return this._cliOptions.yAxisLabel ? this._cliOptions.yAxisLabel : this._yAxisLabel;
|
|
44
|
+
}
|
|
45
|
+
get overwrite() {
|
|
46
|
+
return this._cliOptions.overwrite !== undefined ? this._cliOptions.overwrite : this._overwrite;
|
|
47
|
+
}
|
|
48
|
+
get outFile() {
|
|
49
|
+
return this._cliOptions.outFile ? this._cliOptions.outFile : this._outFile;
|
|
50
|
+
}
|
|
51
|
+
constructor(_cliOptions = {}) {
|
|
52
|
+
this._cliOptions = _cliOptions;
|
|
53
|
+
this._perCategoryAndFileType = false;
|
|
54
|
+
this._perCategoryTotals = true;
|
|
55
|
+
this._width = 1200;
|
|
56
|
+
this._height = 800;
|
|
57
|
+
this._bg = 'white';
|
|
58
|
+
this._title = 'Migration Progress LOC';
|
|
59
|
+
this._xAxisLabel = 'Date';
|
|
60
|
+
this._yAxisLabel = 'Totals';
|
|
61
|
+
this._overwrite = true;
|
|
62
|
+
this._outFile = 'viz.png';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
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;
|
|
File without changes
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// import { join } from 'path';
|
|
2
|
+
// import { AggregateResult } from './models/aggregate-result';
|
|
3
|
+
// import { ChartConfig } from './models/chart-config';
|
|
4
|
+
// import { ProcessResult } from './models/process-result';
|
|
5
|
+
// import { VizDataset } from './models/viz-dataset';
|
|
6
|
+
// import { VizLabelsDatasets } from './models/viz-labels-datasets';
|
|
7
|
+
// import { existsSync, rmSync, writeFileSync } from 'fs';
|
|
8
|
+
// import { format, parse } from 'date-fns';
|
|
9
|
+
// import { ChartJSNodeCanvas } from 'chartjs-node-canvas';
|
|
10
|
+
// import * as ChartDataLabels from 'chartjs-plugin-datalabels';
|
|
11
|
+
// import * as autocolors from 'chartjs-plugin-autocolors';
|
|
12
|
+
// import { ChartConfiguration } from 'chart.js';
|
|
13
|
+
// export class TrackerChart {
|
|
14
|
+
// constructor(private _config: ChartConfig, private _allProcessResults: ProcessResult[], private _dateFormat: string) { }
|
|
15
|
+
// private getDataAndLabels(allJsonData, propName: string): VizLabelsDatasets {
|
|
16
|
+
// if (this._config.perCategoryTotals) {
|
|
17
|
+
// return this.getTotalsPerCategory(allJsonData, propName);
|
|
18
|
+
// }
|
|
19
|
+
// if (this._config.perCategoryAndFileType) {
|
|
20
|
+
// return this.getTotalsPerFileTypePerCategory(allJsonData, propName);
|
|
21
|
+
// }
|
|
22
|
+
// return this.getTotalsPerCategory(allJsonData, propName);
|
|
23
|
+
// }
|
|
24
|
+
// private getTotalsPerFileTypePerCategory(allJsonData, propName: string): VizLabelsDatasets {
|
|
25
|
+
// const runs = { };
|
|
26
|
+
// const allTypes = { };
|
|
27
|
+
// allJsonData.forEach((jsonData: ProcessResult, i) => {
|
|
28
|
+
// runs[jsonData.hash] = jsonData.timestamp;
|
|
29
|
+
// jsonData.categories.forEach((category) => {
|
|
30
|
+
// category.fileTypes.forEach((t) => {
|
|
31
|
+
// const label = `${category.name}: ${t.fileType}`;
|
|
32
|
+
// if (!allTypes[label]) {
|
|
33
|
+
// allTypes[label] = {
|
|
34
|
+
// label,
|
|
35
|
+
// data: []
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
// allTypes[label].data[i] = t[propName];
|
|
39
|
+
// });
|
|
40
|
+
// });
|
|
41
|
+
// });
|
|
42
|
+
// const labels = Object.values(runs) as string[];
|
|
43
|
+
// const datasets = Object.values(allTypes).map((t: VizDataset) => {
|
|
44
|
+
// return {
|
|
45
|
+
// ...t,
|
|
46
|
+
// fill: false,
|
|
47
|
+
// tension: .1
|
|
48
|
+
// }
|
|
49
|
+
// }) as VizDataset[];
|
|
50
|
+
// return {
|
|
51
|
+
// labels,
|
|
52
|
+
// datasets,
|
|
53
|
+
// };
|
|
54
|
+
// }
|
|
55
|
+
// private getTotalsPerCategory(allJsonData, propName: string): VizLabelsDatasets {
|
|
56
|
+
// const runs = { };
|
|
57
|
+
// const allTypes = { };
|
|
58
|
+
// allJsonData.forEach((jsonData: ProcessResult, i) => {
|
|
59
|
+
// runs[jsonData.hash] = jsonData.timestamp;
|
|
60
|
+
// jsonData.categories.forEach((category) => {
|
|
61
|
+
// const label = category.name;
|
|
62
|
+
// if (!allTypes[label]) {
|
|
63
|
+
// allTypes[label] = {
|
|
64
|
+
// label,
|
|
65
|
+
// data: []
|
|
66
|
+
// };
|
|
67
|
+
// }
|
|
68
|
+
// allTypes[label].data[i] = category.totals[propName];
|
|
69
|
+
// });
|
|
70
|
+
// });
|
|
71
|
+
// const labels = Object.values(runs) as string[];
|
|
72
|
+
// const datasets = Object.values(allTypes).map((t: VizDataset) => {
|
|
73
|
+
// return {
|
|
74
|
+
// ...t,
|
|
75
|
+
// fill: false,
|
|
76
|
+
// tension: .1
|
|
77
|
+
// }
|
|
78
|
+
// }) as VizDataset[];
|
|
79
|
+
// return {
|
|
80
|
+
// labels,
|
|
81
|
+
// datasets,
|
|
82
|
+
// };
|
|
83
|
+
// }
|
|
84
|
+
// private async generateGraphImageFile(parentDirectory: string, vizData: VizLabelsDatasets): Promise<void> {
|
|
85
|
+
// const outFile = join(parentDirectory, this._config.outFile);
|
|
86
|
+
// if (this._config.overwrite && existsSync(outFile)) { rmSync(outFile); }
|
|
87
|
+
// const dateFmt = this._dateFormat;
|
|
88
|
+
// const configuration = {
|
|
89
|
+
// type: 'line',
|
|
90
|
+
// data: vizData,
|
|
91
|
+
// options: {
|
|
92
|
+
// elements: {
|
|
93
|
+
// point:{
|
|
94
|
+
// radius: 0
|
|
95
|
+
// }
|
|
96
|
+
// },
|
|
97
|
+
// plugins: {
|
|
98
|
+
// title: {
|
|
99
|
+
// display: true,
|
|
100
|
+
// text: this._config.title
|
|
101
|
+
// },
|
|
102
|
+
// autocolors: {
|
|
103
|
+
// enabled: true,
|
|
104
|
+
// mode: 'data',
|
|
105
|
+
// },
|
|
106
|
+
// scales: {
|
|
107
|
+
// x: {
|
|
108
|
+
// type: 'timeseries',
|
|
109
|
+
// time: {
|
|
110
|
+
// minUnit: 'week',
|
|
111
|
+
// },
|
|
112
|
+
// parsing: false,
|
|
113
|
+
// title: {
|
|
114
|
+
// display: true,
|
|
115
|
+
// text: this._config.xAxisLabel
|
|
116
|
+
// },
|
|
117
|
+
// ticks: {
|
|
118
|
+
// source: 'data',
|
|
119
|
+
// callback: function(val) {
|
|
120
|
+
// return format(
|
|
121
|
+
// parse(this.getLabelForValue(val), dateFmt, new Date()),
|
|
122
|
+
// 'yyyy-MM-dd'
|
|
123
|
+
// );
|
|
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 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 as ChartConfiguration);
|
|
147
|
+
// writeFileSync(outFile, result);
|
|
148
|
+
// } catch (exc) {
|
|
149
|
+
// console.error(exc);
|
|
150
|
+
// }
|
|
151
|
+
// }
|
|
152
|
+
// writeTo(parentDirectory: string, graphablePropertyName: keyof AggregateResult = 'total'): Promise<void> {
|
|
153
|
+
// const vizData = this.getDataAndLabels(this._allProcessResults, graphablePropertyName);
|
|
154
|
+
// return this.generateGraphImageFile(parentDirectory, vizData);
|
|
155
|
+
// }
|
|
156
|
+
// }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Config } from './models/config';
|
|
2
|
+
import { ProcessResult } from './models/process-result';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* exported alphabetized util functions ->
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function getData(localRootDir: string, outputDir: string): any;
|
|
11
|
+
export declare function getGitCommit(): Promise<{
|
|
12
|
+
hash: string;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function getTheRootDirectory(directory: string): string;
|
|
16
|
+
export declare function readConfig(rootDirectory: string, optionsPath?: string): Config;
|
|
17
|
+
export declare function saveResults(localRootDir: string, outputDir: string, results: ProcessResult): void;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveResults = exports.readConfig = exports.getTheRootDirectory = exports.getGitCommit = exports.getData = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const date_fns_1 = require("date-fns");
|
|
7
|
+
const git_last_commit_1 = require("git-last-commit");
|
|
8
|
+
// import { AggregateResult } from './models/aggregate-result';
|
|
9
|
+
// import { TrackerChart } from './tracker-chart';
|
|
10
|
+
// import { ChartConfig } from './models/chart-config';
|
|
11
|
+
const DATE_FORMAT = 'yyyy-MM-dd-HH-mm-ss-SSS';
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* internal alphabetized helper functions ->
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
function formatDate(date) {
|
|
20
|
+
return (0, date_fns_1.format)(date, DATE_FORMAT);
|
|
21
|
+
}
|
|
22
|
+
function getDataFilePath(localRootDir, outputDir) {
|
|
23
|
+
return (0, path_1.resolve)((0, path_1.join)(localRootDir, outputDir, 'data.json'));
|
|
24
|
+
}
|
|
25
|
+
function getGitDate(date) {
|
|
26
|
+
return new Date(+date * 1000);
|
|
27
|
+
}
|
|
28
|
+
function getLastCommitAsPromise() {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
(0, git_last_commit_1.getLastCommit)((err, commit) => {
|
|
31
|
+
if (err) {
|
|
32
|
+
reject(err);
|
|
33
|
+
}
|
|
34
|
+
resolve(commit);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
*
|
|
42
|
+
* exported alphabetized util functions ->
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
// export async function createDataVizIn(
|
|
46
|
+
// chartConfig: ChartConfig,
|
|
47
|
+
// parentDirectory: string,
|
|
48
|
+
// allJsonData: ProcessResult[],
|
|
49
|
+
// graphablePropertyName: keyof AggregateResult = 'total'
|
|
50
|
+
// ): Promise<void> {
|
|
51
|
+
// const chart = new TrackerChart(chartConfig, allJsonData, DATE_FORMAT);
|
|
52
|
+
// return chart.writeTo(parentDirectory, graphablePropertyName);
|
|
53
|
+
// }
|
|
54
|
+
function getData(localRootDir, outputDir) {
|
|
55
|
+
const outputPath = getDataFilePath(localRootDir, outputDir);
|
|
56
|
+
let contents = '';
|
|
57
|
+
if ((0, fs_1.existsSync)(outputPath)) {
|
|
58
|
+
contents = (0, fs_1.readFileSync)(outputPath).toString('utf-8');
|
|
59
|
+
}
|
|
60
|
+
return contents === '' ? [] : JSON.parse(contents);
|
|
61
|
+
}
|
|
62
|
+
exports.getData = getData;
|
|
63
|
+
async function getGitCommit() {
|
|
64
|
+
const commit = await getLastCommitAsPromise();
|
|
65
|
+
return {
|
|
66
|
+
hash: commit.hash,
|
|
67
|
+
timestamp: formatDate(getGitDate(commit.committedOn)),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.getGitCommit = getGitCommit;
|
|
71
|
+
function getTheRootDirectory(directory) {
|
|
72
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(directory, 'package.json'))) {
|
|
73
|
+
return directory;
|
|
74
|
+
}
|
|
75
|
+
return getTheRootDirectory((0, path_1.resolve)((0, path_1.join)(directory, '..')));
|
|
76
|
+
}
|
|
77
|
+
exports.getTheRootDirectory = getTheRootDirectory;
|
|
78
|
+
function readConfig(rootDirectory, optionsPath) {
|
|
79
|
+
const path = optionsPath && (0, fs_1.existsSync)((0, path_1.join)(rootDirectory, optionsPath))
|
|
80
|
+
? (0, path_1.join)(rootDirectory, optionsPath)
|
|
81
|
+
: (0, path_1.join)(rootDirectory, 'hd-tracker', 'config.json');
|
|
82
|
+
const contents = (0, fs_1.readFileSync)(path).toString('utf-8');
|
|
83
|
+
return JSON.parse(contents);
|
|
84
|
+
}
|
|
85
|
+
exports.readConfig = readConfig;
|
|
86
|
+
function saveResults(localRootDir, outputDir, results) {
|
|
87
|
+
console.log('Outputting file');
|
|
88
|
+
const output = getData(localRootDir, outputDir);
|
|
89
|
+
if (!Array.isArray(output)) {
|
|
90
|
+
console.error('Invalid output file format');
|
|
91
|
+
}
|
|
92
|
+
output.push(results);
|
|
93
|
+
const outputPath = getDataFilePath(localRootDir, outputDir);
|
|
94
|
+
const outputText = JSON.stringify(output, null, 2);
|
|
95
|
+
(0, fs_1.writeFileSync)(outputPath, outputText);
|
|
96
|
+
console.log(`Output written to: ${outputPath}`);
|
|
97
|
+
}
|
|
98
|
+
exports.saveResults = saveResults;
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.2",
|
|
3
3
|
"commands": {
|
|
4
4
|
"report:committers": {
|
|
5
5
|
"id": "report:committers",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"summary": "Start Date (format: yyyy-MM-dd)",
|
|
42
42
|
"required": false,
|
|
43
43
|
"multiple": false,
|
|
44
|
-
"default": "2024-03-
|
|
44
|
+
"default": "2024-03-06"
|
|
45
45
|
},
|
|
46
46
|
"endDate": {
|
|
47
47
|
"name": "endDate",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"summary": "End Date (format: yyyy-MM-dd)",
|
|
51
51
|
"required": false,
|
|
52
52
|
"multiple": false,
|
|
53
|
-
"default": "2023-03-
|
|
53
|
+
"default": "2023-03-06"
|
|
54
54
|
},
|
|
55
55
|
"exclude": {
|
|
56
56
|
"name": "exclude",
|
|
@@ -70,6 +70,49 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"args": {}
|
|
73
|
+
},
|
|
74
|
+
"tracker:init": {
|
|
75
|
+
"id": "tracker:init",
|
|
76
|
+
"description": "Initialize the tracker configuration",
|
|
77
|
+
"strict": true,
|
|
78
|
+
"pluginName": "@herodevs/cli",
|
|
79
|
+
"pluginAlias": "@herodevs/cli",
|
|
80
|
+
"pluginType": "core",
|
|
81
|
+
"aliases": [],
|
|
82
|
+
"examples": [
|
|
83
|
+
"<%= config.bin %> <%= command.id %>"
|
|
84
|
+
],
|
|
85
|
+
"flags": {},
|
|
86
|
+
"args": {}
|
|
87
|
+
},
|
|
88
|
+
"tracker:run": {
|
|
89
|
+
"id": "tracker:run",
|
|
90
|
+
"description": "Run the tracker",
|
|
91
|
+
"strict": true,
|
|
92
|
+
"pluginName": "@herodevs/cli",
|
|
93
|
+
"pluginAlias": "@herodevs/cli",
|
|
94
|
+
"pluginType": "core",
|
|
95
|
+
"aliases": [],
|
|
96
|
+
"examples": [
|
|
97
|
+
"<%= config.bin %> <%= command.id %>"
|
|
98
|
+
],
|
|
99
|
+
"flags": {
|
|
100
|
+
"root": {
|
|
101
|
+
"name": "root",
|
|
102
|
+
"type": "option",
|
|
103
|
+
"char": "r",
|
|
104
|
+
"description": "root dir of the project",
|
|
105
|
+
"multiple": false
|
|
106
|
+
},
|
|
107
|
+
"config": {
|
|
108
|
+
"name": "config",
|
|
109
|
+
"type": "option",
|
|
110
|
+
"char": "c",
|
|
111
|
+
"description": "path to config file",
|
|
112
|
+
"multiple": false
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"args": {}
|
|
73
116
|
}
|
|
74
117
|
}
|
|
75
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herodevs/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "HeroDevs CLI",
|
|
5
5
|
"author": "@herodevs",
|
|
6
6
|
"bin": {
|
|
@@ -56,6 +56,9 @@
|
|
|
56
56
|
"topics": {
|
|
57
57
|
"report": {
|
|
58
58
|
"description": "Run reports for the current project (commands: committers)"
|
|
59
|
+
},
|
|
60
|
+
"tracker": {
|
|
61
|
+
"description": "Track project progress based upon lines of code (commands: init, run)"
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
},
|