File tree 3 files changed +26
-6
lines changed
3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,18 @@ export default class Config {
30
30
return outputDirectoryPath ;
31
31
}
32
32
33
+ getBatteryDirectoryPaths ( ) : string [ ] {
34
+ const __dirname = url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
35
+ const ciProjectPath = `${ __dirname } /../ci/LDKSwift` ;
36
+ const xcodeProjectPath = `${ __dirname } /../xcode/LDKFramework` ;
37
+ return [
38
+ `${ ciProjectPath } /Sources/LDKSwift/batteries/` ,
39
+ `${ ciProjectPath } /Tests/LDKSwiftTests/` ,
40
+ `${ xcodeProjectPath } /DirectlyLinkedBindingsApp/` ,
41
+ `${ xcodeProjectPath } /DirectlyLinkedBindingsAppTests/` ,
42
+ ] ;
43
+ }
44
+
33
45
getSwiftFormatterBinaryPath ( ) : string | null {
34
46
let swiftformatPath = process . env [ 'SWIFT_FORMAT_PATH' ] ;
35
47
if ( ! swiftformatPath ) {
Original file line number Diff line number Diff line change @@ -154,24 +154,32 @@ export default class Generator {
154
154
}
155
155
}
156
156
157
- async runFormatter ( ) {
157
+ async runFormatter ( formatBatteryFiles = false ) {
158
158
const configFilePath = url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) + '../../.swift-format' ;
159
159
const outputDirectory = this . parser . config . getOutputBaseDirectoryPath ( ) ;
160
160
const swiftFormatterBinary = this . parser . config . getSwiftFormatterBinaryPath ( ) ;
161
161
if ( ! swiftFormatterBinary ) {
162
162
return ;
163
163
}
164
164
165
+ const paths = [ outputDirectory ] ;
166
+ if ( formatBatteryFiles ) {
167
+ paths . push ( ...this . parser . config . getBatteryDirectoryPaths ( ) ) ;
168
+ }
169
+
165
170
try {
166
171
const command = `${ swiftFormatterBinary } --configuration ${ configFilePath } --recursive --in-place ./ ` ;
167
172
console . log ( command ) ;
168
- child_process . execSync ( command , {
169
- cwd : outputDirectory
170
- } ) . toString ( 'utf-8' ) ;
173
+ for ( const currentDirectory of paths ) {
174
+ console . log ( currentDirectory ) ;
175
+ child_process . execSync ( command , {
176
+ cwd : currentDirectory
177
+ } ) . toString ( 'utf-8' ) ;
178
+ }
171
179
} catch ( e ) {
172
180
const errorOutput = e . stderr . toString ( 'utf-8' ) . trim ( ) ;
173
181
console . error ( 'Failed to format Swift output:' , errorOutput ) ;
174
- throw new Error ( errorOutput )
182
+ throw new Error ( errorOutput ) ;
175
183
}
176
184
177
185
// after all is generated and formatted, we generate the version file
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import Generator from './generation/index.mjs';
18
18
19
19
await generator . generateTypes ( ) ;
20
20
await generator . generateFunctions ( ) ;
21
- await generator . runFormatter ( ) ;
21
+ await generator . runFormatter ( true ) ;
22
22
} ) ( ) ;
23
23
24
24
interface NullTest {
You can’t perform that action at this time.
0 commit comments