Skip to content

Commit 7abab3e

Browse files
committed
[#98] Replaced globbing feature by a recursive swift files search.
1 parent 5cb1d45 commit 7abab3e

15 files changed

+81
-51
lines changed

Documentation/Migration_from_0.11.+_to_0.12.+.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Migration from v0.11.+ to v0.12.+
1+
# Migration from v0.11.+ to v0.12.1+
22

33
Weaver 0.12.0 comes with several breaking changes.
44

@@ -29,6 +29,7 @@ Options:
2929
--single-output
3030
--input-path - Paths to input files.
3131
--ignored-path - Paths to ignore.
32+
--recursive-off
3233
```
3334
3435
See the [documentation](https://github.com/scribd/Weaver#generate-swift-files) for details.
@@ -43,10 +44,10 @@ The command to add to the build phase looked like the following:
4344
weaver generate --output_path ${SOURCE_ROOT}/output/path `find ${SOURCE_ROOT} -name '*.swift' | xargs -0`
4445
```
4546
46-
With 0.12.+:
47+
With 0.12.1+:
4748
4849
This build phase should now be written like the following:
4950
5051
```bash
51-
weaver swift --project-path $PROJECT_DIR/$PROJECT_NAME --input-path "*.swift" --input-path "**/*.swift" --output-path output/relative/path
52+
weaver swift --project-path $PROJECT_DIR/$PROJECT_NAME --output-path output/relative/path
5253
```

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ Run the following to check if Weaver has been installed correctly.
102102

103103
```bash
104104
$ weaver swift --help
105-
106105
Usage:
107106

108107
$ weaver swift
@@ -116,14 +115,15 @@ Options:
116115
--single-output
117116
--input-path - Paths to input files.
118117
--ignored-path - Paths to ignore.
118+
--recursive-off
119119
```
120120
121121
### (2) - Weaver build phase
122122
123123
In Xcode, add the following command to a command line build phase:
124124
125125
```
126-
weaver swift --project-path $PROJECT_DIR/$PROJECT_NAME --input-path "*.swift" --input-path "**/*.swift" --output-path output/relative/path
126+
weaver swift --project-path $PROJECT_DIR/$PROJECT_NAME --output-path output/relative/path
127127
```
128128
129129
**Important - Move this build phase above the `Compile Source` phase so Weaver can generate the boilerplate code before compilation happens.**
@@ -352,12 +352,13 @@ Options:
352352
--single-output
353353
--input-path - Paths to input files.
354354
--ignored-path - Paths to ignore.
355+
--recursive-off
355356
```
356357
357358
### Example:
358359
359360
```bash
360-
weaver swift --project-path $PROJECT_DIR/$PROJECT_NAME --input-path "*.swift" --input-path "**/*.swift" --output-path Generated
361+
weaver swift --project-path $PROJECT_DIR/$PROJECT_NAME --output-path Generated
361362
```
362363
363364
### Parameters:
@@ -368,8 +369,9 @@ weaver swift --project-path $PROJECT_DIR/$PROJECT_NAME --input-path "*.swift" --
368369
- `--template-path`: Path to a custom rendering template.
369370
- `--unsafe`: Deactivates the dependency graph safety checks.
370371
- `--single-output`: Makes Weaver generate only one single Swift file.
371-
- `--input-path`: Path to the project's Swift code. Defaults to `project-path`. Supports [unix globbing](https://en.wikipedia.org/wiki/Glob_(programming)). Variadic parameter, which means it can be set more than once.
372+
- `--input-path`: Path to the project's Swift code. Defaults to `project-path`. Variadic parameter, which means it can be set more than once. By default, Weaver recursively read any Swift file located under the `input-path`.
372373
- `--ignored-path`: Same than `input-path` but for ignoring files which shouldn't be parsed by Weaver.
374+
- `--recursive-off`: Deactivates recursivity for `input-path` and `ignored-path`.
373375
374376
### Configuration File:
375377
@@ -382,12 +384,11 @@ Parameters are named the same, but snakecased.
382384
For example, the [sample project configuration](https://github.com/scribd/Weaver/blob/master/Sample/.sample.weaver.yaml) looks like:
383385
384386
```yaml
385-
output_path: "Sample/Generated"
387+
output_path: Sample/Generated
386388
input_paths:
387-
- "Sample/*.swift"
388-
- "Sample/**/*.swift"
389+
- Sample
389390
ignored_paths:
390-
- "Sample/Generated/*"
391+
- Sample/Generated
391392
```
392393
393394
## Export Dependency Graph
@@ -396,7 +397,6 @@ Weaver can ouput a JSON representation of the dependency graph of a project.
396397
397398
```bash
398399
$ weaver json --help
399-
400400
Usage:
401401

402402
$ weaver json
@@ -407,6 +407,7 @@ Options:
407407
--pretty [default: false]
408408
--input-path - Paths to input files.
409409
--ignored-path - Paths to ignore.
410+
--recursive-off
410411
```
411412
412413
For an output example, please check this [Gist](https://gist.github.com/trupin/9438713f8fae0a5a7f424eca1976f42b).
@@ -417,7 +418,6 @@ Weaver can output the input/output `xcfilelist` files which can then be added to
417418
418419
```bash
419420
$ weaver xcfilelist --help
420-
421421
Usage:
422422
423423
$ weaver xcfilelist
@@ -429,6 +429,7 @@ Options:
429429
--single-output
430430
--input-path - Paths to input files.
431431
--ignored-path - Paths to ignore.
432+
--recursive-off
432433
```
433434
434435
## Migration guides

Sample/.api.weaver.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
output_path: "API/Generated"
1+
output_path: API/Generated
22
input_paths:
3-
- "API/*.swift"
4-
- "API/**/*.swift"
3+
- API
54
ignored_paths:
6-
- "API/Generated/*"
5+
- API/Generated

Sample/.sample.weaver.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
output_path: "Sample/Generated"
1+
output_path: Sample/Generated
22
input_paths:
3-
- "Sample/*.swift"
4-
- "Sample/**/*.swift"
3+
- Sample
54
ignored_paths:
6-
- "Sample/Generated/*"
5+
- Sample/Generated

Sample/API/Generated/Weaver.API.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import Foundation
44
// MARK: - MovieAPI

Sample/API/Generated/Weaver.ImageManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import Foundation
44
import UIKit

Sample/API/Generated/Weaver.MovieManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import Foundation
44
// MARK: - MovieManager

Sample/Sample/Generated/Weaver.AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import API
44
import UIKit

Sample/Sample/Generated/Weaver.HomeViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import API
44
import Foundation

Sample/Sample/Generated/Weaver.MovieViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import API
44
import Foundation

Sample/Sample/Generated/Weaver.PersonManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import API
44
import Foundation

Sample/Sample/Generated/Weaver.ReviewManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import API
44
import Foundation

Sample/Sample/Generated/Weaver.WSReviewViewController+Injectable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// This file is generated by Weaver 0.12.0
1+
/// This file is generated by Weaver 0.12.1
22
/// DO NOT EDIT!
33
import Foundation
44
// MARK: - WSReviewViewController

Sources/WeaverCommand/Configuration.swift

+31-8
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,25 @@ struct Configuration {
1919
let ignoredPathStrings: [String]
2020
let unsafe: Bool
2121
let singleOutput: Bool
22+
let recursiveOff: Bool
2223

2324
private init(inputPathStrings: [String]?,
2425
ignoredPathStrings: [String]?,
2526
projectPath: Path?,
2627
outputPath: Path?,
2728
templatePath: Path?,
2829
unsafe: Bool?,
29-
singleOutput: Bool?) {
30+
singleOutput: Bool?,
31+
recursiveOff: Bool?) {
3032

31-
self.inputPathStrings = inputPathStrings ?? []
33+
self.inputPathStrings = inputPathStrings ?? Defaults.inputPathStrings
3234
self.ignoredPathStrings = ignoredPathStrings ?? []
3335
self.projectPath = projectPath ?? Defaults.projectPath
3436
self.outputPath = outputPath ?? Defaults.outputPath
3537
self.templatePath = templatePath ?? Defaults.templatePath
3638
self.unsafe = unsafe ?? Defaults.unsafe
3739
self.singleOutput = singleOutput ?? Defaults.singleOuput
40+
self.recursiveOff = recursiveOff ?? Defaults.recursiveOff
3841
}
3942

4043
init(configPath: Path? = nil,
@@ -44,7 +47,8 @@ struct Configuration {
4447
outputPath: Path? = nil,
4548
templatePath: Path? = nil,
4649
unsafe: Bool? = nil,
47-
singleOutput: Bool? = nil) throws {
50+
singleOutput: Bool? = nil,
51+
recursiveOff: Bool? = nil) throws {
4852

4953
let projectPath = projectPath ?? Defaults.projectPath
5054
let configPath = Configuration.prepareConfigPath(configPath ?? Defaults.configPath,
@@ -65,14 +69,16 @@ struct Configuration {
6569
outputPath: outputPath,
6670
templatePath: templatePath,
6771
unsafe: unsafe,
68-
singleOutput: singleOutput)
72+
singleOutput: singleOutput,
73+
recursiveOff: recursiveOff)
6974
}
7075

7176
self.inputPathStrings = inputPathStrings ?? configuration.inputPathStrings
7277
self.ignoredPathStrings = ignoredPathStrings ?? configuration.ignoredPathStrings
7378
self.projectPath = projectPath
7479
self.unsafe = unsafe ?? configuration.unsafe
7580
self.singleOutput = singleOutput ?? configuration.singleOutput
81+
self.recursiveOff = recursiveOff ?? configuration.recursiveOff
7682

7783
let outputPath = outputPath ?? configuration.outputPath
7884
self.outputPath = outputPath.isRelative ? projectPath + configuration.outputPath : outputPath
@@ -93,6 +99,10 @@ struct Configuration {
9399
}
94100
return configPath
95101
}
102+
103+
private var recursive: Bool {
104+
return !recursiveOff
105+
}
96106
}
97107

98108
// MARK: - Constants
@@ -106,6 +116,8 @@ extension Configuration {
106116
static let outputPath = Path(".")
107117
static let unsafe = false
108118
static let singleOuput = false
119+
static let recursiveOff = false
120+
static let inputPathStrings = ["."]
109121

110122
static var projectPath: Path {
111123
if let projectPath = ProcessInfo.processInfo.environment["WEAVER_PROJECT_PATH"] {
@@ -137,6 +149,7 @@ extension Configuration: Decodable {
137149
case ignoredPaths = "ignored_paths"
138150
case unsafe
139151
case singleOutput = "single_output"
152+
case recursive
140153
}
141154

142155
public init(from decoder: Decoder) throws {
@@ -149,10 +162,11 @@ extension Configuration: Decodable {
149162
projectPath = Defaults.projectPath
150163
outputPath = try container.decodeIfPresent(Path.self, forKey: .outputPath) ?? Defaults.outputPath
151164
templatePath = try container.decodeIfPresent(Path.self, forKey: .templatePath) ?? Defaults.templatePath
152-
inputPathStrings = try container.decode([String].self, forKey: .inputPaths)
165+
inputPathStrings = try container.decodeIfPresent([String].self, forKey: .inputPaths) ?? Defaults.inputPathStrings
153166
ignoredPathStrings = try container.decodeIfPresent([String].self, forKey: .ignoredPaths) ?? []
154167
unsafe = try container.decodeIfPresent(Bool.self, forKey: .unsafe) ?? Defaults.unsafe
155168
singleOutput = try container.decodeIfPresent(Bool.self, forKey: .singleOutput) ?? Defaults.singleOuput
169+
recursiveOff = !(try container.decodeIfPresent(Bool.self, forKey: .recursive) ?? !Defaults.recursiveOff)
156170
}
157171
}
158172

@@ -168,9 +182,18 @@ extension Path: Decodable {
168182

169183
extension Configuration {
170184

171-
var inputPaths: [Path] {
172-
let inputPaths = Set(inputPathStrings.flatMap { projectPath.glob($0) })
173-
let ignoredPaths = Set(ignoredPathStrings.flatMap { projectPath.glob($0) })
185+
func inputPaths() throws -> [Path] {
186+
187+
let inputPaths = try Set(inputPathStrings
188+
.map { projectPath + $0 }
189+
.flatMap { recursive ? try $0.recursiveChildren() : try $0.children() }
190+
.filter { $0.extension == "swift" })
191+
192+
let ignoredPaths = try Set(ignoredPathStrings
193+
.map { projectPath + $0 }
194+
.flatMap { recursive ? try $0.recursiveChildren() : try $0.children() }
195+
.filter { $0.extension == "swift" })
196+
174197
return inputPaths.subtracting(ignoredPaths).sorted()
175198
}
176199
}

0 commit comments

Comments
 (0)