Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions server/src/parser/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function findPackageEntryPoints(
// Iterate over all template files up to the root package and populate
// templateNodes, TEMPLATE_LIST, PACKAGE_LIST and entryPoints.

for (let templateJson of [...templateNodes.map(({json}) => json)]) {
for (let templateJson of [...templateNodes.map(({ json }) => json)]) {
let packageName = (templateJson as any).within;
while (packageName && packageName !== rootPackageName) {
const packagePath = getPathFromClassName(packageName, dir);
Expand Down Expand Up @@ -157,15 +157,15 @@ export function findPackageEntryPoints(
}
});

return templateNodes.map(({ className, json }) => { return { className, json }; });
return templateNodes.map(({ className, json }) => {
return { className, json };
});
}

/**
* Gets the path to a Modelica JSON file based on the full class name.
* - LIMITATION: This function requires that the library packages use
* [Directory Hierarchy Mapping](https://specification.modelica.org/maint/3.6/packages.html#directory-hierarchy-mapping)
* @param className - The full Modelica class name (e.g. "Library.Package.Class")
* @param dirPath - The directory path to search in
* @param dirPath - The directory path to search in (e.g. element of MODELICA_JSON_PATH)
* @returns The file path if found, null otherwise
*/
function getPathFromClassName(
Expand All @@ -177,18 +177,11 @@ function getPathFromClassName(
let jsonFile = path.resolve(dirPath, filePath.dir, `${filePath.name}.json`);

while (!fs.existsSync(jsonFile) && filePath.name) {
// check if definition already exists
// TODO - construct this path correctly...
const curPath = path.relative(filePath.dir, filePath.name);
const modelicaPath = getClassNameFromRelativePath(curPath);
if (typeStore.has(modelicaPath)) {
break;
}
// package definitions break the typical modelica path to file mapping that
// is used. A typical modelica path to file path look like:
// 'Template.AirHandlerFans.VAVMultizone' -> 'Template/AirhandlerFans/VAVMultizone.json'
// We need to support mapping like this as well:
// 'Template.AirHandlerFans -> Template/AirhandlerFans/package.json'
/* Typically modelica class name to file path looks like:
* Templates.AirHandlerFans.VAVMultizone -> Templates/AirhandlerFans/VAVMultizone.json
* For directory mapping of packages, we need to support mapping like:
* Templates.AirHandlerFans -> Templates/AirhandlerFans/package.json
*/
jsonFile = path.resolve(
dirPath,
filePath.dir,
Expand All @@ -198,6 +191,10 @@ function getPathFromClassName(
if (fs.existsSync(jsonFile)) {
break;
}
/*
* We iterate and trim the file path to cover single file mapping of packages:
* e.g. Buildings.Types.Reset in Buildings/Types.json
*/
filePath = path.parse(filePath.dir);
jsonFile = path.resolve(dirPath, filePath.dir, `${filePath.name}.json`);
}
Expand Down