UNPKG

@quasarbright/projection

Version:

A static site generator that creates a beautiful, interactive gallery to showcase your coding projects. Features search, filtering, tags, responsive design, and an admin UI.

112 lines 3.98 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.JSONFileManager = void 0; const fs = __importStar(require("fs")); /** * JSON file manager with pretty-printing * Uses standard parse/stringify with 2-space indentation */ class JSONFileManager { constructor(filePath) { this.data = null; this.filePath = filePath; } /** * Read projects from JSON file */ async readProjects() { const fileContent = await fs.promises.readFile(this.filePath, 'utf-8'); this.data = JSON.parse(fileContent); // Ensure projects array exists if (!this.data.projects) { this.data.projects = []; } return this.data; } /** * Update an existing project in the JSON file */ async updateProject(projectId, updatedProject) { if (!this.data) { throw new Error('Data not loaded. Call readProjects() first.'); } const projectIndex = this.data.projects.findIndex(p => p.id === projectId); if (projectIndex === -1) { throw new Error(`Project with id "${projectId}" not found`); } // Update the project this.data.projects[projectIndex] = updatedProject; // Write back to file with pretty-printing await this.writeData(); } /** * Add a new project to the JSON file */ async addProject(project) { if (!this.data) { throw new Error('Data not loaded. Call readProjects() first.'); } // Add the new project this.data.projects.push(project); // Write back to file with pretty-printing await this.writeData(); } /** * Delete a project from the JSON file */ async deleteProject(projectId) { if (!this.data) { throw new Error('Data not loaded. Call readProjects() first.'); } const projectIndex = this.data.projects.findIndex(p => p.id === projectId); if (projectIndex === -1) { throw new Error(`Project with id "${projectId}" not found`); } // Remove the project this.data.projects.splice(projectIndex, 1); // Write back to file with pretty-printing await this.writeData(); } /** * Write data to file with 2-space indentation for readability */ async writeData() { const json = JSON.stringify(this.data, null, 2); await fs.promises.writeFile(this.filePath, json, 'utf-8'); } } exports.JSONFileManager = JSONFileManager; //# sourceMappingURL=json-file-manager.js.map