Tofu/scripts/import-recipes/cli/writeJsonFile.js
2026-09-18 01:41:02 +02:00

9 lines
406 B
JavaScript

import { mkdirSync, writeFileSync } from 'node:fs'
import { dirname } from 'node:path'
// Indented JSON with a trailing newline: these files end up in git and on a
// Nextcloud, where a human may well open them in a text editor.
export function writeJsonFile(filePath, value) {
mkdirSync(dirname(filePath), { recursive: true })
writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, 'utf8')
}