Skip to content

Commit 1986a4a

Browse files
committed
chore: changeset preparations
1 parent 9a19dfe commit 1986a4a

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

liblab.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"githubRepoName": "magicbell-java-client",
3131
"ignoreFiles": [],
3232
"includeKotlinSnippets": true,
33-
"sdkVersion": "0.0.1",
33+
"sdkVersion": "0.0.0",
3434
"liblabVersion": "2"
3535
}
3636
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "magicbell-java-client",
3+
"version": "0.0.1",
34
"private": true,
45
"type": "module",
56
"scripts": {
6-
"codegen": "tsx scripts/build.ts"
7+
"changeset": "./scripts/changeset-wrapper.sh"
78
},
89
"devDependencies": {
910
"@changesets/changelog-github": "^0.5.0",

scripts/changeset-wrapper.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# make sure the script runs relative to the repo root
4+
set -euo pipefail && cd "$(dirname "${BASH_SOURCE[0]}")/.."
5+
6+
# some helpers and error handling:
7+
info() { printf "%s\n" "$*" >&1; }
8+
error() { printf "%s\n" "$*" >&2; }
9+
trap 'echo Changeset interrupted >&2; exit 2' INT TERM
10+
11+
# pass all arguments to changeset
12+
./node_modules/.bin/changeset "$@"
13+
14+
changeset_exit=$?
15+
if [ ${changeset_exit} -gt 0 ];
16+
then
17+
error "Changeset finished with error"
18+
exit ${changeset_exit}
19+
fi
20+
21+
# if first argument was `version` also run the `update-version.ts` script
22+
args=("$@")
23+
if [ $# -gt 0 ] && [ ${args[0]} = "version" ]
24+
then
25+
yarn tsx scripts/update-version.ts
26+
fi

scripts/update-version.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { replaceInFile } from "replace-in-file";
2+
3+
import pkgJson from "../package.json";
4+
5+
const version = pkgJson.version;
6+
7+
const replacements = [
8+
{
9+
files: [
10+
"liblab.config.json",
11+
"README.md",
12+
"pom.xml",
13+
"example/pom.xml",
14+
"kotlin-example/pom.xml",
15+
],
16+
17+
from: [
18+
/\"sdkVersion\": \"\d.\d.\d\"/g,
19+
/MagicbellJavaClient Java SDK \d.\d.\d/g,
20+
/- SDK version: `\d.\d.\d`/g,
21+
/<artifactId>magicbell-java-client<\/artifactId>\n.*<version>\d.\d.\d<\/version>/g,
22+
],
23+
to: [
24+
`"sdkVersion": "${version}"`,
25+
`MagicbellJavaClient Java SDK ${version}`,
26+
`- SDK version: \`${version}\``,
27+
(artifactVersion: string) => artifactVersion.replace(/\d.\d.\d/, version),
28+
],
29+
},
30+
];
31+
32+
await Promise.all(replacements.map((options) => replaceInFile(options))).catch(
33+
(e) => {
34+
process.stdout.write(
35+
`Error updating version via update-version.ts: ${e}\n`
36+
);
37+
process.exit(1);
38+
}
39+
);

0 commit comments

Comments
 (0)