Class: ChocTop

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

Defined Under Namespace

Modules: Appcast, Dmg

Constant Summary collapse

VERSION =
'0.11.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ ChocTop

Returns a new instance of ChocTop.

Yields:

  • (_self)

Yield Parameters:

  • _self (ChocTop)

    the object that the method was called on



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/choctop.rb', line 231

def initialize
  $choctop = $sparkle = self # define a global variable for this object ($sparkle is legacy)
  
  yield self if block_given?
  
  # Defaults
  @info_plist_path ||= 'Info.plist'
  @name ||= info_plist['CFBundleExecutable'] || File.basename(File.expand_path("."))
  @name = File.basename(File.expand_path(".")) if @name == '${EXECUTABLE_NAME}'
  @version ||= info_plist['CFBundleVersion']
  @build_type = ENV['BUILD_TYPE'] || 'Release'
  
  if @su_feed_url = info_plist['SUFeedURL']
    @appcast_filename ||= File.basename(su_feed_url)
    @base_url ||= File.dirname(su_feed_url)
  end
  if @base_url
    @host ||= URI.parse(base_url).host
  end
  @release_notes ||= 'release_notes.html'
  @readme        ||= 'README.txt'
  @release_notes_template ||= "release_notes_template.html.erb"
  @rsync_args ||= '-aCv --progress'
  
  @background_file ||= File.dirname(__FILE__) + "/../assets/sky_background.jpg"
  @app_icon_position ||= [175, 65]
  @applications_icon_position ||= [347, 270]
  @volume_icon ||= File.dirname(__FILE__) + "/../assets/DefaultVolumeIcon.icns"
  @icon_size ||= 104
  @icon_text_size ||= 12

  add_file :target_bundle, :position => app_icon_position
  
  define_tasks
end

Instance Attribute Details

#app_icon_positionObject

x, y position of this project’s icon on the custom DMG Default: a useful position for the icon against the default background



170
171
172
# File 'lib/choctop.rb', line 170

def app_icon_position
  @app_icon_position
end

#appcast_filenameObject

The name of the local xml file containing the Sparkle item details Default: info_plist or linker_appcast.xml



88
89
90
# File 'lib/choctop.rb', line 88

def appcast_filename
  @appcast_filename
end

#applications_iconObject

Custom icon for the Applications symlink icon Default: none



183
184
185
# File 'lib/choctop.rb', line 183

def applications_icon
  @applications_icon
end

#applications_icon_positionObject

x, y position of the Applications symlink icon on the custom DMG Default: a useful position for the icon against the default background



174
175
176
# File 'lib/choctop.rb', line 174

def applications_icon_position
  @applications_icon_position
end

#background_fileObject

Path to background .icns image file for custom DMG Value should be file path relative to root of project Default: a choctop supplied background image that matches to default app_icon_position + applications_icon_position To have no custom background, set value to nil



166
167
168
# File 'lib/choctop.rb', line 166

def background_file
  @background_file
end

#base_urlObject

The url from where the xml + dmg files will be downloaded Default: dir path from appcast_filename



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

def base_url
  @base_url
end

#build_optsObject

Returns the value of attribute build_opts.



16
17
18
# File 'lib/choctop.rb', line 16

def build_opts
  @build_opts
end

#build_productsObject

Returns the value of attribute build_products.



113
114
115
# File 'lib/choctop.rb', line 113

def build_products
  @build_products
end

#build_typeObject

The build type of the distributed DMG file Default: Release



46
47
48
# File 'lib/choctop.rb', line 46

def build_type
  @build_type
end

#codesign_identityObject

Returns the value of attribute codesign_identity.



198
199
200
# File 'lib/choctop.rb', line 198

def codesign_identity
  @codesign_identity
end

#filesObject

List of files/bundles to be packaged into the DMG



73
74
75
# File 'lib/choctop.rb', line 73

def files
  @files
end

#generate_index_phpObject

goddamn nuisance



94
95
96
# File 'lib/choctop.rb', line 94

def generate_index_php
  @generate_index_php
end

#hostObject

The host name, e.g. some-domain.com Default: host from base_url



54
55
56
# File 'lib/choctop.rb', line 54

def host
  @host
end

#icon_sizeObject

Size of icons, in pixels, within custom DMG (between 16 and 128) Default: 104 - this is nice and big



187
188
189
# File 'lib/choctop.rb', line 187

def icon_size
  @icon_size
end

#icon_text_sizeObject

Icon text size Can pass integer (12) or string (“12” or “12 px”) Default: 12 (px)



192
193
194
# File 'lib/choctop.rb', line 192

def icon_text_size
  @icon_text_size
end

#info_plist_pathObject

Path to the Info.plist Default: “Info.plist”



23
24
25
# File 'lib/choctop.rb', line 23

def info_plist_path
  @info_plist_path
end

#nameObject

The name of the Cocoa application Default: info_plist or project folder name if “$EXECUTABLE_NAME”



27
28
29
# File 'lib/choctop.rb', line 27

def name
  @name
end

#readmeObject

The file name for the project readme file Default: README.txt



70
71
72
# File 'lib/choctop.rb', line 70

def readme
  @readme
end

#release_notesObject

The file name for generated release notes for the latest release Default: release_notes.html



66
67
68
# File 'lib/choctop.rb', line 66

def release_notes
  @release_notes
end

#release_notes_templateObject

The path for an HTML template into which the release_notes.txt are inserted after conversion to HTML

The template file is an ERb template, with <%= yield %> as the placeholder for the generated release notes.

Currently, any CSS or JavaScript must be inline

Default: release_notes_template.html.erb, which was generated by install_choctop into each project



84
85
86
# File 'lib/choctop.rb', line 84

def release_notes_template
  @release_notes_template
