-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from yassram/new-export/csv
Support for CSV output
- Loading branch information
Showing
11 changed files
with
114 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Component,License,Origin,Copyright | ||
SwiftDate,MIT,https://github.com/malcommac/SwiftDate,"Copyright (c) 2018 Daniele Margutti" | ||
leveldb,BSD-3-Clause,https://github.com/firebase/leveldb,"Copyright (c) 2011 The LevelDB Authors. All rights reserved." | ||
swift-composable-architecture,MIT,https://github.com/pointfreeco/swift-composable-architecture,"Copyright (c) 2020 Point-Free, Inc." | ||
GoogleUtilities,Apache-2.0,https://github.com/google/GoogleUtilities,"Copyright (c) 2017 Landon J. Fuller <landon@landonf.org>" | ||
MSAL,MIT,https://github.com/AzureAD/microsoft-authentication-library-for-objc,"Copyright (c) Microsoft Corporation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import Foundation | ||
import LoggerAPI | ||
|
||
struct LicenseCSVHolder { | ||
let csv: String | ||
static func load(licenses: [LicenseInfo], options: Options) -> LicenseCSVHolder { | ||
var csv = [ | ||
"Component", | ||
"License", | ||
options.config.addSources ? "Origin" : nil, | ||
"Copyright" | ||
] | ||
.compactMap { $0 } | ||
.joined(separator: .delemiter) + .newLine | ||
|
||
for license in licenses { | ||
let component = license.name(withVersion: options.config.addVersionNumbers) | ||
let licenseType = license.licenseType.rawValue | ||
let copyright = license.copyright.quoted | ||
if options.config.addSources, let source = license.source { | ||
csv += [ | ||
component, | ||
licenseType, | ||
source, | ||
copyright | ||
].joined(separator: .delemiter) | ||
} else { | ||
csv += [ | ||
component, | ||
licenseType, | ||
copyright | ||
].joined(separator: .delemiter) | ||
} | ||
csv += .newLine | ||
} | ||
return LicenseCSVHolder(csv: csv) | ||
} | ||
|
||
func write(to csvPath: URL) { | ||
do { | ||
try csv.data(using: .utf8)!.write(to: csvPath) | ||
} catch { | ||
Log.error("Failed to write to (csvPath: \(csvPath)).\nerror: \(error)") | ||
} | ||
} | ||
} | ||
|
||
extension LicenseInfo { | ||
fileprivate var copyright: String { | ||
let copyrightRange = body.range( | ||
of: #"Copyright \(c\) .*"#, | ||
options: .regularExpression | ||
) | ||
return copyrightRange.map { String(body[$0]) } ?? "" | ||
} | ||
} | ||
|
||
extension String { | ||
fileprivate static let newLine = "\n" | ||
fileprivate static let delemiter = "," | ||
fileprivate var quoted: String { | ||
"\"" + self + "\"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters