Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support putting cacheDir into rootProject #247 #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ buildscript {
apply plugin: 'com.moowork.node'
```

In multi-project builds the plugin can be applied to the individual projects making use of it. By
further applying it to the root project, child project will make use of the root configuration
and share a download cache directory.


## Installing snapshots

Expand Down
17 changes: 17 additions & 0 deletions src/main/groovy/com/moowork/gradle/grunt/GruntExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ class GruntExtension
{
this.workDir = project.projectDir
}

static GruntExtension get( final Project project )
{
return project.extensions.getByType( GruntExtension )
}

static GruntExtension create( final Project project )
{
def config = project.extensions.create( NAME, GruntExtension, project )
if(project.rootProject.hasProperty( GruntExtension.NAME) ){
def rootConfig = GruntExtension.get( project.rootProject )
config.colors = rootConfig.colors
config.bufferOutput = rootConfig.bufferOutput
config.gruntFile = rootConfig.gruntFile
}
return config
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GruntPlugin
{
project.plugins.apply( NodePlugin.class )

project.extensions.create( GruntExtension.NAME, GruntExtension, project )
GruntExtension.create( project )

project.extensions.extraProperties.set( 'GruntTask', GruntTask.class )
project.tasks.create( GRUNT_INSTALL_NAME, GruntInstallTask.class )
Expand Down
16 changes: 16 additions & 0 deletions src/main/groovy/com/moowork/gradle/gulp/GulpExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ class GulpExtension
{
this.workDir = project.projectDir
}

static GulpExtension get( final Project project )
{
return project.extensions.getByType( GulpExtension )
}

static GulpExtension create( final Project project )
{
def config = project.extensions.create( NAME, GulpExtension, project )
if(project.rootProject.hasProperty( GulpExtension.NAME) ){
def rootConfig = GulpExtension.get( project.rootProject )
config.colors = rootConfig.colors
config.bufferOutput = rootConfig.bufferOutput
}
return config
}
}
2 changes: 1 addition & 1 deletion src/main/groovy/com/moowork/gradle/gulp/GulpPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GulpPlugin
{
project.plugins.apply( NodePlugin.class )

project.extensions.create( GulpExtension.NAME, GulpExtension, project )
GulpExtension.create( project )

project.extensions.extraProperties.set( 'GulpTask', GulpTask.class )
project.tasks.create( GULP_INSTALL_NAME, GulpInstallTask.class )
Expand Down
17 changes: 16 additions & 1 deletion src/main/groovy/com/moowork/gradle/node/NodeExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ class NodeExtension

static NodeExtension create( final Project project )
{
return project.extensions.create( NAME, NodeExtension, project )
def config = project.extensions.create( NAME, NodeExtension, project )
if(project.rootProject.hasProperty( NodeExtension.NAME) ){
def rootConfig = NodeExtension.get( project.rootProject )
config.workDir = rootConfig.workDir
config.npmWorkDir = rootConfig.npmWorkDir
config.yarnWorkDir = rootConfig.yarnWorkDir
config.version = rootConfig.version
config.npmVersion = rootConfig.npmVersion
config.yarnVersion = rootConfig.yarnVersion
config.distBaseUrl = rootConfig.distBaseUrl
config.npmCommand = rootConfig.npmCommand
config.yarnCommand = rootConfig.yarnCommand
config.download = rootConfig.download
config.variant = rootConfig.variant
}
return config
}
}
22 changes: 19 additions & 3 deletions src/main/groovy/com/moowork/gradle/node/NodePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ class NodePlugin

this.project.afterEvaluate {
this.config.variant = new VariantBuilder( this.config ).build()
configureSetupTask()
configureNpmSetupTask()
configureYarnSetupTask()

// for root project the dependency to the root setup tasks will perform the setup and
// the tasks here will remain disabled
if( !hasRoot() ) {
configureSetupTask()
configureNpmSetupTask()
configureYarnSetupTask()
}
}
}

Expand All @@ -51,13 +56,24 @@ class NodePlugin
addGlobalTaskType( YarnTask )
}

private boolean hasRoot()
{
return this.project.parent != null && this.project.rootProject.hasProperty( NodeExtension.NAME)
}

private void addTasks()
{
this.project.tasks.create( NpmInstallTask.NAME, NpmInstallTask )
this.project.tasks.create( YarnInstallTask.NAME, YarnInstallTask )
this.setupTask = this.project.tasks.create( SetupTask.NAME, SetupTask )
this.npmSetupTask = this.project.tasks.create( NpmSetupTask.NAME, NpmSetupTask )
this.yarnSetupTask = this.project.tasks.create( YarnSetupTask.NAME, YarnSetupTask )

if( hasRoot() ){
this.setupTask.dependsOn( this.project.rootProject.tasks.getByName( SetupTask.NAME ) )
this.npmSetupTask.dependsOn( this.project.rootProject.tasks.getByName( NpmSetupTask.NAME ) )
this.yarnSetupTask.dependsOn( this.project.rootProject.tasks.getByName( YarnSetupTask.NAME ) )
}
}

private void addGlobalTaskType( Class type )
Expand Down