create_bundle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 19e6a1ce28d7de962b1588b95752e87307329a1794dcddbf46adf6bf22b70a90
4
+ data.tar.gz: 6fbcccc3ab2f82e2cb3430a6b838b0ad9199af1b981f8ec4472c12ae6b8a8942
5
+ SHA512:
6
+ metadata.gz: b4f781f3f6c07e5e645b557b34bd798cbf684950c5e73f2da26d9d0e693f840a6d46413736b8720062c5dd467b866e9ed51b589b55f352da5eeae9f1fc267040
7
+ data.tar.gz: d379f9e15d425b2fc695e1a518fcbaa7e2449d7f8456601b5c189900aa82ecf07f48d8b61c903e48c39b2578bb3a2f77cbe6fb0c4e9dd2f5c383c541b8f1cde0
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .rubocop.yml
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ create_bundle (0.1.3)
5
+ plist (~> 3.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ method_source (0.9.0)
12
+ plist (3.4.0)
13
+ pry (0.11.3)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ rake (10.5.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 1.16)
23
+ create_bundle!
24
+ pry (~> 0.11)
25
+ rake (~> 10.0)
26
+
27
+ BUNDLED WITH
28
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Adam Ladachowski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # CreateBundle
2
+
3
+ A simple tool for creating bare MacOS application bundles containing an icon and launch command copied from the source application.
4
+
5
+ ## Installation
6
+
7
+ $ gem install create_bundle
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ Usage: cb SOURCE_APP [DESTINATION_PATH]
13
+ ```
14
+
15
+ ## License
16
+
17
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'create_bundle/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'create_bundle'
9
+ spec.version = CreateBundle::VERSION
10
+ spec.authors = ['Adam Ladachowski']
11
+ spec.email = ['ladachowski@cic.com']
12
+
13
+ spec.summary = 'Create launcher app bundles'
14
+ spec.description = 'Create launcher app bundles with icon from app bundle'
15
+
16
+ spec.homepage = 'https://github.com/aladac/create_bundle'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
23
+ else
24
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ 'public gem pushes.'
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+ spec.required_ruby_version = '>= 2.3'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 1.16'
39
+ spec.add_development_dependency 'pry', '~> 0.11'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_dependency 'plist', '~> 3.4'
42
+ end
data/exe/cb ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'create_bundle'
5
+
6
+ options = {}
7
+
8
+ begin
9
+ OptionParser.new do |opts|
10
+ opts.banner = <<~BANNER
11
+ Usage: #{File.basename $PROGRAM_NAME} [OPTIONS] SOURCE_APP [DESTINATION_APP]
12
+ Usage: #{File.basename $PROGRAM_NAME} -i ICON -s SCRIPT -b DESTINATION_APP
13
+ BANNER
14
+
15
+ opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
16
+ options[:verbose] = v
17
+ end
18
+
19
+ opts.on('-i', '--icon PATH', 'Use a custom icon') do |icon|
20
+ options[:icon] = icon
21
+ end
22
+
23
+ opts.on('-s', '--script PATH', 'Use a custom executable') do |script|
24
+ options[:script] = script
25
+ end
26
+
27
+ opts.on('-b', '--bare', 'Create a bare bundle') do |bare|
28
+ options[:bare] = bare
29
+ end
30
+
31
+ puts opts if opts.default_argv.empty?
32
+ end.parse!
33
+ rescue OptionParser::InvalidOption => e
34
+ puts e.message
35
+ end
36
+
37
+ exit unless ARGV[0]
38
+
39
+ if options[:bare]
40
+ unless options[:script] && options[:icon]
41
+ puts 'You need to specify both a script and icon when creating a bare bundle'
42
+ exit
43
+ end
44
+ end
45
+
46
+ c = CreateBundle::Base.new(ARGV[0], ARGV[1], options[:script], options[:icon], options[:bare])
47
+ c.verbose = options[:verbose]
48
+ c.create
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CreateBundle
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'create_bundle/version'
4
+ require 'logger'
5
+ require 'plist'
6
+ require 'pathname'
7
+ require 'pry'
8
+ require 'optparse'
9
+
10
+ module CreateBundle
11
+ class Base
12
+ attr_accessor :logger, :app_path, :target_path, :verbose
13
+
14
+ def initialize(path, target_path = nil, custom_script = nil, custom_icon = nil, bare = false)
15
+ @logger = Logger.new(STDOUT)
16
+ @app_path = Pathname(path)
17
+ @custom_icon = custom_icon
18
+ @custom_script = custom_script
19
+ if bare
20
+ target_path = path
21
+ else
22
+ (logger.info("Source doesn't look like an app bundle") && exit) unless plist_path.exist?
23
+ end
24
+ @target_path = target_path ? Pathname(target_path) : Pathname(@app_path.basename.to_s)
25
+ end
26
+
27
+ def custom_icon_path
28
+ return false unless @custom_icon
29
+ if Pathname(@custom_icon).exist?
30
+ Pathname(@custom_icon)
31
+ else
32
+ puts "Icon file doesn't exist"
33
+ exit_and_cleanup
34
+ end
35
+ end
36
+
37
+ def icon_path
38
+ app_path + 'Contents' + 'Resources' + icon_file
39
+ rescue ArgumentError
40
+ logger.warn 'Problem reading source plist file, probably binary format, falling back to default icon name'
41
+ icon = app_path + 'Contents' + 'Resources' + 'AppIcon.icns'
42
+ icon || exit_and_cleanup
43
+ end
44
+
45
+ def plist_path
46
+ app_path + 'Contents' + 'Info.plist'
47
+ end
48
+
49
+ def plist
50
+ Plist.parse_xml(plist_path)
51
+ end
52
+
53
+ def icon_file
54
+ !/icns$/.match?(plist['CFBundleIconFile']) ? plist['CFBundleIconFile'] + '.icns' : plist['CFBundleIconFile']
55
+ end
56
+
57
+ def contents_dir
58
+ target_path + 'Contents'
59
+ end
60
+
61
+ def resources_dir
62
+ contents_dir + 'Resources'
63
+ end
64
+
65
+ def macos_dir
66
+ contents_dir + 'MacOS'
67
+ end
68
+
69
+ def create_dirs
70
+ [target_path, contents_dir, resources_dir, macos_dir].each { |dir| create_dir(dir) }
71
+ end
72
+
73
+ def create_dir(path)
74
+ Dir.mkdir path
75
+ logger.debug "Created dir: #{path}" if verbose
76
+ end
77
+
78
+ def create_plist
79
+ target_plist_hash = {
80
+ 'CFBundleExecutable' => 'applet',
81
+ 'CFBundleIconFile' => 'applet'
82
+ }
83
+ f = File.new(contents_dir + 'Info.plist', 'w')
84
+ f.puts target_plist_hash.to_plist
85
+ f.close
86
+ logger.debug "Created plist file: #{(contents_dir + 'Info.plist')}" if verbose
87
+ end
88
+
89
+ def copy_icon
90
+ File.link(custom_icon_path || icon_path, resources_dir + 'applet.icns')
91
+ logger.debug "Copied icon to: #{(resources_dir + 'applet.icns')}" if verbose
92
+ end
93
+
94
+ def write_script
95
+ f = File.new(macos_dir + 'applet', 'w')
96
+ f.puts "#!/bin/sh\nopen -a \"#{ARGV[0]}\""
97
+ f.close
98
+ FileUtils.chmod 0o755, macos_dir + 'applet'
99
+ logger.debug "Created exec: #{(macos_dir + 'applet')}" if verbose
100
+ end
101
+
102
+ def copy_script
103
+ return false unless @custom_script
104
+ if Pathname(@custom_script).exist?
105
+ File.link(Pathname(@custom_script), macos_dir + 'applet')
106
+ true
107
+ else
108
+ puts "Script file doesn't exist"
109
+ exit_and_cleanup
110
+ end
111
+ end
112
+
113
+ def create_exec
114
+ copy_script || write_script
115
+ end
116
+
117
+ def create
118
+ create_dirs
119
+ copy_icon
120
+ create_exec
121
+ create_plist
122
+ rescue Errno::EEXIST => e
123
+ logger.error e.message
124
+ end
125
+
126
+ def exit_and_cleanup
127
+ FileUtils.rm_rf(target_path)
128
+ exit
129
+ end
130
+ end
131
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: create_bundle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Ladachowski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: plist
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ description: Create launcher app bundles with icon from app bundle
70
+ email:
71
+ - ladachowski@cic.com
72
+ executables:
73
+ - cb
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - create_link.gemspec
84
+ - exe/cb
85
+ - lib/create_bundle.rb
86
+ - lib/create_bundle/version.rb
87
+ homepage: https://github.com/aladac/create_bundle
88
+ licenses:
89
+ - MIT
90
+ metadata:
91
+ allowed_push_host: https://rubygems.org
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '2.3'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.7.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Create launcher app bundles
112
+ test_files: []