tycli-public 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7389b8d31d240723a43a84599a77b46a09768eab
4
+ data.tar.gz: ac90133fcac7f3fb12ce8cbb5f1c2fdac13c5efb
5
+ SHA512:
6
+ metadata.gz: 9c3575fdbffcd4ff1db8fc4187af295f0ebb360d72204a213d7e813583fc5665181d3d278b84ff33209c658c0015f40ece8719d96a95001ee37ffbab07cef52c
7
+ data.tar.gz: 0aaf7b5fe4d710a492a7efce3cf90b4dc876d55398476d468bcf5f8784428bba56cb9ab6fb4ee982d2bbf520deeb5680754a850769ed01e17553cdcba29336bd
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 fangdong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Tycli::Public
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tycli/public`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tycli-public'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tycli-public
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tycli-public. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Tycli::Public project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tycli-public/blob/master/CODE_OF_CONDUCT.md).
data/bin/tuya ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tycli'
4
+ require 'cocoapods'
5
+ require 'colored'
6
+
7
+ # help! 'ddd'
8
+ #
9
+ # c = TYCommand2.new
10
+ # c.exe(ARGV)
11
+
12
+ Tuya::Command.run(ARGV)
13
+
14
+
15
+ # TYCommand.run(ARGV)
data/lib/tycli.rb ADDED
@@ -0,0 +1 @@
1
+ require 'tycli/command'
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
4
+
5
+ require 'claide'
6
+ require 'colored'
7
+
8
+
9
+ module Tuya
10
+ class Command < CLAide::Command
11
+
12
+ require 'tycli/command/lib'
13
+ #require 'tycli/command/ci'
14
+ require 'tycli/command/repo'
15
+ require 'tycli/command/group'
16
+
17
+ self.abstract_command = true
18
+
19
+ self.description = 'welcome to tuya-cli'
20
+
21
+ puts "\n
22
+ ████████╗██╗ ██╗██╗ ██╗ █████╗
23
+ ╚══██╔══╝██║ ██║╚██╗ ██╔╝██╔══██╗
24
+ ██║ ██║ ██║ ╚████╔╝ ███████║
25
+ ██║ ██║ ██║ ╚██╔╝ ██╔══██║
26
+ ██║ ╚██████╔╝ ██║ ██║ ██║
27
+ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ \n" .yellow
28
+
29
+
30
+
31
+ self.command = 'tuya'
32
+
33
+ def run
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'tycli/command/ci/show_log_tips'
4
+
5
+ require 'tycli/command'
6
+
7
+ module Tuya
8
+ class Command
9
+ class CI < Command
10
+
11
+ self.abstract_command = true
12
+
13
+ self.summary = 'help for tuya ci'
14
+ self.command = 'ci'
15
+
16
+ self.description = <<-DESC
17
+ tuya ci helper
18
+ DESC
19
+ def self.options
20
+ [
21
+ ['--te=te', 'te te t e']
22
+ ].concat(super)
23
+ end
24
+
25
+ def initialize(argv)
26
+ super
27
+ end
28
+
29
+ def run
30
+ super
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,16 @@
1
+ module Tuya
2
+ class Command
3
+ class CI < Command
4
+ class ShowLogTips < CI
5
+ self.abstract_command = false
6
+ self.summary = "show ci log error tips"
7
+ self.command = 'tips'
8
+
9
+ def run
10
+ puts("when ci build errors, you can search keyworkds: \n")
11
+ puts("- ERROR\nfatal error:\nfastlane finished with errors\n")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'tycli/command/group/create'
4
+ require 'tycli/command/group/init'
5
+ require 'tycli/command/group/status'
6
+
7
+ require 'tycli/command'
8
+
9
+ module Tuya
10
+ class Command
11
+ class Group < Command
12
+
13
+ self.abstract_command = true
14
+
15
+ self.summary = 'help manage your group'
16
+ self.command = 'group'
17
+
18
+ self.description = <<-DESC
19
+ tuya group helper
20
+ DESC
21
+
22
+ def self.options
23
+ [
24
+ ['--name=group_name', '--name the name for your group']
25
+ ]
26
+ end
27
+
28
+ def run
29
+ super
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,36 @@
1
+ module Tuya
2
+ class Command
3
+ class Group < Command
4
+ class GroupCreate < Group
5
+ self.abstract_command = false
6
+ self.summary = "create a remote repo spec(if need) & init your local repo spec"
7
+ self.command = 'create'
8
+
9
+ def run
10
+ puts "group name is #{@name}".green
11
+
12
+ require 'tycli/group'
13
+ require 'tycli/config'
14
+
15
+ group = Tuya::ConfigGroup.new(@name)
16
+ Tuya::TYGroup.setup_spec group
17
+ Tuya::TYGroup.create_tuya_public_inc_if_need
18
+ end
19
+ def self.options
20
+ [
21
+ ['--name=group_name', '--name the name for your group']
22
+ ]
23
+ end
24
+
25
+ def initialize(argv)
26
+ super
27
+ @name = argv.option('name')
28
+ end
29
+
30
+ def validate!
31
+ help! "name need" unless @name
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module Tuya
2
+ class Command
3
+ class Group < Command
4
+ class GroupInit < Group
5
+ self.abstract_command = false
6
+ self.summary = "init your local repo spec"
7
+ self.command = 'init'
8
+
9
+ def run
10
+ puts "group name is #{@name}".green
11
+
12
+ require 'tycli/group'
13
+ require 'tycli/config'
14
+
15
+ group = Tuya::ConfigGroup.new(@name)
16
+ Tuya::TYGroup.setup_local_repo group
17
+ end
18
+ def self.options
19
+ [
20
+ ['--name=group_name', '--name the name for your group']
21
+ ]
22
+ end
23
+
24
+ def initialize(argv)
25
+ super
26
+ @name = argv.option('name')
27
+ end
28
+
29
+ def validate!
30
+ help! "name need" unless @name
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ module Tuya
2
+ class Command
3
+ class Group < Command
4
+ class GroupStatus < Group
5
+ self.abstract_command = false
6
+ self.summary = "show your local tuya repo status"
7
+ self.command = 'status'
8
+
9
+ def run
10
+ require 'tycli/group'
11
+
12
+ Tuya::TYGroup.status
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'tycli/command/lib/create'
4
+ # require 'tycli/command/lib/create_simple'
5
+
6
+ require 'tycli/command'
7
+
8
+ module Tuya
9
+ class Command
10
+ class Lib < Command
11
+
12
+ self.abstract_command = true
13
+
14
+ self.summary = 'create tuya module'
15
+ self.command = 'lib'
16
+
17
+ self.description = "tuya cli tools"
18
+
19
+ def run
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+
@@ -0,0 +1,77 @@
1
+ module Tuya
2
+ class Command
3
+ class Lib < Command
4
+ class Create < Lib
5
+ self.abstract_command = false
6
+ self.summary = "create a module"
7
+ self.command = 'create'
8
+
9
+ def self.options
10
+ [
11
+ ['--name=module_name', '--name to named your module']
12
+ ].concat(super)
13
+ end
14
+
15
+ def validate!
16
+ help! "name need" unless @name
17
+ end
18
+
19
+ def initialize(argv)
20
+ super
21
+ @name = argv.option('name')
22
+ end
23
+
24
+ def run
25
+ puts "creating the module named: #{@name}...".yellow
26
+
27
+ require 'ruby-progressbar'
28
+
29
+ require 'colored'
30
+
31
+ file_not_exist = !File.exist?("./#{@name}")
32
+ puts "#{@name} is alerady exits".red unless file_not_exist
33
+
34
+ if file_not_exist
35
+
36
+ progressbar = ProgressBar.create
37
+ 15.times { progressbar.increment; sleep 3 }
38
+
39
+ t_c = Thread.new {createModule()}
40
+
41
+ t_c.join
42
+ progressbar.finish
43
+
44
+ puts "create module: #{@name} successful".green
45
+
46
+ puts "\n\n我们默认添加了SDK依赖, 可在Podfile文件中查看\n".green
47
+ puts "SDK文档及使用请参考:https://github.com/TuyaInc/tuyasmart_home_ios_sdk\n".green
48
+
49
+ require 'tycli/lib'
50
+
51
+ Tuya::TYLib.create_lib @name
52
+ end
53
+
54
+ end
55
+
56
+ def showProgress
57
+ progressbar = ProgressBar.create
58
+ 100.times { progressbar.increment; sleep 3 }
59
+ end
60
+
61
+ def createModule
62
+
63
+ if File.exist? "./#{@name}"
64
+ puts "#{@name} is alerady exits".red
65
+ else
66
+ result = `pod lib create #{@name} --template-url=https://github.com/TuyaInc/pod-template.git`
67
+ result.each_line do |s|
68
+ if s.include?("fatal")
69
+ puts "#{s}".red
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,52 @@
1
+ module Tuya
2
+ class Command
3
+ class Lib < Command
4
+ class CreateSimple < Lib
5
+ self.abstract_command = false
6
+ self.summary = "create a module"
7
+ self.command = 'create-simple'
8
+
9
+ def self.options
10
+ [
11
+ ['--name=module_name', '--name to named your module']
12
+ ].concat(super)
13
+ end
14
+
15
+ def validate!
16
+ help! "name need" unless @name
17
+ end
18
+
19
+ def initialize(argv)
20
+ super
21
+ @name = argv.option('name')
22
+ end
23
+
24
+ def run
25
+
26
+ puts "do create a simple module named: #{@name}".green
27
+
28
+ require 'ruby-progressbar'
29
+
30
+ progressbar = ProgressBar.create
31
+ 15.times { progressbar.increment; sleep 2 }
32
+
33
+ t_c = Thread.new {createModule()}
34
+
35
+ t_c.join
36
+ progressbar.finish
37
+
38
+ puts "end create simple module: #{@name}".green
39
+ end
40
+
41
+ def createModule
42
+ result = `pod lib create #{@name} --template-url=https://code.registry.wgine.com/client-platform/pod-template-simple.git`
43
+ result.each_line do |s|
44
+ if s.include?("fatal")
45
+ puts "#{s}".red
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,43 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ # require 'tycli/command/repo/init'
4
+ # require 'tycli/command/repo/lint'
5
+ require 'tycli/command/repo/push'
6
+
7
+ require 'tycli/command'
8
+
9
+ module Tuya
10
+ class Command
11
+ class Repo < Command
12
+
13
+ self.abstract_command = true
14
+
15
+ self.summary = 'repo tools'
16
+ self.command = 'repo'
17
+
18
+ self.description = <<-DESC
19
+ repo
20
+ DESC
21
+ def self.options
22
+ [
23
+ ['--version=your-version', 'version if you want do a special version'],
24
+ ['--podspec', 'version if you want do a special version'],
25
+ ['--commit', 'use --no-commit']
26
+ ].concat(super)
27
+ end
28
+
29
+ # def validate!
30
+ # # help! "name need" unless @name
31
+ # end
32
+
33
+ def initialize(argv)
34
+ super
35
+
36
+ end
37
+
38
+ def run
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end
File without changes
File without changes
@@ -0,0 +1,42 @@
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 self.options
10
+ [
11
+ ['--name=group_name', '--name the name for your group']
12
+ ].concat(super)
13
+ end
14
+
15
+ def validate!
16
+ help! "use --version assign your verion " unless @version
17
+ help! "podspec can not be nil" unless @podspec
18
+ end
19
+
20
+ def initialize(argv)
21
+ super
22
+
23
+ @is_commit = argv.flag?('commit', true)
24
+
25
+ @version = argv.option('version')
26
+ # @version = '0.0.1' unless @version
27
+ @podspec = argv.shift_argument
28
+
29
+ # p ("we will push version is #{@version} and before #{@is_commit}")
30
+ end
31
+
32
+ def run
33
+ puts "Pushing the podspec: #{@podspec} to version: #{@version}".green
34
+
35
+ require 'tycli/spec_repo'
36
+
37
+ Tuya::SpecRepo.push(@version, @is_commit, @podspec)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,103 @@
1
+ module Tuya
2
+
3
+ # require 'singleton'
4
+ class Config
5
+
6
+ # include Singleton
7
+
8
+ CONFIG_NAME = 'tuya-cli-public.json'
9
+
10
+ def self.config_path(user)
11
+ "/Users/#{user}/.tuya/"
12
+ end
13
+
14
+ def self.config_file_path(user)
15
+ path = config_path user
16
+ file = CONFIG_NAME
17
+ "#{path}#{file}"
18
+ end
19
+
20
+ def self.local_config(user)
21
+ path = config_path user
22
+ file = CONFIG_NAME
23
+ file_path = config_file_path user
24
+
25
+ if File.exist? file_path
26
+ config_string = File.read(file_path)
27
+
28
+ require 'json'
29
+ content = JSON.parse(config_string)
30
+
31
+ Tuya::ConfigGroup.new content['group']
32
+ end
33
+ end
34
+
35
+ attr_accessor :path
36
+ attr_accessor :file
37
+ attr_accessor :file_path
38
+ attr_accessor :group_name
39
+
40
+
41
+ def initialize(group_name)
42
+
43
+ require 'tycli/system'
44
+
45
+ @group_name = group_name
46
+ @system = Tuya::System.instance
47
+
48
+ @path = Tuya::Config.config_path @system.user
49
+ @file = CONFIG_NAME
50
+ @file_path = Tuya::Config.config_file_path @system.user
51
+
52
+ end
53
+
54
+ # create local file
55
+ def update_local_config
56
+
57
+ require 'json'
58
+
59
+ `mkdir -p #{@path}`
60
+
61
+ group_hash = Hash["group"=>@group_name]
62
+ group_json = JSON group_hash
63
+
64
+ if File.exist?@file_path
65
+ `rm #{file_path}`
66
+ end
67
+
68
+ fh = File.new(@file_path, 'w')
69
+ fh.puts group_json
70
+ fh.close
71
+
72
+ end
73
+
74
+ def group_local
75
+
76
+ end
77
+
78
+ end
79
+
80
+ class ConfigGroup
81
+ attr_accessor :name
82
+ attr_accessor :spec
83
+ attr_accessor :url
84
+ def initialize(name)
85
+ @name = name
86
+
87
+ @spec = "#{name}Specs"
88
+ @url = "https://gitlab.com/#{name}/#{@spec}.git"
89
+ end
90
+ end
91
+
92
+ class ConfigLib
93
+ attr_accessor :name
94
+ attr_accessor :group_name
95
+ attr_accessor :url
96
+ def initialize(group_name, name)
97
+ @name = name
98
+ @group_name = group_name
99
+
100
+ @url = "https://gitlab.com/#{group_name}/#{name}.git"
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,21 @@
1
+ module Tuya
2
+ class EXE
3
+ def self.exe(executable, command, raise_if_need = false)
4
+ require 'cocoapods'
5
+ require 'cocoapods/executable'
6
+ require 'tycli/util/puts_util'
7
+
8
+ result = Pod::Executable.execute_command(executable, command, raise_if_need)
9
+
10
+ TYUtil::TYPuts.filter(result, TYUtil::TYPuts::ERROR_KEYS)
11
+
12
+ result
13
+ end
14
+
15
+ def self.multi_exe(executable, commands, raise_if_need = false)
16
+ commands.each do |command|
17
+ exe(executable, command, raise_if_need)
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/tycli/git.rb ADDED
@@ -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,128 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ require 'tycli/system'
3
+
4
+ require 'cocoapods'
5
+ require 'cocoapods/executable'
6
+
7
+ module Tuya
8
+ class TYGroup
9
+
10
+ def self.status
11
+
12
+ system = Tuya::System.instance
13
+
14
+ group = system.group
15
+
16
+ puts "can not find tuya group, please use 'tuya group create --name=group_name'".red unless group
17
+
18
+ if group
19
+ puts "#{group.name}".yellow
20
+ puts "- Repo: #{group.spec}".green
21
+ puts "- URL: #{group.url}".green
22
+
23
+ puts "\ncan not find #{group.spec}, please use 'tuya group create --name=group_name'".red unless is_local_repo_exist? group.spec
24
+ end
25
+
26
+ tuya_pub = is_tuya_public_inc_exist?
27
+
28
+ puts "\ncan not find TYPublicSpecs please use 'pod repo add TYPublicSpecs https://github.com/TuyaInc/TYPublicSpecs.git'".red unless tuya_pub
29
+
30
+ if tuya_pub
31
+ puts "\nTYPublic".yellow
32
+ puts "- Repo: TYPublicSpecs".green
33
+ puts "- URL: https://github.com/TuyaInc/TYPublicSpecs.git".green
34
+ end
35
+ end
36
+
37
+ def self.setup_spec(group)
38
+ create_spec group unless remote_spec_exist? group
39
+ setup_local_repo group
40
+ end
41
+
42
+ def self.create_spec(group)
43
+ require 'tycli/config'
44
+
45
+ config = Tuya::Config.new(group.name)
46
+
47
+ local_spec_path = "#{config.path}spec/#{group.spec}"
48
+
49
+ if File.exist? local_spec_path
50
+ `rm -rf #{local_spec_path}`
51
+ end
52
+
53
+ `mkdir -p #{local_spec_path}`
54
+ # `touch #{local_spec_path}/README.md`
55
+ fh = File.new("#{local_spec_path}/README.md", 'w')
56
+ fh.puts 'create by tuya-cli'
57
+ fh.close
58
+
59
+ origin_path = FileUtils.pwd
60
+
61
+ FileUtils.cd "#{local_spec_path}"
62
+
63
+ require 'tycli/executable'
64
+
65
+ commands = [
66
+ %W(init),
67
+ %W(add -A),
68
+ %W(commit -am init\ repo\ spec),
69
+ %W(remote add origin #{group.url}),
70
+ %W(push --set-upstream origin master)
71
+ ]
72
+
73
+ Tuya::EXE.multi_exe('git', commands, true)
74
+
75
+ FileUtils.cd origin_path
76
+ end
77
+
78
+ def self.remote_spec_exist?(group)
79
+
80
+ require 'tycli/executable'
81
+
82
+ result = Tuya::EXE.exe('git', %W(ls-remote #{group.url}))
83
+
84
+ result.include? "refs/heads/master"
85
+ end
86
+
87
+ def self.setup_local_repo(group)
88
+ if is_local_repo_exist?(group.spec)
89
+ system = Tuya::System.instance
90
+ local_path = system.pod_config.repos_dir + group.spec
91
+ FileUtils.rm_rf(local_path)
92
+ end
93
+ repo_add = "pod repo add #{group.spec} #{group.url}"
94
+ `#{repo_add}`
95
+
96
+ require 'tycli/config'
97
+ puts "update local config: #{group.name}".yellow
98
+ config = Tuya::Config.new(group.name)
99
+ config.update_local_config
100
+ end
101
+
102
+ def self.is_local_repo_exist?(group_spec)
103
+
104
+ system = Tuya::System.instance
105
+ local_path = system.pod_config.repos_dir + group_spec
106
+
107
+ File.directory?(local_path)
108
+ end
109
+
110
+ def self.is_tuya_public_inc_exist?
111
+ is_local_repo_exist? 'TYPublicSpecs'
112
+ end
113
+
114
+ def self.create_tuya_public_inc_if_need
115
+ create_tuya_public_inc unless is_tuya_public_inc_exist?
116
+ end
117
+
118
+ def self.create_tuya_public_inc
119
+ `pod repo add TYPublicSpecs https://github.com/TuyaInc/TYPublicSpecs.git`
120
+ end
121
+
122
+ def self.update_tuya_public_inc
123
+ puts "\nUpdate TYPublicSpecs".yellow
124
+ `pod repo update TYPublicSpecs`
125
+ end
126
+
127
+ end
128
+ end
data/lib/tycli/lib.rb ADDED
@@ -0,0 +1,73 @@
1
+ module Tuya
2
+ class TYLib
3
+ def self.create_lib(name)
4
+
5
+ require 'tycli/config'
6
+ require 'tycli/system'
7
+
8
+ system = Tuya::System.instance
9
+
10
+ group = system.group
11
+ config = Tuya::ConfigLib.new(group.name, name)
12
+
13
+ if remote_lib_exist? config.url
14
+ puts "remote #{config.name} exist".yellow
15
+ else
16
+ puts "\n pushing #{name} to remote...".yellow
17
+ push_lib config
18
+ end
19
+
20
+ puts "#{config.name}".green
21
+ puts "URL- #{config.url}".green
22
+
23
+ end
24
+
25
+ def self.push_lib(config)
26
+ origin_path = FileUtils.pwd
27
+
28
+ target_path = "#{origin_path}/#{config.name}"
29
+
30
+ if File.exist? target_path
31
+ FileUtils.cd target_path
32
+
33
+ git_path = "#{target_path}/.git"
34
+
35
+ require 'tycli/executable'
36
+
37
+ if File.exist? git_path
38
+ rm_commands = [
39
+ %W(-rf #{git_path})
40
+ ]
41
+ Tuya::EXE.multi_exe('rm', rm_commands, true)
42
+ end
43
+
44
+ repair_podspec(target_path, "#{config.name}.podspec", config)
45
+
46
+ git_commands = [
47
+ %W(init),
48
+ %W(add -A),
49
+ %W(commit -am init\ #{config.name}\ by\ tuya-cli),
50
+ %W(remote add origin #{config.url}),
51
+ %W(push --set-upstream origin master)
52
+ ]
53
+ Tuya::EXE.multi_exe('git', git_commands, true)
54
+ end
55
+
56
+ FileUtils.cd origin_path
57
+ end
58
+
59
+ def self.repair_podspec(path, file, config)
60
+ require 'tycli/repo/spec'
61
+ Tuya::PodSpec.repair_lib_spec(path, file, config)
62
+ end
63
+
64
+ def self.remote_lib_exist?(url)
65
+
66
+ require 'tycli/executable'
67
+
68
+ result = Tuya::EXE.exe('git', %W(ls-remote #{url}))
69
+
70
+ result.include? "refs/heads/master"
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,59 @@
1
+ module Tuya
2
+ class PodSpec
3
+ def self.update(podspec, version)
4
+
5
+ result = Array.new
6
+
7
+ files = podspec_files(podspec)
8
+
9
+ files.each do |podspec_path|
10
+
11
+ spec_content = File.read(podspec_path)
12
+
13
+ res = spec_content.scan(/.version\s*=\s*'#{version}'/)
14
+
15
+ if res.size == 0
16
+ spec_content.gsub!(/s.version\s*=(.*?)'$/, "s.version = '#{version}'")
17
+
18
+ fh = File.new(podspec_path, "w")
19
+ fh.puts spec_content
20
+ fh.close
21
+
22
+ result.push(podspec_path)
23
+ end
24
+
25
+ result
26
+ end
27
+ end
28
+
29
+ def self.repair_lib_spec(path, file, config)
30
+
31
+ podspec = "#{path}/#{file}"
32
+
33
+ if File.exist? podspec
34
+ spec_content = File.read(podspec)
35
+ spec_content = repair_source(spec_content, config.url)
36
+
37
+ fh = File.new(podspec, "w")
38
+ fh.puts spec_content
39
+ fh.close
40
+ end
41
+ end
42
+
43
+ def self.repair_source(podspec, git_url)
44
+ podspec.gsub!(/:git => (.*),/, ":git => '#{git_url}',")
45
+ end
46
+
47
+ def self.podspec_files(podspec)
48
+ if podspec
49
+ path = Pathname(podspec)
50
+ raise Informative, "Couldn't find #{podspec}" unless path.exist?
51
+ [path]
52
+ else
53
+ files = Pathname.glob('*.podspec{,.json}')
54
+ raise Informative, "Couldn't find any podspec files in current directory" if files.empty?
55
+ files
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,60 @@
1
+ module Tuya
2
+ class SpecRepo
3
+ def self.push(version, is_commit_all, podspec)
4
+
5
+ require 'tycli/repo/spec'
6
+ require 'tycli/git'
7
+ require 'colored'
8
+
9
+ if is_commit_all
10
+ Tuya::TuyaGit.commit_all('feat: update all by tuya-cli repo push')
11
+ end
12
+
13
+ podspecs = Tuya::PodSpec.update(podspec, version)
14
+ podspecs.each do |podspec_file|
15
+ Tuya::TuyaGit.commit_file(podspec_file, "feat: update version #{version} by tuya-cli repo push")
16
+ end
17
+
18
+ require 'tycli/executable'
19
+
20
+ puts "\nPush podspec(git)...".yellow
21
+ git_push_commands = [
22
+ %W(push)
23
+ ]
24
+ Tuya::EXE.multi_exe('git', git_push_commands, true)
25
+
26
+ puts "\nAdd tag: #{version}...".yellow
27
+ git_tag_commands = [
28
+ %W(tag -a #{version} -m 'add\ tag:\ #{version}\ by\ tuya-cli\ repo\ push')
29
+ ]
30
+ Tuya::EXE.multi_exe('git', git_tag_commands, true)
31
+
32
+ puts "\nPush tag: #{version}...".yellow
33
+ git_tag_push_commands = [
34
+ %W(push origin --tags)
35
+ ]
36
+ Tuya::EXE.multi_exe('git', git_tag_push_commands, true)
37
+
38
+ require 'tycli/system'
39
+
40
+ system = Tuya::System.instance
41
+
42
+ group = system.group
43
+
44
+ podspecs.each do |podspec_file|
45
+
46
+ puts "\nPush #{podspec_file}...".yellow
47
+
48
+ pod_push = "pod repo push #{group.spec} #{podspec_file} --sources='#{group.url},https://github.com/CocoaPods/Specs.git,https://github.com/TuyaInc/TYPublicSpecs.git' --use-libraries --allow-warnings"
49
+
50
+ pod_push_result = `#{pod_push}`
51
+
52
+ pod_push_result.each_line do |s|
53
+ if s.include?("fatal") || s.include?("Couldn't find")
54
+ puts "!!!#{s}".red
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,28 @@
1
+ require 'cocoapods'
2
+ require 'cocoapods/config'
3
+ require 'tycli/config'
4
+
5
+ module Tuya
6
+ require 'singleton'
7
+ class System
8
+ include Pod::Config::Mixin
9
+ include Singleton
10
+ def self.lint
11
+ p "current ruby version: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
12
+
13
+ require 'cocoapods'
14
+ p Pod::VERSION
15
+ end
16
+
17
+ attr_accessor :user
18
+ attr_accessor :pod_config
19
+ attr_accessor :group
20
+
21
+ def initialize
22
+ @user = `id -un`.strip
23
+ @pod_config = config
24
+
25
+ @group = Tuya::Config.local_config @user
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+ module TYUtil
3
+ class TYPuts
4
+
5
+ ERROR_KEYS = [
6
+ "fatal",
7
+ "error",
8
+ "can not",
9
+ "not found"
10
+ ]
11
+
12
+ def self.filter_color(target, keys, color, pre)
13
+ target.each_line do |s|
14
+
15
+ eval_command = ""
16
+ keys.each do |key|
17
+ temp = ""
18
+ if eval_command.length > 0
19
+ temp = " || "
20
+ end
21
+ eval_command = "#{eval_command}#{temp}s.include?('#{key}')"
22
+ end
23
+ if eval_command.length > 0 && (eval eval_command)
24
+ out = "#{pre} #{s}".gsub!("'","")
25
+ eval "puts '#{out}'.#{color}"
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ def self.filter(target, keys)
32
+ filter_color(target, keys, 'yellow', '[!tuya-cli]')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Tycli
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tycli-public
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - fangdong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: claide
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-progressbar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: colored
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: cocoapods
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: tuya cli public tools
112
+ email:
113
+ - fangdong@tuyasmart.com
114
+ executables:
115
+ - tuya
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - LICENSE.txt
120
+ - README.md
121
+ - bin/tuya
122
+ - lib/tycli.rb
123
+ - lib/tycli/command.rb
124
+ - lib/tycli/command/ci.rb
125
+ - lib/tycli/command/ci/show_log_tips.rb
126
+ - lib/tycli/command/group.rb
127
+ - lib/tycli/command/group/create.rb
128
+ - lib/tycli/command/group/init.rb
129
+ - lib/tycli/command/group/status.rb
130
+ - lib/tycli/command/lib.rb
131
+ - lib/tycli/command/lib/create.rb
132
+ - lib/tycli/command/lib/create_simple.rb
133
+ - lib/tycli/command/repo.rb
134
+ - lib/tycli/command/repo/init.rb
135
+ - lib/tycli/command/repo/lint.rb
136
+ - lib/tycli/command/repo/push.rb
137
+ - lib/tycli/config.rb
138
+ - lib/tycli/executable.rb
139
+ - lib/tycli/git.rb
140
+ - lib/tycli/group.rb
141
+ - lib/tycli/lib.rb
142
+ - lib/tycli/repo/spec.rb
143
+ - lib/tycli/spec_repo.rb
144
+ - lib/tycli/system.rb
145
+ - lib/tycli/util/puts_util.rb
146
+ - lib/tycli/version.rb
147
+ homepage: https://docs.tuya.com/cn/
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.5.2.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: cli for tuya
171
+ test_files: []