burp-brightscript
Version:
lightweight processor for roku brightscript projects
79 lines • 2.92 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var path = require("path");
var FileType_1 = require("./FileType");
var FileDescriptor = /** @class */ (function () {
function FileDescriptor(directory, filename, extension) {
this._fileContents = null;
this.filename = filename;
this.directory = directory;
this.extension = extension;
}
Object.defineProperty(FileDescriptor.prototype, "fileType", {
get: function () {
switch (this.extension.toLowerCase()) {
case '.brs':
return FileType_1.FileType.Brs;
case '.bs':
return FileType_1.FileType.Bs;
default:
return FileType_1.FileType.Other;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileDescriptor.prototype, "fullPath", {
get: function () {
return path.join(this.directory, this.filename);
},
enumerable: true,
configurable: true
});
FileDescriptor.prototype.getPackagePath = function (projectRoot, cwd) {
var pkgPath = "pkg:" + this.fullPath.replace(projectRoot, '');
pkgPath = pkgPath.replace(cwd, '');
pkgPath = pkgPath.replace('.bs', '.brs');
return pkgPath.replace('pkg://', 'pkg:/');
};
Object.defineProperty(FileDescriptor.prototype, "normalizedFileName", {
get: function () {
return this.filename.replace('.brs', '').replace('-', '_').replace('.', '_');
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileDescriptor.prototype, "normalizedFullFileName", {
get: function () {
return this.fullPath.replace('/', '_') + this.normalizedFileName;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileDescriptor.prototype, "fileContents", {
get: function () {
if (this._fileContents === null) {
this._fileContents = fs.readFileSync(this.fullPath, 'utf8');
}
return this._fileContents;
},
enumerable: true,
configurable: true
});
FileDescriptor.prototype.setFileContents = function (newContents) {
this._fileContents = newContents;
};
FileDescriptor.prototype.saveFileContents = function () {
fs.writeFileSync(this.fullPath, this._fileContents, 'utf8');
};
FileDescriptor.prototype.unloadContents = function () {
this._fileContents = null;
};
FileDescriptor.prototype.toString = function () {
return "DESCRIPTOR: " + this.filename + " TYPE " + this.fileType + " PATH " + this.fullPath;
};
return FileDescriptor;
}());
exports.default = FileDescriptor;
//# sourceMappingURL=FileDescriptor.js.map