Module: Ruflet::CLI::FlutterSdk

Included in:
BuildCommand, ExtraCommand
Defined in:
lib/ruflet/cli/flutter_sdk.rb

Constant Summary collapse

RELEASES_BASE =
"https://storage.googleapis.com/flutter_infra_release/releases".freeze
DEFAULT_FLUTTER_CHANNEL =
"stable".freeze

Instance Method Summary collapse

Instance Method Details

#ensure_flutter!(command_name, client_dir: nil, auto_install: true) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/ruflet/cli/flutter_sdk.rb', line 18

def ensure_flutter!(command_name, client_dir: nil, auto_install: true)
  tools = flutter_tools(client_dir: client_dir, auto_install: auto_install)
  return tools if tools

  warn "Flutter is required for `ruflet #{command_name}` and FVM bootstrap failed."
  warn "Set RUFLET_FLUTTER_VERSION or add .fvmrc to the project."
  exit 1
end

#flutter_version_summary(tools) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruflet/cli/flutter_sdk.rb', line 27

def flutter_version_summary(tools)
  flutter_bin = tools[:flutter]
  env = tools[:env] || {}

  machine_output, status = Open3.capture2e(env, flutter_bin, "--version", "--machine")
  if status.success?
    parsed = JSON.parse(machine_output) rescue nil
    version = parsed && parsed["frameworkVersion"].to_s.strip
    channel = parsed && parsed["channel"].to_s.strip
    return [version, channel].reject(&:empty?).join(" ") unless version.to_s.empty?
  end

  text_output, text_status = Open3.capture2e(env, flutter_bin, "--version")
  return text_output.lines.first.to_s.strip if text_status.success?

  File.basename(flutter_bin.to_s)
rescue StandardError
  File.basename(flutter_bin.to_s)
end