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.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pindo/command/jps/media.rb', line 57

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]

    # Task 参数
    @args_select_flag = @options[:select] || false

    super(argv)
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



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

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

.optionsObject



53
54
55
# File 'lib/pindo/command/jps/media.rb', line 53

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

Instance Method Details

#runObject



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
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
# File 'lib/pindo/command/jps/media.rb', line 80

def run
    project_path = Dir.pwd

    # 如果启用 --select 参数,获取用户选择的 commit
    selected_commit_info = nil
    if @args_select_flag
        selected_commit_info = select_git_commit(project_path)

        if selected_commit_info.nil?
            puts "未选择任何提交,已取消操作"
            return
        end

        puts "\n已选择提交:"
        puts "  Commit ID: #{selected_commit_info[:commit_id][0..7]}"
        puts "  时间: #{selected_commit_info[:commit_time]}"
        puts "  描述: #{selected_commit_info[:commit_desc]}"
        puts ""
    end

    # 获取 JPS 配置(app_info_obj 和 workflow_info)
    # 使用 manage_type: "git" 来获取 git 管理类型的工作流
    app_info_obj, workflow_info = PgyerHelper.share_instace.prepare_upload(
        working_directory: project_path,
        proj_name: @args_proj_name,
        package_type: "",  # package_type 在 manage_type=git 时会被忽略
        manage_type: "git"
    )

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

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

    # 创建任务链
    tasks = []

    # 1. 提前询问用户如何处理未提交的文件
    process_type = Pindo::GitHandler.get_uncommitted_files_process_type(
        project_dir: project_path,
        interactive: true
    )

    # 2. 创建 Git 提交任务
    git_commit_task = Pindo::TaskSystem::GitCommitTask.new(
        project_path,
        {
            process_type: process_type,
            commit_message: "feat: jps media 上传前提交"
        }
    )
    tasks << git_commit_task

    # 3. 创建 JPS Media 上传任务
    # 所有逻辑都在 Task 中处理:
    # - 自动查找 git 仓库和 HEAD 信息
    # - 展开文件路径(通配符、目录)
    # - 自动查找 JPSMedia/ 目录
    # - 匹配 git_commit_id 到 JPS commit_log
    media_upload_task = Pindo::TaskSystem::JPSUploadMediaTask.new(
        @file_paths,
        project_path,  # upload_path
        app_info_obj: app_info_obj,
        workflow_info: workflow_info,
        project_name: @args_proj_name,
        git_commit_id: selected_commit_info&.dig(:commit_id),
        git_commit_time: selected_commit_info&.dig(:commit_time),
        git_commit_desc: selected_commit_info&.dig(:commit_desc)
    )
    # Media 上传任务依赖 Git 提交任务
    media_upload_task.dependencies << git_commit_task.id
    tasks << media_upload_task

    # 执行任务链
    task_manager = Pindo::TaskSystem::TaskManager.instance
    task_manager.clear_all
    tasks.each { |task| 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



76
77
78
# File 'lib/pindo/command/jps/media.rb', line 76

def validate!
    super
end