nuxt-spec 0.3.4 → 0.4.0-alpha.1

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.
Files changed (39) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +13 -13
  3. package/app/app.vue +10 -10
  4. package/app/components/NuxtSpecApiTestComponent.vue +24 -24
  5. package/app/components/NuxtSpecTestComponent.vue +9 -9
  6. package/app/components/index.d.ts +7 -7
  7. package/app/components/index.ts +2 -2
  8. package/app/utils/vitest-utils.ts +5 -5
  9. package/bin/_internal/prepublish-check.js +16 -16
  10. package/bin/cli.js +44 -44
  11. package/bin/helpers/commands.js +82 -82
  12. package/bin/setup.js +366 -287
  13. package/bin/update.js +94 -94
  14. package/config/index.d.ts +36 -33
  15. package/config/index.mjs +140 -132
  16. package/config/report/report-entry.html +6 -0
  17. package/config/report/report-head.html +34 -0
  18. package/{utils/screenshot/report-entry.html → config/report/report-screenshot.html} +8 -8
  19. package/config/report/report-tail.html +4 -0
  20. package/config/templates/pnpm-workspace.yaml.template +19 -19
  21. package/config/templates/vitest.config.ts.template +5 -5
  22. package/config/utils/merge.mjs +43 -43
  23. package/config/utils/options.d.mts +59 -0
  24. package/config/utils/options.mjs +116 -0
  25. package/config/utils/reporter.mjs +409 -0
  26. package/config/utils/warnings.mjs +38 -33
  27. package/modules/spec-options.ts +23 -0
  28. package/nuxt.config.ts +20 -24
  29. package/package.json +33 -31
  30. package/utils/e2e.ts +131 -131
  31. package/utils/helpers/check-params.ts +44 -41
  32. package/utils/helpers/location-hint.ts +30 -30
  33. package/utils/helpers/screenshot-utils.ts +27 -0
  34. package/utils/index.ts +12 -12
  35. package/utils/playwright.ts +28 -20
  36. package/utils/screenshot.ts +201 -172
  37. package/utils/screenshot/report-head.html +0 -24
  38. package/utils/screenshot/report-tail.html +0 -4
  39. package/utils/screenshot/report-utils.ts +0 -236
