-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack-mcpb.mjs
More file actions
81 lines (71 loc) · 2.56 KB
/
pack-mcpb.mjs
File metadata and controls
81 lines (71 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Pack the MCP server into an .mcpb bundle (ZIP with manifest + server + node_modules).
* Run from repo root: node scripts/pack-mcpb.mjs
* Prerequisite: npm run build
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { spawnSync } from "node:child_process";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.resolve(__dirname, "..");
const buildDir = path.join(root, ".mcpb-build");
const outFile = path.join(root, "acc-mcp.mcpb");
// Clean and create bundle dir
if (fs.existsSync(buildDir)) fs.rmSync(buildDir, { recursive: true });
fs.mkdirSync(buildDir, { recursive: true });
fs.mkdirSync(path.join(buildDir, "server"), { recursive: true });
// Copy manifest
fs.copyFileSync(path.join(root, "manifest.json"), path.join(buildDir, "manifest.json"));
// Copy server entry (dist -> server/)
const distDir = path.join(root, "dist");
for (const name of ["index.js", "aps-auth.js", "aps-issues-helpers.js", "aps-dm-helpers.js"]) {
const src = path.join(distDir, name);
if (!fs.existsSync(src)) throw new Error(`Build first: missing ${src}`);
fs.copyFileSync(src, path.join(buildDir, "server", name));
}
// Bundle package.json (dependencies only for production install)
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
const bundlePkg = {
name: pkg.name,
version: pkg.version,
type: "module",
dependencies: pkg.dependencies || {},
};
fs.writeFileSync(path.join(buildDir, "package.json"), JSON.stringify(bundlePkg, null, 2));
// Install production deps in bundle dir
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
const install = spawnSync(npm, ["install", "--omit=dev"], {
cwd: buildDir,
stdio: "inherit",
shell: true,
});
if (install.status !== 0) {
console.error("npm install in bundle failed");
process.exit(1);
}
// Create .mcpb (ZIP) using system command
const buildDirAbs = path.resolve(buildDir);
const outFileAbs = path.resolve(outFile);
if (process.platform === "win32") {
// PowerShell: compress contents of buildDir into outFile
const ps = spawnSync(
"powershell",
[
"-NoProfile",
"-Command",
`Compress-Archive -Path "${buildDirAbs}\\*" -DestinationPath "${outFileAbs}" -Force`,
],
{ stdio: "inherit" }
);
if (ps.status !== 0) process.exit(1);
} else {
const zip = spawnSync("zip", ["-r", outFileAbs, "."], {
cwd: buildDir,
stdio: "inherit",
});
if (zip.status !== 0) process.exit(1);
}
// Cleanup
fs.rmSync(buildDir, { recursive: true });
console.log(`Created ${outFile}`);