project-analyzer
Version:
Node cli utility for analyzing project complexity structure
84 lines • 4.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sortDirectoryStructure = exports.getDirectoryStructure = exports.getComplexityScore = exports.runAnalysis = void 0;
const lib_1 = require("./lib");
Object.defineProperty(exports, "sortDirectoryStructure", { enumerable: true, get: function () { return lib_1.sortDirectoryStructure; } });
Object.defineProperty(exports, "getDirectoryStructure", { enumerable: true, get: function () { return lib_1.getDirectoryStructure; } });
Object.defineProperty(exports, "getComplexityScore", { enumerable: true, get: function () { return lib_1.getComplexityScore; } });
const finalReport_json_1 = __importDefault(require("./data/finalReport.json"));
function runAnalysis(config) {
const _config = config || (0, lib_1.collectArgs)();
// Kill consoles if silent mode is activated
(0, lib_1.silentMode)((_config === null || _config === void 0 ? void 0 : _config.silent) || false);
// Splash screen
(0, lib_1.createSpacer)(2);
(0, lib_1.logWithColor)("magenta", (0, lib_1.createSplashScreen)());
(0, lib_1.logWithColor)("green", "Starting analysis...");
(0, lib_1.createSpacer)(2);
// Get the ignore patterns, for folder analysis,
//.gitigonre + standard list is used
const ignorePatterns = (0, lib_1.getPatterns)();
// Get the directory structure
const data = (0, lib_1.getDirectoryStructure)(process.cwd(), ignorePatterns);
if (!data) {
(0, lib_1.logWithColor)("red", "Error reading directory structure");
throw new Error("Error reading directory structure");
}
// sort the first level of children, move the .files to the end
const structure = data === null || data === void 0 ? void 0 : data.item;
// Sort the top level of the structure
const finalStructure = Object.assign(Object.assign({}, structure), ((structure === null || structure === void 0 ? void 0 : structure.children) && {
children: (0, lib_1.sortDirectoryStructure)(structure.children),
}));
// -t, --tree
// output folder structure as a tree
if (_config === null || _config === void 0 ? void 0 : _config.tree) {
(0, lib_1.createSpacer)(2);
(0, lib_1.printTree)(finalStructure);
(0, lib_1.createSpacer)(2);
}
const dataStats = data === null || data === void 0 ? void 0 : data.stats;
if (!dataStats ||
!dataStats.files ||
!dataStats.folders ||
!dataStats.chars ||
!dataStats.codelines ||
!dataStats.deepestLevel) {
(0, lib_1.logWithColor)("red", "Error reading directory stats, exiting");
throw new Error("Error reading directory stats");
}
const finalScore = (0, lib_1.getComplexityScore)(dataStats);
const table = (0, lib_1.createTable)(["Metric", "Value"], Object.entries(dataStats).map(([key, value]) => [key, value.toString()]));
(0, lib_1.createSpacer)(2);
(0, lib_1.logWithColor)("green", "Analysis complete");
(0, lib_1.createSpacer)(2);
(0, lib_1.logWithColor)("yellow", "Analysis results:");
(0, lib_1.createSpacer)(1);
(0, lib_1.logWithColor)("yellow", table);
(0, lib_1.createSpacer)(2);
(0, lib_1.logWithColor)("yellow", "Final score:");
(0, lib_1.createSpacer)(2);
(0, lib_1.logWithColor)("yellow", (0, lib_1.createAsciiBox)(finalScore));
(0, lib_1.createSpacer)(2);
const thisProject = { finalScore: Number(finalScore), name: "this project" };
const recordedScores = finalReport_json_1.default.projects;
const sortedScores = [thisProject, ...recordedScores].sort(lib_1.sortScores);
const points = sortedScores.map(({ finalScore, name }, i) => ({
x: i,
y: finalScore,
label: name,
}));
const graph = (0, lib_1.plotXYGraph)(points, 40, 40);
console.log(graph);
if (_config === null || _config === void 0 ? void 0 : _config.markdown) {
// Write the markdown file
const markdown = (0, lib_1.convertToMarkdown)({ dataStats, finalScore });
(0, lib_1.writeFile)(_config.reportPath ? _config.reportPath : "analysis.md", markdown);
}
}
exports.runAnalysis = runAnalysis;
exports.default = runAnalysis;
//# sourceMappingURL=index.js.map