Skip to content

Commit d11290a

Browse files
author
Guillaume Chau
committed
feat(plugin api): task match can now be a function
1 parent da66f93 commit d11290a

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

docs/dev-guide/ui-api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ api.describeTask({
350350
})
351351
```
352352

353+
You can also use a function for `match`:
354+
355+
```js
356+
api.describeTask({
357+
match: (command) => /vue-cli-service serve/.test(command),
358+
})
359+
```
360+
353361
### Task icon
354362

355363
It can be either a [Material icon](https://material.io/tools/icons) code or a custom image (see [Public static files](#public-static-files)):

packages/@vue/cli-ui/apollo-server/api/PluginApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class PluginApi {
191191
*/
192192
getDescribedTask (command) {
193193
return this.describedTasks.find(
194-
options => options.match.test(command)
194+
options => typeof options.match === 'function' ? options.match(command) : options.match.test(command)
195195
)
196196
}
197197

packages/@vue/cli-ui/apollo-server/api/task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const schema = joi => ({
1818
})
1919

2020
const describeSchema = createSchema(joi => ({
21-
match: joi.object().type(RegExp).required().description('Match a npm script command'),
21+
match: joi.alternatives().try(joi.object().type(RegExp), joi.func()).required().description('Match a npm script command'),
2222
...schema(joi)
2323
}))
2424

0 commit comments

Comments
 (0)