Skip to content

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)
}))

@haoqunjiang haoqunjiang 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.

5 participants