UNPKG

aahook

Version:

A CLI tool that displays ASCII art when commands succeed or fail

127 lines 3.95 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.DEFAULT_CONFIG = exports.ARTS_DIR = exports.CONFIG_FILE = exports.CONFIG_DIR = void 0; exports.loadConfig = loadConfig; exports.saveConfig = saveConfig; exports.validateConfig = validateConfig; exports.getConfigDir = getConfigDir; exports.getArtsDir = getArtsDir; exports.isInitialized = isInitialized; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const os = __importStar(require("os")); // Configuration paths exports.CONFIG_DIR = path.join(os.homedir(), '.aahook'); exports.CONFIG_FILE = path.join(exports.CONFIG_DIR, 'config.json'); exports.ARTS_DIR = path.join(exports.CONFIG_DIR, 'arts'); // Default configuration exports.DEFAULT_CONFIG = { version: '0.1.0', hooks: { 'git push': { success: 'dragon.txt', error: 'error.txt' }, 'ls': { success: 'cat.txt' }, 'npm test': { success: 'success.txt', error: 'error.txt' } } }; /** * Load configuration from file * @throws Error if config file doesn't exist or is invalid */ function loadConfig() { if (!fs.existsSync(exports.CONFIG_FILE)) { throw new Error('aahook not initialized. Run \'aahook init\' first.'); } try { const configContent = fs.readFileSync(exports.CONFIG_FILE, 'utf8'); const config = JSON.parse(configContent); return config; } catch (error) { if (error instanceof SyntaxError) { throw new Error('Invalid config.json format. Please check ~/.aahook/config.json'); } throw error; } } /** * Save configuration to file */ function saveConfig(config) { const configContent = JSON.stringify(config, null, 2); fs.writeFileSync(exports.CONFIG_FILE, configContent, { mode: 0o600 }); } /** * Validate configuration object */ function validateConfig(config) { if (!config || typeof config !== 'object') { return false; } if (!config.version || typeof config.version !== 'string') { return false; } if (!config.hooks || typeof config.hooks !== 'object') { return false; } return true; } /** * Get configuration directory path */ function getConfigDir() { return exports.CONFIG_DIR; } /** * Get arts directory path */ function getArtsDir() { return exports.ARTS_DIR; } /** * Check if aahook is initialized */ function isInitialized() { return fs.existsSync(exports.CONFIG_FILE); } //# sourceMappingURL=config.js.map