Module: Ruflet::CLI::ExtraCommand

Includes:
AndroidSdk, EnvironmentSetup, FlutterSdk, NewCommand
Included in:
Ruflet::CLI
Defined in:
lib/ruflet/cli/extra_command.rb

Constant Summary

Constants included from NewCommand

NewCommand::CLIENT_EXTENSION_MAP, NewCommand::RUNTIME_REPO_URL, NewCommand::TEMPLATE_REPO_URL

Constants included from AndroidSdk

AndroidSdk::ANDROID_BUILD_TOOLS, AndroidSdk::ANDROID_PLATFORM, AndroidSdk::CMDLINE_TOOLS_BASE, AndroidSdk::CMDLINE_TOOLS_VERSION, AndroidSdk::JDK_PACKAGES, AndroidSdk::MINIMUM_JAVA_MAJOR

Constants included from EnvironmentSetup

Ruflet::CLI::EnvironmentSetup::LINUX_PACKAGE_MANAGERS

Constants included from FlutterSdk

FlutterSdk::DEFAULT_FLUTTER_CHANNEL, FlutterSdk::RELEASES_BASE

Instance Method Summary collapse

Methods included from NewCommand

#command_new

Methods included from AndroidSdk

#android_build_env, #android_environment_setup!, #detect_android_sdk_root, #managed_android_sdk_root

Methods included from EnvironmentSetup

#environment_setup!, #required_system_tools, #system_package_manager

Methods included from FlutterSdk

#ensure_flutter!, #flutter_version_summary

Instance Method Details

#command_create(args) ⇒ Object



13
14
15
# File 'lib/ruflet/cli/extra_command.rb', line 13

def command_create(args)
  command_new(args)
end

#command_debug(args) ⇒ Object



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
# File 'lib/ruflet/cli/extra_command.rb', line 109

def command_debug(args)
  options = {
    platform: nil,
    device_id: nil,
    release: false,
    verbose: false,
    web_renderer: nil
  }
  parser = OptionParser.new do |o|
    o.on("--platform NAME") { |v| options[:platform] = v }
    o.on("--device-id ID") { |v| options[:device_id] = v }
    o.on("--release") { options[:release] = true }
    o.on("-v", "--verbose") { options[:verbose] = true }
    o.on("--web-renderer NAME") { |v| options[:web_renderer] = v }
  end
  parser.parse!(args)

  options[:platform] ||= args.shift
  client_dir = detect_client_dir
  unless client_dir
    warn "Could not find Flutter client directory."
    warn "Set RUFLET_CLIENT_DIR or let Ruflet manage the client under ./build/client"
    warn "`ruflet debug` requires Flutter client source code."
    warn "For prebuilt clients, use: `ruflet run --web` or `ruflet run --desktop`."
    return 1
  end

  tools = ensure_flutter!("debug", client_dir: client_dir)
  cmd = [tools[:flutter], "run"]
  cmd << "--release" if options[:release]
  cmd << "-v" if options[:verbose]
  cmd += ["--web-renderer", options[:web_renderer]] if options[:web_renderer]

  if options[:device_id]
    cmd += ["-d", options[:device_id]]
  else
    case options[:platform]
    when "web"
      cmd += ["-d", "chrome"]
    when "macos", "windows", "linux"
      cmd += ["-d", options[:platform]]
    when "ios", "android"
      # let flutter pick the default device
    end
  end

  system(tools[:env], *cmd, chdir: client_dir)
  $?.exitstatus || 1
end

#command_devices(args) ⇒ Object



68
69
70
71
72
# File 'lib/ruflet/cli/extra_command.rb', line 68

def command_devices(args)
  tools = ensure_flutter!("devices")
  system(tools[:env], tools[:flutter], "devices", *args)
  $?.exitstatus || 1
end

#command_doctor(args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruflet/cli/extra_command.rb', line 17

def command_doctor(args)
  verbose = args.delete("--verbose") || args.delete("-v")
  fix = args.delete("--fix")
  client_dir = detect_client_dir
  template_root = resolve_ruflet_client_template_root
  puts "Ruflet doctor"
  puts "  Ruby: #{RUBY_VERSION}"
  puts "  Flutter host target: #{flutter_host || 'unsupported'}"

  # System prerequisites first: Flutter cannot be installed (or even
  # extracted) without them.
  environment_issues = environment_setup!(fix: !!fix, verbose: !!verbose)
  return 1 unless flutter_host

  if template_root
    puts "  Template: #{template_root}"
  elsif fix
    template_root = ensure_cached_ruflet_client_template!(force: true, verbose: !!verbose)
    unless template_root
      warn "  Template: missing"
      warn "Failed to fetch the Ruflet Flutter template from GitHub."
      return 1
    end
    puts "  Template: #{template_root}"
  else
    warn "  Template: missing"
    warn "Run `ruflet doctor --fix` to fetch the Flutter template from GitHub."
  end
  puts "  Ruby runtime: pub.dev package"
  if fix
    tools = ensure_flutter!("doctor", client_dir: client_dir, auto_install: true)
  else
    tools = flutter_tools(client_dir: client_dir, auto_install: false)
    unless tools
      warn "  Flutter: missing"
      warn "Run `ruflet doctor --fix` to install the host-platform Flutter SDK from .fvmrc."
      return 1
    end
  end
  puts "  Flutter: #{flutter_version_summary(tools)}"
  environment_issues += android_environment_setup!(fix: !!fix, verbose: !!verbose)
  ok = system(android_build_env(tools[:env]), tools[:flutter], "doctor", *(verbose ? ["-v"] : []))
  status = $?.exitstatus if $?
  status ||= ok ? 0 : 1
  if environment_issues.any?
    warn "Unresolved environment issues: #{environment_issues.join('; ')}"
    status = 1 if status.zero?
  end
  status
end

#command_emulators(args) ⇒ Object



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
# File 'lib/ruflet/cli/extra_command.rb', line 74

def command_emulators(args)
  tools = ensure_flutter!("emulators")
  action = nil
  emulator_id = nil
  verbose = false
  parser = OptionParser.new do |o|
    o.on("--create") { action = "create" }
    o.on("--delete") { action = "delete" }
    o.on("--start") { action = "start" }
    o.on("--emulator ID") { |v| emulator_id = v }
    o.on("-v", "--verbose") { verbose = true }
  end
  parser.parse!(args)

  case action
  when "start"
    unless emulator_id
      warn "Missing --emulator for start"
      return 1
    end
    cmd = [tools[:flutter], "emulators", "--launch", emulator_id]
    cmd << "-v" if verbose
    system(tools[:env], *cmd)
    $?.exitstatus || 1
  when "create", "delete"
    warn "ruflet emulators --#{action} is not implemented yet. Use your platform tools."
    1
  else
    cmd = [tools[:flutter], "emulators"]
    cmd << "-v" if verbose
    system(tools[:env], *cmd)
    $?.exitstatus || 1
  end
end