Class: Pindo::Command::Jps::Upload

Inherits:
Pindo::Command::Jps show all
Defined in:
lib/pindo/command/jps/upload.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Upload

Returns a new instance of Upload.



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
95
96
97
98
99
# File 'lib/pindo/command/jps/upload.rb', line 62

def initialize(argv)

    @args_ipa_file = argv.shift_argument
    @ipa_file = argv.option('ipa')

    if !@ipa_file.nil?
        @args_ipa_file = @ipa_file
    end
    if @args_ipa_file && !@args_ipa_file.empty?
        @args_ipa_file = @args_ipa_file.strip.gsub(/\"/, '')
    end

     = argv.flag?('login', false)
    @args_send_flag = argv.flag?('send', false)
    @args_resign_flag = argv.flag?('resign', false)

    @args_proj_name = argv.option('proj')
    @args_attach_name = argv.option('attach')
    @args_upload_desc = argv.option('desc')
    @args_cert_id = argv.option('certid')



    if @args_upload_desc && !@args_upload_desc.empty?
        @args_upload_desc = @args_upload_desc.strip.gsub(/\"/, '')
    end


    if !@args_cert_id.nil? && !@args_cert_id.empty?
        @args_resign_flag = true
    end
    if @args_resign_flag
        @args_send_flag = true
    end

    super(argv)
    @additional_args = argv.remainder!
end

Class Method Details

.optionsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pindo/command/jps/upload.rb', line 47

def self.options
  [
    ['--login', '强制再次登录jps网站,用法: pindo jps upload --login'],
    ['--ipa', '强制指定上传的ipa文件: pindo jps upload --ipa=path/to/demo.ipa'],
    ['--proj', '指定哪个项目(忽略大小写空格等等字符),用法:pindo jps upload --proj=prancksoundv4'],
    ['--attach', '指定需要和ipa一起上传的附件: pindo jps upload --attach=path/to/attach.zip'],
    ['--send',  '发送消息到项目群(注意:不带此参数也会发送给自己),用法:pindo jps upload --send'],
    ['--desc', '指定上传的备注信息: -pindo jps upload -desc="1.upload message"'],
    ['--resign',  '上传到之后是否重签名,用法:pindo jps upload --resign'],
    ['--certid',  '设置重签名的正式id,用法:pindo jps upload --certid=com.test.bundleid'],

  ].concat(super)
end

Instance Method Details

#runObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/pindo/command/jps/upload.rb', line 106

def run

    current_project_dir = Dir.pwd
    build_helper = Pindo::BuildHelper.share_instance

    Dir.chdir(current_project_dir)
    is_need_add_tag,tag_action_parms = build_helper.check_is_need_add_tag?(current_project_dir)
    if is_need_add_tag
        Pindo::Command::Dev::Tag::run(tag_action_parms)
    end

    if @args_ipa_file.nil? || !File.exist?(@args_ipa_file)
        # 获取build目录下的ipa文件
        project_type = build_helper.project_type(current_project_dir)
        case project_type
        when :ios
            build_path = File.join(current_project_dir, "build", "*.{ipa,app}")
            @args_ipa_file = Dir.glob(build_path).max_by {|f| File.mtime(f)}
        when :android
            build_path = File.join(current_project_dir, "build", "*.{apk}")
            @args_ipa_file = Dir.glob(build_path).max_by {|f| File.mtime(f)}
        when :unity
            # Unity 工程支持三种平台的包:iOS、Android 和 WebGL
            all_packages = []

            # 检测 iOS 包(收集所有 iOS 包)
            if File.exist?(File.join(current_project_dir, "GoodPlatform/BaseiOS/build"))
                ios_build_path = File.join(current_project_dir, "GoodPlatform/BaseiOS/build", "*.{ipa,app}")
                all_packages.concat(Dir.glob(ios_build_path))
            end

            if File.exist?(File.join(current_project_dir, "GoodPlatform/iOS/build"))
                ios_build_path = File.join(current_project_dir, "GoodPlatform/iOS/build", "*.{ipa,app}")
                all_packages.concat(Dir.glob(ios_build_path))
            end

            # 检测 Android 包(收集所有 Android 包)
            if File.exist?(File.join(current_project_dir, "GoodPlatform/BaseAndroid/build"))
                android_build_path = File.join(current_project_dir, "GoodPlatform/BaseAndroid/build", "*.{apk,aab}")
                all_packages.concat(Dir.glob(android_build_path))
            end

            if File.exist?(File.join(current_project_dir, "GoodPlatform/Android/build"))
                android_build_path = File.join(current_project_dir, "GoodPlatform/Android/build", "*.{apk,aab}")
                all_packages.concat(Dir.glob(android_build_path))
            end

            # 检测 WebGL 包(HTML 文件)
            if File.exist?(File.join(current_project_dir, "GoodPlatform/WebGL/build"))
                webgl_build_path = File.join(current_project_dir, "GoodPlatform/WebGL/build", "index.html")
                webgl_files = Dir.glob(webgl_build_path)
                all_packages.concat(webgl_files)
            end

            # 从所有找到的包中选择最新的一个
            if all_packages.length > 0
                # 选择修改时间最新的文件
                @args_ipa_file = all_packages.max_by {|f| File.mtime(f)}
            else
                @args_ipa_file = nil
            end
        else
            raise Informative, "当前目录不是工程目录,不能编译"
        end


        if @args_ipa_file.nil?
            build_path = File.join(current_project_dir, "*.{ipa,app,apk,html}")
            @args_ipa_file = Dir.glob(build_path).max_by {|f| File.mtime(f)}
        end

        if !@args_ipa_file.nil?
            answer = agree("需要上传的文件是: #{@args_ipa_file} ?(Y/n)")
            if !answer
                @args_ipa_file = nil
            end
        end

        if !@args_ipa_file.nil? && File.exist?(@args_ipa_file)
        else
            @args_ipa_file = ask('需要上传的文件:') || nil
            @args_ipa_file = @args_ipa_file.strip.gsub(/\\ /, ' ')
        end
    end

    if !File.exist?(@args_ipa_file)
        raise Informative, "#{@args_ipa_file} 文件不存在"
    end

    # 根据文件后缀确定 package_type
    package_type = nil
    ext = File.extname(@args_ipa_file).downcase
    case ext
    when '.ipa'
        package_type = 'ipa'
    when '.apk'
        package_type = 'apk'
    when '.html'
        package_type = 'zip'
    when '.app'
        package_type = 'mac'
    else
        raise Informative, "不支持的文件类型: #{ext},支持的类型:.ipa, .apk, .html, .app"
    end

    PgyerHelper.share_instace.setForeLogin(beforeLogin:)
    app_info_obj, workflow_info = PgyerHelper.share_instace.prepare_upload(
        working_directory: Dir.pwd,
        proj_name: @args_proj_name,
        package_type: package_type
    )

    if app_info_obj.nil?
        raise Informative, "#{@args_proj_name} 错误, 请输入正确的App代号名称, jps网站没有该App"
    end

    result_data = PgyerHelper.share_instace.start_upload(
        app_info_obj: app_info_obj,
        ipa_file_upload: @args_ipa_file,
        description: @args_upload_desc,
        workflow_info: workflow_info
    )
    if !result_data.nil? && !result_data["data"].nil? && !result_data["data"]["id"].nil?
        PgyerHelper.share_instace.print_app_version_info(
            app_info_obj: app_info_obj,
            app_version_info_obj: result_data["data"]
        )

        if @args_resign_flag
            args = []
            if @args_send_flag
                args << "--send"
            end
            if !@args_cert_id.nil? && !@args_cert_id.empty?
                args << "--certid=#{@args_cert_id}"
            end
            if !@args_proj_name.nil? && !@args_proj_name.empty?
                args << "--proj=#{@args_proj_name}"
            end
            Pindo::Command::Jps::Resign::run(args)
        else
            # 始终发送给自己
            PgyerHelper.share_instace.send_apptest_msg(
                app_info_obj: app_info_obj,
                app_version_info_obj: result_data["data"],
                receiveType: "self"
            )

            # 如果有 --send 参数,额外发送到测试群
            if @args_send_flag
                PgyerHelper.share_instace.send_apptest_msg(
                    app_info_obj: app_info_obj,
                    app_version_info_obj: result_data["data"],
                    chatEnv: "DevTest",
                    receiveType: "chat"
                )
            end
        end
    end

end

#validate!Object



101
102
103
104
# File 'lib/pindo/command/jps/upload.rb', line 101

def validate!

    super
end