Skip to content

Commit

Permalink
feat(ui): plugin invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Mar 14, 2018
1 parent 798445f commit 1a48c9f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/@vue/cli-plugin-eslint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -44,7 +44,7 @@ module.exports = function lint (args = {}, api) {
}
} else {
console.log(formatter(report.results))
process.exit(1)
exit(1)
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand All @@ -195,7 +196,7 @@ function invoke (id, context) {

currentPluginId = id

// TODO
await invoke(id, prompts.getAnswers(), cwd.get())

currentPluginId = null

Expand All @@ -221,5 +222,5 @@ module.exports = {
getInstallation,
install,
uninstall,
invoke
runInvoke
}
2 changes: 1 addition & 1 deletion packages/@vue/cli-ui/src/graphql-api/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
17 changes: 14 additions & 3 deletions packages/@vue/cli-ui/src/views/ProjectPluginsAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
icon-left="close"
label="Cancel"
class="big"
@click="cancel()"
@click="close()"
/>

<div class="algolia">
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -198,7 +199,7 @@ export default {
},
methods: {
cancel () {
close () {
this.$router.push({ name: 'project-home' })
},
Expand Down Expand Up @@ -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)
}
},
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/@vue/cli/lib/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down
13 changes: 0 additions & 13 deletions packages/@vue/cli/lib/util/installDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a48c9f

Please sign in to comment.