Skip to content

Commit ec87841

Browse files
committedJan 20, 2025
fix: tsconfig not found
1 parent 2a3d12d commit ec87841

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed
 

‎src/cli/framework/build.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
#!/usr/bin/env node
21
import { spawnSync } from "child_process";
3-
import { readFileSync, writeFileSync } from "fs";
2+
import { readFileSync, writeFileSync, existsSync } from "fs";
43
import { join } from "path";
54
import { platform } from "os";
6-
import { existsSync } from "fs";
75

86
export function buildFramework() {
9-
const tsconfigPath = join(process.cwd(), "tsconfig.json");
7+
const isCreatingProject = process.argv.includes('create');
8+
if (isCreatingProject) {
9+
return;
10+
}
11+
12+
const projectDir = process.cwd();
13+
const tsconfigPath = join(projectDir, "tsconfig.json");
14+
1015
if (!existsSync(tsconfigPath)) {
1116
console.error("Error: tsconfig.json not found!");
1217
process.exit(1);
1318
}
1419
console.log("Found tsconfig.json");
20+
1521
const isWindows = platform() === "win32";
16-
const tscPath = join(
17-
process.cwd(),
18-
"node_modules",
19-
".bin",
20-
isWindows ? "tsc.cmd" : "tsc"
21-
);
22+
const nodeModulesPath = join(projectDir, "node_modules");
23+
const tscPath = join(nodeModulesPath, ".bin", isWindows ? "tsc.cmd" : "tsc");
2224

2325
if (!existsSync(tscPath)) {
2426
console.error("Error: TypeScript compiler not found at:", tscPath);
@@ -30,8 +32,8 @@ export function buildFramework() {
3032
shell: true,
3133
env: {
3234
...process.env,
33-
PATH: process.env.PATH,
34-
},
35+
PATH: process.env.PATH
36+
}
3537
});
3638

3739
if (tsc.error) {
@@ -47,14 +49,14 @@ export function buildFramework() {
4749
}
4850

4951
try {
50-
const distPath = join(process.cwd(), "dist");
52+
const distPath = join(projectDir, "dist");
5153

5254
if (!existsSync(distPath)) {
5355
console.error("Error: dist directory not found after compilation!");
5456
process.exit(1);
5557
}
5658

57-
const indexPath = join(process.cwd(), "dist", "index.js");
59+
const indexPath = join(distPath, "index.js");
5860
console.log("Adding shebang to:", indexPath);
5961

6062
if (!existsSync(indexPath)) {

‎src/cli/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ program
1414
.version("0.1.8");
1515

1616
program
17-
.command("build-framework", { hidden: true })
18-
.description("Build the MCP framework")
17+
.command("build")
18+
.description("Build the MCP project")
1919
.action(buildFramework);
2020

2121
program

‎src/cli/project/create.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mkdir, writeFile } from "fs/promises";
33
import { join } from "path";
44
import prompts from "prompts";
55
import { generateReadme } from "../templates/readme.js";
6+
import { platform } from "os";
67

78
export async function createProject(name?: string) {
89
let projectName: string;
@@ -119,22 +120,17 @@ export default ExampleTool;`;
119120

120121
console.log("Creating project files...");
121122
await Promise.all([
122-
writeFile(
123-
join(projectDir, "package.json"),
124-
JSON.stringify(packageJson, null, 2)
125-
),
126-
writeFile(
127-
join(projectDir, "tsconfig.json"),
128-
JSON.stringify(tsconfig, null, 2)
129-
),
123+
writeFile(join(projectDir, "package.json"), JSON.stringify(packageJson, null, 2)),
124+
writeFile(join(projectDir, "tsconfig.json"), JSON.stringify(tsconfig, null, 2)),
130125
writeFile(join(projectDir, "README.md"), generateReadme(projectName)),
131126
writeFile(join(srcDir, "index.ts"), indexTs),
132127
writeFile(join(toolsDir, "ExampleTool.ts"), exampleToolTs),
133128
]);
134129

130+
process.chdir(projectDir);
131+
135132
console.log("Initializing git repository...");
136133
const gitInit = spawnSync("git", ["init"], {
137-
cwd: projectDir,
138134
stdio: "inherit",
139135
shell: true,
140136
});
@@ -145,7 +141,6 @@ export default ExampleTool;`;
145141

146142
console.log("Installing dependencies...");
147143
const npmInstall = spawnSync("npm", ["install"], {
148-
cwd: projectDir,
149144
stdio: "inherit",
150145
shell: true,
151146
});
@@ -156,9 +151,9 @@ export default ExampleTool;`;
156151

157152
console.log("Building project...");
158153
const npmBuild = spawnSync("npm", ["run", "build"], {
159-
cwd: projectDir,
160154
stdio: "inherit",
161155
shell: true,
156+
env: process.env
162157
});
163158

164159
if (npmBuild.status !== 0) {

0 commit comments

Comments
 (0)
Please sign in to comment.