module BigKeeper

Bigkeeper module

Constants

DEFAULT_LOG
ERROR_LOG
HIGHLIGHT_LOG
VERSION
WARNING_LOG

Public Class Methods

client_command() click to toggle source
# File lib/big_keeper/command/client.rb, line 8
def self.client_command
  desc 'API for bigkeeper-client.'
  command :client do | c |
    c.desc 'Commands about operate modules.'
    c.command :modules do |modules|
      modules.desc 'Get modules list from Bigkeeper file.'
      modules.command :list do |list|
          list.action do |global_options, options, args|
          LeanCloudLogger.instance.set_command("spec/list")
          path = File.expand_path(global_options[:path])
          version = global_options[:ver]
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          spec_list(path, user, options)
        end
      end
      modules.desc 'Update modules.'
      modules.command :update do |update|
        update.action do |global_options, options, args|
          LeanCloudLogger.instance.set_command("spec/list")
          path = File.expand_path(global_options[:path])
          version = global_options[:ver]
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          spec_list(path, user, options)
        end
      end
    end
    c.desc 'Commands about features.'
    c.command :feature do |feature|
      feature.desc "List all the features including origin."
      feature.command :list do | list |
          list.flag %i[v version] , default_value: 'all versions'
          list.action do |global_options, options, args|
            LeanCloudLogger.instance.set_command("feature/list/json")
            options[:json] = true
            path = File.expand_path(global_options[:path])
            user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
            list(path, user, GitflowType::FEATURE, options)
        end
      end
    end
  end
