UNPKG

@typecad/typecad

Version:

🤖programmatically 💥create 🛰️hardware

31 lines (30 loc) 1.19 kB
import fs from "node:fs"; import chalk from 'chalk'; export const REGISTRY_FILE_PATH = './build/cache/component_registry.json'; export function loadRegistry(filePath = REGISTRY_FILE_PATH) { try { if (fs.existsSync(filePath)) { const fileContent = fs.readFileSync(filePath, 'utf-8'); return JSON.parse(fileContent); } else { const dirPath = filePath.substring(0, filePath.lastIndexOf('/')); if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath, { recursive: true }); } } } catch (error) { console.warn(chalk.yellow(`[Registry] WARN: Could not read or parse registry file at ${filePath}. Using new registry. Error: ${error}`)); } return { vias: {}, conceptualOutlines: {}, outlineElements: {}, components: {} }; } export function saveRegistry(filePath = REGISTRY_FILE_PATH, data) { try { const jsonData = JSON.stringify(data, null, 2); fs.writeFileSync(filePath, jsonData, 'utf-8'); } catch (error) { console.error(chalk.red(`[Registry] 👺 Error: Could not save component registry to ${filePath}: ${error}`)); } }