vogdb
vogdb

Reputation: 4829

How to resolve path inside grunt plugin task to its own resources?

I have a sample grunt plugin

/tasks
   sample.js
   config.file
Gruntfile.js
package.json

I want to get the path to the config.file inside the sample.js. At first, I did it like this

path.resolve('tasks/config.file')

It was OK until the plugin had been installed. Path to the config.file changed to '~/some_project/node_modules/sample_plugin/tasks/config.file' but path.resolve returned '~/some_project/tasks/config.file'.

How can I get proper path to the config.file?

Upvotes: 4

Views: 2378

Answers (1)

vogdb
vogdb

Reputation: 4829

It turned out that I asked the question in the wrong direction. My question belonged to the nodejs not to the gruntjs. Answer is a __dirname directive. You can get full path to the config.file like this: __dirname + path.sep + 'config.file'

Upvotes: 4

Related Questions