Class: MendixBridge::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/mendix_bridge/importer.rb

Constant Summary collapse

SNAPSHOT_FILE =
"inventory/project-tree.json"
ELEMENT_DETAILS_FILE =
"inventory/element-details.json"
METADATA_FILE =
"mendix-project.json"
DEPENDENCIES_FILE =
"inventory/dependencies.json"

Instance Method Summary collapse

Constructor Details

#initialize(mxcli:) ⇒ Importer

Returns a new instance of Importer.



16
17
18
# File 'lib/mendix_bridge/importer.rb', line 16

def initialize(mxcli:)
  @mxcli = File.expand_path(mxcli)
end

Instance Method Details

#import(project_file, output_dir) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mendix_bridge/importer.rb', line 20

def import(project_file, output_dir)
  project_file = File.expand_path(project_file)
  output_dir = File.expand_path(output_dir)

  raise ImportError, "Mendix project does not exist: #{project_file}" unless File.file?(project_file)
  raise ImportError, "mxcli is not executable: #{@mxcli}" unless File.executable?(@mxcli)

  stdout, stderr, status = Open3.capture3(
    @mxcli, "--json", "-p", project_file, "project-tree"
  )
  unless status.success?
    raise ImportError, "mxcli could not read the project: #{stderr.strip}"
  end

  inventory = Inventory.from_json(stdout)
  element_details, warnings = describe_elements(project_file, inventory)
  inventory = Inventory.from_json(stdout, details: element_details)
  write_project(output_dir, project_file, inventory)
  [inventory, warnings]
rescue JSON::ParserError => error
  raise ImportError, "mxcli returned invalid project-tree JSON: #{error.message}"
end