yk_command 0.5.0 → 0.5.1

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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/vcs.xml +2 -0
  3. data/.idea/yk_command.iml +6 -6
  4. data/Gemfile.lock +3 -3
  5. data/lib/yk_command/analyze/analyze.rb +4 -0
  6. data/lib/yk_command/bot/wx_bot.rb +0 -10
  7. data/lib/yk_command/module/module_handler.rb +119 -0
  8. data/lib/yk_command/module/template/objc/CategoryHeader.h +1 -1
  9. data/lib/yk_command/module/template/objc/RouterRegister.m +6 -5
  10. data/lib/yk_command/module/template/objc/ServiceRegister.m +1 -1
  11. data/lib/yk_command/module/yk_module.rb +138 -144
  12. data/lib/yk_command/project/YKProjectTemplate/.gitignore +37 -0
  13. data/lib/yk_command/project/YKProjectTemplate/CODE_OF_CONDUCT.md +40 -0
  14. data/lib/yk_command/project/YKProjectTemplate/LICENSE +21 -0
  15. data/lib/yk_command/project/YKProjectTemplate/NAME-osx.podspec +43 -0
  16. data/lib/yk_command/project/YKProjectTemplate/NAME.podspec +27 -0
  17. data/lib/yk_command/project/YKProjectTemplate/POD_LICENSE +19 -0
  18. data/lib/yk_command/project/YKProjectTemplate/POD_README.md +29 -0
  19. data/lib/yk_command/project/YKProjectTemplate/Pod/Assets/.gitkeep +0 -0
  20. data/lib/yk_command/project/YKProjectTemplate/Pod/Classes/.gitkeep +0 -0
  21. data/lib/yk_command/project/YKProjectTemplate/README.md +22 -0
  22. data/lib/yk_command/project/YKProjectTemplate/configure +12 -0
  23. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/Base.lproj/LaunchScreen.storyboard +31 -0
  24. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/Base.lproj/Main.storyboard +79 -0
  25. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/CPDAppDelegate.h +15 -0
  26. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/CPDAppDelegate.m +46 -0
  27. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/CPDViewController.h +13 -0
  28. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/CPDViewController.m +60 -0
  29. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/Images.xcassets/AppIcon.appiconset/Contents.json +98 -0
  30. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/PROJECT-Info.plist +49 -0
  31. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/PROJECT-Prefix.pch +16 -0
  32. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/en.lproj/InfoPlist.strings +2 -0
  33. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT/main.m +17 -0
  34. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT.xcodeproj/project.pbxproj +500 -0
  35. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  36. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/PROJECT.xcodeproj/xcshareddata/xcschemes/PROJECT.xcscheme +101 -0
  37. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/Podfile +19 -0
  38. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/Tests/Tests-Info.plist +22 -0
  39. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/Tests/Tests-Prefix.pch +7 -0
  40. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/Tests/Tests.m +9 -0
  41. data/lib/yk_command/project/YKProjectTemplate/templates/ios/Example/Tests/en.lproj/InfoPlist.strings +2 -0
  42. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT/AppDelegate.swift +26 -0
  43. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
  44. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT/Base.lproj/Main.storyboard +717 -0
  45. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT/Info.plist +30 -0
  46. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT/PROJECT.entitlements +10 -0
  47. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT/ViewController.swift +27 -0
  48. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT.xcodeproj/project.pbxproj +444 -0
  49. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  50. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/PROJECT.xcodeproj/xcshareddata/xcschemes/PROJECT.xcscheme +103 -0
  51. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/Podfile +11 -0
  52. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/Tests/Info.plist +22 -0
  53. data/lib/yk_command/project/YKProjectTemplate/templates/macos-swift/Example/Tests/Tests.swift +1 -0
  54. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT/AppDelegate.swift +46 -0
  55. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT/Base.lproj/LaunchScreen.xib +46 -0
  56. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT/Base.lproj/Main.storyboard +86 -0
  57. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  58. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT/Info.plist +39 -0
  59. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT/ViewController.swift +37 -0
  60. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT.xcodeproj/project.pbxproj +468 -0
  61. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  62. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/PROJECT.xcodeproj/xcshareddata/xcschemes/PROJECT.xcscheme +117 -0
  63. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/Podfile +20 -0
  64. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/Tests/Info.plist +24 -0
  65. data/lib/yk_command/project/YKProjectTemplate/templates/swift/Example/Tests/Tests.swift +1 -0
  66. data/lib/yk_command/project/setup/ConfigureMacOSSwift.rb +46 -0
  67. data/lib/yk_command/project/setup/ConfigureSwift.rb +40 -0
  68. data/lib/yk_command/project/setup/ConfigureiOS.rb +107 -0
  69. data/lib/yk_command/project/setup/MessageBank.rb +113 -0
  70. data/lib/yk_command/project/setup/ProjectManipulator.rb +141 -0
  71. data/lib/yk_command/project/setup/TemplateConfigurator.rb +253 -0
  72. data/lib/yk_command/project/test_examples/kiwi.m +36 -0
  73. data/lib/yk_command/project/test_examples/quick.swift +50 -0
  74. data/lib/yk_command/project/test_examples/specta.m +39 -0
  75. data/lib/yk_command/project/test_examples/xctest.m +26 -0
  76. data/lib/yk_command/project/test_examples/xctest.swift +28 -0
  77. data/lib/yk_command/project/yk_project.rb +86 -0
  78. data/lib/yk_command/version.rb +1 -1
  79. data/yk_command.gemspec +2 -1
  80. metadata +76 -11
  81. data/.YKModuleFilesConfig.yml +0 -5
  82. data//345/275/222/346/241/243.zip +0 -0
