Class: Mxrb::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/exporter.rb

Overview

Exports an MPR into an editable, layered Ruby source tree.

Constant Summary collapse

MODES =
%i[mendix ruby].freeze
LAYERS =
%w[domain application presentation infrastructure].freeze
MODULE_PROGRESS_WEIGHT =
10
MARKETPLACE_PROVENANCE =
[
  ".mxrb/marketplace.lock.json",
  ".mxrb/marketplace",
  ".mxrb/marketplace-originals"
].freeze
EDITABLE_FLOW_OBJECT_TYPES =
%w[
  Microflows$StartEvent
  Microflows$EndEvent
  Microflows$ActionActivity
  Microflows$ExclusiveSplit
  Microflows$InheritanceSplit
  Microflows$ExclusiveMerge
  Microflows$LoopedActivity
  Microflows$ErrorEvent
  Microflows$ContinueEvent
  Microflows$Annotation
  Microflows$MicroflowParameter
].freeze
EDITABLE_ACTION_TYPES =
%w[
  Microflows$CreateObjectAction
  Microflows$CreateChangeAction
  Microflows$ChangeObjectAction
  Microflows$ChangeAction
  Microflows$RetrieveAction
  Microflows$CommitObjectsAction
  Microflows$CommitAction
  Microflows$DeleteAction
  Microflows$MicroflowCallAction
  Microflows$CreateVariableAction
  Microflows$ChangeVariableAction
  Microflows$ShowMessageAction
  Microflows$LogMessageAction
  Microflows$ShowFormAction
  Microflows$CloseFormAction
  Microflows$JavaActionCallAction
  Microflows$JavaScriptActionCallAction
  Microflows$NanoflowCallAction
  Microflows$AppServiceCallAction
  Microflows$AggregateAction
  Microflows$RollbackAction
  Microflows$CastAction
  Microflows$CreateListAction
  Microflows$ListOperationsAction
  Microflows$ChangeListAction
  Microflows$ValidationFeedbackAction
  Microflows$RestCallAction
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mpr_path, output_dir, mode: :mendix) ⇒ Exporter

Returns a new instance of Exporter.

Raises:

  • (ArgumentError)


64
65
66
67
68
69
# File 'lib/mxrb/exporter.rb', line 64

def initialize(mpr_path, output_dir, mode: :mendix)
  @mpr_path = File.expand_path(mpr_path)
  @output_dir = File.expand_path(output_dir)
  @mode = mode.to_sym
  raise ArgumentError, "export mode must be mendix or ruby" unless MODES.include?(@mode)
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



62
63
64
# File 'lib/mxrb/exporter.rb', line 62

def mode
  @mode
end

Instance Method Details

#export!(parallel: true) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/mxrb/exporter.rb', line 71

def export!(parallel: true)
  return export_ruby!(parallel:) if mode == :ruby

  Progress.with("Exporting #{File.basename(@mpr_path)}") do |progress|
    FileUtils.mkdir_p(@output_dir)
    Mxrb.open(@mpr_path) do |project|
      @architecture = project.architecture_definition
      units = project.all_units
      modules = project.modules
      @inferred_public_artifacts = infer_public_artifacts(modules)
      assets = project_asset_files
      progress.update(
        current: 0,
        total: 4 + assets.size + (units.size * 2) + (modules.size * MODULE_PROGRESS_WEIGHT),
        detail: "preparing Ruby project"
      )
      export_app_structure
      progress.advance(detail: "project structure")
      export_project_assets(assets, progress)
      export_native_units(project, units, progress)
      ruby_sources = export_ruby_app_sources(project)
      export_security(project)
      progress.advance(detail: "project security")
      export_architecture_contracts(project)
      progress.advance(detail: "navigation and design system")
      export_modules(modules, progress, parallel:)
      write_project(project, ruby_sources:)
      progress.advance(detail: "project.rb")
    end
  end
  @output_dir
end