From 98b6d268e3f8860955ec86752e27af96d2730266 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 5 Jun 2018 10:59:28 +0200 Subject: [PATCH] feat(ui): update all plugin to wanted version button (#1456) --- packages/@vue/cli-ui/locales/en.json | 3 +- .../src/graphql-api/connectors/plugins.js | 32 ++++++++++++++++++- .../cli-ui/src/graphql-api/schema/plugin.js | 4 ++- .../@vue/cli-ui/src/graphql/pluginsUpdate.gql | 10 ++++++ .../@vue/cli-ui/src/views/ProjectPlugins.vue | 24 ++++++++++++++ 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 packages/@vue/cli-ui/src/graphql/pluginsUpdate.gql diff --git a/packages/@vue/cli-ui/locales/en.json b/packages/@vue/cli-ui/locales/en.json index 8ef7c12e00..6cc9a6f450 100644 --- a/packages/@vue/cli-ui/locales/en.json +++ b/packages/@vue/cli-ui/locales/en.json @@ -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", diff --git a/packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js b/packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js index 06167dc054..de431e7cf7 100644 --- a/packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js +++ b/packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js @@ -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', @@ -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 } @@ -433,6 +462,7 @@ module.exports = { install, uninstall, update, + updateAll, runInvoke, resetPluginApi, getApi, diff --git a/packages/@vue/cli-ui/src/graphql-api/schema/plugin.js b/packages/@vue/cli-ui/src/graphql-api/schema/plugin.js index a22aab0488..5a30e7038b 100644 --- a/packages/@vue/cli-ui/src/graphql-api/schema/plugin.js +++ b/packages/@vue/cli-ui/src/graphql-api/schema/plugin.js @@ -17,6 +17,7 @@ extend type Mutation { pluginFinishInstall: PluginInstallation pluginUpdate (id: ID!): Plugin pluginActionCall (id: ID!, params: JSON): PluginActionResult + pluginsUpdate: [Plugin] } extend type Subscription { @@ -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: { diff --git a/packages/@vue/cli-ui/src/graphql/pluginsUpdate.gql b/packages/@vue/cli-ui/src/graphql/pluginsUpdate.gql new file mode 100644 index 0000000000..d57ba1495f --- /dev/null +++ b/packages/@vue/cli-ui/src/graphql/pluginsUpdate.gql @@ -0,0 +1,10 @@ +#import "./versionFragment.gql" + +mutation pluginsUpdate { + pluginsUpdate { + id + version { + ...version + } + } +} diff --git a/packages/@vue/cli-ui/src/views/ProjectPlugins.vue b/packages/@vue/cli-ui/src/views/ProjectPlugins.vue index bdc213cda4..1cdba065f9 100644 --- a/packages/@vue/cli-ui/src/views/ProjectPlugins.vue +++ b/packages/@vue/cli-ui/src/views/ProjectPlugins.vue @@ -12,6 +12,20 @@ :to="{ name: 'project-plugins-add' }" data-testid="add-plugin" /> + + + + + +