@build-script/heft-esbuild-plugin
Version:
lowlevel esbuild plugin for [heft]
74 lines (73 loc) • 1.98 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutputFile = void 0;
const node_1 = require("@idlebox/node");
class OutputFile {
path;
_contents;
_text;
_hash;
get contents() {
if (this._contents === undefined) {
if (this._text === undefined)
throw new Error('contents is undefined');
this._contents = Buffer.from(this._text, 'utf-8');
this._text = undefined;
}
return this._contents;
}
set contents(contents) {
this._text = undefined;
this._contents = contents;
}
get text() {
if (this._text === undefined) {
if (this._contents === undefined)
throw new Error('contents is undefined');
this._text = this._contents.toString();
this._contents = undefined;
}
return this._text;
}
set text(text) {
this._contents = undefined;
this._text = text;
}
asString() {
if (this._text) {
return this._text;
}
if (this._contents) {
return this._contents.toString();
}
throw new Error('text/contents is undefined');
}
asBinary() {
if (this._text) {
return Buffer.from(this._text);
}
if (this._contents) {
return this._contents;
}
throw new Error('text/contents is undefined');
}
asAny() {
return this._contents ?? this._text ?? '';
}
get hash() {
return this._hash;
}
set hash(_) {
throw new Error('can not set hash');
}
constructor(path, init, hash = (0, node_1.md5)(init)) {
this.path = path;
if (typeof init === 'string')
this._text = init;
else
this._contents = init;
this._hash = hash;
}
}
exports.OutputFile = OutputFile;
//# sourceMappingURL=write.helper.js.map