Skip to content

Commit

Permalink
refactor(ui): update all plugins in one command which is much quicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jun 15, 2018
1 parent 80a847f commit 3a88152
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 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 @@ -154,7 +154,8 @@
"plugin-install": "Installing {arg0}...",
"plugin-uninstall": "Uninstalling {arg0}...",
"plugin-invoke": "Invoking {arg0}...",
"plugin-update": "Updating {arg0}..."
"plugin-update": "Updating {arg0}...",
"plugins-update": "Updating {arg0} plugins..."
}
},
"types": {
Expand Down
68 changes: 43 additions & 25 deletions packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function findPlugins (deps) {
)
}

function list (file, context) {
function list (file, context, resetApi = true) {
const pkg = folders.readPackage(file, context)
plugins = []
plugins = plugins.concat(findPlugins(pkg.devDependencies || {}))
Expand All @@ -90,7 +90,7 @@ function list (file, context) {
plugins.unshift(service)
}

resetPluginApi(context)
if (resetApi) resetPluginApi(context)
return plugins
}

Expand Down Expand Up @@ -379,7 +379,7 @@ async function initPrompts (id, context) {
await prompts.start()
}

function update (id, context, multi = false) {
function update (id, context) {
return progress.wrap('plugin-update', context, async setProgress => {
setProgress({
status: 'plugin-update',
Expand All @@ -396,38 +396,56 @@ function update (id, context, multi = false) {
type: 'info'
}, context)

if (!multi) {
notify({
title: `Plugin updated`,
message: `Plugin ${id} was successfully updated`,
icon: 'done'
})
resetPluginApi(context)
}
notify({
title: `Plugin updated`,
message: `Plugin ${id} was successfully updated`,
icon: 'done'
})
resetPluginApi(context)

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, true))
return progress.wrap('plugins-update', context, async setProgress => {
const plugins = await list(cwd.get(), context, false)
let updatedPlugins = []
for (const plugin of plugins) {
const version = await getVersion(plugin, context)
if (version.current !== version.wanted) {
updatedPlugins.push(plugin)
}
}
}

notify({
title: `Plugins updated`,
message: `${updatedPlugins.length} plugin(s) were successfully updated`,
icon: 'done'
})
resetPluginApi(context)
if (!updatedPlugins.length) {
notify({
title: `No updates available`,
message: `No plugin to update in the version ranges declared in package.json`,
icon: 'done'
})
return []
}

setProgress({
status: 'plugins-update',
args: [updatedPlugins.length]
})

await updatePackage(cwd.get(), getCommand(), null, updatedPlugins.map(
p => p.id
).join(' '))

return updatedPlugins
notify({
title: `Plugins updated`,
message: `${updatedPlugins.length} plugin(s) were successfully updated`,
icon: 'done'
})
resetPluginApi(context)

return updatedPlugins
})
}

function getApi () {
Expand Down
5 changes: 2 additions & 3 deletions packages/@vue/cli-ui/src/views/ProjectPlugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
</ApolloQuery>
</ContentView>

<ProgressScreen
progress-id="plugin-update"
/>
<ProgressScreen progress-id="plugin-update"/>
<ProgressScreen progress-id="plugins-update"/>
</div>
</template>

Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/util/installDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ exports.updatePackage = async function (targetDir, command, cliRegistry, package

await addRegistryToArgs(command, args, cliRegistry)

args.push(packageName)
packageName.split(' ').forEach(name => args.push(name))

debug(`command: `, command)
debug(`args: `, args)
Expand Down

0 comments on commit 3a88152

Please sign in to comment.