Class: Pindo::Command::Unity::Packbuild
- Inherits:
-
Pindo::Command::Unity
- Object
- CLAide::Command
- Pindo::Command
- Pindo::Command::Unity
- Pindo::Command::Unity::Packbuild
- Defined in:
- lib/pindo/command/unity/packbuild.rb
Constant Summary
Constants inherited from Pindo::Command
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
Attributes inherited from Pindo::Command
Class Method Summary collapse
- .arguments ⇒ Object
-
.option_items ⇒ Object
定义此命令使用的参数项.
- .options ⇒ Object
Instance Method Summary collapse
-
#initialize(argv) ⇒ Packbuild
constructor
A new instance of Packbuild.
- #run ⇒ Object
Methods inherited from Pindo::Command
command_name, #initialize_options, run, use_cache?, #validate!
Methods included from Funlog::Mixin
Methods included from Pindoconfig::Mixin
Constructor Details
#initialize(argv) ⇒ Packbuild
Returns a new instance of Packbuild.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pindo/command/unity/packbuild.rb', line 55 def initialize(argv) @options = (argv) # 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 end |
Class Method Details
.arguments ⇒ Object
42 43 44 |
# File 'lib/pindo/command/unity/packbuild.rb', line 42 def self.arguments [] end |
.option_items ⇒ Object
定义此命令使用的参数项
47 48 49 |
# File 'lib/pindo/command/unity/packbuild.rb', line 47 def self.option_items @option_items ||= Pindo::Options::GitOptions.all end |
.options ⇒ Object
51 52 53 |
# File 'lib/pindo/command/unity/packbuild.rb', line 51 def self. option_items.map(&:to_claide_option).concat(super) end |
Instance Method Details
#run ⇒ Object
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 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 |
# File 'lib/pindo/command/unity/packbuild.rb', line 67 def run package_dir = Dir.pwd Funlog.instance.("Unity Package 打包流程") # 创建任务管理器 task_manager = Pindo::TaskSystem::TaskManager.instance task_manager.clear_all tasks = [] # 0. 预检查:获取并确认版本号 # 先执行初始化检查以确保文件存在 Pindo::Unity::NugetHelper.nuget_init(package_dir) nuspec_file = Pindo::Unity::NugetHelper.find_nuspec_file(package_dir) unless nuspec_file raise Informative, "初始化后仍未找到 .nuspec 文件,无法继续" end nuspec_info = Pindo::Unity::NugetHelper.parse_nuspec(nuspec_file) current_version = nuspec_info['version'] puts "" puts "即将编译 NuGet Package 的版本是 #{current_version.yellow}" if agree("确认是否继续? (Y/n)") confirmed_version = current_version else puts "" confirmed_version = ask("请输入新的打包版本号: ") { |q| q.required = true }.to_s.strip end if confirmed_version.empty? raise Informative, "版本号不能为空" end # 更新 .nuspec 和 package.json 中的版本号(如果用户修改了) if confirmed_version != current_version Funlog.instance.("更新配置文件版本号: #{confirmed_version}") # 这里我们需要手动更新一下,因为 GitCommitTask 只是提交,不负责改文件内容 # update_package_json_from_nuspec 会用到 nuspec_info,我们先更新 nuspec_info nuspec_info['version'] = confirmed_version # 更新 .nuspec 文件 # 注意:这里需要重新生成或更新 xml,为了简单调用 NugetHelper 的更新逻辑 # 但 NugetHelper 目前没有单独更新 version 的公开方法,我们可以读取->修改->写入 doc = Nokogiri::XML(File.read(nuspec_file)) doc.remove_namespaces! = doc.at_xpath('//metadata') version_node = .at_xpath('version') if version_node version_node.content = confirmed_version File.write(nuspec_file, doc.to_xml) end # 同步到 package.json Pindo::Unity::NugetHelper.update_package_json_from_nuspec(nuspec_info, package_dir) Funlog.instance.("版本号已更新") end # 1. Git 提交任务 (确保工作区干净,或提交预构建更改) # 交互式询问用户如何处理未提交文件 process_type = Pindo::GitHandler.get_uncommitted_files_process_type( project_dir: package_dir, interactive: true ) git_commit_task = Pindo::TaskSystem::GitCommitTask.new( package_dir, release_branch: @args_release_branch, ver_inc: @args_ver_inc, # 虽然有 fixed_version,但保留此参数无妨 tag_type: @args_tag_type, tag_pre: @args_tag_pre, process_type: process_type, commit_message: "chore: nuget packbuild v#{confirmed_version}", fixed_version: confirmed_version # 传入确认后的版本号 ) tasks << git_commit_task # 2. Nuget 构建任务 nuget_build_task = Pindo::TaskSystem::NugetBuildTask.new( project_path: package_dir ) nuget_build_task.dependencies << git_commit_task.id tasks << nuget_build_task # 3. Git Tag 任务 (依赖构建成功) git_tag_task = Pindo::TaskSystem::GitTagTask.new( package_dir, release_branch: @args_release_branch, ver_inc: @args_ver_inc, tag_type: @args_tag_type, tag_pre: @args_tag_pre, fixed_version: confirmed_version # 传入确认后的版本号 ) git_tag_task.dependencies << nuget_build_task.id tasks << git_tag_task # 添加并执行任务 tasks.each { |task| task_manager.add_task(task) } task_manager.start # 打印构建结果 if nuget_build_task.status == :success && nuget_build_task.result nupkg_file = nuget_build_task.result[:nupkg_file] puts "" Funlog.instance.("打包完成") puts " 📦 生成文件: #{File.basename(nupkg_file)}" puts " 📁 完整路径: #{nupkg_file}" puts "" Funlog.instance.("下一步: 运行 pindo unity packpush 上传到 JPS") end end |