Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/create-gen-app/__tests__/create-gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jest.mock('inquirerer', () => {
prompt: jest.fn().mockResolvedValue({}),
};
}),
registerDefaultResolver: jest.fn(),
};
});

Expand Down
7 changes: 7 additions & 0 deletions packages/create-gen-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import * as fs from 'fs';
import * as path from 'path';

import { registerDefaultResolver } from 'inquirerer';

import { extractVariables } from './template/extract';
import { promptUser } from './template/prompt';
import { replaceVariables } from './template/replace';
import { listSupportedLicenses } from './licenses';
import { CreateGenOptions } from './types';

// Register the 'licenses' resolver for optionsFrom support
// This allows boilerplate templates to use: "optionsFrom": "licenses"
registerDefaultResolver('licenses', () => listSupportedLicenses());

// Export new modular classes
export * from './cache/cache-manager';
export * from './cache/types';
Expand Down
21 changes: 20 additions & 1 deletion packages/inquirerer/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ export class Inquirerer {
// Resolve dynamic defaults before processing questions
await this.resolveDynamicDefaults(questions);

// Resolve dynamic options before processing questions
await this.resolveOptionsFrom(questions);

// Resolve setFrom values - these bypass prompting entirely
await this.resolveSetValues(questions, obj);

Expand Down Expand Up @@ -609,6 +612,22 @@ export class Inquirerer {
}
}

/**
* Resolves optionsFrom values for all questions that have optionsFrom specified.
* Updates the question.options property with the resolved array.
*/
private async resolveOptionsFrom(questions: Question[]): Promise<void> {
for (const question of questions) {
if ('optionsFrom' in question && question.optionsFrom) {
const resolved = await this.resolverRegistry.resolve(question.optionsFrom);
if (resolved !== undefined && Array.isArray(resolved)) {
// Update question.options with resolved array
(question as any).options = resolved;
}
}
}
}

private applyDefaultValues(questions: Question[], obj: any): void {
questions.forEach(question => {
if ('default' in question) {
Expand Down Expand Up @@ -1192,4 +1211,4 @@ export class Inquirerer {
this.keypress.destroy();
}
}
}
}
3 changes: 2 additions & 1 deletion packages/inquirerer/src/question/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface BaseQuestion {
default?: any;
defaultFrom?: string;
setFrom?: string;
optionsFrom?: string;
useDefault?: boolean;
required?: boolean;
message?: string;
Expand Down Expand Up @@ -69,4 +70,4 @@ export interface BaseQuestion {
default?: number;
}

export type Question = ConfirmQuestion | ListQuestion | AutocompleteQuestion | CheckboxQuestion | TextQuestion | NumberQuestion;
export type Question = ConfirmQuestion | ListQuestion | AutocompleteQuestion | CheckboxQuestion | TextQuestion | NumberQuestion;