@bitecraft/yaak2postman
Version:
CLI tool to convert YAAK files to Postman
21 lines (20 loc) • 677 B
JavaScript
import fs from 'node:fs';
import path from 'node:path';
export function resolvePath(filePath) {
if (path.isAbsolute(filePath)) {
return path.normalize(filePath);
}
return path.resolve(process.cwd(), filePath);
}
export function readJsonFile(filePath) {
const resolvedPath = resolvePath(filePath);
const fileContent = fs.readFileSync(resolvedPath, 'utf8');
return JSON.parse(fileContent);
}
export function saveJsonFile(filePath, data) {
const outputDir = path.dirname(filePath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
}