Add generate-{cask,formula}-api commands
These replace the similar scripts in formulae.brew.sh. Part of #14730.
This commit is contained in:
parent
5272640cfc
commit
8d02143c2b
@ -802,6 +802,8 @@ then
|
||||
edit
|
||||
extract
|
||||
formula
|
||||
generate-cask-api
|
||||
generate-formula-api
|
||||
livecheck
|
||||
pr-pull
|
||||
pr-upload
|
||||
|
||||
62
Library/Homebrew/dev-cmd/generate-cask-api.rb
Normal file
62
Library/Homebrew/dev-cmd/generate-cask-api.rb
Normal file
@ -0,0 +1,62 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
require "cask/cask"
|
||||
|
||||
module Homebrew
|
||||
extend T::Sig
|
||||
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def generate_cask_api_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
description <<~EOS
|
||||
Generates Cask API data files for formulae.brew.sh.
|
||||
EOS
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
JSON_TEMPLATE = <<~EOS
|
||||
---
|
||||
layout: cask_json
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
|
||||
def html_template(title)
|
||||
<<~EOS
|
||||
---
|
||||
title: #{title}
|
||||
layout: cask
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
end
|
||||
|
||||
def generate_cask_api
|
||||
generate_cask_api_args.parse
|
||||
|
||||
tap = Tap.fetch("homebrew/cask")
|
||||
|
||||
directories = ["_data/cask", "api/cask", "api/cask-source", "cask"].freeze
|
||||
FileUtils.rm_rf directories
|
||||
FileUtils.mkdir_p directories
|
||||
|
||||
Cask::Cask.generating_hash!
|
||||
|
||||
tap.cask_files.each do |path|
|
||||
cask = Cask::CaskLoader.load(path)
|
||||
name = cask.token
|
||||
json = JSON.pretty_generate(cask.to_hash_with_variations)
|
||||
|
||||
File.write("_data/cask/#{name}.json", "#{json}\n")
|
||||
File.write("api/cask/#{name}.json", JSON_TEMPLATE)
|
||||
File.write("api/cask-source/#{name}.rb", path.read)
|
||||
File.write("cask/#{name}.html", html_template(name))
|
||||
end
|
||||
end
|
||||
end
|
||||
65
Library/Homebrew/dev-cmd/generate-formula-api.rb
Normal file
65
Library/Homebrew/dev-cmd/generate-formula-api.rb
Normal file
@ -0,0 +1,65 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
require "formula"
|
||||
|
||||
module Homebrew
|
||||
extend T::Sig
|
||||
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def generate_formula_api_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
description <<~EOS
|
||||
Generates Formula API data files for formulae.brew.sh.
|
||||
EOS
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
JSON_TEMPLATE = <<~EOS
|
||||
---
|
||||
layout: formula_json
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
|
||||
def html_template(title)
|
||||
<<~EOS
|
||||
---
|
||||
title: #{title}
|
||||
layout: formula
|
||||
redirect_from: /formula-linux/$TITLE
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
end
|
||||
|
||||
def generate_formula_api
|
||||
generate_formula_api_args.parse
|
||||
|
||||
tap = Tap.fetch("homebrew/core")
|
||||
|
||||
directories = ["_data/formula", "api/formula", "formula"]
|
||||
FileUtils.rm_rf directories + ["_data/formula_canonical.json"]
|
||||
FileUtils.mkdir_p directories
|
||||
|
||||
Formulary.enable_factory_cache!
|
||||
|
||||
tap.formula_names.each do |name|
|
||||
formula = Formulary.factory(name)
|
||||
name = formula.name
|
||||
json = JSON.pretty_generate(formula.to_hash_with_variations)
|
||||
|
||||
File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n")
|
||||
File.write("api/formula/#{name}.json", JSON_TEMPLATE)
|
||||
File.write("formula/#{name}.html", html_template(name))
|
||||
end
|
||||
|
||||
canonical_json = JSON.pretty_generate(tap.formula_renames.merge(tap.alias_table))
|
||||
File.write("_data/formula_canonical.json", "#{canonical_json}\n")
|
||||
end
|
||||
end
|
||||
8
Library/Homebrew/test/dev-cmd/generate-cask-api_spec.rb
Normal file
8
Library/Homebrew/test/dev-cmd/generate-cask-api_spec.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# typed: false
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
describe "brew generate-cask-api" do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
@ -0,0 +1,8 @@
|
||||
# typed: false
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
describe "brew generate-formula-api" do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user