Skip to content

Commit

Permalink
fix: Ensure parent directory exists before copying over the icons to …
Browse files Browse the repository at this point in the history
…generated static directory (#4865)

fix: Ensure parent directory exists before copying over the icon to generated static directory.

This fixes the issue of icons not showing up for custom nodes that use a package-name with a `/` in them.
  • Loading branch information
netroy authored Dec 12, 2022
1 parent 61aafc9 commit 91e9a88
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions packages/cli/src/LoadNodesAndCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,21 @@ export class LoadNodesAndCredentialsClass implements INodesAndCredentials {
this.types.credentials = this.types.credentials.concat(types.credentials);

// Copy over all icons and set `iconUrl` for the frontend
const iconPromises: Array<Promise<void>> = [];
for (const node of types.nodes) {
if (node.icon?.startsWith('file:')) {
const icon = node.icon.substring(5);
const iconUrl = `icons/nodes/${node.name}${path.extname(icon)}`;
delete node.icon;
node.iconUrl = iconUrl;
iconPromises.push(copyFile(path.join(dir, icon), path.join(GENERATED_STATIC_DIR, iconUrl)));
}
}
for (const credential of types.credentials) {
if (credential.icon?.startsWith('file:')) {
const icon = credential.icon.substring(5);
const iconUrl = `icons/credentials/${credential.name}${path.extname(icon)}`;
delete credential.icon;
credential.iconUrl = iconUrl;
iconPromises.push(copyFile(path.join(dir, icon), path.join(GENERATED_STATIC_DIR, iconUrl)));
}
}
const iconPromises = Object.entries(types).flatMap(([typeName, typesArr]) =>
typesArr.map((type) => {
if (!type.icon?.startsWith('file:')) return;
const icon = type.icon.substring(5);
const iconUrl = `icons/${typeName}/${type.name}${path.extname(icon)}`;
delete type.icon;
type.iconUrl = iconUrl;
const source = path.join(dir, icon);
const destination = path.join(GENERATED_STATIC_DIR, iconUrl);
return mkdir(path.dirname(destination), { recursive: true }).then(async () =>
copyFile(source, destination),
);
}),
);

await Promise.all(iconPromises);

// Nodes and credentials that have been loaded immediately
Expand Down

0 comments on commit 91e9a88

Please sign in to comment.