Method: OpenC3::WidgetModel#deploy

Defined in:
lib/openc3/models/widget_model.rb

#deploy(gem_path, variables, validate_only: false) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/openc3/models/widget_model.rb', line 110

def deploy(gem_path, variables, validate_only: false)
  # Ensure tools bucket exists
  bucket = nil
  unless validate_only
    bucket = Bucket.getClient()
    bucket.ensure_public(ENV['OPENC3_TOOLS_BUCKET'])
  end

  filename = gem_path + "/tools/widgets/" + @full_name + '/' + @filename

  # Load widget file
  data = File.read(filename, mode: "rb")
  OpenC3.set_working_dir(File.dirname(filename)) do
    data = ERB.new(data, trim_mode: "-").result(binding.set_variables(variables)) if data.is_printable?
  end
  unless validate_only
    cache_control = BucketUtilities.get_cache_control(@filename)
    # TODO: support widgets that aren't just a single js file (and its associated map file)
    bucket.put_object(bucket: ENV['OPENC3_TOOLS_BUCKET'], content_type: 'application/javascript', cache_control: cache_control, key: @bucket_key, body: data)
    data = File.read(filename + '.map', mode: "rb")
    bucket.put_object(bucket: ENV['OPENC3_TOOLS_BUCKET'], content_type: 'application/json', cache_control: cache_control, key: @bucket_key + '.map', body: data)
  end
end