27 lines
818 B
JavaScript
27 lines
818 B
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ensureDir = ensureDir;
|
|
exports.readJsonFile = readJsonFile;
|
|
exports.writeJsonFile = writeJsonFile;
|
|
const fs_1 = __importDefault(require("fs"));
|
|
function ensureDir(path) {
|
|
if (!fs_1.default.existsSync(path)) {
|
|
fs_1.default.mkdirSync(path, { recursive: true });
|
|
}
|
|
}
|
|
function readJsonFile(path, fallback) {
|
|
try {
|
|
const raw = fs_1.default.readFileSync(path, "utf-8");
|
|
return JSON.parse(raw);
|
|
}
|
|
catch {
|
|
return fallback;
|
|
}
|
|
}
|
|
function writeJsonFile(path, value) {
|
|
fs_1.default.writeFileSync(path, JSON.stringify(value, null, 2), "utf-8");
|
|
}
|