Class: Fastlane::Actions::GodotInstallTemplatesAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/godot/actions/godot_install_templates_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



49
50
51
# File 'lib/fastlane/plugin/godot/actions/godot_install_templates_action.rb', line 49

def self.authors
  ['Mad Science Software']
end

.available_optionsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/godot/actions/godot_install_templates_action.rb', line 53

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :platform,
                                 env_name: 'FL_GODOT_TEMPLATE_PLATFORM',
                                 description: "Which platform's templates to install: iOS, Android, macOS, Web, or all",
                                 type: String,
                                 default_value: 'all'),
    FastlaneCore::ConfigItem.new(key: :godot_binary,
                                 env_name: 'FL_GODOT_BINARY',
                                 description: 'Path to the Godot binary',
                                 type: String,
                                 default_value: 'godot'),
    FastlaneCore::ConfigItem.new(key: :force,
                                 env_name: 'FL_GODOT_TEMPLATE_FORCE',
                                 description: 'Reinstall even when already present',
                                 type: Boolean,
                                 default_value: false)
  ]
end

.descriptionObject



41
42
43
# File 'lib/fastlane/plugin/godot/actions/godot_install_templates_action.rb', line 41

def self.description
  "Download and install the export templates matching the Godot binary's version, for one platform or all"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/fastlane/plugin/godot/actions/godot_install_templates_action.rb', line 73

def self.is_supported?(platform)
  true
end

.return_valueObject



45
46
47
# File 'lib/fastlane/plugin/godot/actions/godot_install_templates_action.rb', line 45

def self.return_value
  'Path to the version-specific export-templates directory'
end

.run(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/godot/actions/godot_install_templates_action.rb', line 8

def self.run(params)
  godot = Helper::GodotHelper.discover_godot_binary(params[:godot_binary])
  version = Helper::GodotHelper.godot_version(godot)
  release = Helper::GodotHelper.template_directory_name(version)
  target_dir = File.join(Helper::GodotHelper.templates_root, release)

  wanted = params[:platform] == 'all' ? Helper::GodotHelper::PLATFORM_TEMPLATE_FILES.values.flatten : Helper::GodotHelper::PLATFORM_TEMPLATE_FILES[params[:platform]]
  UI.user_error!("Unknown platform '#{params[:platform]}' — use one of: #{Helper::GodotHelper::PLATFORM_TEMPLATE_FILES.keys.join(', ')}, all") if wanted.nil?

  missing = wanted.reject { |f| File.exist?(File.join(target_dir, f)) }
  missing = wanted if params[:force]
  if missing.empty?
    UI.success("Export templates for #{params[:platform]} (#{release}) already installed")
    return target_dir
  end

  url = Helper::GodotHelper.template_download_url(version)
  archive = File.join(Dir.mktmpdir('godot-templates'), 'templates.tpz')
  UI.message("Downloading #{url} (the full bundle is large — one-time per engine version)")
  Actions.sh("curl -fL --progress-bar -o #{archive.shellescape} #{url.shellescape}", log: false)

  FileUtils.mkdir_p(target_dir)
  extract_dir = File.join(File.dirname(archive), 'extracted')
  members = missing.map { |f| "templates/#{f}".shellescape }.join(' ')
  Actions.sh("unzip -o -q #{archive.shellescape} #{members} -d #{extract_dir.shellescape}", log: false)
  missing.each do |file|
    FileUtils.mv(File.join(extract_dir, 'templates', file), File.join(target_dir, file))
    UI.success("installed #{file}")
  end
  FileUtils.rm_rf(File.dirname(archive))
  target_dir
end