Skip to content

Commit e71fc30

Browse files
committed
build: use standard-version to automate version bumping
1 parent efdff40 commit e71fc30

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

.ts_module_version_updater.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This module is used by standard-version to read/write the VERSION constant in
2+
// our .ts files.
3+
4+
const VERSION_PATTERN =
5+
/(?<=^export const VERSION = ")(\d+\.\d+\.\d+)(?="; \/\/ managed by standard-version, do not modify$)/m;
6+
7+
module.exports.readVersion = function (contents) {
8+
const match = VERSION_PATTERN.exec(contents);
9+
if (!match) {
10+
throw new Error(
11+
`Failed to find version, no match for pattern: ${VERSION_PATTERN}`,
12+
);
13+
}
14+
return match[0];
15+
};
16+
17+
module.exports.writeVersion = function (contents, version) {
18+
// ensure contents has a match for the pattern
19+
if (module.exports.readVersion(contents) === version) {
20+
return contents;
21+
}
22+
return contents.replace(VERSION_PATTERN, version);
23+
};

.versionrc.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"bumpFiles": [
3+
{
4+
"filename": "mod.ts",
5+
"updater": ".ts_module_version_updater.js"
6+
}
7+
]
8+
}

mod.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [RFC 7464]: https://datatracker.ietf.org/doc/html/rfc7464
66
*/
77

8+
export const VERSION = "0.0.0"; // managed by standard-version, do not modify
89
export const JSON_SEQ_START = "\x1E";
910
export const JSON_SEQ_END = "\n";
1011

0 commit comments

Comments
 (0)