class TYCiCore::TYTemplate
Constants
- TARGET_PROJECT
Attributes
configurator[RW]
Public Class Methods
new(group)
click to toggle source
# 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
Public Instance Methods
add_license()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/tuya/ci/core/template.rb, line 51 def template_project @template_project = TemplateProject.new(@configurator) @template_project.run end