Skip to content

Commit f783fc4

Browse files
committed
Fix readme and warnings
1 parent cb76cd0 commit f783fc4

4 files changed

Lines changed: 68 additions & 25 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ export const InitialProjectConfiguration: ProjectConfiguration = {
2121
dataProvider: '',
2222
authProvider: '',
2323
resources: [],
24-
installer: 'npm',
24+
installer: '',
2525
};

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

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ const stepReducer = (
4242
...state,
4343
step:
4444
state.dataProvider === 'ra-data-fakerest'
45-
? 'generate'
45+
? 'install'
4646
: 'resources',
4747
authProvider: action.value,
4848
};
4949
case 'resources':
5050
return {
5151
...state,
52-
step: 'generate',
52+
step: 'install',
5353
resources: action.value,
5454
};
55-
case 'generate':
55+
case 'install':
5656
return {
5757
...state,
58-
step: 'install',
58+
installer: action.value,
59+
step: 'generate',
5960
};
60-
case 'install':
61+
case 'generate':
6162
return {
6263
...state,
63-
installer: action.value,
64-
step: action.value ? 'run-install' : 'finish',
64+
step: state.installer ? 'run-install' : 'finish',
6565
};
6666
case 'run-install':
6767
return {
@@ -98,16 +98,16 @@ export default function App({ name = 'my-admin' }: Props) {
9898
if (state.step === 'resources') {
9999
return <StepResources onSubmit={handleSubmit} />;
100100
}
101+
if (state.step === 'install') {
102+
return <StepInstall onSubmit={handleSubmit} />;
103+
}
101104
if (state.step === 'generate') {
102105
generateProject(state).then(messages => {
103106
helpMessages.current = messages;
104107
dispatch({});
105108
});
106109
return <Text>Generating your application...</Text>;
107110
}
108-
if (state.step === 'install') {
109-
return <StepInstall onSubmit={handleSubmit} />;
110-
}
111111
if (state.step === 'run-install') {
112112
installDeps(state).then(() => {
113113
dispatch({});
@@ -125,16 +125,33 @@ export default function App({ name = 'my-admin' }: Props) {
125125
<Text>
126126
To start working, run <Text bold>cd {state.name}</Text>.
127127
</Text>
128-
<Text>
129-
Start the app in development mode by running{' '}
130-
<Text bold>
131-
{state.installer === 'npm' ? 'npm run' : 'yarn'} dev
128+
{state.installer ? (
129+
<Text>
130+
Start the app in development mode by running{' '}
131+
<Text bold>
132+
{state.installer === 'npm' ? 'npm run' : 'yarn'} dev
133+
</Text>
134+
.
132135
</Text>
133-
.
134-
</Text>
136+
) : (
137+
<Box>
138+
<Box>
139+
<Text>
140+
Install the dependencies using your favorite package
141+
manager.
142+
</Text>
143+
</Box>
144+
<Box>
145+
<Text>
146+
Run the <Text bold>dev</Text> command to start the
147+
app.
148+
</Text>
149+
</Box>
150+
</Box>
151+
)}
135152
<Box marginBottom={1}>
136-
{helpMessages.current.map(line => (
137-
<Text key={line}>{line}</Text>
153+
{helpMessages.current.map((line, index) => (
154+
<Text key={index}>{line}</Text>
138155
))}
139156
</Box>
140157
</>

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ const generateReadme = (
255255
const dataProviderReadme = getTemplateReadme(state.dataProvider);
256256
const authProviderReadme = getTemplateReadme(state.authProvider);
257257

258-
let readme = replaceTokens(defaultReadme, state);
258+
let readme = `${defaultReadme}`;
259259

260260
if (dataProviderReadme) {
261261
readme += `\n${dataProviderReadme}`;
@@ -266,7 +266,10 @@ const generateReadme = (
266266
}
267267

268268
if (readme) {
269-
fs.writeFileSync(path.join(projectDirectory, 'README.md'), readme);
269+
fs.writeFileSync(
270+
path.join(projectDirectory, 'README.md'),
271+
replaceTokens(`${readme}\n`, state)
272+
);
270273
}
271274
};
272275

@@ -288,9 +291,32 @@ const getTemplateReadme = (template: string) => {
288291
};
289292

290293
const replaceTokens = (content: string, state: ProjectConfiguration) => {
294+
let installCommand;
295+
let devCommand;
296+
let buildCommand;
297+
298+
switch (state.installer) {
299+
case 'npm':
300+
installCommand = 'npm install';
301+
devCommand = 'npm run dev';
302+
buildCommand = 'npm run build';
303+
break;
304+
case 'yarn':
305+
installCommand = 'yarn';
306+
devCommand = 'yarn dev';
307+
buildCommand = 'yarn build';
308+
break;
309+
default:
310+
installCommand = 'npm install\n# or\nyarn install';
311+
devCommand = 'npm run dev\n# or\nyarn dev';
312+
buildCommand = 'npm run build\n# or\nyarn build';
313+
}
314+
291315
return content
292316
.replace(`{{name}}`, state.name)
293-
.replace(`{{pkgManager}}`, state.installer);
317+
.replace(`{{installCommand}}`, installCommand)
318+
.replace(`{{devCommand}}`, devCommand)
319+
.replace(`{{buildCommand}}`, buildCommand);
294320
};
295321

296322
const replaceTokensInFile = (filePath: string, state: ProjectConfiguration) => {

packages/create-react-admin/templates/common/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
Install the application dependencies by running:
66

77
```sh
8-
{{pkgManager}} install
8+
{{installCommand}}
99
```
1010

1111
## Development
1212

1313
Start the application in development mode by running:
1414

1515
```sh
16-
{{pkgManager}} run dev
16+
{{devCommand}}
1717
```
1818

1919
## Production
2020

2121
Build the application in production mode by running:
2222

2323
```sh
24-
{{pkgManager}} run build
24+
{{buildCommand}}
2525
```

0 commit comments

Comments
 (0)