dciccale / grunt-processhtml

Process html files at build time to modify them depending on the release environment
MIT License
407 stars 30 forks source link

Feature request - Ability to set function to option data #110

Closed YannickGagnon closed 7 years ago

YannickGagnon commented 7 years ago

Would be pretty helpful to be able to assign function to option > data

One example could be:

version: function() { var version = 1; if(!grunt.file.exists('VERSION')) { version = grunt.file.read('VERSION'); } }

I know one work-around could be to have a task write/overwrite this property from outside using:

grunt.registerTask('presetVersion', function() {

var version = 1;

if(grunt.file.exists('VERSION')) {
  version = grunt.file.read('VERSION');
}

// Set data version using grunt.config.set
grunt.config.set('processhtml.options.data.version', version);

});

Thanks,

dciccale commented 7 years ago

You could do your version calculation logic outside the configuration of the plugin and pass the already calculated version as data. I actually would encourage this, otherwise the performance of calling the function every time a file is processed could be affected seriously if misused.

Thanks for your feedback :)

YannickGagnon commented 7 years ago

Thanks and sorry about the delayed answer. I agree this could be misused, in my case, it's only called when I package a distribution version ;)

But I agree with you, modifying this plugin for my use case might cause more problems for others.

Don't bother ;)