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

Inherits:
Pindo::Command::Unity show all
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 inherited from Pindo::Command

command_name, #initialize_options, 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.



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

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



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

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

.optionsObject



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

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

Instance Method Details

#runObject



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

def run
  package_dir = Dir.pwd

  puts ""
  puts "🚀 上传 Unity Package 到 JPS"
  puts ""

  # 如果没有指定文件或文件不存在,则查找
  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

  # 显示包信息并确认
  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

  puts ""

  # 创建上传任务
  upload_task = Pindo::TaskSystem::NugetUploadTask.new(
    project_path: package_dir,
    nupkg_file: @args_nupkg_file
  )

  # 执行任务
  task_manager = Pindo::TaskSystem::TaskManager.instance
  task_manager.clear_all
  task_manager.add_task(upload_task)
  task_manager.start

  puts ""
  Funlog.instance.fancyinfo_success("上传完成!")
  puts ""
end