package/bin/setup.js CHANGED
@@ -1,287 +1,366 @@
1
- #!/usr/bin/env node
2
-
3
- import { execSync } from 'node:child_process'
4
- import {
5
- createFileFromWebTemplate, deletePath, hasJsonKey,
6
- pathExists, promptUser, removeFromJsonFile, showMessage,
7
- updateConfigFile, updateJsonFile, updateTextFile,
8
- } from 'elrh-cosca'
9
- import {
10
- getPlaywrightInstallCmd, getPrepareCmd,
11
- } from './helpers/commands.js'
12
-
13
- const TARGET_VERSION = '0.3.4'
14
-
15
- /**
16
- * CLI tool to scaffold necessary adjustments in project folder.
17
- *
18
- * It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
19
- *
20
- * Then it:
21
- * 1) adds `nuxt-spec` into `package.json` dependencies and removes `nuxt`, `vue` and `vue-router` if present
22
- * 2) adds `extends: ['nuxt-spec']` to `nuxt.config.ts`
23
- * 3) creates/updates `pnpm-workspace.yaml` file (only if pnpm is used)
24
- * 4) creates default `vitest.config.ts` file
25
- * 5) creates default `.nuxtrc` file
26
- * 6) adds test-related scripts in `package.json`
27
- * 7) creates sample test files
28
- * 8) clear node_modules and lock file(s)
29
- * 9) run install command
30
- * 10) run Nuxt prepare command to generate types and auto-imports
31
- * 11) run Playwright setup command
32
- *
33
- * @param {boolean} autoRun - Whether to run the setup automatically without any prompts (defaults to false).
34
- * @param {string} [packageManager] - Package manager to be used (`npm`, `pnpm`, `yarn`, `bun` or `deno`).
35
- */
36
- export async function specSetup(autoRun = false, packageManager) {
37
- showMessage('NUXT SPEC SETUP')
38
- showMessage('This CLI tool will help you include Nuxt Spec in your project.')
39
- showMessage('Refer to the documentation for more information.', 2)
40
-
41
- const isAutoRun = autoRun || await promptUser('Do you want to set everything up automatically (no more prompts)?')
42
- showMessage('')
43
-
44
- // 1) manage dependencies in package.json
45
-
46
- // add nuxt-spec
47
- try {
48
- await updateJsonFile('package.json', 'dependencies', {
49
- ['nuxt-spec']: TARGET_VERSION,
50
- }, isAutoRun, `This will add 'nuxt-spec' dependency to your 'package.json'. Continue?`)
51
- } catch (error) {
52
- console.error(`Error adding 'nuxt-spec' dependency:\n`, error.message)
53
- }
54
-
55
- // remove now obsolete nuxt, vue and vue-router
56
- 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?`)
57
- if (removeDeps) {
58
- if (hasJsonKey('package.json', 'dependencies.nuxt')) {
59
- try {
60
- await removeFromJsonFile('package.json', 'dependencies.nuxt', true)
61
- } catch (error) {
62
- console.error('Error removing \'nuxt\' dependency:\n', error.message)
63
- }
64
- }
65
- if (hasJsonKey('package.json', 'dependencies.vue')) {
66
- try {
67
- await removeFromJsonFile('package.json', 'dependencies.vue', true)
68
- } catch (error) {
69
- console.error('Error removing \'vue\' dependency:\n', error.message)
70
- }
71
- }
72
- if (hasJsonKey('package.json', 'dependencies.vue-router')) {
73
- try {
74
- await removeFromJsonFile('package.json', 'dependencies.vue-router', true)
75
- } catch (error) {
76
- console.error('Error removing \'vue-router\' dependency:\n', error.message)
77
- }
78
- }
79
- if (hasJsonKey('package.json', 'devDependencies.nuxt')) {
80
- try {
81
- await removeFromJsonFile('package.json', 'devDependencies.nuxt', true)
82
- } catch (error) {
83
- console.error('Error removing \'nuxt\' devDependency:\n', error.message)
84
- }
85
- }
86
- if (hasJsonKey('package.json', 'devDependencies.vue')) {
87
- try {
88
- await removeFromJsonFile('package.json', 'devDependencies.vue', true)
89
- } catch (error) {
90
- console.error('Error removing \'vue\' devDependency:\n', error.message)
91
- }
92
- }
93
- if (hasJsonKey('package.json', 'devDependencies.vue-router')) {
94
- try {
95
- await removeFromJsonFile('package.json', 'devDependencies.vue-router', true)
96
- } catch (error) {
97
- console.error('Error removing \'vue-router\' devDependency:\n', error.message)
98
- }
99
- }
100
- }
101
-
102
- // 2) modify nuxt.config.ts
103
- try {
104
- await updateConfigFile('nuxt.config.ts', {
105
- extends: [
106
- 'nuxt-spec',
107
- ],
108
- }, isAutoRun, `This will add 'nuxt-spec' module to your 'nuxt.config.ts'. Continue?`)
109
- } catch (error) {
110
- console.error('Error updating \'nuxt.config.ts\':\n', error.message)
111
- }
112
-
113
- // 3) `pnpm-workspace.yaml` file (only if pnpm is used)
114
- if (packageManager === 'pnpm') {
115
- try {
116
- if (pathExists('pnpm-workspace.yaml')) {
117
- await updateTextFile('pnpm-workspace.yaml', ['shamefully-hoist: true'], isAutoRun, 'This will adjust \'pnpm-workspace.yaml\' file in your project. Continue?')
118
- } else {
119
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/config/templates/pnpm-workspace.yaml.template`,
120
- 'pnpm-workspace.yaml', isAutoRun, 'This will add \'pnpm-workspace.yaml\' file for your project. Continue?')
121
- }
122
- } catch (error) {
123
- console.error('Error setting up \'pnpm-workspace.yaml\':\n', error.message)
124
- }
125
- }
126
-
127
- // 4) create vitest.config.ts
128
- try {
129
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/config/templates/vitest.config.ts.template`,
130
- 'vitest.config.ts', isAutoRun, 'This will create a new \'vitest.config.ts\' file for your project. Continue?')
131
- } catch (error) {
132
- console.error('Error setting up \'vitest.config.ts\':\n', error.message)
133
- }
134
-
135
- // 5) create .nuxtrc to prevent @nuxt/test-utils setup from running automatically on first start
136
- if (!pathExists('.nuxtrc')) {
137
- try {
138
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/.nuxtrc`, '.nuxtrc', isAutoRun, 'This will create a \'.nuxtrc\' file to prevent @nuxt/test-utils setup from running automatically when dev server starts. Continue?')
139
- } catch (error) {
140
- console.error('Error creating \'.nuxtrc\':\n', error.message)
141
- }
142
- }
143
-
144
- // 6) modify package.json with test scripts
145
- try {
146
- await updateJsonFile('package.json', 'scripts', {
147
- 'test': 'vitest run',
148
- 'test-u': 'vitest run -u',
149
- 'test-i': 'vitest',
150
- }, isAutoRun, 'This will adjust the test-related commands in your \'package.json\'. Continue?')
151
- } catch (error) {
152
- console.error('Error adjusting scripts in \'package.json\':\n', error.message)
153
- }
154
-
155
- // 7) create sample test files
156
- const createSampleTests = isAutoRun || await promptUser('Do you want to create sample tests in \'/test\' folder?')
157
- if (createSampleTests) {
158
- try {
159
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/browser/vitest-browser.test.ts`,
160
- 'test/browser/vitest-browser.test.ts', true)
161
- } catch (error) {
162
- console.error('Error setting up \'vitest-browser.test.ts\':\n', error.message)
163
- }
164
- try {
165
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/nuxt-e2e.test.ts`,
166
- 'test/e2e/nuxt-e2e.test.ts', true)
167
- } catch (error) {
168
- console.error('Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
169
- }
170
- try {
171
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/nuxt-visual.test.ts`,
172
- 'test/e2e/nuxt-visual.test.ts', true)
173
- } catch (error) {
174
- console.error('Error setting up \'nuxt-visual.test.ts\':\n', error.message)
175
- }
176
- try {
177
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/nuxt/nuxt-unit.test.ts`,
178
- 'test/nuxt/nuxt-unit.test.ts', true)
179
- } catch (error) {
180
- console.error('Error setting up \'nuxt-unit.test.ts\':\n', error.message)
181
- }
182
- try {
183
- await createFileFromWebTemplate(`https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/unit/vitest-unit.test.ts`,
184
- 'test/unit/vitest-unit.test.ts', true)
185
- } catch (error) {
186
- console.error('Error setting up \'vitest-unit.test.ts\':\n', error.message)
187
- }
188
- }
189
-
190
- // 8) clear node_modules and lock file(s)
191
- const prepareForReinstall = isAutoRun || await promptUser('Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?')
192
- if (prepareForReinstall) {
193
- if (pathExists('node_modules')) {
194
- try {
195
- await deletePath('node_modules', true)
196
- } catch (error) {
197
- console.error('Error deleting \'node_modules\':\n', error.message)
198
- }
199
- }
200
- if (pathExists('package-lock.json')) {
201
- try {
202
- await deletePath('package-lock.json', true)
203
- } catch (error) {
204
- console.error('Error deleting \'package-lock.json\':\n', error.message)
205
- }
206
- }
207
- if (pathExists('pnpm-lock.yaml')) {
208
- try {
209
- await deletePath('pnpm-lock.yaml', true)
210
- } catch (error) {
211
- console.error('Error deleting \'pnpm-lock.yaml\':\n', error.message)
212
- }
213
- }
214
- if (pathExists('yarn.lock')) {
215
- try {
216
- await deletePath('yarn.lock', true)
217
- } catch (error) {
218
- console.error('Error deleting \'yarn.lock\':\n', error.message)
219
- }
220
- }
221
- if (pathExists('bun.lockb')) {
222
- try {
223
- await deletePath('bun.lockb', true)
224
- } catch (error) {
225
- console.error('Error deleting \'bun.lockb\':\n', error.message)
226
- }
227
- }
228
- if (pathExists('deno.lock')) {
229
- try {
230
- await deletePath('deno.lock', true)
231
- } catch (error) {
232
- console.error('Error deleting \'deno.lock\':\n', error.message)
233
- }
234
- }
235
- }
236
-
237
- // 9) run install command
238
- const runInstall = isAutoRun || await promptUser(`Fresh \`${packageManager} install\` is required. Do you want to run it now?`)
239
- if (runInstall) {
240
- try {
241
- showMessage(`Running \`${packageManager} install\`...`)
242
- execSync(`${packageManager} install`, { stdio: 'inherit' })
243
- } catch (error) {
244
- console.error(`Error running \`${packageManager} install\`:\n`, error.message)
245
- }
246
- }
247
-
248
- // 10) run Nuxt prepare command to generate types and auto-imports
249
- const prepareCmd = getPrepareCmd(packageManager)
250
- const runPrepare = isAutoRun || await promptUser(`Nuxt needs to generate types and auto-imports before the project is fully usable. Do you want to run \`${prepareCmd}\` now?`)
251
- if (runPrepare) {
252
- try {
253
- showMessage(`Running \`${prepareCmd}\`...`)
254
- execSync(prepareCmd, { stdio: 'inherit' })
255
- } catch (error) {
256
- console.error(`Error running \`${prepareCmd}\`:\n`, error.message)
257
- }
258
- }
259
-
260
- // 11) run Playwright browser install command
261
- const playwrightInstallCmd = getPlaywrightInstallCmd(packageManager)
262
- const runPlaywrightInstall = isAutoRun || await promptUser(`Playwright browser runtimes might need to be installed locally for e2e tests. Do you want to run \`${playwrightInstallCmd}\` now?`)
263
- if (runPlaywrightInstall) {
264
- try {
265
- showMessage(`Running \`${playwrightInstallCmd}\`...`)
266
- execSync(playwrightInstallCmd, { stdio: 'inherit' })
267
- } catch (error) {
268
- console.error(`Error running \`${playwrightInstallCmd}\`:\n`, error.message)
269
- }
270
- }
271
-
272
- // 12) inform user
273
- showMessage('')
274
- showMessage('NUXT SPEC SETUP COMPLETE', 2)
275
- if (!runInstall) {
276
- showMessage(`Proceed with \`${packageManager} install\` to install dependencies.`)
277
- }
278
- if (!runPrepare) {
279
- showMessage(`Run \`${prepareCmd}\` to generate the required Nuxt types and auto-imports.`)
280
- }
281
- if (!runPlaywrightInstall) {
282
- showMessage(`Run \`${playwrightInstallCmd}\` to setup the Playwright browser runtimes for e2e tests.`)
283
- }
284
-
285
- // force exit to prevent #20
286
- process.exit(0)
287
- }
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync } from 'node:child_process'
4
+ import { readFileSync } from 'node:fs'
5
+ import {
6
+ createFileFromWebTemplate, deletePath,
7
+ pathExists, promptUser, removeFromJsonFile, showMessage,
8
+ updateConfigFile, updateJsonFile, updateTextFile,
9
+ } from 'elrh-cosca'
10
+ import {
11
+ getPlaywrightInstallCmd, getPrepareCmd,
12
+ } from './helpers/commands.js'
13
+
14
+ const TARGET_VERSION = '0.4.0-alpha.1'
15
+
16
+ /**
17
+ * CLI tool to scaffold necessary adjustments in project folder.
18
+ *
19
+ * It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
20
+ *
21
+ * Then it:
22
+ * 1) adds `nuxt-spec` into `package.json` dependencies and removes `nuxt`, `vue` and `vue-router` if present
23
+ * 2) adds `extends: ['nuxt-spec']` to `nuxt.config.ts`
24
+ * 3) creates/updates `pnpm-workspace.yaml` file (only if pnpm is used)
25
+ * 4) creates default `vitest.config.ts` file
26
+ * 5) creates default `.nuxtrc` file
27
+ * 6) adds test-related scripts in `package.json`
28
+ * 7) creates sample test files
29
+ * 8) adds nuxt-spec related entries to `.gitignore`
30
+ * 9) clear node_modules and lock file(s)
31
+ * 10) run install command
32
+ * 11) run Nuxt prepare command to generate types and auto-imports
33
+ * 12) run Playwright setup command
34
+ *
35
+ * @param {boolean} autoRun - Whether to run the setup automatically without any prompts (defaults to false).
36
+ * @param {string} [packageManager] - Package manager to be used (`npm`, `pnpm`, `yarn`, `bun` or `deno`).
37
+ */
38
+ export async function specSetup(autoRun = false, packageManager) {
39
+ showMessage({ message: 'NUXT SPEC SETUP' })
40
+ showMessage({ message: 'This CLI tool will help you include Nuxt Spec in your project.' })
41
+ showMessage({ message: 'Refer to the documentation for more information.', linesAfter: 2 })
42
+
43
+ const isAutoRun = autoRun || await promptUser({ question: '[Nuxt Spec] Do you want to set everything up automatically (no more prompts)?' })
44
+ showMessage({ message: '' })
45
+
46
+ // 1) manage dependencies in package.json
47
+
48
+ // add nuxt-spec
49
+ try {
50
+ await updateJsonFile({
51
+ targetFile: 'package.json',
52
+ jsonKey: 'dependencies',
53
+ patch: {
54
+ ['nuxt-spec']: TARGET_VERSION,
55
+ },
56
+ force: isAutoRun,
57
+ prompt: `[Nuxt Spec] This will add 'nuxt-spec' dependency to your 'package.json'. Continue?`,
58
+ })
59
+ } catch (error) {
60
+ console.error(`[Nuxt Spec] Error adding 'nuxt-spec' dependency:\n`, error.message)
61
+ }
62
+
63
+ // remove now obsolete nuxt, vue and vue-router
64
+ const removeDeps = isAutoRun || await promptUser({ question: `[Nuxt Spec] 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?` })
65
+ if (removeDeps) {
66
+ try {
67
+ await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'dependencies.nuxt', force: true })
68
+ } catch (error) {
69
+ console.error('[Nuxt Spec] Error removing \'nuxt\' dependency:\n', error.message)
70
+ }
71
+ try {
72
+ await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'dependencies.vue', force: true })
73
+ } catch (error) {
74
+ console.error('[Nuxt Spec] Error removing \'vue\' dependency:\n', error.message)
75
+ }
76
+ try {
77
+ await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'dependencies.vue-router', force: true })
78
+ } catch (error) {
79
+ console.error('[Nuxt Spec] Error removing \'vue-router\' dependency:\n', error.message)
80
+ }
81
+ try {
82
+ await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'devDependencies.nuxt', force: true })
83
+ } catch (error) {
84
+ console.error('[Nuxt Spec] Error removing \'nuxt\' devDependency:\n', error.message)
85
+ }
86
+ try {
87
+ await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'devDependencies.vue', force: true })
88
+ } catch (error) {
89
+ console.error('[Nuxt Spec] Error removing \'vue\' devDependency:\n', error.message)
90
+ }
91
+ try {
92
+ await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'devDependencies.vue-router', force: true })
93
+ } catch (error) {
94
+ console.error('[Nuxt Spec] Error removing \'vue-router\' devDependency:\n', error.message)
95
+ }
96
+ }
97
+
98
+ // 2) modify nuxt.config.ts
99
+ try {
100
+ await updateConfigFile({
101
+ targetFile: 'nuxt.config.ts',
102
+ newConfig: {
103
+ extends: [
104
+ 'nuxt-spec',
105
+ ],
106
+ },
107
+ force: isAutoRun,
108
+ prompt: `[Nuxt Spec] This will add 'nuxt-spec' module to your 'nuxt.config.ts'. Continue?`,
109
+ })
110
+ } catch (error) {
111
+ console.error('[Nuxt Spec] Error updating \'nuxt.config.ts\':\n', error.message)
112
+ }
113
+
114
+ // 3) `pnpm-workspace.yaml` file (only if pnpm is used)
115
+ if (packageManager === 'pnpm') {
116
+ try {
117
+ if (pathExists({ targetPath: 'pnpm-workspace.yaml' })) {
118
+ await updateTextFile({
119
+ targetFile: 'pnpm-workspace.yaml',
120
+ rowsToAdd: ['shamefullyHoist: true'],
121
+ force: isAutoRun,
122
+ prompt: '[Nuxt Spec] This will adjust \'pnpm-workspace.yaml\' file in your project. Continue?',
123
+ })
124
+ } else {
125
+ await createFileFromWebTemplate({
126
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/config/templates/pnpm-workspace.yaml.template`,
127
+ targetFile: 'pnpm-workspace.yaml',
128
+ force: isAutoRun,
129
+ prompt: '[Nuxt Spec] This will add \'pnpm-workspace.yaml\' file for your project. Continue?',
130
+ })
131
+ }
132
+ } catch (error) {
133
+ console.error('[Nuxt Spec] Error setting up \'pnpm-workspace.yaml\':\n', error.message)
134
+ }
135
+ }
136
+
137
+ // 4) create vitest.config.ts
138
+ try {
139
+ await createFileFromWebTemplate({
140
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/config/templates/vitest.config.ts.template`,
141
+ targetFile: 'vitest.config.ts',
142
+ force: isAutoRun,
143
+ prompt: '[Nuxt Spec] This will create a new \'vitest.config.ts\' file for your project. Continue?',
144
+ })
145
+ } catch (error) {
146
+ console.error('[Nuxt Spec] Error setting up \'vitest.config.ts\':\n', error.message)
147
+ }
148
+
149
+ // 5) create .nuxtrc to prevent @nuxt/test-utils setup from running automatically on first start
150
+ if (!pathExists({ targetPath: '.nuxtrc' })) {
151
+ try {
152
+ await createFileFromWebTemplate({
153
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/.nuxtrc`,
154
+ targetFile: '.nuxtrc',
155
+ force: isAutoRun,
156
+ prompt: '[Nuxt Spec] This will create a \'.nuxtrc\' file to prevent @nuxt/test-utils setup from running automatically when dev server starts. Continue?',
157
+ })
158
+ } catch (error) {
159
+ console.error('[Nuxt Spec] Error creating \'.nuxtrc\':\n', error.message)
160
+ }
161
+ }
162
+
163
+ // 6) modify package.json with test scripts
164
+ try {
165
+ await updateJsonFile({
166
+ targetFile: 'package.json',
167
+ jsonKey: 'scripts',
168
+ patch: {
169
+ 'test': 'vitest run',
170
+ 'test-u': 'vitest run -u',
171
+ 'test-i': 'vitest',
172
+ },
173
+ force: isAutoRun,
174
+ prompt: '[Nuxt Spec] This will adjust the test-related commands in your \'package.json\'. Continue?',
175
+ })
176
+ } catch (error) {
177
+ console.error('[Nuxt Spec] Error adjusting scripts in \'package.json\':\n', error.message)
178
+ }
179
+
180
+ // 7) create sample test files
181
+ const createSampleTests = isAutoRun || await promptUser({ question: '[Nuxt Spec] Do you want to create sample tests in \'/test\' folder?' })
182
+ if (createSampleTests) {
183
+ try {
184
+ await createFileFromWebTemplate({
185
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/browser/vitest-browser.test.ts`,
186
+ targetFile: 'test/browser/vitest-browser.test.ts',
187
+ force: true,
188
+ })
189
+ } catch (error) {
190
+ console.error('[Nuxt Spec] Error setting up \'vitest-browser.test.ts\':\n', error.message)
191
+ }
192
+ try {
193
+ await createFileFromWebTemplate({
194
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/nuxt-e2e.test.ts`,
195
+ targetFile: 'test/e2e/nuxt-e2e.test.ts',
196
+ force: true,
197
+ })
198
+ } catch (error) {
199
+ console.error('[Nuxt Spec] Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
200
+ }
201
+ try {
202
+ await createFileFromWebTemplate({
203
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/nuxt-visual.test.ts`,
204
+ targetFile: 'test/e2e/nuxt-visual.test.ts',
205
+ force: true,
206
+ })
207
+ } catch (error) {
208
+ console.error('[Nuxt Spec] Error setting up \'nuxt-visual.test.ts\':\n', error.message)
209
+ }
210
+ // pre-existing baseline ensures the sample "wrong" visual test fails as intended
211
+ try {
212
+ await createFileFromWebTemplate({
213
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/__baseline__/wrong.png`,
214
+ targetFile: 'test/e2e/__baseline__/wrong.png',
215
+ force: true,
216
+ })
217
+ } catch (error) {
218
+ console.error('[Nuxt Spec] Error setting up \'wrong.png\':\n', error.message)
219
+ }
220
+ try {
221
+ await createFileFromWebTemplate({
222
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/nuxt/nuxt-unit.test.ts`,
223
+ targetFile: 'test/nuxt/nuxt-unit.test.ts',
224
+ force: true,
225
+ })
226
+ } catch (error) {
227
+ console.error('[Nuxt Spec] Error setting up \'nuxt-unit.test.ts\':\n', error.message)
228
+ }
229
+ try {
230
+ await createFileFromWebTemplate({
231
+ url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/unit/vitest-unit.test.ts`,
232
+ targetFile: 'test/unit/vitest-unit.test.ts',
233
+ force: true,
234
+ })
235
+ } catch (error) {
236
+ console.error('[Nuxt Spec] Error setting up \'vitest-unit.test.ts\':\n', error.message)
237
+ }
238
+ }
239
+
240
+ // 8) add nuxt-spec related entries to .gitignore
241
+ try {
242
+ const gitignoreEntries = [
243
+ ['# vitest output folder', '.vitest'],
244
+ ['# nuxt-spec screenshots folder', '__current__'],
245
+ ['# nuxt-spec HTML test reports folder', '__reports__'],
246
+ ]
247
+ // if .gitignore exists, we rather check for duplicates
248
+ const gitignoreExists = pathExists({ targetPath: '.gitignore' })
249
+ const gitignoreRows = gitignoreExists ? readFileSync('.gitignore', 'utf8').split(/\r?\n/) : []
250
+ const rowsToAdd = gitignoreEntries
251
+ .filter(([, entry]) => !gitignoreRows.includes(entry))
252
+ .flatMap(([comment, entry]) => ['', comment, entry])
253
+ .slice(gitignoreExists ? 0 : 1)
254
+ //
255
+ if (rowsToAdd.length > 0) {
256
+ await updateTextFile({
257
+ targetFile: '.gitignore',
258
+ rowsToAdd,
259
+ allowDuplicates: true,
260
+ createMissing: true,
261
+ force: isAutoRun,
262
+ prompt: '[Nuxt Spec] This will add nuxt-spec related entries to your \'.gitignore\' file. Continue?',
263
+ })
264
+ }
265
+ } catch (error) {
266
+ console.error('[Nuxt Spec] Error updating \'.gitignore\':\n', error.message)
267
+ }
268
+
269
+ // 9) clear node_modules and lock file(s)
270
+ const prepareForReinstall = isAutoRun || await promptUser({ question: '[Nuxt Spec] Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?' })
271
+ if (prepareForReinstall) {
272
+ if (pathExists({ targetPath: 'node_modules' })) {
273
+ try {
274
+ await deletePath({ targetPath: 'node_modules', force: true })
275
+ } catch (error) {
276
+ console.error('[Nuxt Spec] Error deleting \'node_modules\':\n', error.message)
277
+ }
278
+ }
279
+ if (pathExists({ targetPath: 'package-lock.json' })) {
280
+ try {
281
+ await deletePath({ targetPath: 'package-lock.json', force: true })
282
+ } catch (error) {
283
+ console.error('[Nuxt Spec] Error deleting \'package-lock.json\':\n', error.message)
284
+ }
285
+ }
286
+ if (pathExists({ targetPath: 'pnpm-lock.yaml' })) {
287
+ try {
288
+ await deletePath({ targetPath: 'pnpm-lock.yaml', force: true })
289
+ } catch (error) {
290
+ console.error('[Nuxt Spec] Error deleting \'pnpm-lock.yaml\':\n', error.message)
291
+ }
292
+ }
293
+ if (pathExists({ targetPath: 'yarn.lock' })) {
294
+ try {
295
+ await deletePath({ targetPath: 'yarn.lock', force: true })
296
+ } catch (error) {
297
+ console.error('[Nuxt Spec] Error deleting \'yarn.lock\':\n', error.message)
298
+ }
299
+ }
300
+ if (pathExists({ targetPath: 'bun.lockb' })) {
301
+ try {
302
+ await deletePath({ targetPath: 'bun.lockb', force: true })
303
+ } catch (error) {
304
+ console.error('[Nuxt Spec] Error deleting \'bun.lockb\':\n', error.message)
305
+ }
306
+ }
307
+ if (pathExists({ targetPath: 'deno.lock' })) {
308
+ try {
309
+ await deletePath({ targetPath: 'deno.lock', force: true })
310
+ } catch (error) {
311
+ console.error('[Nuxt Spec] Error deleting \'deno.lock\':\n', error.message)
312
+ }
313
+ }
314
+ }
315
+
316
+ // 10) run install command
317
+ const runInstall = isAutoRun || await promptUser({ question: `[Nuxt Spec] Fresh \`${packageManager} install\` is required. Do you want to run it now?` })
318
+ if (runInstall) {
319
+ try {
320
+ showMessage({ message: `Running \`${packageManager} install\`...` })
321
+ execSync(`${packageManager} install`, { stdio: 'inherit' })
322
+ } catch (error) {
323
+ console.error(`[Nuxt Spec] Error running \`${packageManager} install\`:\n`, error.message)
324
+ }
325
+ }
326
+
327
+ // 11) run Nuxt prepare command to generate types and auto-imports
328
+ const prepareCmd = getPrepareCmd(packageManager)
329
+ const runPrepare = isAutoRun || await promptUser({ question: `[Nuxt Spec] Nuxt needs to generate types and auto-imports before the project is fully usable. Do you want to run \`${prepareCmd}\` now?` })
330
+ if (runPrepare) {
331
+ try {
332
+ showMessage({ message: `Running \`${prepareCmd}\`...` })
333
+ execSync(prepareCmd, { stdio: 'inherit' })
334
+ } catch (error) {
335
+ console.error(`[Nuxt Spec] Error running \`${prepareCmd}\`:\n`, error.message)
336
+ }
337
+ }
338
+
339
+ // 12) run Playwright browser install command
340
+ const playwrightInstallCmd = getPlaywrightInstallCmd(packageManager)
341
+ const runPlaywrightInstall = isAutoRun || await promptUser({ question: `[Nuxt Spec] Playwright browser runtimes might need to be installed locally for e2e tests. Do you want to run \`${playwrightInstallCmd}\` now?` })
342
+ if (runPlaywrightInstall) {
343
+ try {
344
+ showMessage({ message: `Running \`${playwrightInstallCmd}\`...` })
345
+ execSync(playwrightInstallCmd, { stdio: 'inherit' })
346
+ } catch (error) {
347
+ console.error(`[Nuxt Spec] Error running \`${playwrightInstallCmd}\`:\n`, error.message)
348
+ }
349
+ }
350
+
351
+ // 13) inform user
352
+ showMessage({ message: '' })
353
+ showMessage({ message: 'NUXT SPEC SETUP COMPLETE', linesAfter: 2 })
354
+ if (!runInstall) {
355
+ showMessage({ message: `Proceed with \`${packageManager} install\` to install dependencies.` })
356
+ }
357
+ if (!runPrepare) {
358
+ showMessage({ message: `Run \`${prepareCmd}\` to generate the required Nuxt types and auto-imports.` })
359
+ }
360
+ if (!runPlaywrightInstall) {
361
+ showMessage({ message: `Run \`${playwrightInstallCmd}\` to setup the Playwright browser runtimes for e2e tests.` })
362
+ }
363
+
364
+ // force exit to prevent #20
365
+ process.exit(0)
366
+ }