Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add template updater #100

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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;

Check warning on line 179 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L179

Added line #L179 was not covered by tests
}
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 }}';

Check warning on line 5 in lib/updaters/types/template.js

View check run for this annotation

Codecov / codecov/patch

lib/updaters/types/template.js#L5

Added line #L5 was not covered by tests
};

/* eslint-enable no-unused-vars */
module.exports.writeVersion = function (contents, version) {
return Handlebars.compile(contents)({ version });

Check warning on line 10 in lib/updaters/types/template.js

View check run for this annotation

Codecov / codecov/patch

lib/updaters/types/template.js#L10

Added line #L10 was not covered by tests
};
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
Loading