-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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 #174292 from Homebrew/findappcast
find-appcast: convert from developer script to command
- Loading branch information
Showing
2 changed files
with
69 additions
and
95 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,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cli/parser" | ||
require "formula" | ||
require "open3" | ||
require "pathname" | ||
require "yaml" | ||
require "net/http" | ||
require "uri" | ||
|
||
module Homebrew | ||
module_function | ||
|
||
sig { returns(CLI::Parser) } | ||
def find_appcast_args | ||
Homebrew::CLI::Parser.new do | ||
usage_banner <<~EOS | ||
`find-appcast` <app_path> | ||
Finds the appcast for a given app when a path is provided to the .app bundle. | ||
EOS | ||
|
||
named_args :app_path, min: 1 | ||
|
||
hide_from_man_page! | ||
end | ||
end | ||
|
||
def find_appcast | ||
args = find_appcast_args.parse | ||
|
||
app = Pathname.new(args.named.first) | ||
find_sparkle(app) || find_electron_builder(app) | ||
end | ||
|
||
def verify_appcast(appcast_type, *urls) | ||
print "Looking for #{appcast_type} appcast… " | ||
urls.each do |url| | ||
next unless url_exist?(url) | ||
|
||
puts "Found!" | ||
puts " #{url}" | ||
return true | ||
end | ||
puts "Not found." | ||
false | ||
end | ||
|
||
def url_exist?(url) | ||
return false unless url | ||
|
||
system("curl", "--silent", "--location", "--fail", url, out: File::NULL) | ||
end | ||
|
||
def find_sparkle(app) | ||
plist = app.join("Contents/Info.plist") | ||
url = Open3.capture3("defaults", "read", plist.to_path, "SUFeedURL").first.strip | ||
verify_appcast("Sparkle", url) | ||
end | ||
|
||
def find_electron_builder(app) | ||
appcast_file = app.join("Contents/Resources/app-update.yml") | ||
unless appcast_file.exist? | ||
verify_appcast("electron-builder", false) | ||
return false | ||
end | ||
YAML.load_file(appcast_file) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.