|
1 | 1 | import { ValidCreateNextStackFlags } from "../create-next-stack-types" |
2 | | -import { ThenArg } from "../helpers/then-arg" |
3 | 2 | import { withKeyConstraint } from "../helpers/with-key-constraint" |
4 | 3 | import { CategoryValue, promptOptionalCategories } from "./questions/categories" |
5 | | -import { promptAnimation } from "./questions/categories/animation" |
6 | | -import { promptContinuousIntegration } from "./questions/categories/continuous-integration" |
7 | | -import { promptFormStateManagement } from "./questions/categories/form-state-management" |
8 | | -import { promptFormatting } from "./questions/categories/formatting" |
| 4 | +import { |
| 5 | + AnimationValue, |
| 6 | + promptAnimation, |
| 7 | +} from "./questions/categories/animation" |
| 8 | +import { |
| 9 | + ComponentLibraryValue, |
| 10 | + promptComponentLibraries, |
| 11 | +} from "./questions/categories/component-libraries" |
| 12 | +import { |
| 13 | + ContinuousIntegrationValue, |
| 14 | + promptContinuousIntegration, |
| 15 | +} from "./questions/categories/continuous-integration" |
| 16 | +import { |
| 17 | + FormStateManagementValue, |
| 18 | + promptFormStateManagement, |
| 19 | +} from "./questions/categories/form-state-management" |
| 20 | +import { |
| 21 | + FormattingValue, |
| 22 | + promptFormatting, |
| 23 | +} from "./questions/categories/formatting" |
9 | 24 | import { |
10 | 25 | MiscellaneousValue, |
11 | 26 | promptMiscellaneous, |
12 | 27 | } from "./questions/categories/miscellaneous" |
13 | | -import { promptPackageManager } from "./questions/categories/package-manager" |
14 | | -import { promptStyling } from "./questions/categories/styling" |
| 28 | +import { |
| 29 | + PackageManagerValue, |
| 30 | + promptPackageManager, |
| 31 | +} from "./questions/categories/package-manager" |
| 32 | +import { promptStyling, StylingValue } from "./questions/categories/styling" |
15 | 33 |
|
16 | 34 | const categoryToPromptFunction = withKeyConstraint<CategoryValue>()({ |
17 | 35 | formatting: promptFormatting, |
| 36 | + componentLibraries: promptComponentLibraries, |
18 | 37 | formStateManagement: promptFormStateManagement, |
19 | 38 | animation: promptAnimation, |
20 | 39 | continuousIntegration: promptContinuousIntegration, |
21 | 40 | } as const) |
22 | 41 |
|
23 | | -type PromptReturnType = ThenArg< |
24 | | - ReturnType<typeof categoryToPromptFunction[CategoryValue]> |
25 | | -> |
26 | | -export type OptionalTechnology = PromptReturnType extends Array<unknown> |
27 | | - ? PromptReturnType[number] |
28 | | - : PromptReturnType |
| 42 | +export type Technology = |
| 43 | + | AnimationValue |
| 44 | + | ComponentLibraryValue |
| 45 | + | ContinuousIntegrationValue |
| 46 | + | FormStateManagementValue |
| 47 | + | FormattingValue |
| 48 | + | MiscellaneousValue |
| 49 | + | PackageManagerValue |
| 50 | + | StylingValue |
29 | 51 |
|
30 | 52 | export const performFlagsQuestionnaire = |
31 | 53 | async (): Promise<ValidCreateNextStackFlags> => { |
| 54 | + const technologies = new Set<Technology>() |
| 55 | + |
32 | 56 | // Mandatory prompts |
33 | 57 | const packageManager = await promptPackageManager() |
| 58 | + technologies.add(packageManager) |
34 | 59 | const stylingMethod = await promptStyling() |
| 60 | + technologies.add(stylingMethod) |
35 | 61 |
|
36 | 62 | // Optional categories prompt |
37 | 63 | const optionalCategories = await promptOptionalCategories() |
38 | | - const optionalTechnologies = new Set<OptionalTechnology>() |
39 | 64 | for (const category of optionalCategories) { |
40 | | - const additionalTechnologies = await categoryToPromptFunction[category]() |
41 | | - additionalTechnologies.forEach((tech) => optionalTechnologies.add(tech)) |
| 65 | + const optionalTechnologies = await categoryToPromptFunction[category]( |
| 66 | + technologies |
| 67 | + ) |
| 68 | + optionalTechnologies.forEach((tech) => technologies.add(tech)) |
42 | 69 | } |
43 | 70 |
|
44 | 71 | // TODO: Remove prettier-check when promptMiscellaneous adds more options |
45 | 72 | let miscellaneous: Set<MiscellaneousValue> = new Set() |
46 | | - if (optionalTechnologies.has("prettier")) { |
47 | | - miscellaneous = await promptMiscellaneous(optionalTechnologies) |
| 73 | + if (technologies.has("prettier")) { |
| 74 | + miscellaneous = await promptMiscellaneous(technologies) |
| 75 | + miscellaneous.forEach((tech) => technologies.add(tech)) |
48 | 76 | } |
49 | 77 |
|
50 | | - return { |
| 78 | + const result: Required< |
| 79 | + Omit<ValidCreateNextStackFlags, "help" | "version" | "debug"> |
| 80 | + > = { |
51 | 81 | "package-manager": packageManager, |
52 | 82 | styling: stylingMethod, |
53 | | - prettier: optionalTechnologies.has("prettier"), |
54 | | - "react-hook-form": optionalTechnologies.has("reactHookForm"), |
55 | | - formik: optionalTechnologies.has("formik"), |
56 | | - "framer-motion": optionalTechnologies.has("framerMotion"), |
57 | | - "github-actions": optionalTechnologies.has("githubActions"), |
| 83 | + prettier: technologies.has("prettier"), |
| 84 | + "react-hook-form": technologies.has("reactHookForm"), |
| 85 | + formik: technologies.has("formik"), |
| 86 | + "framer-motion": technologies.has("framerMotion"), |
| 87 | + "github-actions": technologies.has("githubActions"), |
58 | 88 | "formatting-pre-commit-hook": miscellaneous.has( |
59 | 89 | "formattingPreCommitHook" |
60 | 90 | ), |
| 91 | + chakra: technologies.has("chakra"), |
61 | 92 | } |
| 93 | + |
| 94 | + return result |
62 | 95 | } |
0 commit comments