Skip to content

Commit 09c767f

Browse files
authored
Merge pull request #17 from QuantGeekDev/feat/find-up
feat: add find-up
2 parents 2407b2d + 9f90df9 commit 09c767f

File tree

4 files changed

+224
-57
lines changed

4 files changed

+224
-57
lines changed

package-lock.json

+182-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcp-framework",
3-
"version": "0.1.17",
3+
"version": "0.1.18",
44
"description": "Framework for building Model Context Protocol (MCP) servers in Typescript",
55
"type": "module",
66
"author": "Alex Andru <[email protected]>",
@@ -21,7 +21,6 @@
2121
},
2222
"scripts": {
2323
"build": "tsc",
24-
"postbuild": "node ./dist/cli/framework/build.js",
2524
"watch": "tsc --watch",
2625
"prepare": "npm run build"
2726
},
@@ -40,6 +39,7 @@
4039
"@types/prompts": "^2.4.9",
4140
"commander": "^12.1.0",
4241
"execa": "^9.5.2",
42+
"find-up": "^7.0.0",
4343
"prompts": "^2.4.2",
4444
"typescript": "^5.3.3",
4545
"zod": "^3.23.8"

src/cli/framework/build.ts

+40-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,53 @@
11
import { execa } from "execa";
22
import { readFile, writeFile } from "fs/promises";
33
import { join } from "path";
4+
import { findUp } from "find-up";
45

56
export async function buildFramework() {
6-
const projectDir = process.cwd();
7-
8-
try {
9-
console.log(`Building project in: ${projectDir}`);
10-
11-
await execa("tsc", [], {
12-
stdio: "inherit",
13-
reject: true,
14-
cwd: projectDir
7+
const projectRoot = await findUp(async directory => {
8+
const pkgPath = join(directory, 'package.json');
9+
const tsConfigPath = join(directory, 'tsconfig.json');
10+
11+
try {
12+
const [pkgContent, tsConfigContent] = await Promise.all([
13+
readFile(pkgPath, 'utf8').catch(() => null),
14+
readFile(tsConfigPath, 'utf8').catch(() => null)
15+
]);
16+
17+
if (pkgContent && tsConfigContent) {
18+
const pkg = JSON.parse(pkgContent);
19+
return pkg.name === 'composer-mcp' ? directory : undefined;
20+
}
21+
} catch {
22+
return undefined;
23+
}
1524
});
1625

17-
const distPath = join(projectDir, "dist");
18-
const projectIndexPath = join(distPath, "index.js");
19-
const shebang = "#!/usr/bin/env node\n";
20-
21-
const content = await readFile(projectIndexPath, "utf8");
22-
if (!content.startsWith(shebang)) {
23-
await writeFile(projectIndexPath, shebang + content);
26+
if (!projectRoot) {
27+
throw new Error('Could not find target project root directory');
2428
}
2529

26-
console.log("Build complete!");
27-
} catch (error) {
28-
console.error("Build failed:", error instanceof Error ? error.message : error);
29-
process.exit(1);
30-
}
30+
try {
31+
await execa("tsc", [], {
32+
stdio: "inherit",
33+
reject: true,
34+
cwd: projectRoot
35+
});
36+
37+
const distPath = join(projectRoot, "dist");
38+
const projectIndexPath = join(distPath, "index.js");
39+
const shebang = "#!/usr/bin/env node\n";
40+
41+
const content = await readFile(projectIndexPath, "utf8");
42+
if (!content.startsWith(shebang)) {
43+
await writeFile(projectIndexPath, shebang + content);
44+
}
45+
} catch (error) {
46+
console.error("Build failed:", error instanceof Error ? error.message : error);
47+
process.exit(1);
48+
}
3149
}
3250

3351
if (import.meta.url === new URL(import.meta.url).href) {
34-
buildFramework().catch(console.error);
52+
buildFramework().catch(console.error);
3553
}

src/cli/project/create.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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";
76

87
export async function createProject(name?: string) {
98
let projectName: string;

0 commit comments

Comments
 (0)