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

Allow the setting of a working directory for Grunt tasks #22

Open
antillean opened this issue Feb 23, 2015 · 4 comments
Open

Allow the setting of a working directory for Grunt tasks #22

antillean opened this issue Feb 23, 2015 · 4 comments

Comments

@antillean
Copy link

There doesn't seem to be a way of setting Grunt's working directory. Grunt install always seems to install grunt to node_modules/grunt and node_modules/grunt-cli in my project directory, and it also always looks for Gruntfile.js in my project directory. I made a custom install task as follows to get more generic behaviour:

task gruntInstallCustom(type: NpmTask, dependsOn: npmInstallCustom) {
    execOverrides {
        it.workingDir = nodeBuildDir
    }

    setArgs( ['install', 'grunt-cli', 'grunt'] )

    outputs.dir { file("$nodeBuildDir/node_modules/grunt") }
    outputs.dir { file("$nodeBuildDir/node_modules/grunt-cli") }
}

It might be worth making a similar/corresponding change in the default grunt tasks.

(This corresponds to issue 48 of gradle-node-plugin. npmInstallCustom is defined on that ticket.)

@antillean antillean changed the title Grunt tasks should honour workDir property Allow the setting of a working directory for Grunt tasks Feb 23, 2015
@btiernay
Copy link

Was this fixed? I'm still having the same issue. For my grunt tasks, I would like to be able to use the same npm modules directory configured using node. Thanks!

@btiernay
Copy link

I think this is still an issue due to:

https://github.com/srs/gradle-grunt-plugin/blob/master/src/main/groovy/com/moowork/gradle/grunt/GruntTask.groovy#L19

Essentially, this binds grunt binaries relative to the project directory. This should be done relative to the working directory. Otherwise, it is required that "${project.projectDir}/node_modules/" exist, which limits customization / flexibility.

@btiernay
Copy link

@antillean I wasn't able to successfully use your custom task suggestion above due to the binding of GruntTask to the project directory. Although grunt will get installed to your specified folder, it still seems that the grunt tasks fail if you remove "${project.projectDir}/node_modules/"

@antillean
Copy link
Author

@btiernay, you're right. I forgot to include another task redefinition that I'm using to get it to work:

task gruntBuild(type: NodeTask, dependsOn: gruntInstallCustom) {
    execOverrides {
        it.workingDir = nodeBuildDir
    }

    setScript(file("$nodeBuildDir/node_modules/grunt-cli/bin/grunt"))
}

And the setScript overrides the problematic line that you pointed out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants