Reputation: 3826
I want pass a parameter to my Gruntfile.js so the grunt.file.readJSON can read the filename passed in. What should I do?
grunt.initConfig({
filename: grunt.option('filename'),
config: grunt.file.readJSON('<%= filename %>'),
... ... ...
});
The above does not work.
> grunt build-dev --filename=test.json
Loading "Gruntfile.js" tasks...ERROR
>> Error: Unable to read "<%= filename %>" file (Error code: ENOENT).
Upvotes: 2
Views: 1296
Reputation: 13762
Grunt templates only work within the Grunt config itself. grunt.file.readJSON
is a function that takes a single argument and does not process template patterns.
But rather just reads a JSON file from the specified file path and feeds that object to the Grunt config (which means the JSON file can contain Grunt template patterns).
Try the following instead:
grunt.initConfig({
filename: grunt.option('filename'),
config: grunt.file.readJSON(grunt.option('filename')),
// ... ... ...
});
Upvotes: 5