Skip to content

Commit ce4cf9a

Browse files
author
Guillaume Chau
committed
feat(ui): plugin add prompts
1 parent 63ccde8 commit ce4cf9a

File tree

9 files changed

+146
-212
lines changed

9 files changed

+146
-212
lines changed

packages/@vue/cli-ui/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"build": "vue-cli-service build",
77
"lint": "vue-cli-service lint",
88
"graphql-api": "vue-cli-service graphql-api",
9-
"run-graphql-api": "vue-cli-service run-graphql-api"
9+
"run-graphql-api": "vue-cli-service run-graphql-api",
10+
"prod-graphql-api": "cross-env NODE_ENV=production vue-cli-service run-graphql-api"
1011
},
1112
"dependencies": {
1213
"graphql": "^0.13.0",
@@ -38,7 +39,7 @@
3839
"subscriptions-transport-ws": "^0.9.5",
3940
"vue": "^2.5.13",
4041
"vue-apollo": "^3.0.0-beta.5",
41-
"vue-cli-plugin-apollo": "^0.4.1",
42+
"vue-cli-plugin-apollo": "^0.6.1",
4243
"vue-instantsearch": "^1.5.1",
4344
"vue-router": "^3.0.1",
4445
"vue-template-compiler": "^2.5.13",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div class="prompt prompt-input">
3+
<div class="prompt-content">
4+
<ListItemInfo
5+
:name="prompt.message"
6+
:description="prompt.description"
7+
:link="prompt.link"
8+
/>
9+
10+
<div class="prompt-input">
11+
<VueInput
12+
:value="value(prompt.value)"
13+
:type="prompt.type === 'password' ? 'password' : 'text'"
14+
@input="value => answer(value)"
15+
/>
16+
</div>
17+
</div>
18+
</div>
19+
</template>
20+
21+
<script>
22+
import Prompt from './Prompt'
23+
24+
export default {
25+
extends: Prompt
26+
}
27+
</script>

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
</template>
1515

1616
<script>
17+
const types = {
18+
rawlist: 'list',
19+
password: 'input'
20+
}
21+
1722
export default {
1823
props: {
1924
prompts: {
@@ -24,7 +29,11 @@ export default {
2429
2530
methods: {
2631
getModule (prompt) {
27-
const type = prompt.type.charAt(0).toUpperCase() + prompt.type.substr(1)
32+
let type = prompt.type
33+
if (types[type]) {
34+
type = types[type]
35+
}
36+
type = type.charAt(0).toUpperCase() + type.substr(1)
2837
return require(`./Prompt${type}.vue`).default
2938
}
3039
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ function install (id, context) {
162162
const packageManager = loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm')
163163
await installPackage(cwd.get(), packageManager, null, id)
164164

165+
await initPrompts(id, context)
166+
165167
return getInstallation(context)
166168
})
167169
}
@@ -178,6 +180,8 @@ function uninstall (id, context) {
178180
const packageManager = loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm')
179181
await uninstallPackage(cwd.get(), packageManager, null, id)
180182

183+
currentPluginId = null
184+
181185
return getInstallation(context)
182186
})
183187
}
@@ -190,11 +194,25 @@ function invoke (id, context) {
190194
})
191195

192196
currentPluginId = id
197+
193198
// TODO
199+
200+
currentPluginId = null
201+
194202
return getInstallation(context)
195203
})
196204
}
197205

206+
async function initPrompts (id, context) {
207+
prompts.reset()
208+
let data = require(path.join(getPath(id), 'prompts.js'))
209+
if (typeof data === 'function') {
210+
data = await data()
211+
}
212+
data.forEach(prompts.add)
213+
prompts.start()
214+
}
215+
198216
module.exports = {
199217
list,
200218
getVersion,

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

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function initCreator (context) {
126126
// Prompts
127127
prompts.reset()
128128
creator.injectedPrompts.forEach(prompts.add)
129+
prompts.start()
129130

130131
return creator
131132
}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function getDefaultValue (prompt) {
4141
function getEnabled (value) {
4242
const type = typeof value
4343
if (type === 'function') {
44-
return value(answers)
44+
return !!value(answers)
4545
} else if (type === 'boolean') {
4646
return value
4747
} else {
@@ -198,6 +198,10 @@ function add (data) {
198198
prompts.push(generatePrompt(data))
199199
}
200200

201+
function start () {
202+
updatePrompts()
203+
}
204+
201205
function remove (id) {
202206
const index = prompts.findIndex(p => p.id === id)
203207
index !== -1 && prompts.splice(index, 1)
@@ -232,5 +236,6 @@ module.exports = {
232236
list,
233237
add,
234238
remove,
239+
start,
235240
setValue
236241
}

packages/@vue/cli-ui/src/graphql/pluginInstallationFragment.gql

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
fragment pluginInstallation on PluginInstallation {
44
id
5+
pluginId
56
prompts {
67
...prompt
78
}

packages/@vue/cli-ui/src/views/ProjectPluginsAdd.vue

+18-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'name',
3434
'description'
3535
],
36-
// filters: `keywords:vue-cli-plugin`
36+
filters: `keywords:vue-cli-plugin`
3737
}"
3838
>
3939
<InstantSearchInput ref="searchInput"/>
@@ -163,7 +163,6 @@ export default {
163163
return {
164164
tabId: 'search',
165165
selectedId: null,
166-
enabledPrompts: [],
167166
showCancelInstall: false,
168167
pluginInstallation: null
169168
}
@@ -172,13 +171,29 @@ export default {
172171
apollo: {
173172
pluginInstallation: {
174173
query: PLUGIN_INSTALLATION,
175-
fetchPolicy: 'netork-only'
174+
fetchPolicy: 'netork-only',
175+
result () {
176+
if (this.pluginInstallation.pluginId) {
177+
this.tabId = 'config'
178+
} else {
179+
this.tabId = 'search'
180+
}
181+
},
176182
}
177183
},
178184
179185
computed: {
180186
configurationValid () {
181187
return false
188+
},
189+
190+
enabledPrompts () {
191+
if (!this.pluginInstallation) {
192+
return []
193+
}
194+
return this.pluginInstallation.prompts.filter(
195+
p => p.enabled
196+
)
182197
}
183198
},
184199

0 commit comments

Comments
 (0)