Class: Pindo::Command::Deploy::Initconfig

Inherits:
Pindo::Command::Deploy show all
Defined in:
lib/pindo/command/deploy/initconfig.rb

Constant Summary

Constants inherited from Pindo::Command

Pindo::Command::DEFAULT_OPTIONS, Pindo::Command::DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

run

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Initconfig

Returns a new instance of Initconfig.



27
28
29
30
31
32
# File 'lib/pindo/command/deploy/initconfig.rb', line 27

def initialize(argv)
  @bundle_id = argv.shift_argument 
  @test_flag = argv.flag?('test', false)
  super
  @additional_args = argv.remainder!
end

Class Method Details

.optionsObject



21
22
23
24
25
# File 'lib/pindo/command/deploy/initconfig.rb', line 21

def self.options
  [
    ['--test', 'use dev build mode']
  ].concat(super)
end

Instance Method Details

#modify_repo_setting(repo_name: nil, owner_org: nil) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/pindo/command/deploy/initconfig.rb', line 86

def modify_repo_setting(repo_name:nil, owner_org:nil)
    pindo_setting_dir = pindo_single_config.pindo_env_configdir
    git_repo_file = pindo_single_config.git_base_url_fullname
    git_repo_json = JSON.parse(File.read(git_repo_file))
    git_repo_json = git_repo_json || {}
    if git_repo_json 
      git_repo_json[repo_name] = owner_org
    end
    File.open(git_repo_file, "w") do |f|
      f.write(JSON.pretty_generate(git_repo_json))
    end
    git_addpush_repo(path:pindo_setting_dir, message:"add #{repo_name}")
end

#runObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pindo/command/deploy/initconfig.rb', line 49

def run

  @gitee_client = GiteeClient.new(access_token:pindo_single_config.gitee_api_key)

  demo_dir = clong_buildconfig_repo(repo_name: pindo_single_config.demo_bundle_id) 

  public_type = 0
  owner_org = pindo_single_config.build_deploy_org
  repo_name = @bundle_id

  if @test_flag
    owner_org = pindo_single_config.build_test_org
    public_type = 2
  end

  success = @gitee_client.gitee_create_repo(owner:owner_org, repo_name:repo_name, public_type:public_type)
  if success

      if @test_flag
        modify_repo_setting(repo_name:repo_name, owner_org:owner_org)
      end

      app_config_dir = clong_buildconfig_repo(repo_name: repo_name)
      system 'open ' + app_config_dir

      if File.exist?(app_config_dir)                     
        update_appconfig_repo(resDir:demo_dir, desDir:app_config_dir)
      else
        puts "Creaate app config repo error !!!"
      end
  else
    app_config_dir = clong_buildconfig_repo(repo_name: repo_name)
    system 'open ' + app_config_dir
  end

end

#update_appconfig_repo(resDir: nil, desDir: nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/pindo/command/deploy/initconfig.rb', line 100

def update_appconfig_repo(resDir:nil, desDir:nil)
  if File.exist?(resDir) 
    
    if File.exist?(File.join(resDir, "config.json"))
      FileUtils.cp_r(File.join(resDir, "config.json"), desDir)
    end

    if File.exist?(File.join(resDir, "fastlane"))
      FileUtils.cp_r(File.join(resDir, "fastlane"), desDir)
    end

    if File.exist?(File.join(resDir, "launch"))
      FileUtils.cp_r(File.join(resDir, "launch"), desDir)
    end

    text = File.read(File.join(desDir, "config.json"))
    new_contents = text.gsub(/#{pindo_single_config.demo_bundle_id}/, "#{@bundle_id}")
    File.open(File.join(desDir, "config.json"), "w") {|file| file.puts new_contents }
    
    git_addpush_repo(path:desDir, message:"init app config")

  end
end

#validate!Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pindo/command/deploy/initconfig.rb', line 34

def validate!
  super

  if @bundle_id.nil?
    
    say "需要输入仓库名称, 默认以bundle id作为仓库名称"

    @bundle_id = ask('bundle id: ') || nil
    
  end

  help! '你需要输入一个仓库名称' if @bundle_id.nil? || @bundle_id.empty?

end