flutter-deploy 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +39 -0
- data/bin/flutter-cli +25 -0
- data/lib/build.rb +67 -0
- data/lib/command.rb +12 -0
- data/lib/config.rb +24 -0
- data/lib/print.rb +17 -0
- data/lib/produce.rb +161 -0
- data/lib/repo.rb +20 -0
- data/lib/upload.rb +239 -0
- data/lib/version.rb +7 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 14c53b7da537f3cb0e9e18bd1ac73889cf58737e2e0041713ec8d04a41021e69
|
4
|
+
data.tar.gz: d2c6f165c22932bcd2beed55f447c0015f2a9a323751ddcf09ddfb3377b2f6a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb1fadd13a1befb258ad18dc070e2f99f10ae531e6f0397e21eb7a8cac43291e96e5c3fb51a82b4a2f991afcafc6f66d630fe1ebf94c92c5939895945e2b3516
|
7
|
+
data.tar.gz: 917e7a625c24a4b69f79e2ddaa9523dc25a7f372d3d580056c06cb3c60376f0ef546e5d544681383d97c8383496f3072018de43e63bab40f7031e5dc7b3efbc6
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Flutter::Deploy
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flutter/deploy`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add flutter-cli
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install flutter-cli
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/flutter-deploy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/flutter-deploy/blob/main/CODE_OF_CONDUCT.md).
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
34
|
+
|
35
|
+
## Code of Conduct
|
36
|
+
|
37
|
+
Everyone interacting in the Flutter::Deploy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/flutter-deploy/blob/main/CODE_OF_CONDUCT.md).
|
38
|
+
=======
|
39
|
+
# flutter-cli
|
data/bin/flutter-cli
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "build"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
# require "irb"
|
15
|
+
# IRB.start(__FILE__)
|
16
|
+
# puts __FILE__
|
17
|
+
# puts $PROGRAM_NAME
|
18
|
+
# puts __dir__
|
19
|
+
# puts File.expand_path("../Gemfile", __dir__)
|
20
|
+
if $PROGRAM_NAME == __FILE__
|
21
|
+
ENV["BUNDLE_GEMFILE"] = File.expand_path("../Gemfile", __dir__)
|
22
|
+
require "bundler/setup"
|
23
|
+
end
|
24
|
+
|
25
|
+
Flutter::Command.run(ARGV)
|
data/lib/build.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require "command"
|
2
|
+
require "produce"
|
3
|
+
require "repo"
|
4
|
+
require "upload"
|
5
|
+
require "colored2"
|
6
|
+
|
7
|
+
module Flutter
|
8
|
+
class Command
|
9
|
+
class Build < Command
|
10
|
+
self.summary = "Build the Flutter module into a framework and upload it to your private repository"
|
11
|
+
self.description = <<-DESC
|
12
|
+
Build the Flutter module into a framework and upload it to your private repository. If an `BUILD_CONFIG` is specified, the command can produce a given configuration framework.
|
13
|
+
You can set up the configuration for `debug`、`profile`、`release`, If none given, By default, all build configurations are built.
|
14
|
+
DESC
|
15
|
+
self.arguments = [
|
16
|
+
CLAide::Argument.new("BUILD_CONFIG", false, false)
|
17
|
+
]
|
18
|
+
def self.options
|
19
|
+
[
|
20
|
+
["--build-only", "build only Don\u2019t deploy"],
|
21
|
+
["--ignore-gp", "Don\u2019t pull new code from remote, use your local code"],
|
22
|
+
["--messae=msg", "git commit log"],
|
23
|
+
["--branch=branch", "which branch to build"],
|
24
|
+
["--project-dir=/project/dir", "The path to the root of the project directory"]
|
25
|
+
].concat(super)
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(argv)
|
29
|
+
super
|
30
|
+
@build_only = argv.flag?("build-only")
|
31
|
+
Flutter::Config.instance.ignore_gp = argv.flag?("ignore-gp")
|
32
|
+
Flutter::Config.instance.debug = argv.flag?("debug")
|
33
|
+
# flutter module 根目录
|
34
|
+
Flutter::Config.instance.project_dir = argv.option("project-dir")
|
35
|
+
Flutter::Config.instance.config = argv.shift_argument
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate!
|
39
|
+
super
|
40
|
+
build_type = Config.instance.config
|
41
|
+
return unless !build_type.nil? && !Flutter::Config.instance.product_types.include?(build_type)
|
42
|
+
|
43
|
+
help! "构建类型指定错误,请输入要构建包的类型:(debug/profile/release)".red
|
44
|
+
end
|
45
|
+
|
46
|
+
def run
|
47
|
+
# 尝试更新私有库
|
48
|
+
Repo.repo_update
|
49
|
+
produce = Flutter::Produce.new
|
50
|
+
# 构建前的初始化工作
|
51
|
+
produce.setup
|
52
|
+
# 开始构建
|
53
|
+
result = produce.build
|
54
|
+
# 上传到私服
|
55
|
+
raise "构建失败,请检查环境配置......".red unless result
|
56
|
+
|
57
|
+
# 输出产物信息
|
58
|
+
produce.log
|
59
|
+
return if @build_only
|
60
|
+
|
61
|
+
# 上传
|
62
|
+
deploy = Flutter::Upload.new
|
63
|
+
deploy.upload
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/command.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "claide"
|
2
|
+
require "version"
|
3
|
+
|
4
|
+
module Flutter
|
5
|
+
class Command < CLAide::Command
|
6
|
+
self.abstract_command = true
|
7
|
+
self.command = "flutter-cli"
|
8
|
+
self.version = Flutter::Deploy::VERSION
|
9
|
+
self.summary = 'Build the Flutter module into a framework and upload it to your private repository'
|
10
|
+
self.description = "flutter-deploy, build and deploy to private git repo"
|
11
|
+
end
|
12
|
+
end
|
data/lib/config.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Flutter
|
2
|
+
class Config
|
3
|
+
# 声明私有方法
|
4
|
+
private_class_method :new
|
5
|
+
|
6
|
+
attr_reader :router_name, :swift_version, :source, :xcconfig_path, :podfile_path, :framework_path, :product_types
|
7
|
+
|
8
|
+
attr_accessor :project_dir, :config, :debug, :new_products, :ignore_gp
|
9
|
+
|
10
|
+
def self.instance
|
11
|
+
@instance ||= new
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@source = "source 'git@code.sohuno.com:mtpc_sh_ios/ios_sohu_spec.git'"
|
16
|
+
@router_name = " pod 'SHNRouter', :subspecs => ['Core','Flutter'], :source => 'git@code.sohuno.com:mtpc_sh_ios/ios_sohu_spec.git'"
|
17
|
+
@swift_version = "SWIFT_VERSION=4.0"
|
18
|
+
@xcconfig_path = ".ios/Flutter/Generated.xcconfig"
|
19
|
+
@podfile_path = ".ios/Podfile"
|
20
|
+
@framework_path = "./build/flutter"
|
21
|
+
@product_types = %w[debug profile release]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/print.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "tty-box"
|
2
|
+
|
3
|
+
module Flutter
|
4
|
+
class Print
|
5
|
+
def self.print_product_info(product_type, number, path)
|
6
|
+
print TTY::Box.info "产物类型:#{product_type}\n产物数量:#{number}\n产物路径:#{path}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.print_all_products(products)
|
10
|
+
print TTY::Box.info "产物:\n#{products}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.print_version_info(new_version, old_version)
|
14
|
+
print TTY::Box.info "新版本号为:#{new_version}\n旧版本号为:#{old_version}\n''"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/produce.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require "config"
|
2
|
+
require "fileutils"
|
3
|
+
require "colored2"
|
4
|
+
require "print"
|
5
|
+
module Flutter
|
6
|
+
class Produce
|
7
|
+
def insert_swift_version
|
8
|
+
file_path = Config.instance.xcconfig_path
|
9
|
+
File.open(file_path, "a") do |file|
|
10
|
+
file.puts(Config.instance.swift_version)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def insert_source
|
15
|
+
source = Flutter::Config.instance.source
|
16
|
+
podfile_path = Flutter::Config.instance.podfile_path
|
17
|
+
podfiles = File.readlines(podfile_path)
|
18
|
+
# 插入source源
|
19
|
+
podfiles.insert(0, source)
|
20
|
+
# 把修改的内容写回原文件
|
21
|
+
File.open(podfile_path, "w") { |file| file.puts(podfiles) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def podfile_content
|
25
|
+
File.readlines(Config.instance.podfile_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
# 目标字符串的行号
|
29
|
+
def target_line
|
30
|
+
# 读取原始文件内容,存放到数组中
|
31
|
+
file_lines = podfile_content
|
32
|
+
# 目标字符串
|
33
|
+
target_str = "flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))"
|
34
|
+
# 目标字符串行号
|
35
|
+
file_lines.index do |line|
|
36
|
+
line.include?(target_str)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def insert_router
|
41
|
+
# 获取目标字符串的行号
|
42
|
+
target_file_num = target_line
|
43
|
+
|
44
|
+
file_lines = podfile_content
|
45
|
+
return unless target_file_num
|
46
|
+
|
47
|
+
# 向目标字符串的下一行插入新字符串
|
48
|
+
file_lines.insert(target_file_num + 1, Config.instance.router_name)
|
49
|
+
# 将修改后的内容写回文件
|
50
|
+
File.open(Config.instance.podfile_path, "w") do |file|
|
51
|
+
file.puts(file_lines)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def clean
|
56
|
+
unless Flutter::Config.instance.ignore_gp
|
57
|
+
# 清空当前的工作目录
|
58
|
+
`git checkout .`
|
59
|
+
# 更新内容
|
60
|
+
`git pull`
|
61
|
+
end
|
62
|
+
|
63
|
+
# 清空flutter,并且更新依赖
|
64
|
+
if Flutter::Config.instance.debug
|
65
|
+
flutter_cmd = File.expand_path(File.join("~/.flutter_sdks/3.7.12", "bin", "flutter"))
|
66
|
+
system("#{flutter_cmd} clean && #{flutter_cmd} pub get")
|
67
|
+
system("#{flutter_cmd} pub upgrade")
|
68
|
+
else
|
69
|
+
system("flutter clean && flutter pub get")
|
70
|
+
system("flutter pub upgrade")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# 获取项目指定flutter SDK版本的SDK路径
|
75
|
+
# eg: ~/.flutter_sdks/#{version}
|
76
|
+
def flutter_root
|
77
|
+
generated_xcode_build_settings_path = File.expand_path(File.join(".ios", "Flutter", "Generated.xcconfig"), Dir.pwd)
|
78
|
+
unless File.exist?(generated_xcode_build_settings_path)
|
79
|
+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
|
80
|
+
end
|
81
|
+
|
82
|
+
File.foreach(generated_xcode_build_settings_path) do |line|
|
83
|
+
matches = line.match(/FLUTTER_ROOT=(.*)/)
|
84
|
+
return matches[1].strip if matches
|
85
|
+
end
|
86
|
+
# This should never happen...
|
87
|
+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
|
88
|
+
end
|
89
|
+
private :target_line, :insert_swift_version, :podfile_content, :insert_router, :clean, :insert_source, :flutter_root
|
90
|
+
|
91
|
+
def setup
|
92
|
+
project_dir = Config.instance.project_dir
|
93
|
+
# 切换到指定项目目录
|
94
|
+
Dir.chdir(project_dir) if project_dir
|
95
|
+
clean
|
96
|
+
# insert_source
|
97
|
+
insert_swift_version
|
98
|
+
insert_router
|
99
|
+
end
|
100
|
+
|
101
|
+
def build
|
102
|
+
# 创建framework存放目录
|
103
|
+
framework_path = Flutter::Config.instance.framework_path
|
104
|
+
FileUtils.mkdir_p(framework_path) unless Dir.exist?(framework_path)
|
105
|
+
config = Config.instance.config
|
106
|
+
flutter_cmd = File.expand_path(File.join(flutter_root, "bin", "flutter"))
|
107
|
+
if config
|
108
|
+
if config.casecmp("debug").zero?
|
109
|
+
system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --debug --no-profile --no-release --output=#{Flutter::Config.instance.framework_path}")
|
110
|
+
elsif config.casecmp("profile").zero?
|
111
|
+
system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --profile --no-debug --no-release --output=#{Flutter::Config.instance.framework_path}")
|
112
|
+
elsif config.casecmp("release").zero?
|
113
|
+
system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --release --no-debug --no-profile --output=#{Flutter::Config.instance.framework_path}")
|
114
|
+
else
|
115
|
+
raise "请指定正确的构建类型(debug/profile/release)".red
|
116
|
+
end
|
117
|
+
else
|
118
|
+
# 构建所有环境的包(debug、profile、release)
|
119
|
+
system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --output=#{Flutter::Config.instance.framework_path}")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def log
|
124
|
+
# 产物类型
|
125
|
+
product_type = if !Flutter::Config.instance.config
|
126
|
+
"所有类型(debug/profile/release)"
|
127
|
+
else
|
128
|
+
Flutter::Config.instance.config
|
129
|
+
end
|
130
|
+
# 产物路径
|
131
|
+
product_path = if !Flutter::Config.instance.config
|
132
|
+
File.expand_path(Flutter::Config.instance.framework_path, Dir.pwd)
|
133
|
+
else
|
134
|
+
File.expand_path(File.join(Flutter::Config.instance.framework_path, "#{product_type}"), Dir.pwd)
|
135
|
+
end
|
136
|
+
|
137
|
+
# 产物数量
|
138
|
+
product_num = if !Flutter::Config.instance.config
|
139
|
+
Dir.glob("#{File.join(product_path, "Debug")}/*").size
|
140
|
+
else
|
141
|
+
Dir.glob("#{product_path}/*").size
|
142
|
+
end
|
143
|
+
Flutter::Print.print_product_info(product_type, product_num, product_path)
|
144
|
+
|
145
|
+
# 产物
|
146
|
+
products = Dir.glob(File.join(product_path, "*.xcframework")).map do |file|
|
147
|
+
File.basename(file)
|
148
|
+
end
|
149
|
+
Flutter::Config.instance.new_products = products
|
150
|
+
puts "\n"
|
151
|
+
pro_str = ""
|
152
|
+
products.each do |ele|
|
153
|
+
pro_str = pro_str + ele + "\n"
|
154
|
+
end
|
155
|
+
pro_str = pro_str.rstrip
|
156
|
+
return if pro_str.empty?
|
157
|
+
|
158
|
+
Flutter::Print.print_all_products(pro_str)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/lib/repo.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Flutter
|
2
|
+
class Repo
|
3
|
+
def self.repo_update
|
4
|
+
spec_path1 = File.expand_path("~/.cocoapods/repos/ios_sohu_spec/")
|
5
|
+
spec_path2 = File.expand_path("~/.cocoapods/repos/SHSpecs/")
|
6
|
+
p = Pathname.new(spec_path1)
|
7
|
+
if Dir.exist?(p.realpath)
|
8
|
+
`pod repo update ~/.cocoapods/repos/ios_sohu_spec/`
|
9
|
+
else
|
10
|
+
`pod repo add ios_sohu_spec git@code.sohuno.com:mtpc_sh_ios/ios_sohu_spec.git`
|
11
|
+
end
|
12
|
+
|
13
|
+
if File.exist?(spec_path2)
|
14
|
+
`pod repo update ~/.cocoapods/repos/SHSpecs/`
|
15
|
+
else
|
16
|
+
`pod repo add SHSpecs git@code.sohuno.com:MPTC-iOS/SHSpecs.git`
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/upload.rb
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Flutter
|
4
|
+
class Upload
|
5
|
+
def initialize
|
6
|
+
# project_dir = Config.instance.project_dir
|
7
|
+
# # 切换到指定项目目录
|
8
|
+
# Dir.chdir(project_dir) if project_dir
|
9
|
+
# spec name
|
10
|
+
@spec_name = "ios_sohu_spec"
|
11
|
+
# pec库远程地址
|
12
|
+
@spec_url = "git@code.sohuno.com:mtpc_sh_ios/ios_sohu_spec.git"
|
13
|
+
# SoHuHost远程仓库地址
|
14
|
+
@framework_url = "git@code.sohuno.com:MOBILE-BASIC/SoHuHost.git"
|
15
|
+
@sohu_host_project_name = "SoHuHost"
|
16
|
+
# 手搜framework local地址(从远程clone到本地)
|
17
|
+
@framework_localPath = File.expand_path(File.join("..", "#{@sohu_host_project_name}"), Dir.pwd)
|
18
|
+
# 手搜spec文件名
|
19
|
+
@podspec_name = "#{@sohu_host_project_name}.podspec"
|
20
|
+
# spec文件路径
|
21
|
+
@spec_path = File.expand_path(File.join("#{@framework_localPath}", "#{@podspec_name}"), Dir.pwd)
|
22
|
+
|
23
|
+
# 产物的类型 debug/profile/release
|
24
|
+
@product_type = Flutter::Config.instance.config
|
25
|
+
|
26
|
+
@product_map = { 1 => "Debug", 2 => "Profile", 3 => "Release" }
|
27
|
+
# 用于记录旧的构建产物
|
28
|
+
@origin_products = []
|
29
|
+
end
|
30
|
+
|
31
|
+
# 上传
|
32
|
+
def upload
|
33
|
+
update_host
|
34
|
+
copy_products
|
35
|
+
modify_podspec_file
|
36
|
+
origin_version = get_origin_version
|
37
|
+
new_version = gen_new_version(origin_version)
|
38
|
+
update_version(new_version)
|
39
|
+
push_to_remote(new_version)
|
40
|
+
end
|
41
|
+
|
42
|
+
def log_products_diff
|
43
|
+
return unless !Flutter::Config.instance.new_products.empty? && !@origin_products.empty?
|
44
|
+
|
45
|
+
diff = Flutter::Config.instance.new_products.size > @origin_products.size ? Flutter::Config.instance.new_products.difference(@origin_products) : @origin_products.difference(Flutter::Config.instance.new_products)
|
46
|
+
return if diff.empty?
|
47
|
+
|
48
|
+
diff_str = ""
|
49
|
+
diff.each { |ele| diff_str = diff_str + ele + "\n" }
|
50
|
+
diff_str = diff_str.rstrip
|
51
|
+
if Flutter::Config.instance.new_products.size > @origin_products.size
|
52
|
+
print TTY::Box.info "产物新增了:\n#{diff_str}"
|
53
|
+
elsif Flutter::Config.instance.new_products.size < @origin_products.size
|
54
|
+
print TTY::Box.info "产物减少了:\n#{diff_str}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# 更新下本地SoHuHost
|
59
|
+
def update_host
|
60
|
+
if !Dir.exist?(@framework_localPath)
|
61
|
+
# 执行Git clone
|
62
|
+
system("git clone #{@framework_url} #{@framework_localPath}")
|
63
|
+
else
|
64
|
+
# 执行 git pull
|
65
|
+
system("git -C #{@framework_localPath} checkout .")
|
66
|
+
system("git -C #{@framework_localPath} pull")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def check_build_type
|
71
|
+
return unless !@product_type || @product_type.empty?
|
72
|
+
|
73
|
+
puts "您构建了多个类型的产物:"
|
74
|
+
puts "[1]: debug"
|
75
|
+
puts "[2]: profile"
|
76
|
+
puts "[3]: release"
|
77
|
+
print "请选择一个上传(退出,请选择'q/Q'):"
|
78
|
+
input = $stdin.gets.chomp
|
79
|
+
exit if input.casecmp("q").zero?
|
80
|
+
@product_type = @product_map[input.to_i]
|
81
|
+
return if @product_type
|
82
|
+
|
83
|
+
print TTY::Box.error("请选择正确的构建类型")
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
# 获得产物路径
|
88
|
+
def path_for_product
|
89
|
+
check_build_type
|
90
|
+
source_dir = File.expand_path(File.join(Flutter::Config.instance.framework_path, @product_type.capitalize), Dir.pwd)
|
91
|
+
end
|
92
|
+
|
93
|
+
# 将产物copy到@framework_localPath目录下
|
94
|
+
def copy_products
|
95
|
+
# 先记录下旧的产物,用于比较是否有更新
|
96
|
+
@origin_products = Dir.glob(File.join(@framework_localPath, "*.xcframework")).map do |file|
|
97
|
+
File.basename(file)
|
98
|
+
end
|
99
|
+
|
100
|
+
# 如果有则删之
|
101
|
+
system("find #{@framework_localPath} -name 'Debug' | xargs rm -rf")
|
102
|
+
system("find #{@framework_localPath} -name 'Profile' | xargs rm -rf")
|
103
|
+
system("find #{@framework_localPath} -name 'Release' | xargs rm -rf")
|
104
|
+
system("find #{@framework_localPath} -name 'iphoneos' | xargs rm -rf")
|
105
|
+
system("find #{@framework_localPath} -name 'iphonesimulator' | xargs rm -rf")
|
106
|
+
# 1、先移除旧的framework
|
107
|
+
xcframework_files = Dir.glob(File.join(@framework_localPath, "*.xcframework"))
|
108
|
+
xcframework_files.each do |xc_file|
|
109
|
+
# FileUtils.rm(xc_file)
|
110
|
+
system("rm -rf #{xc_file}")
|
111
|
+
end
|
112
|
+
# 2、将新产物move到@framework_localPath目录下
|
113
|
+
source_dir = path_for_product
|
114
|
+
|
115
|
+
# 获取源文件夹下的所有.xcframework文件
|
116
|
+
xc_files = Dir.glob(File.join(source_dir, "*"))
|
117
|
+
raise "当前产物路径:#{source_dir}为空,\n请先构建需要的产物" unless xc_files.any?
|
118
|
+
|
119
|
+
# 移动到目标文件夹下
|
120
|
+
xc_files.each do |file|
|
121
|
+
FileUtils.mv(file, @framework_localPath)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# 修改.podspec文件
|
126
|
+
def modify_podspec_file
|
127
|
+
# 1、移除.xcframework行和多余的空格
|
128
|
+
pattern = ".xcframework"
|
129
|
+
lines = File.readlines(@spec_path).reject { |line| line.match(pattern) }.filter { |element| element.strip.size > 0 }
|
130
|
+
new_vendored_framework = get_vendored_frameworks
|
131
|
+
# 插入新的vendored_frameworks
|
132
|
+
lines.insert(lines.size - 1, new_vendored_framework)
|
133
|
+
# 写入新的内容
|
134
|
+
File.open(@spec_path, "w") { |file| file.puts lines }
|
135
|
+
end
|
136
|
+
|
137
|
+
# 生成vendored_framewoks的字符串
|
138
|
+
def get_vendored_frameworks
|
139
|
+
xc_files = Dir.glob(File.join(@framework_localPath, "*.xcframework")).map do |file|
|
140
|
+
File.basename(file)
|
141
|
+
end
|
142
|
+
vendored_frameworks = " s.vendored_frameworks = "
|
143
|
+
xc_files.each do |line|
|
144
|
+
vendored_frameworks = vendored_frameworks + "'" + line + "'" + "," + "\n" + " "
|
145
|
+
end
|
146
|
+
# 去掉末尾所有空格和最后的`,`
|
147
|
+
vendored_frameworks.rstrip.chomp(",")
|
148
|
+
end
|
149
|
+
|
150
|
+
# 获取修改之前的versin
|
151
|
+
def get_origin_version
|
152
|
+
versin_line = File.readlines(@spec_path).filter { |line| line.gsub(/\s+/, "").match("s.version=") }
|
153
|
+
raise "\u6CA1\u6709\u627E\u5230version" unless versin_line.any?
|
154
|
+
|
155
|
+
version = versin_line.last.split("=").last
|
156
|
+
|
157
|
+
# (/^\'|\'$/)去掉首尾单引号的正则
|
158
|
+
version.strip.gsub(/^'|'$/, "")
|
159
|
+
end
|
160
|
+
|
161
|
+
# 生成新的version
|
162
|
+
def gen_new_version(origin_version)
|
163
|
+
# 按`·`分割一下
|
164
|
+
version_split = origin_version.split(".")
|
165
|
+
# 取出第一位日期部分
|
166
|
+
first_part = version_split.first
|
167
|
+
# 取出最后一位构建次数
|
168
|
+
last_part = version_split.last
|
169
|
+
# 获取当前日期
|
170
|
+
current_date = Time.now.strftime("%Y%m%d")
|
171
|
+
# 构建次数
|
172
|
+
build_time = if first_part.eql?(current_date)
|
173
|
+
# 相等说明当前日期构建多次
|
174
|
+
last_part.to_i + 1
|
175
|
+
else
|
176
|
+
# 不相等说明隔天首次构建
|
177
|
+
0
|
178
|
+
end
|
179
|
+
# 获取pubspec.yaml 中的版本号
|
180
|
+
project_dir = Config.instance.project_dir
|
181
|
+
yaml_path = if !project_dir
|
182
|
+
File.join(Dir.pwd, "pubspec.yaml")
|
183
|
+
else
|
184
|
+
File.join(project_dir, "pubspec.yaml")
|
185
|
+
end
|
186
|
+
file_content = File.read(yaml_path)
|
187
|
+
# 提取版本号
|
188
|
+
version = file_content.match(/version: (.+)/)&.captures&.first
|
189
|
+
# 最终新的version
|
190
|
+
new_version = "#{current_date}.#{version}.#{build_time}"
|
191
|
+
# 输出版本信息
|
192
|
+
Flutter::Print.print_version_info(new_version, origin_version)
|
193
|
+
new_version
|
194
|
+
end
|
195
|
+
|
196
|
+
# 更新版本
|
197
|
+
def update_version(version)
|
198
|
+
# 读取文件内容
|
199
|
+
file_content = File.read(@spec_path)
|
200
|
+
|
201
|
+
# 提取版本号
|
202
|
+
version_match = file_content.match(/s\.version\s+=\s+'(.+)'/)
|
203
|
+
current_version = version_match&.captures&.first
|
204
|
+
|
205
|
+
return unless current_version
|
206
|
+
|
207
|
+
# 替换版本号
|
208
|
+
new_file_content = file_content.gsub(/s\.version\s+=\s+'#{current_version}'/, "s.version = '#{version}'")
|
209
|
+
|
210
|
+
# 将替换后的内容写回文件
|
211
|
+
File.write(@spec_path, new_file_content)
|
212
|
+
end
|
213
|
+
|
214
|
+
# 推到远程
|
215
|
+
def push_to_remote(version)
|
216
|
+
log_products_diff
|
217
|
+
# 当前的分支
|
218
|
+
branch_name = `git branch --show-current`
|
219
|
+
# 生成提交日志(版本号+构件类型+分支名)
|
220
|
+
log = "版本号:#{version}---构件类型:#{@product_type.capitalize}---分支名:#{branch_name}"
|
221
|
+
# 提交
|
222
|
+
`git -C #{@framework_localPath} add -A`
|
223
|
+
`git -C #{@framework_localPath} commit -m #{log}`
|
224
|
+
`git -C #{@framework_localPath} push origin`
|
225
|
+
# 打tag
|
226
|
+
`git -C #{@framework_localPath} tag -a #{version} -m #{log}`
|
227
|
+
`git -C #{@framework_localPath} push origin #{version}`
|
228
|
+
|
229
|
+
# 切换到SoHuHost目录下执行`pod repo push`
|
230
|
+
Dir.chdir(@framework_localPath) if @framework_localPath
|
231
|
+
# podspec 推到远程
|
232
|
+
result = system("pod repo push #{@spec_name} #{@podspec_name} --sources='#{@spec_url}' --allow-warnings --skip-import-validation")
|
233
|
+
|
234
|
+
raise "上传失败。。。。。。" unless result
|
235
|
+
|
236
|
+
print TTY::Box.success("#{@podspec_name}推送成功,请在项目中使用:\nflutter_pod '#{@sohu_host_project_name}', '#{version}'")
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flutter-deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- wangfei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: claide
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.2
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.2
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: cocoapods
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.11.3
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.11.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: colored2
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: tty-box
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.7.0
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.7.0
|
75
|
+
description: flutter deploy
|
76
|
+
email:
|
77
|
+
- firorwang@sohu-inc.com
|
78
|
+
executables:
|
79
|
+
- flutter-cli
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- README.md
|
84
|
+
- bin/flutter-cli
|
85
|
+
- lib/build.rb
|
86
|
+
- lib/command.rb
|
87
|
+
- lib/config.rb
|
88
|
+
- lib/print.rb
|
89
|
+
- lib/produce.rb
|
90
|
+
- lib/repo.rb
|
91
|
+
- lib/upload.rb
|
92
|
+
- lib/version.rb
|
93
|
+
homepage: http://www.baidu.com
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 2.6.0
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubygems_version: 3.0.3.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: flutter deploy
|
116
|
+
test_files: []
|