nuxt-spec 0.4.0-alpha.1 → 0.4.0-alpha.3

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 (41) 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/config/index.d.ts +36 -36
  10. package/config/index.mjs +147 -140
  11. package/config/report/report-entry.html +6 -6
  12. package/config/report/report-head.html +34 -34
  13. package/config/report/report-screenshot.html +8 -8
  14. package/config/report/report-tail.html +4 -4
  15. package/config/templates/.github/workflows/ci-test-update.yml.template +105 -0
  16. package/config/templates/.github/workflows/ci-test-verify.yml.template +68 -0
  17. package/config/templates/.gitlab/ci/ci-test-update.yml.template +69 -0
  18. package/config/templates/.gitlab/ci/ci-test-verify.yml.template +41 -0
  19. package/config/templates/.gitlab-ci.yml.template +6 -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 -59
  24. package/config/utils/options.mjs +116 -116
  25. package/config/utils/reporter.mjs +409 -409
  26. package/config/utils/warnings.mjs +38 -38
  27. package/modules/spec-options.ts +23 -23
  28. package/nuxt.config.ts +20 -20
  29. package/package.json +23 -25
  30. package/utils/e2e.ts +131 -131
  31. package/utils/helpers/check-params.ts +44 -44
  32. package/utils/helpers/location-hint.ts +30 -30
  33. package/utils/helpers/screenshot-utils.ts +27 -27
  34. package/utils/index.ts +12 -12
  35. package/utils/playwright.ts +28 -28
  36. package/utils/screenshot.ts +201 -201
  37. package/bin/_internal/prepublish-check.js +0 -16
  38. package/bin/cli.js +0 -44
  39. package/bin/helpers/commands.js +0 -82
  40. package/bin/setup.js +0 -366
  41. package/bin/update.js +0 -94
