From 1a48c9fc3efe40ddde3b02a78d5524220ff460cf Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Wed, 14 Mar 2018 14:49:52 +0100 Subject: [PATCH] feat(ui): plugin invoke --- packages/@vue/cli-plugin-eslint/lint.js | 4 ++-- .../src/graphql-api/connectors/plugins.js | 7 ++++--- .../@vue/cli-ui/src/graphql-api/resolvers.js | 2 +- .../@vue/cli-ui/src/views/ProjectPluginsAdd.vue | 17 ++++++++++++++--- packages/@vue/cli/lib/invoke.js | 4 +++- packages/@vue/cli/lib/util/installDeps.js | 13 ------------- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/packages/@vue/cli-plugin-eslint/lint.js b/packages/@vue/cli-plugin-eslint/lint.js index a8a21b2b24..2ef6cfe217 100644 --- a/packages/@vue/cli-plugin-eslint/lint.js +++ b/packages/@vue/cli-plugin-eslint/lint.js @@ -4,7 +4,7 @@ module.exports = function lint (args = {}, api) { const cwd = api.resolve('.') const { CLIEngine } = require('eslint') const options = require('./eslintOptions')(api) - const { log, done } = require('@vue/cli-shared-utils') + const { log, done, exit } = require('@vue/cli-shared-utils') const files = args._ && args._.length ? args._ : ['src', 'tests', '*.js'] if (args['no-fix']) { @@ -44,7 +44,7 @@ module.exports = function lint (args = {}, api) { } } else { console.log(formatter(report.results)) - process.exit(1) + exit(1) } } 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 671ac10f09..f2266ac35a 100644 --- a/packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js +++ b/packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js @@ -14,6 +14,7 @@ const { uninstallPackage } = require('@vue/cli/lib/util/installDeps') const { loadOptions } = require('@vue/cli/lib/options') +const invoke = require('@vue/cli/lib/invoke') const cwd = require('./cwd') const folders = require('./folders') @@ -186,7 +187,7 @@ function uninstall (id, context) { }) } -function invoke (id, context) { +function runInvoke (id, context) { return progress.wrap(PROGRESS_ID, context, async setProgress => { setProgress({ status: 'plugin-invoke', @@ -195,7 +196,7 @@ function invoke (id, context) { currentPluginId = id - // TODO + await invoke(id, prompts.getAnswers(), cwd.get()) currentPluginId = null @@ -221,5 +222,5 @@ module.exports = { getInstallation, install, uninstall, - invoke + runInvoke } diff --git a/packages/@vue/cli-ui/src/graphql-api/resolvers.js b/packages/@vue/cli-ui/src/graphql-api/resolvers.js index 4703885146..f643d4c70b 100644 --- a/packages/@vue/cli-ui/src/graphql-api/resolvers.js +++ b/packages/@vue/cli-ui/src/graphql-api/resolvers.js @@ -64,7 +64,7 @@ module.exports = { projectCwdReset: (root, args, context) => projects.resetCwd(context), pluginInstall: (root, { id }, context) => plugins.install(id, context), pluginUninstall: (root, { id }, context) => plugins.uninstall(id, context), - pluginInvoke: (root, { id }, context) => plugins.invoke(id, context) + pluginInvoke: (root, { id }, context) => plugins.runInvoke(id, context) }, Subscription: { diff --git a/packages/@vue/cli-ui/src/views/ProjectPluginsAdd.vue b/packages/@vue/cli-ui/src/views/ProjectPluginsAdd.vue index 46a05f8b34..914419869f 100644 --- a/packages/@vue/cli-ui/src/views/ProjectPluginsAdd.vue +++ b/packages/@vue/cli-ui/src/views/ProjectPluginsAdd.vue @@ -60,7 +60,7 @@ icon-left="close" label="Cancel" class="big" - @click="cancel()" + @click="close()" />
@@ -156,6 +156,7 @@ import Prompts from '../mixins/Prompts' import PLUGIN_INSTALLATION from '../graphql/pluginInstallation.gql' import PLUGIN_INSTALL from '../graphql/pluginInstall.gql' import PLUGIN_UNINSTALL from '../graphql/pluginUninstall.gql' +import PLUGIN_INVOKE from '../graphql/pluginInvoke.gql' import PROMPT_ANSWER from '../graphql/promptAnswer.gql' export default { @@ -198,7 +199,7 @@ export default { }, methods: { - cancel () { + close () { this.$router.push({ name: 'project-home' }) }, @@ -238,7 +239,17 @@ export default { }, async invokePlugin () { - // TODO + try { + await this.$apollo.mutate({ + mutation: PLUGIN_INVOKE, + variables: { + id: this.selectedId + } + }) + this.close() + } catch(e) { + console.error(e) + } }, } } diff --git a/packages/@vue/cli/lib/invoke.js b/packages/@vue/cli/lib/invoke.js index b6481b9380..1caf10c10f 100644 --- a/packages/@vue/cli/lib/invoke.js +++ b/packages/@vue/cli/lib/invoke.js @@ -135,7 +135,9 @@ async function invoke (pluginName, options = {}, context = process.cwd()) { log() log(` Successfully invoked generator for plugin: ${chalk.cyan(id)}`) if (!process.env.VUE_CLI_TEST && hasGit()) { - const { stdout } = await execa('git', ['ls-files', '--exclude-standard', '--modified', '--others']) + const { stdout } = await execa('git', ['ls-files', '--exclude-standard', '--modified', '--others'], { + cwd: context + }) if (stdout.trim()) { log(` The following files have been updated / added:\n`) log(chalk.red(stdout.split(/\r?\n/g).map(line => ` ${line}`).join('\n'))) diff --git a/packages/@vue/cli/lib/util/installDeps.js b/packages/@vue/cli/lib/util/installDeps.js index a1ebb1fffd..3de10cda33 100644 --- a/packages/@vue/cli/lib/util/installDeps.js +++ b/packages/@vue/cli/lib/util/installDeps.js @@ -154,19 +154,6 @@ function executeCommand (command, args, targetDir) { progress.enabled = false - // const lines = [] - // let count = 0 - // const unhook = intercept(buffer => { - // count++ - // lines.push(buffer) - // const str = buffer === 'string' ? buffer : buffer.toString() - // // Steps - // const stepMatch = str.match(/\[\d+\/\d+]\s+(.*)/) - // if (stepMatch) { - // progress.log(stepMatch[1]) - // } - // }) - if (apiMode) { if (command === 'npm') { // TODO when this is supported