xcode-utils 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b14e3134d54007d64f78bc4f8ae7e21e1c4b7e1fa8daca331531f530eb5988fc
4
- data.tar.gz: 9b7545102ade35930d143e4dcd598534c69d70cc6a0d39f9a9d28a4ec6fb3a68
3
+ metadata.gz: d58c6c3c1418f6bc12d54a2bcdb5a290da89564573d9fabeb127229658090f16
4
+ data.tar.gz: 012517dbb939e188d54b794e4cd7485c68d2cf20037ff4c7c6e1142e9b09cef0
5
5
  SHA512:
6
- metadata.gz: 4d59c829bfe2e9db38e8f9ecd7a3a4dfe092082845f5f9320ee1adf48cf9f6678916264ab181c72a1fe76e9de62c85f03c5fa660cbd6586b04da7b947fe2933e
7
- data.tar.gz: 45c0a89f7cd471f12d1031775102abbe3f588d45fcd6cc77bd0cd215af9e1443899cbcd7a178d6ea69095403153027055083f84f9df7b92a427463e03ec1c3f0
6
+ metadata.gz: 7bc9cb9139998f7a68ff3d3416d6826d8cde5df1e51d3667a3ec7dd18245d9ef701f0a25de78c134298f42958121ead1d1f3d56f634d9243882731dffee7ad29
7
+ data.tar.gz: d09c7b288867967fbfa7ec089fb155377eef94fa3eae53faa795fece8e19aeae4d2b7d0b0d6b4f9d812048c888bb09a1d584679253150334994d138eefdf8b35
data/README.md CHANGED
@@ -9,6 +9,7 @@ $ gem install xcode-utils
9
9
  ```
10
10
 
11
11
  ## UITestRunner
12
+ Make available single test page in app as standalone
12
13
 
13
14
  ### Install UITestRunner in your xcode project
14
15
  ```
@@ -121,4 +122,4 @@ $ xcutils carthage clean
121
122
 
122
123
  This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.
123
124
 
124
- > This project and all fastlane tools are in no way affiliated with Apple Inc or Google. This project is open source under the MIT license, which means you have full access to the source code and can modify it to fit your own needs. All fastlane tools run on your own computer or server, so your credentials or other sensitive information will never leave your own computer. You are responsible for how you use fastlane tools.
125
+ > This project and all fastlane tools are in no way affiliated with Apple Inc or Google. This project is open source under the MIT license, which means you have full access to the source code and can modify it to fit your own needs. All fastlane tools run on your own computer or server, so your credentials or other sensitive information will never leave your own computer. You are responsible for how you use fastlane tools.
@@ -1,5 +1,5 @@
1
1
  require 'xcodeproj'
2
- require 'xcutils/carthage/colors'
2
+ require 'xcutils/colors'
3
3
 
4
4
  module XcodeUtils
5
5
  module Carthage
@@ -24,13 +24,13 @@ module XcodeUtils
24
24
 
25
25
  def open_project
26
26
  if !Dir.exist?(@build_path)
27
- abort("😭 The Carthage build has not yet been successful. Please try again after successful arthage build.")
27
+ abort "😭 The Carthage build has not yet been successful. Please try again after successful arthage build.".red
28
28
  end
29
29
 
30
30
  project_names = Dir["./*.xcodeproj"]
31
31
 
32
32
  if project_names.first.nil?
33
- abort("😭 Does not exist project to configure.")
33
+ abort "😭 Does not exist project to configure.".red
34
34
  end
35
35
 
36
36
  puts "💎💎 Project Found -> #{project_names.first} 💎💎"
@@ -1,6 +1,7 @@
1
1
  require 'xcodeproj'
2
2
  require 'plist'
3
3
  require 'nokogiri'
4
+ require 'xcutils/colors'
4
5
 
5
6
  module XcodeUtils
6
7
  class Command
@@ -14,8 +15,8 @@ module XcodeUtils
14
15
 
15
16
  self.arguments = [
16
17
  CLAide::Argument.new('PROJECT_NAME', :true),
17
- CLAide::Argument.new('BASE_CONFIG_NAME', :true),
18
- CLAide::Argument.new('BASE_SCHEME_NAME', :true)
18
+ CLAide::Argument.new('TARGET_CONFIG_NAME', :true),
19
+ CLAide::Argument.new('TARGET_SCHEME_NAME', :true)
19
20
  ]
20
21
 
21
22
  def self.options
@@ -44,69 +45,100 @@ module XcodeUtils
44
45
  end
45
46
 
46
47
  def run
48
+ puts "Input: project_name: #{@project_name}, target_config: #{@taget_config}, target_scheme: #{@target_scheme}"
49
+ open_project
50
+ generate_project_configuration
47
51
  generate_build_configuration
