Skip to content

Commit

Permalink
Move hardcoded output path to main.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed May 2, 2022
1 parent 780073d commit c2bee0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 1 addition & 4 deletions Sources/WebIDLToSwift/IDLBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ enum IDLBuilder {
"DOMMatrix_or_Float32Array_or_Float64Array",
]

static let outDir = "Sources/DOMKit/"
static func writeFile(named name: String, content: String) throws -> String {
let path = outDir + name + ".swift"
static func writeFile(path: String, content: String) throws {
if FileManager.default.fileExists(atPath: path) {
try FileManager.default.removeItem(atPath: path)
}
try (preamble + content).write(toFile: path, atomically: true, encoding: .utf8)
return path
}

static func generateIDLBindings(idl: [GenericCollection<IDLNode>]) throws -> SwiftSource {
Expand Down
5 changes: 3 additions & 2 deletions Sources/WebIDLToSwift/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ func main() {
do {
let startTime = Date()
let idl = try IDLParser.parseIDL()
let outputPath = "Sources/DOMKit/Generated.swift"
var contents: [SwiftSource] = []
print("Generating bindings...")
contents.append(try IDLBuilder.generateIDLBindings(idl: idl))
Expand All @@ -16,8 +17,8 @@ func main() {
contents.append(try IDLBuilder.generateStrings())
print("Generating union protocols...")
contents.append(try IDLBuilder.generateUnions())
let outputPath = try IDLBuilder.writeFile(
named: "Generated",
try IDLBuilder.writeFile(
path: outputPath,
content: contents.joined(separator: "\n\n").source)

SwiftFormatter.run(source: outputPath)
Expand Down

0 comments on commit c2bee0a

Please sign in to comment.