nuxt-spec 0.1.9 → 0.1.11

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/README.md CHANGED
@@ -17,11 +17,15 @@ The `nuxt-spec` package comes with a built-in CLI tool that can help you:
17
17
  - scaffold the default `vitest.config.ts` (see [configuration](#configuration) section)
18
18
  - add a few test-related script shorthands into your `package.json` (see [running tests](#running-tests) section)
19
19
 
20
- To use it, just run the following command in your terminal:
20
+ To use it, just run the CLI script in your terminal:
21
21
 
22
- ```bash
23
- npx nuxt-spec setup
24
- ```
22
+ | Manager | Command |
23
+ |-----------------|---------|
24
+ | npm | `npx nuxt-spec setup` |
25
+ | yarn | `yarn dlx nuxt-spec setup` |
26
+ | pnpm | `pnpx nuxt-spec setup` |
27
+ | Bun | `bunx nuxt-spec setup` |
28
+ | Deno | `deno run --allow-run npm:npx nuxt-spec setup` |
25
29
 
26
30
  First, the CLI tool will ask you whether you want to do the setup automatically. If you choose `y`es, it will perform all the steps for you. If you choose `n`o, it will guide you through the manual setup step-by-step (see [manual setup](#manual-setup) section).
27
31
 
@@ -32,7 +36,7 @@ If you don't want to use the CLI tool, or you want to understand its flow better
32
36
  1) Add following dependency into your `package.json`:
33
37
 
34
38
  ```
35
- "nuxt-spec": "0.1.9"
39
+ "nuxt-spec": "0.1.11"
36
40
  ```
37
41
 
38
42
  2) Add following section into your `nuxt.config.ts`:
@@ -69,15 +73,113 @@ export default loadVitestConfig({
69
73
  }
70
74
  ```
71
75
 
76
+ 6) (Optional) Setup file structures for tests as follows:
77
+
78
+ ```
79
+ test/
80
+ ├── e2e/
81
+ │ └── nuxt-e2e.test.ts
82
+ ├── nuxt/
83
+ │ └── nuxt-unit.test.ts
84
+ └── unit/
85
+ └── vitest.test.ts
86
+ ```
87
+
88
+ You can use sample files from the [project repository](https://github.com/AloisSeckar/nuxt-spec/tree/v0.1.11/test).
89
+
72
90
  ### Install and execute
73
91
 
74
92
  Whether you used the CLI tool or did the manual setup, you are ready to install and run the tests.
75
93
 
76
- 1) Run `pnpm install` to install the dependencies.
94
+ 1) Install the dependencies:
95
+
96
+ <!-- tabs:start -->
97
+
98
+ #### **npm**
99
+
100
+ ```bash
101
+ npm install
102
+ ```
103
+
104
+ #### **yarn**
105
+
106
+ ```bash
107
+ yarn install
108
+ ```
109
+
110
+ #### **pnpm**
111
+
112
+ ```bash
113
+ pnpm install
114
+ ```
115
+
116
+ #### **bun**
117
+
118
+ ```bash
119
+ bun install
120
+ ```
121
+
122
+ <!-- tabs:end -->
123
+
124
+ 2) If you're prompted (for the first time when installing to a new machine), install headless browser runtimes:
125
+
126
+ <!-- tabs:start -->
127
+
128
+ #### **npm**
129
+
130
+ ```bash
131
+ npx playwright-core install
132
+ ```
133
+
134
+ #### **yarn**
135
+
136
+ ```bash
137
+ yarn dlx playwright-core install
138
+ ```
139
+
140
+ #### **pnpm**
141
+
142
+ ```bash
143
+ pnpm exec playwright-core install
144
+ ```
145
+
146
+ #### **bun**
147
+
148
+ ```bash
149
+ bunx playwright-core install
150
+ ```
151
+
152
+ <!-- tabs:end -->
153
+
154
+ 3) Start the development server of your awesome Nuxt project:
155
+
156
+ <!-- tabs:start -->
157
+
158
+ #### **npm**
159
+
160
+ ```bash
161
+ npm run dev
162
+ ```
163
+
164
+ #### **yarn**
165
+
166
+ ```bash
167
+ yarn dev
168
+ ```
169
+
170
+ #### **pnpm**
77
171
 
78
- 2) If you're prompoted (for the first time when installing to a new machine), run `pnpm exec playwright-core install` to download and locally install headless browser runtimes.
172
+ ```bash
173
+ pnpm dev
174
+ ```
79
175
 
80
- 3) Run `pnpm dev` to start the development server of your awesome Nuxt project!
176
+ #### **bun**
177
+
178
+ ```bash
179
+ bun run dev
180
+ ```
181
+
182
+ <!-- tabs:end -->
81
183
 
82
184
  ### Running tests
83
185
 
@@ -88,9 +190,43 @@ You can use those three optional commands `package.json` file in `"scripts"` sec
88
190
  - `test-u: vitest run -u` - runs once and updates snapshots
89
191
  - `test-i: vitest` - runs and waits in HMR mode for test file changes
90
192
 
91
- Then you can call in terminal in root of your project:
193
+ Then you can call in terminal in root of your project:
194
+
195
+ <!-- tabs:start -->
196
+
197
+ #### **npm**
198
+
199
+ ```bash
200
+ npm run test # runs once and ends
201
+ npm run test-u # runs once and updates snapshots
202
+ npm run test-i # runs and waits in HMR mode
203
+ ```
204
+
205
+ #### **yarn**
206
+
207
+ ```bash
208
+ yarn test # runs once and ends
209
+ yarn test-u # runs once and updates snapshots
210
+ yarn test-i # runs and waits in HMR mode
211
+ ```
212
+
213
+ #### **pnpm**
214
+
215
+ ```bash
216
+ pnpm test # runs once and ends
217
+ pnpm test-u # runs once and updates snapshots
218
+ pnpm test-i # runs and waits in HMR mode
219
+ ```
220
+
221
+ #### **bun**
222
+
223
+ ```bash
224
+ bun run test # runs once and ends
225
+ bun run test-u # runs once and updates snapshots
226
+ bun run test-i # runs and waits in HMR mode
227
+ ```
92
228
 
93
- `pnpm test` | `pnpm test-u` | `pnpm test-i`
229
+ <!-- tabs:end -->
94
230
 
95
231
  Or you can use the `vitest` command directly with all its parameters. See [Vitest CLI documentation](https://vitest.dev/guide/cli.html) for more info.
96
232
 
@@ -108,11 +244,11 @@ Planned future development:
108
244
  - reason about (not) using Vitest browser mode (or make it optional)
109
245
  - solution for visual testing - either [backstopjs](https://www.npmjs.com/package/backstopjs) or Vitest's native (currently experimental)
110
246
 
111
- See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/main/CHANGELOG.md) for the latest updates and features.
247
+ See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.11/CHANGELOG.md) for the latest updates and features.
112
248
 
113
249
  ## Configuration
114
250
 
115
- By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/main/config/index.mjs). The configuration is based on [Nuxt team recommendations](https://nuxt.com/docs/4.x/getting-started/testing) and our best judgement.
251
+ By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.11/config/index.mjs). The configuration is based on [Nuxt team recommendations](https://nuxt.com/docs/4.x/getting-started/testing) and our best judgement.
116
252
 
117
253
  To add/override your custom config, you can create (or scaffold via CLI tool) a file named `vitest.config.ts` in the root of your project with the following content:
118
254
 
package/app/app.vue CHANGED
@@ -4,6 +4,6 @@
4
4
  <div>
5
5
  Test-pack layer for <a href="https://nuxt.com/">Nuxt</a> applications
6
6
  </div>
7
- <NuxtTestComponent text="Test Component" />
7
+ <NuxtSpecTestComponent text="Test Component" />
8
8
  </div>
9
9
  </template>
package/bin/cli.js CHANGED
@@ -1,19 +1,46 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
+
3
+ import { getPackageManager } from 'elrh-cosca'
2
4
 
3
5
  /**
4
6
  * CLI tool to scaffold necessary adjustments in project folder.
7
+ *
5
8
  * Currently only allows `setup` to be passed as parameter.
9
+ *
10
+ * Second parameter for `setup` might be a boolean to indicate auto mode
11
+ * (no prompts, force = true) or manual mode (with prompts, force = false).
6
12
  */
7
13
 
14
+ // get parameters passed by user
8
15
  const args = process.argv.slice(2);
9
16
 
17
+ // execute actions based on first param
18
+ // additional params might be passed into the called functions
10
19
  (async () => {
11
20
  switch (args[0]) {
12
21
  case 'setup':
13
- await (await import('./setup.js')).specSetup();
14
- break;
22
+ await (await import('./setup.js')).specSetup(args[1] || false)
23
+ break
24
+ default:
25
+ console.log(`Usage: \`${getCmd()} nuxt-spec setup [true|false]\``)
26
+ process.exit(args.length ? 1 : 0)
27
+ }
28
+ })()
29
+
30
+ // try detecting what package manager was used
31
+ // to give user apropriate usage hint
32
+ function getCmd() {
33
+ const packageManager = getPackageManager()
34
+ switch (packageManager) {
35
+ case 'pnpm':
36
+ return 'pnpx'
37
+ case 'yarn':
38
+ return 'yarn dlx'
39
+ case 'bun':
40
+ return 'bunx'
41
+ case 'deno':
42
+ return 'deno run --allow-run npm:npx'
15
43
  default:
16
- console.log('Usage: `npx nuxt-spec setup`');
17
- process.exit(args.length ? 1 : 0);
44
+ return 'npx'
18
45
  }
19
- })();
46
+ }
package/bin/setup.js CHANGED
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { promptUser, showMessage } from 'elrh-cosca'
3
+ import {
4
+ createFileFromWebTemplate, deletePath, getPackageManager, hasJsonKey,
5
+ pathExists, promptUser, removeFromJsonFile, showMessage,
6
+ updateConfigFile, updateJsonFile, updateTextFile,
7
+ } from 'elrh-cosca'
4
8
 
