declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
28 lines • 1.8 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ path, content, }) {
yield (0, makeDirAsync_1.makeDirectoryAsync)({ directoryPath: yield (0, getDirOfPath_1.getDirOfPath)(path) }); // find or create the dir, before writing the file to the dir
yield writeFile(path, `${content.replace(/\n$/, '')}\n`);
});
exports.writeFileAsync = writeFileAsync;
//# sourceMappingURL=writeFileAsync.js.map