@@ -26,12 +26,14 @@ module DevTools
2626 module Support
2727 class CDPClientGenerator
2828 # Input JSON files are generated from PDL tasks.
29- TEMPLATE_PATH = File . expand_path ( 'cdp/domain.rb.erb' , __dir__ )
29+ DOMAIN_TEMPLATE_PATH = File . expand_path ( 'cdp/domain.rb.erb' , __dir__ )
30+ LOADER_TEMPLATE_PATH = File . expand_path ( 'cdp/loader.rb.erb' , __dir__ )
3031
3132 RESERVED_KEYWORDS = %w[ end ] . freeze
3233
3334 def call ( output_dir :, version :, **opts )
34- @template = ERB . new ( File . read ( TEMPLATE_PATH ) )
35+ @domain_template = ERB . new ( File . read ( DOMAIN_TEMPLATE_PATH ) )
36+ @loader_template = ERB . new ( File . read ( LOADER_TEMPLATE_PATH ) )
3537 @output_dir = output_dir
3638 @loader_path = opts . delete ( :loader_path ) || "#{ @output_dir } .rb"
3739 @version = version
@@ -48,13 +50,13 @@ def call(output_dir:, version:, **opts)
4850
4951 FileUtils . mkdir_p ( @output_dir )
5052
51- browser_protocol [ :domains ] . each { | domain | process_domain ( domain ) }
52- js_protocol [ :domains ] . each { |domain | process_domain ( domain ) }
53- require_file
53+ all_domains = browser_protocol [ :domains ] + js_protocol [ :domains ]
54+ all_domains . each { |domain | process_domain ( domain ) }
55+ process_loader ( all_domains )
5456 end
5557
5658 def process_domain ( domain )
57- result = @template . result_with_hash ( domain : domain , version : @version . upcase , h : self )
59+ result = @domain_template . result_with_hash ( domain : domain , version : @version . upcase , h : self )
5860 filename = File . join ( @output_dir , "#{ snake_case ( domain [ :domain ] ) } .rb" )
5961 File . write ( filename , remove_empty_lines ( result ) )
6062 end
@@ -86,13 +88,9 @@ def remove_empty_lines(string)
8688 string . split ( "\n " ) . grep_v ( /^\s +$/ ) . join ( "\n " )
8789 end
8890
89- def require_file
90- # rubocop:disable Lint/InterpolationCheck
91- dynamic_location = '#{File.dirname(File.absolute_path(__FILE__))}'
92- # rubocop:enable Lint/InterpolationCheck
93-
94- require_all = "Dir.glob(\" #{ dynamic_location } /#{ @version } /*\" , &method(:require))"
95- File . write ( @loader_path , require_all )
91+ def process_loader ( domains )
92+ result = @loader_template . result_with_hash ( domains : domains , version : @version . upcase , h : self )
93+ File . write ( @loader_path , remove_empty_lines ( result ) )
9694 end
9795 end
9896 end
0 commit comments