jetup
Version:
Jetup: JavaScript Project Setup! Jetting-up your next JS project in seconds with one command, using fully modular, customizable presets, instantly ready to code!.
43 lines • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateJson = updateJson;
exports.hasJsonProperty = hasJsonProperty;
const fs_1 = require("fs");
const promises_1 = require("fs/promises");
async function updateJson(filePath, updates) {
try {
const content = await (0, promises_1.readFile)(filePath, 'utf-8');
const json = JSON.parse(content);
const updated = { ...json, ...updates };
await (0, promises_1.writeFile)(filePath, JSON.stringify(updated, null, 2) + '\n');
}
catch (error) {
console.error(`Failed to update JSON at ${filePath}:`, error);
throw error;
}
}
function hasJsonProperty(filePath, propertyPath) {
if (!(0, fs_1.existsSync)(filePath))
return false;
const raw = (0, fs_1.readFileSync)(filePath, { encoding: 'utf-8' });
let obj;
try {
obj = JSON.parse(raw);
}
catch {
return false;
}
const keys = propertyPath.split('.');
let current = obj;
for (const key of keys) {
if (current === null ||
current === undefined ||
typeof current !== 'object' ||
!(key in current)) {
return false;
}
current = current[key];
}
return true;
}
//# sourceMappingURL=json.js.map