-
Notifications
You must be signed in to change notification settings - Fork 472
/
Copy pathgenerateReadme.ts
172 lines (135 loc) · 4.13 KB
/
generateReadme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import getCommand from './getCommand'
const sfcTypeSupportDoc = [
'',
'## Type Support for `.vue` Imports in TS',
'',
'TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.',
'',
].join('\n')
export default function generateReadme({
projectName,
packageManager,
needsTypeScript,
needsCypress,
needsNightwatch,
needsCypressCT,
needsNightwatchCT,
needsPlaywright,
needsVitest,
needsEslint,
}) {
const commandFor = (scriptName: string, args?: string) =>
getCommand(packageManager, scriptName, args)
let readme = `# ${projectName}
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
${needsTypeScript ? sfcTypeSupportDoc : ''}
## Customize configuration
See [Vite Configuration Reference](https://vite.dev/config/).
## Project Setup
`
let installCommand = commandFor('install')
if (packageManager === 'pnpm' && needsNightwatch) {
// TODO: remove the "for pnpm 10+" note when pnpm 10 is widely adopted
installCommand += `\npnpm approve-builds # for pnpm 10+`
}
let npmScriptsDescriptions = `\`\`\`sh
${installCommand}
\`\`\`
### Compile and Hot-Reload for Development
\`\`\`sh
${commandFor('dev')}
\`\`\`
### ${needsTypeScript ? 'Type-Check, ' : ''}Compile and Minify for Production
\`\`\`sh
${commandFor('build')}
\`\`\`
`
if (needsVitest) {
npmScriptsDescriptions += `
### Run Unit Tests with [Vitest](https://vitest.dev/)
\`\`\`sh
${commandFor('test:unit')}
\`\`\`
`
}
if (needsCypressCT) {
npmScriptsDescriptions += `
### Run Headed Component Tests with [Cypress Component Testing](https://on.cypress.io/component)
\`\`\`sh
${commandFor('test:unit:dev')} # or \`${commandFor('test:unit')}\` for headless testing
\`\`\`
`
}
if (needsCypress) {
npmScriptsDescriptions += `
### Run End-to-End Tests with [Cypress](https://www.cypress.io/)
\`\`\`sh
${commandFor('test:e2e:dev')}
\`\`\`
This runs the end-to-end tests against the Vite development server.
It is much faster than the production build.
But it's still recommended to test the production build with \`test:e2e\` before deploying (e.g. in CI environments):
\`\`\`sh
${commandFor('build')}
${commandFor('test:e2e')}
\`\`\`
`
}
if (needsNightwatch) {
npmScriptsDescriptions += `
### Run End-to-End Tests with [Nightwatch](https://nightwatchjs.org/)
\`\`\`sh
# When using CI, the project must be built first.
${commandFor('build')}
# Runs the end-to-end tests
${commandFor('test:e2e')}
# Runs the tests only on Chrome
${commandFor('test:e2e', '--env chrome')}
# Runs the tests of a specific file
${commandFor('test:e2e', `tests/e2e/example.${needsTypeScript ? 'ts' : 'js'}`)}
# Runs the tests in debug mode
${commandFor('test:e2e', '--debug')}
\`\`\`
`
}
if (needsNightwatchCT) {
npmScriptsDescriptions += `
### Run Headed Component Tests with [Nightwatch Component Testing](https://nightwatchjs.org/guide/component-testing/introduction.html)
\`\`\`sh
${commandFor('test:unit')}
${commandFor('test:unit -- --headless # for headless testing')}
\`\`\`
`
}
if (needsPlaywright) {
npmScriptsDescriptions += `
### Run End-to-End Tests with [Playwright](https://playwright.dev)
\`\`\`sh
# Install browsers for the first run
npx playwright install
# When testing on CI, must build the project first
${commandFor('build')}
# Runs the end-to-end tests
${commandFor('test:e2e')}
# Runs the tests only on Chromium
${commandFor('test:e2e', '--project=chromium')}
# Runs the tests of a specific file
${commandFor('test:e2e', 'tests/example.spec.ts')}
# Runs the tests in debug mode
${commandFor('test:e2e', '--debug')}
\`\`\`
`
}
if (needsEslint) {
npmScriptsDescriptions += `
### Lint with [ESLint](https://eslint.org/)
\`\`\`sh
${commandFor('lint')}
\`\`\`
`
}
readme += npmScriptsDescriptions
return readme
}