Skip to content

Commit

Permalink
Merge pull request #100 from immobiliare/template_updater
Browse files Browse the repository at this point in the history
feat: add template updater
  • Loading branch information
dnlup authored Feb 26, 2024
2 parents a077928 + 5b8f5b1 commit 596b41e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions lib/updaters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
11 changes: 11 additions & 0 deletions lib/updaters/types/template.js
Original file line number Diff line number Diff line change
@@ -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 });
};
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 596b41e

Please sign in to comment.