nuxt-spec 0.2.0-alpha.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +364 -364
- package/app/app.vue +10 -10
- package/app/components/NuxtSpecApiTestComponent.vue +24 -24
- package/app/components/NuxtSpecTestComponent.vue +9 -9
- package/app/components/index.ts +2 -0
- package/app/utils/vitest-utils.ts +5 -5
- package/bin/cli.js +53 -53
- package/bin/setup.js +243 -243
- package/config/index.d.ts +17 -17
- package/config/index.mjs +79 -79
- package/config/templates/pnpm-workspace.yaml.template +4 -4
- package/config/templates/vitest.config.ts.template +5 -5
- package/config/utils/merge.mjs +43 -43
- package/config/utils/warnings.mjs +32 -26
- package/nuxt.config.ts +19 -14
- package/package.json +12 -4
- package/utils/e2e.ts +30 -30
- package/utils/index.d.ts +70 -70
- package/utils/index.ts +12 -12
- package/utils/screenshot.ts +89 -89
package/bin/setup.js
CHANGED
|
@@ -1,243 +1,243 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createFileFromWebTemplate, deletePath, getPackageManager, hasJsonKey,
|
|
5
|
-
pathExists, promptUser, removeFromJsonFile, showMessage,
|
|
6
|
-
updateConfigFile, updateJsonFile, updateTextFile,
|
|
7
|
-
} from 'elrh-cosca'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* CLI tool to scaffold necessary adjustments in project folder.
|
|
11
|
-
*
|
|
12
|
-
* It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
|
|
13
|
-
*
|
|
14
|
-
* Then it:
|
|
15
|
-
* 1) adds `nuxt-spec` into `package.json` dependencies and removes `nuxt`, `vue` and `vue-router` if present
|
|
16
|
-
* 2) adds `extends: ['nuxt-spec']` to `nuxt.config.ts`
|
|
17
|
-
* 3) creates/updates `pnpm-workspace.yaml` file (only if pnpm is used)
|
|
18
|
-
* 4) creates default `vitest.config.ts` file
|
|
19
|
-
* 5) adds test-related scripts and pnpm approved build scripts (if using pnpm) in `package.json`
|
|
20
|
-
* 6) creates sample test files
|
|
21
|
-
* 7) clear node_modules and lock file(s)
|
|
22
|
-
*
|
|
23
|
-
* @param {boolean} autoRun - Whether to run the setup automatically without any prompts (defaults to false).
|
|
24
|
-
*/
|
|
25
|
-
export async function specSetup(autoRun = false) {
|
|
26
|
-
showMessage('NUXT SPEC SETUP')
|
|
27
|
-
showMessage('This CLI tool will help you include Nuxt Spec in your project.')
|
|
28
|
-
showMessage('Refer to the documentation for more information.', 2)
|
|
29
|
-
|
|
30
|
-
const isAutoRun = autoRun || await promptUser('Do you want to set everything up automatically (no more prompts)?')
|
|
31
|
-
showMessage('')
|
|
32
|
-
|
|
33
|
-
const packageManager = getPackageManager()
|
|
34
|
-
|
|
35
|
-
// 1) manage dependencies in package.json
|
|
36
|
-
|
|
37
|
-
// add nuxt-spec
|
|
38
|
-
try {
|
|
39
|
-
await updateJsonFile('package.json', 'dependencies', {
|
|
40
|
-
'nuxt-spec': '0.2.0
|
|
41
|
-
}, isAutoRun, 'This will add \'nuxt-spec\' dependency to your \'package.json\'. Continue?')
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error('Error adding \'nuxt-spec\' dependency:\n', error.message)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// remove now obsolete nuxt, vue and vue-router
|
|
47
|
-
const removeDeps = isAutoRun || await promptUser('As \'nuxt-spec\' provides \'nuxt\', \'vue\' and \'vue-router\' dependencies out of the box, do you want to remove them from your \'package.json\' to avoid duplications and possible version clashes?')
|
|
48
|
-
if (removeDeps) {
|
|
49
|
-
if (hasJsonKey('package.json', 'dependencies.nuxt')) {
|
|
50
|
-
try {
|
|
51
|
-
await removeFromJsonFile('package.json', 'dependencies.nuxt', true)
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error('Error removing \'nuxt\' dependency:\n', error.message)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (hasJsonKey('package.json', 'dependencies.vue')) {
|
|
57
|
-
try {
|
|
58
|
-
await removeFromJsonFile('package.json', 'dependencies.vue', true)
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error('Error removing \'vue\' dependency:\n', error.message)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (hasJsonKey('package.json', 'dependencies.vue-router')) {
|
|
64
|
-
try {
|
|
65
|
-
await removeFromJsonFile('package.json', 'dependencies.vue-router', true)
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.error('Error removing \'vue-router\' dependency:\n', error.message)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (hasJsonKey('package.json', 'devDependencies.nuxt')) {
|
|
71
|
-
try {
|
|
72
|
-
await removeFromJsonFile('package.json', 'devDependencies.nuxt', true)
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error('Error removing \'nuxt\' devDependency:\n', error.message)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (hasJsonKey('package.json', 'devDependencies.vue')) {
|
|
78
|
-
try {
|
|
79
|
-
await removeFromJsonFile('package.json', 'devDependencies.vue', true)
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error('Error removing \'vue\' devDependency:\n', error.message)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (hasJsonKey('package.json', 'devDependencies.vue-router')) {
|
|
85
|
-
try {
|
|
86
|
-
await removeFromJsonFile('package.json', 'devDependencies.vue-router', true)
|
|
87
|
-
} catch (error) {
|
|
88
|
-
console.error('Error removing \'vue-router\' devDependency:\n', error.message)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 2) modify nuxt.config.ts
|
|
94
|
-
try {
|
|
95
|
-
await updateConfigFile('nuxt.config.ts', {
|
|
96
|
-
extends: [
|
|
97
|
-
'nuxt-spec',
|
|
98
|
-
],
|
|
99
|
-
}, isAutoRun, 'This will add \'nuxt-spec\' module to your \'nuxt.config.ts\'. Continue?')
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.error('Error updating \'nuxt.config.ts\':\n', error.message)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 3) `pnpm-workspace.yaml` file (only if pnpm is used)
|
|
105
|
-
if (packageManager === 'pnpm') {
|
|
106
|
-
try {
|
|
107
|
-
if (pathExists('pnpm-workspace.yaml')) {
|
|
108
|
-
await updateTextFile('pnpm-workspace.yaml', ['shamefully-hoist=true'], isAutoRun, 'This will adjust \'pnpm-workspace.yaml\' file in your project. Continue?')
|
|
109
|
-
} else {
|
|
110
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0
|
|
111
|
-
'pnpm-workspace.yaml', isAutoRun, 'This will add \'pnpm-workspace.yaml\' file for your project. Continue?')
|
|
112
|
-
}
|
|
113
|
-
} catch (error) {
|
|
114
|
-
console.error('Error setting up \'pnpm-workspace.yaml\':\n', error.message)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 4) create vitest.config.ts
|
|
119
|
-
try {
|
|
120
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0
|
|
121
|
-
'vitest.config.ts', isAutoRun, 'This will create a new \'vitest.config.ts\' file for your project. Continue?')
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error('Error setting up \'vitest.config.ts\':\n', error.message)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 5) modify package.json
|
|
127
|
-
|
|
128
|
-
// add test scripts
|
|
129
|
-
try {
|
|
130
|
-
await updateJsonFile('package.json', 'scripts', {
|
|
131
|
-
'test': 'vitest run',
|
|
132
|
-
'test-u': 'vitest run -u',
|
|
133
|
-
'test-i': 'vitest',
|
|
134
|
-
}, isAutoRun, 'This will adjust the test-related commands in your \'package.json\'. Continue?')
|
|
135
|
-
} catch (error) {
|
|
136
|
-
console.error('Error adjusting scripts in \'package.json\':\n', error.message)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// add pnpm approved build scripts
|
|
140
|
-
if (packageManager === 'pnpm') {
|
|
141
|
-
try {
|
|
142
|
-
await updateJsonFile('package.json', 'pnpm', {
|
|
143
|
-
onlyBuiltDependencies: [
|
|
144
|
-
'@parcel/watcher',
|
|
145
|
-
'esbuild',
|
|
146
|
-
'unrs-resolver',
|
|
147
|
-
],
|
|
148
|
-
}, isAutoRun, 'This will adjust pnpm approved build scripts in your \'package.json\'. Continue?')
|
|
149
|
-
} catch (error) {
|
|
150
|
-
console.error('Error adjusting pnpm approved build scripts in \'package.json\':\n', error.message)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// 6) create sample test files
|
|
155
|
-
const createSampleTests = isAutoRun || await promptUser('Do you want to create sample tests in \'/test\' folder?')
|
|
156
|
-
if (createSampleTests) {
|
|
157
|
-
try {
|
|
158
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0
|
|
159
|
-
'test/browser/vitest-browser.test.ts', true)
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.error('Error setting up \'vitest-browser.test.ts\':\n', error.message)
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0
|
|
165
|
-
'test/e2e/nuxt-e2e.test.ts', true)
|
|
166
|
-
} catch (error) {
|
|
167
|
-
console.error('Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0
|
|
171
|
-
'test/e2e/nuxt-visual.test.ts', true)
|
|
172
|
-
} catch (error) {
|
|
173
|
-
console.error('Error setting up \'nuxt-visual.test.ts\':\n', error.message)
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0
|
|
177
|
-
'test/nuxt/nuxt-unit.test.ts', true)
|
|
178
|
-
} catch (error) {
|
|
179
|
-
console.error('Error setting up \'nuxt-unit.test.ts\':\n', error.message)
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0
|
|
183
|
-
'test/unit/vitest-unit.test.ts', true)
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.error('Error setting up \'vitest-unit.test.ts\':\n', error.message)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// 7) clear node_modules and lock file(s)
|
|
190
|
-
const prepareForReinstall = isAutoRun || await promptUser('Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?')
|
|
191
|
-
if (prepareForReinstall) {
|
|
192
|
-
if (pathExists('node_modules')) {
|
|
193
|
-
try {
|
|
194
|
-
await deletePath('node_modules', true)
|
|
195
|
-
} catch (error) {
|
|
196
|
-
console.error('Error deleting \'node_modules\':\n', error.message)
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (pathExists('package-lock.json')) {
|
|
200
|
-
try {
|
|
201
|
-
await deletePath('package-lock.json', true)
|
|
202
|
-
} catch (error) {
|
|
203
|
-
console.error('Error deleting \'package-lock.json\':\n', error.message)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (pathExists('pnpm-lock.yaml')) {
|
|
207
|
-
try {
|
|
208
|
-
await deletePath('pnpm-lock.yaml', true)
|
|
209
|
-
} catch (error) {
|
|
210
|
-
console.error('Error deleting \'pnpm-lock.yaml\':\n', error.message)
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
if (pathExists('yarn.lock')) {
|
|
214
|
-
try {
|
|
215
|
-
await deletePath('yarn.lock', true)
|
|
216
|
-
} catch (error) {
|
|
217
|
-
console.error('Error deleting \'yarn.lock\':\n', error.message)
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (pathExists('bun.lockb')) {
|
|
221
|
-
try {
|
|
222
|
-
await deletePath('bun.lockb', true)
|
|
223
|
-
} catch (error) {
|
|
224
|
-
console.error('Error deleting \'bun.lockb\':\n', error.message)
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (pathExists('deno.lock')) {
|
|
228
|
-
try {
|
|
229
|
-
await deletePath('deno.lock', true)
|
|
230
|
-
} catch (error) {
|
|
231
|
-
console.error('Error deleting \'deno.lock\':\n', error.message)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// 7) inform user
|
|
237
|
-
showMessage('')
|
|
238
|
-
showMessage('NUXT SPEC SETUP COMPLETE', 2)
|
|
239
|
-
showMessage(`Proceed with \`${packageManager} install\` to get started.`)
|
|
240
|
-
|
|
241
|
-
// force exit to prevent #20
|
|
242
|
-
process.exit(0)
|
|
243
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createFileFromWebTemplate, deletePath, getPackageManager, hasJsonKey,
|
|
5
|
+
pathExists, promptUser, removeFromJsonFile, showMessage,
|
|
6
|
+
updateConfigFile, updateJsonFile, updateTextFile,
|
|
7
|
+
} from 'elrh-cosca'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CLI tool to scaffold necessary adjustments in project folder.
|
|
11
|
+
*
|
|
12
|
+
* It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
|
|
13
|
+
*
|
|
14
|
+
* Then it:
|
|
15
|
+
* 1) adds `nuxt-spec` into `package.json` dependencies and removes `nuxt`, `vue` and `vue-router` if present
|
|
16
|
+
* 2) adds `extends: ['nuxt-spec']` to `nuxt.config.ts`
|
|
17
|
+
* 3) creates/updates `pnpm-workspace.yaml` file (only if pnpm is used)
|
|
18
|
+
* 4) creates default `vitest.config.ts` file
|
|
19
|
+
* 5) adds test-related scripts and pnpm approved build scripts (if using pnpm) in `package.json`
|
|
20
|
+
* 6) creates sample test files
|
|
21
|
+
* 7) clear node_modules and lock file(s)
|
|
22
|
+
*
|
|
23
|
+
* @param {boolean} autoRun - Whether to run the setup automatically without any prompts (defaults to false).
|
|
24
|
+
*/
|
|
25
|
+
export async function specSetup(autoRun = false) {
|
|
26
|
+
showMessage('NUXT SPEC SETUP')
|
|
27
|
+
showMessage('This CLI tool will help you include Nuxt Spec in your project.')
|
|
28
|
+
showMessage('Refer to the documentation for more information.', 2)
|
|
29
|
+
|
|
30
|
+
const isAutoRun = autoRun || await promptUser('Do you want to set everything up automatically (no more prompts)?')
|
|
31
|
+
showMessage('')
|
|
32
|
+
|
|
33
|
+
const packageManager = getPackageManager()
|
|
34
|
+
|
|
35
|
+
// 1) manage dependencies in package.json
|
|
36
|
+
|
|
37
|
+
// add nuxt-spec
|
|
38
|
+
try {
|
|
39
|
+
await updateJsonFile('package.json', 'dependencies', {
|
|
40
|
+
'nuxt-spec': '0.2.0',
|
|
41
|
+
}, isAutoRun, 'This will add \'nuxt-spec\' dependency to your \'package.json\'. Continue?')
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Error adding \'nuxt-spec\' dependency:\n', error.message)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// remove now obsolete nuxt, vue and vue-router
|
|
47
|
+
const removeDeps = isAutoRun || await promptUser('As \'nuxt-spec\' provides \'nuxt\', \'vue\' and \'vue-router\' dependencies out of the box, do you want to remove them from your \'package.json\' to avoid duplications and possible version clashes?')
|
|
48
|
+
if (removeDeps) {
|
|
49
|
+
if (hasJsonKey('package.json', 'dependencies.nuxt')) {
|
|
50
|
+
try {
|
|
51
|
+
await removeFromJsonFile('package.json', 'dependencies.nuxt', true)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Error removing \'nuxt\' dependency:\n', error.message)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (hasJsonKey('package.json', 'dependencies.vue')) {
|
|
57
|
+
try {
|
|
58
|
+
await removeFromJsonFile('package.json', 'dependencies.vue', true)
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error('Error removing \'vue\' dependency:\n', error.message)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (hasJsonKey('package.json', 'dependencies.vue-router')) {
|
|
64
|
+
try {
|
|
65
|
+
await removeFromJsonFile('package.json', 'dependencies.vue-router', true)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error('Error removing \'vue-router\' dependency:\n', error.message)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (hasJsonKey('package.json', 'devDependencies.nuxt')) {
|
|
71
|
+
try {
|
|
72
|
+
await removeFromJsonFile('package.json', 'devDependencies.nuxt', true)
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Error removing \'nuxt\' devDependency:\n', error.message)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (hasJsonKey('package.json', 'devDependencies.vue')) {
|
|
78
|
+
try {
|
|
79
|
+
await removeFromJsonFile('package.json', 'devDependencies.vue', true)
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error removing \'vue\' devDependency:\n', error.message)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (hasJsonKey('package.json', 'devDependencies.vue-router')) {
|
|
85
|
+
try {
|
|
86
|
+
await removeFromJsonFile('package.json', 'devDependencies.vue-router', true)
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Error removing \'vue-router\' devDependency:\n', error.message)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 2) modify nuxt.config.ts
|
|
94
|
+
try {
|
|
95
|
+
await updateConfigFile('nuxt.config.ts', {
|
|
96
|
+
extends: [
|
|
97
|
+
'nuxt-spec',
|
|
98
|
+
],
|
|
99
|
+
}, isAutoRun, 'This will add \'nuxt-spec\' module to your \'nuxt.config.ts\'. Continue?')
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Error updating \'nuxt.config.ts\':\n', error.message)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 3) `pnpm-workspace.yaml` file (only if pnpm is used)
|
|
105
|
+
if (packageManager === 'pnpm') {
|
|
106
|
+
try {
|
|
107
|
+
if (pathExists('pnpm-workspace.yaml')) {
|
|
108
|
+
await updateTextFile('pnpm-workspace.yaml', ['shamefully-hoist=true'], isAutoRun, 'This will adjust \'pnpm-workspace.yaml\' file in your project. Continue?')
|
|
109
|
+
} else {
|
|
110
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0/config/templates/pnpm-workspace.yaml.template',
|
|
111
|
+
'pnpm-workspace.yaml', isAutoRun, 'This will add \'pnpm-workspace.yaml\' file for your project. Continue?')
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error('Error setting up \'pnpm-workspace.yaml\':\n', error.message)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 4) create vitest.config.ts
|
|
119
|
+
try {
|
|
120
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0/config/templates/vitest.config.ts.template',
|
|
121
|
+
'vitest.config.ts', isAutoRun, 'This will create a new \'vitest.config.ts\' file for your project. Continue?')
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error('Error setting up \'vitest.config.ts\':\n', error.message)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 5) modify package.json
|
|
127
|
+
|
|
128
|
+
// add test scripts
|
|
129
|
+
try {
|
|
130
|
+
await updateJsonFile('package.json', 'scripts', {
|
|
131
|
+
'test': 'vitest run',
|
|
132
|
+
'test-u': 'vitest run -u',
|
|
133
|
+
'test-i': 'vitest',
|
|
134
|
+
}, isAutoRun, 'This will adjust the test-related commands in your \'package.json\'. Continue?')
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error('Error adjusting scripts in \'package.json\':\n', error.message)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// add pnpm approved build scripts
|
|
140
|
+
if (packageManager === 'pnpm') {
|
|
141
|
+
try {
|
|
142
|
+
await updateJsonFile('package.json', 'pnpm', {
|
|
143
|
+
onlyBuiltDependencies: [
|
|
144
|
+
'@parcel/watcher',
|
|
145
|
+
'esbuild',
|
|
146
|
+
'unrs-resolver',
|
|
147
|
+
],
|
|
148
|
+
}, isAutoRun, 'This will adjust pnpm approved build scripts in your \'package.json\'. Continue?')
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error('Error adjusting pnpm approved build scripts in \'package.json\':\n', error.message)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 6) create sample test files
|
|
155
|
+
const createSampleTests = isAutoRun || await promptUser('Do you want to create sample tests in \'/test\' folder?')
|
|
156
|
+
if (createSampleTests) {
|
|
157
|
+
try {
|
|
158
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0/test/browser/vitest-browser.test.ts',
|
|
159
|
+
'test/browser/vitest-browser.test.ts', true)
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('Error setting up \'vitest-browser.test.ts\':\n', error.message)
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0/test/e2e/nuxt-e2e.test.ts',
|
|
165
|
+
'test/e2e/nuxt-e2e.test.ts', true)
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error('Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0/test/e2e/nuxt-visual.test.ts',
|
|
171
|
+
'test/e2e/nuxt-visual.test.ts', true)
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error('Error setting up \'nuxt-visual.test.ts\':\n', error.message)
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0/test/nuxt/nuxt-unit.test.ts',
|
|
177
|
+
'test/nuxt/nuxt-unit.test.ts', true)
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error('Error setting up \'nuxt-unit.test.ts\':\n', error.message)
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.2.0/test/unit/vitest-unit.test.ts',
|
|
183
|
+
'test/unit/vitest-unit.test.ts', true)
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error('Error setting up \'vitest-unit.test.ts\':\n', error.message)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 7) clear node_modules and lock file(s)
|
|
190
|
+
const prepareForReinstall = isAutoRun || await promptUser('Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?')
|
|
191
|
+
if (prepareForReinstall) {
|
|
192
|
+
if (pathExists('node_modules')) {
|
|
193
|
+
try {
|
|
194
|
+
await deletePath('node_modules', true)
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error('Error deleting \'node_modules\':\n', error.message)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (pathExists('package-lock.json')) {
|
|
200
|
+
try {
|
|
201
|
+
await deletePath('package-lock.json', true)
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.error('Error deleting \'package-lock.json\':\n', error.message)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (pathExists('pnpm-lock.yaml')) {
|
|
207
|
+
try {
|
|
208
|
+
await deletePath('pnpm-lock.yaml', true)
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error('Error deleting \'pnpm-lock.yaml\':\n', error.message)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (pathExists('yarn.lock')) {
|
|
214
|
+
try {
|
|
215
|
+
await deletePath('yarn.lock', true)
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.error('Error deleting \'yarn.lock\':\n', error.message)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (pathExists('bun.lockb')) {
|
|
221
|
+
try {
|
|
222
|
+
await deletePath('bun.lockb', true)
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error('Error deleting \'bun.lockb\':\n', error.message)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (pathExists('deno.lock')) {
|
|
228
|
+
try {
|
|
229
|
+
await deletePath('deno.lock', true)
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error('Error deleting \'deno.lock\':\n', error.message)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 7) inform user
|
|
237
|
+
showMessage('')
|
|
238
|
+
showMessage('NUXT SPEC SETUP COMPLETE', 2)
|
|
239
|
+
showMessage(`Proceed with \`${packageManager} install\` to get started.`)
|
|
240
|
+
|
|
241
|
+
// force exit to prevent #20
|
|
242
|
+
process.exit(0)
|
|
243
|
+
}
|
package/config/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { UserConfig } from 'vite'
|
|
2
|
-
import type { TestUserConfig } from 'vitest/config'
|
|
3
|
-
|
|
4
|
-
type ExtendedUserConfig = UserConfig & {
|
|
5
|
-
test?: TestUserConfig
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Prepare Vitest configuration object - user config merged with nuxt-spec defaults
|
|
10
|
-
* @param userVitestConfig - custom Vitest config passed from the user
|
|
11
|
-
* @param projects - can be used to suspend the default inclusion of "projects" in Vitest config
|
|
12
|
-
* @returns Promise resolving to defu-merged Vitest configuration
|
|
13
|
-
*/
|
|
14
|
-
export declare function loadVitestConfig(
|
|
15
|
-
userVitestConfig: ExtendedUserConfig,
|
|
16
|
-
projects?: boolean,
|
|
17
|
-
): Promise<ExtendedUserConfig>
|
|
1
|
+
import type { UserConfig } from 'vite'
|
|
2
|
+
import type { TestUserConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
type ExtendedUserConfig = UserConfig & {
|
|
5
|
+
test?: TestUserConfig
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Prepare Vitest configuration object - user config merged with nuxt-spec defaults
|
|
10
|
+
* @param userVitestConfig - custom Vitest config passed from the user
|
|
11
|
+
* @param projects - can be used to suspend the default inclusion of "projects" in Vitest config
|
|
12
|
+
* @returns Promise resolving to defu-merged Vitest configuration
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadVitestConfig(
|
|
15
|
+
userVitestConfig: ExtendedUserConfig,
|
|
16
|
+
projects?: boolean,
|
|
17
|
+
): Promise<ExtendedUserConfig>
|