Skip to content

Commit

Permalink
Merge pull request #16541 from apainintheneck/next-gen-api-formula-js…
Browse files Browse the repository at this point in the history
…on-v3

Next gen api formula json v3
  • Loading branch information
apainintheneck authored Feb 4, 2024
2 parents f09ea3a + 54b54b7 commit d947721
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 135 deletions.
15 changes: 14 additions & 1 deletion Library/Homebrew/dev-cmd/generate-formula-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def generate_formula_api
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
Expand All @@ -58,6 +58,14 @@ def generate_formula_api
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
Expand All @@ -69,11 +77,16 @@ def generate_formula_api
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
Expand Down
Loading

0 comments on commit d947721

Please sign in to comment.