nuxt-spec 0.1.4 → 0.1.6

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
@@ -14,7 +14,7 @@ Aside from being "forked" and used as you seem fit, `nuxt-spec` is also availabl
14
14
 
15
15
  1) Add following dependency into your `package.json`:
16
16
  ```
17
- "nuxt-spec": "0.1.4"
17
+ "nuxt-spec": "0.1.6"
18
18
  ```
19
19
 
20
20
  2) Add following section into your `nuxt.config.ts`:
package/bin/spec-setup.js CHANGED
@@ -4,15 +4,14 @@
4
4
  // and to add test-related commands in `package.json`
5
5
  // usage: `npx spec-setup.js` in target folder
6
6
 
7
- import { createFileFromTemplate } from './utils/create-file.js'
8
- import { updatePackageJsonScripts } from './utils/modify-scripts.js'
7
+ import { createFileFromTemplate, updateJsonFile } from 'elrh-cosca'
9
8
 
10
- async function main() {
9
+ export async function main() {
11
10
  // 1) create vitest.config.ts
12
- await createFileFromTemplate('../config/vitest.config.ts.template', 'vitest.config.ts')
11
+ await createFileFromTemplate('nuxt-spec:config/vitest.config.ts.template', 'vitest.config.ts')
13
12
 
14
13
  // 2) modify scripts in package.json
15
- await updatePackageJsonScripts({
14
+ await updateJsonFile('package.json', 'scripts', {
16
15
  'test': 'vitest run',
17
16
  'test-u': 'vitest run -u',
18
17
  'test-i': 'vitest',
package/config/index.mjs CHANGED
@@ -14,7 +14,7 @@ export async function loadVitestConfig(userVitestConfig) {
14
14
  // default fallback to catch tests in /test folder
15
15
  {
16
16
  test: {
17
- name: 'node',
17
+ name: 'default',
18
18
  include: ['test/*.{test,spec}.ts'],
19
19
  environment: 'node',
20
20
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-spec",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Test-pack layer for Nuxt Applications",
5
5
  "repository": "github:AloisSeckar/nuxt-spec",
6
6
  "license": "MIT",
@@ -23,11 +23,12 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@nuxt/test-utils": "3.19.2",
26
+ "@vitest/browser": "4.0.0-beta.8",
26
27
  "@vue/test-utils": "2.4.6",
28
+ "elrh-cosca": "0.1.4",
27
29
  "happy-dom": "18.0.1",
28
30
  "playwright-core": "1.54.2",
29
- "vitest": "4.0.0-beta.7",
30
- "@vitest/browser": "4.0.0-beta.7"
31
+ "vitest": "4.0.0-beta.8"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@nuxt/eslint": "1.8.0",
@@ -1,37 +0,0 @@
1
- import path from 'path'
2
- import { existsSync, copyFileSync } from 'fs'
3
- import { fileURLToPath } from 'url'
4
- import { promptUser } from './prompt-user.js'
5
-
6
- export async function createFileFromTemplate(templateFile, targetFile) {
7
- const shouldCreate = await promptUser(
8
- `This will create default 'vitest.config.ts' file. Continue?`,
9
- )
10
- if (shouldCreate) {
11
- const __filename = fileURLToPath(import.meta.url)
12
- const __dirname = path.dirname(__filename)
13
-
14
- const templatePath = path.resolve(__dirname, `../${templateFile}`)
15
- const targetPath = path.resolve(process.cwd(), targetFile)
16
-
17
- if (!existsSync(templatePath)) {
18
- console.error(`Template file not found at ${templatePath}`)
19
- process.exit(1)
20
- }
21
-
22
- if (existsSync(targetPath)) {
23
- const shouldOverwrite = await promptUser(
24
- `File 'vitest.config.ts' already exists. Overwrite?`,
25
- )
26
- if (!shouldOverwrite) {
27
- console.log('Aborted.')
28
- process.exit(0)
29
- }
30
- }
31
-
32
- copyFileSync(templatePath, targetPath)
33
- console.log(`Default 'vitest.config.ts' successfully created.`)
34
- } else {
35
- console.log(`Creation of 'vitest.config.ts' skipped.`)
36
- }
37
- }
@@ -1,46 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync } from 'fs'
2
- import path from 'path'
3
- import { promptUser } from './prompt-user.js'
4
-
5
- export async function updatePackageJsonScripts(scriptsToAdd) {
6
- const shouldUpdate = await promptUser(
7
- `This will update scripts section of 'package.json' file. Continue?`,
8
- )
9
- if (shouldUpdate) {
10
- const packageJsonPath = path.resolve(process.cwd(), 'package.json')
11
-
12
- if (!existsSync(packageJsonPath)) {
13
- console.warn(`No 'package.json' found in project root — skipping script updates.`)
14
- return
15
- }
16
-
17
- const pkgRaw = readFileSync(packageJsonPath, 'utf8')
18
- let pkg
19
- try {
20
- pkg = JSON.parse(pkgRaw)
21
- } catch {
22
- console.error(`Could not parse 'package.json' — skipping script updates.`)
23
- return
24
- }
25
-
26
- pkg.scripts = pkg.scripts || {}
27
-
28
- let modified = false
29
-
30
- for (const [name, cmd] of Object.entries(scriptsToAdd)) {
31
- if (pkg.scripts[name] !== cmd) {
32
- pkg.scripts[name] = cmd
33
- modified = true
34
- }
35
- }
36
-
37
- if (modified) {
38
- writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
39
- console.log(`Scripts section of 'package.json' updated.`)
40
- } else {
41
- console.log(`Scripts section of 'package.json' already up to date.`)
42
- }
43
- } else {
44
- console.log(`Adding scripts to 'package.json' skipped.`)
45
- }
46
- }
@@ -1,15 +0,0 @@
1
- import readline from 'readline'
2
-
3
- export async function promptUser(question) {
4
- const rl = readline.createInterface({
5
- input: process.stdin,
6
- output: process.stdout,
7
- })
8
-
9
- return new Promise((resolve) => {
10
- rl.question(question + ' (y/N): ', (answer) => {
11
- rl.close()
12
- resolve(/^y(es)?$/i.test(answer.trim()))
13
- })
14
- })
15
- }