@ng-doc/builder
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
36 lines • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.emitFileOutput = emitFileOutput;
const tslib_1 = require("tslib");
const core_1 = require("@ng-doc/core");
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
const operators_1 = require("rxjs/operators");
const types_1 = require("../types");
/**
* An operator function that emits file outputs.
* @returns An OperatorFunction that can be used in an RxJS pipe.
*/
function emitFileOutput() {
return (source) => {
return source.pipe((0, operators_1.tap)((state) => {
if ((0, types_1.isBuilderDone)(state)) {
emitFiles((0, core_1.asArray)(state.result));
}
}));
};
}
/**
* Writes the content of each file in the provided array to the file system.
* @param {FileOutput[]} files - An array of FileOutput objects to be written to the file system.
*/
function emitFiles(files) {
files.forEach((output) => {
const fileContent = fs_1.default.existsSync(output.filePath) && fs_1.default.readFileSync(output.filePath, 'utf-8');
if (fileContent !== output.content) {
fs_1.default.mkdirSync(path_1.default.dirname(output.filePath), { recursive: true });
fs_1.default.writeFileSync(output.filePath, output.content);
}
});
}
//# sourceMappingURL=emit-file-output.js.map