dev-cmd/generate-formula-api: generate homebrew-core.json
This adds the code to generate the homebrew-core.json file which represents the entire tap instead of just the previous array of formula hashes. Any shared logic has been moved into the top-level hash scope including aliases, renames, tap_git_head and tap_migrations. I also added a check to skip adding the variations hash to the api hash if it is empty. Now we're down to 10MB from 24MB!!!
This commit is contained in:
parent
69609731d9
commit
ba3a0f8c33
@ -46,7 +46,7 @@ module Homebrew
|
|||||||
raise TapUnavailableError, tap.name unless tap.installed?
|
raise TapUnavailableError, tap.name unless tap.installed?
|
||||||
|
|
||||||
unless args.dry_run?
|
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.rm_rf directories + ["_data/formula_canonical.json"]
|
||||||
FileUtils.mkdir_p directories
|
FileUtils.mkdir_p directories
|
||||||
end
|
end
|
||||||
@ -58,6 +58,14 @@ module Homebrew
|
|||||||
Formulary.enable_factory_cache!
|
Formulary.enable_factory_cache!
|
||||||
Formula.generating_hash!
|
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|
|
tap.formula_names.each do |name|
|
||||||
formula = Formulary.factory(name)
|
formula = Formulary.factory(name)
|
||||||
name = formula.name
|
name = formula.name
|
||||||
@ -69,11 +77,16 @@ module Homebrew
|
|||||||
File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
|
File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
|
||||||
File.write("formula/#{name}.html", html_template_name)
|
File.write("formula/#{name}.html", html_template_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
homebrew_core_tap_hash["formulae"][formula.name] =
|
||||||
|
formula.to_hash_with_variations(hash_method: :to_api_hash)
|
||||||
rescue
|
rescue
|
||||||
onoe "Error while generating data for formula '#{name}'."
|
onoe "Error while generating data for formula '#{name}'."
|
||||||
raise
|
raise
|
||||||
end
|
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))
|
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?
|
File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2407,7 +2407,7 @@ class Formula
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
hash["variations"] = variations
|
hash["variations"] = variations if hash_method != :to_api_hash || variations.present?
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user