end
cmd(key, value) { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 48
def self.cmd(key, value)
  BigkeeperParser.parse_command(key, value)
  yield if block_given?
end
configs() { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 33
def self.configs
  BigkeeperParser.parse_configs
  yield if block_given?
end
delete(path, user, name, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/delete.rb, line 18
def self.delete(path, user, name, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = "#{GitflowType.name(type)}/#{name}"
    version = 'all version'

    modules = BigkeeperParser.module_names
    modules.each do |module_name|
      module_full_path = BigkeeperParser.module_full_path(path, user, module_name)

      if FileOperator.definitely_exists?(module_full_path)
        StashService.new.pop_stash(module_full_path, branch_name, module_name)
        GitService.new.verify_del(module_full_path, branch_name, module_name, type)
      end
    end

    StashService.new.pop_stash(path, branch_name, 'Home')
    GitService.new.verify_del(path, branch_name, 'Home', type)
  ensure
  end
end
feature_and_hotfix_command(type) click to toggle source
# File lib/big_keeper/command/feature&hotfix.rb, line 15
def self.feature_and_hotfix_command(type)
  desc "Gitflow #{GitflowType.name(type)} operations"
  command GitflowType.command(type) do |c|
    c.desc "Start a new #{GitflowType.name(type)} with name for given modules and main project"
    c.command :start do |start|
      start.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        version = global_options[:ver]
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/start")

        help_now!('user name is required') if user and user.empty?
        help_now!("#{GitflowType.name(type)} name is required") if args.length < 1
        name = args[0]
        modules = args[(1...args.length)] if args.length > 1
        start(path, version, user, name, modules, type)
      end
    end

    c.desc "Update modules for the #{GitflowType.name(type)} with name"
    c.command :update do |update|
      update.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/update")

        help_now!('user name is required') if user and user.empty?
        modules = args[(0...args.length)] if args.length > 0
        update(path, user, modules, type)
      end
    end

    c.desc "Modules operate for the #{GitflowType.name(type)}"
    c.command :module do |m|
      m.desc "Add modules for the #{GitflowType.name(type)}"
      m.command :add do |add|
        add.action do |global_options, options, args|
          path = File.expand_path(global_options[:path])
          version = global_options[:ver]
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          LeanCloudLogger.instance.set_command("feature/module/add")
          modules = args[(0...args.length)] if args.length > 0
          module_add(path, user, modules, type)
        end
      end

      m.desc "delete modules for the #{GitflowType.name(type)}"
      m.command :delete do |delete|
        delete.action do |global_options, options, args|
          path = File.expand_path(global_options[:path])
          version = global_options[:ver]
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          LeanCloudLogger.instance.set_command("feature/module/delete")
          modules = args[(0...args.length)] if args.length > 0
          module_del(path, user, modules, type)
        end
      end
    end

    c.desc "Switch to the #{GitflowType.name(type)} with name"
    c.command :switch do |switch|
      switch.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        version = global_options[:ver]
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/switch")

        help_now!('user name is required') if user and user.empty?
        help_now!("#{GitflowType.name(type)} name is required") if args.length < 1
        name = args[0]
        switch_to(path, version, user, name, type)
      end
    end

    c.desc "Pull remote changes for current #{GitflowType.name(type)}"
    c.command :pull do |pull|
      pull.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/pull")

        help_now!('user name is required') if user and user.empty?
        pull(path, user, type)
      end
    end

    c.desc "Push local changes to remote for current #{GitflowType.name(type)}"
    c.command :push do |push|
      push.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/push")

        help_now!('user name is required') if user and user.empty?
        help_now!('comment message is required') if args.length < 1
        help_now!(%Q(comment message should be wrappered with '' or "")) if args.length > 1
        comment = args[0]
        push(path, user, comment, type)
      end
    end

    c.desc "Rebase '#{GitflowType.base_branch(type)}' to current #{GitflowType.name(type)}"
    c.command :rebase do |rebase|
      rebase.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/rebase")

        help_now!('user name is required') if user and user.empty?
        rebase(path, user, type)
      end
    end

    c.desc "Finish current #{GitflowType.name(type)}"
    c.command :finish do |finish|
      finish.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/finish")

        help_now!('user name is required') if user and user.empty?
        finish(path, user, type)
      end
    end

    c.desc "Publish current #{GitflowType.name(type)}"
    c.command :publish do |publish|
      publish.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/publish")

        help_now!('user name is required') if user and user.empty?
        publish(path, user, type)
      end
    end

    c.desc "Delete #{GitflowType.name(type)} with name"
    c.command :delete do |delete|
      delete.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/delete")

        help_now!('user name is required') if user and user.empty?
        help_now!("#{GitflowType.name(type)} name is required") if args.length < 1
        name = args[0]
        delete(path, user, name, type)
      end
    end

    c.desc "List all the #{GitflowType.name(type)}s"
    c.command :list do |list|
      list.flag %i[v version] , default_value: 'all versions'
      list.desc "Print list of TREE format."
      list.command :tree do |tree|
        tree.action do |global_options, options, args|
          LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/list/tree")

          Logger.highlight("Generating #{GitflowType.name(type)} tree of all version...") if args.length < 1
          path = File.expand_path(global_options[:path])
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          list(path, user, type, options)
        end
      end

      list.desc "Print list of JSON format."
      list.command :json do |json|
        json.action do |global_options, options, args|
          LeanCloudLogger.instance.set_command("#{GitflowType.command(type)}/list/json")

          options[:json] = true
          path = File.expand_path(global_options[:path])
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          list(path, user, type, options)
        end
      end
    end
  end
end
finish(path, user, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/finish.rb, line 17
def self.finish(path, user, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")

    branch_name = GitOperator.new.current_branch(path)
    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    # Cache git modules
    if ModuleCacheOperator.new(path).all_path_modules.empty?
      Logger.error("Branch '#{branch_name}' is already finished, exit.")
    end

    ModuleCacheOperator.new(path).cache_git_modules(ModuleCacheOperator.new(path).all_path_modules)

    modules = ModuleCacheOperator.new(path).remain_git_modules
    # Rebase modules and modify module as git
    modules.each do |module_name|
      ModuleService.new.finish(path, user, module_name, branch_name, type)
    end

    Logger.highlight("Finish branch '#{branch_name}' for 'Home'")

    # Delete all path modules
    ModuleCacheOperator.new(path).cache_path_modules([], [], [])

    # Install
    DepService.dep_operator(path, user).install(modules, OperateType::FINISH, false)

    # Open home workspace
    DepService.dep_operator(path, user).open

    # Push home changes to remote
    GitService.new.verify_push(path, "finish branch #{branch_name}", branch_name, 'Home')
  ensure
  end
end
generate_list_with_option(options, file_path, version, home_branches) click to toggle source
# File lib/big_keeper/command/feature&hotfix/list.rb, line 56
def self.generate_list_with_option(options, file_path, version, home_branches)
  if options[:json]
      ListGenerator.generate_json(file_path, home_branches, version)
  else
      ListGenerator.generate_tree(file_path, home_branches, version)
  end
end
get_module_info(path, user, type, version, home_branches, is_print_log) click to toggle source
# File lib/big_keeper/command/feature&hotfix/list.rb, line 36
def self.get_module_info(path, user, type, version, home_branches, is_print_log)
  #get module list
  modules = BigkeeperParser.module_names
  git_operator = GitOperator.new
  module_info_list = []
  modules.each do |module_name|
    module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
    #local project verify
    if !File.exist? module_full_path
      Logger.default("No local repository for module '#{module_name}', clone it...") if is_print_log
      module_git = BigkeeperParser.module_git(module_name)
      git_operator.clone(File.expand_path("#{module_full_path}/../"), module_git)
    end
    #每个模块详细信息
    module_branch_info = ModuleService.new.module_info(module_full_path, home_branches, user, type, module_name, version)
    module_info_list << module_branch_info
  end
  module_info_list
end
get_pod_version(locks, pod_name) click to toggle source
# File lib/big_keeper/command/spec/sync.rb, line 32
def self.get_pod_version(locks, pod_name)
  pod_version = Hash.new
  if locks[pod_name]
    pod_version = {"#{pod_name}" => locks[pod_name]}
  end
end
home(name, params) click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 15
def self.home(name, params)
  BigkeeperParser.parse_home(name, params)
end
image_command() click to toggle source
# File lib/big_keeper/command/image.rb, line 5
def self.image_command
  desc 'Image operations'
  command :image do | c |
    c.desc "Detect duplicate name images."
    c.command :name do | name |
      name.action do | global_options, options, args |
        LeanCloudLogger.instance.set_command("image/name")

        path = File.expand_path(global_options[:path])
        BigResources::ImageAnalyzeUtil.get_duplicate_name_file_with_type(path, BigResources::PNG)
      end
    end

    c.desc "Detect duplicate content images."
    c.command :content do | content |
      content.action do | global_options, options, args |
        LeanCloudLogger.instance.set_command("image/content")
        path = File.expand_path(global_options[:path])
        BigResources::ImageAnalyzeUtil.get_duplicate_content_file_with_type(path, BigResources::PNG)
      end
    end
  end
end
init_command() click to toggle source
# File lib/big_keeper/command/init.rb, line 7
def self.init_command
  desc 'BigKeeper file initialize'
  command :init do | c |
    c.desc "BigKeeper template file initialize."
    c.action do | global_options, options, args |
      LeanCloudLogger.instance.set_command("big/init")

      bin_path = File.dirname(__FILE__)
      bin_path = File.dirname(bin_path)
      bin_path = File.dirname(bin_path)
      bin_path = File.dirname(bin_path)
      path = global_options['path']
      Logger.highlight("Initialize BigKeeper File...")
      #template path
      source_file = File.join(bin_path, 'resources/template/BigKeeper')
      #BigKeeper file need exist path
      target_path = File.join(path, 'BigKeeper')

      if !File.exists?(target_path)
        FileUtils.cp(source_file, target_path)
        Logger.highlight("Initialize BigKeeper Complete!")
      else
        Logger.highlight("BigKeeper File Has Exist!")
      end

      LeanCloudLogger.instance.set_command("file/init")
    end
  end
end
list(path, user, type, options) click to toggle source
# File lib/big_keeper/command/feature&hotfix/list.rb, line 8
def self.list(path, user, type, options)
  BigkeeperParser.parse("#{path}/Bigkeeper")
  home_path = File.expand_path(path)
  #get home project branches
  branches = GitService.new.branchs_with_type(home_path, type)
  #get modules list
  is_print_log = false if options[:json]
  #get search version
  version = options[:version]
  cache_path = File.expand_path("#{path}/.bigkeeper")
  json_path = "#{cache_path}/branches.json"
  begin
    #get cache file path
    FileUtils.mkdir_p(cache_path) unless File.exist?(cache_path)
    file = File.new(json_path, 'w', :encoding => 'UTF-8')
    begin
      #get all modules info
      module_list_dic = get_module_info(path, user, type, version, branches, is_print_log)
      file << module_list_dic.to_json
      file.close
    end
    #print list
    generate_list_with_option(options, json_path, version, branches)
  ensure
    file.close
  end
end
mod(name, params) click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 19
def self.mod(name, params)
  BigkeeperParser.parse_mod(name, params)
end
module_add(path, user, modules, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/module.rb, line 20
def self.module_add(path, user, modules, type)
  BigkeeperParser.parse("#{path}/Bigkeeper")
  branch_name = GitOperator.new.current_branch(path)

  Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

  full_name = branch_name.gsub(/#{GitflowType.name(type)}\//, '')

  # Verify input modules
  modules = BigkeeperParser.verify_modules(modules)

  current_modules = ModuleCacheOperator.new(path).current_path_modules

  ModuleCacheOperator.new(path).clean_modules
  ModuleCacheOperator.new(path).cache_path_modules(current_modules + modules, modules, [])

  Logger.highlight("Start to add modules for branch '#{branch_name}'...")

  if modules.empty?
    Logger.default("There is nothing changed with modules #{modules}.")
  else
    # Modify podfile as path and Start modules feature
    modules.each do |module_name|
      ModuleCacheOperator.new(path).add_path_module(module_name)
      ModuleService.new.add(path, user, module_name, full_name, type)
    end
  end

  # Install
  DepService.dep_operator(path, user).install(modules, OperateType::UPDATE, false)

  # Open home workspace
  DepService.dep_operator(path, user).open
end
module_del(path, user, modules, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/module.rb, line 55
def self.module_del(path, user, modules, type)
  BigkeeperParser.parse("#{path}/Bigkeeper")
  branch_name = GitOperator.new.current_branch(path)

  Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

  full_name = branch_name.gsub(/#{GitflowType.name(type)}\//, '')

  current_modules = ModuleCacheOperator.new(path).current_path_modules

  # Verify input modules
  modules = BigkeeperParser.verify_modules(modules)

  ModuleCacheOperator.new(path).clean_modules
  ModuleCacheOperator.new(path).cache_path_modules(current_module + modules, [], modules)

  Logger.highlight("Start to delete modules for branch '#{branch_name}'...")

  if modules.empty?
    Logger.default("There is nothing changed with modules #{modules}.")
  else
    # Modify podfile as path and Start modules feature
    modules.each do |module_name|
      ModuleCacheOperator.new(path).del_path_module(module_name)
      ModuleService.new.del(path, user, module_name, full_name, type)
    end
  end

  # Install
  DepService.dep_operator(path, user).install(modules, OperateType::UPDATE, false)

  # Open home workspace
  DepService.dep_operator(path, user).open
end
modules() { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 23
def self.modules
  BigkeeperParser.parse_modules
  yield if block_given?
end
param(key, value) { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 38
def self.param(key, value)
  BigkeeperParser.parse_param(key, value)
  yield if block_given?
end
pod_command() click to toggle source
# File lib/big_keeper/command/pod.rb, line 6
def self.pod_command
  desc 'Podfile operation'
  command :podfile do |podfile|
    podfile.desc 'Podfile'

    podfile.desc 'Detect podname should be locked.'
    podfile.command :detect do |detect|
      detect.action do |global_options, options, args|
        LeanCloudLogger.instance.set_command("podfile/detect")

        path = File.expand_path(global_options[:path])
        podfile_detect(path)
      end
    end

    podfile.desc 'Lock podname should be locked.'
    podfile.command :lock do |lock|
      lock.desc 'Lock pods accouding to Podfile.'
      lock.command :module do |m|
        m.action do |global_options, options, args|
          LeanCloudLogger.instance.set_command("podfile/lock/module")

          path = File.expand_path(global_options[:path])
          podfile_lock(path, false)
        end
      end
      lock.desc 'Lock pods accouding to Podfile.lock.'
      lock.command :submodule do |s|
        s.action do |global_options, options, args|
          LeanCloudLogger.instance.set_command("podfile/lock/submodule")

          path = File.expand_path(global_options[:path])
          podfile_lock(path, true)
        end
      end

    end

    podfile.desc 'Update modules should be upgrade.'
    podfile.command :update do |update|
      update.action do |global_options, options, args|
        LeanCloudLogger.instance.set_command("podfile/update")

        path = File.expand_path(global_options[:path])
        podfile_modules_update(path)
      end
    end
  end
end
podfile_detect(path) click to toggle source
# File lib/big_keeper/command/pod/podfile.rb, line 12
def self.podfile_detect(path)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # Get modules' name
    # module_list = BigkeeperParser.module_names
    # initialize PodfileDetector
    detector = PodfileParser.instance
    detactor.parse
    # Get unlocked third party pods list
    unlock_pod_list = detector.get_unlock_pod_list
    # Print out unlock pod list
    unlock_pod_list.each do |pod_name|
      Logger.default("#{pod_name} should be locked.")
    end
    Logger.separator

end
podfile_lock(path, is_all) click to toggle source
# File lib/big_keeper/command/pod/podfile.rb, line 30
def self.podfile_lock(path, is_all)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # initialize PodfileDetector
    pod_parser = PodfileParser.instance
    #Parser Podfile.lock
    pod_parser.parse(path)
    #initialize LockfileParser
    lock_parser = LockfileParser.instance
    #Parser Podfile.lock
    lock_parser.parse(path)
    # Get unlocked third party pods list
    unlock_pod_info = lock_parser.get_unlock_pod_list(is_all)
    # Lock modules in podfile
    if unlock_pod_info.empty?
      Logger.warning("There is nothing to be locked.")
    else
      PodfileOperator.new.find_and_lock("#{path}/Podfile", unlock_pod_info)
      Logger.highlight("The Podfile has been changed.")
      Logger.separator
    end

end
podfile_modules_update(path) click to toggle source
# File lib/big_keeper/command/pod/podfile.rb, line 54
def self.podfile_modules_update(path)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # Get modules' name
    module_list = BigkeeperParser.module_names
    # initialize PodfileDetector
    detector = PodfileModuleDetector.new(path)
    # Get module latest version
    module_dictionary = detector.check_version_list
    # Check if anything should be upgrade
    if module_dictionary.empty?
      Logger.warning("There is nothing to be upgrade.")
    else
      PodfileOperator.new.find_and_upgrade("#{path}/Podfile", module_dictionary)
      Logger.highlight("The Podfile has been changed.")
    end
end
post_install() { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 43
def self.post_install
  BigkeeperParser.parse_post_install
  yield if block_given?
end
prerelease_finish(path, version, user, modules) click to toggle source
# File lib/big_keeper/command/release/home.rb, line 17
def self.prerelease_finish(path, version, user, modules)
  BigkeeperParser.parse("#{path}/Bigkeeper")
  version = BigkeeperParser.version if version == 'Version in Bigkeeper file'
  modules = BigkeeperParser.module_names
  DepService.dep_operator(path, user).prerelease_finish(path, version, user, modules)
end
prerelease_start(path, version, user, modules) click to toggle source
# File lib/big_keeper/command/release/home.rb, line 11
def self.prerelease_start(path, version, user, modules)
  BigkeeperParser.parse("#{path}/Bigkeeper")
  version = BigkeeperParser.version if version == 'Version in Bigkeeper file'
  DepService.dep_operator(path, user).prerelease_start(path, version, user, modules)
end
publish(path, user, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/publish.rb, line 17
def self.publish(path, user, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")

    branch_name = GitOperator.new.current_branch(path)
    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    path_modules = ModuleCacheOperator.new(path).current_path_modules
    Logger.error("You have unfinished modules #{path_modules}, Use 'finish' first please.") unless path_modules.empty?

    # Push modules changes to remote then rebase
    modules = ModuleCacheOperator.new(path).current_git_modules
    modules.each do |module_name|
      ModuleService.new.pre_publish(path, user, module_name, branch_name, type)
    end

    # Install
    DepService.dep_operator(path, user).install(modules, OperateType::PUBLISH, false)

    # Modify module as git
    modules.each do |module_name|
      ModuleService.new.publish(path, user, module_name, branch_name, type)
    end

    Logger.highlight("Publish branch '#{branch_name}' for 'Home'")

    # [CHG] try to fix publish bug
    # Recover home
    # DepService.dep_operator(path, user).recover

    # Push home changes to remote
    GitService.new.verify_push(path, "publish branch #{branch_name}", branch_name, 'Home')
    # Rebase Home
    GitService.new.verify_rebase(path, GitflowType.base_branch(type), 'Home')

    current_cmd = LeanCloudLogger.instance.command
    cmds = BigkeeperParser.post_install_command

    if cmds && (cmds.keys.include? current_cmd)
      cmd = BigkeeperParser.post_install_command[current_cmd]
      if path
        Dir.chdir(path) do
          system cmd
        end
      end
    else
      `open #{BigkeeperParser.home_pulls()}`
    end
  ensure
  end
end
pull(path, user, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/pull.rb, line 7
def self.pull(path, user, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    modules = ModuleCacheOperator.new(path).current_path_modules

    modules.each do |module_name|
      ModuleService.new.pull(path, user, module_name, branch_name, type)
    end

    Logger.highlight("Pull branch '#{branch_name}' for 'Home'...")
    GitOperator.new.pull(path)
  ensure
  end
end
push(path, user, comment, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/push.rb, line 8
def self.push(path, user, comment, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    modules = ModuleCacheOperator.new(path).current_path_modules

    modules.each do |module_name|
      ModuleService.new.push(path, user, module_name, branch_name, type, comment)
    end

    Logger.highlight("Push branch '#{branch_name}' for 'Home'...")
    GitService.new.verify_push(path, comment, branch_name, 'Home')
  ensure
  end
end
rebase(path, user, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/rebase.rb, line 7
def self.rebase(path, user, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    modules = ModuleCacheOperator.new(path).current_path_modules

    modules.each do |module_name|
      ModuleService.new.rebase(path, user, module_name, branch_name, type)
    end

    Logger.highlight("Rebase '#{GitflowType.base_branch(type)}' "\
      "to branch '#{branch_name}' for 'Home'...")

    # Rebase Home
    Logger.error("You have some changes in branch '#{branch_name}' "\
      "for 'Home'. Use 'push' first please") if GitOperator.new.has_changes(path)

    GitService.new.verify_rebase(path, GitflowType.base_branch(type), 'Home')
  ensure
  end
end
release_command() click to toggle source
# File lib/big_keeper/command/release.rb, line 7
def self.release_command
  desc 'Prerelease home project command'
  command :prerelease do |c|
    c.desc 'Prerelease home project start. (for Andriod)'
    c.command :start do |start|
      start.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        version = global_options[:ver]
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("prerelease/start")

        help_now!('user name is required') if user and user.empty?
        raise Logger.error("release version is required") if version == nil
        modules = args[(0...args.length)] if args.length > 0
        prerelease_start(path, version, user, modules)
      end
    end

    c.desc 'Prerelease home project finish.'
    c.command :finish do |finish|
      finish.action do |global_options, options, args|
        path = File.expand_path(global_options[:path])
        version = global_options[:ver]
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        LeanCloudLogger.instance.set_command("prerelease/start")

        help_now!('user name is required') if user and user.empty?
        raise Logger.error("release version is required") if version == nil
        modules = args[(0...args.length)] if args.length > 0
        prerelease_finish(path, version, user, modules)
      end
    end
  end

  desc 'Release home project & module.'
  command :release do |c|
    c.desc 'Release home project & module.'
    c.command :home do |home|
      home.desc 'Start release home project'
      home.command :start do |start|
        start.action do |global_options, options, args|
          path = File.expand_path(global_options[:path])
          version = global_options[:ver]
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          LeanCloudLogger.instance.set_command("release/home/start")

          help_now!('user name is required') if user and user.empty?
          raise Logger.error("release version is required") if version == nil
          modules = args[(0...args.length)] if args.length > 0
          release_home_start(path, version, user, modules)
        end
      end

      home.desc 'Finish release home project'
      home.command :finish do |finish|
        finish.action do |global_options, options, args|
          path = File.expand_path(global_options[:path])
          version = global_options[:ver]
          user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
          LeanCloudLogger.instance.set_command("release/home/finish")

          help_now!('user name is required') if user and user.empty?
          raise Logger.error("release version is required") if version == nil
          release_home_finish(path, version, user, modules)
        end
      end
    end

    c.desc 'if ignore warning'
    c.switch [:i,:ignore]
    c.desc 'Release single module operations (for iOS)'
    c.command :module do |m|
      m.action do |global_options, options, args|
        LeanCloudLogger.instance.set_command("release/module")
        path = File.expand_path(global_options[:path])
        version = global_options[:ver]
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        help_now!('module name is required') if args.length == 0
        raise Logger.error("release version is required") if version == nil
        modules = args[(0...args.length)] if args.length > 0
        release_module(path, version, user, modules, options[:spec])
      end
    end
  end
end
release_home_finish(path, version, user, modules) click to toggle source
# File lib/big_keeper/command/release/home.rb, line 28
  def self.release_home_finish(path, version, user, modules)
    BigkeeperParser.parse("#{path}/Bigkeeper")

    version = BigkeeperParser.version if version == 'Version in Bigkeeper file'
    modules = []
    BigkeeperParser.module_names.each do |module_name|
      module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
      if GitOperator.new.has_branch(module_full_path, "release/#{version}")
        Logger.highlight("#{module_name} has release/#{version}")
        modules << module_name
      end
    end
54322
    DepService.dep_operator(path, user).release_home_finish(path, version, user, modules)
  end
release_home_start(path, version, user, modules) click to toggle source
# File lib/big_keeper/command/release/home.rb, line 24
def self.release_home_start(path, version, user, modules)
  DepService.dep_operator(path, user).release_home_start(path, version, user, modules)
end
release_module(path, version, user, modules, spec) click to toggle source
# File lib/big_keeper/command/release/module.rb, line 11
def self.release_module(path, version, user, modules, spec)
  BigkeeperParser.parse("#{path}/Bigkeeper")

  if !CommandLineUtil.double_check("modules #{modules} will publish version #{version}, are you sure?")
    Logger.error('module prerelease interrupt')
  end

  version = BigkeeperParser.version if version == 'Version in Bigkeeper file'

  for module_name in modules
    module_path = BigkeeperParser.module_full_path(path, user, module_name)

    StashService.new.stash(module_path, GitOperator.new.current_branch(module_path), module_name)
    GitService.new.verify_checkout_pull(module_path, "release/#{version}")
    GitService.new.verify_checkout_pull(module_path, "develop")

    has_diff = release_module_pre_check(module_path, module_name, version)

    if has_diff
      # merge release to develop
      branch_name = GitOperator.new.current_branch(module_path)
      if branch_name == "develop"
        GitOperator.new.merge_no_ff(module_path, "release/#{version}")
        GitOperator.new.push_to_remote(module_path, "develop")
      else
        Logger.error("current branch is not develop branch")
      end
    end

    # check commit
    Logger.error("current branch has unpush files") if GitOperator.new.has_changes(module_path)

    # check out master
    Logger.highlight("'#{module_name}' checkout branch to master...")
    GitService.new.verify_checkout_pull(module_path, "master")

    # merge release to master
    GitOperator.new.merge_no_ff(module_path, "release/#{version}")

    Logger.highlight(%Q(Merge "release/#{version}" to master))

    GitOperator.new.push_to_remote(module_path, "master")

    #修改 podspec 文件
    # TO DO: - advanced to use Regular Expression
    # has_change = PodfileOperator.new.podspec_change(%Q(#{module_path}/#{module_name}.podspec), version, module_name)
    # GitService.new.verify_push(module_path, "Change version number", "master", "#{module_name}") if has_change == true

    GitOperator.new.tag(module_path, version)
    # pod repo push
    if spec == true
      PodOperator.pod_repo_push(module_path, module_name, BigkeeperParser.source_spec_path(module_name), version)
    end
  end
end
release_module_pre_check(module_path, module_name, version) click to toggle source
# File lib/big_keeper/command/release/module.rb, line 67
def self.release_module_pre_check(module_path, module_name, version)
  #check
  #GitOperator.new.check_merge(module_path, "feature/#{version}")
  Logger.highlight(%Q(#{module_name} release pre-check finish))
  return GitOperator.new.check_diff(module_path, "develop", "release/#{version}")
end
source(name) { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 28
def self.source(name)
  BigkeeperParser.parse_source(name)
  yield if block_given?
end
spec_add() click to toggle source
# File lib/big_keeper/command/spec/add.rb, line 6
def self.spec_add
  Logger.default('Coming soon.')
end
spec_analyze(path,is_all,find_module_names) click to toggle source
# File lib/big_keeper/command/spec/analyze.rb, line 7
def self.spec_analyze(path,is_all,find_module_names)
  # Parse Bigkeeper file
  BigkeeperParser.parse("#{path}/Bigkeeper")
  
  is_default = !is_all&&find_module_names.size==0
  if is_all && find_module_names.size>0
    Logger.error("parameter conflict: [--all] | [module_names]")
    return
  end
  Logger.highlight('Start spec analyze...')
  Logger.default(Time.now.to_s)

  # Parse Bigkeeper file
  # BigkeeperParser.parse("#{path}/Bigkeeper")
  # module_names = BigkeeperParser.module_names

  # find modules
  Logger.highlight('Get all modules...')
  module_names = []
  pod_path = path+"/Pods/"
  dir = Dir.open(pod_path)
  dir.each do |dir_name|
    if !dir_name.include?(".") && dir_name != "Headers" && dir_name != "Local Podspecs" && dir_name != "Target Support Files"
      module_names[module_names.size]=dir_name
    end
  end

  for input_moudle_name in find_module_names do
    if !module_names.include?(input_moudle_name)
      Logger.error("["+input_moudle_name+"] not exist.")
    end
  end

  # setup modules
  module_list = []
  module_keyword_map = Hash.new
  file_count = 0
  for module_name in module_names do
    library = LibraryModel.new(module_name)
    library.get_all_public_file(path)
    module_list[module_list.size]=library
    module_keyword_map[module_name]=library.keyword_list
    if is_all || find_module_names.include?(library.name)
      file_count = file_count + library.file_list.size
    end
  end
  # analyze modules spec

  Logger.highlight('Analyze modules...')
  Logger.default(Time.now.to_s)
  file_index = 0
  for library in module_list do
    if is_all || find_module_names.include?(library.name)
      Logger.default('Analyzing ' + library.name)
      file_index = file_index + library.file_list.size
      library.spec_dependece_library(module_keyword_map.clone)#(Hash.new(module_keyword_map)).to_hash)
      progress = (file_index*100.0)/file_count
      progress = format("%.02f", progress).to_f
      Logger.default('progress >>>> ' + String(progress) + '% [' + library.name + ' done] ')
    end
  end
  Logger.highlight('Analyze complete.')
  Logger.default(Time.now.to_s)

  # log spec info
  for library in module_list do
    if is_all || find_module_names.include?(library.name)
      Logger.highlight("\n-"+library.name+":")
      for spec_library in library.spec_library do
        puts " -"+spec_library
      end
    end
  end

  # save cache to file
  if is_all

  end

end
spec_command() click to toggle source
# File lib/big_keeper/command/spec.rb, line 11
def self.spec_command
  desc 'Spec operations'

  command :spec do |spec|
    spec.switch [:a,:all]
    spec.desc 'Analyze spec dependency infomation.'
    spec.command :analyze do |analyze|
      analyze.action do |global_options, options, args|
        LeanCloudLogger.instance.set_command("spec/analyze")

        path = File.expand_path(global_options[:path])
        is_all = options[:all]
        module_names = args
        spec_analyze(path, is_all, module_names)
      end
    end

    spec.desc 'List all the specs.'
    spec.command :list do | list |
      list.action do |global_options, options, args|
        LeanCloudLogger.instance.set_command("spec/list")

        path = File.expand_path(global_options[:path])
        version = global_options[:ver]
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase

        spec_list(path, user, options)
      end
    end

    spec.desc 'Sync Module dependency from Home.'
    spec.command :sync do | sync|
      sync.action do |global_options, options, args|
        LeanCloudLogger.instance.set_command("spec/sync")
        path = File.expand_path(global_options[:path])
        user = global_options[:user].gsub(/[^0-9A-Za-z]/, '').downcase
        help_now!('module name is required') if args.length != 1
        module_name = args[0]
        spec_sync(path, user, module_name)
      end
    end

    spec.desc 'Add a spec (Coming soon).'
    spec.command :add do |add|
      add.action do
        spec_add()
      end
    end

    spec.desc 'Delete a spec (Coming soon).'
    spec.command :delete do |delete|
      delete.action do
        spec_delete()
      end
    end

    spec.desc 'Search a spec with name (Coming soon).'
    spec.command :search do |search|
      search.action do
        spec_search()
      end
    end

  end
end
spec_delete() click to toggle source
# File lib/big_keeper/command/spec/delete.rb, line 6
def self.spec_delete
  Logger.default('Coming soon.')
end
spec_list(path, user, options) click to toggle source
# File lib/big_keeper/command/spec/list.rb, line 5
def self.spec_list(path, user, options)
    BigkeeperParser.parse("#{path}/Bigkeeper")
    
    module_dic = BigkeeperParser.parse_modules
    module_list = Array.new
    module_dic.keys.each do | key |
      dic = Hash["module_name" => key,
                         "git" => module_dic[key][:git],
                       "pulls" => module_dic[key][:pulls]]
      module_list << dic
    end
    json = JSON.pretty_generate(module_list)
    puts json
end
spec_sync(path, user, module_name) click to toggle source
# File lib/big_keeper/command/spec/sync.rb, line 8
def self.spec_sync(path, user, module_name)
  # Parse Bigkeeper file
  BigkeeperParser.parse("#{path}/Bigkeeper")

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)

  detector = PodspecOperator.instance
  detector.parse(module_full_path, module_name)

  lock_parser = LockfileParser.instance
  lock_parser.parse(path)

  pod_versions = Hash.new
  for pod in detector.pod_list
    pod_ver = get_pod_version(lock_parser.pods, pod)
    if pod_ver != nil
      pod_versions = pod_versions.merge(pod_ver)
    end
  end

  PodfileOperator.new.find_and_lock("#{module_full_path}/Example/Podfile", pod_versions)
  Logger.highlight("The Podfile has been changed.")
end
start(path, version, user, name, modules, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/start.rb, line 20
def self.start(path, version, user, name, modules, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")

    version = BigkeeperParser.version if version == 'Version in Bigkeeper file'
    full_name = "#{version}_#{user}_#{name}"
    branch_name = "#{GitflowType.name(type)}/#{full_name}"

    GitService.new.verify_home_branch(path, branch_name, OperateType::START)

    stash_modules = ModuleCacheOperator.new(path).all_path_modules

    # Stash current branch
    StashService.new.stash_all(path, branch_name, user, stash_modules)

    # Verify input modules
    modules = BigkeeperParser.verify_modules(modules)

    Logger.highlight("Add branch '#{branch_name}' for 'Home'...")
    # Start home feature
    GitService.new.start(path, full_name, type)

    # Clean module cache
    ModuleCacheOperator.new(path).clean_modules

    # Cache all path modules
    ModuleCacheOperator.new(path).cache_path_modules(modules, modules, [])
    modules = ModuleCacheOperator.new(path).remain_path_modules

    # Backup home
    DepService.dep_operator(path, user).backup

    # Start modules feature and modify module as path
    modules.each do |module_name|
      ModuleService.new.add(path, user, module_name, full_name, type)
    end

    # install
    DepService.dep_operator(path, user).install(modules, OperateType::START, true)

    # Open home workspace
    DepService.dep_operator(path, user).open

    # Push home changes to remote
    Logger.highlight("Push branch '#{branch_name}' for 'Home'...")
    GitService.new.verify_push(
      path,
      "init #{GitflowType.name(type)} #{full_name}",
      branch_name,
      'Home')
  ensure
  end
end
switch_to(path, version, user, full_name, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/switch.rb, line 10
def self.switch_to(path, version, user, full_name, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")

    version = BigkeeperParser.version if version == 'Version in Bigkeeper file'
    branch_name = "#{GitflowType.name(type)}/#{full_name}"

    GitService.new.verify_home_branch(path, branch_name, OperateType::SWITCH)

    stash_modules = ModuleCacheOperator.new(path).all_path_modules

    # Stash current branch
    StashService.new.stash_all(path, branch_name, user, stash_modules)

    # Switch to new feature
    GitOperator.new.checkout(path, branch_name)
    GitOperator.new.pull(path)

    # Apply home stash
    StashService.new.pop_stash(path, branch_name, 'Home')

    modules = ModuleCacheOperator.new(path).all_path_modules

    modules.each do |module_name|
      ModuleService.new.switch_to(path, user, module_name, branch_name, type)
    end

    # Install
    DepService.dep_operator(path, user).install(modules, OperateType::SWITCH, false)

    # Open home workspace
    DepService.dep_operator(path, user).open
  ensure
  end
end
update(path, user, modules, type) click to toggle source
# File lib/big_keeper/command/feature&hotfix/update.rb, line 20
def self.update(path, user, modules, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    full_name = branch_name.gsub(/#{GitflowType.name(type)}\//, '')

    current_modules = ModuleCacheOperator.new(path).current_path_modules

    # Verify input modules
    modules = BigkeeperParser.verify_modules(modules)

    Logger.highlight("Start to update modules for branch '#{branch_name}'...")

    add_modules = modules - current_modules
    del_modules = current_modules - modules

    # Clean module cache
    ModuleCacheOperator.new(path).clean_modules
    ModuleCacheOperator.new(path).cache_path_modules(modules, add_modules, del_modules)
    remain_path_modules = ModuleCacheOperator.new(path).remain_path_modules

    if add_modules.empty? and del_modules.empty?
      Logger.default("There is nothing changed with modules #{modules}.")
    else
      # Modify podfile as path and Start modules feature
      remain_path_modules.each do |module_name|
        ModuleService.new.add(path, user, module_name, full_name, type)
      end

      del_modules.each do |module_name|
        ModuleService.new.del(path, user, module_name, full_name, type)
      end
    end

    # Install
    DepService.dep_operator(path, user).install(modules, OperateType::UPDATE, false)

    # Open home workspace
    DepService.dep_operator(path, user).open
  ensure
  end
end
user(name) { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 10
def self.user(name)
  BigkeeperParser.parse_user(name)
  yield if block_given?
end
version(name) click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 6
def self.version(name)
  BigkeeperParser.parse_version(name)
end