Skip to content

Commit

Permalink
Add comments to script generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-liu committed Nov 28, 2016
1 parent 5da9697 commit 8d1dad7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions Scripts/anchors.swift
Expand Up @@ -42,7 +42,7 @@ func main() {

let pwdURL = URL(fileURLWithPath: fileManager.currentDirectoryPath)
let scriptURL = URL(fileURLWithPath: #file, relativeTo: pwdURL)
let sourcesURL = scriptURL.deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Sources")
let sourcesURL = scriptURL.appendingPathComponent("../../Sources")
let codeFileURL = sourcesURL.appendingPathComponent("ConstraintMaker+Anchors.swift")
let code = try! String(contentsOf: codeFileURL)

Expand Down Expand Up @@ -74,14 +74,15 @@ func main() {
"centerXWithinMargins",
"centerYWithinMargins",
]
let equals = anchors
var equals = anchors
.map { seedCode.replacingOccurrences(of: seedAnchor, with: $0) }
.joined(separator: "\n\n")

let equalsString = equals.joined(separator: "\n\n")
let relations = ["greaterThanOrEqualTo", "lessThanOrEqualTo"]
.map { equals.replacingOccurrences(of: "equalTo", with: $0) }
.map { equalsString.replacingOccurrences(of: "equalTo", with: $0) }

let finalCode = header + ([equals] + relations).joined(separator: "\n\n")
equals.insert("//== ↓ Generated by `swift Scripts/anchors.swift` ↓ ==", at: 1)
let finalCode = header + (equals + relations).joined(separator: "\n\n")

do {
try finalCode.write(to: codeFileURL, atomically: true, encoding: .utf8)
Expand Down
4 changes: 2 additions & 2 deletions Scripts/helpers.swift
Expand Up @@ -42,7 +42,7 @@ func main() {

let pwdURL = URL(fileURLWithPath: fileManager.currentDirectoryPath)
let scriptURL = URL(fileURLWithPath: #file, relativeTo: pwdURL)
let sourcesURL = scriptURL.deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Sources")
let sourcesURL = scriptURL.appendingPathComponent("../../Sources")
let codeFileURL = sourcesURL.appendingPathComponent("ConstraintMaker+Helpers.swift")
let code = try! String(contentsOf: codeFileURL)

Expand All @@ -57,7 +57,7 @@ func main() {
let relations = ["greaterThanOrEqualTo", "lessThanOrEqualTo"]
.map { seedCode.replacingOccurrences(of: "equalTo", with: $0) }

let finalCode = header + ([seedCode] + relations).joined(separator: "\n\n")
let finalCode = header + ([seedCode, "//== ↓ Generated by `swift Scripts/helpers.swift` ↓ =="] + relations).joined(separator: "\n\n")

do {
try finalCode.write(to: codeFileURL, atomically: true, encoding: .utf8)
Expand Down
2 changes: 2 additions & 0 deletions Sources/ConstraintMaker+Anchors.swift
Expand Up @@ -52,6 +52,8 @@ extension ConstraintMaker {

}

//== ↓ Generated by `swift Scripts/anchors.swift` ↓ ==

extension ConstraintMaker {

/// Make item.right equalTo item2.attribute * multiplier + constant
Expand Down
2 changes: 2 additions & 0 deletions Sources/ConstraintMaker+Helpers.swift
Expand Up @@ -109,6 +109,8 @@ extension ConstraintMaker {

}

//== ↓ Generated by `swift Scripts/helpers.swift` ↓ ==

extension ConstraintMaker {

/// Make item.with greaterThanOrEqualTo one value
Expand Down

0 comments on commit 8d1dad7

Please sign in to comment.