Class: PluginManager::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/psdk/helpers/plugin_manager/builder.rb

Overview

Class responsible of building plugins

Constant Summary collapse

PLUGIN_FILE_EXT =

rubocop:disable Metrics/ClassLength

'psdkplug'
SCRIPTS_FOLDER =
'scripts'

Instance Method Summary collapse

Constructor Details

#initialize(plugin_name, in_project: true, out_dir: '.') ⇒ Builder

Create a new plugin builder

Parameters:

  • plugin_name (String)

    name of the plugin directory

  • in_project (Boolean) (defaults to: true)

    whether we are building inside a PSDK project

  • out_dir (String) (defaults to: '.')

    directory to output the compiled plugin



17
18
19
20
21
# File 'lib/psdk/helpers/plugin_manager/builder.rb', line 17

def initialize(plugin_name, in_project: true, out_dir: '.')
  @name = plugin_name
  @in_project = in_project
  @out_dir = out_dir
end

Instance Method Details

#buildObject

Start the building process



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/psdk/helpers/plugin_manager/builder.rb', line 24

def build # rubocop:disable Metrics/MethodLength
  puts "--- Starting build for plugin '#{@name}' ---"
  if @in_project
    puts '[INFO] Operating inside a PSDK project.'
  else
    puts '[INFO] Operating in standalone mode (outside a PSDK project).'
  end

  project_root = @in_project.is_a?(String) ? @in_project : Dir.pwd
  out_dir = File.absolute_path(@out_dir)

  Dir.chdir(project_root) do
    @config = load_plugin_configuration
    plugin_filename = File.join(out_dir, "#{@config.name}.#{PLUGIN_FILE_EXT}")
    tmp_filename = "#{plugin_filename}.tmp"

    build_internal(tmp_filename)
    compute_sha512(tmp_filename)
    write_config_an_rename_file(tmp_filename, plugin_filename)

    puts "\e[32m[SUCCESS]\e[0m Built #{@config.name} at #{plugin_filename}"
  end
end