Skip to content

Commit e07abbb

Browse files
author
Guillaume Chau
committed
feat(ui): PluginApi -> describeTask initial impl.
1 parent fbc9a09 commit e07abbb

File tree

19 files changed

+380
-98
lines changed

19 files changed

+380
-98
lines changed

packages/@vue/cli-plugin-eslint/ui.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
module.exports = api => {
2+
// Config file
3+
api.describeConfig({
4+
name: 'ESLint configuration',
5+
description: 'Error checking & Code quality',
6+
link: 'https://eslint.org',
7+
files: {
8+
json: ['eslintrc', 'eslintrc.json'],
9+
js: ['eslintrc.js'],
10+
package: 'eslintConfig'
11+
},
12+
onRead: ({ data }) => {
13+
return {
14+
prompts: [
15+
{
16+
name: 'rules.commaDangle',
17+
type: 'list',
18+
message: 'Trailing commas',
19+
description: 'Enforce or disallow trailing commas at the end of the lines',
20+
link: 'https://eslint.org/docs/rules/comma-dangle',
21+
choices: [
22+
{
23+
name: 'Off',
24+
value: 'off'
25+
},
26+
{
27+
name: 'Never',
28+
value: JSON.stringify(['error', 'never'])
29+
},
30+
{
31+
name: 'Always',
32+
value: JSON.stringify(['error', 'always'])
33+
},
34+
{
35+
name: 'Always on multiline',
36+
value: JSON.stringify(['error', 'always-multiline'])
37+
},
38+
{
39+
name: 'Only on multiline',
40+
value: JSON.stringify(['error', 'only-multiline'])
41+
}
42+
],
43+
value: JSON.stringify(data.rules['comma-dangle'] || ['error', 'never'])
44+
}
45+
]
46+
}
47+
},
48+
onWrite: ({ file, answers }) => {
49+
file.assignData({
50+
'rules.comma-dangle': answers.rules.commaDangle
51+
})
52+
}
53+
})
54+
55+
// Tasks
56+
api.describeTask({
57+
match: /vue-cli-service lint/,
58+
description: 'Lints and fixes files',
59+
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint#injected-commands',
60+
prompts: [
61+
{
62+
name: 'noFix',
63+
type: 'confirm',
64+
default: false,
65+
description: 'Do not fix errors'
66+
}
67+
],
68+
onRun: ({ answers, args }) => {
69+
if (answers.noFix) {
70+
args.push('--no-fix')
71+
}
72+
}
73+
})
74+
}

