Module: FIR::BuildCommon
- Included in:
- Util::ClassMethods
- Defined in:
- lib/fir/util/build_common.rb
Instance Method Summary collapse
-
#convert_hash_to_assignment_string(hash) ⇒ Object
convert { “a” => “1”, “b” => “2” } => “a=‘1’ b=‘2’”.
- #git_clone_build_dir(ssh_url, options) ⇒ Object
- #initialize_build_common_options(args, options) ⇒ Object
- #initialize_build_dir(args, options) ⇒ Object
- #initialize_output_path(options) ⇒ Object
- #logger_info_and_run_build_command ⇒ Object
- #publish_build_app(options) ⇒ Object
-
#split_assignment_array_to_hash(arr) ⇒ Object
split [‘a=1’, ‘b=2’] => { ‘a’ => ‘1’, ‘b’ => ‘2’ }.
Instance Method Details
#convert_hash_to_assignment_string(hash) ⇒ Object
convert { “a” => “1”, “b” => “2” } => “a=‘1’ b=‘2’”
89 90 91 |
# File 'lib/fir/util/build_common.rb', line 89 def convert_hash_to_assignment_string(hash) hash.collect { |k, v| "#{k}='#{v}'" }.join(' ') end |
#git_clone_build_dir(ssh_url, options) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fir/util/build_common.rb', line 28 def git_clone_build_dir(ssh_url, ) repo_name = File.basename(ssh_url, '.git') + "_#{Time.now.strftime('%Y%m%dT%H%M%S')}" branch = [:branch].blank? ? 'master' : [:branch] git_cmd = "git clone --depth=50 --branch=#{branch} #{ssh_url} #{repo_name}" logger.info git_cmd logger_info_dividing_line if system(git_cmd) File.absolute_path(repo_name) else logger.error 'Git clone failed' exit 1 end end |
#initialize_build_common_options(args, options) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fir/util/build_common.rb', line 6 def (args, ) @build_dir = initialize_build_dir(args, ) @output_path = initialize_output_path() @token = [:token] || current_token @changelog = [:changelog].to_s @short = [:short].to_s @name = [:name].to_s @proj = [:proj].to_s @export_qrcode = [:qrcode] end |
#initialize_build_dir(args, options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fir/util/build_common.rb', line 17 def initialize_build_dir(args, ) build_dir = args.first.to_s if File.extname(build_dir) == '.git' args.shift && git_clone_build_dir(build_dir, ) elsif build_dir.blank? || !File.exist?(build_dir) Dir.pwd else args.shift && File.absolute_path(build_dir) end end |
#initialize_output_path(options) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fir/util/build_common.rb', line 44 def initialize_output_path() if [:output].blank? output_path = "#{@build_dir}/fir_build" FileUtils.mkdir_p(output_path) unless File.exist?(output_path) output_path else output_path = [:output].to_s unless File.exist?(output_path) logger.warn "The output path not exist and fir-cli will autocreate it..." end File.absolute_path(output_path) end end |
#logger_info_and_run_build_command ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fir/util/build_common.rb', line 63 def logger_info_and_run_build_command puts @build_cmd if $DEBUG logger.info 'Building......' logger_info_dividing_line logger.info `#{@build_cmd}` if $?.to_i != 0 logger.error 'Build failed' exit 1 end end |
#publish_build_app(options) ⇒ Object
58 59 60 61 |
# File 'lib/fir/util/build_common.rb', line 58 def publish_build_app() logger_info_blank_line publish @builded_app_path, end |
#split_assignment_array_to_hash(arr) ⇒ Object
split [‘a=1’, ‘b=2’] => { ‘a’ => ‘1’, ‘b’ => ‘2’ }
78 79 80 81 82 83 84 85 86 |
# File 'lib/fir/util/build_common.rb', line 78 def split_assignment_array_to_hash(arr) hash = {} arr.each do |assignment| k, v = assignment.split('=', 2).map(&:strip) hash[k] = v end hash end |