Skip to content
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

feat(cli): Generator support async #3897

Merged
merged 2 commits into from Jul 29, 2019
Merged

feat(cli): Generator support async #3897

merged 2 commits into from Jul 29, 2019

Conversation

xierenyuan
Copy link
Contributor

In some cases, asynchronous operations in the generator will cause the build to fail, so I hope that the generator can support async

demo

const packageJson = require('package-json')

const pkgConfig = {
  registryUrl: 'todo'
}

module.exports = async (api, options, rootOptions) => {
   const pkg1 = await packageJson('todo pkg', pkgConfig)
   api.render('./template', rootOptions)
   
    // todo...

    api.extendPackage({
	devDependencies: {
	     'todo pkg': pkg1.version
	}
    })
}


initPlugins () {
const { rootOptions, invoking } = this
return new Promise((resolve, reject) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use async with a for loop?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not do something like:

Suggested change
return new Promise((resolve, reject) => {
return Promise.all(this.plugins.map(({ id, apply, options }) => {
const api = new GeneratorAPI(id, this, options, rootOptions)
return apply(api, options, rootOptions, invoking)
}))

@sodatea sodatea merged commit 74f629e into vuejs:dev Jul 29, 2019
@vue-bot
Copy link

vue-bot commented Jul 29, 2019

Hey @xierenyuan, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

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

Successfully merging this pull request may close these issues.

None yet

5 participants