spinjector 0.0.1 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1df47e374d69631e9106daf013bd0b2e57cea05f9e99e4f2fa3fd5d019a5036c
4
- data.tar.gz: 8b29d180bab07ea5b1d40c14cca971674f9b5cffba2cc918fbb2dec59074ed64
3
+ metadata.gz: 13754e7fa2165ee93579dd1d2064c9eb5e692ef67a2e2b7cd59f8a755b14a21b
4
+ data.tar.gz: 21e6d78086b4ed644eaf628c1548fc6570f198d2ad3aaf224d51da41e4d065ba
5
5
  SHA512:
6
- metadata.gz: c71c9217b566eba894bc6ea1d9e6173c1a3ae6e1039ee0073e533d115861199364c7692e0d1753a1fcd655582b190c4955199668d3d7c055a940140444eba7fe
7
- data.tar.gz: 464e24d8fb992378ee8fe306daca6e1241363e38771290e7004eef0eea731ff622355636db8f2025a560cd8835d8cfe9872ce98924897f49953b3a1d5e573bb7
6
+ metadata.gz: f44c4b944a3a1859d5e2d9396bcc5a4ca4820d4d1b1f9633f1657b5b4f4430a60ab26bdedfa725bccba05c695a109d9e2d8e254c247a45b4d651639a88733463
7
+ data.tar.gz: 45a06ffa00166fa35326be22ac1156f1930d42e5737906e6c0f3d9a34c904ff3d5490bf3ab3e5f3403d18e9ac6bfd2f9e9f589b6a62e1b85dae45e6bdb709952
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ name: "HelloWorld"
2
+ script_path: "Scripts/helloworld.sh"
3
+ input_paths:
4
+ output_paths:
5
+ input_file_list_paths:
6
+ output_file_list_paths:
7
+ dependency_file:
8
+ execution_position: :before_compile
@@ -0,0 +1,9 @@
1
+ name: "HelloWorldExplicit"
2
+ script: |
3
+ echo Hello
4
+ echo World
5
+ input_paths:
6
+ - "Configuration/hello_world_input"
7
+ output_paths:
8
+ - "Configuration/hello_world_output"
9
+ execution_position: :before_compile
@@ -0,0 +1,3 @@
1
+ name: "HelloWorldShort"
2
+ script_path: "Scripts/helloworld.sh"
3
+ execution_position: :after_compile
@@ -0,0 +1,18 @@
1
+ scripts:
2
+ foo:
3
+ name: "Foo"
4
+ script_path: "Scripts/helloworld.sh"
5
+ bar:
6
+ name: "Bar"
7
+ script: |
8
+ echo Bar
9
+ execution_position: :after_compile
10
+
11
+ targets:
12
+ TargetNameA:
13
+ - foo
14
+ - "helloworld.yaml"
15
+ - bar
16
+ - "helloworld_explicit_script.yaml"
17
+ TargetNameB:
18
+ - "helloworld_short.yaml"
Binary file
@@ -0,0 +1 @@
1
+ echo "Hello World"
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # spinjector
2
+ Inject Script phase in your Xcode project easily.
3
+
4
+ # How to install
5
+
6
+ ```
7
+ gem install spinjector
8
+ ```
9
+
10
+ # How to use
11
+ ## Global configuration file
12
+ First, create a YAML configuration file under `./Configuration/spinjector_configuration.yaml` (default path where spinjector looks for a configuration file).
13
+
14
+ ```
15
+ scripts:
16
+ foo:
17
+ name: "Foo"
18
+ script: |
19
+ echo Foo
20
+ execution_position: :after_compile
21
+
22
+ targets:
23
+ TargetNameA:
24
+ - foo
25
+ - "helloworld.yaml"
26
+ - "helloworld_explicit_script.yaml"
27
+ TargetNameB:
28
+ - "helloworld_short.yaml"
29
+ - foo
30
+
31
+ ```
32
+
33
+ ## Script configuration file
34
+ Then, for each script you want to inject in your Xcode project:
35
+ - You can use `scripts` section in the global configuration file to define your script directly (eg. `foo`)...
36
+
37
+ - ...Or create a script configuration file (eg. `helloworld.yaml`)
38
+
39
+ ```
40
+ name: "Hello World" # required. Script phase name.
41
+
42
+ # One and only one :script_path or :script may appear.
43
+ # For now, it makes no sense to have 2 differents script sources.
44
+ script_path: "Script/helloworld.sh" # required. Script file path.
45
+ script: | # required. Script.
46
+ <some code lines>
47
+ <other code lines>
48
+
49
+ input_paths: # optional.
50
+ - ""
51
+
52
+ output_paths: # optional.
53
+ - ""
54
+
55
+ input_file_list_paths: # optional.
56
+ - ""
57
+
58
+ output_file_list_paths: # optional.
59
+ - ""
60
+
61
+ dependency_file: # optional.
62
+
63
+ execution_position: # optional. [:before-compile | :after-compile | :before-headers | :after-headers].
64
+ ```
65
+
66
+ - If you use the `script_path option, create the script file
67
+ ```
68
+ echo Hello World
69
+ ```
70
+
71
+ ## Execution
72
+ Finally, inject script phases
73
+ ```
74
+ spinjector [-c] <path-to-your-global-configuration-file>
75
+ ```
76
+
77
+ Enjoy your build phases
78
+ ![Image of your build phases](/Examples/Images/build_phases.png)
79
+ ![Image of hello world 2 build phase](/Examples/Images/hello_world_explicit.png)
data/bin/spinjector ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spinjector'
data/lib/spinjector.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  # @author Guillaume Berthier
4
4
  #
5
5
 
6
+ require 'optparse'
6
7
  require 'xcodeproj'
7
8
  require 'yaml'
8
9
 
@@ -13,6 +14,16 @@ BUILD_PHASE_PREFIX = '[SPI] '.freeze
13
14
 
14
15
  CONFIGURATION_FILE_PATH = 'Configuration/spinjector_configuration.yaml'.freeze
15
16
 
17
+ options = {}
18
+ OptionParser.new do |opts|
19
+ opts.banner = "Usage: spinjector [options]"
20
+
21
+
22
+ opts.on("-cName", "--configuration-path=Name", "Inject scripts using configuration file at Name location. Default is ./#{CONFIGURATION_FILE_PATH}") do |config_path|
23
+ options[:configuration_path] = config_path
24
+ end
25
+ end.parse!
26
+
16
27
  # @param [Xcodeproj::Project] project
17
28
  #
18
29
  def remove_all_spi_script_phases(project)
@@ -29,13 +40,23 @@ end
29
40
 
30
41
  # @param [Xcodeproj::Project] project
31
42
  #
32
- def inject_script_phases(project)
33
- configuration_file = load_yml_content(CONFIGURATION_FILE_PATH)
34
- configuration_file.each do |target_name, script_paths|
35
- return unless !target_name.nil?
43
+ def inject_script_phases(project, configuration_file_path)
44
+ configuration_file = load_yml_content(configuration_file_path)
45
+ # Check if there are scripts in the global configuration file
46
+ implicit_scripts = configuration_file["scripts"] || []
47
+ configuration_file["targets"].each do |target_name, script_paths|
36
48
  script_phases = (script_paths || []).flat_map do |script_path|
37
- load_yml_content(script_path)
49
+ if !implicit_scripts.empty? and !implicit_scripts[script_path].nil?
50
+ # Target uses script from the global configuration file
51
+ script = implicit_scripts[script_path]
52
+ else
53
+ # Target uses script from a dedicated configuration file
54
+ script = load_yml_content(script_path)
55
+ end
56
+ raise "[Error] Could not find script #{script_path}" unless !script.nil?
57
+ script
38
58
  end
59
+ warn "[Warning] No script phases found for #{target_name} target. You can add them in your configuration file at #{configuration_file_path}" unless !script_phases.empty?
39
60
  target = app_target(project, target_name)
40
61
  create_script_phases(script_phases, target)
41
62
  end
@@ -45,10 +66,7 @@ end
45
66
  # @return [Hash] the hash in the configuration file
46
67
  #
47
68
  def load_yml_content(configuration_path)
48
- if !File.exist?(configuration_path)
49
- puts "Script phase #{configuration_path} unknown"
50
- return {}
51
- end
69
+ raise "[Error] YAML file #{configuration_path} not found." unless File.exist?(configuration_path)
52
70
  YAML.load(File.read(configuration_path)) || {}
53
71
  end
54
72
 
@@ -58,7 +76,7 @@ end
58
76
  #
59
77
  def app_target(project, target_name)
60
78
  target = project.targets.find { |t| t.name == target_name }
61
- puts "Invalid #{target_name} target." unless !target.nil?
79
+ raise "[Error] Invalid #{target_name} target." unless !target.nil?
62
80
  return target
63
81
  end
64
82
 
@@ -69,8 +87,8 @@ def create_script_phases(script_phases, target)
69
87
  script_phases.each do |script_phase|
70
88
  name_with_prefix = BUILD_PHASE_PREFIX + script_phase["name"]
71
89
  phase = target.new_shell_script_build_phase(name_with_prefix)
72
- script = File.read(script_phase["script_path"])
73
- phase.shell_script = script
90
+ shell_script = get_script(script_phase)
91
+ phase.shell_script = shell_script
74
92
  phase.shell_path = script_phase["shell_path"] || '/bin/sh'
75
93
  phase.input_paths = script_phase["input_paths"]
76
94
  phase.output_paths = script_phase["output_paths"]
@@ -88,6 +106,27 @@ def create_script_phases(script_phases, target)
88
106
  end
89
107
  end
90
108
 
109
+ # @param [Hash] script_phase the script phase defined in configuration files
110
+ # @return [String] script to add in script phase
111
+ #
112
+ # If script is in a dedicated file, find the URL under <script_path>.
113
+ # Otherwise, it may be written directly in the configuration file, find it under <script>.
114
+ #
115
+ def get_script(script_phase)
116
+ if !script_phase["script"].nil? and !script_phase["script_path"].nil?
117
+ raise "[Error] Script phase #{script_phase["name"]} contains 2 script sources. Please use one of :script_path or :script option"
118
+ end
119
+ if !script_phase["script_path"].nil?
120
+ raise "[Error] File #{script_phase["script_path"]} does not exist" unless File.exist?(script_phase["script_path"])
121
+ File.read(script_phase["script_path"])
122
+ elsif !script_phase["script"].nil?
123
+ script_phase["script"]
124
+ else
125
+ warn "[Warning] Script phase #{script_phase["name"]} contains no script"
126
+ return ""
127
+ end
128
+ end
129
+
91
130
  # @param [Xcodeproj::Project::Object::PBXNativeTarget] target where build phases should be reordered
92
131
  # @param [Hash] script_phase to reorder
93
132
  # @param [Symbol] execution_position could be :before_compile, :after_compile, :before_headers, :after_headers
@@ -135,7 +174,9 @@ end
135
174
 
136
175
  project_path = Dir.glob("*.xcodeproj").first
137
176
  project = Xcodeproj::Project.open(project_path)
177
+ raise "[Error] No xcodeproj found" unless !project.nil?
138
178
  remove_all_spi_script_phases(project)
139
- inject_script_phases(project)
179
+ configuration_file_path = options[:configuration_path] || CONFIGURATION_FILE_PATH
180
+ inject_script_phases(project, configuration_file_path)
140
181
  project.save()
141
- puts "Success"
182
+ puts "Success."
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'spinjector'
3
+ s.version = '0.0.5'
4
+ s.executables << 'spinjector'
5
+ s.summary = "Inject script phases into your Xcode project"
6
+ s.description = ""
7
+ s.authors = ["Guillaume Berthier, Fabernovel"]
8
+ s.email = 'guillaume.berthier@fabernovel.com'
9
+ # use `git ls-files -coz -x *.gem` for development
10
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
11
+ s.homepage = 'https://github.com/guillaumeberthier/spinjector'
12
+ s.license = 'MIT'
13
+
14
+ s.add_dependency 'optparse', '~> 0.1'
15
+ s.add_dependency 'xcodeproj', '~> 1.21'
16
+ s.add_dependency 'yaml', '~> 0.2'
17
+ end
metadata CHANGED
@@ -1,23 +1,79 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinjector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Berthier, Fabernovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: optparse
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: xcodeproj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.21'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.21'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yaml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.2'
13
55
  description: ''
14
56
  email: guillaume.berthier@fabernovel.com
15
- executables: []
57
+ executables:
58
+ - spinjector
16
59
  extensions: []
17
60
  extra_rdoc_files: []
18
61
  files:
62
+ - ".gitignore"
63
+ - Examples/Configuration/hello_world_input
64
+ - Examples/Configuration/hello_world_output
65
+ - Examples/Configuration/helloworld.yaml
66
+ - Examples/Configuration/helloworld_explicit_script.yaml
67
+ - Examples/Configuration/helloworld_short.yaml
68
+ - Examples/Configuration/spinjector_configuration.yaml
69
+ - Examples/Images/build_phases.png
70
+ - Examples/Images/hello_world_explicit.png
71
+ - Examples/Scripts/helloworld.sh
72
+ - README.md
73
+ - bin/spinjector
19
74
  - lib/spinjector.rb
20
- homepage: https://www.fabernovel.com
75
+ - spinjector.gemspec
76
+ homepage: https://github.com/guillaumeberthier/spinjector
21
77
  licenses:
22
78
  - MIT
23
79
  metadata: {}