UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

19 lines 1.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeFileAsync = exports.mkdir = void 0; const fs_1 = __importDefault(require("fs")); const util_1 = __importDefault(require("util")); const getDirOfPath_1 = require("../filepaths/getDirOfPath"); const makeDirAsync_1 = require("./makeDirAsync"); // export these from a seperate file to make testing easier (i.e., easier to define the mocks) exports.mkdir = util_1.default.promisify(fs_1.default.mkdir); const writeFile = util_1.default.promisify(fs_1.default.writeFile); const writeFileAsync = async ({ path, content, }) => { await (0, makeDirAsync_1.makeDirectoryAsync)({ directoryPath: await (0, getDirOfPath_1.getDirOfPath)(path) }); // find or create the dir, before writing the file to the dir await writeFile(path, `${content.replace(/\n$/, '')}\n`); }; exports.writeFileAsync = writeFileAsync; //# sourceMappingURL=writeFileAsync.js.map