@@ -0,0 +1,40 @@
1
+ module Pod
2
+
3
+ class ConfigureSwift
4
+ attr_reader :configurator
5
+
6
+ def self.perform(options)
7
+ new(options).perform
8
+
9
+ end
10
+
11
+ def initialize(options)
12
+ @configurator = options.fetch(:configurator)
13
+ end
14
+
15
+ def perform
16
+ # keep_demo = configurator.ask_with_answers("Would you like to include a demo application with your library", ["Yes", "No"]).to_sym
17
+
18
+ keep_demo = :yes
19
+
20
+ Pod::ProjectManipulator.new({
21
+ :configurator => @configurator,
22
+ # :xcodeproj_path => "templates/swift/Example/PROJECT.xcodeproj",
23
+ :xcodeproj_path => "#{$current_dir}/templates/swift/Example/PROJECT.xcodeproj",
24
+ :platform => :ios,
25
+ :remove_demo_project => (keep_demo == :no),
26
+ :prefix => @configurator.prefix
27
+ }).run
28
+
29
+ # There has to be a single file in the Classes dir
30
+ # or a framework won't be created
31
+ `touch #{$current_dir}/Pod/Classes/ReplaceMe.swift`
32
+
33
+ `mv #{$current_dir}/templates/swift/* #{$current_dir}`
34
+
35
+ # remove podspec for osx
36
+ `rm #{$current_dir}/NAME-osx.podspec`
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,107 @@
1
+ module Pod
2
+
3
+ class ConfigureIOS
4
+ attr_reader :configurator
5
+
6
+ def self.perform(options)
7
+ new(options).perform
8
+ end
9
+
10
+ def initialize(options)
11
+ @configurator = options.fetch(:configurator)
12
+ $current_dir = @configurator.temp_path
13
+ end
14
+
15
+ def perform
16
+
17
+
18
+ # keep_demo = configurator.ask_with_answers("Would you like to include a demo application with your library", ["Yes", "No"]).to_sym
19
+ keep_demo = :yes
20
+ # framework = configurator.ask_with_answers("Which testing frameworks will you use", ["Specta", "Kiwi", "None"]).to_sym
21
+ # case framework
22
+ # when :specta
23
+ # configurator.add_pod_to_podfile "Specta"
24
+ # configurator.add_pod_to_podfile "Expecta"
25
+
26
+ # configurator.add_line_to_pch "@import Specta;"
27
+ # configurator.add_line_to_pch "@import Expecta;"
28
+
29
+ # configurator.set_test_framework("specta", "m", "ios")
30
+
31
+ # when :kiwi
32
+ # configurator.add_pod_to_podfile "Kiwi"
33
+ # configurator.add_line_to_pch "@import Kiwi;"
34
+ # configurator.set_test_framework("kiwi", "m", "ios")
35
+
36
+ # when :none
37
+ # configurator.set_test_framework("xctest", "m", "ios")
38
+ # end
39
+
40
+ # snapshots = configurator.ask_with_answers("Would you like to do view based testing", ["Yes", "No"]).to_sym
41
+ # case snapshots
42
+ # when :yes
43
+ # configurator.add_pod_to_podfile "FBSnapshotTestCase"
44
+ # configurator.add_line_to_pch "@import FBSnapshotTestCase;"
45
+
46
+ # if keep_demo == :no
47
+ # puts " Putting demo application back in, you cannot do view tests without a host application."
48
+ # keep_demo = :yes
49
+ # end
50
+
51
+ # if framework == :specta
52
+ # configurator.add_pod_to_podfile "Expecta+Snapshots"
53
+ # configurator.add_line_to_pch "@import Expecta_Snapshots;"
54
+ # end
55
+ # end
56
+
57
+ # prefix = nil
58
+ prefix = ''
59
+ # loop do
60
+ # prefix = configurator.ask("What is your class prefix").upcase
61
+
62
+ # if prefix.include?(' ')
63
+ # puts 'Your class prefix cannot contain spaces.'.red
64
+ # else
65
+ # break
66
+ # end
67
+ # end
68
+
69
+ # Pod::ProjectManipulator.new({
70
+ # :configurator => @configurator,
71
+ # :xcodeproj_path => "templates/ios/Example/PROJECT.xcodeproj",
72
+ # :platform => :ios,
73
+ # :remove_demo_project => (keep_demo == :no),
74
+ # :prefix => prefix
75
+ # }).run
76
+
77
+ Pod::ProjectManipulator.new({
78
+ :configurator => @configurator,
79
+ # :xcodeproj_path => "templates/swift/Example/PROJECT.xcodeproj",
80
+ :xcodeproj_path => "#{$current_dir}/templates/ios/Example/PROJECT.xcodeproj",
81
+ :platform => :ios,
82
+ :remove_demo_project => (keep_demo == :no),
83
+ :prefix => @configurator.prefix
84
+ }).run
85
+
86
+
87
+
88
+ # There has to be a single file in the Classes dir
89
+ # or a framework won't be created, which is now default
90
+ # `touch Pod/Classes/ReplaceMe.m`
91
+
92
+ # `mv ./templates/ios/* ./`
93
+
94
+ # # remove podspec for osx
95
+ # `rm ./NAME-osx.podspec`
96
+
97
+ `touch #{$current_dir}/Pod/Classes/ReplaceMe.swift`
98
+
99
+ `mv #{$current_dir}/templates/ios/* #{$current_dir}`
100
+
101
+ # remove podspec for osx
102
+ `rm #{$current_dir}/NAME-osx.podspec`
103
+
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,113 @@
1
+ module Pod
2
+ class MessageBank
3
+ attr_reader :configurator
4
+
5
+ def initialize(config)
6
+ @configurator = config
7
+ end
8
+
9
+ def show_prompt
10
+ print " > ".green
11
+ end
12
+
13
+ def yellow_bang
14
+ "! ".yellow
15
+ end
16
+
17
+ def green_bang
18
+ "! ".green
19
+ end
20
+
21
+ def red_bang
22
+ "! ".red
23
+ end
24
+
25
+ def run_command command, output_command=nil
26
+ output_command ||= command
27
+
28
+ puts " " + output_command.magenta
29
+ system command
30
+ end
31
+
32
+ def welcome_message
33
+ unless @configurator.validate_user_details
34
+ run_setup_questions
35
+ end
36
+
37
+ puts "\n------------------------------"
38
+ puts ""
39
+ puts "To get you started we need to ask a few questions, this should only take a minute."
40
+ puts ""
41
+
42
+ has_run_before = `defaults read org.cocoapods.pod-template HasRunBefore`.chomp == "1"
43
+
44
+ puts "If this is your first time we recommend running through with the guide: "
45
+ puts " - " + "https://guides.cocoapods.org/making/using-pod-lib-create.html".blue.underlined
46
+
47
+ if ENV["TERM_PROGRAM"] == "iTerm.app"
48
+ puts " ( hold cmd and click links to open in a browser. )".magenta
49
+ else
50
+ puts " ( hold cmd and double click links to open in a browser. )".magenta
51
+ end
52
+
53
+ unless has_run_before
54
+ puts "\n Press return to continue."
55
+ `defaults write org.cocoapods.pod-template HasRunBefore -bool true`
56
+ end
57
+
58
+ puts ""
59
+ end
60
+
61
+ def farewell_message
62
+ puts ""
63
+
64
+ puts " Ace! you're ready to go!"
65
+ puts " We will start you off by opening your project in Xcode"
66
+ pod_name = @configurator.pod_name
67
+ run_command "open '#{$current_dir}/Example/#{pod_name}.xcworkspace'", "open '#{$current_dir}/Example/#{pod_name}.xcworkspace'"
68
+ end
69
+
70
+
71
+ def run_setup_questions
72
+
73
+ puts yellow_bang + "Before you can create a new library we need to setup your git credentials."
74
+
75
+ unless @configurator.user_name.length > 0
76
+ puts "\n What is your name? "
77
+ answer = ""
78
+
79
+ loop do
80
+ show_prompt
81
+
82
+ answer = gets.chomp
83
+ break if answer.length > 0
84
+
85
+ puts red_bang + "Please enter a name."
86
+ end
87
+
88
+ puts ""
89
+ puts green_bang + "Setting your name in git to " + answer
90
+ run_command('git config user.name "' + answer + '"')
91
+ end
92
+
93
+ unless @configurator.user_email.length > 0
94
+ puts "\n What is your email?"
95
+ answer = ""
96
+
97
+ loop do
98
+ show_prompt
99
+ answer = gets.downcase.chomp
100
+ break if answer.length > 0
101
+
102
+ puts red_bang + "Please enter a email."
103
+ end
104
+
105
+ puts ""
106
+ puts green_bang + "Setting your email in git to " + answer
107
+ run_command('git config user.email "' + answer + '"')
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,141 @@
1
+ require 'xcodeproj'
2
+
3
+ module Pod
4
+
5
+ class ProjectManipulator
6
+ attr_reader :configurator, :xcodeproj_path, :platform, :remove_demo_target, :string_replacements, :prefix
7
+
8
+ def self.perform(options)
9
+ new(options).perform
10
+ end
11
+
12
+ def initialize(options)
13
+ @xcodeproj_path = options.fetch(:xcodeproj_path)
14
+ @configurator = options.fetch(:configurator)
15
+ @platform = options.fetch(:platform)
16
+ @remove_demo_target = options.fetch(:remove_demo_project)
17
+ @prefix = options.fetch(:prefix)
18
+ end
19
+
20
+ def run
21
+ @string_replacements = {
22
+ "PROJECT_OWNER" => @configurator.user_name,
23
+ "TODAYS_DATE" => @configurator.date,
24
+ "TODAYS_YEAR" => @configurator.year,
25
+ "PROJECT" => @configurator.pod_name,
26
+ "CPD" => @prefix
27
+ }
28
+ replace_internal_project_settings
29
+
30
+ @project = Xcodeproj::Project.open(@xcodeproj_path)
31
+ add_podspec_metadata
32
+ remove_demo_project if @remove_demo_target
33
+ @project.save
34
+
35
+ rename_files
36
+ rename_project_folder
37
+ end
38
+
39
+ def add_podspec_metadata
40
+ project_metadata_item = @project.root_object.main_group.children.select { |group| group.name == "Podspec Metadata" }.first
41
+ project_metadata_item.new_file "../" + @configurator.pod_name + ".podspec"
42
+ project_metadata_item.new_file "../README.md"
43
+ project_metadata_item.new_file "../LICENSE"
44
+ end
45
+
46
+ def remove_demo_project
47
+ app_project = @project.native_targets.find { |target| target.product_type == "com.apple.product-type.application" }
48
+ test_target = @project.native_targets.find { |target| target.product_type == "com.apple.product-type.bundle.unit-test" }
49
+ test_target.name = @configurator.pod_name + "_Tests"
50
+
51
+ # Remove the implicit dependency on the app
52
+ test_dependency = test_target.dependencies.first
53
+ test_dependency.remove_from_project
54
+ app_project.remove_from_project
55
+
56
+ # Remove the build target on the unit tests
57
+ test_target.build_configuration_list.build_configurations.each do |build_config|
58
+ build_config.build_settings.delete "BUNDLE_LOADER"
59
+ end
60
+
61
+ # Remove the references in xcode
62
+ project_app_group = @project.root_object.main_group.children.select { |group| group.display_name.end_with? @configurator.pod_name }.first
63
+ project_app_group.remove_from_project
64
+
65
+ # Remove the product reference
66
+ product = @project.products.select { |product| product.path == @configurator.pod_name + "_Example.app" }.first
67
+ product.remove_from_project
68
+
69
+ # Remove the actual folder + files for both projects
70
+ `rm -rf templates/ios/Example/PROJECT`
71
+ `rm -rf templates/swift/Example/PROJECT`
72
+
73
+ # Replace the Podfile with a simpler one with only one target
74
+ podfile_path = project_folder + "/Podfile"
75
+ podfile_text = <<-RUBY
76
+ use_frameworks!
77
+ target '#{test_target.name}' do
78
+ pod '#{@configurator.pod_name}', :path => '../'
79
+
80
+ ${INCLUDED_PODS}
81
+ end
82
+ RUBY
83
+ File.open(podfile_path, "w") { |file| file.puts podfile_text }
84
+ end
85
+
86
+ def project_folder
87
+ File.dirname @xcodeproj_path
88
+ end
89
+
90
+ def rename_files
91
+ # shared schemes have project specific names
92
+ scheme_path = project_folder + "/PROJECT.xcodeproj/xcshareddata/xcschemes/"
93
+ File.rename(scheme_path + "PROJECT.xcscheme", scheme_path + @configurator.pod_name + "-Example.xcscheme")
94
+
95
+ # rename xcproject
96
+ File.rename(project_folder + "/PROJECT.xcodeproj", project_folder + "/" + @configurator.pod_name + ".xcodeproj")
97
+
98
+ unless @remove_demo_target
99
+ # change app file prefixes
100
+ ["CPDAppDelegate.h", "CPDAppDelegate.m", "CPDViewController.h", "CPDViewController.m"].each do |file|
101
+ before = project_folder + "/PROJECT/" + file
102
+ next unless File.exists? before
103
+
104
+ after = project_folder + "/PROJECT/" + file.gsub("CPD", prefix)
105
+ File.rename before, after
106
+ end
107
+
108
+ # rename project related files
109
+ ["PROJECT-Info.plist", "PROJECT-Prefix.pch", "PROJECT.entitlements"].each do |file|
110
+ before = project_folder + "/PROJECT/" + file
111
+ next unless File.exists? before
112
+
113
+ after = project_folder + "/PROJECT/" + file.gsub("PROJECT", @configurator.pod_name)
114
+ File.rename before, after
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ def rename_project_folder
121
+ if Dir.exist? project_folder + "/PROJECT"
122
+ File.rename(project_folder + "/PROJECT", project_folder + "/" + @configurator.pod_name)
123
+ end
124
+ end
125
+
126
+ def replace_internal_project_settings
127
+ Dir.glob(project_folder + "/**/**/**/**").each do |name|
128
+ next if Dir.exists? name
129
+ text = File.read(name)
130
+
131
+ for find, replace in @string_replacements
132
+ text = text.gsub(find, replace)
133
+ end
134
+
135
+ File.open(name, "w") { |file| file.puts text }
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ end
@@ -0,0 +1,253 @@
1
+ require 'fileutils'
2
+ require 'colored2'
3
+
4
+ require_relative 'MessageBank'
5
+ require_relative 'ConfigureIOS'
6
+ require_relative 'ProjectManipulator'
7
+
8
+ module Pod
9
+ class TemplateConfigurator
10
+
11
+ attr_reader :pod_name, :pods_for_podfile, :prefix,:prefixes, :test_example_file, :username, :email,:temp_path
12
+
13
+ def initialize(pod_name,framework,prefix,author,temp_path)
14
+ @temp_path = temp_path
15
+ @pod_name = pod_name
16
+ @framework = framework
17
+ @prefix = prefix
18
+ @author = author
19
+
20
+ @pods_for_podfile = []
21
+ @prefixes = []
22
+ @message_bank = MessageBank.new(self)
23
+ end
24
+
25
+ def ask(question)
26
+ answer = ""
27
+ loop do
28
+ puts "\n#{question}?"
29
+
30
+ @message_bank.show_prompt
31
+ answer = gets.chomp
32
+
33
+ break if answer.length > 0
34
+
35
+ print "\nYou need to provide an answer."
36
+ end
37
+ answer
38
+ end
39
+
40
+ def ask_with_answers(question, possible_answers)
41
+
42
+ print "\n#{question}? ["
43
+
44
+ print_info = Proc.new {
45
+
46
+ possible_answers_string = possible_answers.each_with_index do |answer, i|
47
+ _answer = (i == 0) ? answer.underlined : answer
48
+ print " " + _answer
49
+ print(" /") if i != possible_answers.length-1
50
+ end
51
+ print " ]\n"
52
+ }
53
+ print_info.call
54
+
55
+ answer = ""
56
+
57
+ loop do
58
+ @message_bank.show_prompt
59
+ answer = STDIN.gets.downcase.chomp
60
+
61
+ answer = "yes" if answer == "y"
62
+ answer = "no" if answer == "n"
63
+
64
+ # default to first answer
65
+ if answer == ""
66
+ answer = possible_answers[0].downcase
67
+ print answer.yellow
68
+ end
69
+
70
+ break if possible_answers.map { |a| a.downcase }.include? answer
71
+
72
+ print "\nPossible answers are ["
73
+ print_info.call
74
+ end
75
+
76
+ answer
77
+ end
78
+
79
+ def run
80
+ # @message_bank.welcome_message
81
+
82
+ if @framework == "swift"
83
+ ConfigureSwift.perform(configurator: self)
84
+ else
85
+ ConfigureIOS.perform(configurator: self)
86
+ end
87
+
88
+ replace_variables_in_files
89
+ clean_template_files
90
+ rename_template_files
91
+
92
+ add_yk_pods
93
+
94
+ add_pods_to_podfile
95
+
96
+ customise_prefix
97
+ rename_classes_folder
98
+ ensure_carthage_compatibility
99
+ reinitialize_git_repo
100
+ run_pod_install
101
+
102
+ # @message_bank.farewell_message
103
+ end
104
+
105
+ def add_yk_pods
106
+ self.add_pod_to_podfile "YKCategoryComponent"
107
+ self.add_pod_to_podfile "YKModuleLifeCircleComponent"
108
+ self.add_pod_to_podfile "YKRouterComponent"
109
+ self.add_pod_to_podfile "YKModuleServiceComponent"
110
+
111
+ if @framework == "swift"
112
+ self.add_pod_to_podfile "SnapKit"
113
+ else
114
+ self.add_pod_to_podfile "YKModuleServiceComponent"
115
+ end
116
+
117
+ end
118
+ #----------------------------------------#
119
+
120
+ def ensure_carthage_compatibility
121
+ # FileUtils.ln_s("#{$current_dir}/Example/Pods/Pods.xcodeproj", "#{$current_dir}/_Pods.xcodeproj")
122
+ end
123
+
124
+ def run_pod_install
125
+ puts "\nRunning " + "pod install".magenta + " on your new library."
126
+ puts ""
127
+
128
+ Dir.chdir("#{$current_dir}/Example") do
129
+ # system "pod install"
130
+ end
131
+
132
+ # `git add #{$current_dir}/Example/#{pod_name}.xcodeproj/project.pbxproj`
133
+ # `git commit -m "Initial commit"`
134
+ end
135
+
136
+ def clean_template_files
137
+ ["./**/.gitkeep", "configure", "_CONFIGURE.rb", "README.md", "LICENSE", "templates", "setup", "CODE_OF_CONDUCT.md"].each do |asset|
138
+ `rm -rf #{$current_dir}/#{asset}`
139
+ end
140
+ end
141
+
142
+ def replace_variables_in_files
143
+ file_names = ['POD_LICENSE', 'POD_README.md', 'NAME.podspec', '.travis.yml', podfile_path]
144
+ file_names.each do |file_name|
145
+ # text = File.read(file_name)
146
+ text = File.read("#{$current_dir}/#{file_name}")
147
+ # text = File.read("./#{file_name}")
148
+ text.gsub!("${POD_NAME}", @pod_name)
149
+ text.gsub!("${REPO_NAME}", @pod_name.gsub('+', '-'))
150
+ text.gsub!("${USER_NAME}", user_name)
151
+ text.gsub!("${USER_EMAIL}", user_email)
152
+ text.gsub!("${YEAR}", year)
153
+ text.gsub!("${DATE}", date)
154
+ # File.open(file_name, "w") { |file| file.puts text }
155
+ File.open("#{$current_dir}/#{file_name}", "w") { |file| file.puts text }
156
+ end
157
+ end
158
+
159
+ def add_pod_to_podfile podname
160
+ @pods_for_podfile << podname
161
+ end
162
+
163
+ def add_pods_to_podfile
164
+ podfile = File.read "#{$current_dir}/#{podfile_path}"
165
+ podfile_content = @pods_for_podfile.map do |pod|
166
+ "pod '" + pod + "'"
167
+ end.join("\n ")
168
+ podfile.gsub!("${INCLUDED_PODS}", podfile_content)
169
+ File.open("#{$current_dir}/#{podfile_path}", "w") { |file| file.puts podfile }
170
+
171
+ end
172
+
173
+ def add_line_to_pch line
174
+ @prefixes << line
175
+ end
176
+
177
+ def customise_prefix
178
+ prefix_path = "Example/Tests/Tests-Prefix.pch"
179
+ return unless File.exists? prefix_path
180
+
181
+ pch = File.read prefix_path
182
+ pch.gsub!("${INCLUDED_PREFIXES}", @prefixes.join("\n ") )
183
+ File.open(prefix_path, "w") { |file| file.puts pch }
184
+ end
185
+
186
+ def set_test_framework(test_type, extension, folder)
187
+ content_path = "setup/test_examples/" + test_type + "." + extension
188
+ tests_path = "templates/" + folder + "/Example/Tests/Tests." + extension
189
+ tests = File.read tests_path
190
+ tests.gsub!("${TEST_EXAMPLE}", File.read(content_path) )
191
+ File.open(tests_path, "w") { |file| file.puts tests }
192
+ end
193
+
194
+ def rename_template_files
195
+ FileUtils.mv "#{$current_dir}/POD_README.md", "#{$current_dir}/README.md"
196
+ FileUtils.mv "#{$current_dir}/POD_LICENSE", "#{$current_dir}/LICENSE"
197
+ FileUtils.mv "#{$current_dir}/NAME.podspec", "#{$current_dir}/#{pod_name}.podspec"
198
+ end
199
+
200
+ def rename_classes_folder
201
+ # FileUtils.mv "#{@pod_name}/Pod", @pod_name
202
+ FileUtils.mv "#{$current_dir}/Pod", "#{$current_dir}/#{@pod_name}"
203
+ end
204
+
205
+
206
+ def reinitialize_git_repo
207
+ Dir.chdir("#{$current_dir}") do
208
+ `rm -rf .git`
209
+ `git init`
210
+ `git add -A`
211
+ end
212
+
213
+
214
+ end
215
+
216
+ def validate_user_details
217
+ return (user_email.length > 0) && (user_name.length > 0)
218
+ end
219
+
220
+ #----------------------------------------#
221
+
222
+ def user_name
223
+ # (ENV['GIT_COMMITTER_NAME'] || github_user_name || `git config user.name` || `<GITHUB_USERNAME>` ).strip
224
+ (ENV['GIT_COMMITTER_NAME'] || `git config user.name` || `<GITHUB_USERNAME>` ).strip
225
+
226
+ end
227
+
228
+
229
+ def github_user_name
230
+ github_user_name = `security find-internet-password -s github.com | grep acct | sed 's/"acct"<blob>="//g' | sed 's/"//g'`.strip
231
+ is_valid = github_user_name.empty? or github_user_name.include? '@'
232
+ return is_valid ? nil : github_user_name
233
+ end
234
+
235
+ def user_email
236
+ (ENV['GIT_COMMITTER_EMAIL'] || `git config user.email`).strip
237
+ end
238
+
239
+ def year
240
+ Time.now.year.to_s
241
+ end
242
+
243
+ def date
244
+ Time.now.strftime "%m/%d/%Y"
245
+ end
246
+
247
+ def podfile_path
248
+ 'Example/Podfile'
249
+ end
250
+
251
+ #----------------------------------------#
252
+ end
253
+ end
@@ -0,0 +1,36 @@
1
+ // https://github.com/kiwi-bdd/Kiwi
2
+
3
+ SPEC_BEGIN(InitialTests)
4
+
5
+ describe(@"My initial tests", ^{
6
+
7
+ context(@"will fail", ^{
8
+
9
+ it(@"can do maths", ^{
10
+ [[@1 should] equal:@2];
11
+ });
12
+
13
+ it(@"can read", ^{
14
+ [[@"number" should] equal:@"string"];
15
+ });
16
+
17
+ it(@"will wait and fail", ^{
18
+ NSObject *object = [[NSObject alloc] init];
19
+ [[expectFutureValue(object) shouldEventually] receive:@selector(autoContentAccessingProxy)];
20
+ });
21
+ });
22
+
23
+ context(@"will pass", ^{
24
+
25
+ it(@"can do maths", ^{
26
+ [[@1 should] beLessThan:@23];
27
+ });
28
+
29
+ it(@"can read", ^{
30
+ [[@"team" shouldNot] containString:@"I"];
31
+ });
32
+ });
33
+
34
+ });
35
+
36
+ SPEC_END