Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/scripts/occurances/CommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/scripts/occurances/processors/LOCLanguagesProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(),
});
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/projectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading