Skip to content

Commit 015ebea

Browse files
authored
Add version.ts instead of importing package.json in source code (#61)
Add version.ts
1 parent ee2e592 commit 015ebea

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

.github/scripts/update-version.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ async function updateVersion(newVersion) {
99
const files = {
1010
packageJson: './package.json',
1111
packageLockJson: './package-lock.json',
12+
versionTs: './src/version.ts',
1213
};
1314

1415
// package.json
@@ -23,6 +24,16 @@ async function updateVersion(newVersion) {
2324
packageLockJsonData.packages[""].version = newVersion;
2425
}
2526
await fs.writeFile(files.packageLockJson, JSON.stringify(packageLockJsonData, null, 2) + '\n');
27+
28+
// src/version.ts
29+
const versionTsData = await fs.readFile(files.versionTs, 'utf8');
30+
const updatedVersionTsData = versionTsData.replace(
31+
/const LINE_BOT_MCP_SERVER_VERSION = ".*?";/,
32+
`const LINE_BOT_MCP_SERVER_VERSION = "${newVersion}";`
33+
);
34+
await fs.writeFile(files.versionTs, updatedVersionTsData);
35+
36+
console.log(`Version updated to ${newVersion} in all files.`);
2637
}
2738

2839
async function verifyVersion(expectedVersion) {
@@ -41,6 +52,12 @@ async function verifyVersion(expectedVersion) {
4152
throw new Error(`package-lock.json root package version mismatch: expected ${expectedVersion}, found ${packageLockJsonData.packages[""].version}`);
4253
}
4354

55+
// src/version.ts
56+
const versionTsData = await fs.readFile('./src/version.ts', 'utf8');
57+
if (!versionTsData.includes(`const LINE_BOT_MCP_SERVER_VERSION = "${expectedVersion}";`)) {
58+
throw new Error(`src/version.ts version mismatch: expected ${expectedVersion}`);
59+
}
60+
4461
console.log(`All files have the correct version: ${expectedVersion}`);
4562
}
4663

@@ -54,7 +71,7 @@ async function verifyGitDiff() {
5471
return acc;
5572
}, { addedLines: 0, deletedLines: 0 });
5673

57-
if (addedLines !== 3 || deletedLines !== 3) {
74+
if (addedLines !== 4 || deletedLines !== 4) {
5875
throw new Error(`Unexpected number of changed lines: expected 4 added and 4 deleted, found ${addedLines} added and ${deletedLines} deleted`);
5976
}
6077

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2020
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2121
import * as line from "@line/bot-sdk";
2222
import { z } from "zod";
23-
import pkg from "../package.json" with { type: "json" };
23+
import { LINE_BOT_MCP_SERVER_VERSION, USER_AGENT } from "./version.js";
2424

2525
const NO_USER_ID_ERROR =
2626
"Error: Specify the userId or set the DESTINATION_USER_ID in the environment variables of this MCP Server.";
2727

2828
const server = new McpServer({
2929
name: "line-bot",
30-
version: pkg.version,
30+
version: LINE_BOT_MCP_SERVER_VERSION,
3131
});
3232

3333
const channelAccessToken = process.env.CHANNEL_ACCESS_TOKEN || "";
@@ -36,7 +36,7 @@ const destinationId = process.env.DESTINATION_USER_ID || "";
3636
const messagingApiClient = new line.messagingApi.MessagingApiClient({
3737
channelAccessToken: channelAccessToken,
3838
defaultHeaders: {
39-
"User-Agent": `${pkg.name}/${pkg.version}`,
39+
"User-Agent": USER_AGENT,
4040
},
4141
});
4242

src/version.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const LINE_BOT_MCP_SERVER_VERSION = "0.1.0-local";
2+
export const USER_AGENT = `@line/line-bot-mcp-server/${LINE_BOT_MCP_SERVER_VERSION}`;

0 commit comments

Comments
 (0)