Skip to content

Commit

Permalink
feat(ui): update all plugin to wanted version button (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum authored Jun 5, 2018
1 parent f42632b commit 98b6d26
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/@vue/cli-ui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@
"project-plugins": {
"title": "Project plugins",
"button": "Add plugin",
"heading": "Installed plugins"
"heading": "Installed plugins",
"update-all": "Update all plugins"
},
"project-plugins-add": {
"title": "Add a plugin",
Expand Down
32 changes: 31 additions & 1 deletion packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ async function initPrompts (id, context) {
await prompts.start()
}

function update (id, context) {
function update (id, context, notify = true) {
return progress.wrap('plugin-update', context, async setProgress => {
setProgress({
status: 'plugin-update',
Expand All @@ -370,15 +370,44 @@ function update (id, context) {
const { current, wanted } = await getVersion(plugin, context)
await updatePackage(cwd.get(), getCommand(), null, id)
resetPluginApi(context)

logs.add({
message: `Plugin ${id} updated from ${current} to ${wanted}`,
type: 'info'
}, context)

if (notify) {
notifier.notify({
title: `Plugin updated`,
message: `Plugin ${id} was successfully updated`,
icon: path.resolve(__dirname, '../../assets/done.png')
})
}

currentPluginId = null
return findOne(id)
})
}

async function updateAll (context) {
const plugins = await list(cwd.get(), context)
let updatedPlugins = []
for (const plugin of plugins) {
const version = await getVersion(plugin, context)
if (version.current !== version.wanted) {
updatedPlugins.push(await update(plugin.id, context, false))
}
}

notifier.notify({
title: `Plugins updated`,
message: `${updatedPlugins.length} plugin(s) were successfully updated`,
icon: path.resolve(__dirname, '../../assets/done.png')
})

return updatedPlugins
}

function getApi () {
return pluginApi
}
Expand Down Expand Up @@ -433,6 +462,7 @@ module.exports = {
install,
uninstall,
update,
updateAll,
runInvoke,
resetPluginApi,
getApi,
Expand Down
4 changes: 3 additions & 1 deletion packages/@vue/cli-ui/src/graphql-api/schema/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extend type Mutation {
pluginFinishInstall: PluginInstallation
pluginUpdate (id: ID!): Plugin
pluginActionCall (id: ID!, params: JSON): PluginActionResult
pluginsUpdate: [Plugin]
}
extend type Subscription {
Expand Down Expand Up @@ -80,7 +81,8 @@ exports.resolvers = {
pluginInvoke: (root, { id }, context) => plugins.runInvoke(id, context),
pluginFinishInstall: (root, args, context) => plugins.finishInstall(context),
pluginUpdate: (root, { id }, context) => plugins.update(id, context),
pluginActionCall: (root, args, context) => plugins.callAction(args, context)
pluginActionCall: (root, args, context) => plugins.callAction(args, context),
pluginsUpdate: (root, args, context) => plugins.updateAll(context)
},

Subscription: {
Expand Down
10 changes: 10 additions & 0 deletions packages/@vue/cli-ui/src/graphql/pluginsUpdate.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import "./versionFragment.gql"

mutation pluginsUpdate {
pluginsUpdate {
id
version {
...version
}
}
}
24 changes: 24 additions & 0 deletions packages/@vue/cli-ui/src/views/ProjectPlugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
:to="{ name: 'project-plugins-add' }"
data-testid="add-plugin"
/>

<VueDropdown>
<VueButton
slot="trigger"
icon-left="more_vert"
class="icon-button flat round"
/>

<VueDropdownButton
icon-left="file_download"
:label="$t('views.project-plugins.update-all')"
@click="updateAll()"
/>
</VueDropdown>
</template>

<ApolloQuery
Expand Down Expand Up @@ -43,13 +57,23 @@
</template>

<script>
import PLUGINS_UPDATE from '../graphql/pluginsUpdate.gql'
export default {
name: 'ProjectPlugins',
metaInfo () {
return {
title: this.$t('views.project-plugins.title')
}
},
methods: {
updateAll () {
return this.$apollo.mutate({
mutation: PLUGINS_UPDATE
})
}
}
}
</script>
Expand Down

0 comments on commit 98b6d26

Please sign in to comment.