UNPKG

linear-cmd

Version:

A GitHub CLI-like tool for Linear - manage issues, accounts, and more

24 lines (23 loc) 853 B
import * as fs from 'fs'; import JSON5 from 'json5'; export function readJson5(filePath) { if (!fs.existsSync(filePath)) { throw new Error(`File not found: ${filePath}`); } try { const rawData = fs.readFileSync(filePath, 'utf-8'); return JSON5.parse(rawData); } catch (error) { throw new Error(`Failed to parse JSON5 file: ${filePath}. Error: ${error instanceof Error ? error.message : 'Unknown error'}`); } } export function writeJson5(filePath, data, pretty = true) { try { const jsonString = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data); fs.writeFileSync(filePath, jsonString, 'utf-8'); } catch (error) { throw new Error(`Failed to write JSON5 file: ${filePath}. Error: ${error instanceof Error ? error.message : 'Unknown error'}`); } }