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
If you don't specify an icon, the plugin logo will be displayed if any (see [Logo](#logo)).
109
109
110
-
#### Config file
110
+
#### Config files
111
111
112
-
By default, a configuration UI might read and write to a configuration file, for example `.eslintrc.js`.
112
+
By default, a configuration UI might read and write to one or more configuration files, for example both `.eslintrc.js` and `vue.config.js`.
113
113
114
114
You can provide what are the possible files to be detected in the user project:
115
115
@@ -118,17 +118,22 @@ api.describeConfig({
118
118
/* ... */
119
119
// All possible files for this config
120
120
files: {
121
-
json: ['.eslintrc', '.eslintrc.json'],
122
-
js: ['.eslintrc.js'],
123
-
// Will read from `package.json`
124
-
package:'eslintConfig'
121
+
// eslintrc.js
122
+
eslint: {
123
+
js: ['.eslintrc.js'],
124
+
json: ['.eslintrc', '.eslintrc.json'],
125
+
// Will read from `package.json`
126
+
package:'eslintConfig'
127
+
},
128
+
// vue.config.js
129
+
vue: {
130
+
js: ['vue.config.js']
131
+
}
125
132
},
126
133
})
127
134
```
128
135
129
-
Supported types: `json`, `yaml`, `js`, `package`.
130
-
131
-
**⚠️ Currently, only 1 file can be read and written to at a time.**
136
+
Supported types: `json`, `yaml`, `js`, `package`. The order is important: the first filename in the list will be used to create the config file if it doesn't exist.
132
137
133
138
#### Display config prompts
134
139
@@ -149,14 +154,132 @@ Those prompts will be displayed in the configuration details pane.
149
154
150
155
See [Prompts](#prompts) for more info.
151
156
157
+
The `data` object contains the JSON result of each config file content.
158
+
159
+
For example, let's say the user has the following `vue.config.js` in his project:
160
+
161
+
```js
162
+
module.exports= {
163
+
lintOnSave:false
164
+
}
165
+
```
166
+
167
+
We declare the config file in our plugin like this:
168
+
169
+
```js
170
+
api.describeConfig({
171
+
/* ... */
172
+
// All possible files for this config
173
+
files: {
174
+
// vue.config.js
175
+
vue: {
176
+
js: ['vue.config.js']
177
+
}
178
+
},
179
+
})
180
+
```
181
+
182
+
Then the `data` object will be:
183
+
184
+
```js
185
+
{
186
+
// File
187
+
vue: {
188
+
// File data
189
+
lintOnSave:false
190
+
}
191
+
}
192
+
```
193
+
194
+
Multiple files example: if we add the following `eslintrc.js` file in the user project:
195
+
196
+
```js
197
+
module.exports= {
198
+
root:true,
199
+
extends: [
200
+
'plugin:vue/essential',
201
+
'@vue/standard'
202
+
]
203
+
}
204
+
```
205
+
206
+
And change the `files` option in our plugin to this:
207
+
208
+
```js
209
+
api.describeConfig({
210
+
/* ... */
211
+
// All possible files for this config
212
+
files: {
213
+
// eslintrc.js
214
+
eslint: {
215
+
js: ['.eslintrc.js'],
216
+
json: ['.eslintrc', '.eslintrc.json'],
217
+
// Will read from `package.json`
218
+
package:'eslintConfig'
219
+
},
220
+
// vue.config.js
221
+
vue: {
222
+
js: ['vue.config.js']
223
+
}
224
+
},
225
+
})
226
+
```
227
+
228
+
Then the `data` object will be:
229
+
230
+
```js
231
+
{
232
+
eslint: {
233
+
root:true,
234
+
extends: [
235
+
'plugin:vue/essential',
236
+
'@vue/standard'
237
+
]
238
+
},
239
+
vue: {
240
+
lintOnSave:false
241
+
}
242
+
}
243
+
```
244
+
245
+
#### Configuration tabs
246
+
247
+
You can organize the prompts into several tabs:
248
+
249
+
```js
250
+
api.describeConfig({
251
+
/* ... */
252
+
onRead: ({ data, cwd }) => ({
253
+
tabs: [
254
+
{
255
+
id:'tab1',
256
+
label:'My tab',
257
+
// Optional
258
+
icon:'application_settings',
259
+
prompts: [
260
+
// Prompt objects
261
+
]
262
+
},
263
+
{
264
+
id:'tab2',
265
+
label:'My other tab',
266
+
prompts: [
267
+
// Prompt objects
268
+
]
269
+
}
270
+
]
271
+
})
272
+
})
273
+
```
274
+
152
275
#### Save config changes
153
276
154
277
Use the `onWrite` hook to write the data to the configuration file (or execute any nodejs code):
0 commit comments