Skip to content

Use prompt on a preset level #2529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arnedesmedt opened this issue Sep 15, 2018 · 4 comments
Closed

Use prompt on a preset level #2529

arnedesmedt opened this issue Sep 15, 2018 · 4 comments

Comments

@arnedesmedt
Copy link

What problem does this feature solve?

Now, if you want to share answers from prompts over multiple vue cli plugins, you need to ask the same question again in each plugin, because prompts are asked on plugin level. Wouldn't it be nice to make this available on preset level, so every plugin in the preset could use the ansers of the preset prompts

What does the proposed API look like?

add a prompst property to the presets json.

@haoqunjiang
Copy link
Member

https://cli.vuejs.org/guide/plugins-and-presets.html#remote-presets
You can have a prompt.js in a preset repo and then add plugins using the prompt answers in generator.js.

@yuicer
Copy link

yuicer commented Nov 14, 2018

@sodatea
excuse me , but how can i add plugins like @vue/cli-plugin-eslint in generator.js, and i also want the prompts of the @vue/cli-plugin-eslint,i just can't find the way to get that done

@haoqunjiang
Copy link
Member

@yuicer
I'm sorry it seems my initial impression on this issue was incorrect. Currently there's no specific API to achieve this kind of customization.
The corresponding feature request is tracked at #1938
Nevertheless, there's a workaround:

// prompts.js
module.exports = [{
  name: 'useEslint',
  type: 'confirm',
  message: 'use eslint'
}]
// generator.js
const path = require('path')

module.exports = (api, options, rootOptions) => {
  if (options.useEslint) {
    api.extendPackage({
      devDependencies: {
        '@vue/cli-plugin-eslint': '^3.1.5'
      }
    })

    api.onCreateComplete(() => {
      require('child_process').spawnSync(
        'vue',
        [
          'invoke',
          '@vue/cli-plugin-eslint',
          // the following 4 lines can be commented out if you need the plugin prompts
          '--config',
          'standard',
          '--lintOn',
          'save,commit'
        ],
        {
          stdio: 'inherit',
          cwd: path.join(process.cwd(), rootOptions.projectName)
        })
    })
  }
}

@yuicer
Copy link

yuicer commented Nov 14, 2018

@sodatea
thanks ! it does get it done !
anyway, will we have this feature later? it just takes extra time to do this in this way

再次感谢~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants