tuya-cli-odm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'tuya/cli/odm/command/repo/push'
4
+ require 'tuya/cli/odm/command'
5
+
6
+ module Tuya
7
+ class Command
8
+ class Repo < Command
9
+
10
+ self.abstract_command = true
11
+
12
+ self.summary = 'repo tools'
13
+ self.command = 'repo'
14
+
15
+ self.description = <<-DESC
16
+ repo
17
+ DESC
18
+ def self.options
19
+ [
20
+ ['--version=your-version', 'version if you want do a special version'],
21
+ ['--podspec', 'version if you want do a special version'],
22
+ ['--commit', 'use --no-commit']
23
+ ].concat(super)
24
+ end
25
+
26
+ # def validate!
27
+ # # help! "name need" unless @name
28
+ # end
29
+
30
+ def initialize(argv)
31
+ super
32
+
33
+ end
34
+
35
+ def run
36
+ super
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ module Tuya
2
+ class Command
3
+ class Repo < Command
4
+ class Push < Repo
5
+ self.abstract_command = false
6
+ self.summary = "push a module to tuya specs(your spec)"
7
+ self.command = 'push'
8
+
9
+ def validate!
10
+
11
+ @podspec = Tuya::PodSpec.ask_pod_spec unless @podspec
12
+ help! "\npodspec can not be nil" unless @podspec
13
+
14
+ @version = Tuya::PodSpec.pod_spec_version @podspec unless @version
15
+ help! "\nuse --version assign your verion " unless @version
16
+ end
17
+
18
+ def initialize(argv)
19
+ super
20
+
21
+ @is_commit = argv.flag?('commit', true)
22
+
23
+ @version = argv.option('version')
24
+ @podspec = argv.shift_argument
25
+
26
+ end
27
+
28
+ def run
29
+ puts "Pushing the podspec: #{@podspec} to version: #{@version}".green
30
+
31
+ Tuya::SpecRepo.push(@version, @is_commit, @podspec, @verbose)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,105 @@
1
+ module Tuya
2
+
3
+ TUYA_ODM_GITLAB_HOST = 'https://code-odm.tuya-inc.com'
4
+ TUYA_ODM_PUBLIC_REPO = 'TYPublicSpecs'
5
+ TUYA_ODM_PUBLIC_REPO_GIT = 'https://github.com/TuyaInc/TYPublicSpecs.git'
6
+
7
+ # require 'singleton'
8
+ class Config
9
+
10
+ # include Singleton
11
+
12
+ CONFIG_NAME = 'tuya-cli-public.json'
13
+
14
+
15
+ def self.config_path(user)
16
+ "#{user}/.tuya/"
17
+ end
18
+
19
+ def self.config_file_path(user)
20
+ path = config_path user
21
+ file = CONFIG_NAME
22
+ "#{path}#{file}"
23
+ end
24
+
25
+ def self.local_config(user)
26
+ path = config_path user
27
+ file = CONFIG_NAME
28
+ file_path = config_file_path user
29
+
30
+ if File.exist? file_path
31
+ config_string = File.read(file_path)
32
+
33
+ require 'json'
34
+ content = JSON.parse(config_string)
35
+
36
+ Tuya::ConfigGroup.new content['group']
37
+ end
38
+ end
39
+
40
+ attr_accessor :path
41
+ attr_accessor :file
42
+ attr_accessor :file_path
43
+ attr_accessor :group_name
44
+
45
+
46
+ def initialize(group_name)
47
+
48
+ @group_name = group_name
49
+ @system = Tuya::System.instance
50
+
51
+ @path = Tuya::Config.config_path @system.user
52
+ @file = CONFIG_NAME
53
+ @file_path = Tuya::Config.config_file_path @system.user
54
+
55
+ end
56
+
57
+ # create local file
58
+ def update_local_config
59
+
60
+ require 'json'
61
+
62
+ `mkdir -p #{@path}`
63
+
64
+ group_hash = Hash["group"=>@group_name]
65
+ group_json = JSON group_hash
66
+
67
+ if File.exist?@file_path
68
+ `rm #{file_path}`
69
+ end
70
+
71
+ fh = File.new(@file_path, 'w')
72
+ fh.puts group_json
73
+ fh.close
74
+
75
+ end
76
+
77
+ def group_local
78
+
79
+ end
80
+
81
+ end
82
+
83
+ class ConfigGroup
84
+ attr_accessor :name
85
+ attr_accessor :spec
86
+ attr_accessor :url
87
+ def initialize(name)
88
+ @name = name
89
+
90
+ @spec = "#{name}Specs"
91
+ @url = "#{Tuya::TUYA_ODM_GITLAB_HOST}/#{name}/#{@spec}.git"
92
+ end
93
+ end
94
+
95
+ class ConfigLib
96
+ attr_accessor :name
97
+ attr_accessor :group_name
98
+ attr_accessor :url
99
+ def initialize(group_name, name)
100
+ @name = name
101
+ @group_name = group_name
102
+ @url = "#{Tuya::TUYA_ODM_GITLAB_HOST}/#{group_name}/#{name}.git"
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,9 @@
1
+ module ODM
2
+ class ODMSpecSummaryHook
3
+ attr_accessor :type, :app_version
4
+ # def initialize(type, app_version)
5
+ # @type = type
6
+ # @app_version = app_version
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Tuya
2
+ class EXE
3
+ def self.exe(executable, command, raise_if_need = false, puts_filter = true )
4
+
5
+ result = Pod::Executable.execute_command(executable, command, raise_if_need)
6
+
7
+ # puts "##########"
8
+ # puts command
9
+ # puts "##########"
10
+
11
+
12
+ TYUtil::TYPuts.filter(result, TYUtil::TYPuts::ERROR_KEYS) if puts_filter
13
+
14
+ result
15
+ end
16
+
17
+ def self.multi_exe(executable, commands, raise_if_need = false)
18
+ commands.each do |command|
19
+ exe(executable, command, raise_if_need)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Tuya
2
+ class TuyaGit
3
+ def self.commit_all(msg)
4
+
5
+ puts "commit message can not be nil".red unless msg
6
+
7
+ `git add -A`
8
+ `git commit -am '#{msg}'`
9
+ end
10
+
11
+ def self.commit_file(file, msg)
12
+ puts "commit message/file can not be nil".red unless msg
13
+
14
+ `git add #{file}`
15
+ `git commit -m '#{msg}'`
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,121 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ module Tuya
4
+ class TYGroup
5
+
6
+ def self.status
7
+
8
+ system = Tuya::System.instance
9
+
10
+ group = system.group
11
+
12
+ puts "can not find tuya group, please use 'tuya group create --name=group_name'".red unless group
13
+
14
+ if group
15
+ puts "#{group.name}".yellow
16
+ puts "- Repo: #{group.spec}".green
17
+ puts "- URL: #{group.url}".green
18
+
19
+ puts "\ncan not find #{group.spec}, please use 'tuya group create --name=group_name'".red unless is_local_repo_exist? group.spec
20
+ end
21
+
22
+ tuya_pub = is_tuya_public_inc_exist?
23
+
24
+ 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
25
+
26
+ if tuya_pub
27
+ puts "\nTYPublic".yellow
28
+ puts "- Repo: #{Tuya::TUYA_ODM_PUBLIC_REPO}".green
29
+ puts "- URL: #{Tuya::TUYA_ODM_PUBLIC_REPO_GIT}".green
30
+ end
31
+ end
32
+
33
+ def self.setup_spec(group)
34
+ create_spec group unless remote_spec_exist? group
35
+ setup_local_repo group
36
+ end
37
+
38
+ def self.create_spec(group)
39
+ require 'tuya/cli/odm/config'
40
+
41
+ config = Tuya::Config.new(group.name)
42
+
43
+ local_spec_path = "#{config.path}spec/#{group.spec}"
44
+
45
+ if File.exist? local_spec_path
46
+ `rm -rf #{local_spec_path}`
47
+ end
48
+
49
+ `mkdir -p #{local_spec_path}`
50
+ # `touch #{local_spec_path}/README.md`
51
+ fh = File.new("#{local_spec_path}/README.md", 'w')
52
+ fh.puts 'create by tuya-cli-odm'
53
+ fh.close
54
+
55
+ origin_path = FileUtils.pwd
56
+
57
+ FileUtils.cd "#{local_spec_path}"
58
+
59
+ require 'tuya/cli/odm/executable'
60
+
61
+ commands = [
62
+ %W(init),
63
+ %W(add -A),
64
+ %W(commit -am init\ repo\ spec),
65
+ %W(remote add origin #{group.url}),
66
+ %W(push --set-upstream origin master)
67
+ ]
68
+
69
+ Tuya::EXE.multi_exe('git', commands, true)
70
+
71
+ FileUtils.cd origin_path
72
+ end
73
+
74
+ def self.remote_spec_exist?(group)
75
+
76
+ result = Tuya::EXE.exe('git', %W(ls-remote #{group.url}))
77
+
78
+ result.include? "refs/heads/master"
79
+ end
80
+
81
+ def self.setup_local_repo(group)
82
+ if is_local_repo_exist?(group.spec)
83
+ system = Tuya::System.instance
84
+ local_path = system.pod_config.repos_dir + group.spec
85
+ FileUtils.rm_rf(local_path)
86
+ end
87
+ repo_add = "pod repo add #{group.spec} #{group.url}"
88
+ `#{repo_add}`
89
+
90
+ puts "update local config: #{group.name}".yellow
91
+ config = Tuya::Config.new(group.name)
92
+ config.update_local_config
93
+ end
94
+
95
+ def self.is_local_repo_exist?(group_spec)
96
+
97
+ system = Tuya::System.instance
98
+ local_path = system.pod_config.repos_dir + group_spec
99
+
100
+ File.directory?(local_path)
101
+ end
102
+
103
+ def self.is_tuya_public_inc_exist?
104
+ is_local_repo_exist? Tuya::TUYA_ODM_PUBLIC_REPO
105
+ end
106
+
107
+ def self.create_tuya_public_inc_if_need
108
+ create_tuya_public_inc unless is_tuya_public_inc_exist?
109
+ end
110
+
111
+ def self.create_tuya_public_inc
112
+ `pod repo add #{Tuya::TUYA_ODM_PUBLIC_REPO} #{Tuya::TUYA_ODM_PUBLIC_REPO_GIT}`
113
+ end
114
+
115
+ def self.update_tuya_public_inc
116
+ puts "\nUpdate #{Tuya::TUYA_ODM_PUBLIC_REPO}".yellow
117
+ `pod repo update #{Tuya::TUYA_ODM_PUBLIC_REPO}`
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,91 @@
1
+ module Tuya
2
+ class TYLib
3
+ def self.create_lib(template)
4
+
5
+ name = template.configurator.pod_name
6
+
7
+ system = Tuya::System.instance
8
+
9
+ group = system.group
10
+ config = Tuya::ConfigLib.new(group.name, name)
11
+
12
+ if remote_lib_exist? config.url
13
+ puts "remote #{config.name} exist".yellow
14
+ else
15
+ puts "\npushing #{name} to remote...".yellow
16
+ push_lib config, template
17
+ end
18
+
19
+ puts "#{config.name}".green
20
+ puts "URL- #{config.url}".green
21
+
22
+ end
23
+
24
+ def self.push_lib(config, template)
25
+ origin_path = FileUtils.pwd
26
+
27
+ target_path = "#{origin_path}/#{config.name}"
28
+
29
+ if File.exist? target_path
30
+ FileUtils.cd target_path
31
+
32
+ git_path = "#{target_path}/.git"
33
+
34
+ if File.exist? git_path
35
+ rm_commands = [
36
+ %W(-rf #{git_path})
37
+ ]
38
+ Tuya::EXE.multi_exe('rm', rm_commands, true)
39
+ end
40
+
41
+ repair_podspec(target_path, "#{config.name}.podspec", config, template)
42
+
43
+ FileUtils.cd "Example"
44
+ repair_podfile_source
45
+ FileUtils.cd ".."
46
+
47
+ git_commands = [
48
+ %W(init),
49
+ %W(add -A),
50
+ %W(commit -am init\ #{config.name}\ by\ tuya-cli),
51
+ %W(remote add origin #{config.url}),
52
+ %W(push --set-upstream origin master)
53
+ ]
54
+ Tuya::EXE.multi_exe('git', git_commands, true)
55
+ end
56
+
57
+ FileUtils.cd origin_path
58
+ end
59
+
60
+ def self.repair_podfile_source
61
+
62
+ system = Tuya::System.instance
63
+
64
+ group = system.group
65
+ podfile = TYCiCore::Podfile.new
66
+ podfile.source_replace("# source '@{GROUP_SPEC}'", "source '#{group.url}'")
67
+ podfile.save
68
+ end
69
+
70
+ def self.repair_podspec(path, file, config, template)
71
+ Tuya::PodSpec.repair_lib_spec(path, file, config)
72
+
73
+ podspec = TYCiCore::PodSpec.new "./#{file}"
74
+
75
+ summary_hash = Hash.new
76
+ summary_hash['type'] = template.configurator.config.type
77
+ summary_hash['appVersion'] = template.configurator.config.last_version
78
+
79
+
80
+ podspec.update 'summary', summary_hash.to_json
81
+ podspec.save
82
+ end
83
+
84
+ def self.remote_lib_exist?(url)
85
+
86
+ result = Tuya::EXE.exe('git', %W(ls-remote #{url}), false , false )
87
+
88
+ result.include? "refs/heads/master"
89
+ end
90
+ end
91
+ end