diff --git a/Library/Homebrew/dev-cmd/generate-formula-api.rb b/Library/Homebrew/dev-cmd/generate-formula-api.rb index 6bc958082e..bf149c8c31 100644 --- a/Library/Homebrew/dev-cmd/generate-formula-api.rb +++ b/Library/Homebrew/dev-cmd/generate-formula-api.rb @@ -46,7 +46,7 @@ module Homebrew raise TapUnavailableError, tap.name unless tap.installed? unless args.dry_run? - directories = ["_data/formula", "api/formula", "formula"] + directories = ["_data/formula", "api/formula", "formula", "api/internal/v3"] FileUtils.rm_rf directories + ["_data/formula_canonical.json"] FileUtils.mkdir_p directories end @@ -58,6 +58,14 @@ module Homebrew Formulary.enable_factory_cache! Formula.generating_hash! + homebrew_core_tap_hash = { + "tap_git_head" => tap.git_head, + "aliases" => tap.alias_table, + "renames" => tap.formula_renames, + "tap_migrations" => tap.tap_migrations, + "formulae" => {}, + } + tap.formula_names.each do |name| formula = Formulary.factory(name) name = formula.name @@ -69,11 +77,16 @@ module Homebrew File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE) File.write("formula/#{name}.html", html_template_name) end + + homebrew_core_tap_hash["formulae"][formula.name] = + formula.to_hash_with_variations(hash_method: :to_api_hash) rescue onoe "Error while generating data for formula '#{name}'." raise end + homebrew_core_tap_json = JSON.generate(homebrew_core_tap_hash) + File.write("api/internal/v3/homebrew-core.json", homebrew_core_tap_json) unless args.dry_run? canonical_json = JSON.pretty_generate(tap.formula_renames.merge(tap.alias_table)) File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run? end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index bdf8175738..05161759cd 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2407,7 +2407,7 @@ class Formula end end - hash["variations"] = variations + hash["variations"] = variations if hash_method != :to_api_hash || variations.present? hash end