3
3
@preconcurrency import var Foundation. stderr
4
4
@preconcurrency import struct Foundation. URL
5
5
@preconcurrency import struct Foundation. Data
6
+ @preconcurrency import struct Foundation. ObjCBool
6
7
@preconcurrency import class Foundation. JSONEncoder
7
8
@preconcurrency import class Foundation. FileManager
8
9
@preconcurrency import class Foundation. JSONDecoder
10
+ @preconcurrency import class Foundation. ProcessInfo
9
11
import SwiftParser
10
12
11
13
#if canImport(BridgeJSCore)
@@ -50,7 +52,7 @@ import TS2Skeleton
50
52
do {
51
53
try run ( )
52
54
} catch {
53
- printStderr ( " Error : \( error) " )
55
+ printStderr ( " error : \( error) " )
54
56
exit ( 1 )
55
57
}
56
58
}
@@ -83,6 +85,10 @@ import TS2Skeleton
83
85
help: " Print verbose output " ,
84
86
required: false
85
87
) ,
88
+ " target-dir " : OptionRule (
89
+ help: " The SwiftPM package target directory " ,
90
+ required: true
91
+ ) ,
86
92
" output-swift " : OptionRule ( help: " The output file path for the Swift source code " , required: true ) ,
87
93
" output-skeleton " : OptionRule (
88
94
help: " The output file path for the skeleton of the imported TypeScript APIs " ,
@@ -99,6 +105,9 @@ import TS2Skeleton
99
105
)
100
106
let progress = ProgressReporting ( verbose: doubleDashOptions [ " verbose " ] == " true " )
101
107
var importer = ImportTS ( progress: progress, moduleName: doubleDashOptions [ " module-name " ] !)
108
+ let targetDirectory = URL ( fileURLWithPath: doubleDashOptions [ " target-dir " ] !)
109
+ let config = try BridgeJSConfig . load ( targetDirectory: targetDirectory)
110
+ let nodePath : URL = try config. findTool ( " node " , targetDirectory: targetDirectory)
102
111
for inputFile in positionalArguments {
103
112
if inputFile. hasSuffix ( " .json " ) {
104
113
let sourceURL = URL ( fileURLWithPath: inputFile)
@@ -109,7 +118,7 @@ import TS2Skeleton
109
118
importer. addSkeleton ( skeleton)
110
119
} else if inputFile. hasSuffix ( " .d.ts " ) {
111
120
let tsconfigPath = URL ( fileURLWithPath: doubleDashOptions [ " project " ] !)
112
- try importer. addSourceFile ( inputFile, tsconfigPath: tsconfigPath. path)
121
+ try importer. addSourceFile ( inputFile, tsconfigPath: tsconfigPath. path, nodePath : nodePath )
113
122
}
114
123
}
115
124
0 commit comments