UNPKG

@codewithmehmet/paul-cli

Version:

Intelligent project file scanner and Git change tracker with interactive interface

46 lines (45 loc) 1.37 kB
import fs from 'fs/promises'; import path from 'path'; export class PresetService { constructor() { this.presetsFile = path.join(process.cwd(), '.paul', 'presets.json'); } async ensureDirectory() { const dir = path.dirname(this.presetsFile); await fs.mkdir(dir, { recursive: true }); } async loadPresets() { try { const content = await fs.readFile(this.presetsFile, 'utf8'); return JSON.parse(content); } catch { return []; } } async savePreset(name, selectedFiles, options = {}) { await this.ensureDirectory(); const presets = await this.loadPresets(); // Convertir en chemins relatifs pour la portabilité const relativePaths = [...selectedFiles].map(filePath => { return path.isAbsolute(filePath) ? path.relative(process.cwd(), filePath) : filePath; }); const preset = { id: Date.now().toString(), name, selectedFiles: relativePaths, options, createdAt: new Date().toISOString() }; presets.push(preset); await fs.writeFile(this.presetsFile, JSON.stringify(presets, null, 2)); return preset; } async deletePreset(id) { const presets = await this.loadPresets(); const filtered = presets.filter(p => p.id !== id); await fs.writeFile(this.presetsFile, JSON.stringify(filtered, null, 2)); return true; } }