0

I created a yeoman generator with user interaction, that can be called in the terminal like (after running npm link):

yo mygenerator --name test --path /test/path --project testproject

Now I want to include this generator in my vscode extension.

How can I call the yo generator from my typescript code when the generator when the generator is added as a package.json dependency?

So something like (pseudo code)

import { yo } from 'yeoman';
import mygenerator; // added as a dependency via package.json

const options = {
   name: 'test',
   path: '/test/path',
   project: 'testproject',
};
yo.exec(mygenerator, options, () => {
    console.log('yeoman finished')
});

Is something like this possible?

Zoker
  • 2,020
  • 5
  • 32
  • 53

1 Answers1

0

Here is a solution for that:

const env = yeoman.createEnv();
const generatorPath = '../node_modules/generator-name/generators/app/index.js';
env.getByPath(generatorDir);
env.on('error', (err: any) => {
  // handle error
});
const options = {
  env,
  'option1': option1,
  'option2': option2,
};
try {
  await env.run('name', options);
} catch (err) {
  // handle error
}
Zoker
  • 2,020
  • 5
  • 32
  • 53