Class: Pindo::Command::Jps::Media

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

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, 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

command_name, #initialize_options, run, use_cache?

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Constructor Details

#initialize(argv) ⇒ Media

Returns a new instance of Media.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pindo/command/jps/media.rb', line 50

def initialize(argv)
    # 收集所有文件参数
    @file_paths = []
    while (arg = argv.shift_argument)
        @file_paths << arg.strip.gsub(/\"/, '')
    end

    # 使用 Options 系统解析参数
    @options = initialize_options(argv)

    # JPS 参数
    @args_proj_name = @options[:proj]

    # Git 参数
    @args_release_branch = @options[:release_branch] || 'master'
    @args_ver_inc = Pindo::Options::GitOptions.parse_version_increase_type(@options[:ver_inc] || 'mini')
    @args_tag_type = Pindo::Options::GitOptions.parse_create_tag_type(@options[:tag_type] || 'new')
    @args_tag_pre = @options[:tag_pre] || 'v'

    super(argv)
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



39
40
41
42
43
44
# File 'lib/pindo/command/jps/media.rb', line 39

def self.option_items
  @option_items ||= Pindo::Options::OptionGroup.merge(
    Pindo::Options::JPSOptions.only(:proj),
    Pindo::Options::GitOptions.all
  )
end

.optionsObject



46
47
48
# File 'lib/pindo/command/jps/media.rb', line 46

def self.options
  option_items.map(&:to_claide_option).concat(super)
end

Instance Method Details

#runObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/pindo/command/jps/media.rb', line 76

def run
    project_path = Dir.pwd

    # 获取 JPS 配置(app_info_obj 和 workflow_info)
    app_info_obj, workflow_info = PgyerHelper.share_instace.prepare_upload(
        working_directory: project_path,
        proj_name: @args_proj_name,
        package_type: 'ipa'  # 任意类型,只是为了获取 workflow_id
    )

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

    # 获取 workflow_id
    workflow_id = workflow_info&.dig('id')

    # 创建并执行任务
    # 所有逻辑都在 Task 中处理:
    # - 自动查找 git 仓库和 HEAD 信息
    # - 展开文件路径(通配符、目录)
    # - 自动查找 JPSMedia/ 目录
    # - 匹配 git_commit_id 到 JPS commit_log
    task = Pindo::TaskSystem::JPSUploadMediaTask.new(
        @file_paths,
        workflow_id: workflow_id,
        project_path: project_path
    )

    task_manager = Pindo::TaskSystem::TaskManager.instance
    task_manager.clear_all
    task_manager.add_task(task)
    task_manager.start

    # 输出结果
    report = task_manager.execution_report
    if report[:success] > 0
        puts "\n上传完成!"
    else
        raise Informative, "上传失败"
    end
end

#validate!Object



72
73
74
# File 'lib/pindo/command/jps/media.rb', line 72

def validate!
    super
end