Skip to content

Commit 7d12516

Browse files
authored
IBX-10133: Added plugin to rename icons names (#40)
1 parent f62d2ef commit 7d12516

File tree

6 files changed

+300
-4
lines changed

6 files changed

+300
-4
lines changed

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = function (api) {
88
'./js/ibexa-rename-string-values.js',
99
'./js/ibexa-rename-trans-id.js',
1010
'./js/ibexa-rename-in-translations.js',
11+
'./js/ibexa-rename-icons.js',
1112
];
1213
const finalPlugins = modifyPlugins(ibexaPlugins);
1314

js/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,28 @@ Set to `false` or remove property to change text values as well.
231231
|---|---|---|
232232
| 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")*/` |
233233
| 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")*/` |
234+
235+
### Rename icons names used in getIconPath method
236+
This plugin allows you to rename any icon name that is passed as an argument to the `getIconPath` method.
237+
238+
**Name:** `ibexa-rename-icons`
239+
240+
**Configuration example:**
241+
242+
In this plugin, the `exactMatch` default value is set `true` when using the shorthand expression.
243+
244+
``` js
245+
{
246+
"browse": "folder-browse",
247+
"content-": {
248+
to: "file-",
249+
exactMatch: false
250+
}
251+
}
252+
```
253+
254+
**Example:**
255+
256+
| Before | After |
257+
|---|---|
258+
| `getIconPath('browse')` | `getIconPath('folder-browse')` |

js/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const getModifyMethod = (method) => {
4747
};
4848

4949
const getRulesConfig = (name) => {
50-
const modifyConfig = getModifyMethod('config');
50+
const modifyConfig = getModifyMethod('pluginsConfig');
5151
const rulesConfigPath = path.join(__dirname, 'rules.config.json');
5252
const rawData = fs.readFileSync(rulesConfigPath);
5353
const parsedData = JSON.parse(rawData);
@@ -100,7 +100,7 @@ const isFunctionArgument = ({ parentPath }, functionName) => {
100100
return false;
101101
}
102102

103-
return parentPath.node.callee.property?.name === functionName;
103+
return parentPath.node.callee.property?.name === functionName || parentPath.node.callee.name === functionName;
104104
};
105105

106106
module.exports = {

js/ibexa-rename-icons.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { getRulesConfig, traverse, isFunctionArgument } = require('./helpers.js');
2+
3+
const moduleConfig = getRulesConfig('ibexa-rename-icons');
4+
const forcedExactMatchModuleConfig = Object.entries(moduleConfig).reduce((output, [key, value]) => {
5+
return {
6+
...output,
7+
[key]: {
8+
...(typeof value === 'string' ? { to: value } : value),
9+
exactMatch: value.exactMatch ?? true,
10+
},
11+
};
12+
}, {});
13+
14+
module.exports = function () {
15+
return {
16+
visitor: {
17+
StringLiteral(path) {
18+
if (!isFunctionArgument(path, 'getIconPath')) {
19+
return;
20+
}
21+
22+
traverse(forcedExactMatchModuleConfig, path.node.value, (oldValue, newValue) => {
23+
path.node.value = path.node.value.replace(oldValue, newValue);
24+
});
25+
},
26+
},
27+
};
28+
};

js/rules.config.json

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,248 @@
5959
"regexp": true,
6060
"selectors-only": true
6161
}
62+
},
63+
"ibexa-rename-icons": {
64+
"about-info": "help",
65+
"about": "info-square",
66+
"airtime": "signal-radio",
67+
"align-center": "align-text-center",
68+
"align-justify": "align-text-justified",
69+
"align-left": "align-text-left",
70+
"align-right": "align-text-right",
71+
"approved": "check-circle",
72+
"article": "file-text",
73+
"assign-section": "assign",
74+
"author": "user-editor",
75+
"autosave-error": "cloud-error",
76+
"autosave-off": "cloud-discard",
77+
"autosave-on": "cloud",
78+
"autosave-saved": "cloud-check",
79+
"autosave-saving": "cloud-synch",
80+
"b2b": "handshake",
81+
"back": "arrow-left",
82+
"back-current-date": "calendar-back",
83+
"bestseller": "badge-star",
84+
"block-invisible": "block-hidden",
85+
"block-visible-recurring": "block-lock",
86+
"blog": "app-blog",
87+
"blog_post": "note-blog",
88+
"bold": "text-bold",
89+
"bookmark": "favourite-outline",
90+
"bookmark-active": "favourite-filled",
91+
"bookmark-manager": "book",
92+
"box-collapse": "arrow-move-right",
93+
"browse": "folder-browse",
94+
"bubbles": "message-bubble",
95+
"business-deal-cash": "user-money",
96+
"button": "cursor-clicked",
97+
"campaign": "speaker",
98+
"captcha": "form-captcha",
99+
"caret-back": "arrow-chevron-left",
100+
"caret-double-back": "arrow-double-left",
101+
"caret-double-next": "arrow-double-right",
102+
"caret-down": "arrow-chevron-down",
103+
"caret-expanded": "arrow-double-left",
104+
"caret-next": "arrow-chevron-right",
105+
"caret-up": "arrow-chevron-up",
106+
"cart": "shopping-cart",
107+
"cart-full": "shopping-cart",
108+
"cart-upload": "shopping-cart-arrow-up",
109+
"cart-wishlist": "shopping-cart-heart",
110+
"category": "tag",
111+
"checkbox": "form-checkbox",
112+
"checkbox-multiple": "form-check-list",
113+
"checkmark": "form-check",
114+
"circle-caret-down": "chevron-down-circle",
115+
"circle-caret-left": "chevron-left-circle",
116+
"circle-caret-right": "chevron-right-circle",
117+
"circle-caret-up": "chevron-up-circle",
118+
"circle-close": "discard-circle",
119+
"circle-create": "add-circle",
120+
"circle-minus": "minus-circle",
121+
"circle-pause": "minus-circle",
122+
"clicked-recommendations": "cursor-clicked-hand",
123+
"clipboard": "clipboard-check",
124+
"collapse": "arrow-collapse-right",
125+
"content-write": "file-text-write",
126+
"column-settings": "table-settings-column",
127+
"comment": "message",
128+
"components": "box-component",
129+
"connect": "connection",
130+
"content-draft": "draft",
131+
"contentlist": "list-content",
132+
"content-list": "list-content",
133+
"content-type": "tools",
134+
"content-type-content": "file-type",
135+
"content-type-group": "tool-group",
136+
"copy-subtree": "content-tree-copy",
137+
"create": "add",
138+
"create-content": "file-add",
139+
"create-location": "content-tree-create-location",
140+
"customer": "user-customer",
141+
"customer-portal": "device-monitor-user",
142+
"customer-portal-page": "app-user",
143+
"customer-type": "device-monitor-type",
144+
"custom_tags": "prompt",
145+
"date": "calendar",
146+
"date-updated": "calendar-reload",
147+
"discount-coupon": "discount-ticket",
148+
"drafts": "edit-draft",
149+
"dropdown": "form-dropdown",
150+
"earth-access": "world-cursor",
151+
"embed": "text-embedded",
152+
"embed-inline": "text-embedded-inline",
153+
"erp": "connection-erp",
154+
"error": "exclamation-mark",
155+
"error-icon": "file-warning",
156+
"expand-left": "arrow-expand-left",
157+
"expand-right": "arrow-expand-right",
158+
"explore": "ai",
159+
"fields": "form-input",
160+
"file-video": "video",
161+
"flash": "lightning",
162+
"focus": "arrows-outside",
163+
"focus-image": "focus-target",
164+
"folder-empty": "folder-open",
165+
"form": "form-check-square",
166+
"full-view": "arrows-full-view",
167+
"future-publication": "calendar-clock",
168+
"gallery": "image-gallery",
169+
"go-right": "arrow-to-right",
170+
"go-to-root": "content-tree-arrow-up",
171+
"go-up": "arrow-to-up",
172+
"h1": "header-1",
173+
"h2": "header-2",
174+
"h3": "header-3",
175+
"h4": "header-4",
176+
"h5": "header-5",
177+
"h6": "header-6",
178+
"hide": "visibility-hidden",
179+
"hierarchy": "hierarchy-site-map",
180+
"history-file": "file-history",
181+
"'home-page'": "home",
182+
"image-center": "align-block-center",
183+
"image-editor": "image-edit",
184+
"image-left": "align-block-left",
185+
"image-right": "align-block-right",
186+
"image-variations": "image-focus",
187+
"imported-items": "database-synch",
188+
"information": "info-square",
189+
"input-hidden": "form-input-hidden",
190+
"input-line": "form-input-single-line",
191+
"input-line-multiple": "form-input-multi-line",
192+
"input-number": "form-input-number",
193+
"interface-block": "forbidden",
194+
"italic": "text-italic",
195+
"keyword": "hash",
196+
"landing_page": "layout-navbar",
197+
"landingpage-add": "layout-navbar-add",
198+
"landingpage-preview": "layout-navbar-visible",
199+
"languages": "world",
200+
"languages-add": "world-add",
201+
"last-purchased": "cursor-clicked-hand",
202+
"last-viewed": "app-recent",
203+
"layout-manager": "layout",
204+
"link-content": "file-link",
205+
"link-remove": "unlink",
206+
"list": "list-bullet",
207+
"list-numbered": "list-number",
208+
"localize": "target-location",
209+
"location-add-new": "content-tree-create-location",
210+
"lock-unlock": "unlock",
211+
"logout": "log-out",
212+
"maform": "chart-histogram",
213+
"mail": "message-email",
214+
"mail-open": "message-email-read",
215+
"markup": "file-code",
216+
"menu": "menu-hamburger",
217+
"move": "folder-open-move",
218+
"newsletter": "news",
219+
"notice": "alert-error",
220+
"open-newtab": "open-new-window",
221+
"open-sametab": "open-same-window",
222+
"options": "more",
223+
"order-history": "file-history",
224+
"order-management": "receipt-settings",
225+
"order-status": "product-search",
226+
"panels": "view-panels",
227+
"paragraph": "text-paragraph",
228+
"paragraph-add": "text-paragraph-add",
229+
"pdf-file": "file-pdf",
230+
"personalize": "user-target",
231+
"personalize-block": "file-settings",
232+
"personalize-content": "tag-settings",
233+
"pin-unpin": "unpin",
234+
"place": "pin-location",
235+
"places": "pins-locations",
236+
"portfolio": "suitcase",
237+
"previewed": "overdue",
238+
"product-category": "product-tag",
239+
"product-list": "clipboard-list",
240+
"product_list": "clipboard-list",
241+
"product-low": "product-arrow-down",
242+
"product type": "product-collection",
243+
"product-type": "product-collection",
244+
"profile": "user-profile",
245+
"publish": "rocket",
246+
"publish-later": "calendar-number",
247+
"publish-later-cancel": "calendar-discard",
248+
"publish-later-create": "calendar-add",
249+
"qa-content": "qa-file",
250+
"qa-form": "qa-form-check",
251+
"radio-button": "form-radio",
252+
"radio-button-multiple": "form-radio-list",
253+
"rate": "stars",
254+
"rate-review": "star-circle",
255+
"recent-activity": "activity-clock",
256+
"recently-added": "history",
257+
"recommendation-calls": "arrows-circle",
258+
"redo": "action-redo",
259+
"refresh": "arrows-reload",
260+
"rejected": "arrow-to-down-circle",
261+
"relations": "hierarchy-square",
262+
"restore": "arrow-restore",
263+
"restore-parent": "content-tree-restore-parent",
264+
"review": "message-edit",
265+
"roles": "user-id",
266+
"rss": "signal-rss",
267+
"schedule": "calendar-schedule",
268+
"sections": "database",
269+
"send-email": "send",
270+
"settings-block": "settings",
271+
"settings-config": "settings-configure",
272+
"sites-all": "sites",
273+
"spinner": "arrow-rotate",
274+
"stats": "chart-dots",
275+
"strikethrough": "text-strikethrough",
276+
"subscriber": "user-mail",
277+
"subscript": "text-subscript",
278+
"superscript": "text-superscript",
279+
"swap": "arrows-synchronize",
280+
"system-information": "info-circle",
281+
"trash-empty": "trash-discard",
282+
"trash-notrashed": "trash-open",
283+
"underscore": "text-underline",
284+
"undo": "action-undo",
285+
"un-focus": "arrows-inside",
286+
"un-full-view": "arrows-full-view-out",
287+
"upload-image": "image-upload",
288+
"user-blocked": "user-block",
289+
"user_group": "user-group",
290+
"users-personalization": "user-focus",
291+
"user-recycle": "arrows-reload-user",
292+
"users-select": "users-add",
293+
"user-tick": "user-check",
294+
"version-compare": "action-compare-versions",
295+
"version-compare-action": "action-compare",
296+
"versions": "archived-version",
297+
"vertical-left-right": "arrow-collapse-expand",
298+
"view": "visibility",
299+
"view-desktop": "device-monitor",
300+
"view-hide": "visibility-hidden",
301+
"view-mobile": "device-mobile",
302+
"view-tablet": "device-tablet",
303+
"warning": "alert-warning",
304+
"warning-triangle": "alert-warning"
62305
}
63306
}

js/transform-script.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const { execSync } = require('child_process');
2-
const path = require('path');
32
const fs = require('fs');
43

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

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

2221
try {
2322
execSync(command, { stdio: 'inherit' });

0 commit comments

Comments
 (0)