Skip to content

Commit ad45963

Browse files
committed
Templates can now provide help texts
1 parent d3bc55e commit ad45963

3 files changed

Lines changed: 46 additions & 7 deletions

File tree

packages/create-react-admin/src/app.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useReducer } from 'react';
2-
import { Text } from 'ink';
1+
import React, { useReducer, useRef } from 'react';
2+
import { Box, Text } from 'ink';
33
import {
44
InitialProjectConfiguration,
55
ProjectConfiguration,
@@ -71,6 +71,7 @@ export default function App({ name = 'my-admin' }: Props) {
7171
...InitialProjectConfiguration,
7272
name,
7373
});
74+
const helpMessages = useRef([]);
7475
const installDeps = useInstallDeps();
7576
const handleSubmit = (value: any) => {
7677
dispatch({ value });
@@ -86,7 +87,8 @@ export default function App({ name = 'my-admin' }: Props) {
8687
return <StepResources onSubmit={handleSubmit} />;
8788
}
8889
if (state.step === 'generate') {
89-
generateProject(state).then(() => {
90+
generateProject(state).then(messages => {
91+
helpMessages.current = messages;
9092
dispatch({});
9193
});
9294
return <Text>Generating your application...</Text>;
@@ -102,17 +104,24 @@ export default function App({ name = 'my-admin' }: Props) {
102104
}
103105
return (
104106
<>
105-
<Text>
106-
Your application <Text bold>{state.name}</Text> was successfully
107-
generated.
108-
</Text>
107+
<Box marginBottom={1}>
108+
<Text>
109+
Your application <Text bold>{state.name}</Text> was
110+
successfully generated.
111+
</Text>
112+
</Box>
109113
<Text>
110114
To start working, run <Text bold>cd {state.name}</Text>.
111115
</Text>
112116
<Text>
113117
Start the app in development mode by running{' '}
114118
<Text bold>npm dev</Text>.
115119
</Text>
120+
<Box marginBottom={1}>
121+
{helpMessages.current.map(line => (
122+
<Text key={line}>{line}</Text>
123+
))}
124+
</Box>
116125
</>
117126
);
118127
}

packages/create-react-admin/src/generateProject.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ export const generateProject = async (state: ProjectConfiguration) => {
3636
generatePackageJson(projectDirectory, state);
3737
generateEnvFile(projectDirectory, state);
3838
generateReadme(projectDirectory, state);
39+
40+
return getHelpMessages(state);
41+
};
42+
43+
const getHelpMessages = (state: ProjectConfiguration) => {
44+
const dataProviderHelpMessages = getTemplateHelpMessages(
45+
state.dataProvider
46+
);
47+
const authProviderHelpMessages = getTemplateHelpMessages(
48+
state.authProvider
49+
);
50+
51+
return [dataProviderHelpMessages, authProviderHelpMessages];
52+
};
53+
54+
const getTemplateHelpMessages = (template: string) => {
55+
const helpMessagesPath = path.join(
56+
__dirname,
57+
'../templates',
58+
template,
59+
'help.txt'
60+
);
61+
if (fs.existsSync(helpMessagesPath)) {
62+
const helpMessages = fs.readFileSync(helpMessagesPath, 'utf-8');
63+
return helpMessages;
64+
}
65+
return '';
3966
};
4067

4168
const generateAppFile = (
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
You can sign in to the application with the following usernames and password:
2+
- janedoe / password
3+
- johndoe / password

0 commit comments

Comments
 (0)