UNPKG

@webdoc/template-library

Version:

Goodies for @webdoc template packages! See @webdoc/legacy-template for an example!

41 lines (40 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlushToFile = void 0; var fse = _interopRequireWildcard(require("fs-extra")); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class FlushToFile { constructor(options = {}) { _defineProperty(this, "halt", void 0); _defineProperty(this, "skipNullFile", void 0); this.halt = options.halt || false; this.skipNullFile = options.skipNullFile || false; } attachTo(pipeline) {} run(input, pipelineData = {}) { if (!pipelineData.outputFile) { if (this.skipNullFile) { return input; } throw new Error("No outputFile specified in pipeline-data"); } fse.outputFile(pipelineData.outputFile, input, err => { if (err) throw err; }); if (!this.halt) { return input; } } clone() { return new FlushToFile({ halt: this.halt, skipNullFile: this.skipNullFile }); } close() {} } exports.FlushToFile = FlushToFile;