Skip to content

Commit 91a4b2e

Browse files
author
Guillaume Chau
committed
feat(plugin): quick local plugin refresh
1 parent 11e59f8 commit 91a4b2e

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

packages/@vue/cli-ui/apollo-server/connectors/plugins.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ async function initPrompts (id, context) {
467467
await prompts.start()
468468
}
469469

470-
function update (id, context) {
470+
function update ({ id, full }, context) {
471471
return progress.wrap('plugin-update', context, async setProgress => {
472472
setProgress({
473473
status: 'plugin-update',
@@ -478,7 +478,7 @@ function update (id, context) {
478478
const { current, wanted, localPath } = await dependencies.getVersion(plugin, context)
479479

480480
if (localPath) {
481-
await updateLocalPackage({ cwd: cwd.get(), id, localPath }, context)
481+
await updateLocalPackage({ cwd: cwd.get(), id, localPath, full }, context)
482482
} else {
483483
await updatePackage(cwd.get(), getCommand(cwd.get()), null, id)
484484
}
@@ -502,11 +502,19 @@ function update (id, context) {
502502
})
503503
}
504504

505-
async function updateLocalPackage ({ id, cwd, localPath }, context) {
505+
async function updateLocalPackage ({ id, cwd, localPath, full = true }, context) {
506506
const from = path.resolve(cwd, localPath)
507507
const to = path.resolve(cwd, 'node_modules', ...id.split('/'))
508-
await fs.remove(to)
509-
await fs.copy(from, to)
508+
let filterRegEx
509+
if (full) {
510+
await fs.remove(to)
511+
filterRegEx = /\.git/
512+
} else {
513+
filterRegEx = /(\.git|node_modules)/
514+
}
515+
await fs.copy(from, to, {
516+
filter: (file) => !file.match(filterRegEx)
517+
})
510518
}
511519

512520
async function updateAll (context) {

packages/@vue/cli-ui/apollo-server/schema/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extend type Mutation {
1919
pluginUninstall (id: ID!): PluginInstallation
2020
pluginInvoke (id: ID!): PluginInstallation
2121
pluginFinishInstall: PluginInstallation
22-
pluginUpdate (id: ID!): Plugin
22+
pluginUpdate (id: ID!, full: Boolean = true): Plugin
2323
pluginActionCall (id: ID!, params: JSON): PluginActionResult
2424
pluginsUpdate: [Plugin]
2525
pluginResetApi: Boolean
@@ -87,7 +87,7 @@ exports.resolvers = {
8787
pluginUninstall: (root, { id }, context) => plugins.uninstall(id, context),
8888
pluginInvoke: (root, { id }, context) => plugins.runInvoke(id, context),
8989
pluginFinishInstall: (root, args, context) => plugins.finishInstall(context),
90-
pluginUpdate: (root, { id }, context) => plugins.update(id, context),
90+
pluginUpdate: (root, { id, full }, context) => plugins.update({ id, full }, context),
9191
pluginActionCall: (root, args, context) => plugins.callAction(args, context),
9292
pluginsUpdate: (root, args, context) => plugins.updateAll(context),
9393
pluginResetApi: (root, args, context) => plugins.resetPluginApi({ file: cwd.get() }, context)

packages/@vue/cli-ui/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"installed": "Installed",
117117
"actions": {
118118
"update": "Update {target}",
119-
"refresh": "Force Refresh {target}"
119+
"refresh": "Force Refresh {target}<br><i>Press [Shift] for Quick Refresh (node_modules won't be updated)</i>"
120120
},
121121
"local": "Local"
122122
},

packages/@vue/cli-ui/src/components/plugin/ProjectPluginItem.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
class="icon-button"
7272
v-tooltip="$t('org.vue.components.project-plugin-item.actions.refresh', { target: plugin.id })"
7373
:loading-left="updating"
74-
@click="updatePlugin()"
74+
@click="e => updatePlugin(!e.shiftKey)"
7575
/>
7676

7777
<VueButton
@@ -138,13 +138,14 @@ export default {
138138
},
139139
140140
methods: {
141-
async updatePlugin () {
141+
async updatePlugin (full = true) {
142142
this.updating = true
143143
try {
144144
this.$apollo.mutate({
145145
mutation: PLUGIN_UPDATE,
146146
variables: {
147-
id: this.plugin.id
147+
id: this.plugin.id,
148+
full
148149
}
149150
})
150151
} catch (e) {

packages/@vue/cli-ui/src/graphql/plugin/pluginUpdate.gql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import "../version/versionFragment.gql"
22

3-
mutation pluginUpdate ($id: ID!) {
4-
pluginUpdate (id: $id) {
3+
mutation pluginUpdate ($id: ID!, $full: Boolean) {
4+
pluginUpdate (id: $id, full: $full) {
55
id
66
version {
77
...version

0 commit comments

Comments
 (0)