package/bin/cli.js DELETED
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { getCmd, resolvePackageManager } from './helpers/commands.js'
4
-
5
- /**
6
- * CLI tool to scaffold necessary adjustments in project folder.
7
- *
8
- * Allows `setup` or `update` to be passed as parameter.
9
- *
10
- * Second (optional) parameter might be a boolean to indicate auto mode
11
- * (no prompts, force = true) or manual mode (with prompts, force = false).
12
- *
13
- * Third (optional) parameter allows explicitly passing the package manager
14
- * (`npm`, `pnpm`, `yarn`, `bun` or `deno`), bypassing auto-detection.
15
- */
16
-
17
- // get parameters passed by user
18
- const args = process.argv.slice(2);
19
-
20
- // execute actions based on first param
21
- // additional params might be passed into the called functions
22
- (async () => {
23
- let status = 0
24
- try {
25
- const packageManager = resolvePackageManager(args[2])
26
- // CLI args are always strings, so 'false' must be parsed explicitly rather than treated as truthy
27
- const autoRun = args[1] === 'true'
28
- switch (args[0]) {
29
- case 'setup':
30
- await (await import('./setup.js')).specSetup(autoRun, packageManager)
31
- break
32
- case 'update':
33
- await (await import('./update.js')).specUpdate(autoRun, packageManager)
34
- break
35
- default:
36
- console.log(`[Nuxt Spec] Usage: \`${getCmd(packageManager)} setup [true|false] [npm|pnpm|yarn|bun|deno]\` or \`${getCmd(packageManager)} update [true|false] [npm|pnpm|yarn|bun|deno]\``)
37
- status = 1
38
- }
39
- } catch (error) {
40
- console.error('[Nuxt Spec] CLI failed:', error.message)
41
- status = 1
42
- }
43
- process.exit(status)
44
- })()
@@ -1,82 +0,0 @@
1
- import { getPackageManager } from 'elrh-cosca'
2
-
3
- export const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun', 'deno']
4
-
5
- // get the package manager name for usage in commands
6
- // explicit override takes precedence over auto-detection
7
- export function resolvePackageManager(override) {
8
- if (override) {
9
- if (!SUPPORTED_PACKAGE_MANAGERS.includes(override)) {
10
- throw new Error(`Unsupported package manager '${override}'. Use one of: ${SUPPORTED_PACKAGE_MANAGERS.join(', ')}`)
11
- }
12
- return override
13
- }
14
- return getPackageManager()
15
- }
16
-
17
- // use nuxt-spec CLI tool
18
- export function getCmd(packageManager) {
19
- const command = 'nuxt-spec'
20
- switch (packageManager) {
21
- case 'pnpm':
22
- return `pnpx ${command}`
23
- case 'yarn':
24
- return `yarn dlx ${command}`
25
- case 'bun':
26
- return `bunx ${command}`
27
- case 'deno':
28
- return `deno run -A npm:${command}`
29
- default:
30
- return `npx ${command}`
31
- }
32
- }
33
-
34
- // update nuxt-spec
35
- export function getUpdateCmd(packageManager, target) {
36
- switch (packageManager) {
37
- case 'pnpm':
38
- return `pnpm update ${target}`
39
- case 'yarn':
40
- return `yarn up ${target}`
41
- case 'bun':
42
- return `bun update ${target}`
43
- case 'deno':
44
- return `deno add npm:${target}`
45
- default:
46
- return `npm install ${target}`
47
- }
48
- }
49
-
50
- // generate Nuxt types and auto-imports
51
- export function getPrepareCmd(packageManager) {
52
- const command = 'nuxt prepare'
53
- switch (packageManager) {
54
- case 'pnpm':
55
- return `pnpm exec ${command}`
56
- case 'yarn':
57
- return `yarn ${command}`
58
- case 'bun':
59
- return `bunx ${command}`
60
- case 'deno':
61
- return `deno run -A npm:${command}`
62
- default:
63
- return `npx ${command}`
64
- }
65
- }
66
-
67
- // install/update playwright
68
- export function getPlaywrightInstallCmd(packageManager) {
69
- const command = 'playwright install'
70
- switch (packageManager) {
71
- case 'pnpm':
72
- return `pnpm exec ${command}`
73
- case 'yarn':
74
- return `yarn ${command}`
75
- case 'bun':
76
- return `bunx ${command}`
77
- case 'deno':
78
- return `deno run -A npm:${command}`
79
- default:
80
- return `npx ${command}`
81
- }
82
- }
package/bin/setup.js DELETED
@@ -1,366 +0,0 @@
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
- }
package/bin/update.js DELETED
@@ -1,94 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { execSync } from 'node:child_process'
4
- import {
5
- hasJsonKey, promptUser, showMessage,
6
- } from 'elrh-cosca'
7
- import {
8
- getPlaywrightInstallCmd, getPrepareCmd, getUpdateCmd,
9
- } from './helpers/commands.js'
10
-
11
- const TARGET_VERSION = '0.4.0-alpha.1'
12
-
13
- /**
14
- * CLI tool to update existing `nuxt-spec` installation.
15
- *
16
- * It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
17
- *
18
- * Then it:
19
- * 1) verifies `nuxt-spec` is present in `package.json` (fails with a hint to run `setup` otherwise)
20
- * 2) runs the package manager's update command to bump `nuxt-spec` to the latest version
21
- * 3) run the `nuxt prepare` command to regenerate types and auto-imports
22
- * 4) run the `playwright install` command to ensure the Playwright browser runtimes are up to date
23
- *
24
- * @param {boolean} autoRun - Whether to run the update automatically without any prompts (defaults to false).
25
- * @param {string} [packageManager] - Package manager to be used (`npm`, `pnpm`, `yarn`, `bun` or `deno`).
26
- */
27
- export async function specUpdate(autoRun = false, packageManager) {
28
- showMessage({ message: 'NUXT SPEC UPDATE' })
29
- showMessage({ message: 'This CLI tool will help you update Nuxt Spec in your project.' })
30
- showMessage({ message: 'Refer to the documentation for more information.', linesAfter: 2 })
31
-
32
- // fail fast if there is nothing to update
33
- const isInstalled = hasJsonKey({ targetFile: 'package.json', jsonKey: `dependencies.nuxt-spec` })
34
- || hasJsonKey({ targetFile: 'package.json', jsonKey: `devDependencies.nuxt-spec` })
35
- if (!isInstalled) {
36
- console.error(`[Nuxt Spec] 'nuxt-spec' was not found in your 'package.json'. Run the 'setup' command first.`)
37
- process.exit(1)
38
- }
39
-
40
- const isAutoRun = autoRun || await promptUser({ question: '[Nuxt Spec] Do you want to update everything automatically (no more prompts)?' })
41
- showMessage({ message: '' })
42
-
43
- // 1) run 'update nuxt-spec'
44
- const updateCmd = getUpdateCmd(packageManager, `nuxt-spec@${TARGET_VERSION}`)
45
- const runUpdate = isAutoRun || await promptUser({ question: `[Nuxt Spec] This will bump 'nuxt-spec' to version '${TARGET_VERSION}' by running \`${updateCmd}\`. Continue?` })
46
- if (runUpdate) {
47
- try {
48
- showMessage({ message: `Running \`${updateCmd}\`...` })
49
- execSync(updateCmd, { stdio: 'inherit' })
50
- } catch (error) {
51
- console.error(`[Nuxt Spec] Error running \`${updateCmd}\`:\n`, error.message)
52
- }
53
- }
54
-
55
- // 2) run 'nuxt prepare'
56
- const prepareCmd = getPrepareCmd(packageManager)
57
- const runPrepare = isAutoRun || await promptUser({ question: `[Nuxt Spec] Nuxt types and auto-imports should be regenerated after the update. Do you want to run \`${prepareCmd}\` now?` })
58
- if (runPrepare) {
59
- try {
60
- showMessage({ message: `Running \`${prepareCmd}\`...` })
61
- execSync(prepareCmd, { stdio: 'inherit' })
62
- } catch (error) {
63
- console.error(`[Nuxt Spec] Error running \`${prepareCmd}\`:\n`, error.message)
64
- }
65
- }
66
-
67
- // 3) run 'playwright install'
68
- const playwrightUpdateCmd = getPlaywrightInstallCmd(packageManager)
69
- const runPlaywrightUpdate = isAutoRun || await promptUser({ question: `[Nuxt Spec] Playwright browser runtimes might need to be updated for e2e tests. Do you want to run \`${playwrightUpdateCmd}\` now?` })
70
- if (runPlaywrightUpdate) {
71
- try {
72
- showMessage({ message: `Running \`${playwrightUpdateCmd}\`...` })
73
- execSync(playwrightUpdateCmd, { stdio: 'inherit' })
74
- } catch (error) {
75
- console.error(`[Nuxt Spec] Error running \`${playwrightUpdateCmd}\`:\n`, error.message)
76
- }
77
- }
78
-
79
- // 4) inform user
80
- showMessage({ message: '' })
81
- showMessage({ message: 'NUXT SPEC UPDATE COMPLETE', linesAfter: 2 })
82
- if (!runUpdate) {
83
- showMessage({ message: `Run \`${updateCmd}\` to update 'nuxt-spec'.` })
84
- }
85
- if (!runPrepare) {
86
- showMessage({ message: `Run \`${prepareCmd}\` to regenerate the Nuxt types and auto-imports.` })
87
- }
88
- if (!runPlaywrightUpdate) {
89
- showMessage({ message: `Run \`${playwrightUpdateCmd}\` to update the Playwright browser runtimes for e2e tests.` })
90
- }
91
-
92
- // force exit to prevent #20
93
- process.exit(0)
94
- }