Class: Tuya::TYGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/tuya/cli/odm/group.rb

Class Method Summary collapse

Class Method Details

.create_spec(group) ⇒ Object



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
67
68
69
70
71
72
# File 'lib/tuya/cli/odm/group.rb', line 38

def self.create_spec(group)
  require 'tuya/cli/odm/config'
  
  config = Tuya::Config.new(group.name)

  local_spec_path = "#{config.path}spec/#{group.spec}"

  if File.exist? local_spec_path
    `rm -rf #{local_spec_path}`
  end

  `mkdir -p #{local_spec_path}`
  # `touch #{local_spec_path}/README.md`
  fh = File.new("#{local_spec_path}/README.md", 'w')
  fh.puts 'create by tuya-cli-odm'
  fh.close

  origin_path = FileUtils.pwd

  FileUtils.cd "#{local_spec_path}"

  require 'tuya/cli/odm/executable'

  commands = [
    %W(init),
    %W(add -A),
    %W(commit -am init\ repo\ spec),
    %W(remote add origin #{group.url}),
    %W(push --set-upstream origin master)
  ]

  Tuya::EXE.multi_exe('git', commands, true)

  FileUtils.cd origin_path
end

.create_tuya_public_incObject



111
112
113
# File 'lib/tuya/cli/odm/group.rb', line 111

def self.create_tuya_public_inc
  `pod repo add #{Tuya::TUYA_ODM_PUBLIC_REPO} #{Tuya::TUYA_ODM_PUBLIC_REPO_GIT}`
end

.create_tuya_public_inc_if_needObject



107
108
109
# File 'lib/tuya/cli/odm/group.rb', line 107

def self.create_tuya_public_inc_if_need
  create_tuya_public_inc unless is_tuya_public_inc_exist?
end

.is_local_repo_exist?(group_spec) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
# File 'lib/tuya/cli/odm/group.rb', line 95

def self.is_local_repo_exist?(group_spec)

  system = Tuya::System.instance
  local_path = system.pod_config.repos_dir + group_spec

  File.directory?(local_path)
end

.is_tuya_public_inc_exist?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/tuya/cli/odm/group.rb', line 103

def self.is_tuya_public_inc_exist?
  is_local_repo_exist? Tuya::TUYA_ODM_PUBLIC_REPO
end

.remote_spec_exist?(group) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'lib/tuya/cli/odm/group.rb', line 74

def self.remote_spec_exist?(group)

  result = Tuya::EXE.exe('git', %W(ls-remote #{group.url}))

  result.include? "refs/heads/master"
end

.setup_local_repo(group) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/tuya/cli/odm/group.rb', line 81

def self.setup_local_repo(group)
  if is_local_repo_exist?(group.spec)
    system = Tuya::System.instance
    local_path = system.pod_config.repos_dir + group.spec
    FileUtils.rm_rf(local_path)
  end
  repo_add = "pod repo add #{group.spec} #{group.url}"
  `#{repo_add}`

  puts "update local config: #{group.name}".yellow
  config = Tuya::Config.new(group.name)
  config.update_local_config
end

.setup_spec(group) ⇒ Object



33
34
35
36
# File 'lib/tuya/cli/odm/group.rb', line 33

def self.setup_spec(group)
  create_spec group unless remote_spec_exist? group
  setup_local_repo group
end

.statusObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tuya/cli/odm/group.rb', line 6

def self.status

  system = Tuya::System.instance

  group = system.group

  puts "can not find tuya group, please use 'tuya group create --name=group_name'".red unless group

  if group
    puts "#{group.name}".yellow
    puts "- Repo: #{group.spec}".green
    puts "- URL:  #{group.url}".green

    puts "\ncan not find #{group.spec}, please use 'tuya group create --name=group_name'".red unless is_local_repo_exist? group.spec
  end

  tuya_pub = is_tuya_public_inc_exist?

  puts "\ncan not find #{Tuya::TUYA_ODM_PUBLIC_REPO} please use 'pod repo add #{Tuya::TUYA_ODM_PUBLIC_REPO} #{Tuya::TUYA_ODM_PUBLIC_REPO_GIT}".red unless tuya_pub

  if tuya_pub
    puts "\nTYPublic".yellow
    puts "- Repo: #{Tuya::TUYA_ODM_PUBLIC_REPO}".green
    puts "- URL:  #{Tuya::TUYA_ODM_PUBLIC_REPO_GIT}".green
  end
end

.update_tuya_public_incObject



115
116
117
118
# File 'lib/tuya/cli/odm/group.rb', line 115

def self.update_tuya_public_inc
  puts "\nUpdate #{Tuya::TUYA_ODM_PUBLIC_REPO}".yellow
  `pod repo update #{Tuya::TUYA_ODM_PUBLIC_REPO}`
end