aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/build.gradle
blob: 5ed90c310b79732e68423bd8d6d80f1f0be4c6bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
plugins {
	id 'refinery-frontend-workspace'
	id 'refinery-sonarqube'
}

import org.siouan.frontendgradleplugin.infrastructure.gradle.RunYarn

def viteOutputDir = "${buildDir}/vite"
def productionResources = file("${viteOutputDir}/production")

frontend {
	assembleScript = 'run build'
}

configurations {
	productionAssets {
		canBeConsumed = true
		canBeResolved = false
	}
}

def installFrontend = tasks.named('installFrontend')

def assembleFrontend = tasks.named('assembleFrontend')
assembleFrontend.configure {
	inputs.dir 'src'
	inputs.files('package.json', 'tsconfig.json', 'tsconfig.base.json', 'vite.config.ts')
	inputs.file rootProject.file('yarn.lock')
	outputs.dir productionResources
}

artifacts {
	productionAssets(productionResources) {
		builtBy assembleFrontend
	}
}

def typecheckFrontend = tasks.register('typecheckFrontend', RunYarn) {
	dependsOn installFrontend
	inputs.dir 'src'
	inputs.files('package.json', 'tsconfig.json', 'tsconfig.base.json', 'tsconfig.node.json')
	inputs.file rootProject.file('yarn.lock')
	outputs.dir "${buildDir}/typescript"
	script = 'run typecheck'
	group = 'verification'
	description = 'Check for TypeScript type errors.'
}

def lintFrontend = tasks.register('lintFrontend', RunYarn) {
	dependsOn installFrontend
	inputs.dir 'src'
	inputs.files('.eslintrc.cjs', 'prettier.config.cjs')
	inputs.files('package.json', 'tsconfig.json', 'tsconfig.base.json', 'tsconfig.node.json')
	inputs.file rootProject.file('yarn.lock')
	if (project.hasProperty('ci')) {
		outputs.file "${buildDir}/eslint.json"
		script = 'run lint:ci'
	} else {
		script = 'run lint'
	}
	group = 'verification'
	description = 'Check for TypeScript lint errors and warnings.'
}

def prettier = tasks.register('fixFrontend', RunYarn) {
	dependsOn installFrontend
	inputs.dir 'src'
	inputs.files('.eslintrc.cjs', 'prettier.config.cjs')
	inputs.files('package.json', 'tsconfig.json', 'tsconfig.base.json', 'tsconfig.node.json')
	inputs.file rootProject.file('yarn.lock')
	script = 'run lint:fix'
	group = 'verification'
	description = 'Fix TypeScript lint errors and warnings.'
}

tasks.named('check') {
	dependsOn(typecheckFrontend)
	dependsOn(lintFrontend)
}

tasks.register('serveFrontend', RunYarn) {
	dependsOn installFrontend
	inputs.dir 'src'
	inputs.files('package.json', 'tsconfig.json', 'tsconfig.base.json', 'vite.config.ts')
	inputs.file rootProject.file('yarn.lock')
	outputs.dir "${viteOutputDir}/development"
	script = 'run serve'
	group = 'run'
	description = 'Start a Vite dev server with hot module replacement.'
}

sonarqube.properties {
	properties['sonar.sources'] += ['src']
	property 'sonar.nodejs.executable', "${frontend.nodeInstallDirectory.get()}/bin/node"
	property 'sonar.eslint.reportPaths', "${buildDir}/eslint.json"
}