diff --git a/index.ts b/index.ts index cf7a54d24..eccf8a2fb 100755 --- a/index.ts +++ b/index.ts @@ -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) @@ -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') @@ -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'), diff --git a/template/base/package.json b/template/base/package.json index 5798b2de0..5b0150a7d 100644 --- a/template/base/package.json +++ b/template/base/package.json @@ -2,6 +2,7 @@ "private": true, "scripts": { "dev": "vite", + "start": "vite", "build": "vite build", "preview": "vite preview" }, diff --git a/template/config/cypress-ct/package.json b/template/config/cypress-ct/package.json index 61db75720..9ac423cad 100644 --- a/template/config/cypress-ct/package.json +++ b/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" diff --git a/template/config/cypress/package.json b/template/config/cypress/package.json index 77d5a5062..7e64374c9 100644 --- a/template/config/cypress/package.json +++ b/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", diff --git a/template/config/nightwatch-ct/package.json b/template/config/nightwatch-ct/package.json index 9299618bf..18c66efec 100644 --- a/template/config/nightwatch-ct/package.json +++ b/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" diff --git a/template/config/nightwatch/package.json b/template/config/nightwatch/package.json index a77d512d8..86f5bc7b7 100644 --- a/template/config/nightwatch/package.json +++ b/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", diff --git a/template/config/playwright/package.json b/template/config/playwright/package.json index a66b93aaa..32d977904 100644 --- a/template/config/playwright/package.json +++ b/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" diff --git a/template/config/vitest/package.json b/template/config/vitest/package.json index a87f97253..50857913d 100644 --- a/template/config/vitest/package.json +++ b/template/config/vitest/package.json @@ -1,6 +1,7 @@ { "scripts": { - "test:unit": "vitest" + "test:unit": "vitest", + "test": "vitest" }, "dependencies": { "vue": "^3.3.8" diff --git a/utils/addNpmScript.ts b/utils/addNpmScript.ts deleted file mode 100644 index df29014f6..000000000 --- a/utils/addNpmScript.ts +++ /dev/null @@ -1,33 +0,0 @@ -import * as fs from 'node:fs' - -/** - * Adds a new NPM script to the generated package.json file. - * The new script invokes another existing script with the package manager used by the developer, - * and is placed directly after the referenced NPM script. - * @param {string} scriptName the name of the new NPM script - * @param {string} packageManager the name of the used package manager, e.g. npm, pnpm or yarn - * @param {string} invokedScriptName the name of the invoked NPM script - * @param {string} packageJsonPath the path of the destination package.json file - */ -function addNpmScript( - scriptName: string, - packageManager: string, - invokedScriptName: string, - packageJsonPath: string -) { - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) - const command = - packageManager === 'npm' - ? `npm run ${invokedScriptName}` - : `${packageManager} ${invokedScriptName}` - packageJson.scripts = Object.entries(packageJson.scripts).reduce((result, entry) => { - result[entry[0]] = entry[1] - if (entry[0] === invokedScriptName) { - result[scriptName] = command - } - return result - }, {}) - fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n') -} - -export default addNpmScript