Method: Flutter::Upload#gen_new_version
- Defined in:
- lib/upload.rb
#gen_new_version(origin_version) ⇒ Object
生成新的version
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/upload.rb', line 162 def gen_new_version(origin_version) # 按`·`分割一下 version_split = origin_version.split(".") # 取出第一位日期部分 first_part = version_split.first # 取出最后一位构建次数 last_part = version_split.last # 获取当前日期 current_date = Time.now.strftime("%Y%m%d") # 构建次数 build_time = if first_part.eql?(current_date) # 相等说明当前日期构建多次 last_part.to_i + 1 else # 不相等说明隔天首次构建 0 end # 获取pubspec.yaml 中的版本号 project_dir = Config.instance.project_dir yaml_path = if !project_dir File.join(Dir.pwd, "pubspec.yaml") else File.join(project_dir, "pubspec.yaml") end file_content = File.read(yaml_path) # 提取版本号 version = file_content.match(/version: (.+)/)&.captures&.first # 最终新的version new_version = "#{current_date}.#{version}.#{build_time}" # 输出版本信息 Flutter::Print.print_version_info(new_version, origin_version) new_version end |