
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
grunt-simple-version
Advanced tools
Easily update the version across your project. By default this updates the version field in package.json. Uses Semantic Versioning format.
Sample Gruntfile.js below. The version can take an optional map of file names as the options for files to update (other than package.json). For updating JSON files, the value is the name of the field to change. For instance, in this example bower.json has a field called version
.
module.exports = function(grunt)
{
grunt.loadNpmTasks('grunt-simple-version');
grunt.initConfig({
version: {
options : {
'bower.json' : 'version'
}
}
});
};
The target field property on a JSON file can also be nested using a dot-syntax style address. The example below would update a version
field on a meta
object.
grunt.initConfig({
version : {
options : {
'info.json' : 'meta.version'
}
}
});
Providing a value of cache-bust
to an HTML file will append any src or CSS href properties with the version number. For instance, <script src="main.js"></script>
would become <script src="main.js?v=1.0.0"></script>
. This will help invalid the browser cache for linked assets.
grunt.initConfig({
version : {
options : {
'deploy/index.html' : 'cache-bust'
}
}
});
A replacement function can be used to replace the version in the contents of a file. The function takes two arguments, the contents of the file and the version number to update to. The function must return an update string with the contents of the file.
grunt.initConfig({
version : {
options : {
'deploy/index.html' : function(content, version) {
return content.replace(
/\<\!\-\- Version .* \-\-\>/,
'<!-- Version ' + version + ' -->'
);
}
}
}
});
The target field also supports multiple options (fields, nested-fields, functions, cache-bust
) for a single file. The example below would update two fields in the JSON file with the version and do a dynamic function replacement.
grunt.initConfig({
version : {
options : {
'project.json' : [
'version',
'meta.version',
function(content, version){
content.description = "Current build version " + version;
}
]
}
}
});
Ways to set the version across the project:
# Return the current version
grunt version:current
# Set a specific version
grunt version:1.0.0-rc
# Bump the patch version e.g., 1.0.1 => 1.0.2
grunt version:patch
# Bump the patch version e.g., 1.2.1 => 1.3.0
grunt version:minor
# Bump the patch version e.g., 1.3.0 => 2.0.0
grunt version:major
FAQs
Update the project version across multiple files
We found that grunt-simple-version demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.