48
- generate_scheme
52
+ generate_scheme_file
49
53
  copy_template_files
54
+
55
+ if !@project.nil?
56
+ @project.save()
57
+ puts "🦾 Installing Completed".green
58
+ end
50
59
  end
51
-
52
- def generate_build_configuration
53
- puts "Input: project_name: #{@project_name}, target_config: #{@taget_config}, target_scheme: #{@target_scheme}"
60
+
61
+ def open_project
62
+ puts "🤖 Installing #{@uitest_name} into #{@project_name}".green
63
+
64
+ if !Dir.exist?(@project_path)
65
+ abort "😭 Project #{project_name} does not exist.".red
66
+ end
67
+ @project = Xcodeproj::Project.open(@project_path)
68
+ end
69
+
70
+ def generate_project_configuration
71
+ puts "Generating project configuration"
54
72
 
55
- project = Xcodeproj::Project.open(@project_path)
56
- configuration_list = project.root_object.build_configuration_list
73
+ configuration_list = @project.root_object.build_configuration_list
57
74
 
58
75
  if configuration_list.build_settings(@uitest_name) != nil
59
- puts "uitest already install in the project #{@project_name}"
76
+ puts "#{@uitest_name} is already installed in the project #{@project_name}".gray
60
77
  return
61
78
  end
62
79
 
63
- puts "Initializing #{@uitest_name}"
64
- puts "Generating project configuration"
65
-
66
80
  configuration = project.new(Xcodeproj::Project::Object::XCBuildConfiguration)
67
81
  configuration.name = @uitest_name
68
82
  configuration.build_settings = configuration_list.build_settings(@taget_config)
69
83
  configuration_list.build_configurations << configuration
70
-
71
- project.targets.each do |target|
72
- break if target.build_configurations.select { |e| e.name == @uitest_name }.count > 0
73
-
74
- puts "Generating build configuration #{target.name}:#{@uitest_name}"
75
-
76
- base_config = target.build_configurations.select { |e| e.name == @taget_config }.first
77
- org_main_storyboard_file = nil
84
+ end
85
+
86
+ def generate_build_configuration
87
+ @project.targets.each { |target|
88
+ target_config = target.build_configurations.select { |e| e.name == @taget_config }.first
89
+ target_main_sb = nil
78
90
 
79
91
  target.build_configurations.each { |e|
92
+ puts "Configure build configuration #{e.name} in #{target.name}"
93
+
80
94
  path = e.build_settings['INFOPLIST_FILE']
81
- obj = Plist.parse_xml(path)
82
- var_name = '$(MAIN_STORYBOARD_FILE)'
83
- e.build_settings['MAIN_STORYBOARD_FILE'] = obj['UIMainStoryboardFile'] != var_name ? obj['UIMainStoryboardFile'] : org_main_storyboard_file
84
- obj['UIMainStoryboardFile'] = '$(MAIN_STORYBOARD_FILE)'
85
-
86
- if org_main_storyboard_file == nil
87
- org_main_storyboard_file = e.build_settings['MAIN_STORYBOARD_FILE']
95
+ plist = Plist.parse_xml(path)
96
+ plist_main_sb = plist['UIMainStoryboardFile']
97
+ variable_name = '$(MAIN_STORYBOARD_FILE)'
98
+ is_not_variable = plist_main_sb != variable_name
99
+
100
+ e.build_settings['MAIN_STORYBOARD_FILE'] = is_not_variable ? plist_main_sb : target_main_sb
101
+
102
+ if target_main_sb.nil?
103
+ target_main_sb = e.build_settings['MAIN_STORYBOARD_FILE']
88
104
  end
105
+
106
+ plist['UIMainStoryboardFile'] = variable_name
89
107
 
90
- File.write(path, obj.to_plist)
108
+ if is_not_variable
109
+ File.write(path, plist.to_plist)
110
+ end
111
+
112
+ file_names_string = e.build_settings['EXCLUDED_SOURCE_FILE_NAMES']
113
+ file_names_string = appended(file_names_string, '$(SRCROOT)/$(PRODUCT_NAME)/UITestRunner/*')
114
+ file_names_string = appended(file_names_string, '$(SRCROOT)/$(PRODUCT_NAME)/UITestRunner/**/*')
115
+ e.build_settings['EXCLUDED_SOURCE_FILE_NAMES'] = file_names_string
91
116
  }
92
-
93
- new_config = project.new(Xcodeproj::Project::Object::XCBuildConfiguration)
94
- new_config.name = @uitest_name
95
- new_config.base_configuration_reference = base_config.base_configuration_reference
96
- new_config.build_settings.update(base_config.build_settings)
117
+
118
+ test_config = target.build_configurations.select { |e| e.name == @uitest_name }.first
119
+
120
+ if test_config.nil?
121
+ puts "Generating build configuration #{@uitest_name} into #{target.name}"
122
+ new_config = project.new(Xcodeproj::Project::Object::XCBuildConfiguration)
123
+ new_config.name = @uitest_name
124
+ new_config.target_configuration_reference = target_config.base_configuration_reference
125
+ target.build_configurations << new_config
126
+ else
127
+ puts "Configure build configuration #{@uitest_name} in #{target.name}"
128
+ new_config = test_config
129
+ end
130
+
131
+ new_config.build_settings.update(target_config.build_settings)
97
132
  new_config.build_settings['MAIN_STORYBOARD_FILE'] = @uitest_name
98
-
99
- target.build_configurations << new_config
100
-
101
- puts "Generating scheme #{target.name} #{@uitest_name}"
102
-
103
- project.save()
104
- end
133
+ new_config.build_settings['EXCLUDED_SOURCE_FILE_NAMES'] = nil
134
+ }
105
135
  end
