Skip to content

Commit 7e8c05e

Browse files
committed
fix: better instructions for package managers
1 parent 5b030a2 commit 7e8c05e

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

src/create-app.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,44 @@ function createTemplateFile(
5959
targetFileName?: string,
6060
extraTemplateValues?: Record<string, any>,
6161
) {
62+
function getPackageManagerAddScript(
63+
packageName: string,
64+
isDev: boolean = false,
65+
) {
66+
let command
67+
switch (options.packageManager) {
68+
case 'yarn':
69+
case 'pnpm':
70+
command = isDev
71+
? `${options.packageManager} add ${packageName} --dev`
72+
: `${options.packageManager} add ${packageName}`
73+
break
74+
default:
75+
command = isDev
76+
? `${options.packageManager} install ${packageName} -D`
77+
: `${options.packageManager} install ${packageName}`
78+
break
79+
}
80+
return command
81+
}
82+
83+
function getPackageManagerRunScript(scriptName: string) {
84+
let command
85+
switch (options.packageManager) {
86+
case 'yarn':
87+
case 'pnpm':
88+
command = `${options.packageManager} ${scriptName}`
89+
break
90+
case 'deno':
91+
command = `${options.packageManager} task ${scriptName}`
92+
break
93+
default:
94+
command = `${options.packageManager} run ${scriptName}`
95+
break
96+
}
97+
return command
98+
}
99+
62100
const templateValues = {
63101
packageManager: options.packageManager,
64102
projectName: projectName,
@@ -77,7 +115,11 @@ function createTemplateFile(
77115
{},
78116
),
79117
addOns: options.chosenAddOns,
118+
80119
...extraTemplateValues,
120+
121+
getPackageManagerAddScript,
122+
getPackageManagerRunScript,
81123
}
82124

83125
const template = await environment.readFile(

templates/react/base/README.md.ejs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ To run this application:
66

77
```bash
88
<%= packageManager %> install
9-
<%= packageManager %> start
9+
<%= getPackageManagerRunScript('start') %>
1010
```
1111

1212
# Building For Production
1313

1414
To build this application for production:
1515

1616
```bash
17-
<%= packageManager %> run build
17+
<%= getPackageManagerRunScript('build') %>
1818
```
1919

2020
## Testing
2121

2222
This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:
2323

2424
```bash
25-
<%= packageManager %> run test
25+
<%= getPackageManagerRunScript('test') %>
2626
```
2727

2828
## Styling
@@ -36,9 +36,9 @@ This project uses CSS for styling.
3636
This project uses [Biome](https://biomejs.dev/) for linting and formatting. The following scripts are available:
3737
3838
```bash
39-
<%= packageManager %> run lint
40-
<%= packageManager %> run format
41-
<%= packageManager %> run check # runs both lint and format together
39+
<%= getPackageManagerRunScript('lint') %>
40+
<%= getPackageManagerRunScript('format') %>
41+
<%= getPackageManagerRunScript('check') %>
4242
```
4343
<% } %>
4444
@@ -183,7 +183,7 @@ More information on layouts can be found in the [Layouts documentation](hthttps:
183183
First you need to add the Vite plugin for Tanstack Router:
184184
185185
```bash
186-
<%= packageManager %> install -D @tanstack/router-plugin
186+
<%= getPackageManagerAddScript("@tanstack/router-plugin", true) %>
187187
```
188188
189189
From there you need to update your `vite.config.js` file to use the plugin:
@@ -391,7 +391,7 @@ React-Query is an excellent addition or alternative to route loading and integra
391391
First add your dependencies:
392392
393393
```bash
394-
<%= packageManager %> install @tanstack/react-query @tanstack/react-query-devtools
394+
<%= getPackageManagerAddScript("@tanstack/react-query @tanstack/react-query-devtools") %>
395395
```
396396
397397
Next we'll need to creata query client and provider. We recommend putting those in `main.<%= jsx %>`.
@@ -474,7 +474,7 @@ Another common requirement for React applications is state management. There are
474474
First you need to add TanStack Store as a dependency:
475475
476476
```bash
477-
<%= packageManager %> install @tanstack/store
477+
<%= getPackageManagerAddScript("@tanstack/store") %>
478478
```
479479
480480
Now let's create a simple counter in the `src/App.<%= jsx %>` file as a demonstration.

templates/solid/base/README.md.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ To run this application:
66

77
```bash
88
<%= packageManager %> install
9-
<%= packageManager %> start
9+
<%= getPackageManagerRunScript('start') %>
1010
```
1111

1212
# Building For Production
1313

1414
To build this application for production:
1515

1616
```bash
17-
<%= packageManager %> run build
17+
<%= getPackageManagerRunScript('build') %>
1818
```
1919

2020
## Styling

tests/snapshots/cra/cr-js-npm.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snapshots/cra/cr-ts-npm.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snapshots/cra/fr-ts-npm.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snapshots/cra/fr-ts-tw-npm.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)