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 sourcesWithoutTypegen = fileTree('src') { exclude '**/*.typegen.ts' } def assembleFrontend = tasks.named('assembleFrontend') assembleFrontend.configure { dependsOn generateXStateTypes inputs.dir 'public' inputs.files sourcesWithoutTypegen inputs.file 'index.html' 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 generateXStateTypes = tasks.register('generateXStateTypes', RunYarn) { dependsOn installFrontend inputs.files sourcesWithoutTypegen inputs.file 'package.json' inputs.file rootProject.file('yarn.lock') outputs.dir 'src' script = 'run typegen' description = 'Generate TypeScript typings for XState state machines.' } def typecheckFrontend = tasks.register('typecheckFrontend', RunYarn) { dependsOn installFrontend dependsOn generateXStateTypes inputs.dir 'src' inputs.dir 'types' 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 dependsOn generateXStateTypes inputs.dir 'src' inputs.dir 'types' 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 dependsOn generateXStateTypes inputs.dir 'src' inputs.dir 'types' 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 dependsOn generateXStateTypes inputs.dir 'public' inputs.files sourcesWithoutTypegen inputs.file 'index.html' 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.' } tasks.named('clean') { delete 'dev-dist' delete fileTree('src') { include '**/*.typegen.ts' } } sonarqube.properties { properties['sonar.sources'] += ['src'] property 'sonar.nodejs.executable', "${frontend.nodeInstallDirectory.get()}/bin/node" property 'sonar.eslint.reportPaths', "${buildDir}/eslint.json" }