diff options
| author | Tom Black <[email protected]> | 2018-11-27 23:44:35 -0800 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2019-01-03 21:06:43 -0800 |
| commit | 8095e56c9d8532f6558316d4426c72baad50e043 (patch) | |
| tree | 7289a059487337c1cb0e06138099c3a1258c22c3 | |
| parent | 3ef35cdf4fd699cce93a51b1167d765324a213bd (diff) | |
| download | ruby2d-8095e56c9d8532f6558316d4426c72baad50e043.tar.gz ruby2d-8095e56c9d8532f6558316d4426c72baad50e043.zip | |
Add ability to build macOS app bundles
| -rwxr-xr-x | bin/ruby2d | 25 | ||||
| -rw-r--r-- | lib/ruby2d/cli/build.rb | 51 |
2 files changed, 64 insertions, 12 deletions
@@ -20,16 +20,19 @@ Summary of commands and options: -v|--version Prints the installed version\n\n" usage_build = " -Use the #{"build".bold} command to compile or build Ruby 2D apps. +Use the #{'build'.bold} command to compile or build Ruby 2D apps. To compile and create a native executable, use: build --native <ruby_file> To build for the web, creating a JavaScript and HTML package, use: build --web <ruby_file> - #{"Warning:".warn} #{"This feature is currently disabled while it's being upgraded.".bold} + #{'Warning:'.warn} #{"This feature is currently disabled while it's being upgraded.".bold} -To build an iOS or tvOS app, use the following: +To build a macOS app bundle, use: + build --macos <ruby_file> + +To build an iOS or tvOS app, use: build --ios <ruby_file> build --tvos <ruby_file> @@ -39,11 +42,11 @@ To build for every platform supported by the current system, use: To clean up the build directory, use: build --clean -Add the #{"--debug".bold} option to print debugging info +Add the #{'--debug'.bold} option to print debugging info and keep all intermediate files generated.\n\n" usage_launch = " -Use the #{"launch".bold} command to run a Ruby 2D app that has been built. +Use the #{'launch'.bold} command to run a Ruby 2D app that has been built. Choose one of the following options to select the kind of app to run: --native @@ -52,7 +55,7 @@ Choose one of the following options to select the kind of app to run: --tvos\n\n" usage_simulator = " -Choose an option with the #{"simulator".bold} command: +Choose an option with the #{'simulator'.bold} command: --list List available devices --booted Show currently booted devices @@ -82,15 +85,17 @@ when 'build' build_native(ARGV[2]) when '--web' build_web(ARGV[2]) + when '--macos' + build_macos(ARGV[2]) when '--ios' - build_apple(ARGV[2], 'ios') + build_ios_tvos(ARGV[2], 'ios') when '--tvos' - build_apple(ARGV[2], 'tvos') + build_ios_tvos(ARGV[2], 'tvos') when '--all' build_native(ARGV[2]) build_web(ARGV[2]) - build_apple(ARGV[2], 'ios') - build_apple(ARGV[2], 'tvos') + build_ios_tvos(ARGV[2], 'ios') + build_ios_tvos(ARGV[2], 'tvos') when '--clean' clean_up(:all) else diff --git a/lib/ruby2d/cli/build.rb b/lib/ruby2d/cli/build.rb index 92e68f7..72b80a4 100644 --- a/lib/ruby2d/cli/build.rb +++ b/lib/ruby2d/cli/build.rb @@ -114,8 +114,54 @@ def build_web(rb_file) end +# Build an app bundle for macOS +def build_macos(rb_file) + + # Build native app for macOS + build_native(rb_file) + + # Property list source for the bundle + info_plist = %( +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleExecutable</key> + <string>app</string> + <key>CFBundleIconFile</key> + <string>app.icns</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleVersion</key> + <string>1</string> + <key>NSHighResolutionCapable</key> + <string>True</string> +</dict> +</plist> +) + + # Create directories + FileUtils.mkpath 'build/App.app/Contents/MacOS' + FileUtils.mkpath 'build/App.app/Contents/Resources' + + # Create Info.plist and copy over assets + File.open('build/App.app/Contents/Info.plist', 'w') { |f| f.write(info_plist) } + FileUtils.cp 'build/app', 'build/App.app/Contents/MacOS/' + # Consider using an icon: + # FileUtils.cp "#{@gem_dir}/assets/app.icns", 'build/App.app/Contents/Resources' + + # Clean up + FileUtils.rm_f 'build/app' unless @debug + + # Success! + puts 'macOS app bundle created: `build/App.app`' +end + + # Build an iOS or tvOS app -def build_apple(rb_file, device) +def build_ios_tvos(rb_file, device) check_build_src_file(rb_file) # Check for Simple 2D framework, @@ -160,7 +206,7 @@ def build_apple(rb_file, device) clean_up unless @debug # Success! - puts "App created at `build/#{device}`" + puts "App created: `build/#{device}`" end @@ -175,6 +221,7 @@ def clean_up(cmd = nil) FileUtils.rm_f 'build/app' FileUtils.rm_f 'build/app.js' FileUtils.rm_f 'build/app.html' + FileUtils.rm_rf 'build/App.app' FileUtils.rm_rf 'build/ios' FileUtils.rm_rf 'build/tvos' end |
