-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-cloudflare): allow users to change prompt answer (#6428)
- Loading branch information
1 parent
0d85f24
commit 37dc86f
Showing
11 changed files
with
449 additions
and
250 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"create-cloudflare": minor | ||
--- | ||
|
||
feat: allow users to change prompt answer | ||
|
||
It is now possible to change the answer for category and type while the project has not been created locally. |
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 |
---|---|---|
@@ -1,29 +1,21 @@ | ||
import { getRenderers, inputPrompt } from "./interactive"; | ||
import { crash, logRaw } from "."; | ||
import { inputPrompt } from "./interactive"; | ||
import type { Arg, PromptConfig } from "./interactive"; | ||
|
||
export const processArgument = async <T>( | ||
args: Record<string, Arg>, | ||
name: string, | ||
promptConfig: PromptConfig | ||
) => { | ||
let value = args[name]; | ||
const renderSubmitted = getRenderers(promptConfig).submit; | ||
const value = args[name]; | ||
const result = await inputPrompt<T>({ | ||
...promptConfig, | ||
// Accept the default value if the arg is already set | ||
acceptDefault: promptConfig.acceptDefault ?? value !== undefined, | ||
defaultValue: value ?? promptConfig.defaultValue, | ||
}); | ||
|
||
// If the value has already been set via args, use that | ||
if (value !== undefined) { | ||
const error = promptConfig.validate?.(value); | ||
if (error) { | ||
crash(error); | ||
} | ||
// Update value in args before returning the result | ||
args[name] = result as Arg; | ||
|
||
const lines = renderSubmitted({ value }); | ||
logRaw(lines.join("\n")); | ||
|
||
return value as T; | ||
} | ||
|
||
value = await inputPrompt(promptConfig); | ||
|
||
return value as T; | ||
return result; | ||
}; |
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
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.