@arthurgubaidullin/nx-embed-dependencies
Version:
This plugin for [Nx](https://nx.dev) helps injecting local dependencies into a package.
30 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.copyDist = void 0;
const tslib_1 = require("tslib");
const E = require("fp-ts/Either");
const function_1 = require("fp-ts/function");
const T = require("fp-ts/Task");
const TE = require("fp-ts/TaskEither");
const fs = require("node:fs/promises");
function copyDist(distPath, targetPath) {
const dist = distPath;
const target = targetPath;
return (0, function_1.pipe)(statExists(target), T.chain((exists) => exists ? rm(target, { recursive: true }) : T.fromIO(function_1.constVoid)), T.chain(() => mkdir(target, { recursive: true })), T.chain(() => cp(dist, target, { recursive: true })));
}
exports.copyDist = copyDist;
function cp(src, dest, options) {
return (0, function_1.pipe)(() => tslib_1.__awaiter(this, void 0, void 0, function* () { return yield fs.cp(src, dest, options); }), (f) => TE.tryCatch(f, E.toError), TE.getOrElse(() => T.fromIO(function_1.constVoid)));
}
function mkdir(path, options) {
return (0, function_1.pipe)(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield fs.mkdir(path, options);
}), (f) => TE.tryCatch(f, E.toError), TE.getOrElse(() => T.fromIO(function_1.constVoid)));
}
function statExists(path) {
return (0, function_1.pipe)(() => tslib_1.__awaiter(this, void 0, void 0, function* () { return yield fs.stat(path); }), (f) => TE.tryCatch(f, E.toError), TE.map(() => true), TE.getOrElse(() => T.of(false)));
}
function rm(path, options) {
return (0, function_1.pipe)(() => tslib_1.__awaiter(this, void 0, void 0, function* () { return yield fs.rm(path, options); }), (f) => TE.tryCatch(f, E.toError), TE.getOrElse(() => T.fromIO(function_1.constVoid)));
}
//# sourceMappingURL=DistCopying.js.map