@@ -11,38 +11,26 @@ export async function buildFramework() {
11
11
const startDir = process . cwd ( ) ;
12
12
process . stderr . write ( `Starting search from: ${ startDir } \n` ) ;
13
13
14
- let projectRoot : string | null = null ;
14
+ if ( process . argv . includes ( 'create' ) ) {
15
+ process . stderr . write ( `Skipping build for create command\n` ) ;
16
+ return ;
17
+ }
18
+
15
19
try {
16
20
const pkgPath = join ( startDir , 'package.json' ) ;
17
- const tsConfigPath = join ( startDir , 'tsconfig.json' ) ;
18
-
19
- process . stderr . write ( `Checking for package.json at: ${ pkgPath } \n` ) ;
20
- const [ pkgContent , _tsConfigContent ] = await Promise . all ( [
21
- readFile ( pkgPath , 'utf8' ) ,
22
- readFile ( tsConfigPath , 'utf8' )
23
- ] ) ;
24
-
21
+ const pkgContent = await readFile ( pkgPath , 'utf8' ) ;
25
22
const pkg = JSON . parse ( pkgContent ) ;
26
- if ( pkg . dependencies ?. [ "mcp-framework" ] ) {
27
- projectRoot = startDir ;
28
- process . stderr . write ( `Found MCP project at current directory: ${ projectRoot } \n` ) ;
23
+
24
+ if ( ! pkg . dependencies ?. [ "mcp-framework" ] ) {
25
+ throw new Error ( "This directory is not an MCP project (mcp-framework not found in dependencies)" ) ;
29
26
}
30
- } catch ( error ) {
31
- process . stderr . write ( `Error checking current directory: ${ error instanceof Error ? error . message : String ( error ) } \n` ) ;
32
- }
33
-
34
- if ( ! projectRoot ) {
35
- process . stderr . write ( "Error: Current directory is not an MCP project\n" ) ;
36
- throw new Error ( 'Current directory must be an MCP project with mcp-framework as a dependency' ) ;
37
- }
38
-
39
- try {
40
- process . stderr . write ( `Running tsc in ${ projectRoot } \n` ) ;
27
+
28
+ process . stderr . write ( `Running tsc in ${ startDir } \n` ) ;
41
29
42
30
const tscCommand = process . platform === 'win32' ? [ 'npx.cmd' , 'tsc' ] : [ 'npx' , 'tsc' ] ;
43
31
44
32
await execa ( tscCommand [ 0 ] , [ tscCommand [ 1 ] ] , {
45
- cwd : projectRoot ,
33
+ cwd : startDir ,
46
34
stdio : "inherit" ,
47
35
env : {
48
36
...process . env ,
@@ -51,7 +39,7 @@ export async function buildFramework() {
51
39
}
52
40
} ) ;
53
41
54
- const distPath = join ( projectRoot , "dist" ) ;
42
+ const distPath = join ( startDir , "dist" ) ;
55
43
const projectIndexPath = join ( distPath , "index.js" ) ;
56
44
const shebang = "#!/usr/bin/env node\n" ;
57
45
@@ -68,7 +56,7 @@ export async function buildFramework() {
68
56
69
57
process . stderr . write ( "Build completed successfully!\n" ) ;
70
58
} catch ( error ) {
71
- process . stderr . write ( `Build error : ${ error instanceof Error ? error . message : String ( error ) } \n` ) ;
59
+ process . stderr . write ( `Error : ${ error instanceof Error ? error . message : String ( error ) } \n` ) ;
72
60
process . exit ( 1 ) ;
73
61
}
74
62
}
@@ -80,3 +68,5 @@ if (import.meta.url.startsWith('file:')) {
80
68
process . exit ( 1 ) ;
81
69
} ) ;
82
70
}
71
+
72
+ export default buildFramework ;
0 commit comments