5
9
  /**
6
10
  * CLI tool to scaffold necessary adjustments in project folder.
@@ -10,24 +14,215 @@ import { promptUser, showMessage } from 'elrh-cosca'
10
14
  * Then it:
11
15
  * 1) adds `nuxt-spec` into `package.json` dependencies and removes `nuxt`, `vue` and `vue-router` if present
12
16
  * 2) adds `extends: ['nuxt-spec']` to `nuxt.config.ts`
13
- * 3) creates/updates `.npmrc` file
17
+ * 3) creates/updates `.npmrc` file (only if pnpm is used)
14
18
  * 4) creates default `vitest.config.ts` file
15
- * 5) adds test-related scripts in `package.json`
16
- * 6) clear node_modules and lock file(s)
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).
17
24
  */
18
- export async function specSetup() {
25
+ export async function specSetup(autoRun = false) {
19
26
  showMessage('NUXT SPEC SETUP')
20
27
  showMessage('This CLI tool will help you include Nuxt Spec in your project.')
21
28
  showMessage('Refer to the documentation for more information.', 2)
22
29
 
23
- const shouldDoAuto = await promptUser('Do you want to set everything up automatically (no more prompts)?')
30
+ const isAutoRun = autoRun || await promptUser('Do you want to set everything up automatically (no more prompts)?')
24
31
  showMessage('')
25
32
 
26
- if (shouldDoAuto) {
27
- const { specSetupAuto } = await import('./setup-auto.js')
28
- await specSetupAuto()
29
- } else {
30
- const { specSetupManual } = await import('./setup-manual.js')
31
- await specSetupManual()
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.1.11',
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) .npmrc file (only if pnpm is used)
105
+ if (packageManager === 'pnpm') {
106
+ try {
107
+ if (pathExists('.npmrc')) {
108
+ await updateTextFile('.npmrc', ['shamefully-hoist=true'], isAutoRun, 'This will adjust \'.npmrc\' file in your project. Continue?')
109
+ } else {
110
+ await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/.npmrc',
111
+ '.npmrc', isAutoRun, 'This will add \'.npmrc\' file for your project. Continue?')
112
+ }
113
+ } catch (error) {
114
+ console.error('Error setting up \'.npmrc\':\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.1.11/config/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)
32
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.1.11/test/e2e/nuxt-e2e.test.ts',
159
+ 'test/e2e/nuxt-e2e.test.ts', true)
160
+ } catch (error) {
161
+ console.error('Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
162
+ }
163
+ try {
164
+ await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/test/nuxt/nuxt-unit.test.ts',
165
+ 'test/nuxt/nuxt-unit.test.ts', true)
166
+ } catch (error) {
167
+ console.error('Error setting up \'nuxt-unit.test.ts\':\n', error.message)
168
+ }
169
+ try {
170
+ await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/test/unit/vitest.test.ts',
171
+ 'test/unit/vitest.test.ts', true)
172
+ } catch (error) {
173
+ console.error('Error setting up \'vitest.test.ts\':\n', error.message)
174
+ }
175
+ }
176
+
177
+ // 7) clear node_modules and lock file(s)
178
+ const prepareForReinstall = isAutoRun || await promptUser('Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?')
179
+ if (prepareForReinstall) {
180
+ if (pathExists('node_modules')) {
181
+ try {
182
+ await deletePath('node_modules', true)
183
+ } catch (error) {
184
+ console.error('Error deleting \'node_modules\':\n', error.message)
185
+ }
186
+ }
187
+ if (pathExists('package-lock.json')) {
188
+ try {
189
+ await deletePath('package-lock.json', true)
190
+ } catch (error) {
191
+ console.error('Error deleting \'package-lock.json\':\n', error.message)
192
+ }
193
+ }
194
+ if (pathExists('pnpm-lock.yaml')) {
195
+ try {
196
+ await deletePath('pnpm-lock.yaml', true)
197
+ } catch (error) {
198
+ console.error('Error deleting \'pnpm-lock.yaml\':\n', error.message)
199
+ }
200
+ }
201
+ if (pathExists('yarn.lock')) {
202
+ try {
203
+ await deletePath('yarn.lock', true)
204
+ } catch (error) {
205
+ console.error('Error deleting \'yarn.lock\':\n', error.message)
206
+ }
207
+ }
208
+ if (pathExists('bun.lockb')) {
209
+ try {
210
+ await deletePath('bun.lockb', true)
211
+ } catch (error) {
212
+ console.error('Error deleting \'bun.lockb\':\n', error.message)
213
+ }
214
+ }
215
+ if (pathExists('deno.lock')) {
216
+ try {
217
+ await deletePath('deno.lock', true)
218
+ } catch (error) {
219
+ console.error('Error deleting \'deno.lock\':\n', error.message)
220
+ }
221
+ }
222
+ }
223
+
224
+ // 7) inform user
225
+ showMessage('')
226
+ showMessage('NUXT SPEC SETUP COMPLETE', 2)
227
+ showMessage(`Proceed with \`${packageManager} install\` to get started.`)
33
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-spec",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Test-pack layer for Nuxt Applications",
5
5
  "repository": "github:AloisSeckar/nuxt-spec",
