mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Merge pull request #1050 from sparkle-project/genapp
generate_appcast improvements
This commit is contained in:
commit
629c42d62d
2 files changed
+49
-11
No files matched your search
@@ -119,14 +119,45 @@ class ArchiveItem: CustomStringConvertible {
|
||||
return (self.archiveFileAttributes[.size] as! NSNumber).int64Value;
|
||||
}
|
||||
|
||||
var releaseNotesPath : URL {
|
||||
let basename = self.archivePath.deletingPathExtension();
|
||||
private var releaseNotesPath : URL? {
|
||||
var basename = self.archivePath.deletingPathExtension();
|
||||
if basename.pathExtension == "tar" { // tar.gz
|
||||
basename = basename.deletingPathExtension();
|
||||
}
|
||||
let releaseNotes = basename.appendingPathExtension("html");
|
||||
if !FileManager.default.fileExists(atPath: releaseNotes.path) {
|
||||
return nil;
|
||||
}
|
||||
return releaseNotes;
|
||||
}
|
||||
|
||||
private func getReleaseNotesAsHTMLFragment(_ path: URL) -> String? {
|
||||
if let html = try? String(contentsOf: path) {
|
||||
if html.utf8.count < 1000 &&
|
||||
!html.localizedCaseInsensitiveContains("<!DOCTYPE") &&
|
||||
!html.localizedCaseInsensitiveContains("<body") {
|
||||
return html;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
var releaseNotesHTML : String? {
|
||||
if let path = self.releaseNotesPath {
|
||||
return self.getReleaseNotesAsHTMLFragment(path);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
var releaseNotesURL : URL? {
|
||||
guard let escapedFilename = self.releaseNotesPath.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
|
||||
guard let path = self.releaseNotesPath else {
|
||||
return nil;
|
||||
}
|
||||
// The file is already used as inline description
|
||||
if self.getReleaseNotesAsHTMLFragment(path) != nil {
|
||||
return nil;
|
||||
}
|
||||
guard let escapedFilename = path.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
|
||||
return nil;
|
||||
}
|
||||
if let relative = self.feedURL {
|
||||
|
||||
@@ -23,6 +23,7 @@ func findOrCreateElement(name: String, parent: XMLElement) -> XMLElement {
|
||||
return element;
|
||||
}
|
||||
let element = XMLElement(name: name);
|
||||
linebreak(parent);
|
||||
parent.addChild(element);
|
||||
return element;
|
||||
}
|
||||
@@ -69,7 +70,9 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
channel = channelNodes[0] as! XMLElement;
|
||||
} else {
|
||||
channel = XMLElement(name: "channel");
|
||||
linebreak(channel);
|
||||
channel.addChild(XMLElement.element(withName: "title", stringValue: appBaseName) as! XMLElement);
|
||||
linebreak(root);
|
||||
root.addChild(channel);
|
||||
}
|
||||
|
||||
@@ -102,6 +105,13 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement);
|
||||
}
|
||||
|
||||
if let html = update.releaseNotesHTML {
|
||||
let descElement = findOrCreateElement(name: "description", parent: item);
|
||||
let cdata = XMLNode(kind:.text, options:.nodeIsCDATA);
|
||||
cdata.stringValue = html;
|
||||
descElement.setChildren([cdata]);
|
||||
}
|
||||
|
||||
var minVer = findElement(name: "sparkle:minimumSystemVersion", parent: item);
|
||||
if nil == minVer {
|
||||
minVer = XMLElement.element(withName: "sparkle:minimumSystemVersion", uri: sparkleNS) as? XMLElement;
|
||||
@@ -111,16 +121,13 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
minVer?.setChildren([text(update.minimumSystemVersion)]);
|
||||
|
||||
let relElement = findElement(name: "sparkle:releaseNotesLink", parent: item);
|
||||
if nil == relElement {
|
||||
if FileManager.default.fileExists(atPath: update.releaseNotesPath.path) {
|
||||
if let url = update.releaseNotesURL {
|
||||
if nil == relElement {
|
||||
linebreak(item);
|
||||
item.addChild(XMLElement.element(withName:"sparkle:releaseNotesLink", stringValue: (update.releaseNotesURL?.absoluteString)!) as! XMLElement);
|
||||
}
|
||||
} else {
|
||||
if !FileManager.default.fileExists(atPath: update.releaseNotesPath.path) {
|
||||
let childIndex = relElement?.index;
|
||||
item.removeChild(at: childIndex!);
|
||||
item.addChild(XMLElement.element(withName:"sparkle:releaseNotesLink", stringValue: url.absoluteString) as! XMLElement);
|
||||
}
|
||||
} else if let childIndex = relElement?.index {
|
||||
item.removeChild(at: childIndex);
|
||||
}
|
||||
|
||||
var enclosure = findElement(name: "enclosure", parent: item);
|
||||
|
||||
Reference in new issue
Block a user