UNPKG

@homeofthings/node-utils

Version:

HomeOfThings - Node Utils: various utilities and common types

25 lines 860 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeFileIfChanged = writeFileIfChanged; const tslib_1 = require("tslib"); const node_fs_1 = require("node:fs"); const path = tslib_1.__importStar(require("node:path")); async function writeFileIfChanged(outputPath, content) { let oldContent; try { oldContent = await node_fs_1.promises.readFile(outputPath, { encoding: 'utf8' }); } catch (err) { oldContent = undefined; } if (oldContent === content) { return false; } if (!oldContent) { const outputDir = path.dirname(outputPath); await node_fs_1.promises.mkdir(outputDir, { recursive: true }); } await node_fs_1.promises.writeFile(outputPath, content, { encoding: 'utf8' }); return true; } //# sourceMappingURL=write-file-if-changed.js.map