Class: TYCiCore::TYTemplate
- Inherits:
-
Object
- Object
- TYCiCore::TYTemplate
- Defined in:
- lib/tuya/ci/core/template.rb
Constant Summary collapse
- TARGET_PROJECT =
'TYProjectTemplate'
Instance Attribute Summary collapse
-
#configurator ⇒ Object
Returns the value of attribute configurator.
Instance Method Summary collapse
- #add_license ⇒ Object
- #adjust_download_files ⇒ Object
- #create ⇒ Object
- #download_template ⇒ Object
-
#initialize(group) ⇒ TYTemplate
constructor
A new instance of TYTemplate.
- #rename_files ⇒ Object
- #replace_content!(text) ⇒ Object
- #replace_files ⇒ Object
- #template_project ⇒ Object
Constructor Details
#initialize(group) ⇒ TYTemplate
Returns a new instance of TYTemplate.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tuya/ci/core/template.rb', line 8 def initialize(group) download_template config = TemplateConfigurator.load_config TARGET_PROJECT config.log_type type = TYAsk.ask_with_answers('Please tell me which module will be create', config.keys) puts "\n" sub_types = config.sub_types type sub_type = nil if sub_types && sub_types.size > 0 config.log_sub_type type sub_type = TYAsk.ask_with_answers("Please tell me which sub type of #{type} module will be create", sub_types) end puts "\n" config.setup type, sub_type name = TYAsk.ask'Please enter your module name' prefix = TYAsk.ask 'Please enter your Prefix' @configurator = TemplateConfigurator.new(name, config, prefix, group) @template_project = nil end |
Instance Attribute Details
#configurator ⇒ Object
Returns the value of attribute configurator.
6 7 8 |
# File 'lib/tuya/ci/core/template.rb', line 6 def configurator @configurator end |
Instance Method Details
#add_license ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tuya/ci/core/template.rb', line 79 def add_license `touch LICENSE` if File.exist? 'LICENSE' File.open('LICENSE', 'w') do |file| file.puts "Copyright (c) ${YEAR} ${USER_NAME} <${USER_EMAIL}> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." file.close end end end |
#adjust_download_files ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/tuya/ci/core/template.rb', line 56 def adjust_download_files result = File.exist? @configurator.pod_name if result puts "Folder #{@configurator.pod_name} is exists".red `rm -rf #{TARGET_PROJECT}` else `mkdir #{@configurator.pod_name}` `cp -a ./#{TARGET_PROJECT}/#{@configurator.config.alias}/ #{@configurator.pod_name}` `cp ./#{TARGET_PROJECT}/#{TYCiCore::TEMPLATE_CONFIG} #{@configurator.pod_name}/#{TYCiCore::TEMPLATE_CONFIG}` `rm -rf #{TARGET_PROJECT}` end !result end |
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tuya/ci/core/template.rb', line 34 def create if adjust_download_files template_project FileUtils.cd "#{@configurator.pod_name}" add_license rename_files replace_files FileUtils.cd "Example" # `pod update --no-repo-update` `pod update` `open #{@configurator.pod_name}.xcworkspace` FileUtils.cd ".." FileUtils.cd ".." end end |
#download_template ⇒ Object
72 73 74 75 76 77 |
# File 'lib/tuya/ci/core/template.rb', line 72 def download_template # `rm -rf #{@configurator.pod_name}` if File.exist? "./#{@configurator.pod_name}" url = TYCiCore::URL # EXE.exe('git', %W(clone -b develop #{url})) EXE.exe('git', %W(clone #{url})) end |
#rename_files ⇒ Object
107 108 109 110 |
# File 'lib/tuya/ci/core/template.rb', line 107 def rename_files FileUtils.mv @configurator.config.project, @configurator.pod_name FileUtils.mv "#{@configurator.config.project}.podspec", "#{@configurator.pod_name}.podspec" end |
#replace_content!(text) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tuya/ci/core/template.rb', line 127 def replace_content!(text) if !text.valid_encoding? text = text.encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8') end text.gsub!(/#{@configurator.config.project}/, @configurator.pod_name) text.gsub!("${POD_NAME}", @configurator.pod_name) text.gsub!("${REPO_NAME}", @configurator.pod_name.gsub('+', '-')) text.gsub!("${USER_EMAIL}", @configurator.owner_email) text.gsub!("${USER_NAME}", @configurator.owner_name) text.gsub!(/\${TODAYS_YEAR}/, @configurator.year) text.gsub!("${YEAR}", @configurator.year) text.gsub!(/\${TODAYS_DATE}/, @configurator.date) text.gsub!("${DATE}", @configurator.date) text.gsub!("${GROUP_NAME}", @configurator.group) text end |
#replace_files ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/tuya/ci/core/template.rb', line 112 def replace_files file_names = Dir.glob("**/**/**/**/**") file_names.each do |name| next if Dir.exists? name text = File.read(name) for find, replace in @template_project.string_replacements text = text.gsub(find, replace) end text = replace_content! text File.open(name, "w") { |file| file.puts text } end end |
#template_project ⇒ Object
51 52 53 54 |
# File 'lib/tuya/ci/core/template.rb', line 51 def template_project @template_project = TemplateProject.new(@configurator) @template_project.run end |