Sha256: d1cbe4e3c56590d40004f238f8556a77f0ebcbdbe399cbe107fb245de7db11b1
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require 'faraday' require 'faraday_middleware' require 'net/http' require 'uri' require 'lhj/config' module Lhj class Command # sync config class Init < Command self.summary = '初始化控件' self.description = '使用工具前先执行`lhj init`' def handle FileUtils.mkdir_p(target_folder) unless File.exist?(target_folder) download_file end def down_load_urls %w[http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/localizable_config.yml http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/oss_config.yml http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/yapi.yml http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/pod_config.yml http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/main_config.yml] end def target_folder Lhj::Config.instance.home_dir end def save_file(url, target) http_client = Faraday.new do |c| c.adapter Faraday.default_adapter end response = http_client.get(url) File.open(target, 'wb') { |fp| fp.write(response.body) } end def file_name_with_url(url) url.scan(%r{/([^/]+)}).flatten.last end def download_file down_load_urls.each do |url| file_name = file_name_with_url(url) file_path = File.join(target_folder, file_name) save_file(url, file_path) unless File.exist?(file_path) end puts "工具初始化完成 \n" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lhj-tools-0.1.9 | lib/lhj/command/init.rb |