Skip to content

Commit

Permalink
feat: add the dev and test scripts to the template files (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
szgabsz91 committed Nov 25, 2023
1 parent 6ae5c5d commit 7c9431d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 63 deletions.
33 changes: 9 additions & 24 deletions index.ts
Expand Up @@ -18,7 +18,6 @@ import getCommand from './utils/getCommand'
import getLanguage from './utils/getLanguage'
import renderEslint from './utils/renderEslint'
import { FILES_TO_FILTER } from './utils/filterList'
import addNpmScript from './utils/addNpmScript'

function isValidPackageName(projectName) {
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName)
Expand Down Expand Up @@ -349,24 +348,24 @@ async function init() {
if (needsPinia) {
render('config/pinia')
}
if (needsVitest) {
render('config/vitest')
}
if (needsCypress) {
render('config/cypress')
}
if (needsCypressCT) {
render('config/cypress-ct')
}
if (needsNightwatch) {
render('config/nightwatch')
}
if (needsNightwatchCT) {
render('config/nightwatch-ct')
}
if (needsPlaywright) {
render('config/playwright')
}
if (needsVitest) {
render('config/vitest')
}
if (needsCypressCT) {
render('config/cypress-ct')
}
if (needsNightwatchCT) {
render('config/nightwatch-ct')
}
if (needsTypeScript) {
render('config/typescript')

Expand Down Expand Up @@ -492,20 +491,6 @@ async function init() {
const userAgent = process.env.npm_config_user_agent ?? ''
const packageManager = /pnpm/.test(userAgent) ? 'pnpm' : /yarn/.test(userAgent) ? 'yarn' : 'npm'

// Extend the package.json with the test script
const packageJsonPath = path.resolve(root, 'package.json')
addNpmScript('start', packageManager, 'dev', packageJsonPath)
if (
(needsCypress || needsNightwatch || needsPlaywright) &&
!needsVitest &&
!needsCypressCT &&
!needsNightwatchCT
) {
addNpmScript('test', packageManager, 'test:e2e', packageJsonPath)
} else if (needsVitest || needsCypressCT || needsNightwatchCT) {
addNpmScript('test', packageManager, 'test:unit', packageJsonPath)
}

// README generation
fs.writeFileSync(
path.resolve(root, 'README.md'),
Expand Down
1 change: 1 addition & 0 deletions template/base/package.json
Expand Up @@ -2,6 +2,7 @@
"private": true,
"scripts": {
"dev": "vite",
"start": "vite",
"build": "vite build",
"preview": "vite preview"
},
Expand Down
3 changes: 2 additions & 1 deletion template/config/cypress-ct/package.json
@@ -1,7 +1,8 @@
{
"scripts": {
"test:unit": "cypress run --component",
"test:unit:dev": "cypress open --component"
"test:unit:dev": "cypress open --component",
"test": "cypress run --component"
},
"dependencies": {
"vue": "^3.3.8"
Expand Down
3 changes: 2 additions & 1 deletion template/config/cypress/package.json
@@ -1,7 +1,8 @@
{
"scripts": {
"test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'",
"test:e2e:dev": "start-server-and-test 'vite dev --port 4173' http://localhost:4173 'cypress open --e2e'"
"test:e2e:dev": "start-server-and-test 'vite dev --port 4173' http://localhost:4173 'cypress open --e2e'",
"test": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'"
},
"devDependencies": {
"cypress": "^13.5.1",
Expand Down
3 changes: 2 additions & 1 deletion template/config/nightwatch-ct/package.json
@@ -1,6 +1,7 @@
{
"scripts": {
"test:unit": "nightwatch src/components/**/__tests__/*"
"test:unit": "nightwatch src/components/**/__tests__/*",
"test": "nightwatch src/components/**/__tests__/*"
},
"dependencies": {
"vue": "^3.3.8"
Expand Down
3 changes: 2 additions & 1 deletion template/config/nightwatch/package.json
@@ -1,6 +1,7 @@
{
"scripts": {
"test:e2e": "nightwatch tests/e2e"
"test:e2e": "nightwatch tests/e2e",
"test": "nightwatch tests/e2e"
},
"devDependencies": {
"nightwatch": "^3.3.2",
Expand Down
3 changes: 2 additions & 1 deletion template/config/playwright/package.json
@@ -1,6 +1,7 @@
{
"scripts": {
"test:e2e": "playwright test"
"test:e2e": "playwright test",
"test": "playwright test"
},
"devDependencies": {
"@playwright/test": "^1.40.0"
Expand Down
3 changes: 2 additions & 1 deletion template/config/vitest/package.json
@@ -1,6 +1,7 @@
{
"scripts": {
"test:unit": "vitest"
"test:unit": "vitest",
"test": "vitest"
},
"dependencies": {
"vue": "^3.3.8"
Expand Down
33 changes: 0 additions & 33 deletions utils/addNpmScript.ts

This file was deleted.

0 comments on commit 7c9431d

Please sign in to comment.