UNPKG

@developerisnow/git-repositories-statistic-analyzer

Version:

A powerful tool for analyzing multiple Git repositories and generating comprehensive statistics

110 lines (109 loc) 4 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.GitScanner = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const glob_1 = require("glob"); const os_1 = require("os"); class GitScanner { constructor(ignorePatterns) { this.ignorePatterns = ignorePatterns; this.homeDir = (0, os_1.homedir)(); } shouldIgnore(filePath) { const relativePath = path.relative(this.homeDir, filePath); return this.ignorePatterns.some((pattern) => { const regexPattern = pattern .replace(/\./g, "\\.") .replace(/\*/g, ".*") .replace(/\?/g, "."); return new RegExp(regexPattern).test(relativePath); }); } isValidGitDir(gitPath) { try { return (fs.statSync(gitPath).isDirectory() && fs.existsSync(path.join(gitPath, "HEAD")) && fs.existsSync(path.join(gitPath, "config"))); } catch { return false; } } async findGitRepos() { try { const gitFolders = await (0, glob_1.glob)("**/.git", { cwd: this.homeDir, ignore: ["**/node_modules/**"], absolute: true, dot: true, }); return gitFolders .filter((gitFolder) => this.isValidGitDir(gitFolder)) .map((gitFolder) => path.dirname(gitFolder)) .filter((repoPath) => !this.shouldIgnore(repoPath)); } catch (error) { console.error("Error scanning repositories:", error); return []; } } static async loadIgnorePatterns(configPath) { const defaultPatterns = [ "**/node_modules/**", "**/vendor/**", "**/dist/**", "**/auto_gpt_workspace/**", // Add problematic paths "**/broken_repos/**", ]; try { if (!fs.existsSync(configPath)) { return defaultPatterns; } const content = await fs.promises.readFile(configPath, "utf-8"); const patterns = content .split("\n") .map((line) => line.trim()) .filter((line) => line && !line.startsWith("#")); return patterns.length ? patterns : defaultPatterns; } catch (error) { console.warn(`Warning: Could not load ignore patterns from ${configPath}`); return defaultPatterns; } } } exports.GitScanner = GitScanner;