yeoman / yo

CLI tool for running Yeoman generators
http://yeoman.io
BSD 2-Clause "Simplified" License
3.8k stars 396 forks source link

update yeoman-environment to v4.0.0 #793

Closed mshima closed 7 months ago

mshima commented 7 months ago

Purpose of this pull request?

What changes did you make?

Is there anything you'd like reviewers to focus on?

ntucker commented 7 months ago

What's the point of yeoman-environment release without this updated? Can yeoman-environment be used without yo?

mshima commented 7 months ago

Yes it’s possible.

Would be nice if someone could convert yo to ESM.

mshima commented 7 months ago

What's the point of yeoman-environment release without this updated? Can yeoman-environment be used without yo?

@ntucker yes it's possible and I actually recommend. There a yeoman-environment built-in cli yoe (I consider experimental since I've never had a feedback about it and do not use it, generator-jhipster has a much more complex custom cli which yeoman-environment is based on). https://github.com/yeoman/environment/blob/e929644f4497a417dc158a12dd32d24690b2cf9c/package.json#L33. Since v3.0.0 https://github.com/yeoman/environment/releases/tag/v3.0.0.

You can build your own, yeoman-environment has helpers for that.

ntucker commented 7 months ago

Oh that's cool. Is there much difference than yoe? I actually have my own cli that I just proxy calls to yo with https://github.com/ntucker/anansi/blob/master/packages/cli/run.mjs#L42

Would it be as simple as replacing yo with yoe to run a generator?

ntucker commented 7 months ago

@mshima I don't get how to use yoe. the help says

run [options] <namespace> <namespace>  Run a generator

What are namespaces? What happened to specifying the generator? With yo I do yo [generator-filepath] [...args]

So where does [generator-filepath] go?

ntucker commented 7 months ago

Running npx --package=yeoman-environment yoe run @anansi/generator-js app temp:

TypeError: Cannot read properties of undefined (reading 'splice')
    at YeomanCommand.environmentAction (file:///home/ntucker/.npm/_npx/39f97afeb06609d2/node_modules/yeoman-environment/dist/cli/utils.js:33:57)

which associates with

export const environmentAction = async function (generatorNamespace, options, command) {
    debug('Handling operands %o', generatorNamespace);
    if (!generatorNamespace) {
        return;
    }
    const env = createEnv({ ...options, command: this });
    this.env = env;
    await env.lookupLocalPackages();
    return env.execute(generatorNamespace, command.args.splice(1));
};

the return line here

console.log on command gives:

{
  skipInstall: false,
  skipCache: false,
  localConfigOnly: false,
  askAnswered: false,
  force: false,
  dryRun: false,
  whitespace: false,
  bail: false,
  skipYoResolve: false,
  skipLocalCache: true,
  skipParseOptions: false,
  experimental: false
}
mshima commented 7 months ago

It’s not designed to use paths, it relies on lookup and use namespaces. You can easily create your own using YeomanCommand and prepareCommand. https://github.com/yeoman/environment/blob/6bacec60de3cc2bbd8b3f4bd5c890a50f26da013/test/command.js#L139.

You can use yoe as reference implementation.

ntucker commented 7 months ago

Is require('./fixtures/generator-commands/generators/arguments') a generator?

mshima commented 7 months ago

Yes, https://github.com/yeoman/environment/blob/6bacec60de3cc2bbd8b3f4bd5c890a50f26da013/test/fixtures/generator-commands/generators/arguments/index.js. Please open a new issue at environment repository to keep the discussion registered in the right repository.