Class: Flutter::Produce

Inherits:
Object
  • Object
show all
Defined in:
lib/produce.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/produce.rb', line 101

def build
  # 创建framework存放目录
  framework_path = Flutter::Config.instance.framework_path
  FileUtils.mkdir_p(framework_path) unless Dir.exist?(framework_path)
  config = Config.instance.config
  flutter_cmd = File.expand_path(File.join(flutter_root, "bin", "flutter"))
  if config
    if config.casecmp("debug").zero?
      system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --debug --no-profile --no-release --output=#{Flutter::Config.instance.framework_path}")
    elsif config.casecmp("profile").zero?
      system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --profile --no-debug --no-release --output=#{Flutter::Config.instance.framework_path}")
    elsif config.casecmp("release").zero?
      system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --release --no-debug --no-profile --output=#{Flutter::Config.instance.framework_path}")
    else
      raise "请指定正确的构建类型(debug/profile/release)".red
    end
  else
    # 构建所有环境的包(debug、profile、release)
    system("#{flutter_cmd} build ios-framework --xcframework --no-universal --no-tree-shake-icons --output=#{Flutter::Config.instance.framework_path}")
  end
end

#logObject



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
# File 'lib/produce.rb', line 123

def log
  # 产物类型
  product_type = if !Flutter::Config.instance.config
                   "所有类型(debug/profile/release)"
                 else
                   Flutter::Config.instance.config
                 end
  # 产物路径
  product_path = if !Flutter::Config.instance.config
                   File.expand_path(Flutter::Config.instance.framework_path, Dir.pwd)
                 else
                   File.expand_path(File.join(Flutter::Config.instance.framework_path, "#{product_type}"), Dir.pwd)
                 end

  # 产物数量
  product_num = if !Flutter::Config.instance.config
                  Dir.glob("#{File.join(product_path, "Debug")}/*").size
                else
                  Dir.glob("#{product_path}/*").size
                end
  Flutter::Print.print_product_info(product_type, product_num, product_path)

  # 产物
  products = Dir.glob(File.join(product_path, "*.xcframework")).map do |file|
    File.basename(file)
  end
  Flutter::Config.instance.new_products = products
  puts "\n"
  pro_str = ""
  products.each do |ele|
    pro_str = pro_str + ele + "\n"
  end
  pro_str = pro_str.rstrip
  return if pro_str.empty?

  Flutter::Print.print_all_products(pro_str)
end

#setupObject



91
92
93
94
95
96
97
98
99
# File 'lib/produce.rb', line 91

def setup
  project_dir = Config.instance.project_dir
  # 切换到指定项目目录
  Dir.chdir(project_dir) if project_dir
  clean
  # insert_source
  insert_swift_version
  insert_router
end