UNPKG

@jasondark/proompt

Version:

CLI tool for running AI prompts with structure and repeatability

169 lines 5.93 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.writeProjectSettings = exports.writeGlobalSettings = exports.readProjectSettings = exports.readGlobalSettings = exports.ensureProjectSettingsDir = exports.ensureGlobalSettingsDir = exports.getProjectSettingsPath = exports.getGlobalSettingsPath = void 0; const fs = __importStar(require("fs")); const os = __importStar(require("os")); const path = __importStar(require("path")); const schemas_1 = require("../schemas"); /** * Get the path to the global settings file */ const getGlobalSettingsPath = () => { return path.join(os.homedir(), '.proompt', 'settings.json'); }; exports.getGlobalSettingsPath = getGlobalSettingsPath; /** * Get the path to the project settings file */ const getProjectSettingsPath = () => { return path.join(process.cwd(), '.proompt', 'settings.json'); }; exports.getProjectSettingsPath = getProjectSettingsPath; /** * Ensure the global settings directory exists */ const ensureGlobalSettingsDir = () => { const settingsDir = path.dirname((0, exports.getGlobalSettingsPath)()); if (!fs.existsSync(settingsDir)) { fs.mkdirSync(settingsDir, { recursive: true }); } }; exports.ensureGlobalSettingsDir = ensureGlobalSettingsDir; /** * Ensure the project settings directory exists */ const ensureProjectSettingsDir = () => { const settingsDir = path.dirname((0, exports.getProjectSettingsPath)()); if (!fs.existsSync(settingsDir)) { fs.mkdirSync(settingsDir, { recursive: true }); } }; exports.ensureProjectSettingsDir = ensureProjectSettingsDir; /** * Read global settings from file with metadata */ const readGlobalSettings = () => { const filePath = (0, exports.getGlobalSettingsPath)(); try { if (!fs.existsSync(filePath)) { return { settings: null, fileExists: false, filePath, }; } const settingsContent = fs.readFileSync(filePath, 'utf8'); const parsedSettings = JSON.parse(settingsContent); const validatedSettings = schemas_1.settingsSchema.parse(parsedSettings); return { settings: validatedSettings, fileExists: true, filePath, }; } catch { console.warn('Warning: Could not read global settings file'); return { settings: null, fileExists: false, filePath, }; } }; exports.readGlobalSettings = readGlobalSettings; /** * Read project settings from file with metadata */ const readProjectSettings = () => { const filePath = (0, exports.getProjectSettingsPath)(); try { if (!fs.existsSync(filePath)) { return { settings: null, fileExists: false, filePath, }; } const settingsContent = fs.readFileSync(filePath, 'utf8'); const parsedSettings = JSON.parse(settingsContent); const validatedSettings = schemas_1.settingsSchema.parse(parsedSettings); return { settings: validatedSettings, fileExists: true, filePath, }; } catch { console.warn('Warning: Could not read project settings file'); return { settings: null, fileExists: false, filePath, }; } }; exports.readProjectSettings = readProjectSettings; /** * Write global settings to file */ const writeGlobalSettings = (settings) => { try { (0, exports.ensureGlobalSettingsDir)(); const settingsPath = (0, exports.getGlobalSettingsPath)(); const validatedSettings = schemas_1.settingsSchema.parse(settings); fs.writeFileSync(settingsPath, JSON.stringify(validatedSettings, null, 2)); } catch (error) { throw new Error(`Failed to write global settings: ${error.message}`); } }; exports.writeGlobalSettings = writeGlobalSettings; /** * Write project settings to file */ const writeProjectSettings = (settings) => { try { (0, exports.ensureProjectSettingsDir)(); const settingsPath = (0, exports.getProjectSettingsPath)(); const validatedSettings = schemas_1.settingsSchema.parse(settings); fs.writeFileSync(settingsPath, JSON.stringify(validatedSettings, null, 2)); } catch (error) { throw new Error(`Failed to write project settings: ${error.message}`); } }; exports.writeProjectSettings = writeProjectSettings; //# sourceMappingURL=settings.js.map