@@ -3,6 +3,10 @@ import { readFileSync, writeFileSync, existsSync } from "fs";
3
3
import { join } from "path" ;
4
4
import { platform } from "os" ;
5
5
6
+ interface NodeError extends Error {
7
+ code ?: string ;
8
+ }
9
+
6
10
export function buildFramework ( ) {
7
11
const isCreatingProject = process . argv . includes ( 'create' ) ;
8
12
if ( isCreatingProject ) {
@@ -20,31 +24,40 @@ export function buildFramework() {
20
24
21
25
const isWindows = platform ( ) === "win32" ;
22
26
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 ;
29
29
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 , [ ] , {
33
40
stdio : "inherit" ,
34
41
env : {
35
42
...process . env ,
36
- ELECTRON_RUN_AS_NODE : "1"
43
+ ELECTRON_RUN_AS_NODE : "1"
37
44
}
38
45
} ) ;
46
+ }
39
47
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 ) ;
42
55
process . exit ( 1 ) ;
43
56
}
44
57
45
- if ( tsc . status !== 0 ) {
58
+ if ( spawnResult . status !== 0 ) {
46
59
console . error ( "TypeScript compilation failed" ) ;
47
- process . exit ( tsc . status ?? 1 ) ;
60
+ process . exit ( spawnResult . status ?? 1 ) ;
48
61
}
49
62
50
63
try {
@@ -55,19 +68,25 @@ export function buildFramework() {
55
68
process . exit ( 1 ) ;
56
69
}
57
70
71
+ const cliIndexPath = join ( distPath , "cli" , "index.js" ) ;
58
72
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
+ }
64
86
}
65
87
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" ) ;
71
90
}
72
91
} catch ( error ) {
73
92
console . error ( "Error in shebang process:" , error ) ;
0 commit comments