From 8095e56c9d8532f6558316d4426c72baad50e043 Mon Sep 17 00:00:00 2001 From: Tom Black Date: Tue, 27 Nov 2018 23:44:35 -0800 Subject: Add ability to build macOS app bundles --- lib/ruby2d/cli/build.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'lib') 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 = %( + + + + + CFBundleExecutable + app + CFBundleIconFile + app.icns + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleVersion + 1 + NSHighResolutionCapable + True + + +) + + # 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 -- cgit v1.2.3