Skip to content

Commit 7b43d2c

Browse files
Add sonarqube support (#10)
* Add SonarQube --------- Co-authored-by: yordan.ramchev <[email protected]>
1 parent 2ca7c66 commit 7b43d2c

File tree

6 files changed

+118
-3
lines changed

6 files changed

+118
-3
lines changed

index.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'node:path'
55

66
import minimist from 'minimist'
77
import prompts from 'prompts'
8-
import { red, green, bold } from 'kolorist'
8+
import { red, green, bold, yellow } from 'kolorist'
99

1010
import ejs from 'ejs'
1111

@@ -104,6 +104,7 @@ async function init() {
104104
argv.pinia ??
105105
argv.tests ??
106106
argv.vitest ??
107+
argv.sonarQube ??
107108
argv.cypress ??
108109
argv.nightwatch ??
109110
argv.playwright ??
@@ -126,6 +127,7 @@ async function init() {
126127
needsRouter?: boolean
127128
needsPinia?: boolean
128129
needsVitest?: boolean
130+
needsSonarQube?: boolean
129131
needsE2eTesting?: false | 'cypress' | 'nightwatch' | 'playwright'
130132
needsEslint?: boolean
131133
needsPrettier?: boolean
@@ -224,6 +226,19 @@ async function init() {
224226
active: 'Yes',
225227
inactive: 'No'
226228
},
229+
{
230+
name: 'needsSonarQube',
231+
type: (prev, values) => {
232+
if (isFeatureFlagsUsed || !values.needsVitest) {
233+
return null
234+
}
235+
return 'toggle'
236+
},
237+
message: 'Add SonarQube for code coverage?',
238+
initial: false,
239+
active: 'Yes',
240+
inactive: 'No'
241+
},
227242
{
228243
name: 'needsE2eTesting',
229244
type: () => (isFeatureFlagsUsed ? null : 'select'),
@@ -311,6 +326,7 @@ async function init() {
311326
needsRouter = argv.router,
312327
needsPinia = argv.pinia,
313328
needsVitest = argv.vitest || argv.tests,
329+
needsSonarQube = argv.SneedsSonarQube,
314330
needsEslint = argv.eslint || argv['eslint-with-prettier'],
315331
needsPrettier = argv['eslint-with-prettier'],
316332
needsVueUse = argv.vueUse,
@@ -363,6 +379,9 @@ async function init() {
363379
if (needsVitest) {
364380
render('config/vitest')
365381
}
382+
if (needsSonarQube) {
383+
render('config/sonarQube')
384+
}
366385
if (needsCypress) {
367386
render('config/cypress')
368387
}
@@ -520,8 +539,7 @@ async function init() {
520539
needsPlaywright,
521540
needsNightwatchCT,
522541
needsCypressCT,
523-
needsEslint,
524-
needsStorybook
542+
needsEslint
525543
})
526544
)
527545

@@ -539,6 +557,9 @@ async function init() {
539557
if (needsStorybook) {
540558
console.log(` ${bold(green('npx storybook@latest init --builder vite'))}`)
541559
}
560+
if (needsSonarQube) {
561+
console.log(` ${bold(yellow('Do not forget to update sonar-project.properties'))}`)
562+
}
542563
console.log(` ${bold(green(getCommand(packageManager, 'dev')))}`)
543564
console.log()
544565
}

pnpm-lock.yaml

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

template/config/sonarQube/_gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TernJS port file
2+
coverage
3+
.scannerwork
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"scripts": {
3+
"coverage": "vitest run --coverage",
4+
"sonar": "npx sonar-scanner"
5+
},
6+
"devDependencies": {
7+
"sonarqube-scanner": "^3.1.0"
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sonar.projectKey=#Required
2+
sonar.sources=src/
3+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
4+
sonar.exclusions=dist/**
5+
sonar.coverage.exclusions=**/*.test.*
6+
sonar.token=#Required
7+
host.url=http://localhost:9000
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mergeConfig, defineConfig } from 'vite'
2+
import viteConfig from './vite.config'
3+
4+
export default mergeConfig(
5+
viteConfig,
6+
defineConfig({
7+
test: {
8+
coverage: {
9+
provider: 'v8', // or 'istanbul'
10+
reporter: ['text', 'lcov', 'json', 'html']
11+
}
12+
}
13+
})
14+
)

0 commit comments

Comments
 (0)