Class: MyFlutter::Tool

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

Constant Summary collapse

@@flutter_root =
ENV['HOME']+'/flutter'
@@flutterSDK_url =
"https://github.com/flutter/flutter.git"

Instance Method Summary collapse

Instance Method Details

#installObject



11
12
13
14
15
16
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
# File 'lib/myFlutter.rb', line 11

def install()
    if File.exist?(@@flutter_root)
      puts("flutterSDK 已经安装了")
    else
      Dir.chdir(ENV['HOME'])
      puts("执行下载FLutter SDK")
      `git clone #{@@flutterSDK_url}`
      raise 'flutter sdk下载失败' unless $?.success?
      puts("flutter SDK下载成功")
    end
    annotation = "#flutter settings\n"
    path_setting = "export PATH=\"$PATH:#{@@flutter_root}/bin\"\n"
      bash_profile_path = ENV['HOME']+'/.bash_profile'
      if File.exist?("#{bash_profile_path}")
        puts "Export the settings into #{bash_profile_path}"
        content = File.readlines("#{bash_profile_path}")
        bash_file = File.open(ENV['HOME']+'/.bash_profile', 'a')
        bash_file << "\n" unless content.last.eql?("\n")
        bash_file << "#{annotation}" unless content.include?("#{annotation}")
        bash_file << "#{path_setting}" unless content.include?("#{path_setting}")
        bash_file.close
      end

      zshrc_path = ENV['HOME']+'/.zshrc'
      if File.exist?("#{zshrc_path}")
        puts "Export the settings into #{zshrc_path}"
        content = File.readlines("#{zshrc_path}")
        zshrc = File.open(ENV['HOME']+'/.zshrc', 'a')
        zshrc << "\n" unless content.last.eql?("\n")
        zshrc << "#{annotation}" unless content.include?("#{annotation}")
        zshrc << "#{path_setting}" unless content.include?("#{path_setting}")
        zshrc.close
      end
end

#uninstallObject



47
48
49
50
51
52
53
54
# File 'lib/myFlutter.rb', line 47

def uninstall()
  if File.exist?("#{@@flutter_root}")
    puts "deleting the flutter sdk..."
    `rm -rf #{@@flutter_root}`
    raise 'git clone failed' unless $?.success?
  end
  puts "Remove the exported flutter variables in ~/.bash_profile and ~/.zshrc, if not needed anymore."
end