end

#remote_dirObject

The remote directory where the xml + dmg files will be uploaded



91
92
93
# File 'lib/choctop.rb', line 91

def remote_dir
  @remote_dir
end

#rsync_argsObject

The argument flags passed to rsync Default: -aCv



107
108
109
# File 'lib/choctop.rb', line 107

def rsync_args
  @rsync_args
end

#scp_argsObject

Additional arguments to pass to scp e.g. -P 11222



111
112
113
# File 'lib/choctop.rb', line 111

def scp_args
  @scp_args
end

#src_folderObject

Folder from where all files will be copied into the DMG Files are copied here if specified with add_file before DMG creation



120
121
122
# File 'lib/choctop.rb', line 120

def src_folder
  @src_folder
end

#su_feed_urlObject

The Sparkle feed URL Default: info_plist



50
51
52
# File 'lib/choctop.rb', line 50

def su_feed_url
  @su_feed_url
end

#targetObject

The target name of the distributed DMG file Default: ##name.app



35
36
37
# File 'lib/choctop.rb', line 35

def target
  @target
end

#transportObject

Defines the transport to use for upload, default is :rsync, :scp is also available



100
101
102
# File 'lib/choctop.rb', line 100

def transport
  @transport
end

#userObject

The user to log in on the remote server. Default: empty



58
59
60
# File 'lib/choctop.rb', line 58

def user
  @user
end

#versionObject

The version of the Cocoa application Default: info_plist



31
32
33
# File 'lib/choctop.rb', line 31

def version
  @version
end

#volume_iconObject

Path to an .icns file for the DMG’s volume icon (looks like a disk or drive) Default: a DMG icon provided within choctop To get default, boring blank DMG volume icon, set value to nil



179
180
181
# File 'lib/choctop.rb', line 179

def volume_icon
  @volume_icon
end

Instance Method Details

#build_pathObject

Path to built DMG, sparkle’s xml file and other assets to be uploaded to remote server



143
144
145
# File 'lib/choctop.rb', line 143

def build_path
  "appcast/build"
end

#define_tasksObject



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/choctop.rb', line 267

def define_tasks
  return unless Object.const_defined?("Rake")
  
  desc "Build Xcode #{build_type}"
  task :build => "build/#{build_type}/#{target}/Contents/Info.plist"
  
  task "build/#{build_type}/#{target}/Contents/Info.plist" do
    make_build
  end
  
  desc "Create the dmg file for appcasting"
  task :dmg => :build do
    detach_dmg
    make_dmg
    detach_dmg
    convert_dmg_readonly
    add_eula
  end
  
  desc "Create/update the appcast file"
  task :feed do
    make_appcast
    make_dmg_symlink
    make_index_redirect if generate_index_php == true
    make_release_notes
  end
  
  desc "Upload the appcast file to the host"
  task :upload => :feed do
    upload_appcast
  end

  task :detach_dmg do
    detach_dmg
  end
  
  task :size do
    puts configure_dmg_window
  end
end

#file(*args, &block) ⇒ Object Also known as: add_file

Add an explicit file/bundle/folder into the DMG Examples:

file 'build/Release/SampleApp.app', :position => [50, 100]
file :target_bundle, :position => [50, 100]
file proc { 'README.txt' }, :position => [50, 100]
file :position => [50, 100] { 'README.txt' }

Required option:

+:position+ - two item array [x, y] window position


223
224
225
226
227
228
# File 'lib/choctop.rb', line 223

def file(*args, &block)
  path_or_helper, options = args.first.is_a?(Hash) ? [block, args.first] : [args.first, args.last]
  throw "add_files #{path_or_helper}, :position => [x,y] option is missing" unless options[:position]
  self.files ||= {}
  files[path_or_helper] = options
end

#info_plistObject



211
212
213
# File 'lib/choctop.rb', line 211

def info_plist
  @info_plist ||= OSX::NSDictionary.dictionaryWithContentsOfFile(File.expand_path(info_plist_path)) || {}
end

#mountpointObject



147
148
149
150
# File 'lib/choctop.rb', line 147

def mountpoint
  # @mountpoint ||= "/tmp/build/mountpoint#{rand(10000000)}"
  @mountpoint ||= "/Volumes"
end

#pkgObject

Path to generated package DMG



138
139
140
# File 'lib/choctop.rb', line 138

def pkg
  "#{build_path}/#{pkg_name}"
end

#pkg_nameObject

Generated filename for a distribution, from name, version and .dmg e.g. MyApp-1.0.0.dmg



127
128
129
# File 'lib/choctop.rb', line 127

def pkg_name
  version ? "#{name}-#{version}.dmg" : versionless_pkg_name
end

#pkg_relative_urlObject

The url for the remote package, without the protocol + host e.g. if absolute url is mydomain.com/downloads/MyApp-1.0.dmg then pkg_relative_url is /downloads/MyApp-1.0.dmg



206
207
208
209
# File 'lib/choctop.rb', line 206

def pkg_relative_url
  _base_url = base_url.gsub(%r{/$}, '')
  "#{_base_url}/#{pkg_name}".gsub(%r{^.*#{host}}, '')
end

#target_bundleObject



40
41
42
# File 'lib/choctop.rb', line 40

def target_bundle
  @target_bundle ||= Dir["#{build_products}/#{name}.*"].first
end

#versionless_pkg_nameObject

Version-less generated filename for a distribution, from name and .dmg e.g. MyApp.dmg



133
134
135
# File 'lib/choctop.rb', line 133

def versionless_pkg_name
  "#{name}.dmg"
end

#volume_pathObject

Path to Volume when DMG is mounted



153
154
155
# File 'lib/choctop.rb', line 153

def volume_path
  "#{mountpoint}/#{name}"
end