33@preconcurrency import var Foundation. stderr
44@preconcurrency import struct Foundation. URL
55@preconcurrency import struct Foundation. Data
6+ @preconcurrency import struct Foundation. ObjCBool
67@preconcurrency import class Foundation. JSONEncoder
78@preconcurrency import class Foundation. FileManager
89@preconcurrency import class Foundation. JSONDecoder
10+ @preconcurrency import class Foundation. ProcessInfo
911import SwiftParser
1012
1113#if canImport(BridgeJSCore)
@@ -50,7 +52,7 @@ import TS2Skeleton
5052 do {
5153 try run ( )
5254 } catch {
53- printStderr ( " Error : \( error) " )
55+ printStderr ( " error : \( error) " )
5456 exit ( 1 )
5557 }
5658 }
@@ -83,6 +85,10 @@ import TS2Skeleton
8385 help: " Print verbose output " ,
8486 required: false
8587 ) ,
88+ " target-dir " : OptionRule (
89+ help: " The SwiftPM package target directory " ,
90+ required: true
91+ ) ,
8692 " output-swift " : OptionRule ( help: " The output file path for the Swift source code " , required: true ) ,
8793 " output-skeleton " : OptionRule (
8894 help: " The output file path for the skeleton of the imported TypeScript APIs " ,
@@ -99,6 +105,9 @@ import TS2Skeleton
99105 )
100106 let progress = ProgressReporting ( verbose: doubleDashOptions [ " verbose " ] == " true " )
101107 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)
102111 for inputFile in positionalArguments {
103112 if inputFile. hasSuffix ( " .json " ) {
104113 let sourceURL = URL ( fileURLWithPath: inputFile)
@@ -109,7 +118,7 @@ import TS2Skeleton
109118 importer. addSkeleton ( skeleton)
110119 } else if inputFile. hasSuffix ( " .d.ts " ) {
111120 let tsconfigPath = URL ( fileURLWithPath: doubleDashOptions [ " project " ] !)
112- try importer. addSourceFile ( inputFile, tsconfigPath: tsconfigPath. path)
121+ try importer. addSourceFile ( inputFile, tsconfigPath: tsconfigPath. path, nodePath : nodePath )
113122 }
114123 }
115124
0 commit comments