From 91e9a88e3a83530e1dce2e72b8796da24775dcf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 12 Dec 2022 16:41:18 +0100 Subject: [PATCH] fix: Ensure parent directory exists before copying over the icons to 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. --- packages/cli/src/LoadNodesAndCredentials.ts | 34 +++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/cli/src/LoadNodesAndCredentials.ts b/packages/cli/src/LoadNodesAndCredentials.ts index af6b6a146..bb612dd7f 100644 --- a/packages/cli/src/LoadNodesAndCredentials.ts +++ b/packages/cli/src/LoadNodesAndCredentials.ts @@ -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> = []; - 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