Class: ProtobufClosureLibrary::ProtocJs

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf-closure-library/protoc_js.rb

Class Method Summary collapse

Class Method Details

.compile(proto_file, out_dir, options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/protobuf-closure-library/protoc_js.rb', line 4

def self.compile proto_file, out_dir, options
  options = {
    generator_options: {},
    protoc_options: []
  }.merge options

  if !File.exist? out_dir
    FileUtils.mkdir_p out_dir
  end

  generator_options = options[:generator_options].map{|k, v| "#{k}=#{v}" }.join(',')
  js_out_options = generator_options.empty? ? out_dir : "#{generator_options}:#{out_dir}"

  ProtocJsCore.compile RUBY_BIN, proto_file, 
    @@static_proto_path | [
      "--js_out=#{js_out_options}",
      "--proto_path=#{File.dirname proto_file}"
    ] | options[:protoc_options]
end