UNPKG

maestro-cli-roku

Version:

command line tools for maestro-roku projects

203 lines (202 loc) 8.57 kB
"use strict"; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var NameSpace_1 = require("../namespaceSupport/NameSpace"); var Feedback_1 = require("../utils/Feedback"); var File_1 = require("./File"); var FileType_1 = require("./FileType"); var ProjectFileMap = /** @class */ (function () { /** * For a given file, which has been listed as a dependency, will list ALL of the files it also depends on * @returns {{string[]}|*} - array of filenames of all dependncies */ function ProjectFileMap(addRuntimeFiles) { if (addRuntimeFiles === void 0) { addRuntimeFiles = true; } this._allFiles = new Map(); this._filesByPkgPath = new Map(); this._xmlComponentFiles = new Map(); this._nonProcessFiles = new Set(); this._namespacesByName = new Map(); this._namespacesByClassName = new Map(); this._classesByClassName = new Map(); this._nodeClassesByClassName = new Map(); this._instantiationCalls = new Map(); if (addRuntimeFiles) { this.addRuntimeFiles(); } } ProjectFileMap.prototype.addRuntimeFiles = function () { var runtimeFile = new File_1.File('', 'source', 'MRuntime.brs', '.brs'); var runtimeNamespace = new NameSpace_1.Namespace('MRuntime', runtimeFile); runtimeFile.namespace = runtimeNamespace; this.addFile(runtimeFile); this.addNamespace(runtimeNamespace); }; Object.defineProperty(ProjectFileMap.prototype, "allFiles", { get: function () { return this._allFiles; }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "nonProcessFilePaths", { get: function () { return this._nonProcessFiles; }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "filesByPkgPath", { get: function () { return this._filesByPkgPath; }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "allNamespaces", { get: function () { return this._namespacesByName; }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "xmlComponentFiles", { get: function () { return this._xmlComponentFiles; }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "allClasses", { get: function () { return __spread(this.classesByClassName.values()); }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "nodeClassesByClassName", { get: function () { return this._nodeClassesByClassName; }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "allNodeClasses", { get: function () { return __spread(this.nodeClassesByClassName.values()); }, enumerable: true, configurable: true }); Object.defineProperty(ProjectFileMap.prototype, "classesByClassName", { get: function () { return this._classesByClassName; }, enumerable: true, configurable: true }); ProjectFileMap.prototype.getAllFiles = function () { return __spread(this._allFiles.values()); }; ProjectFileMap.prototype.getFile = function (fullPath) { return this._allFiles.get(fullPath.toLowerCase()); }; ProjectFileMap.prototype.getFileByPkgPath = function (pkgPath) { return this._filesByPkgPath.get(pkgPath.toLowerCase()); }; ProjectFileMap.prototype.getNamespaceByName = function (name) { return this._namespacesByName.get(name.toLowerCase()); }; ProjectFileMap.prototype.getClasssByClassName = function (name) { return this._classesByClassName.get(name.toLowerCase()); }; ProjectFileMap.prototype.getNodeClasssByClassName = function (name) { return this._nodeClassesByClassName.get(name.toLowerCase()); }; ProjectFileMap.prototype.getFileByNamespaceName = function (name) { var namespace = this.getNamespaceByName(name.toLowerCase()); return namespace ? namespace.file : null; }; ProjectFileMap.prototype.addXMLComponent = function (componentName, file) { if (file.fileType === FileType_1.FileType.ViewXml || file.fileType === FileType_1.FileType.Xml) { if (!this.xmlComponentFiles.has(componentName)) { this.xmlComponentFiles.set(componentName, file); } else { var duplicateFile = this.xmlComponentFiles.get(componentName); Feedback_1.feedbackError(file, "Failed, due to duplicate named xml component " + componentName + ". The name is already used by " + duplicateFile.pkgPath); } } }; ProjectFileMap.prototype.addFile = function (file) { this._allFiles.set(file.fullPath.toLowerCase(), file); this._filesByPkgPath.set(file.pkgPath.toLowerCase(), file); if (file.namespace) { this.addNamespace(file.namespace); } }; ProjectFileMap.prototype.addClass = function (brsClass) { if (!this._namespacesByClassName.has(brsClass.className)) { if (brsClass.file.namespace) { this._namespacesByClassName.set(brsClass.className, brsClass.file.namespace); var namespace = new NameSpace_1.Namespace((brsClass.file.namespace.name + "_" + brsClass.className).toLowerCase(), brsClass.file); this.addNamespace(namespace); } this._classesByClassName.set(brsClass.className, brsClass); } else { Feedback_1.feedbackError(brsClass.file, "Failed to create duplicate named class " + brsClass.className + ", which is already declared in namespace " + this._namespacesByClassName.get(brsClass.className).name + ". Please also note, duplicate class names are not supported at this time (i.e. you cannot use the same class name in multiple namespaces? This restriction is not present in the new bs compiler, which is almost complete. Thanks for being patient."); } }; ProjectFileMap.prototype.addNodeClass = function (brsClass) { if (!this.classesByClassName.has(brsClass.className)) { this.classesByClassName.set(brsClass.className, brsClass); } else { Feedback_1.feedbackError(brsClass.file, "Failed to create duplicate named class " + brsClass.className); } }; ProjectFileMap.prototype.addNamespace = function (namespace) { if (!this._namespacesByName.has(namespace.name.toLowerCase())) { this._namespacesByName.set(namespace.name.toLowerCase(), namespace); } }; ProjectFileMap.prototype.addNamespaceMember = function (namespace, memberName) { if (!namespace.membersByName.has(namespace.name.toLowerCase())) { namespace.membersByName.add(memberName); } else { Feedback_1.feedbackError(namespace.file, "Failed to create duplicate member " + memberName + " in namespace " + namespace.name); } }; ProjectFileMap.prototype.getXMLCompTypesFunction = function (namespace) { var text = "\n function " + namespace + "_getAllXMLCompNames()\n return [\n\n "; var compNames = __spread(this.xmlComponentFiles.keys()); compNames.forEach(function (name) { text += " \"" + name + "\"\n"; }); text += "\n]\n'\n end function\n\n "; return text; }; return ProjectFileMap; }()); exports.ProjectFileMap = ProjectFileMap;