Skip to content

Commit

Permalink
AUI: Added parts support to anatomy import (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
bheston authored Nov 1, 2024
1 parent e119f94 commit 119ef00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "AUI: Added parts support to anatomy import",
"packageName": "@adaptive-web/adaptive-ui",
"email": "47367562+bheston@users.noreply.github.com",
"dependentChangeType": "patch"
}
17 changes: 12 additions & 5 deletions packages/adaptive-ui/src/bin/aui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,18 @@ program.command("compile-json-anatomy <anatomyPath>")
const impWithExt = imp.toLowerCase().endsWith(".json") ? imp : `${imp}.json`;
const impFilePath = path.format({ ...path.parse(path.join(path.parse(jsonPath).dir, impWithExt)) });
const impData = (await fsp.readFile(impFilePath)).toString();
const impJsonData = JSON.parse(impData);
// If `parts` are in the import, they are for validation/consistency of that file, but we want to use the parts
// list from the main anatomy definition.
// Consider extending this so imports can add their own known parts.
delete impJsonData.parts;
const impJsonData = JSON.parse(impData) as SerializableAnatomy;

// If `parts` are in the import, they are either for validation/consistency of that file
// or additive to the main anatomy definition.
// If the part selector is empty, remove it an use the value from the main anatomy definition.
for (const part in impJsonData.parts) {
if (impJsonData.parts.hasOwnProperty(part)) {
if (impJsonData.parts[part] === "") {
delete impJsonData.parts[part];
}
}
}

jsonData = deepmerge(jsonData, impJsonData);
}
Expand Down

0 comments on commit 119ef00

Please sign in to comment.