import { existsSync } from "node:fs"; import Cli from "./cli"; import { Options } from "../lib/types"; import * as Output from "./output"; import Statistics from "../lib"; export default async function main(): Promise { const options = await Cli.parse(); warnIfUsingComplexityWithIncompatibleFileTypes(options); assertIsGitRootDirectory(options.directory); const statistics = await Statistics.compute(options); Cli.cleanup(options); Output.render(statistics.list(), options); } function warnIfUsingComplexityWithIncompatibleFileTypes(options: Options) { if (options.complexityStrategy !== "sloc") { console.warn( "Beware, the 'halstead' and 'cyclomatic' strategies are only available for JavaScript/TypeScript.", ); } } function assertIsGitRootDirectory(directory: string): void { if (!existsSync(`${directory}/.git`)) { throw new Error(`Argument 'dir' must be the git root directory.`); } }