Class: Fastlane::Actions::CreateDmgAction

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

Constant Summary collapse

UI =
FastlaneCore::UI

Class Method Summary collapse

Class Method Details

.authorsObject



62
63
64
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 62

def self.authors
  ["Vitalii Budnik"]
end

.available_optionsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 85

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :source,
                            env_name: "CREATE_DMG_SOURCE",
                         description: "Path to the folder or file to be archived to dmg",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("Could not find folder at #{value}") unless File.exist?(value)
                                      end),
    FastlaneCore::ConfigItem.new(key: :output_filename,
                            env_name: "CREATE_DMG_OUTPUT_FILENAME",
                         description: "Path to the folder to be archived to dmg",
                            optional: true,
                                type: String),

    # Volume options
    FastlaneCore::ConfigItem.new(key: :volume_name,
                            env_name: "CREATE_DMG_VOLUME_NAME",
                         description: "Volume name displayed in the Finder sidebar and window title",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :volume_icon,
                            env_name: "CREATE_DMG_VOLUME_ICON",
                         description: "Volume icon (*.incs)",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :volume_format,
                            env_name: "CREATE_DMG_VOLUME_FORMAT",
                         description: "The final image format. 'UDZO' or 'UDBZ'",
                            optional: true,
                                type: String,
                       default_value: 'UDZO',
                        verify_block: proc do |value|
                                        UI.user_error!("Could not find folder at '#{value}'") unless ['UDZO', 'UDBZ'].include?(value)
                                      end),
    FastlaneCore::ConfigItem.new(key: :volume_size,
                            env_name: "CREATE_DMG_VOLUME_SIZE",
                         description: "Disk image size (in MB)",
                            optional: true,
                                type: Integer),

    # Window options
    FastlaneCore::ConfigItem.new(key: :window_position,
                            env_name: "CREATE_DMG_WINDOW_POSITION",
                         description: "Position of the disk image window on the screen X Y coordinates. E.g. '420 150'",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :window_size,
                            env_name: "CREATE_DMG_WINDOW_SIZE",
                         description: "Size of the disk image window on the screen WIDTH HEIGHT. E.g. '480 320'",
                            optional: true,
                                type: String),

    # Disk image folder options
    FastlaneCore::ConfigItem.new(key: :background,
                            env_name: "CREATE_DMG_BACKGROUND",
                         description: "Disk Image folder background image (png, gif, jpg)",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :icon_size,
                            env_name: "CREATE_DMG_ICON_SIZE",
                         description: "Icon size inside the DMG folder. Up to 128",
                            optional: true,
                                type: Integer),
    FastlaneCore::ConfigItem.new(key: :text_size,
                            env_name: "CREATE_DMG_TEXT_SIZE",
                         description: "Text size inside the DMG folder (10-16)",
                            optional: true,
                                type: Integer),
    FastlaneCore::ConfigItem.new(key: :source_icon_position,
                            env_name: "CREATE_DMG_SOURCE_ICON_POSITION",
                         description: "Position of the file's icon 'X Y'. E.g. '10 10'",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :hide_source_extension,
                            env_name: "CREATE_DMG_HIDE_SOURCE_EXTENSION",
                         description: "Hide the source extension",
                            optional: true,
                                type: Boolean),

    # Link positions
    FastlaneCore::ConfigItem.new(key: :applications_folder_position,
                            env_name: "CREATE_DMG_APPLICATIONS_FOLDER_ICON_POSITION",
                         description: "Position of the /Applications folder icon 'X Y'. E.g. '150 10'",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :quick_look_folder_position,
                            env_name: "CREATE_DMG_SOURCE_ICON_POSITION",
                         description: "Position of the QuickLook install folder icon 'X Y'. E.g. '150 150'",
                            optional: true,
                                type: String),

    # EULA
    FastlaneCore::ConfigItem.new(key: :eula_filename,
                            env_name: "CREATE_DMG_EULA_FILENAME",
                         description: "A path to the end-user license agreement file",
                            optional: true,
                                type: String),

    # Additional files
    FastlaneCore::ConfigItem.new(key: :addiional_files,
                            env_name: "CREATE_DMG_ADDITIONAL_FILES",
                         description: "A list of files to add '<target_name> <file>|<folder> <x> <y>'. E.g. 'Another.app Second.app 200 200'",
                            optional: true,
                                type: Array),

    # hdiutil
    FastlaneCore::ConfigItem.new(key: :hdiutil_verbose,
                            env_name: "CREATE_DMG_HDUTIL_VERBOSE",
                         description: "Execute hdiutil in verbose mode",
                 conflicting_options: [:hdiutil_quiet],
                            optional: true,
                                type: Boolean),
    FastlaneCore::ConfigItem.new(key: :hdiutil_quiet,
                            env_name: "CREATE_DMG_HDUTIL_QUIET",
                         description: "Execute hdiutil in quiet mode",
                 conflicting_options: [:hdiutil_verbose],
                            optional: true,
                                type: Boolean),
    FastlaneCore::ConfigItem.new(key: :hdiutil_sandbox_safe,
                            env_name: "CREATE_DMG_HDUTIL_SANDBOX_SAFE",
                         description: "Execute hdiutil with sandbox compatibility and do not bless. Some options are unavailable if this options is set to true",
                            optional: true,
                                type: Boolean,
                       default_value: false),

    # Plugin options
    FastlaneCore::ConfigItem.new(key: :verbose,
                            env_name: "CREATE_DMG_VERBOSE",
                         description: "Whether to log create-dmg output",
                            optional: true,
                                type: Boolean)
  ]
