@@ -26,12 +26,14 @@ module DevTools
26
26
module Support
27
27
class CDPClientGenerator
28
28
# 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__ )
30
31
31
32
RESERVED_KEYWORDS = %w[ end ] . freeze
32
33
33
34
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 ) )
35
37
@output_dir = output_dir
36
38
@loader_path = opts . delete ( :loader_path ) || "#{ @output_dir } .rb"
37
39
@version = version
@@ -48,13 +50,13 @@ def call(output_dir:, version:, **opts)
48
50
49
51
FileUtils . mkdir_p ( @output_dir )
50
52
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 )
54
56
end
55
57
56
58
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 )
58
60
filename = File . join ( @output_dir , "#{ snake_case ( domain [ :domain ] ) } .rb" )
59
61
File . write ( filename , remove_empty_lines ( result ) )
60
62
end
@@ -86,13 +88,9 @@ def remove_empty_lines(string)
86
88
string . split ( "\n " ) . grep_v ( /^\s +$/ ) . join ( "\n " )
87
89
end
88
90
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 ) )
96
94
end
97
95
end
98
96
end
0 commit comments