tuya-ci-core 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc0a9c16de4cfe342233ac87bd4c7c959c44b65c
4
- data.tar.gz: 0cf27767a625642a740b9159d2e0092e15e1098e
3
+ metadata.gz: 43dcc2e3b61bd8467abab09d0f95ac9b3e2ac8f2
4
+ data.tar.gz: 81893089943726ae61c19a2276a4210a9d40cf19
5
5
  SHA512:
6
- metadata.gz: 9172a9c72fbf310f329580e55bc5786bc90bcee27c06a63263e2997dc36300491719441bb0ea0b8adac07b593fc1b99f128cae5582d814af492c38a015559838
7
- data.tar.gz: 8e063a90ebd6876355e37c3f50811efd474fd0108966c15745e4301cac4286db1501173687c8e2a80dfaaf27d3d227738e20b45fb976508bc2400e6e220a87dc
6
+ metadata.gz: ddb198c7cf62fe2a5d708bcfbc2e6b36b3c4ee54d611748d53df782223d601b09f93e5dd87838fe3b637995e1e5fe308398b1c35d47b1b864c1a0f28125a78ad
7
+ data.tar.gz: 8a859709a6e22b2edc849178c22edfaf8cabac8f98fcd8d41b41d44abfdf9c2c47d9fa77f55bbd5e745fb2235999e5cd4bb612228c69fbaa5bf3ea371f1a2585
data/bin/tuyacicore ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tuya/ci/core/command'
4
+
5
+ require 'cocoapods'
6
+ require 'colored'
7
+
8
+ TYCiCore::Command.run(ARGV)
@@ -0,0 +1,40 @@
1
+ module TYCiCore
2
+ class Command
3
+ class Lib < Command
4
+ class Create < Lib
5
+ self.abstract_command = false
6
+ self.summary = "custom module git branch create"
7
+ self.command = 'custom_branch'
8
+
9
+ def self.options
10
+ [
11
+ ['--path=target_path', '--path target path a ci local module'],
12
+ ['--tag=0.0.1', '--tag tag'],
13
+ ['--branch=new_branch', '--branch new branch'],
14
+ ['--temp=temp_path', '--temp a temp path']
15
+ ].concat(super)
16
+ end
17
+
18
+ def validate!
19
+ help! "path need" unless @path
20
+ help! "tag need" unless @tag
21
+ help! "branch need" unless @branch
22
+ help! "temp need" unless @temp
23
+ end
24
+
25
+ def initialize(argv)
26
+ super
27
+ @path = argv.option('path')
28
+ @tag = argv.option('tag')
29
+ @branch = argv.option('branch')
30
+ @temp = argv.option('temp')
31
+ end
32
+
33
+ def run
34
+ require 'tuya/ci/core'
35
+ TYGit.checkout_custom_branch(@path, @tag, @branch, @temp)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'tuya/ci/core/command/lib/create_branch'
4
+
5
+ require 'tuya/ci/core/command'
6
+
7
+ module TYCiCore
8
+ class Command
9
+ class Lib < Command
10
+
11
+ self.abstract_command = true
12
+
13
+ self.summary = 'tuya ci module'
14
+ self.command = 'lib'
15
+
16
+ self.description = "tuya ci tools"
17
+
18
+ def run
19
+ super
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
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 TYCiCore
10
+ class Command < CLAide::Command
11
+
12
+ require 'tuya/ci/core/command/lib'
13
+
14
+ self.abstract_command = true
15
+
16
+ self.description = 'welcome to tuya-cli'
17
+
18
+ self.command = 'tuyacicore'
19
+
20
+ def run
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module TYCiCore
2
+ class TYGit
3
+ def self.checkout_custom_branch(target_path, tag, new_branch, temp)
4
+
5
+ puts "Checkout custom branch: #{new_branch} base on: #{tag} path: #{target_path} workspace: #{temp}"
6
+
7
+ FileUtils.cd TYUtil::TYFile.folder_copy(target_path, temp)
8
+
9
+ TYCiCore::Git.git_tag_checkout tag
10
+
11
+ TYCiCore::Git.git_checkout_branch new_branch
12
+ end
13
+ end
14
+ end
@@ -1,30 +1,44 @@
1
- require 'tuya/ci/core'
2
-
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
3
2
  module TYCiCore
4
3
  class Git
5
4
 
