yeoman / environment

Yeoman runtime environment
BSD 2-Clause "Simplified" License
127 stars 71 forks source link

Howto yeoman-environment to build a custom cli. #500

Closed ntucker closed 9 months ago

ntucker commented 10 months ago

How to use yeoman 4? I just want to run a generator that i have the filepath for

https://github.com/yeoman/environment/blob/6bacec60de3cc2bbd8b3f4bd5c890a50f26da013/test/command.js#L139 doesn't work I get Environment.prepareEnvironment is not a function

Related to https://github.com/yeoman/yo/pull/793#issuecomment-1792792833

mshima commented 10 months ago

cli.mjs:

import { prepareCommand } from 'yeoman-environment`;
import generator from '../generators/app/index.js';

await prepareCommand(generator).parseAsync();

cli.cjs (executable should be commonjs`):

#!/usr/bin/env node
(async function () {
  await import('../cli.mjs');
})();
ntucker commented 10 months ago

I'm getting some conflicting indicators in the prepareCommand types:

/**
 * Prepare a commander instance for cli support.
 *
 * @param generatorPaht - Generator to create Command
 * @return Return a Command instance
 */
export declare const prepareCommand: (options: CommandPreparation) => Promise<YeomanCommand>;

JSDOCS do not match types.

When I try the import code you had above, I get

A generator with namespace or a generator path is required
ntucker commented 10 months ago

https://github.com/yeoman/environment/blob/main/src/commands.ts#L27C1-L33C4

Indicates that prepareCommand(generator) is not a valid call

ntucker commented 10 months ago

This definitely doesn't do the same thing as calling yo as env isn't setup the same

github-actions[bot] commented 9 months ago

This issue is stale because it has been open with no activity. Remove stale label or comment or this will be closed