Skip to content

Commit c52c1cb

Browse files
authored
Merge pull request #174292 from Homebrew/findappcast
find-appcast: convert from developer script to command
2 parents 058e82b + 8119126 commit c52c1cb

File tree

2 files changed

+69
-95
lines changed

2 files changed

+69
-95
lines changed

cmd/find-appcast.rb

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# frozen_string_literal: true
2+
3+
require "cli/parser"
4+
require "formula"
5+
require "open3"
6+
require "pathname"
7+
require "yaml"
8+
require "net/http"
9+
require "uri"
10+
11+
module Homebrew
12+
module_function
13+
14+
sig { returns(CLI::Parser) }
15+
def find_appcast_args
16+
Homebrew::CLI::Parser.new do
17+
usage_banner <<~EOS
18+
`find-appcast` <app_path>
19+
20+
Finds the appcast for a given app when a path is provided to the .app bundle.
21+
EOS
22+
23+
named_args :app_path, min: 1
24+
25+
hide_from_man_page!
26+
end
27+
end
28+
29+
def find_appcast
30+
args = find_appcast_args.parse
31+
32+
app = Pathname.new(args.named.first)
33+
find_sparkle(app) || find_electron_builder(app)
34+
end
35+
36+
def verify_appcast(appcast_type, *urls)
37+
print "Looking for #{appcast_type} appcast… "
38+
urls.each do |url|
39+
next unless url_exist?(url)
40+
41+
puts "Found!"
42+
puts " #{url}"
43+
return true
44+
end
45+
puts "Not found."
46+
false
47+
end
48+
49+
def url_exist?(url)
50+
return false unless url
51+
52+
system("curl", "--silent", "--location", "--fail", url, out: File::NULL)
53+
end
54+
55+
def find_sparkle(app)
56+
plist = app.join("Contents/Info.plist")
57+
url = Open3.capture3("defaults", "read", plist.to_path, "SUFeedURL").first.strip
58+
verify_appcast("Sparkle", url)
59+
end
60+
61+
def find_electron_builder(app)
62+
appcast_file = app.join("Contents/Resources/app-update.yml")
63+
unless appcast_file.exist?
64+
verify_appcast("electron-builder", false)
65+
return false
66+
end
67+
YAML.load_file(appcast_file)
68+
end
69+
end

developer/bin/find-appcast

-95
This file was deleted.

0 commit comments

Comments
 (0)