Skip to content

IBX-10133: [Rector] Added plugin to rename icons names #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function (api) {
'./js/ibexa-rename-string-values.js',
'./js/ibexa-rename-trans-id.js',
'./js/ibexa-rename-in-translations.js',
'./js/ibexa-rename-icons.js',
];
const finalPlugins = modifyPlugins(ibexaPlugins);

Expand Down
25 changes: 25 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,28 @@ Set to `false` or remove property to change text values as well.
|---|---|---|
| true | `/*@Desc("<p class='ez-not-error--show-modal'>Show message</p> for ez-not-error--show-modal")*/` | `/*@Desc("<p class='ibexa-not-error--show-modal'>Show message</p> for ez-not-error--show-modal")*/` |
| false | `/*@Desc("<p class='ez-not-error--show-modal'>Show message</p> for ez-not-error--show-modal")*/` | `/*@Desc("<p class='ibexa-not-error--show-modal'>Show message</p> for ibexa-not-error--show-modal")*/` |

### Rename icons names used in getIconPath method
This plugin allows you to rename any icon name that is passed as an argument to the `getIconPath` method.

**Name:** `ibexa-rename-icons`

**Configuration example:**

In this plugin, the `exactMatch` default value is set `true` when using the shorthand expression.

``` js
{
"browse": "folder-browse",
"content-": {
to: "file-",
exactMatch: false
}
}
```

**Example:**

| Before | After |
|---|---|
| `getIconPath('browse')` | `getIconPath('folder-browse')` |
4 changes: 2 additions & 2 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getModifyMethod = (method) => {
};

const getRulesConfig = (name) => {
const modifyConfig = getModifyMethod('config');
const modifyConfig = getModifyMethod('pluginsConfig');
const rulesConfigPath = path.join(__dirname, 'rules.config.json');
const rawData = fs.readFileSync(rulesConfigPath);
const parsedData = JSON.parse(rawData);
Expand Down Expand Up @@ -100,7 +100,7 @@ const isFunctionArgument = ({ parentPath }, functionName) => {
return false;
}

return parentPath.node.callee.property?.name === functionName;
return parentPath.node.callee.property?.name === functionName || parentPath.node.callee.name === functionName;
};

