grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Initial current working directory

Open vagasvau opened this issue 7 years ago • 6 comments

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.

vagasvau avatar Oct 23 '18 13:10 vagasvau

You can get the cwd of any node process with: process.cwd()

shama avatar Oct 23 '18 19:10 shama

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?

screenshot_2 logging process.cwd() after calling grunt results in "....widget_repos". Now I want to get the "....widget_repos\templates\template_1" path somehow.

vagasvau avatar Oct 25 '18 07:10 vagasvau

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.

shama avatar Oct 25 '18 16:10 shama

I saw other people on the internet looking for the same thing. Possible to ask a feature request?

vagasvau avatar Oct 25 '18 20:10 vagasvau

I'll reopen this issue and label it.

shama avatar Oct 25 '18 20:10 shama

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.

magnuspaaske avatar May 27 '20 06:05 magnuspaaske