feat: Add support for dark mode node icons and colors (#9412)

Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
This commit is contained in:
Elias Meire
2024-06-06 13:34:30 +02:00
committed by GitHub
parent 68e856d155
commit 600013a1ab
294 changed files with 1421 additions and 519 deletions

View File

@@ -101,11 +101,11 @@ export abstract class DirectoryLoader {
tempNode.description.name = fullNodeName;
this.fixIconPath(tempNode.description, filePath);
this.fixIconPaths(tempNode.description, filePath);
if ('nodeVersions' in tempNode) {
for (const versionNode of Object.values(tempNode.nodeVersions)) {
this.fixIconPath(versionNode.description, filePath);
this.fixIconPaths(versionNode.description, filePath);
}
for (const version of Object.values(tempNode.nodeVersions)) {
@@ -169,7 +169,7 @@ export abstract class DirectoryLoader {
// include the credential type in the predefined credentials (HTTP node)
Object.assign(tempCredential, { toJSON });
this.fixIconPath(tempCredential, filePath);
this.fixIconPaths(tempCredential, filePath);
} catch (e) {
if (e instanceof TypeError) {
throw new ApplicationError(
@@ -281,14 +281,29 @@ export abstract class DirectoryLoader {
}
}
private fixIconPath(
private getIconPath(icon: string, filePath: string) {
const iconPath = path.join(path.dirname(filePath), icon.replace('file:', ''));
const relativePath = path.relative(this.directory, iconPath);
return `icons/${this.packageName}/${relativePath}`;
}
private fixIconPaths(
obj: INodeTypeDescription | INodeTypeBaseDescription | ICredentialType,
filePath: string,
) {
if (obj.icon?.startsWith('file:')) {
const iconPath = path.join(path.dirname(filePath), obj.icon.substring(5));
const relativePath = path.relative(this.directory, iconPath);
obj.iconUrl = `icons/${this.packageName}/${relativePath}`;
const { icon } = obj;
if (!icon) return;
if (typeof icon === 'string') {
if (icon.startsWith('file:')) {
obj.iconUrl = this.getIconPath(icon, filePath);
delete obj.icon;
}
} else if (icon.light.startsWith('file:') && icon.dark.startsWith('file:')) {
obj.iconUrl = {
light: this.getIconPath(icon.light, filePath),
dark: this.getIconPath(icon.dark, filePath),
};
delete obj.icon;
}
}