Question

I need to run grunt-bump which bumps the version number in the package.json, then run grunt-xmlpoke and update a config file with new version number.

So I have tried a couple of things. Inside the grunt.initConfig I run bump, then I run xmlpoke.

1) xmlpoke takes grunt.file.readJSON('package.json').version

or

2) after bump I run a custom task that adds the new version to a grunt option and xmlpoke takes a value of grunt.options("versionNumber")

In both of these versions the xml result is the pre-bump version. So xmlpoke is getting it's values before the tasks are run and the uses them when it's task is called. But I need it to take the value that is the result of a previous task.

Is there anyway to do this?

Was it helpful?

Solution

Ok, I have figured out the, somewhat obvious, solution.

Using grunt-bump you can update the package.config, you can also update the package.config that is often read into the variable pkg at the beginning of the initConfig. so in the setup of the bump task you specify

{
updateConfigs:['pkg']
}

Then in the xmlpoke I can do

{ xpath:'myxpath', value:'blablabla/<%=pkg.version%>'}  

and this works. What I was doing before was

{ xpath:'myxpath', value:'blablabla/' + grunt.options.versionNumber}

where I had set the versionnumber in a previous task after the bump. Or

{ xpath:'myxpath', value:'blablabla/'+ grunt.file.readJSON('package.json').version}

neither of those worked. I guess I was just getting to smart for my own good as the <%= %> is the more common and typical way of accessing parameters from within the initConfig.

Anyway, there you have it. Or I have it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top