UNPKG

@wangkanai/devops-mcp

Version:

Dynamic Azure DevOps MCP Server for directory-based environment switching

139 lines 4.9 kB
"use strict"; /** * Directory Detection Logic * Detects current working directory and maps to appropriate Azure DevOps configuration */ 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.DirectoryDetector = void 0; const path = __importStar(require("path")); class DirectoryDetector { constructor(mappings, defaultConfig) { this.mappings = new Map(); // Normalize and store mappings for efficient lookup for (const mapping of mappings) { const normalizedPath = path.resolve(mapping.directory); this.mappings.set(normalizedPath, mapping.config); } this.defaultConfig = defaultConfig; } /** * Detect Azure DevOps configuration based on current directory * Supports nested directory matching with closest match priority */ detectConfiguration(currentDirectory) { const workingDir = currentDirectory || process.cwd(); const normalizedPath = path.resolve(workingDir); // Find the longest matching path (most specific match) let bestMatch = null; let bestMatchLength = 0; for (const [mappedPath] of this.mappings) { if (normalizedPath.startsWith(mappedPath)) { if (mappedPath.length > bestMatchLength) { bestMatch = mappedPath; bestMatchLength = mappedPath.length; } } } if (bestMatch) { return this.mappings.get(bestMatch) || null; } // Try parent directory search up to root return this.searchParentDirectories(normalizedPath); } /** * Search parent directories for a match */ searchParentDirectories(currentPath) { let searchPath = currentPath; const root = path.parse(searchPath).root; while (searchPath !== root) { searchPath = path.dirname(searchPath); for (const [mappedPath, config] of this.mappings) { if (searchPath === mappedPath || searchPath.startsWith(mappedPath + path.sep)) { return config; } } } return this.defaultConfig || null; } /** * Get the project name for the current directory */ getProjectContext(currentDirectory) { const config = this.detectConfiguration(currentDirectory); if (!config) { return null; } return { projectName: config.project, organizationUrl: config.organizationUrl }; } /** * Check if a directory is configured for Azure DevOps */ isConfiguredDirectory(currentDirectory) { return this.detectConfiguration(currentDirectory) !== null; } /** * Get all configured directory mappings */ getConfiguredDirectories() { return Array.from(this.mappings.keys()); } /** * Add a new directory mapping */ addMapping(directory, config) { const normalizedPath = path.resolve(directory); this.mappings.set(normalizedPath, config); } /** * Remove a directory mapping */ removeMapping(directory) { const normalizedPath = path.resolve(directory); return this.mappings.delete(normalizedPath); } /** * Update default configuration */ setDefaultConfig(config) { this.defaultConfig = config; } } exports.DirectoryDetector = DirectoryDetector; //# sourceMappingURL=directory-detector.js.map