You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The JavaScript Transform module is a command-line tool you can use to automatically refactor your JavaScript code.
4
+
5
+
# Usage
6
+
7
+
## Install dependencies
8
+
9
+
To install the dependencies, execute the following command:
10
+
```bash
3
11
yarn --cwd ./vendor/ibexa/rector/js install
4
12
```
5
-
`--cwd` argument should point to directory where JS transform module is installed (for example`./vendor/ibexa/rector/js`). This installs node_modules inside vendor bundle.
13
+
`--cwd` argument must point to the directory where the transform module is installed, by default`./vendor/ibexa/rector/js`.
6
14
7
-
# How to run
8
-
```
15
+
# Running transformations
16
+
17
+
```bash
9
18
yarn --cwd ./vendor/ibexa/rector/js transform
10
19
```
11
-
`--cwd` argument should point to directory where JS transform module is installed (for example`./vendor/ibexa/rector/js`).
20
+
`--cwd` argument must point to the directory where the transform module is installed, by default`./vendor/ibexa/rector/js`.
12
21
13
-
## Configuration file
14
-
If you need to modify default config, plugins or configuration for rules, use `rector.config.js` from main directory of bundle.
15
-
```
22
+
## Configuration
23
+
24
+
To adjust the default configuration, plugins, or rules, modify the `rector.config.js` file present in your project or bundle directory:
25
+
26
+
```js
16
27
module.exports= {
17
28
config: {
18
29
paths: [{
@@ -34,21 +45,27 @@ module.exports = {
34
45
};
35
46
```
36
47
37
-
### config
48
+
### Configuration options
38
49
39
-
#### paths
40
-
Array of objects with input and output directories for transformed files. By default it's relative to main bundle root. While transforming, structure of directories is maintained.
50
+
#### `paths`
41
51
42
-
#### prettierConfigPath
43
-
Optional. At the end of transform there's mandatory prettier execution, which by default is taken from package https://github.com/ibexa/eslint-config-ibexa/blob/main/prettier.js
52
+
Array of objects with input and output directories for transformed files, relative to your project or bundle root.
53
+
Directory structure is not modified during the transformation.
44
54
45
-
### plugins
46
-
Allows to modify enabled plugins (more about plugin below).
55
+
#### `prettierConfigPath`
47
56
48
-
### pluginsConfig
49
-
Allows to modify config for plugins.
50
-
Example config:
51
-
```
57
+
[Prettier](https://prettier.io/) is run at the end of the transformation.
58
+
You can provide the path to your own configuration file, otherwise [the default file](https://github.com/ibexa/eslint-config-ibexa/blob/main/prettier.js) is used.
59
+
60
+
### `plugins`
61
+
62
+
Use it to modify enabled plugins.
63
+
To learn more about plugins, see [the list of plugins](#list-of-plugins).
64
+
65
+
### `pluginsConfig`
66
+
67
+
Use this setting to modify the plugins configuration, as in the example below:
68
+
```js
52
69
{
53
70
"ibexa-rename-string-values": {
54
71
"ez-form-error":"ibexa-form-error",
@@ -67,25 +84,29 @@ Example config:
67
84
}
68
85
}
69
86
```
70
-
Plugin config is kept as object with key being plugin name (`ibexa-rename-string-values` in example).
71
87
72
-
Property key inside this object is string that is supposed to be changed, can be either standard string or regex (`(^|\\s)\\.ez-`, `ezform-error"` in example)
88
+
The plugin configuration is an object with plugin names as keys, for example `ibexa-rename-string-values`.
89
+
Inside a single plugin configuration, the property names are values that should be replaced.
90
+
They can be specified explicitly (`ezform-error`) or by using regexp (`(^|\\s)\\.ez-`).
73
91
74
92
#### Shorthand expression
75
93
76
-
`"ez-form-error": "ibexa-form-error"` - change all `ez-form-error` occurences to `ibexa-form-error`
94
+
You can use a shorthand formto specify the configuration:
77
95
78
-
#### Full object config properties
96
+
-`"ez-form-error": "ibexa-form-error"` - changes all `ez-form-error` occurrences to `ibexa-form-error`
79
97
80
-
`"to": "ibexa-selection-settings"` - what string should be replaced with
98
+
#### Complete plugin configuration
81
99
82
-
`"regexp": true/false` - should config use regexp to match original value
100
+
When not using the shorthand configuration, the following options are available:
83
101
84
-
`"exactMatch": true` - should match only full values, using example config, this won't change `ez-selection-settings__field` as `ez-selection-settings` is not exact match.
102
+
-`"to": "ibexa-selection-settings"` - specifies the new value
103
+
-`"regexp": true/false` - use regexp to find the matching values. Use capture groups to reuse parts of the original value in the new value
104
+
-`"exactMatch": true` - replace matching values only when the whole value is matched. Using the example configuration, `ez-selection-settings__field` would not be replaced as it doesn't match `ez-selection-settings` exactly
85
105
86
106
#### Special "shared" property
87
-
Except named plugins config, there is also possibility to create config for all plugins - its rules are later overwritten by specific plugin config if there is intersection in rules names.
88
-
```
107
+
108
+
You can create a shared configuration for all plugins by using the `shared` keyword, as in the example below:
109
+
```js
89
110
"shared": {
90
111
"ez": {
91
112
"to":"ibexa",
@@ -94,21 +115,26 @@ Except named plugins config, there is also possibility to create config for all
94
115
}
95
116
```
96
117
97
-
## Default plugins
118
+
Values specifies in the `shared` configuration can be overwritten using configuration for specific plugins.
119
+
120
+
## List of plugins
121
+
98
122
### Rename eZ global variables
123
+
99
124
This plugin changes all `eZ` variables to `ibexa`.
100
125
101
-
**Plugin name in config:**`./ibexa-rename-ez-global.js`
126
+
**Name:**`ibexa-rename-ez-global`
102
127
103
-
**Example config:** none
128
+
**Configuration:** none
104
129
105
130
### Rename variables
106
-
This plugin allows to change any variable to any other value.
131
+
This plugin allows to rename any variable.
107
132
108
-
**Plugin name in config:**`./ibexa-rename-variables.js`
133
+
**Name:**`ibexa-rename-variables`
109
134
110
-
**Example config:**
111
-
```
135
+
**Configuration example:**
136
+
137
+
```js
112
138
{
113
139
"^Ez(.*?)Validator$": {
114
140
"to":"Ibexa$1Validator",
@@ -121,18 +147,20 @@ This plugin allows to change any variable to any other value.
This plugin allows to change translations. Remember to extract translations afterwards!
208
+
This plugin changes values in translations.
209
+
Extract translations after running this transformation.
177
210
178
-
**Plugin name in config:**`./ibexa-rename-in-translations.js`
211
+
**Name:**`ibexa-rename-in-translations`
179
212
180
-
**Example config:**
181
-
```
213
+
**Configuration example:**
214
+
215
+
```js
182
216
{
183
217
"to":"ibexa-not-$1--show-modal",
184
218
"regexp":true,
185
219
"selectors-only":true
186
220
}
187
221
```
188
222
189
-
**selectors-only config:**
190
-
191
-
If this property is set to `true`, this plugin changes only strings inside html tags (like classes and other html parameters). Set to `false` or remove property to change also normal strings as well.
223
+
**`selectors-only`:**
192
224
193
-
**Example output with selectors-only=true:**
225
+
If this property is set to `true`, this plugin changes only strings inside HTML tags.
226
+
Set to `false` or remove property to change text values as well.
194
227
195
-
`/*@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")*/`
196
-
197
-
**Example output with selectors-only=false:**
228
+
**Example output:**
198
229
199
-
`/*@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")*/`
230
+
|`selectors-only` value | Before | After |
231
+
|---|---|---|
232
+
| 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")*/`|
233
+
| 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")*/`|
0 commit comments