-
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 some answers
- Loading branch information
1 parent
a504725
commit eef5faa
Showing
6 changed files
with
245 additions
and
179 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 |
---|---|---|
@@ -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
Oops, something went wrong.