UNPKG

@necto-ai/pgit

Version:

Private file tracking with dual git repositories

231 lines 6.94 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.PlatformDetector = void 0; const os = __importStar(require("os")); const fs = __importStar(require("fs")); const path = __importStar(require("path")); /** * Platform detection and cross-platform utilities */ class PlatformDetector { /** * Check if running on Windows */ static isWindows() { return process.platform === 'win32'; } /** * Check if running on macOS */ static isMacOS() { return process.platform === 'darwin'; } /** * Check if running on Linux */ static isLinux() { return process.platform === 'linux'; } /** * Check if running on Unix-like system (macOS or Linux) */ static isUnix() { return this.isMacOS() || this.isLinux(); } /** * Get platform-specific path separator */ static getPathSeparator() { return this.isWindows() ? '\\' : '/'; } /** * Get platform name for display */ static getPlatformName() { if (this.isWindows()) return 'Windows'; if (this.isMacOS()) return 'macOS'; if (this.isLinux()) return 'Linux'; return 'Unknown'; } /** * Check if the system supports symbolic links */ static async supportsSymlinks() { if (this.isUnix()) { // Unix systems generally support symbolic links return true; } if (this.isWindows()) { // Windows requires administrator privileges for symlinks in older versions // Try to create a test symlink to check return this.testSymlinkCapability(); } return false; } /** * Test symbolic link capability by attempting to create one */ static async testSymlinkCapability() { const testDir = os.tmpdir(); const testSource = path.join(testDir, `private-git-test-${Date.now()}.txt`); const testTarget = path.join(testDir, `private-git-test-link-${Date.now()}.txt`); try { // Create test file await fs.promises.writeFile(testSource, 'test'); // Try to create symbolic link await fs.promises.symlink(testSource, testTarget); // Clean up await fs.promises.unlink(testTarget); await fs.promises.unlink(testSource); return true; } catch { // Clean up on error try { await fs.promises.unlink(testSource); } catch { // Ignore cleanup errors } try { await fs.promises.unlink(testTarget); } catch { // Ignore cleanup errors } return false; } } /** * Get platform-specific command for creating symbolic links */ static getSymlinkCommand(source, target, isDirectory = false) { if (this.isWindows()) { // Windows uses mklink const flag = isDirectory ? '/D' : ''; return `mklink ${flag} "${target}" "${source}"`; } else { // Unix systems use ln -s return `ln -s "${source}" "${target}"`; } } /** * Get platform-specific home directory */ static getHomeDirectory() { return os.homedir(); } /** * Get platform-specific temporary directory */ static getTempDirectory() { return os.tmpdir(); } /** * Normalize path for current platform */ static normalizePath(inputPath) { return path.normalize(inputPath); } /** * Convert path to platform-specific format */ static toPlatformPath(inputPath) { if (this.isWindows()) { return inputPath.replace(/\//g, '\\'); } else { return inputPath.replace(/\\/g, '/'); } } /** * Check if path is absolute */ static isAbsolutePath(inputPath) { return path.isAbsolute(inputPath); } /** * Get current working directory */ static getCurrentDirectory() { return process.cwd(); } /** * Check file/directory permissions */ static async checkPermissions(filePath) { try { await fs.promises.access(filePath, fs.constants.F_OK); const readable = await this.hasPermission(filePath, fs.constants.R_OK); const writable = await this.hasPermission(filePath, fs.constants.W_OK); const executable = await this.hasPermission(filePath, fs.constants.X_OK); return { readable, writable, executable }; } catch { return { readable: false, writable: false, executable: false }; } } /** * Check specific permission */ static async hasPermission(filePath, mode) { try { await fs.promises.access(filePath, mode); return true; } catch { return false; } } /** * Get system information for debugging */ static getSystemInfo() { return { platform: process.platform, arch: process.arch, nodeVersion: process.version, osRelease: os.release(), supportsSymlinks: false, // Will be set async }; } } exports.PlatformDetector = PlatformDetector; //# sourceMappingURL=platform.detector.js.map