Skip to content

Commit 77410fe

Browse files
committed
add exports
1 parent 94fbb01 commit 77410fe

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

src/commands.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1+
import { type BaseGeneratorConstructor, type GeneratorMeta } from '@yeoman/types';
12
import YeomanCommand, { addEnvironmentOptions } from './util/command.js';
23
import { createEnv } from './index.js';
34

5+
export type CommandPreparation = {
6+
resolved?: string;
7+
command?: YeomanCommand;
8+
generator?: BaseGeneratorConstructor;
9+
namespace?: string;
10+
};
11+
412
/**
513
* Prepare a commander instance for cli support.
614
*
715
* @param {Command} command - Command to be prepared
816
* @param generatorPath - Generator to create Command
917
* @return {Command} return command
1018
*/
11-
export const prepareGeneratorCommand = async (command: YeomanCommand, generatorPath: string, namespace?: string) => {
19+
export const prepareGeneratorCommand = async ({
20+
command = addEnvironmentOptions(new YeomanCommand()),
21+
resolved,
22+
generator,
23+
namespace,
24+
}: CommandPreparation) => {
1225
const env = createEnv();
13-
const meta = env.register(generatorPath, { namespace });
26+
let meta: GeneratorMeta;
27+
if (generator && namespace) {
28+
meta = env.register(generator, { namespace, resolved });
29+
} else if (resolved) {
30+
meta = env.register(resolved, { namespace });
31+
} else {
32+
throw new Error(`A generator with namespace or a generator path is required`);
33+
}
34+
1435
command.env = env;
1536
command.registerGenerator(await meta.instantiateHelp());
1637
command.action(async function (this: YeomanCommand) {
@@ -32,7 +53,8 @@ export const prepareGeneratorCommand = async (command: YeomanCommand, generatorP
3253
* @param generatorPaht - Generator to create Command
3354
* @return Return a Command instance
3455
*/
35-
export const prepareCommand = async (generatorPath: string, command = new YeomanCommand()) => {
36-
command = addEnvironmentOptions(command);
37-
return prepareGeneratorCommand(command, generatorPath);
56+
export const prepareCommand = async (options: CommandPreparation) => {
57+
options.command = options.command ?? new YeomanCommand();
58+
addEnvironmentOptions(options.command);
59+
return prepareGeneratorCommand(options);
3860
};

src/commit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export const commitSharedFsTask = ({
1919
sharedFs,
2020
stream,
2121
}: {
22-
sharedFs: Store<MemFsEditorFile>;
2322
adapter: InputOutputAdapter;
2423
conflicterOptions?: ConflicterOptions;
24+
sharedFs: Store<MemFsEditorFile>;
2525
stream?: PassThrough;
2626
}) => {
2727
const fs = createMemFsEditor(sharedFs);

src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { type EnvironmentOptions } from './environment-base.js';
22
import Environment from './environment-full.js';
33

4+
export { default } from './environment-full.js';
5+
export { default as EnvironmentBase } from './environment-base.js';
6+
47
export const createEnv = (options?: EnvironmentOptions) => new Environment(options);
58

6-
export { default } from './environment-full.js';
9+
export * from './commands.js';
10+
export * from './util/command.js';
11+
export * from './package-manager.js';
12+
export * from './commit.js';
13+
export { lookupGenerator } from './generator-lookup.js';

src/store.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const debug = createDebug('yeoman:environment:store');
1313
* @constructor
1414
* @private
1515
*/
16-
class Store {
16+
export default class Store {
1717
private readonly _meta: Record<string, GeneratorMeta> = {};
1818
// Store packages paths by ns
1919
private readonly _packagesPaths: Record<string, string[]> = {};
@@ -197,5 +197,3 @@ class Store {
197197
return Generator;
198198
}
199199
}
200-
201-
export default Store;

test/command.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ describe('environment (command)', () => {
131131
let env;
132132

133133
beforeEach(async () => {
134-
const command = await prepareCommand(require.resolve('./fixtures/generator-commands/generators/arguments/index.js'));
134+
const command = await prepareCommand({
135+
resolved: require.resolve('./fixtures/generator-commands/generators/arguments/index.js'),
136+
});
135137
console.log('beforeEach', command);
136138
await command.parseAsync(['node', 'yo', 'bar']);
137139

@@ -152,7 +154,7 @@ describe('environment (command)', () => {
152154
let env;
153155

154156
beforeEach(async () => {
155-
const command = await prepareCommand(require.resolve('./fixtures/generator-commands/generators/options/index.js'));
157+
const command = await prepareCommand({ resolved: require.resolve('./fixtures/generator-commands/generators/options/index.js') });
156158
await command.parseAsync([
157159
'node',
158160
'yo',

0 commit comments

Comments
 (0)