5
+ def self.git_tag_checkout(tag)
6
+ EXE.exe('git', %W(checkout #{tag}), true )
7
+ end
8
+
6
9
  def self.git_tag_add_push(tag)
7
10
  git_tag_add tag
8
11
  git_tag_push tag
9
12
  end
10
13
 
11
14
  def self.git_tag_add(tag)
15
+
16
+ puts "Git tag add: #{tag}".green
17
+
12
18
  command = %W(tag -a #{tag} -m add\ tag:\ #{tag})
13
19
  EXE.exe('git', command, true )
14
20
  end
15
21
 
16
22
  def self.git_tag_push(tag)
23
+
24
+ puts "Git tag push: #{tag}".green
25
+
17
26
  command = %W(push origin #{tag})
18
27
  EXE.exe('git', command, true )
19
28
  end
20
29
 
21
30
  def self.git_tag_push_all
31
+
32
+ puts "Git tag push all".green
33
+
22
34
  command = %W(push origin --tags)
23
35
  EXE.exe('git', command, true )
24
36
  end
25
37
 
26
38
  def self.git_tag_delete!(tag, local=true, remote=true)
27
39
 
40
+ puts "Git tag: #{tag} delete".green
41
+
28
42
  commands = []
29
43
 
30
44
  commands << %W(tag tag -d #{tag}) if local
@@ -43,11 +57,14 @@ module TYCiCore
43
57
  end
44
58
 
45
59
  def self.git_push
60
+ puts "Git commit push".green
46
61
  EXE.exe('git', %W(push), true )
47
62
  end
48
63
 
49
64
  def self.git_commit_modify(message)
50
65
 
66
+ puts "Git commit modify".green
67
+
51
68
  git_status = EXE.exe("git", %W(status), true)
52
69
 
53
70
  if git_has_modify? git_status
@@ -62,6 +79,8 @@ module TYCiCore
62
79
 
63
80
  def self.git_commit_all(message)
64
81
 
82
+ puts "Git commit all".green
83
+
65
84
  git_commit_commands = [
66
85
  %W(add -A),
67
86
  %W(commit -am '#{message}')
@@ -70,6 +89,9 @@ module TYCiCore
70
89
  end
71
90
 
72
91
  def self.git_checkout_branch(branch)
92
+
93
+ puts "Git checkout branch: #{branch}".green
94
+
73
95
  branch_origin = branch
74
96
  unless branch_origin.include?("/")
75
97
  branch_origin = "origin/" + branch_origin
@@ -79,11 +101,18 @@ module TYCiCore
79
101
 
80
102
  EXE.exe('git', %W(fetch), true )
81
103
 
82
- commands = [
83
- %W(checkout #{target_branch})
84
- ]
104
+ commands = []
105
+ is_branch_exist = git_branch_exist? target_branch
85
106
 
86
- commands << %W(branch --set-upstream-to=#{branch_origin}) unless git_branch_exist? target_branch
107
+ if is_branch_exist
108
+ puts "Git checkout branch: #{branch} is exist".green
109
+ # git_clean
110
+ commands << %W(checkout #{target_branch})
111
+ else
112
+ puts "Git checkout branch: #{branch} is not exist".green
113
+ commands << %W(checkout -b #{target_branch})
114
+ commands << %W(push --set-upstream origin #{target_branch})
115
+ end
87
116
 
88
117
  commands += [
89
118
  %W(checkout .),
@@ -97,6 +126,9 @@ module TYCiCore
97
126
  end
98
127
 
99
128
 
129
+ def self.git_clean
130
+ EXE.multi_exe('git', [%W(add .), %W(reset --hard)], true)
131
+ end
100
132
 
101
133
 
102
134
  def self.git_branch_exist?(branch)
@@ -1,5 +1,10 @@
1
+ require 'tuya/ci/core/util/dir'
2
+ require 'tuya/ci/core/util/file'
3
+
1
4
  module TYCiCore
2
5
 
6
+ LIB_TYPE_CI = 1
7
+
3
8
  class Lib
4
9
 
5
10
  attr_accessor :repo
@@ -11,15 +16,20 @@ module TYCiCore
11
16
  "#{@project}.podspec"
12
17
  end
13
18
 
14
- def source
15
- puts "Job: #{@project} version: #{@version} on :#{@branch} repo: #{@repo}"
16
- _source
19
+ def create(type, target_path, tag, new_branch, temp)
20
+
21
+ end
22
+
23
+ def source(type)
24
+
25
+ puts "Job: #{@project} version: #{@version} on :#{@branch} repo: #{@repo}".green
26
+ build_source
17
27
  end
18
28
 
19
29
 
20
30
  private
21
31
 
22
- def _source
32
+ def build_source
23
33
 
24
34
  Git.git_checkout_branch branch
25
35
 
@@ -31,10 +41,10 @@ module TYCiCore
31
41
 
32
42
  Git.git_commit_modify "feat: CI add version to #{@version}"
33
43
  Git.git_push
44
+
34
45
  end
35
46
 
36
47
  Git.git_tag_delete! @version if Git.git_tag_exist?(@version, true )
37
-
38
48
  Git.git_tag_add_push @version
39
49
 
40
50
  TYRepo::RepoTuya.new('./*.podspec').push
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ module TYCiCore
4
+ class LibTuya < Lib
5
+ def initialize(branch, project, version)
6
+ @repo = 'TYSpecs'
7
+ @branch = branch
8
+ @project = project
9
+ @version = version
10
+ end
11
+
12
+ def create(type, target_path, tag, new_branch, temp)
13
+
14
+
15
+ end
16
+
17
+ def source(type)
18
+
19
+ TYUtil::Dir.dir_ensure_fastlane
20
+
21
+ super type
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,137 @@
1
+ require 'colored'
2
+ require 'json'
3
+
4
+ module TYCiCore
5
+
6
+ # Podfile
7
+ #
8
+ # 关于工程多target约定
9
+ #
10
+ # 1. 多target的Project 取第一个作为主target
11
+ # 2. 修改删除将应用到全部target
12
+ # 3. 对于普通的Project 新增组件将只应用到第一个target
13
+ # 4. 对Pod有封装的target 方法名约定为 pod_install, 新增组件将只应用到该方法
14
+ #
15
+ class Podfile
16
+
17
+ PODFILE_TARGET_METHOD = 'pod_install'
18
+
19
+ attr_accessor :file
20
+ attr_accessor :content
21
+ attr_accessor :multi_target
22
+ attr_accessor :targets
23
+ attr_accessor :main_target
24
+
25
+ def initialize(file='./Podfile')
26
+
27
+ @file = file
28
+
29
+ puts 'Can not find a Podfile'.red unless File.exist? @file
30
+
31
+ @content = File.read @file
32
+ @multi_target = is_multi_target
33
+ @targets = targets
34
+ @main_target = @targets[0][0] if (@targets.size > 0 && @targets[0].size > 0)
35
+
36
+ end
37
+
38
+ def source_replace(replace_old, replace_new)
39
+ @content.gsub!(/#{replace_old}/, replace_new)
40
+ end
41
+
42
+ def update(updates, deletes)
43
+
44
+ puts "Podfile must contain at least one target".red unless @main_target
45
+
46
+ if @multi_target
47
+ update_pod_methods(updates, deletes)
48
+ else
49
+ update_single_target(updates, deletes)
50
+ end
51
+ end
52
+
53
+ def save
54
+
55
+ puts "Podspec: #{@file} saved".green
56
+
57
+ fh = File.new(@file, "w")
58
+ fh.puts @content
59
+ fh.close
60
+ end
61
+
62
+ private
63
+
64
+ def update_pod_methods(updates, deletes)
65
+ update_pods(updates, deletes, "def #{PODFILE_TARGET_METHOD}")
66
+ end
67
+
68
+ def update_single_target(updates, deletes)
69
+ update_pods(updates, deletes, "target '#{@main_target}' do")
70
+ end
71
+
72
+ def update_pods(updates, deletes, mark_label)
73
+
74
+ append_modules = "#{mark_label}\n"
75
+ append_modules = update_update_pods(updates, append_modules) if updates && updates.size > 0
76
+
77
+ # deletes.each do |delete|
78
+ # json = JSON.parse(JSON(delete))
79
+ # name = json["name"]
80
+ # @content.gsub!(/\s*pod\s*'#{name}(.*)'$/, "")
81
+ # end
82
+
83
+ update_delete_pods deletes if deletes && deletes.size > 0
84
+
85
+ @content.gsub!(/^#{mark_label}/, "#{append_modules}\n")
86
+ @content.gsub!(/\n{2,}/, "\n")
87
+ end
88
+
89
+ def update_delete_pods(deletes)
90
+ deletes.each do |delete|
91
+ json = JSON.parse(JSON(delete))
92
+ name = json["name"]
93
+ @content.gsub!(/\s*pod\s*'#{name}(.*)'$/, "")
94
+ end
95
+
96
+ end
97
+
98
+ def update_update_pods(updates, append_modules)
99
+ updates.each do |update|
100
+
101
+ json = JSON.parse(JSON(update))
102
+ name = json["name"]
103
+ version = json["version"]
104
+
105
+ module_replace = "\n pod '#{name}', '#{version}'"
106
+ if @content.scan(/^[^#]\s*pod\s*'#{name}'(.*)'$/).size == 0
107
+ puts "Module #{name} can not find".yellow
108
+ append_modules << module_replace
109
+ else
110
+ puts "Module #{name} got it".green
111
+ if debug? name
112
+ puts "Module #{name} find debug parameter".green
113
+ module_replace = "#{module_replace}, :configuration => 'Debug'"
114
+ else
115
+ puts "Module #{name} did not find debug".yellow
116
+ end
117
+ @content.gsub!(/^[^#]\s*pod\s*'#{name}'(.*)'$/, module_replace)
118
+ end
119
+ end
120
+ append_modules
121
+ end
122
+
123
+ def targets
124
+ @content.scan(/target '(\w+)' do/)
125
+ end
126
+
127
+ def debug?(name)
128
+ @content.scan(/^[^#]\s*pod\s*'#{name}',(.*,)*\s*:configuration\s*=>\s*'Debug'/).size > 0
129
+ end
130
+
131
+ def is_multi_target
132
+ @content.include? PODFILE_TARGET_METHOD
133
+ end
134
+
135
+ end
136
+
137
+ end
@@ -1,3 +1,6 @@
1
+ require 'tuya/ci/core/util/dir'
2
+ require 'tuya/ci/core/util/file'
3
+
1
4
  module TYCiCore
2
5
  class PodSpec
3
6
 
@@ -6,14 +9,19 @@ module TYCiCore
6
9
 
7
10
  def initialize(podspec)
8
11
 
12
+ puts "Tuya podspec is #{podspec}".green
13
+
9
14
  raise 'podspec cannot be nil' unless podspec
10
15
 
11
- @file = TYUtil::File.podspec_files(podspec)[0]
16
+ @file = TYUtil::TYFile.podspec_files(podspec)[0]
12
17
  @content = File.read(@file)
13
18
 
14
19
  end
15
20
 
16
21
  def update(key, value)
22
+
23
+ puts "Podspec: #{@file} update key: #{key} value: #{value}".green
24
+
17
25
  res = @content.scan(/.#{key}\s*=\s*'#{value}'/)
18
26
  need_update = res.size == 0
19
27
  if need_update
@@ -23,10 +31,14 @@ module TYCiCore
23
31
  end
24
32
 
25
33
  def save
34
+
35
+ puts "Podspec: #{@file} saved".green
36
+
26
37
  fh = File.new(@file, "w")
27
38
  fh.puts @content
28
39
  fh.close
29
40
  end
30
41
 
31
42
  end
43
+
32
44
  end
@@ -26,6 +26,9 @@ module TYRepo
26
26
  end
27
27
 
28
28
  def push
29
+
30
+ puts "Repo push: #{command}".green
31
+
29
32
  `#{command}`
30
33
  end
31
34
 
@@ -0,0 +1,105 @@
1
+ module TYCiCore
2
+ TEMPLATE_CONFIG = '.tuya_project_template'
3
+ URL = 'https://github.com/TuyaInc/TYProjectTemplate.git'
4
+ class TemplateConfigurator
5
+
6
+ attr_accessor :xcodeproj_path, :platform, :remove_demo_project
7
+ attr_accessor :pod_name, :type, :prefix, :pod_spec, :podfile_path
8
+ attr_accessor :date, :year, :owner_email, :owner_name
9
+ attr_accessor :group
10
+ attr_accessor :config
11
+
12
+ def initialize(name, config, prefix, group)
13
+
14
+ @pod_name = name
15
+ @pod_spec = "#{name}.podspec"
16
+ @podfile_path = "Example/Podfile"
17
+ @prefix = prefix
18
+
19
+ @group = group
20
+
21
+ @xcodeproj_path = "#{@pod_name}/Example/PROJECT.xcodeproj"
22
+ @platform = 'ios'
23
+ @remove_demo_project = false
24
+
25
+ @date = date
26
+ @year = year
27
+ @owner_email = user_email
28
+ @owner_name = user_name
29
+
30
+ @config = config
31
+ end
32
+
33
+ def self.load_config(folder)
34
+
35
+ path = "#{folder}/#{TYCiCore::TEMPLATE_CONFIG}"
36
+
37
+ raise 'Can not find config file, pls ask tuya' unless File.exist? path
38
+
39
+ content = File.read path
40
+
41
+ json = JSON(content)
42
+
43
+ TemplateConfig.new json
44
+ end
45
+
46
+ def user_email
47
+ (ENV['GIT_COMMITTER_EMAIL'] || `git config user.email`).strip
48
+ end
49
+
50
+ def user_name
51
+ (ENV['GIT_COMMITTER_NAME'] || github_user_name || `git config user.name` || `<GITHUB_USERNAME>` ).strip
52
+ end
53
+
54
+ def github_user_name
55
+ github_user_name = `security find-internet-password -s github.com | grep acct | sed 's/"acct"<blob>="//g' | sed 's/"//g'`.strip
56
+ is_valid = github_user_name.empty? or github_user_name.include? '@'
57
+ return is_valid ? nil : github_user_name
58
+ end
59
+
60
+ def year
61
+ Time.now.year.to_s
62
+ end
63
+
64
+ def date
65
+ Time.now.strftime "%m/%d/%Y"
66
+ end
67
+
68
+ end
69
+
70
+ class TemplateConfig
71
+
72
+ attr_accessor :json
73
+ attr_accessor :keys
74
+ attr_accessor :type, :alias, :project
75
+
76
+ def initialize(json)
77
+ @project = 'PROJECT'
78
+ @json = json
79
+ @keys = []
80
+ @type = ""
81
+ @alias = ""
82
+ @desc = ""
83
+ end
84
+
85
+ def log_all
86
+
87
+ puts "Here is the module type list".magenta.underline
88
+
89
+ @json.each do |item|
90
+ puts "#{item['type']} : #{item['desc']}".green
91
+ @keys.push item['type']
92
+ end
93
+ end
94
+
95
+ def setup(type)
96
+ @json.each do |item|
97
+ if type == item['type'].downcase
98
+ @type = type
99
+ @alias = item['alias']
100
+ @desc = item['desc']
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,100 @@
1
+ require 'xcodeproj'
2
+
3
+ module TYCiCore
4
+
5
+ class TemplateProject
6
+
7
+ attr_reader :xcodeproj_path, :platform, :remove_demo_target, :string_replacements, :prefix
8
+
9
+ def initialize(configurator)
10
+ @configurator = configurator
11
+ @xcodeproj_path = configurator.xcodeproj_path
12
+ @platform = configurator.platform
13
+ @remove_demo_target = configurator.remove_demo_project
14
+ @prefix = configurator.prefix
15
+ end
16
+
17
+ def run
18
+ @string_replacements = {
19
+ "PROJECT_OWNER" => @configurator.owner_email,
20
+ "PROJECT" => @configurator.pod_name,
21
+ "CPD" => @configurator.prefix
22
+ }
23
+
24
+ replace_internal_project_settings
25
+
26
+ @project = Xcodeproj::Project.open(@xcodeproj_path)
27
+ @project.save
28
+
29
+ rename_files
30
+ rename_project_folder
31
+ end
32
+
33
+ def project_folder
34
+ File.dirname @xcodeproj_path
35
+ end
36
+
37
+ def rename_files
38
+ # shared schemes have project specific names
39
+ scheme_path = project_folder + "/PROJECT.xcodeproj/xcshareddata/xcschemes/"
40
+ File.rename(scheme_path + "PROJECT.xcscheme", scheme_path + @configurator.pod_name + "-Example.xcscheme")
41
+
42
+ # rename xcproject
43
+ File.rename(project_folder + "/PROJECT.xcodeproj", project_folder + "/" + @configurator.pod_name + ".xcodeproj")
44
+
45
+ unless @remove_demo_target
46
+ # change app file prefixes
47
+ ["CPDAppDelegate.h", "CPDAppDelegate.m", "CPDViewController.h", "CPDViewController.m"].each do |file|
48
+ before = project_folder + "/PROJECT/" + file
49
+ next unless File.exists? before
50
+
51
+ after = project_folder + "/PROJECT/" + file.gsub("CPD", prefix)
52
+ File.rename before, after
53
+ end
54
+
55
+ # add module impl
56
+ ["PROJECTImpl.h", "PROJECTImpl.m"].each do |file|
57
+ before = "#{@configurator.pod_name}/PROJECT/Classes/" + file
58
+
59
+ next unless File.exists? before
60
+
61
+ after = "#{@configurator.pod_name}/PROJECT/Classes/" + file.gsub("PROJECT", @configurator.pod_name)
62
+ File.rename before, after
63
+ end
64
+
65
+ # rename project related files
66
+ ["PROJECT-Info.plist", "PROJECT-Prefix.pch", "PROJECT.entitlements"].each do |file|
67
+ before = project_folder + "/PROJECT/" + file
68
+ next unless File.exists? before
69
+
70
+ after = project_folder + "/PROJECT/" + file.gsub("PROJECT", @configurator.pod_name)
71
+ File.rename before, after
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ def rename_project_folder
78
+ if Dir.exist? project_folder + "/PROJECT"
79
+ File.rename(project_folder + "/PROJECT", project_folder + "/" + @configurator.pod_name)
80
+ end
81
+ end
82
+
83
+ def replace_internal_project_settings
84
+
85
+ all_dir = Dir.glob(project_folder + "/**/**/**/**")# + Dir.glob("#{@configurator.pod_name}/**/**/**/**")
86
+
87
+ all_dir.each do |name|
88
+ next if Dir.exists? name
89
+ text = File.read(name)
90
+ for find, replace in @string_replacements
91
+ text = text.gsub(find, replace)
92
+ end
93
+
94
+ File.open(name, "w") { |file| file.puts text }
95
+ end
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,141 @@
1
+ module TYCiCore
2
+ class TYTemplate
3
+
4
+ TARGET_PROJECT = 'TYProjectTemplate'
5
+
6
+ attr_accessor :configurator
7
+
8
+ def initialize(group)
9
+
10
+ download_template
11
+
12
+ config = TemplateConfigurator.load_config TARGET_PROJECT
13
+ config.log_all
14
+
15
+ type = TYAsk.ask_with_answers('Please tell me which module will be create', config.keys)
16
+ puts "\n"
17
+ config.setup type
18
+
19
+ name = TYAsk.ask'Please enter your module name'
20
+ prefix = TYAsk.ask 'Please enter your Prefix'
21
+
22
+ @configurator = TemplateConfigurator.new(name, config, prefix, group)
23
+ @template_project = nil
24
+ end
25
+
26
+ def create
27
+ if adjust_download_files
28
+ template_project
29
+ FileUtils.cd "#{@configurator.pod_name}"
30
+ add_license
31
+ rename_files
32
+ replace_files
33
+
34
+ FileUtils.cd "Example"
35
+ # `pod update --no-repo-update`
36
+ `pod update`
37
+ `open #{@configurator.pod_name}.xcworkspace`
38
+ FileUtils.cd ".."
39
+ FileUtils.cd ".."
40
+ end
41
+ end
42
+
43
+ def template_project
44
+ @template_project = TemplateProject.new(@configurator)
45
+ @template_project.run
46
+ end
47
+
48
+ def adjust_download_files
49
+
50
+ result = File.exist? @configurator.pod_name
51
+
52
+ if result
53
+ puts "Folder #{@configurator.pod_name} is exists".red
54
+ `rm -rf #{TARGET_PROJECT}`
55
+ else
56
+ `mkdir #{@configurator.pod_name}`
57
+ `cp -a ./#{TARGET_PROJECT}/#{@configurator.config.alias}/ #{@configurator.pod_name}`
58
+ `cp ./#{TARGET_PROJECT}/#{TYCiCore::TEMPLATE_CONFIG} #{@configurator.pod_name}/#{TYCiCore::TEMPLATE_CONFIG}`
59
+ `rm -rf #{TARGET_PROJECT}`
60
+
61
+ end
62
+
63
+ !result
64
+ end
65
+
66
+ def download_template
67
+ # `rm -rf #{@configurator.pod_name}` if File.exist? "./#{@configurator.pod_name}"
68
+ url = TYCiCore::URL
69
+ # EXE.exe('git', %W(clone -b develop #{url}))
70
+ EXE.exe('git', %W(clone #{url}))
71
+ end
72
+
73
+ def add_license
74
+ `touch LICENSE`
75
+ if File.exist? 'LICENSE'
76
+ File.open('LICENSE', 'w') do |file|
77
+ file.puts "Copyright (c) ${YEAR} ${USER_NAME} <${USER_EMAIL}>
78
+
79
+ Permission is hereby granted, free of charge, to any person obtaining a copy
80
+ of this software and associated documentation files (the \"Software\"), to deal
81
+ in the Software without restriction, including without limitation the rights
82
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
83
+ copies of the Software, and to permit persons to whom the Software is
84
+ furnished to do so, subject to the following conditions:
85
+
86
+ The above copyright notice and this permission notice shall be included in
87
+ all copies or substantial portions of the Software.
88
+
89
+ THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
91
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
92
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
93
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
94
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
95
+ THE SOFTWARE."
96
+ file.close
97
+ end
98
+ end
99
+ end
100
+
101
+ def rename_files
102
+ FileUtils.mv @configurator.config.project, @configurator.pod_name
103
+ FileUtils.mv "#{@configurator.config.project}.podspec", "#{@configurator.pod_name}.podspec"
104
+ end
105
+
106
+ def replace_files
107
+ file_names = Dir.glob("**/**/**/**/**")
108
+
109
+ file_names.each do |name|
110
+ next if Dir.exists? name
111
+ text = File.read(name)
112
+ for find, replace in @template_project.string_replacements
113
+ text = text.gsub(find, replace)
114
+ end
115
+ text = replace_content! text
116
+ File.open(name, "w") { |file| file.puts text }
117
+ end
118
+
119
+ end
120
+
121
+ def replace_content!(text)
122
+
123
+ if !text.valid_encoding?
124
+ text = text.encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8')
125
+ end
126
+
127
+ text.gsub!(/#{@configurator.config.project}/, @configurator.pod_name)
128
+ text.gsub!("${POD_NAME}", @configurator.pod_name)
129
+ text.gsub!("${REPO_NAME}", @configurator.pod_name.gsub('+', '-'))
130
+ text.gsub!("${USER_EMAIL}", @configurator.owner_email)
131
+ text.gsub!("${USER_NAME}", @configurator.owner_name)
132
+ text.gsub!(/\${TODAYS_YEAR}/, @configurator.year)
133
+ text.gsub!("${YEAR}", @configurator.year)
134
+ text.gsub!(/\${TODAYS_DATE}/, @configurator.date)
135
+ text.gsub!("${DATE}", @configurator.date)
136
+ text.gsub!("${GROUP_NAME}", @configurator.group)
137
+ text
138
+ end
139
+
140
+ end
141
+ end
@@ -0,0 +1,60 @@
1
+ module TYCiCore
2
+ class TYAsk
3
+
4
+ def self.ask(question)
5
+ answer = ""
6
+ loop do
7
+ puts "\n#{question}?"
8
+
9
+ # @message_bank.show_prompt
10
+ print ">".green
11
+ answer = STDIN.gets.chomp
12
+
13
+ break if answer.length > 0
14
+
15
+ print "\nYou need to provide an answer."
16
+ end
17
+ answer
18
+ end
19
+
20
+ def self.ask_with_answers(question, possible_answers)
21
+
22
+ print "\n#{question}? ["
23
+
24
+ print_info = Proc.new {
25
+
26
+ possible_answers_string = possible_answers.each_with_index do |answer, i|
27
+ _answer = (i == 0) ? answer.underline : answer
28
+ print " " + _answer
29
+ print(" /") if i != possible_answers.length-1
30
+ end
31
+ print " ]\n"
32
+ }
33
+ print_info.call
34
+
35
+ answer = ""
36
+
37
+ loop do
38
+ # @message_bank.show_prompt
39
+ print ">".green
40
+ answer = STDIN.gets.downcase.chomp
41
+
42
+ answer = "yes" if answer == "y"
43
+ answer = "no" if answer == "n"
44
+
45
+ # default to first answer
46
+ if answer == ""
47
+ answer = possible_answers[0].downcase
48
+ print answer.yellow
49
+ end
50
+
51
+ break if possible_answers.map { |a| a.downcase }.include? answer
52
+
53
+ print "\nPossible answers are ["
54
+ print_info.call
55
+ end
56
+
57
+ answer
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,20 @@
1
+ module TYUtil
2
+ class Dir
3
+ def self.dir_ensure(path)
4
+ dir = FileUtils.pwd
5
+
6
+ puts "Original dir is #{FileUtils.pwd}".green
7
+
8
+ dir.gsub!(/\/#{path}/, '')
9
+
10
+ FileUtils.cd dir
11
+
12
+ puts "Current dir is #{FileUtils.pwd}".green
13
+
14
+ end
15
+
16
+ def self.dir_ensure_fastlane
17
+ dir_ensure 'fastlane'
18
+ end
19
+ end
20
+ end
@@ -1,9 +1,26 @@
1
1
  module TYUtil
2
- class File
2
+ class TYFile
3
3
  def self.read(filepath)
4
4
 
5
5
  end
6
6
 
7
+ def self.folder_copy(from, to, is_need_delete=true )
8
+
9
+ target = to + '/' << from.split('/')[-1]
10
+
11
+ if is_need_delete
12
+ TYCiCore::EXE.exe('rm', %W(-rf #{to})) if File.exist? target
13
+ else
14
+ raise 'File to copy at is exist.'
15
+ end
16
+
17
+ TYCiCore::EXE.exe('mkdir', %W(-p #{to}))
18
+
19
+ TYCiCore::EXE.exe('cp', %W(-a #{from} #{to}))
20
+
21
+ target
22
+ end
23
+
7
24
  def self.podspec_files(podspec)
8
25
  if podspec
9
26
  path = Pathname(podspec)
@@ -1,7 +1,7 @@
1
1
  module Tuya
2
2
  module Ci
3
3
  module Core
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
data/lib/tuya/ci/core.rb CHANGED
@@ -3,8 +3,25 @@ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
3
3
  require "tuya/ci/core/version"
4
4
 
5
5
  module TYCiCore
6
+
7
+ require 'colored'
8
+
9
+ require 'fileutils'
10
+
11
+ require 'tuya/ci/core/util/file'
12
+ require 'tuya/ci/core/util/dir'
13
+ require 'tuya/ci/core/util/ask'
14
+
6
15
  require 'tuya/ci/core/spec/ty_repo'
7
16
  require 'tuya/ci/core/git'
17
+ require 'tuya/ci/core/git/git_tuya_ci'
8
18
  require 'tuya/ci/core/executable'
9
- require 'tuya/ci/core/lib/lib_tuya'
19
+ require 'tuya/ci/core/lib/lib'
20
+ require 'tuya/ci/core/lib/lib_tuya_ci'
21
+ require 'tuya/ci/core/podspec'
22
+ require 'tuya/ci/core/podfile'
23
+
24
+ require 'tuya/ci/core/template'
25
+ require 'tuya/ci/core/template/template_configurator'
26
+ require 'tuya/ci/core/template/template_project'
10
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuya-ci-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fangdong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-29 00:00:00.000000000 Z
11
+ date: 2018-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,19 +97,31 @@ dependencies:
97
97
  description: tuya cli core
98
98
  email:
99
99
  - fangdong@tuyasmart.com
100
- executables: []
100
+ executables:
101
+ - tuyacicore
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
104
105
  - LICENSE.txt
105
106
  - README.md
107
+ - bin/tuyacicore
106
108
  - lib/tuya/ci/core.rb
109
+ - lib/tuya/ci/core/command.rb
110
+ - lib/tuya/ci/core/command/lib.rb
111
+ - lib/tuya/ci/core/command/lib/create_branch.rb
107
112
  - lib/tuya/ci/core/executable.rb
108
113
  - lib/tuya/ci/core/git.rb
114
+ - lib/tuya/ci/core/git/git_tuya_ci.rb
109
115
  - lib/tuya/ci/core/lib/lib.rb
110
- - lib/tuya/ci/core/lib/lib_tuya.rb
116
+ - lib/tuya/ci/core/lib/lib_tuya_ci.rb
117
+ - lib/tuya/ci/core/podfile.rb
111
118
  - lib/tuya/ci/core/podspec.rb
112
119
  - lib/tuya/ci/core/spec/ty_repo.rb
120
+ - lib/tuya/ci/core/template.rb
121
+ - lib/tuya/ci/core/template/template_configurator.rb
122
+ - lib/tuya/ci/core/template/template_project.rb
123
+ - lib/tuya/ci/core/util/ask.rb
124
+ - lib/tuya/ci/core/util/dir.rb
113
125
  - lib/tuya/ci/core/util/file.rb
114
126
  - lib/tuya/ci/core/version.rb
115
127
  homepage: https://docs.tuya.com/cn/
@@ -1,16 +0,0 @@
1
- require 'tuya/ci/core/lib/lib'
2
-
3
- module TYCiCore
4
- class LibTuya < Lib
5
- def initialize(branch, project, version)
6
- @repo = 'TYSpecs'
7
- @branch = branch
8
- @project = project
9
- @version = version
10
- end
11
-
12
- def source
13
- super
14
- end
15
- end
16
- end