end

.descriptionObject



58
59
60
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 58

def self.description
  "A Ruby wrapper over create-dmg."
end

.detailsObject



80
81
82
83
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 80

def self.details
  # Optional:
  "A Ruby wrapper over create-dmg - A shell script to build fancy DMGs."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 221

def self.is_supported?(platform)
  [:mac].include?(platform)
end

.outputObject



66
67
68
69
70
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 66

def self.output
  [
    ['CREATE_DMG_OUTPUT_PATH', 'The path to the created DMG']
  ]
end

.return_typeObject



76
77
78
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 76

def self.return_type
  :string
end

.return_valueObject



72
73
74
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 72

def self.return_value
  'The path to the created DMG'
end

.run(params) ⇒ Object



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
56
# File 'lib/fastlane/plugin/create_dmg/actions/create_dmg_action.rb', line 16

def self.run(params)
  helper = Fastlane::Helper::CreateDmgHelper.new(params: params)

  if File.exist?(helper.output_filename)
    UI.message("Remove #{helper.output_filename}") if helper.verbose
    File.delete(helper.output_filename)
  end

  temp_source_folder = Dir.mktmpdir('create-dmg')

  create_dmg_parameters = helper.create_dmg_parameters

  create_dmg_script_path = File.expand_path("#{__dir__}/../vendor/create-dmg/create-dmg")

  create_dmg_parameters.insert(0, create_dmg_script_path)
  create_dmg_parameters << temp_source_folder

  begin
    UI.message("Copy source '#{helper.source}' to temp folder '#{temp_source_folder}'") if helper.verbose
    Actions.sh(
      'ditto', '--rsrc', '--extattr', helper.source, "#{temp_source_folder}/#{helper.source_basename}",
      log: helper.verbose
    )
    UI.message("Create DMG at #{helper.output_filename}") if helper.verbose
    Actions.sh(
      create_dmg_parameters,
      log: true
    )
  ensure
    UI.message("Delete temp folder #{temp_source_folder}") if helper.verbose
    FileUtils.rm_rf(temp_source_folder)
  end

  UI.success("Successfully created DMG")
  UI.message(helper.output_filename)

  Actions.lane_context[SharedValues::CREATE_DMG_OUTPUT_PATH] = helper.output_filename
  ENV[SharedValues::CREATE_DMG_OUTPUT_PATH.to_s] = helper.output_filename

  return helper.output_filename
end