-
-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom messages and icons in recipes (#2510)
Adds ability to customize the success message icon in recipes (patch) Co-authored-by: Nicolas <[email protected]>
- Loading branch information
Showing
8 changed files
with
95 additions
and
4 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
36 changes: 36 additions & 0 deletions
36
packages/installer/src/executors/print-message-executor.tsx
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,36 @@ | ||
import {Box, Text} from "ink" | ||
import * as React from "react" | ||
import {Newline} from "../components/newline" | ||
import {useEnterToContinue} from "../utils/use-enter-to-continue" | ||
import {Executor, executorArgument, ExecutorConfig, getExecutorArgument} from "./executor" | ||
|
||
export interface Config extends ExecutorConfig { | ||
message: executorArgument<string> | ||
} | ||
|
||
export const type = "print-message" | ||
|
||
export const Commit: Executor["Commit"] = ({cliArgs, onChangeCommitted, step}) => { | ||
const generatorArgs = React.useMemo( | ||
() => ({ | ||
message: getExecutorArgument((step as Config).message, cliArgs), | ||
stepName: getExecutorArgument((step as Config).stepName, cliArgs), | ||
}), | ||
[cliArgs, step], | ||
) | ||
|
||
const handleChangeCommitted = React.useCallback(() => { | ||
onChangeCommitted(generatorArgs.stepName) | ||
}, [onChangeCommitted, generatorArgs]) | ||
|
||
useEnterToContinue(handleChangeCommitted) | ||
|
||
return ( | ||
<Box flexDirection="column"> | ||
{/* eslint-disable-next-line jsx-a11y/accessible-emoji */} | ||
<Text>{generatorArgs.message}</Text> | ||
<Newline /> | ||
<Text bold>Press ENTER to continue</Text> | ||
</Box> | ||
) | ||
} |
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
7 changes: 7 additions & 0 deletions
7
packages/installer/test/executors/__snapshots__/print-message-executor.test.tsx.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Executor should render PrintMessageExecutor 1`] = ` | ||
"My message | ||
Press ENTER to continue" | ||
`; |
29 changes: 29 additions & 0 deletions
29
packages/installer/test/executors/print-message-executor.test.tsx
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,29 @@ | ||
import {render} from "ink-testing-library" | ||
import React from "react" | ||
import stripAnsi from "strip-ansi" | ||
import {Commit as PrintMessageExecutor} from "../../src/executors/print-message-executor" | ||
|
||
describe("Executor", () => { | ||
const executorConfig = { | ||
stepId: "printMessage", | ||
stepName: "Print message", | ||
stepType: "print-message", | ||
explanation: "Testing text for a print message", | ||
message: "My message", | ||
} | ||
it("should render PrintMessageExecutor", () => { | ||
const {lastFrame} = render( | ||
<PrintMessageExecutor cliArgs={null} onChangeCommitted={() => {}} step={executorConfig} />, | ||
) | ||
|
||
expect(stripAnsi(lastFrame())).toMatchSnapshot() | ||
}) | ||
|
||
it("should contain a step name and explanation", () => { | ||
const {frames} = render( | ||
<PrintMessageExecutor cliArgs={null} onChangeCommitted={() => {}} step={executorConfig} />, | ||
) | ||
|
||
expect(frames[0].includes("My message")).toBeTruthy() | ||
}) | ||
}) |