Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert deps command output to produce JSON #252

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions Sources/Core/FileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,31 @@ public func loadSchemasForUrls(urls: Set<URL>) -> [(URL, Schema)] {

public func generateDeps(urls: Set<URL>) {
let urlSchemas = loadSchemasForUrls(urls: urls)
let deps = Set(urlSchemas.map { (url, schema) -> String in
([url] + schema.deps()).map { $0.path }.joined(separator: ":")
})
deps.forEach { dep in
print(dep)
var depsResult = [String: [String]]()

for (_, schema) in urlSchemas {
switch schema {
case let .object(root):
depsResult[root.name] = schema.deps().map {
FileSchemaLoader.sharedInstance.loadSchema($0)
}.compactMap {
switch $0 {
case let .object(depRoot):
return root.name == depRoot.name ? nil : depRoot.name
default:
return ""
}
}
default: continue
}
}

let encoder = JSONEncoder()
encoder.outputFormatting = JSONEncoder.OutputFormatting.prettyPrinted
if let data = try? encoder.encode(depsResult) {
if let jsonString = String(data: data, encoding: .utf8) {
print(jsonString)
}
}
}

Expand Down