Class: Reflex::Packager::MacOS
- Defined in:
- lib/reflex/packager/macos.rb
Overview
Packages a Reflex application as a macOS application bundle.
Constant Summary collapse
- GIT_CRUBY =
'https://github.com/xord/cruby'- TOOLS =
{ xcodegen: 'install with: brew install xcodegen', pod: 'install with: brew install cocoapods (or gem install cocoapods)', xcodebuild: 'install Xcode and run: sudo xcode-select --switch /Applications/Xcode.app' }
Instance Attribute Summary
Attributes inherited from Platform
Instance Method Summary collapse
- #build ⇒ Object
- #build_dir ⇒ Object
-
#dev_pod_paths ⇒ Object
Returns local directories of pods referenced by path, which need special handling because CocoaPods does not place development pods under PODS_ROOT and does not run their prepare_command.
- #dist_dir ⇒ Object
-
#extensions ⇒ Object
Native extensions registered with CRuby (Init_<name> symbols).
- #generate ⇒ Object
-
#icon_commands(src, iconset_dir) ⇒ Object
Returns sips command lines to resize the icon into an iconset.
-
#libraries ⇒ Object
Ruby library bundles added to the load path.
-
#pod_refs ⇒ Object
Returns => {…, ‘<pod>’ => …} resolved from the config, the <POD>_PODS_PATH env var, or the defaults.
-
#target ⇒ Object
Returns the Xcode target name: the app name without characters unsafe for target/scheme/file names.
Methods inherited from Platform
#initialize, #package, #profile, #verbose?
Constructor Details
This class inherits a constructor from Reflex::Packager::Platform
Instance Method Details
#build ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/reflex/packager/macos.rb', line 30 def build() check_tools TOOLS check_dev_pods run 'xcodegen', 'generate', chdir: build_dir run 'pod', 'install', *('--verbose' if verbose?), chdir: build_dir, env: {'os' => 'macos'} run 'xcodebuild', '-workspace', "#{target}.xcworkspace", '-scheme', target, '-configuration', 'Release', '-destination', 'platform=macOS', '-derivedDataPath', 'DerivedData', 'build', chdir: build_dir copy_app end |
#build_dir ⇒ Object
54 55 56 |
# File 'lib/reflex/packager/macos.rb', line 54 def build_dir() File.join config.dir, 'build', platform_name end |
#dev_pod_paths ⇒ Object
Returns local directories of pods referenced by path, which need special handling because CocoaPods does not place development pods under PODS_ROOT and does not run their prepare_command.
89 90 91 92 93 |
# File 'lib/reflex/packager/macos.rb', line 89 def dev_pod_paths() pod_refs .filter_map {|name, ref| [name, ref[:path]] if ref[:path]} .to_h end |
#dist_dir ⇒ Object
58 59 60 |
# File 'lib/reflex/packager/macos.rb', line 58 def dist_dir() File.join config.dir, 'dist' end |
#extensions ⇒ Object
Native extensions registered with CRuby (Init_<name> symbols).
64 65 66 |
# File 'lib/reflex/packager/macos.rb', line 64 def extensions() profile.extensions end |
#generate ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/reflex/packager/macos.rb', line 22 def generate() copy_app_files generate_icon if config.icon write 'project.yml', render('project.yml.erb') write 'Podfile', render('Podfile.erb') write 'src/main.mm', render('main.mm.erb') end |
#icon_commands(src, iconset_dir) ⇒ Object
Returns sips command lines to resize the icon into an iconset.
97 98 99 100 101 102 103 |
# File 'lib/reflex/packager/macos.rb', line 97 def icon_commands(src, iconset_dir) [16, 32, 128, 256, 512].flat_map {|size| [[size, "icon_#{size}x#{size}.png"], [size * 2, "icon_#{size}x#{size}@2x.png"]] }.map {|px, file| ['sips', '-z', px.to_s, px.to_s, src, '--out', File.join(iconset_dir, file)] } end |
#libraries ⇒ Object
Ruby library bundles added to the load path.
70 71 72 |
# File 'lib/reflex/packager/macos.rb', line 70 def libraries() profile.libraries end |
#pod_refs ⇒ Object
Returns => {…, ‘<pod>’ => …} resolved from the config, the <POD>_PODS_PATH env var, or the defaults.
77 78 79 80 81 82 83 |
# File 'lib/reflex/packager/macos.rb', line 77 def pod_refs() p = profile { 'CRuby' => pod_ref(:cruby, {git: GIT_CRUBY}), p.pod => pod_ref(p.pod_key, {git: p.git, tag: "v#{p.version}"}) } end |
#target ⇒ Object
Returns the Xcode target name: the app name without characters unsafe for target/scheme/file names.
50 51 52 |
# File 'lib/reflex/packager/macos.rb', line 50 def target() config.name.gsub(/[^A-Za-z0-9_\-]+/, '').then {_1.empty? ? 'App' : _1} end |