class Tuya::TYGroup

Public Class Methods

create_spec(group) click to toggle source
# 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_inc() click to toggle source
# 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_need() click to toggle source
# 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) click to toggle source
# 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?() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
status() click to toggle source
# 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_inc() click to toggle source
# 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