Skip to content

Commit a537fa6

Browse files
authored
Merge pull request #12 from QuantGeekDev/fix/build-error
Fix/build error
2 parents 8812793 + adc7e48 commit a537fa6

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcp-framework",
3-
"version": "0.1.13",
3+
"version": "0.1.14",
44
"description": "Framework for building Model Context Protocol (MCP) servers in Typescript",
55
"type": "module",
66
"author": "Alex Andru <[email protected]>",

src/cli/framework/build.ts

+43-24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { readFileSync, writeFileSync, existsSync } from "fs";
33
import { join } from "path";
44
import { platform } from "os";
55

6+
interface NodeError extends Error {
7+
code?: string;
8+
}
9+
610
export function buildFramework() {
711
const isCreatingProject = process.argv.includes('create');
812
if (isCreatingProject) {
@@ -20,31 +24,40 @@ export function buildFramework() {
2024

2125
const isWindows = platform() === "win32";
2226
const nodeModulesPath = join(projectDir, "node_modules");
23-
const tscPath = join(nodeModulesPath, ".bin", isWindows ? "tsc.cmd" : "tsc");
24-
25-
if (!existsSync(tscPath)) {
26-
console.error("Error: TypeScript compiler not found at:", tscPath);
27-
process.exit(1);
28-
}
27+
const tscBin = join(nodeModulesPath, ".bin", "tsc");
28+
const tscPath = isWindows ? `${tscBin}.cmd` : tscBin;
2929

30-
const tsc = spawnSync(isWindows ? tscPath : "node",
31-
isWindows ? [] : [tscPath],
32-
{
30+
let spawnResult;
31+
32+
if (isWindows) {
33+
spawnResult = spawnSync(tscPath, [], {
34+
stdio: "inherit",
35+
env: process.env,
36+
shell: true
37+
});
38+
} else {
39+
spawnResult = spawnSync(tscPath, [], {
3340
stdio: "inherit",
3441
env: {
3542
...process.env,
36-
ELECTRON_RUN_AS_NODE: "1"
43+
ELECTRON_RUN_AS_NODE: "1"
3744
}
3845
});
46+
}
3947

40-
if (tsc.error) {
41-
console.error("TypeScript compilation error:", tsc.error);
48+
if (spawnResult.error) {
49+
const nodeError = spawnResult.error as NodeError;
50+
if (nodeError.code === 'ENOENT') {
51+
console.error("TypeScript compiler not found. Please ensure TypeScript is installed.");
52+
process.exit(1);
53+
}
54+
console.error("TypeScript compilation error:", nodeError);
4255
process.exit(1);
4356
}
4457

45-
if (tsc.status !== 0) {
58+
if (spawnResult.status !== 0) {
4659
console.error("TypeScript compilation failed");
47-
process.exit(tsc.status ?? 1);
60+
process.exit(spawnResult.status ?? 1);
4861
}
4962

5063
try {
@@ -55,19 +68,25 @@ export function buildFramework() {
5568
process.exit(1);
5669
}
5770

71+
const cliIndexPath = join(distPath, "cli", "index.js");
5872
const indexPath = join(distPath, "index.js");
59-
console.log("Adding shebang to:", indexPath);
60-
61-
if (!existsSync(indexPath)) {
62-
console.error("Error: index.js not found in dist directory!");
63-
process.exit(1);
73+
74+
const filesToAddShebang = [cliIndexPath, indexPath];
75+
76+
for (const filePath of filesToAddShebang) {
77+
if (existsSync(filePath)) {
78+
console.log("Adding shebang to:", filePath);
79+
const content = readFileSync(filePath, "utf8");
80+
const shebang = "#!/usr/bin/env node\n";
81+
82+
if (!content.startsWith(shebang)) {
83+
writeFileSync(filePath, shebang + content);
84+
}
85+
}
6486
}
6587

66-
const content = readFileSync(indexPath, "utf8");
67-
const shebang = "#!/usr/bin/env node\n";
68-
69-
if (!content.startsWith(shebang)) {
70-
writeFileSync(indexPath, shebang + content);
88+
if (!existsSync(indexPath)) {
89+
console.error("Warning: index.js not found in dist directory");
7190
}
7291
} catch (error) {
7392
console.error("Error in shebang process:", error);

0 commit comments

Comments
 (0)