xphase 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/xphase +78 -0
- data/lib/xphase.rb +161 -0
- data/lib/xphase/gem_version.rb +5 -0
- data/lib/xphase/spec.rb +91 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 850640a889aed618db6c0927e3c04507b06adfb2
|
4
|
+
data.tar.gz: ac607d858501a56d28a2e814ac75b375468d7388
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4310ea63a6ae6c90f4a8fe82e670230d08108b6909a452784d627b39565d5bbbbfe8f7e4d85e224dad9b6f3db70acab5e687d397a76f8d4c119c0bf65b29a9fa
|
7
|
+
data.tar.gz: 45f1ab6a98d3a7bf72da58c58e6e1d21a6f9a1b0288cb3eaba580d14a80c17ba4986703e5caee2c6c2ec480b4de163ab2ce914641520bc44626217281ea553b0
|
data/bin/xphase
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
optparse = OptionParser.new do |opts|
|
9
|
+
|
10
|
+
opts.banner = "Usage:\n\n"
|
11
|
+
opts.banner += "\t$ xphase command [options]\n\n"
|
12
|
+
opts.banner += "Commands:\n\n"
|
13
|
+
opts.banner += "\t+ init - Creates a new template xphase.json file.\n"
|
14
|
+
opts.banner += "\t+ install - Install the phases defined in the xphase.json file.\n"
|
15
|
+
opts.banner += "\t+ uninstall - Uninstall all the shell scripts from the project.\n"
|
16
|
+
opts.banner += "\n"
|
17
|
+
opts.banner += "Options:\n"
|
18
|
+
opts.banner += "\n"
|
19
|
+
|
20
|
+
|
21
|
+
opts.on( '-v', '--version', 'Output version information' ) do
|
22
|
+
require 'xphase/gem_version'
|
23
|
+
puts "Xphase version v" + Xphase::VERSION + " by Tibor Bödecs<mail.tib@gmail.com>"
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
28
|
+
puts opts
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
begin
|
35
|
+
optparse.parse!
|
36
|
+
|
37
|
+
mandatory = []
|
38
|
+
missing = mandatory.select do |param|
|
39
|
+
options[param].nil?
|
40
|
+
end
|
41
|
+
unless missing.empty?
|
42
|
+
raise OptionParser::MissingArgument.new(missing.join(', '))
|
43
|
+
end
|
44
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
45
|
+
puts $!.to_s
|
46
|
+
puts optparse
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
|
50
|
+
command = ARGV.shift
|
51
|
+
unless command
|
52
|
+
puts "Error: command not found!\n\n"
|
53
|
+
puts optparse
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
require 'xphase'
|
58
|
+
|
59
|
+
xphase = Xphase.new
|
60
|
+
|
61
|
+
case command
|
62
|
+
when 'init'
|
63
|
+
xphase.init
|
64
|
+
exit
|
65
|
+
when 'install'
|
66
|
+
xphase.install
|
67
|
+
exit
|
68
|
+
when 'uninstall'
|
69
|
+
xphase.uninstall
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "Error: invalid command!\n\n"
|
74
|
+
puts optparse
|
75
|
+
exit
|
76
|
+
|
77
|
+
|
78
|
+
|
data/lib/xphase.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'xcodeproj'
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# cmd = "which iconer"
|
7
|
+
# value = `#{cmd}`
|
8
|
+
# puts value.empty?
|
9
|
+
|
10
|
+
# project.targets.each do |target|
|
11
|
+
# target.build_configurations.each do |config|
|
12
|
+
# config.build_settings['XPHASE_PLATFORM'] = "iOS"
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
|
16
|
+
# lib_path = "your_lib_path";
|
17
|
+
# Add the lib file as a reference
|
18
|
+
# libRef = project['Frameworks'].new_file(lib_path);
|
19
|
+
# Get the build phase
|
20
|
+
# framework_buildphase = project.objects.select{|x| x.class == Xcodeproj::Project::Object::PBXFrameworksBuildPhase}[0];
|
21
|
+
# Add it to the build phase
|
22
|
+
# framework_buildphase.add_file_reference(libRef);
|
23
|
+
|
24
|
+
class Xphase
|
25
|
+
|
26
|
+
XPHASE_FILE = "xphase.json"
|
27
|
+
|
28
|
+
|
29
|
+
def setup
|
30
|
+
puts "▸ creating phase file for your project..."
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def init
|
35
|
+
puts "Xphase started:"
|
36
|
+
|
37
|
+
puts " ▸ Creating xphase.json file..."
|
38
|
+
|
39
|
+
current_work_dir = Dir.pwd
|
40
|
+
current_file = "#{current_work_dir}/#{XPHASE_FILE}"
|
41
|
+
|
42
|
+
project = self.loadProject
|
43
|
+
|
44
|
+
phasefile = {
|
45
|
+
:* => {:phases => []}
|
46
|
+
}
|
47
|
+
|
48
|
+
project.targets.each do |target|
|
49
|
+
phasefile[target.name] = {:phases => []}
|
50
|
+
end
|
51
|
+
|
52
|
+
File.open(current_file, 'w').write(phasefile.to_json)
|
53
|
+
puts "Xphase finished running."
|
54
|
+
end
|
55
|
+
|
56
|
+
def uninstall
|
57
|
+
puts "Xphase started:"
|
58
|
+
project = self.loadProject
|
59
|
+
project.targets.each do |target|
|
60
|
+
puts " ▸ Removing phases for target: '" + target.name + "'"
|
61
|
+
target.shell_script_build_phases.each do |value|
|
62
|
+
target.build_phases.delete(value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
project.save
|
66
|
+
|
67
|
+
puts "Xphase finished running."
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def install
|
72
|
+
|
73
|
+
project = self.loadProject
|
74
|
+
json = self.loadPhases
|
75
|
+
|
76
|
+
puts "Xphase started:"
|
77
|
+
|
78
|
+
project.targets.each do |target|
|
79
|
+
puts " ▸ Setting up phases for target: '" + target.name + "'"
|
80
|
+
|
81
|
+
if !json["*"].nil? && !json["*"]["phases"].nil?
|
82
|
+
installPhasesForTarget(json["*"]["phases"], target)
|
83
|
+
end
|
84
|
+
|
85
|
+
if !json[target.name].nil? && !json[target.name]["phases"].nil?
|
86
|
+
installPhasesForTarget(json[target.name]["phases"], target)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
project.save
|
90
|
+
puts "Xphase finished running."
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def loadPhases
|
95
|
+
current_work_dir = Dir.pwd
|
96
|
+
current_file = "#{current_work_dir}/#{XPHASE_FILE}"
|
97
|
+
contents = File.open(current_file, "rb").read
|
98
|
+
json = JSON.parse(contents)
|
99
|
+
json
|
100
|
+
end
|
101
|
+
|
102
|
+
def loadProject
|
103
|
+
current_work_dir = Dir.pwd
|
104
|
+
current_source_files = "#{current_work_dir}/*.xcodeproj"
|
105
|
+
|
106
|
+
if Dir[current_source_files].count == 0
|
107
|
+
puts " ▸ No Xcode file found in the project directory."
|
108
|
+
exit -1
|
109
|
+
end
|
110
|
+
|
111
|
+
project_path = Dir[current_source_files].first
|
112
|
+
|
113
|
+
begin
|
114
|
+
project = Xcodeproj::Project.open project_path
|
115
|
+
rescue
|
116
|
+
puts " ▸ Can't open Xcode project file."
|
117
|
+
exit -1
|
118
|
+
end
|
119
|
+
|
120
|
+
project
|
121
|
+
end
|
122
|
+
|
123
|
+
def installPhasesForTarget(phases, target)
|
124
|
+
|
125
|
+
phases.each do |phase|
|
126
|
+
|
127
|
+
spec = Spec.new(phase["spec"])
|
128
|
+
|
129
|
+
if spec.nil?
|
130
|
+
puts " • Could not find phase with identifier: '" + phase["spec"] + "'"
|
131
|
+
next
|
132
|
+
end
|
133
|
+
|
134
|
+
script_name = spec.name
|
135
|
+
if !phase["name"].nil?
|
136
|
+
script_name = phase["name"]
|
137
|
+
end
|
138
|
+
script_value = spec.script(phase["params"])
|
139
|
+
|
140
|
+
puts " • Setting up '" + spec.id + "' with the name: '" + script_name + "'"
|
141
|
+
|
142
|
+
script = nil
|
143
|
+
target.shell_script_build_phases.each do |value|
|
144
|
+
if value.name == script_name
|
145
|
+
script = value
|
146
|
+
break
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if !script
|
151
|
+
script = target.new_shell_script_build_phase script_name
|
152
|
+
end
|
153
|
+
|
154
|
+
script.shell_script = script_value
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
require 'xphase/spec'
|
data/lib/xphase/spec.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
|
5
|
+
class Xphase::Spec
|
6
|
+
|
7
|
+
DEBUG = true
|
8
|
+
PATH_BASE = "https://raw.githubusercontent.com/CoreKit/xphase/master/phases/"
|
9
|
+
PATH_SPEC = "/spec.json"
|
10
|
+
PATH_SCRIPT = "/script.sh"
|
11
|
+
|
12
|
+
attr_reader :id
|
13
|
+
|
14
|
+
attr_reader :name
|
15
|
+
attr_reader :description
|
16
|
+
attr_reader :author
|
17
|
+
|
18
|
+
attr_reader :dependency
|
19
|
+
attr_reader :params
|
20
|
+
|
21
|
+
attr_reader :template
|
22
|
+
|
23
|
+
def specLocation
|
24
|
+
if ENV["XPHASE_LOCAL"].nil?
|
25
|
+
PATH_BASE + @id + PATH_SPEC
|
26
|
+
else
|
27
|
+
Dir.getwd + "/../phases/" + @id + PATH_SPEC
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def scriptLocation
|
32
|
+
if ENV["XPHASE_LOCAL"].nil?
|
33
|
+
PATH_BASE + @id + PATH_SCRIPT
|
34
|
+
else
|
35
|
+
Dir.getwd + "/../phases/" + @id + PATH_SCRIPT
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def self.new(val)
|
41
|
+
@@obj = super(val)
|
42
|
+
|
43
|
+
if @@obj.id.nil?
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
return @@obj
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def initialize(id)
|
51
|
+
@id = id
|
52
|
+
begin
|
53
|
+
if ENV["XPHASE_LOCAL"].nil?
|
54
|
+
contents = open(self.specLocation).read
|
55
|
+
@template = open(self.scriptLocation).read
|
56
|
+
else
|
57
|
+
contents = File.open(self.specLocation, "rb").read
|
58
|
+
@template = File.open(self.scriptLocation, "rb").read
|
59
|
+
end
|
60
|
+
rescue
|
61
|
+
@id = nil
|
62
|
+
return
|
63
|
+
end
|
64
|
+
|
65
|
+
json = JSON.parse(contents)
|
66
|
+
|
67
|
+
@name = json["name"]
|
68
|
+
@description = json["description"]
|
69
|
+
@author = json["author"]
|
70
|
+
|
71
|
+
@dependency = json["dependency"]
|
72
|
+
@params = json["params"]
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def script(params)
|
77
|
+
|
78
|
+
script = @template
|
79
|
+
if !params.nil?
|
80
|
+
params.each do |key, value|
|
81
|
+
if key.eql? "flags"
|
82
|
+
script = script + ' ' + value
|
83
|
+
next
|
84
|
+
end
|
85
|
+
script = script.gsub('{{'+key+'}}', value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
script
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xphase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tibor Bödecs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xcodeproj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
description: It's like a package manager for your Xcode build phases.
|
28
|
+
email: mail.tib@gmail.com
|
29
|
+
executables:
|
30
|
+
- xphase
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/xphase
|
35
|
+
- lib/xphase.rb
|
36
|
+
- lib/xphase/gem_version.rb
|
37
|
+
- lib/xphase/spec.rb
|
38
|
+
homepage: https://github.com/CoreKit/xphase
|
39
|
+
licenses:
|
40
|
+
- WTFPL
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.6.10
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Build phase manager for Xcode
|
62
|
+
test_files: []
|