6
6
  "license": "MIT",
@@ -24,14 +24,14 @@
24
24
  "dependencies": {
25
25
  "@nuxt/eslint": "1.9.0",
26
26
  "@nuxt/test-utils": "3.19.2",
27
- "@vitest/browser": "4.0.0-beta.16",
27
+ "@vitest/browser": "4.0.0-beta.17",
28
28
  "@vue/test-utils": "2.4.6",
29
- "elrh-cosca": "0.3.3",
30
- "happy-dom": "19.0.2",
31
- "nuxt": "4.1.2",
32
- "playwright-core": "1.55.1",
29
+ "elrh-cosca": "0.3.4",
30
+ "happy-dom": "20.0.0",
31
+ "nuxt": "4.1.3",
32
+ "playwright-core": "1.56.0",
33
33
  "typescript": "5.9.3",
34
- "vitest": "4.0.0-beta.16",
34
+ "vitest": "4.0.0-beta.17",
35
35
  "vue": "3.5.22",
36
36
  "vue-router": "4.5.1"
37
37
  },
package/bin/setup-auto.js DELETED
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import {
4
- createFileFromWebTemplate, deletePath, fileExists, hasJsonKey,
5
- removeFromJsonFile, updateConfigFile, updateJsonFile, updateTextFile,
6
- } from 'elrh-cosca'
7
-
8
- /**
9
- * CLI tool to scaffold necessary adjustments in project folder.
10
- * This is the "auto" version running with supressed prompts (force = true).
11
- * @see `bin/setup.js` for details
12
- */
13
- export async function specSetupAuto() {
14
- // 1) manage dependencies in package.json
15
-
16
- // add nuxt-spec
17
- await updateJsonFile('package.json', 'dependencies', {
18
- 'nuxt-spec': '0.1.9',
19
- }, true)
20
-
21
- // remove now obsolete nuxt, vue and vue-router (if they are present)
22
- if (hasJsonKey('package.json', 'dependencies.nuxt')) {
23
- await removeFromJsonFile('package.json', 'dependencies.nuxt', true)
24
- }
25
- if (hasJsonKey('package.json', 'dependencies.vue')) {
26
- await removeFromJsonFile('package.json', 'dependencies.vue', true)
27
- }
28
- if (hasJsonKey('package.json', 'dependencies.vue-router')) {
29
- await removeFromJsonFile('package.json', 'dependencies.vue-router', true)
30
- }
31
- if (hasJsonKey('package.json', 'devDependencies.nuxt')) {
32
- await removeFromJsonFile('package.json', 'devDependencies.nuxt', true)
33
- }
34
- if (hasJsonKey('package.json', 'devDependencies.vue')) {
35
- await removeFromJsonFile('package.json', 'devDependencies.vue', true)
36
- }
37
- if (hasJsonKey('package.json', 'devDependencies.vue-router')) {
38
- await removeFromJsonFile('package.json', 'devDependencies.vue-router', true)
39
- }
40
-
41
- // 2) modify nuxt.config.ts
42
- await updateConfigFile('nuxt.config.ts', {
43
- extends: [
44
- 'nuxt-spec',
45
- ],
46
- }, true)
47
-
48
- // 3) .npmrc file
49
- if (fileExists('.npmrc')) {
50
- await updateTextFile('.npmrc', ['shamefully-hoist=true'], true)
51
- } else {
52
- await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/heads/main/.npmrc', '.npmrc', true)
53
- }
54
-
55
- // 4) create vitest.config.ts
56
- await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/heads/main/config/vitest.config.ts.template', 'vitest.config.ts', true)
57
-
58
- // 5) modify scripts in package.json
59
- await updateJsonFile('package.json', 'scripts', {
60
- 'test': 'vitest run',
61
- 'test-u': 'vitest run -u',
62
- 'test-i': 'vitest',
63
- }, true)
64
-
65
- // 6) clear node_modules and lock file(s)
66
- await deletePath('node_modules', true)
67
- if (fileExists('package-lock.json')) {
68
- await deletePath('package-lock.json', true)
69
- }
70
- if (fileExists('pnpm-lock.yaml')) {
71
- await deletePath('pnpm-lock.yaml', true)
72
- }
73
- if (fileExists('yarn.lock')) {
74
- await deletePath('yarn.lock', true)
75
- }
76
- if (fileExists('bun.lockb')) {
77
- await deletePath('bun.lockb', true)
78
- }
79
- }
@@ -1,87 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import {
4
- createFileFromWebTemplate, deletePath, fileExists, hasJsonKey, promptUser,
5
- removeFromJsonFile, updateConfigFile, updateJsonFile, updateTextFile,
6
- } from 'elrh-cosca'
7
-
8
- /**
9
- * CLI tool to scaffold necessary adjustments in project folder.
10
- * This is the "manual" version running with prompts for each action (force = false).
11
- * @see `bin/setup.js` for details
12
- */
13
- export async function specSetupManual() {
14
- // 1) manage dependencies in package.json
15
-
16
- // add nuxt-spec
17
- await updateJsonFile('package.json', 'dependencies', {
18
- 'nuxt-spec': '0.1.9',
19
- }, false, 'This will add \'nuxt-spec\' dependency to your \'package.json\'. Continue?')
20
-
21
- // remove now obsolete nuxt, vue and vue-router
22
- const removeDeps = 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?')
23
- if (removeDeps) {
24
- if (hasJsonKey('package.json', 'dependencies.nuxt')) {
25
- await removeFromJsonFile('package.json', 'dependencies.nuxt', true)
26
- }
27
- if (hasJsonKey('package.json', 'dependencies.vue')) {
28
- await removeFromJsonFile('package.json', 'dependencies.vue', true)
29
- }
30
- if (hasJsonKey('package.json', 'dependencies.vue-router')) {
31
- await removeFromJsonFile('package.json', 'dependencies.vue-router', true)
32
- }
33
- if (hasJsonKey('package.json', 'devDependencies.nuxt')) {
34
- await removeFromJsonFile('package.json', 'devDependencies.nuxt', true)
35
- }
36
- if (hasJsonKey('package.json', 'devDependencies.vue')) {
37
- await removeFromJsonFile('package.json', 'devDependencies.vue', true)
38
- }
39
- if (hasJsonKey('package.json', 'devDependencies.vue-router')) {
40
- await removeFromJsonFile('package.json', 'devDependencies.vue-router', true)
41
- }
42
- }
43
-
44
- // 2) modify nuxt.config.ts
45
- await updateConfigFile('nuxt.config.ts', {
46
- extends: [
47
- 'nuxt-spec',
48
- ],
49
- }, false, 'This will add \'nuxt-spec\' module to your \'nuxt.config.ts\'. Continue?')
50
-
51
- // 3) .npmrc file
52
- if (fileExists('.npmrc')) {
53
- await updateTextFile('.npmrc', ['shamefully-hoist=true'], false, 'This will adjust \'.npmrc\' file in your project. Continue?')
54
- } else {
55
- await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/heads/main/.npmrc',
56
- '.npmrc', false, 'This will add \'.npmrc\' file for your project. Continue?')
57
- }
58
-
59
- // 4) create vitest.config.ts
60
- await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/heads/main/config/vitest.config.ts.template',
61
- 'vitest.config.ts', false, 'This will create a new \'vitest.config.ts\' file for your project. Continue?')
62
-
63
- // 5) modify scripts in package.json
64
- await updateJsonFile('package.json', 'scripts', {
65
- 'test': 'vitest run',
66
- 'test-u': 'vitest run -u',
67
- 'test-i': 'vitest',
68
- }, false, 'This will adjust the test-related commands in your \'package.json\'. Continue?')
69
-
70
- // 6) clear node_modules and lock file(s)
71
- const prepareForReinstall = await promptUser('Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?')
72
- if (prepareForReinstall) {
73
- await deletePath('node_modules', true)
74
- if (fileExists('package-lock.json')) {
75
- await deletePath('package-lock.json', true)
76
- }
77
- if (fileExists('pnpm-lock.yaml')) {
78
- await deletePath('pnpm-lock.yaml', true)
79
- }
80
- if (fileExists('yarn.lock')) {
81
- await deletePath('yarn.lock', true)
82
- }
83
- if (fileExists('bun.lockb')) {
84
- await deletePath('bun.lockb', true)
85
- }
86
- }
87
- }