UNPKG

code-complexity

Version:

Measure the churn/complexity score. Higher values mean hotspots where refactorings should happen.

36 lines (35 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const node_child_process_1 = require("node:child_process"); const node_fs_1 = require("node:fs"); const cli_1 = require("./cli"); const output_1 = require("./output"); const lib_1 = require("../lib"); async function main() { const options = await cli_1.default.parse(); warnIfUsingComplexityWithIncompatibleFileTypes(options); assertGitIsInstalled(); assertIsGitRootDirectory(options.directory); const statistics = await lib_1.default.compute(options); cli_1.default.cleanup(options); output_1.default.render(statistics.list(), options); } exports.default = main; function warnIfUsingComplexityWithIncompatibleFileTypes(options) { if (options.complexityStrategy !== "sloc") { console.warn("Beware, the 'halstead' and 'cyclomatic' strategies are only available for JavaScript/TypeScript."); } } function assertGitIsInstalled() { try { (0, node_child_process_1.execSync)("which git"); } catch (error) { throw new Error("Program 'git' must be installed"); } } function assertIsGitRootDirectory(directory) { if (!(0, node_fs_1.existsSync)(`${directory}/.git`)) { throw new Error(`Argument 'dir' must be the git root directory.`); } }