-
-
Save bwoods/4b49508a7bf2b318d7f257609498b0d3 to your computer and use it in GitHub Desktop.
Swift script to generate Acknowledgements.plists (in the Settings.bundle) for the licenses of open source software you are using in your application.
This file contains hidden or 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
// env -i swift Application/Acknowledgements.swift > $CODESIGNING_FOLDER_PATH/Settings.bundle/Acknowledgements.plist | |
import Foundation | |
let fileManager = FileManager() | |
let folders = try! fileManager.contentsOfDirectory(atPath: fileManager.currentDirectoryPath).sorted() | |
var specifiers = [[ "Type" : "PSGroupSpecifier", "Title" : "Open Source", "FooterText" : "This application uses the following third party libraries:" ]] | |
folders.forEach { folder in | |
if let path = [ "LICENSE.md", "LICENSE", "COPYING" ].lazy.map({ "\(folder)/\($0)" }).first(where: { fileManager.fileExists(atPath: $0) }) { | |
var license = (try! String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "(c)", with: "©")) | |
let regex = try! NSRegularExpression(pattern: "[^\\s]\\n([^\\n])") // remove hard-wrapping if any (\\s repects Markdown trailing spaces) | |
license = regex.stringByReplacingMatches(in: license, options:NSRegularExpression.MatchingOptions(rawValue: 0), range:NSMakeRange(0, (license as NSString).length), withTemplate:"$1") | |
specifiers.append([ "Type" : "PSGroupSpecifier", "Title" : "", "FooterText" : license ]) | |
specifiers.append([ "Type" : "PSTitleValueSpecifier", "Title" : folder, "Key" : folder, "DefaultValue" : "" ]) | |
} | |
} | |
let data = try! PropertyListSerialization.data(fromPropertyList: [ "PreferenceSpecifiers" : specifiers ], format: .xml, options: 0) | |
print(String(data: data, encoding: .utf8)!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment