How to use the @vue/cli/lib/invoke.runGenerator function in @vue/cli

To help you get started, we’ve selected a few @vue/cli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-cli / packages / @vue / cli-ui / ui-defaults / suggestions.js View on Github external
api.setProgress({
    status: 'org.vue.cli-service.suggestions.progress',
    args: [id],
    progress: -1
  })

  const context = api.getCwd()

  let error

  try {
    const servicePkg = loadModule('@vue/cli-service/package.json', context)
    // @vue/cli-plugin-router is not compatible with @vue/cli-service v3,
    // so we have to check for the version and call the right generator
    if (semver.satisfies(servicePkg.version, '3.x')) {
      await invoke.runGenerator(context, {
        id: `core:${id}`,
        apply: loadModule(`@vue/cli-service/generator/${id}`, context)
      })
    } else {
      // FIXME: a temporary fix for adding router plugin
      // should implement a plugin prompt ui later
      await add(id, { $inlineOptions: '{}' }, context)
    }
  } catch (e) {
    error = e
  }

  api.removeProgress()

  if (error) throw error
}