Class: Pindo::Command::Unity::Packpush

Inherits:
Pindo::Command::Unity show all
Extended by:
Executable
Includes:
Githelper
Defined in:
lib/pindo/command/unity/packpush.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 included from Executable

capture_command, executable, execute_command, which, which!

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, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods inherited from Pindo::Command

run, use_cache?, #validate!

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Constructor Details

#initialize(argv) ⇒ Packpush

Returns a new instance of Packpush.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pindo/command/unity/packpush.rb', line 52

def initialize(argv)
  @args_nupkg_file = argv.shift_argument
  @nupkg_file = argv.option('nupkg')

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

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

Class Method Details

.argumentsObject



40
41
42
43
44
# File 'lib/pindo/command/unity/packpush.rb', line 40

def self.arguments
  [
    CLAide::Argument.new('path/to/package.nupkg', false),
  ]
end

.optionsObject



46
47
48
49
50
# File 'lib/pindo/command/unity/packpush.rb', line 46

def self.options
  [
    ['--nupkg', '指定要上传的 .nupkg 文件路径'],
  ].concat(super)
end

Instance Method Details

#runObject



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
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
# File 'lib/pindo/command/unity/packpush.rb', line 67

def run
  package_dir = Dir.pwd

  puts
  puts "🚀 上传 Unity Package 到 JPS"
  puts "━" * 40

  # 如果没有指定文件或文件不存在,则查找
  if @args_nupkg_file.nil? || !File.exist?(@args_nupkg_file)
    # 在当前目录查找 .nupkg 文件
    @args_nupkg_file = Pindo::Unity::NugetHelper.find_nupkg_file(package_dir)

    # 如果没有找到文件,让用户手动输入
    if @args_nupkg_file.nil? || !File.exist?(@args_nupkg_file)
      @args_nupkg_file = ask('需要上传的文件:') || nil
      if @args_nupkg_file
        @args_nupkg_file = @args_nupkg_file.strip.gsub(/\\ /, ' ')
      end
    end
  end

  # 验证文件存在
  if @args_nupkg_file.nil? || !File.exist?(@args_nupkg_file)
    raise Informative, "未找到 .nupkg 文件"
  end

  # 从 nuspec 文件或 package.json 获取包信息
  package_info = get_package_info_for_upload(package_dir) rescue nil

  # 显示包信息并一次性确认
  puts
  if package_info && !package_info.empty?
    puts "📦 包信息:"
    puts
    puts "  名称: #{package_info['displayName']}"
    puts "  ID:   #{package_info['name']}"
    puts "  版本: #{package_info['version']}"
    puts "  文件: #{@args_nupkg_file}"
    puts "  大小: #{sprintf('%.2f', File.size(@args_nupkg_file) / 1024.0 / 1024.0)} MB"
  else
    puts "📦 上传文件:"
    puts
    puts "  文件: #{@args_nupkg_file}"
    puts "  大小: #{sprintf('%.2f', File.size(@args_nupkg_file) / 1024.0 / 1024.0)} MB"
  end
  puts

  # 检查是否设置了强制上传环境变量
  force_upload = ENV['NUGET_UPLOAD_FORCE']

  if force_upload && !force_upload.empty?
    puts "🚀 检测到 NUGET_UPLOAD_FORCE 环境变量,跳过确认直接上传..."
  else
    # 一次性确认
    answer = agree("确认上传?(Y/n)")
    unless answer
      puts "已取消上传"
      return
    end
  end

  # 上传到 JPS
  upload_to_jps_nuget(@args_nupkg_file, package_info)

  puts
  puts "✅ 上传完成!"
  puts

  # 上传成功后自动打 tag(仅在有包信息时)
  if package_info && !package_info.empty?
    create_git_tag_from_nuspec(package_dir)
  end
end