Skip to content

Commit

Permalink
Clean up yarn configs. Correct locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dweiss committed Jan 26, 2021
1 parent e69d730 commit 62cbe0f
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 192 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -44,7 +44,7 @@ apply from: file('gradle/gitinfo.gradle')
apply from: file('gradle/buildinfo.gradle')
apply from: file('gradle/defaults-java.gradle')

apply from: file('gradle/node/defaults-node.gradle')
apply from: file('gradle/node/yarn-projects.gradle')

apply from: file('gradle/ide/idea.gradle')

Expand Down
8 changes: 7 additions & 1 deletion dcs/contexts/frontend/build.gradle
Expand Up @@ -7,8 +7,9 @@ dependencies {
}

ext {
srclayout = 'webpack'
descriptorsDir = file("app/src/carrot2/service/algorithms/descriptors")
ext.jsSources = fileTree('app/src') + fileTree('app/public')
ext.jsBuildDir = file("app/build")
}

task descriptors(type: Sync) {
Expand All @@ -23,3 +24,8 @@ task descriptors(type: Sync) {

yarnBuild.dependsOn descriptors

cleanNodeDirs {
doLast {
delete "app/node_modules"
}
}
12 changes: 11 additions & 1 deletion doc/build.gradle
Expand Up @@ -7,8 +7,14 @@ dependencies {
}

ext {
srclayout = 'gatsby'
descriptorsDir = file("src/descriptors")

// Input sources (for incremental checks).
jsSources = fileTree('src') + fileTree('static')

// Gatsby has a non-configurable output folder, sigh.
// https://github.com/gatsbyjs/gatsby/issues/1878
jsBuildDir = file("public")
}

task descriptors(type: Sync) {
Expand All @@ -17,3 +23,7 @@ task descriptors(type: Sync) {
}

yarnBuild.dependsOn descriptors

clean {
delete ".cache"
}
40 changes: 0 additions & 40 deletions gradle/node/defaults-node.gradle

This file was deleted.

149 changes: 0 additions & 149 deletions gradle/node/yarn-project.gradle

This file was deleted.

147 changes: 147 additions & 0 deletions gradle/node/yarn-projects.gradle
@@ -0,0 +1,147 @@

// Configure node/ yarn projects

configure([
project(":dcs:contexts:frontend"),
project(":doc")
]) {

apply plugin: 'base'
apply plugin: 'com.github.node-gradle.node'

ext {
yarnEnv = [
'REACT_APP_VERSION' : rootProject.replaceTokens['product.version'],
'REACT_APP_BUILD_DATE': rootProject.replaceTokens['product.buildDate'],
'REACT_APP_GIT_REV' : rootProject.replaceTokens['product.gitrev']
]
}

configurations {
it.default.extendsFrom archives
}

// Change the default build directory for gradle so that
// it doesn't conflict with npm builds (webpack uses 'build' by default).
buildDir = file("build-gradle")

// Configure node and yarn versions.
node {
version = "${rootProject.versions.node}"
yarnVersion = "${rootProject.versions.yarn}"
download = true
}

task yarnInstall(type: YarnTask) {
group 'build'

inputs.file('package.json')
inputs.file('yarn.lock')

outputs.upToDateWhen {
return project.file('node_modules').exists()
}
outputs.file('node_modules/.yarn-integrity')

args = [
'install',
'--frozen-lockfile'
]
}

task yarnBuild(type: YarnTask) {
group 'build'
dependsOn yarnInstall

afterEvaluate {
inputs.file('package.json')
inputs.file('yarn.lock')
inputs.files { jsSources }

project.properties.each { k,v ->
if (k.startsWith("REACT_APP_")) {
yarnEnv.put(k, v)
}
}

System.getenv().each {k, v ->
if (k.startsWith("REACT_APP_")) {
yarnEnv.put(k, v)
}
}

inputs.properties (yarnEnv.findAll {
it.key != "REACT_APP_BUILD_DATE" &&
it.key != "REACT_APP_GIT_REV"
})
}

outputs.dir { jsBuildDir }

// Set the environment once the task runs, otherwise variables trigger task
// changed events and rebuilds.
doFirst {
environment = yarnEnv

yarnEnv.each { k,v ->
logger.lifecycle("Using yarn env variable $k=$v")
}
}

args = [
'build'
]
}

task fastBuild {
doFirst {
logger.warn("Omitting full yarn build in fast build: ${project.path}")
}
}

artifacts {
archives provider { jsBuildDir }, {
if (project.hasProperty("fast")) {
builtBy fastBuild
} else {
builtBy yarnBuild
}
}
}

assemble.dependsOn configurations.archives

clean {
doLast {
project.delete project.files(project.jsBuildDir)
}
}

task cleanNodeDirs(type: Delete) {
delete ".gradle"
delete "node_modules"
}

cleanall.dependsOn cleanNodeDirs
}

// Yarn install creates many problems when multiple instances try to run concurrently. Enforce
// sequential ordering here.
afterEvaluate {
rootProject.tasks.create("yarnOrdering")

def sequence = [
]

[
":dcs:contexts:frontend:yarnInstall",
":dcs:contexts:frontend:yarnBuild",
":doc:yarnInstall",
":doc:yarnBuild",
":yarnOrdering"
].each { path ->
def task = tasks.findByPath(path)
task.mustRunAfter(sequence)
sequence += task
}
}

0 comments on commit 62cbe0f

Please sign in to comment.