diff --git a/src/scripts/occurances/CommandLine.ts b/src/scripts/occurances/CommandLine.ts index 0e46361..ca182dc 100644 --- a/src/scripts/occurances/CommandLine.ts +++ b/src/scripts/occurances/CommandLine.ts @@ -28,16 +28,11 @@ class CommandLine { }); } - getLoc(fileRegex: string) { + getLoc(fileGlob: string) { // xargs will limit what it takes and thus we will end up with more than one line for total loc // for projects with a lot of files. This is fixed by using grep total and then summing those. - const loc = this.run( - `find ${this.absPath}/${this.projectDir} -name '${fileRegex}' | xargs wc -l|grep total| awk '{sum += $1} END {print sum}'` - ) - .toString() - .trim() - .split("\n"); - + const command = `find ${this.absPath}/${this.projectDir} -name '${fileGlob}' | xargs wc -l|grep total| awk '{sum += $1} END {print sum}'`; + const loc = this.run(command).toString().trim().split("\n"); return loc[0] ? parseInt(loc[0]) : 0; } diff --git a/src/scripts/occurances/processors/LOCLanguagesProcessor.ts b/src/scripts/occurances/processors/LOCLanguagesProcessor.ts index 576e5e3..352187d 100644 --- a/src/scripts/occurances/processors/LOCLanguagesProcessor.ts +++ b/src/scripts/occurances/processors/LOCLanguagesProcessor.ts @@ -10,12 +10,12 @@ const mainBranchNames = ["main", "master"]; */ class LOCLanguagesProcessor implements Processor { commandLine: CommandLine; - languageRegexes: { language: string; regex: string }[]; + languageGlobs: { language: string; glob: string }[]; mainBranchName: string | undefined; - constructor(commandLine: CommandLine, languageRegexes: { language: string; regex: string }[]) { + constructor(commandLine: CommandLine, languageGlobs: { language: string; glob: string }[]) { this.commandLine = commandLine; - this.languageRegexes = languageRegexes; + this.languageGlobs = languageGlobs; } analyses() { @@ -55,12 +55,12 @@ class LOCLanguagesProcessor implements Processor { const commit = commits[commitsTraversed]; this.commandLine.checkout(commit.hash); - this.languageRegexes.forEach((langRegex) => { - const loc = this.commandLine.getLoc(langRegex.regex); + this.languageGlobs.forEach((langGlob) => { + const loc = this.commandLine.getLoc(langGlob.glob); occurances.push({ type: AvailableAnalysisEnum.LOCLanguage, id: commit.hash, - section: langRegex.language, + section: langGlob.language, amount: loc, occurredAt: moment(commit.createdAt).toISOString(), }); diff --git a/src/scripts/projectConfig.ts b/src/scripts/projectConfig.ts index 4c89595..f69c22e 100644 --- a/src/scripts/projectConfig.ts +++ b/src/scripts/projectConfig.ts @@ -34,16 +34,16 @@ class ProjectConfig { return this.config[projectName]?.git; } - languageRegexes(projectName: string): { language: string; regex: string }[] { + languageRegexes(projectName: string): { language: string; glob: string }[] { return (this.config[projectName]?.languages || []) .map((language) => { if (language === "typescript") { - return { language, regex: ".tsx?" }; + return { language, glob: "*.tsx*" }; } else if (language === "ruby") { - return { language, regex: ".rb" }; + return { language, glob: "*.rb" }; } }) - .filter((item): item is { language: string; regex: string } => item !== undefined); + .filter((item): item is { language: string; glob: string } => item !== undefined); } projectDir(projectName: string) {