Class: Fastlane::Actions::GodotInitAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



65
66
67
# File 'lib/fastlane/plugin/godot/actions/godot_init_action.rb', line 65

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

.available_optionsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fastlane/plugin/godot/actions/godot_init_action.rb', line 69

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :project_path,
                                 env_name: 'FL_GODOT_PROJECT_PATH',
                                 description: 'Directory containing project.godot',
                                 type: String,
                                 default_value: '.'),
    FastlaneCore::ConfigItem.new(key: :icon,
                                 env_name: 'FL_GODOT_INIT_ICON',
                                 description: 'Also create a placeholder 1024x1024 app_icon.png (iOS export fails without an icon)',
                                 type: Boolean,
                                 default_value: true)
  ]
end

.descriptionObject



57
58
59
# File 'lib/fastlane/plugin/godot/actions/godot_init_action.rb', line 57

def self.description
  'Scaffold the files a Godot project needs for fastlane mobile releases (never overwrites existing files)'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/fastlane/plugin/godot/actions/godot_init_action.rb', line 84

def self.is_supported?(platform)
  true
end

.return_valueObject



61
62
63
# File 'lib/fastlane/plugin/godot/actions/godot_init_action.rb', line 61

def self.return_value
  'Array of relative paths that were created'
end

.run(params) ⇒ Object



7
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/godot/actions/godot_init_action.rb', line 7

def self.run(params)
  project_path = File.expand_path(params[:project_path])
  UI.user_error!("No project.godot in #{project_path} — run this from (or point project_path at) a Godot project") unless File.exist?(File.join(project_path, 'project.godot'))

  created = []
  skipped = []
  write = lambda do |relative_path, content, binary: false|
    target = File.join(project_path, relative_path)
    if File.exist?(target)
      skipped << relative_path
    else
      FileUtils.mkdir_p(File.dirname(target))
      binary ? File.binwrite(target, content) : File.write(target, content)
      created << relative_path
    end
  end

  scaffold = Helper::GodotScaffold
  write.call('Gemfile', scaffold::GEMFILE)
  write.call('fastlane/Pluginfile', scaffold::PLUGINFILE)
  write.call('fastlane/Appfile', scaffold::APPFILE)
  write.call('fastlane/Fastfile', scaffold::FASTFILE)
  write.call('fastlane/.env.template', scaffold::ENV_TEMPLATE)
  write.call('export_presets.cfg', scaffold::EXPORT_PRESETS)
  write.call('build/.gdignore', '')
  write.call('app_icon.png', scaffold.placeholder_icon_png, binary: true) if params[:icon]

  gitignore = File.join(project_path, '.gitignore')
  if File.exist?(gitignore)
    existing = File.read(gitignore)
    missing = scaffold::GITIGNORE_ENTRIES.reject { |entry| existing.include?(entry) }
    UI.important("Your .gitignore is missing: #{missing.join(', ')} — add them so credentials and build products stay out of git") unless missing.empty?
    skipped << '.gitignore'
  else
    write.call('.gitignore', scaffold::GITIGNORE)
  end

  created.each { |path| UI.success("created #{path}") }
  skipped.each { |path| UI.message("kept existing #{path}") }

  unless created.empty?
    UI.important('Placeholders to fill in before building:')
    UI.important('  - fastlane/Appfile: bundle identifier and team ID')
    UI.important('  - export_presets.cfg: bundle identifier, team ID, export_path names')
    UI.important('  - copy fastlane/.env.template to fastlane/.env and add your App Store Connect API key')
    UI.important('  - app_icon.png is an obvious placeholder — replace it before shipping') if params[:icon]
  end
  created
end