Gather Options Before Execution Instead of During initConfig() (Enhancement)
Opened this issue · 2 comments
Gather Options Before Execution Instead of During initConfig().
It would be very helpful if I could do this:
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-debian-package');
grunt.initConfig({
shell: {
get_version: {
command: 'git describe',
options: {
stdout: false,
callback: function(err, stdout, stderr, callback) {
if (stdout.length !== 0) {
grunt.option('version', stdout);
} else {
// fallback to the version in packge.json
var package_json = grunt.file.readJSON('package.json');
grunt.option('version', package_json.version);
}
callback();
},
},
},
},
debian_package: {
dist: {
options: {
version: grunt.option('version'),
dependencies: '',
maintainer: {
name: 'JD',
email: 'JD@example.com'
},
},
},
},
});
grunt.registerTask('package',[
'shell:get_version',
'debian_package:dist',
]);
}
Looking at the code you might even expect it to work. The problem is debian_package values are determined during grunt.initConfig(), so there's no opportunity to load values dynamically. When grunt.option('version') is called, shell:get_version has not yet run, so the value is undefined:
$ grunt package
Running "shell:get_version" (shell) task
Running "debian_package:dist" (debian_package) task
Warning: Cannot call method 'replaceAll' of undefined Use --force to continue.
I think this can be solved by making debian_package accept a function rather than an object during initConfig(). Something like this:
debian_package: {
dist: function() {
return {
options: {
version: grunt.option('version'),
dependencies: '',
maintainer: {
name: 'JD',
email: 'JD@example.com'
},
},
};
},
},
I was very excited to use grunt-debian-package, but until this is possible I cannot use it. If it is already possible somehow then I wasn't able to figure out how.
I have the same issue, any updates?
Not that I'm aware of. I had to abandon grunt-debian-package and go back to using a bash script.