grunt
grunt copied to clipboard
Initial current working directory
Because the cwd needs to be set where the grunt file is located. Is there a way to get the Initial current working directory? In Gulp they have the process.env.INIT_CWD.
You can get the cwd of any node process with: process.cwd()
When I call the process.cwd() inside the gruntfile it gives the path to the gruntfile not the Initial path from where it was executed as the screenshot is showing. I understand grunt changes the "working directory". Which is fine as long I can somehow get the original "working directory" too. Isn't this path saved somewhere before grunt changes it?
logging process.cwd() after calling grunt results in "....widget_repos". Now I want to get the "....widget_repos\templates\template_1" path somehow.
Ah I see. We don't have a env or API for it but you can add an option for it:
grunt --pwd=$(pwd)
Then in the Gruntfile:
const pwd = grunt.option('pwd')
I'm not sure what it is on Windows, maybe %cd% or something?
Maybe Grunt storing that initial directory in a cross platform way might be a good idea.
I saw other people on the internet looking for the same thing. Possible to ask a feature request?
I'll reopen this issue and label it.
Has this issue been resolved?
I'm using grunt for a few things I can't get Gulp to do and load grunt from the Gulpfile. I load Grunt tasks as such:
gulp.task(task, (cb) => {
return grunt.tasks([
// Get the right name for the task
task.replace('grunt-', '')
], {
gruntfile: `${process.cwd()}/node_modules/jellyapp/src/Gruntfile.js`
}, () => {
cb()
})
})
It would make a lot of sense if I could set the CWD where I make the reference to the Gruntfile.