Skip to content

Instantly share code, notes, and snippets.

@robertwahler
Created January 23, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertwahler/cdedcd244511c05780fbb9a4b515b1b9 to your computer and use it in GitHub Desktop.
Save robertwahler/cdedcd244511c05780fbb9a4b515b1b9 to your computer and use it in GitHub Desktop.
Ruby Thor snippet to package code on OSX
desc "osx", "create distribution package for Mac OS X"
method_option :dmg, :type => :boolean, :desc => "Create a DMG container instead of a zip file"
def osx
set_instance_variables
# clean staging folder
clean
osx_copy_to_staging(@product)
# get version info directly from JSON in staging folder in case this was build off a different version
version_filename = File.join(STAGING_FOLDER, @product, 'version.txt')
version = read_version_string(version_filename)
label = options[:label]
label = read_version_label(@product, version_filename) unless label
label = ".#{label}" if label
if options[:dmg]
# create the dmg file
source = File.join(STAGING_FOLDER, @product, "#{@product}.app".capitalize)
destination = "#{PKG_FOLDER}/#{@product}.#{version}.osx#{label}.dmg"
remove_file(destination)
run("hdiutil create #{destination} -volname #{@product} -size 200m -fs HFS+ -srcfolder #{source}")
else
source = File.join(STAGING_FOLDER, @product)
destination = "#{PKG_FOLDER}/#{@product}.#{version}.osx#{label}.zip"
remove_file(destination)
run "7za a -mx9 #{destination} #{source}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment