-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
112 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import YeomanCommand, { addEnvironmentOptions } from './util/command.js'; | ||
import { createEnv } from './index.js'; | ||
|
||
/** | ||
* Prepare a commander instance for cli support. | ||
* | ||
* @param {Command} command - Command to be prepared | ||
* @param generatorPath - Generator to create Command | ||
* @return {Command} return command | ||
*/ | ||
export const prepareGeneratorCommand = async (command: YeomanCommand, generatorPath: string, namespace?: string) => { | ||
const env = createEnv(); | ||
const meta = env.register(generatorPath, { namespace }); | ||
command.env = env; | ||
command.registerGenerator(await meta.instantiateHelp()); | ||
command.action(async function (this: YeomanCommand) { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
let rootCommand: YeomanCommand = this; | ||
while (rootCommand.parent) { | ||
rootCommand = rootCommand.parent as YeomanCommand; | ||
} | ||
|
||
const generator = await meta.instantiate(this.args, this.opts()); | ||
await env.runGenerator(generator); | ||
}); | ||
return command; | ||
}; | ||
|
||
/** | ||
* Prepare a commander instance for cli support. | ||
* | ||
* @param generatorPaht - Generator to create Command | ||
* @return Return a Command instance | ||
*/ | ||
export const prepareCommand = async (generatorPath: string, command = new YeomanCommand()) => { | ||
command = addEnvironmentOptions(command); | ||
return prepareGeneratorCommand(command, generatorPath); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.