module.exports = {
Expand Down
28 changes: 28 additions & 0 deletions js/ibexa-rename-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { getRulesConfig, traverse, isFunctionArgument } = require('./helpers.js');

const moduleConfig = getRulesConfig('ibexa-rename-icons');
const forcedExactMatchModuleConfig = Object.entries(moduleConfig).reduce((output, [key, value]) => {
return {
...output,
[key]: {
...(typeof value === 'string' ? { to: value } : value),
exactMatch: value.exactMatch ?? true,
},
};
}, {});

module.exports = function () {
return {
visitor: {
StringLiteral(path) {
if (!isFunctionArgument(path, 'getIconPath')) {
return;
}

traverse(forcedExactMatchModuleConfig, path.node.value, (oldValue, newValue) => {
path.node.value = path.node.value.replace(oldValue, newValue);
});
},
},
};
};
243 changes: 243 additions & 0 deletions js/rules.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,248 @@
"regexp": true,
"selectors-only": true
}
},
"ibexa-rename-icons": {
"about-info": "help",
"about": "info-square",
"airtime": "signal-radio",
"align-center": "align-text-center",
"align-justify": "align-text-justified",
"align-left": "align-text-left",
"align-right": "align-text-right",
"approved": "check-circle",
"article": "file-text",
"assign-section": "assign",
"author": "user-editor",
"autosave-error": "cloud-error",
"autosave-off": "cloud-discard",
"autosave-on": "cloud",
"autosave-saved": "cloud-check",
"autosave-saving": "cloud-synch",
"b2b": "handshake",
"back": "arrow-left",
"back-current-date": "calendar-back",
"bestseller": "badge-star",
"block-invisible": "block-hidden",
"block-visible-recurring": "block-lock",
"blog": "app-blog",
"blog_post": "note-blog",
"bold": "text-bold",
"bookmark": "favourite-outline",
"bookmark-active": "favourite-filled",
"bookmark-manager": "book",
"box-collapse": "arrow-move-right",
"browse": "folder-browse",
"bubbles": "message-bubble",
"business-deal-cash": "user-money",
"button": "cursor-clicked",
"campaign": "speaker",
"captcha": "form-captcha",
"caret-back": "arrow-chevron-left",
"caret-double-back": "arrow-double-left",
"caret-double-next": "arrow-double-right",
"caret-down": "arrow-chevron-down",
"caret-expanded": "arrow-double-left",
"caret-next": "arrow-chevron-right",
"caret-up": "arrow-chevron-up",
"cart": "shopping-cart",
"cart-full": "shopping-cart",
"cart-upload": "shopping-cart-arrow-up",
"cart-wishlist": "shopping-cart-heart",
"category": "tag",
"checkbox": "form-checkbox",
"checkbox-multiple": "form-check-list",
"checkmark": "form-check",
"circle-caret-down": "chevron-down-circle",
"circle-caret-left": "chevron-left-circle",
"circle-caret-right": "chevron-right-circle",
"circle-caret-up": "chevron-up-circle",
"circle-close": "discard-circle",
"circle-create": "add-circle",
"circle-minus": "minus-circle",
"circle-pause": "minus-circle",
"clicked-recommendations": "cursor-clicked-hand",
"clipboard": "clipboard-check",
"collapse": "arrow-collapse-right",
"content-write": "file-text-write",
"column-settings": "table-settings-column",
"comment": "message",
"components": "box-component",
"connect": "connection",
"content-draft": "draft",
"contentlist": "list-content",
"content-list": "list-content",
"content-type": "tools",
"content-type-content": "file-type",
"content-type-group": "tool-group",
"copy-subtree": "content-tree-copy",
"create": "add",
"create-content": "file-add",
"create-location": "content-tree-create-location",
"customer": "user-customer",
"customer-portal": "device-monitor-user",
"customer-portal-page": "app-user",
"customer-type": "device-monitor-type",
"custom_tags": "prompt",
"date": "calendar",
"date-updated": "calendar-reload",
"discount-coupon": "discount-ticket",
"drafts": "edit-draft",
"dropdown": "form-dropdown",
"earth-access": "world-cursor",
"embed": "text-embedded",
"embed-inline": "text-embedded-inline",
"erp": "connection-erp",
"error": "exclamation-mark",
"error-icon": "file-warning",
"expand-left": "arrow-expand-left",
"expand-right": "arrow-expand-right",
"explore": "ai",
"fields": "form-input",
"file-video": "video",
"flash": "lightning",
"focus": "arrows-outside",
"focus-image": "focus-target",
"folder-empty": "folder-open",
"form": "form-check-square",
"full-view": "arrows-full-view",
"future-publication": "calendar-clock",
"gallery": "image-gallery",
"go-right": "arrow-to-right",
"go-to-root": "content-tree-arrow-up",
"go-up": "arrow-to-up",
"h1": "header-1",
"h2": "header-2",
"h3": "header-3",
"h4": "header-4",
"h5": "header-5",
"h6": "header-6",
"hide": "visibility-hidden",
"hierarchy": "hierarchy-site-map",
"history-file": "file-history",
"'home-page'": "home",
"image-center": "align-block-center",
"image-editor": "image-edit",
"image-left": "align-block-left",
"image-right": "align-block-right",
"image-variations": "image-focus",
"imported-items": "database-synch",
"information": "info-square",
"input-hidden": "form-input-hidden",
"input-line": "form-input-single-line",
"input-line-multiple": "form-input-multi-line",
"input-number": "form-input-number",
"interface-block": "forbidden",
"italic": "text-italic",
"keyword": "hash",
"landing_page": "layout-navbar",
"landingpage-add": "layout-navbar-add",
"landingpage-preview": "layout-navbar-visible",
"languages": "world",
"languages-add": "world-add",
"last-purchased": "cursor-clicked-hand",
"last-viewed": "app-recent",
"layout-manager": "layout",
"link-content": "file-link",
"link-remove": "unlink",
"list": "list-bullet",
"list-numbered": "list-number",
"localize": "target-location",
"location-add-new": "content-tree-create-location",
"lock-unlock": "unlock",
"logout": "log-out",
"maform": "chart-histogram",
"mail": "message-email",
"mail-open": "message-email-read",
"markup": "file-code",
"menu": "menu-hamburger",
"move": "folder-open-move",
"newsletter": "news",
"notice": "alert-error",
"open-newtab": "open-new-window",
"open-sametab": "open-same-window",
"options": "more",
"order-history": "file-history",
"order-management": "receipt-settings",
"order-status": "product-search",
"panels": "view-panels",
"paragraph": "text-paragraph",
"paragraph-add": "text-paragraph-add",
"pdf-file": "file-pdf",
"personalize": "user-target",
"personalize-block": "file-settings",
"personalize-content": "tag-settings",
"pin-unpin": "unpin",
"place": "pin-location",
"places": "pins-locations",
"portfolio": "suitcase",
"previewed": "overdue",
"product-category": "product-tag",
"product-list": "clipboard-list",
"product_list": "clipboard-list",
"product-low": "product-arrow-down",
"product type": "product-collection",
"product-type": "product-collection",
"profile": "user-profile",
"publish": "rocket",
"publish-later": "calendar-number",
"publish-later-cancel": "calendar-discard",
"publish-later-create": "calendar-add",
"qa-content": "qa-file",
"qa-form": "qa-form-check",
"radio-button": "form-radio",
"radio-button-multiple": "form-radio-list",
"rate": "stars",
"rate-review": "star-circle",
"recent-activity": "activity-clock",
"recently-added": "history",
"recommendation-calls": "arrows-circle",
"redo": "action-redo",
"refresh": "arrows-reload",
"rejected": "arrow-to-down-circle",
"relations": "hierarchy-square",
"restore": "arrow-restore",
"restore-parent": "content-tree-restore-parent",
"review": "message-edit",
"roles": "user-id",
"rss": "signal-rss",
"schedule": "calendar-schedule",
"sections": "database",
"send-email": "send",
"settings-block": "settings",
"settings-config": "settings-configure",
"sites-all": "sites",
"spinner": "arrow-rotate",
"stats": "chart-dots",
"strikethrough": "text-strikethrough",
"subscriber": "user-mail",
"subscript": "text-subscript",
"superscript": "text-superscript",
"swap": "arrows-synchronize",
"system-information": "info-circle",
"trash-empty": "trash-discard",
"trash-notrashed": "trash-open",
"underscore": "text-underline",
"undo": "action-undo",
"un-focus": "arrows-inside",
"un-full-view": "arrows-full-view-out",
"upload-image": "image-upload",
"user-blocked": "user-block",
"user_group": "user-group",
"users-personalization": "user-focus",
"user-recycle": "arrows-reload-user",
"users-select": "users-add",
"user-tick": "user-check",
"version-compare": "action-compare-versions",
"version-compare-action": "action-compare",
"versions": "archived-version",
"vertical-left-right": "arrow-collapse-expand",
"view": "visibility",
"view-desktop": "device-monitor",
"view-hide": "visibility-hidden",
"view-mobile": "device-mobile",
"view-tablet": "device-tablet",
"warning": "alert-warning",
"warning-triangle": "alert-warning"
}
}
3 changes: 1 addition & 2 deletions js/transform-script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');

const { getMainConfig, getPrettierConfigFile, getAbsolutePath } = require('./helpers');
Expand All @@ -17,7 +16,7 @@ paths.forEach(({ input, output }) => {
}

let command = `babel ${inputAbsolutePath} -d ${outputAbsolutePath} --retain-lines`;
command += ` && yarn prettier "${outputAbsolutePath}/**/*.js" --config ${prettierConfigFile} --write`;
command += ` && yarn prettier "${outputAbsolutePath}/**/*.js" --config ${prettierConfigFile} --write --log-level warn`;

try {
execSync(command, { stdio: 'inherit' });
Expand Down