Skip to content

Commit bb03f47

Browse files
committed
text type
1 parent 08a44d9 commit bb03f47

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/create-gen-app/src/extract.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,27 @@ async function loadProjectQuestions(
170170
try {
171171
const content = fs.readFileSync(jsonPath, "utf8");
172172
const questions = JSON.parse(content);
173-
return validateQuestions(questions) ? questions : null;
173+
return validateQuestions(questions) ? normalizeQuestions(questions) : null;
174174
} catch (error) {
175175
const errorMessage =
176176
error instanceof Error ? error.message : String(error);
177177
console.warn(`Failed to parse .questions.json: ${errorMessage}`);
178178
}
179179
}
180-
180+
181181
const jsPath = path.join(templateDir, ".questions.js");
182182
if (fs.existsSync(jsPath)) {
183183
try {
184184
const module = require(jsPath);
185185
const questions = module.default || module;
186-
return validateQuestions(questions) ? questions : null;
186+
return validateQuestions(questions) ? normalizeQuestions(questions) : null;
187187
} catch (error) {
188188
const errorMessage =
189189
error instanceof Error ? error.message : String(error);
190190
console.warn(`Failed to load .questions.js: ${errorMessage}`);
191191
}
192192
}
193-
193+
194194
return null;
195195
}
196196

@@ -286,6 +286,21 @@ function normalizePlaceholder(entry: string): string | null {
286286
return entry || null;
287287
}
288288

289+
/**
290+
* Normalize questions by ensuring all required fields have default values
291+
* @param questions - Questions object to normalize
292+
* @returns Normalized questions object
293+
*/
294+
function normalizeQuestions(questions: Questions): Questions {
295+
return {
296+
...questions,
297+
questions: questions.questions.map((q: any) => ({
298+
...q,
299+
type: q.type || 'text'
300+
}))
301+
};
302+
}
303+
289304
/**
290305
* Validate that the questions object has the correct structure
291306
* @param obj - Object to validate

packages/inquirerer/src/prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function generatePromptMessage(question: Question, ctx: PromptContext): string {
176176
const {
177177
message,
178178
name,
179-
type,
179+
type = 'text',
180180
default: def,
181181
options = [],
182182
description

0 commit comments

Comments
 (0)