106
136
 
107
- def generate_scheme
137
+ def generate_scheme_file
108
138
  scheme_name = "#{@project_name} #{@uitest_name}"
109
139
 
140
+ puts "Generating scheme file #{scheme_path(scheme_name)}"
141
+
110
142
  FileUtils.copy_file(scheme_path(@target_scheme), scheme_path(scheme_name))
111
143
 
112
144
  scheme = Xcodeproj::XCScheme.new(scheme_path(scheme_name))
@@ -117,27 +149,28 @@ module XcodeUtils
117
149
  def copy_template_files
118
150
  template_path = "./#{@project_name}/#{@uitest_name}"
119
151
 
120
- if Dir.exist?(template_path)
121
- puts "Template files already exist in the project #{@project_name}"
122
- return
152
+ if !Dir.exist?(template_path)
153
+ puts "Copying template files into project #{@project_name}"
154
+ path = File.expand_path('../../../templates', __FILE__)
155
+ FileUtils.copy_entry path, "./#{@project_name}"
123
156
  end
124
157
 
125
- puts "Copying template files into project #{@project_name}"
126
-
127
- path = File.expand_path('../../../templates', __FILE__)
128
- FileUtils.copy_entry path, "./#{@project_name}"
129
-
130
158
  puts "Adding references for files and resources into project #{@project_name}"
131
159
 
132
- project = Xcodeproj::Project.open(@project_path)
160
+ @project.targets.each { |target|
161
+ target_group = @project.groups.select { |e| e.path == target.name }.first
133
162
 
134
- project.targets.each { |target|
135
- target_group = project.groups.select { |e| e.path == target.name }.first
136
- template_group = target_group.new_group(nil, @uitest_name)
137
- add_files("#{template_path}/*", template_group, target)
163
+ if target_group.groups.select { |e| e.path == @uitest_name }.first.nil?
164
+ template_group = target_group.new_group(nil, @uitest_name)
165
+ add_files("#{template_path}/*", template_group, target)
166
+ end
138
167
  }
139
-
140
- project.save()
168
+ end
169
+
170
+ def appended(string, other)
171
+ return other if string == nil
172
+ return string if string.include? other
173
+ return string << " #{other}"
141
174
  end
142
175
 
143
176
  def add_files(direc, current_group, main_target)
@@ -1,3 +1,3 @@
1
1
  module XcodeUtils
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
@@ -3,12 +3,10 @@
3
3
  // Copyright © 2020 abc-studio. All rights reserved.
4
4
  //
5
5
 
6
- #if DEBUG
7
6
  protocol UITestAuthorizationProvider {
8
7
  var hasAccessToken: Bool {get}
9
8
  var hasRefreshToken: Bool {get}
10
9
  func refreshToken(completion: @escaping () -> Void)
11
10
  func signIn(_ parent: UIViewController, completion: @escaping () -> Void)
12
11
  func signOut()
13
- }
14
- #endif
12
+ }
@@ -3,7 +3,6 @@
3
3
  // Copyright © 2020 abc-studio. All rights reserved.
4
4
  //
5
5
 
6
- #if DEBUG
7
6
  import Foundation
8
7
 