packages/@vue/cli-ui/src/components/TaskItem.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<ListItemInfo
1919
:name="task.name"
20-
:description="task.description || status"
20+
:description="(task.status === 'idle' && task.description) || status"
2121
:selected="selected"
2222
/>
2323
</div>
@@ -72,6 +72,11 @@ export default {
7272
flex 100% 1 1
7373
width 0
7474
75+
>>> .description
76+
white-space nowrap
77+
overflow hidden
78+
text-overflow ellipsis
79+
7580
&.selected
7681
&.status-error .list-item-info >>> .name
7782
color $vue-ui-color-danger
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class PluginApi {
2+
constructor () {
3+
this.configurations = []
4+
this.tasks = []
5+
}
6+
7+
describeConfig (options) {
8+
this.configurations.push(options)
9+
}
10+
11+
describeTask (options) {
12+
this.tasks.push(options)
13+
}
14+
15+
getTask (command) {
16+
return this.tasks.find(
17+
options => options.match.test(command)
18+
)
19+
}
20+
}
21+
22+
module.exports = PluginApi

packages/@vue/cli-ui/src/graphql-api/connectors/logs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const shortId = require('shortid')
22
const { events } = require('@vue/cli-shared-utils/lib/logger')
33
const { generateTitle } = require('@vue/cli/lib/util/clearConsole')
4-
4+
// Subs
55
const channels = require('../channels')
66

77
let init = false

packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,44 @@ const {
88
getPluginLink
99
} = require('@vue/cli-shared-utils')
1010
const getPackageVersion = require('@vue/cli/lib/util/getPackageVersion')
11+
const { resolveModule, loadModule } = require('@vue/cli/lib/util/module')
1112
const {
1213
progress: installProgress,
1314
installPackage,
1415
uninstallPackage,
1516
updatePackage
1617
} = require('@vue/cli/lib/util/installDeps')
1718
const invoke = require('@vue/cli/lib/invoke')
18-
19+
// Connectors
1920
const cwd = require('./cwd')
2021
const folders = require('./folders')
2122
const prompts = require('./prompts')
2223
const progress = require('./progress')
2324
const logs = require('./logs')
24-
25+
// Api
26+
const PluginApi = require('../api/PluginApi')
27+
// Utils
2528
const { getCommand } = require('../utils/command')
2629

30+
const PROGRESS_ID = 'plugin-installation'
31+
32+
// Caches
2733
const metadataCache = new LRU({
2834
max: 200,
2935
maxAge: 1000 * 60 * 30
3036
})
31-
3237
const logoCache = new LRU({
3338
max: 50
3439
})
3540

36-
const PROGRESS_ID = 'plugin-installation'
37-
41+
// Local
3842
let currentPluginId
3943
let eventsInstalled = false
4044
let plugins = []
45+
let pluginApi
4146

4247
function getPath (id) {
43-
return path.dirname(require.resolve(id, {
44-
paths: [cwd.get()]
45-
}))
48+
return path.dirname(resolveModule(id, cwd.get()))
4649
}
4750

4851
function findPlugins (deps) {
@@ -64,9 +67,23 @@ function list (file, context) {
6467
plugins = []
6568
plugins = plugins.concat(findPlugins(pkg.dependencies || {}))
6669
plugins = plugins.concat(findPlugins(pkg.devDependencies || {}))
70+
resetPluginApi(context)
6771
return plugins
6872
}
6973

74+
function resetPluginApi (context) {
75+
pluginApi = new PluginApi()
76+
plugins.forEach(plugin => runPluginApi(plugin.id, context))
77+
}
78+
79+
function runPluginApi (id, context) {
80+
const module = loadModule(`${id}/ui`, cwd.get(), true)
81+
if (module) {
82+
module(pluginApi)
83+
console.log(`PluginApi called for ${id}`)
84+
}
85+
}
86+
7087
function findOne (id, context) {
7188
return plugins.find(
7289
p => p.id === id
@@ -175,13 +192,9 @@ function install (id, context) {
175192
status: 'plugin-install',
176193
args: [id]
177194
})
178-
179195
currentPluginId = id
180-
181196
await installPackage(cwd.get(), getCommand(), null, id)
182-
183197
await initPrompts(id, context)
184-
185198
return getInstallation(context)
186199
})
187200
}
@@ -192,13 +205,9 @@ function uninstall (id, context) {
192205
status: 'plugin-uninstall',
193206
args: [id]
194207
})
195-
196208
currentPluginId = id
197-
198209
await uninstallPackage(cwd.get(), getCommand(), null, id)
199-
200210
currentPluginId = null
201-
202211
return getInstallation(context)
203212
})
204213
}
@@ -209,13 +218,14 @@ function runInvoke (id, context) {
209218
status: 'plugin-invoke',
210219
args: [id]
211220
})
212-
213221
currentPluginId = id
214-
215-
await invoke(id, prompts.getAnswers(), cwd.get())
216-
222+
// Allow plugins that don't have a generator
223+
if (resolveModule(`${id}/generator`, cwd.get())) {
224+
await invoke(id, prompts.getAnswers(), cwd.get())
225+
}
226+
// Run plugin api
227+
runPluginApi(id, context)
217228
currentPluginId = null
218-
219229
return getInstallation(context)
220230
})
221231
}
@@ -240,25 +250,23 @@ function update (id, context) {
240250
status: 'plugin-update',
241251
args: [id]
242252
})
243-
244253
currentPluginId = id
245-
246254
const plugin = findOne(id, context)
247255
const { current, wanted } = await getVersion(plugin, context)
248-
249256
await updatePackage(cwd.get(), getCommand(), null, id)
250-
251257
logs.add({
252258
message: `Plugin ${id} updated from ${current} to ${wanted}`,
253259
type: 'info'
254260
}, context)
255-
256261
currentPluginId = null
257-
258262
return findOne(id)
259263
})
260264
}
261265

266+
function getApi () {
267+
return pluginApi
268+
}
269+
262270
module.exports = {
263271
list,
264272
findOne,
@@ -269,5 +277,7 @@ module.exports = {
269277
install,
270278
uninstall,
271279
update,
272-
runInvoke
280+
runInvoke,
281+
resetPluginApi,
282+
getApi
273283
}

packages/@vue/cli-ui/src/graphql-api/connectors/progress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Subs
12
const channels = require('../channels')
23

34
let map = new Map()

0 commit comments

Comments
 (0)