Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up yarn configs. Correct locations.
- Loading branch information
Showing
6 changed files
with
166 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |