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

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Initconfig

Returns a new instance of Initconfig.



37
38
39
40
41
42
# File 'lib/pindo/command/deploy/initconfig.rb', line 37

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

Class Method Details

.optionsObject



31
32
33
34
35
# File 'lib/pindo/command/deploy/initconfig.rb', line 31

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

Instance Method Details

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



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/pindo/command/deploy/initconfig.rb', line 96

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



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
85
86
87
88
89
90
91
92
93
94
# File 'lib/pindo/command/deploy/initconfig.rb', line 59

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pindo/command/deploy/initconfig.rb', line 110

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pindo/command/deploy/initconfig.rb', line 44

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