Skip to content

Commit e5d0cb0

Browse files
committed
publish to npm
1 parent 8170ae5 commit e5d0cb0

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dev": "tsx src/index.ts",
1717
"dev:bun": "bun run src/index.ts",
1818
"typecheck": "tsc --noEmit",
19+
"publish-package": "tsx scripts/publish.ts",
1920
"prepublishOnly": "npm run build"
2021
},
2122
"dependencies": {

scripts/publish.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env npx tsx
2+
/**
3+
* Publish x402scan-mcp to npm if version is bumped.
4+
* Also builds the .mcpb bundle for Claude Desktop.
5+
* Usage: bun run publish
6+
*/
7+
8+
import { execSync } from "child_process";
9+
import { readFileSync, existsSync } from "fs";
10+
import { join } from "path";
11+
12+
const PACKAGE_NAME = "x402scan-mcp";
13+
const ROOT = process.cwd();
14+
15+
function checkNpmAuth(): void {
16+
try {
17+
const user = execSync("npm whoami", { encoding: "utf-8", stdio: "pipe" }).trim();
18+
console.log(`✓ Logged in to npm as: ${user}`);
19+
} catch {
20+
console.error("❌ Not logged in to npm. Run `npm login` first.");
21+
process.exit(1);
22+
}
23+
}
24+
25+
function getLocalVersion(): string {
26+
const pkgPath = join(ROOT, "package.json");
27+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
28+
return pkg.version;
29+
}
30+
31+
function getNpmVersion(): string | null {
32+
try {
33+
const result = execSync(`npm view ${PACKAGE_NAME} version 2>/dev/null`, {
34+
encoding: "utf-8",
35+
}).trim();
36+
return result || null;
37+
} catch {
38+
return null; // Package not published yet
39+
}
40+
}
41+
42+
function compareVersions(local: string, remote: string | null): boolean {
43+
if (!remote) return true; // Not published, should publish
44+
45+
const localParts = local.split(".").map(Number);
46+
const remoteParts = remote.split(".").map(Number);
47+
48+
for (let i = 0; i < 3; i++) {
49+
if (localParts[i]! > remoteParts[i]!) return true;
50+
if (localParts[i]! < remoteParts[i]!) return false;
51+
}
52+
return false; // Same version
53+
}
54+
55+
function publish(): void {
56+
console.log("\n📦 Building...");
57+
execSync("bun run build", { cwd: ROOT, stdio: "inherit" });
58+
59+
console.log("\n📤 Publishing to npm...");
60+
execSync("npm publish --access public", { cwd: ROOT, stdio: "inherit" });
61+
62+
console.log("\n✅ Published to npm");
63+
}
64+
65+
function buildMcpb(): void {
66+
console.log("\n📦 Building .mcpb bundle for Claude Desktop...");
67+
execSync("bun run build:mcpb", { cwd: ROOT, stdio: "inherit" });
68+
69+
const mcpbPath = join(ROOT, "x402scan.mcpb");
70+
if (existsSync(mcpbPath)) {
71+
console.log("✅ Created x402scan.mcpb");
72+
console.log("\n⚠️ Remember to:");
73+
console.log(" 1. Commit and push x402scan.mcpb to GitHub");
74+
console.log(" 2. Create a GitHub release with the .mcpb attached");
75+
console.log("\n Users can then download from:");
76+
console.log(" https://github.com/merit-systems/x402scan-mcp/releases/latest");
77+
}
78+
}
79+
80+
async function main() {
81+
console.log("🔍 Checking package version...\n");
82+
83+
checkNpmAuth();
84+
85+
const local = getLocalVersion();
86+
const remote = getNpmVersion();
87+
88+
const status = remote ? `${remote}${local}` : `(new) ${local}`;
89+
const needsPublish = compareVersions(local, remote);
90+
91+
console.log(`\n${PACKAGE_NAME}: ${status}`);
92+
93+
if (!needsPublish) {
94+
console.log("\n✅ Package is up to date. Bump version in package.json to publish.");
95+
console.log(" e.g., npm version patch|minor|major");
96+
return;
97+
}
98+
99+
console.log("\n⬆️ Version bump detected, publishing...");
100+
publish();
101+
buildMcpb();
102+
103+
console.log("\n🎉 Done!");
104+
}
105+
106+
main().catch((err) => {
107+
console.error("Error:", err);
108+
process.exit(1);
109+
});

x402scan.mcpb

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)