ui5plugin-parser
Version:
65 lines (64 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JSNodeFileReader = void 0;
const path = require("path");
const ParserPool_1 = require("../../../../parser/pool/ParserPool");
const JSFileReader_1 = require("./JSFileReader");
class JSNodeFileReader extends JSFileReader_1.JSFileReader {
convertClassNameToFSPath(className, isController = false, isFragment = false, isView = false, isFolder = false) {
const parser = ParserPool_1.default.getParserForCustomClass(className);
if (parser !== this._parser) {
return parser?.fileReader.convertClassNameToFSPath(className, isController, isFragment, isView, isFolder);
}
let FSPath;
let extension = ".js";
const manifest = ParserPool_1.default.getManifestForClass(className);
if (manifest) {
if (isController) {
extension = ".controller.js";
}
else if (isFragment) {
extension = ".fragment.xml";
}
else if (isView) {
extension = ".view.xml";
}
else if (isFolder) {
extension = "";
}
const separator = path.sep;
FSPath = `${manifest.fsPath}${className
.replace(manifest.componentName, "")
.replace(/\./g, separator)
.trim()}-dbg${extension}`;
}
return FSPath;
}
_readAllJSFiles() {
const classPaths = this._readFilesInWorkspace("**/*-dbg.js");
const classNames = classPaths.map(path => this.getClassNameFromPath(path));
classNames.forEach(className => {
if (className) {
try {
this._classFactory.getUIClass(className);
}
catch (error) {
console.error(`Error parsing ${className}: ${error.message}`);
}
}
});
}
getAllJSClassNamesFromProject() {
let classNames = [];
const classPaths = this._readFilesInWorkspace("**/*-dbg.js");
classNames = classPaths.reduce((accumulator, viewPath) => {
const path = this.getClassNameFromPath(viewPath);
if (path) {
accumulator.push(path);
}
return accumulator;
}, []);
return classNames;
}
}
exports.JSNodeFileReader = JSNodeFileReader;