9
8
  protocol UITestSuiteInitializable {
@@ -20,13 +19,14 @@ class UITestSuite: UITestSuiteInitializable {
20
19
 
21
20
  static var authorizationProvider: UITestAuthorizationProvider?
22
21
 
23
- var isNewSession = false
24
- var useLogin = true
25
- var testRunnerViewController: UITestRunnerViewController! {
22
+ weak var testRunnerViewController: UITestRunnerViewController! {
26
23
  didSet {
27
24
  setUp()
28
25
  }
29
26
  }
27
+
28
+ var isNewSession = false
29
+ var useLogin = true
30
30
  var view: UIView {
31
31
  return testRunnerViewController.view
32
32
  }
@@ -86,12 +86,16 @@ class UITestSuite: UITestSuiteInitializable {
86
86
  }
87
87
 
88
88
  extension UITestSuite {
89
+ func present(_ viewController: UIViewController, animated: Bool = false, completion: (() -> Void)? = nil) {
90
+ viewController.modalPresentationStyle = .fullScreen
91
+ testRunnerViewController.present(viewController, animated: animated, completion: completion)
92
+ }
93
+
89
94
  @discardableResult
90
- func present(_ viewController: UIViewController, completion: (() -> Void)? = nil) -> UINavigationController {
91
- let navigationController = UINavigationController(rootViewController: viewController)
95
+ func present(rootViewController: UIViewController, animated: Bool = false, completion: (() -> Void)? = nil) -> UINavigationController {
96
+ let navigationController = UINavigationController(rootViewController: rootViewController)
92
97
  navigationController.modalPresentationStyle = .fullScreen
93
- testRunnerViewController.present(navigationController, animated: false, completion: completion)
98
+ testRunnerViewController.present(navigationController, animated: animated, completion: completion)
94
99
  return navigationController
95
100
  }
96
- }
97
- #endif
101
+ }
@@ -3,7 +3,6 @@
3
3
  // Copyright © 2020 abc-studio. All rights reserved.
4
4
  //
5
5
 
6
- #if DEBUG
7
6
  import Foundation
8
7
 
9
8
  final class MainTestSuite: UITestSuite {
@@ -24,5 +23,4 @@ final class MainTestSuite: UITestSuite {
24
23
  private func testExample() {
25
24
  // This is an example of a functional test case.
26
25
  }
27
- }
28
- #endif
26
+ }
@@ -3,7 +3,6 @@
3
3
  // Copyright © 2020 abc-studio. All rights reserved.
4
4
  //
5
5
 
6
- #if DEBUG
7
6
  struct UITestAuthorizationProviderImpl: UITestAuthorizationProvider {
8
7
 
9
8
  // MARK: - Implementations of Protocol UITestAuthorizationProvider
@@ -23,5 +22,4 @@ struct UITestAuthorizationProviderImpl: UITestAuthorizationProvider {
23
22
 
24
23
  func signOut() {
25
24
  }
26
- }
27
- #endif
25
+ }
@@ -3,36 +3,39 @@
3
3
  // Copyright © 2020 abc-studio. All rights reserved.
4
4
  //
5
5
 
6
- #if DEBUG
7
6
  import UIKit
8
7
 
9
8
  final class UITestRunnerViewController: UIViewController {
10
9
 
10
+ // MARK: - Private Properties
11
+
12
+ private var suite: UITestSuite!
13
+
11
14
  // MARK: - Overridden: UIViewController
12
15
 
13
16
  override func viewDidLoad() {
14
17
  super.viewDidLoad()
15
18
 
16
- title = "UITestRunner"
17
-
18
19
  UITestSuite.authorizationProvider = UITestAuthorizationProviderImpl()
20
+ }
19
21
 
20
- runTestSuites()
22
+ override func viewDidAppear(_ animated: Bool) {
23
+ super.viewDidAppear(animated)
24
+
25
+ if children.count < 1 {
26
+ runTestSuites()
27
+ }
21
28
  }
22
-
23
- // MARK: - Private Properties
24
-
25
- private var suite: UITestSuite!
26
29
 
27
30
  // MARK: - Private Methods
28
31
 
29
32
  private func runTestSuites() {
30
33
  runTestSuite(MainTestSuite.self)
31
34
  }
35
+
32
36
  private func runTestSuite<T: UITestSuite>(_ suiteType: T.Type) {
33
37
  suite = suiteType.init()
34
38
  suite.testRunnerViewController = self
35
39
  suite.run()
36
40
  }
37
- }
38
- #endif
41
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcode-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Kim
@@ -123,8 +123,8 @@ files:
123
123
  - bin/xcutils
124
124
  - lib/xcutils.rb
125
125
  - lib/xcutils/carthage.rb
126
- - lib/xcutils/carthage/colors.rb
127
126
  - lib/xcutils/carthage/xcconfig.rb
127
+ - lib/xcutils/colors.rb
128
128
  - lib/xcutils/command.rb
129
129
  - lib/xcutils/uitest.rb
130
130
  - lib/xcutils/version.rb