dev-cmd/generate-*-api: add dry run option
There are two reasons for this: - Makes it easier to run this command as a sanity check without having to create a temporary directory - Is somewhat faster since you don't have to write thousands of files
This commit is contained in:
parent
64259a420b
commit
358a2ce788
@ -16,6 +16,8 @@ module Homebrew
|
|||||||
The generated files are written to the current directory.
|
The generated files are written to the current directory.
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
|
switch "-n", "--dry-run", description: "Generate API data without writing it to files."
|
||||||
|
|
||||||
named_args :none
|
named_args :none
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -38,13 +40,15 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generate_cask_api
|
def generate_cask_api
|
||||||
generate_cask_api_args.parse
|
args = generate_cask_api_args.parse
|
||||||
|
|
||||||
tap = Tap.default_cask_tap
|
tap = Tap.default_cask_tap
|
||||||
|
|
||||||
directories = ["_data/cask", "api/cask", "api/cask-source", "cask"].freeze
|
unless args.dry_run?
|
||||||
FileUtils.rm_rf directories
|
directories = ["_data/cask", "api/cask", "api/cask-source", "cask"].freeze
|
||||||
FileUtils.mkdir_p directories
|
FileUtils.rm_rf directories
|
||||||
|
FileUtils.mkdir_p directories
|
||||||
|
end
|
||||||
|
|
||||||
Cask::Cask.generating_hash!
|
Cask::Cask.generating_hash!
|
||||||
|
|
||||||
@ -53,10 +57,12 @@ module Homebrew
|
|||||||
name = cask.token
|
name = cask.token
|
||||||
json = JSON.pretty_generate(cask.to_hash_with_variations)
|
json = JSON.pretty_generate(cask.to_hash_with_variations)
|
||||||
|
|
||||||
File.write("_data/cask/#{name}.json", "#{json}\n")
|
unless args.dry_run?
|
||||||
File.write("api/cask/#{name}.json", CASK_JSON_TEMPLATE)
|
File.write("_data/cask/#{name}.json", "#{json}\n")
|
||||||
File.write("api/cask-source/#{name}.rb", path.read)
|
File.write("api/cask/#{name}.json", CASK_JSON_TEMPLATE)
|
||||||
File.write("cask/#{name}.html", html_template(name))
|
File.write("api/cask-source/#{name}.rb", path.read)
|
||||||
|
File.write("cask/#{name}.html", html_template(name))
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
onoe "Error while generating data for cask '#{path.stem}'."
|
onoe "Error while generating data for cask '#{path.stem}'."
|
||||||
raise
|
raise
|
||||||
|
|||||||
@ -16,6 +16,8 @@ module Homebrew
|
|||||||
The generated files are written to the current directory.
|
The generated files are written to the current directory.
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
|
switch "-n", "--dry-run", description: "Generate API data without writing it to files."
|
||||||
|
|
||||||
named_args :none
|
named_args :none
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -39,13 +41,15 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generate_formula_api
|
def generate_formula_api
|
||||||
generate_formula_api_args.parse
|
args = generate_formula_api_args.parse
|
||||||
|
|
||||||
tap = CoreTap.instance
|
tap = CoreTap.instance
|
||||||
|
|
||||||
directories = ["_data/formula", "api/formula", "formula"]
|
unless args.dry_run?
|
||||||
FileUtils.rm_rf directories + ["_data/formula_canonical.json"]
|
directories = ["_data/formula", "api/formula", "formula"]
|
||||||
FileUtils.mkdir_p directories
|
FileUtils.rm_rf directories + ["_data/formula_canonical.json"]
|
||||||
|
FileUtils.mkdir_p directories
|
||||||
|
end
|
||||||
|
|
||||||
Formulary.enable_factory_cache!
|
Formulary.enable_factory_cache!
|
||||||
Formula.generating_hash!
|
Formula.generating_hash!
|
||||||
@ -55,15 +59,17 @@ module Homebrew
|
|||||||
name = formula.name
|
name = formula.name
|
||||||
json = JSON.pretty_generate(formula.to_hash_with_variations)
|
json = JSON.pretty_generate(formula.to_hash_with_variations)
|
||||||
|
|
||||||
File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n")
|
unless args.dry_run?
|
||||||
File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
|
File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n")
|
||||||
File.write("formula/#{name}.html", html_template(name))
|
File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
|
||||||
|
File.write("formula/#{name}.html", html_template(name))
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
onoe "Error while generating data for formula '#{name}'."
|
onoe "Error while generating data for formula '#{name}'."
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
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")
|
File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user