diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js index 912c0cd29..026daec50 100644 --- a/lib/lifecycles/bump.js +++ b/lib/lifecycles/bump.js @@ -164,10 +164,20 @@ function updateConfigs(args, newVersion) { const configPath = path.resolve(process.cwd(), updater.filename); try { if (dotgit.ignore(configPath)) return; - const stat = fs.lstatSync(configPath); - - if (!stat.isFile()) return; - const contents = fs.readFileSync(configPath, 'utf8'); + let contents; + /** + * `data` field is used to pass raw file contents. It's uswfule to pass + * template strings to compile with Handlebars, but it could also be used + * for other use cases. + */ + if (!updater.data) { + const stat = fs.lstatSync(configPath); + + if (!stat.isFile()) return; + contents = fs.readFileSync(configPath, 'utf8'); + } else { + contents = updater.data; + } checkpoint( args, 'bumping version in ' + updater.filename + ' from %s to %s', diff --git a/lib/updaters/index.js b/lib/updaters/index.js index 1813d1c71..a42e02ed8 100644 --- a/lib/updaters/index.js +++ b/lib/updaters/index.js @@ -3,6 +3,7 @@ const JSON_BUMP_FILES = require('../../defaults').bumpFiles; const updatersByType = { json: require('./types/json'), 'plain-text': require('./types/plain-text'), + template: require('./types/template'), }; const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']; diff --git a/lib/updaters/types/template.js b/lib/updaters/types/template.js new file mode 100644 index 000000000..8ab650072 --- /dev/null +++ b/lib/updaters/types/template.js @@ -0,0 +1,11 @@ +const Handlebars = require('handlebars'); + +/* eslint-disable no-unused-vars */ +module.exports.readVersion = function (_contents) { + return '{{ version }}'; +}; + +/* eslint-enable no-unused-vars */ +module.exports.writeVersion = function (contents, version) { + return Handlebars.compile(contents)({ version }); +}; diff --git a/package-lock.json b/package-lock.json index 6daefcc02..e550f991a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "figures": "^3.1.0", "find-up": "^5.0.0", "git-semver-tags": "^7.0.1", + "handlebars": "^4.7.8", "semver": "^7.1.1", "stringify-package": "^1.0.1", "yargs": "^17.5.1" diff --git a/package.json b/package.json index 7f8672f13..13ff02a97 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "figures": "^3.1.0", "find-up": "^5.0.0", "git-semver-tags": "^7.0.1", + "handlebars": "^4.7.8", "semver": "^7.1.1", "stringify-package": "^1.0.1", "yargs": "^17.5.1"