gct 0.3.2 → 0.3.7

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
  SHA256:
3
- metadata.gz: a648ad54002c10e7bca827874e2337664c37dc5a8ead58a1cdd8812e3440ba22
4
- data.tar.gz: 001e5c7c782b750bb32ac0ad18c2510d0f6f1792d8ceb6bd53463cf1b5e2692f
3
+ metadata.gz: 9918181f11fe9f5b6bcfbce81bccd2968f62d3ff6818b14a89697477c4708bf6
4
+ data.tar.gz: cec3e19ab6d35eec9b0be4381ccbdcae73476b18406e41ea990b624899720ffd
5
5
  SHA512:
6
- metadata.gz: 265ee8a53c3682419d8be2e9a223e44d70cbd3a314cc10e8db270566f2389bb2f0adc7c879c53984d5fce867130b8ac0e4586417f8b44f6f93660c216867590d
7
- data.tar.gz: 8c0e81952eeb1d9807598c4bfd3afe67d0a252c7739065130d60d67c56eb67aafeab91c872f81890222d034c40240dc53f87880da4a47166a764a80f253601c5
6
+ metadata.gz: ec151c785207033293bad1b7381328919fbf78f5f80bb7fbe24dbb093d743549aedb797d2447dfb46b5135f97a90e112a9a1e719733dfc5a7641896447c26541
7
+ data.tar.gz: 1d0427577f8d39417823890a81e0911e28dfbd7570f76d5ef1a49f5470f1a385d1383447f9102fbbbb6a877827e9aeca4b287a5ebb28e5b109a9919d5700a1c7
data/lib/gct.rb CHANGED
@@ -1,7 +1,16 @@
1
1
 
2
2
  module Gct
3
- require "gct/version"
3
+ require "gct/gct_version"
4
4
  require "gct/constant"
5
- autoload :Command, 'gct/command'
5
+ require "gct/specification"
6
+ require "gct/temp_local_file"
7
+ require "gct/temp_remote_file"
8
+ require "gct/file_base"
9
+
10
+ autoload :Command, 'gct/command'
11
+
12
+ module Generator
13
+ require "gct/generator/gct_file"
14
+ end
6
15
 
7
16
  end
@@ -2,6 +2,7 @@ require 'colored2'
2
2
  require 'claide'
3
3
  require 'molinillo/errors'
4
4
  require 'xcodeproj'
5
+ require 'gitlab'
5
6
 
6
7
  module Molinillo
7
8
  class ResolverError
@@ -17,13 +18,14 @@ module Gct
17
18
  class Command < CLAide::Command
18
19
  require 'gct/command/create'
19
20
  require 'gct/command/init'
20
- # require 'gct/command/config'
21
- require 'gct/command/analyze'
21
+ require 'gct/command/config'
22
+ # require 'gct/command/analyze'
22
23
  require 'gct/command/op'
23
24
  require 'gct/command/build'
24
25
  require 'gct/command/spec'
25
26
  require 'gct/command/repo'
26
- require 'gct/command/tag'
27
+ require 'gct/command/setup'
28
+ require 'gct/command/update'
27
29
 
28
30
  self.abstract_command = true
29
31
  self.command = 'gct'
@@ -49,5 +51,56 @@ module Gct
49
51
  String.send(:define_method, :colorize) { |string, _| string }
50
52
  end
51
53
  end
54
+
55
+ def file_contents(project_id, file, branch)
56
+ file_contents ||= Gitlab.file_contents(project_id, file, branch)
57
+ rescue Gitlab::Error::NotFound => error
58
+ raise error.message
59
+ end
60
+
61
+ def config_gitlab
62
+ if FileBase.exist_root
63
+ token = FileBase.get_config("token")
64
+ if token
65
+ raise "请先配置token!gct config set token GITLAB_PERSON_TOKEN".red if token.nil?
66
+ Gitlab.configure do |config|
67
+ config.endpoint = 'https://gi-dev.ccrgt.com/api/v4'
68
+ config.private_token = token
69
+ end
70
+ else
71
+ raise "请先运行命令:gct config set token GITLAB_TOKEN,参考文档:http://febase.crgt.xyz/docs/app_ios/base".red
72
+ end
73
+ end
74
+ end
75
+
76
+ def get_project
77
+ proj = nil
78
+ Dir.entries(Dir.pwd).each do |subfile|
79
+ if subfile.include? '.xcodeproj'
80
+ proj = subfile
81
+ end
82
+ end
83
+ if proj.nil?
84
+ puts '没有找到.xcodeproj文件'.red if proj.nil?
85
+ nil
86
+ else
87
+ project_path = File.join(Dir.pwd, "./" + proj)
88
+ project = Xcodeproj::Project.open(project_path)
89
+ project
90
+ end
91
+ end
92
+
93
+ def auto_add_tag(tag)
94
+ tag_points = tag.to_s.split('.')
95
+ index = tag_points.length - 1
96
+ need_add_point = tag_points[index].to_i + 1
97
+ tag_points[index] = need_add_point == 10 ? 0 : need_add_point
98
+ while need_add_point == 10 && index > 0
99
+ index = index - 1
100
+ need_add_point = tag_points[index].to_i + 1
101
+ tag_points[index] = need_add_point == 10 && index != 0 ? 0 : need_add_point
102
+ end
103
+ tag_points.join('.')
104
+ end
52
105
  end
53
106
  end
@@ -1,5 +1,6 @@
1
1
  require 'pathname'
2
2
  require 'tmpdir'
3
+ require 'parallel'
3
4
 
4
5
  module Gct
5
6
  class Command
@@ -9,7 +10,17 @@ module Gct
9
10
  分析podfile完整依赖链,并输出json文件.
10
11
  DESC
11
12
 
13
+ self.arguments = [
14
+ CLAide::Argument.new('PROJECT_ID', true),
15
+ CLAide::Argument.new('FILE', true),
16
+ CLAide::Argument.new('BRANCH', true),
17
+ ]
18
+
12
19
  def initialize(argv)
20
+ @project_id = argv.shift_argument
21
+ @file = argv.shift_argument
22
+ @branch = argv.shift_argument
23
+ config_gitlab
13
24
  super
14
25
  end
15
26
 
@@ -19,11 +30,98 @@ module Gct
19
30
  end
20
31
 
21
32
  def validate!
33
+ help! '必须输入项目名.' unless @project_id
34
+ help! '必须输入读取文件的相对路径.' unless @file
35
+ help! '必须输入读取文件的项目分支.' unless @branch
22
36
  super
23
37
  end
24
38
 
25
39
  def run
26
- system "pod dep"
40
+ analyze_dependencies
41
+ # update_podspec_version()
42
+ end
43
+
44
+ def podfile
45
+ contents = file_contents(@project_id, @file, @branch)
46
+ contents.force_encoding('UTF-8')
47
+
48
+ temp_local_file = TempLocalFile.new(contents, @file)
49
+ temp_local_file.write
50
+ full_path = temp_local_file.full_path
51
+
52
+ @podfile ||= begin
53
+ podfile = Pod::Podfile.from_ruby(full_path, contents)
54
+ podfile
55
+ end
56
+ end
57
+
58
+ def analyze_dependencies
59
+ untagged_git_dependencies = podfile.dependencies.select { |dependency| dependency.external? && dependency.external_source[:tag].nil? && dependency.external_source[:branch] == Constant.DefaultTagBranch}
60
+ puts untagged_git_dependencies
61
+ # untagged_specs = Parallel.map(untagged_git_dependencies, in_threads: 1) do |dep|
62
+ # require 'json'
63
+ # puts "#{Constant.NameSpace}#{dep.name}"
64
+ # puts "#{dep.name}.podspec"
65
+ # puts Constant.DefaultTagBranch
66
+
67
+ # contents_json = file_contents("#{Constant.NameSpace}#{dep.name}", "#{dep.name}.podspec", Constant.DefaultTagBranch)
68
+ # podspec = system contents_json
69
+ # puts podspec.class
70
+ # puts podspec
71
+ # podspec = from_string("", contents_json)
72
+ # podspec = Pod::Spec.new do |spec|
73
+
74
+ # end
75
+
76
+
77
+ # puts podspec.class.to_s
78
+ # puts podspec.to_s
79
+ # gct_spec = Specification.new()
80
+ # gct_spec.specification = podspec
81
+ # gct_spec.priority = 1000
82
+ # gct_spec.status = SpecPublishStatus::CREATED
83
+ # gct_spec.tag = "0"
84
+
85
+ # update_podspec_version(spec)
86
+ # gct_spec
87
+ # end
88
+ end
89
+
90
+ def update_podspec_version(spec)
91
+ content = file_contents("#{Constant.NameSpace}#{dep.name}", "#{spec.name}.podspec", Constant.DefaultTagBranch)
92
+ now_version = spec.version
93
+ version = auto_add_tag(now_version)
94
+ require_variable_prefix = true
95
+ version_var_name = 'version'
96
+ variable_prefix = require_variable_prefix ? /\w\./ : //
97
+ version_regex = /^(?<begin>[^#]*#{variable_prefix}#{version_var_name}\s*=\s*['"])(?<value>(?<major>[0-9]+)(\.(?<minor>[0-9]+))?(\.(?<patch>[0-9]+))?(?<appendix>(\.[0-9]+)*)?(-(?<prerelease>(.+)))?)(?<end>['"])/i
98
+ version_match = version_regex.match(content)
99
+ updated_podspec_content = content.gsub(version_regex, "#{version_match[:begin]}#{version}#{version_match[:end]}")
100
+ updated_podspec_content
101
+
102
+ edit_file(spec, updated_podspec_content, version)
103
+ mr_to_master(spec)
104
+ end
105
+
106
+
107
+
108
+ def edit_file(spec, content, version)
109
+ Gitlab.edit_file("#{Constant.NameSpace}#{dep.name}", "#{spec.name}.podspec", Constant.DefaultTagBranch, content, "@config 升级版本号:#{version}")
110
+ end
111
+
112
+ def mr_to_master(spec)
113
+ mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{dep.name}", "podpesc修改", { source_branch: 'develop', target_branch: 'master' })
114
+ id = mr.iid
115
+ puts mr.to_hash
116
+ if mr.merge_status == 'cannot_be_merged'
117
+ raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{spec.name}/merge_requests/#{id} 解决".red
118
+ end
119
+
120
+ accept_merge_request(spec, id)
121
+ end
122
+
123
+ def accept_merge_request(spec, id)
124
+ Gitlab.accept_merge_request("#{Constant.NameSpace}#{dep.name}", id)
27
125
  end
28
126
  end
29
127
  end
@@ -24,19 +24,8 @@ module Gct
24
24
 
25
25
  def buildR
26
26
  puts "starting search R script ...".green
27
- proj = ''
28
- Dir.entries(Dir.pwd).each do |subfile|
29
- if subfile.include? '.xcodeproj'
30
- proj = subfile
31
- end
32
- end
33
-
34
- if proj == ''
35
- puts '没有找到.xcodeproj文件'.red
36
- else
37
- project_path = File.join(Dir.pwd, "./" + proj)
38
- project = Xcodeproj::Project.open(project_path)
39
-
27
+ project = get_project
28
+ if project
40
29
  objects = project.objects
41
30
  findR = false
42
31
  objects.each do |obj|
@@ -9,6 +9,7 @@ module Gct
9
9
  self.description = <<-DESC
10
10
  配置全局链接等
11
11
  DESC
12
+
12
13
  end
13
14
  end
14
15
  end
@@ -9,25 +9,21 @@ module Gct
9
9
  DESC
10
10
 
11
11
  self.arguments = [
12
- CLAide::Argument.new('NAME', true),
12
+ CLAide::Argument.new('KEY', true),
13
13
  ]
14
14
 
15
15
  def initialize(argv)
16
- @name = argv.shift_argument
16
+ @key = argv.shift_argument
17
17
  super
18
- @additional_args = argv.remainder!
19
18
  end
20
19
 
21
20
  def validate!
22
21
  super
23
- help! 'A name for the Pod is required.' unless @name
24
- help! 'The Pod name cannot contain spaces.' if @name =~ /\s/
25
- help! 'The Pod name cannot contain plusses.' if @name =~ /\+/
26
- help! "The Pod name cannot begin with a '.'" if @name[0, 1] == '.'
22
+ help! '请输入key.' unless @key
27
23
  end
28
24
 
29
25
  def run
30
- puts "获取全局配置成功".green
26
+ puts "#{FileBase.get_config(@key)}"
31
27
  end
32
28
  end
33
29
  end
@@ -8,26 +8,25 @@ module Gct
8
8
  设置gct全局配置.
9
9
  DESC
10
10
 
11
- # self.arguments = [
12
- # CLAide::Argument.new('NAME', true),
13
- # ]
11
+ self.arguments = [
12
+ CLAide::Argument.new('KEY', true),
13
+ CLAide::Argument.new('VALUE', true),
14
+ ]
14
15
 
15
16
  def initialize(argv)
16
- @name = argv.shift_argument
17
+ @key = argv.shift_argument
18
+ @value = argv.shift_argument
17
19
  super
18
- # @additional_args = argv.remainder!
19
20
  end
20
21
 
21
22
  def validate!
22
23
  super
23
- # help! 'A name for the Pod is required.' unless @name
24
- # help! 'The Pod name cannot contain spaces.' if @name =~ /\s/
25
- # help! 'The Pod name cannot contain plusses.' if @name =~ /\+/
26
- # help! "The Pod name cannot begin with a '.'" if @name[0, 1] == '.'
24
+ help! '请输入key.' unless @key
25
+ help! '请输入value.' unless @value
27
26
  end
28
27
 
29
28
  def run
30
- puts "设置全局配置成功".green
29
+ FileBase.set_config(@key, @value)
31
30
  end
32
31
  end
33
32
  end
@@ -1,6 +1,7 @@
1
1
  require 'gct/command/op/gems'
2
2
  require 'gct/command/op/gitconf'
3
3
  require 'gct/command/op/xcache'
4
+ require 'gct/command/op/root'
4
5
 
5
6
  module Gct
6
7
  class Command
@@ -10,6 +11,7 @@ module Gct
10
11
  self.description = <<-DESC
11
12
  打开常用文件夹,并输出路径
12
13
  DESC
14
+
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,33 @@
1
+ module Gct
2
+ class Command
3
+ class Op < Command
4
+ class Root < Op
5
+
6
+ self.summary = '打开gct文件夹'
7
+ self.description = <<-DESC
8
+ 打开gct文件夹
9
+ DESC
10
+
11
+ self.arguments = [
12
+ ]
13
+
14
+ def initialize(argv)
15
+ super
16
+ end
17
+
18
+ def validate!
19
+ super
20
+ end
21
+
22
+ def run
23
+ openGct
24
+ end
25
+
26
+ def openGct
27
+ root_path = Generator::GctFile.root_folder_path
28
+ system "open #{root_path}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ module Gct
2
+ class Command
3
+ class Setup < Command
4
+
5
+ self.summary = '设置Gct'
6
+ self.description = <<-DESC
7
+ 创建gct的全局隐藏文件,配置全局参数,缓存文件等
8
+ DESC
9
+
10
+ def initialize(argv)
11
+ super
12
+ end
13
+
14
+ def run
15
+ create_root_folder
16
+ create_temp_folder
17
+ create_config_file
18
+ puts "setup success!".green
19
+ end
20
+
21
+ def create_root_folder
22
+ gct_path = Generator::GctFile.root_folder_path
23
+ if !File.exist?(gct_path)
24
+ system "mkdir #{gct_path}", exception: true
25
+ puts "#{gct_path} 创建成功!".green
26
+ end
27
+ end
28
+
29
+ def create_temp_folder
30
+ temp_path = Generator::GctFile.temp_folder_path
31
+ if !File.exist?(temp_path)
32
+ system "mkdir #{temp_path}", exception: true
33
+ puts "#{temp_path} 创建成功!".green
34
+ end
35
+ end
36
+
37
+ def create_config_file
38
+ config_path = Generator::GctFile.config_file_path
39
+ if !File.exist?(config_path)
40
+ system "touch #{config_path}", exception: true
41
+ puts "#{config_path} 创建成功!".green
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ require 'gct/command/update/tag'
2
+ require 'gct/command/update/version'
3
+
4
+ module Gct
5
+ class Command
6
+ class Update < Command
7
+ self.abstract_command = true
8
+ self.summary = '更新操作'
9
+ self.description = <<-DESC
10
+ 更新组件tag、主工程版本号等
11
+ DESC
12
+
13
+ def initialize(argv)
14
+ super
15
+ config_gitlab
16
+ end
17
+
18
+ def current_branch
19
+ branch = "#{`git branch | awk '$1 == "*" {print $2}'`}".rstrip
20
+ raise "该文件夹不是一个git仓库".red if branch.empty?
21
+ branch
22
+ end
23
+
24
+ def check_branch_can_be_update(branch)
25
+ can_be_update = current_branch.include?(branch)
26
+
27
+ puts "当前不是#{branch}分支".red if !can_be_update
28
+
29
+ can_be_update
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,86 @@
1
+ module Gct
2
+ class Command
3
+ class Update < Command
4
+ class Tag < Update
5
+
6
+ self.summary = '添加tag'
7
+ self.description = <<-DESC
8
+ 十进制增加tag版本
9
+ DESC
10
+
11
+ self.arguments = [
12
+ CLAide::Argument.new('TAG', false),
13
+ ]
14
+
15
+ def initialize(argv)
16
+ @tag = argv.shift_argument
17
+ @update_version_branch = 'develop'
18
+ @file = get_spec_file
19
+ @project_id = "#{Constant.NameSpace}#{@spec.name}"
20
+ super
21
+ end
22
+
23
+ def validate!
24
+ super
25
+ end
26
+
27
+ def run
28
+ update_podspec_version
29
+ end
30
+
31
+ def get_spec_file
32
+ spec_file = Pathname.glob('*.podspec').first
33
+ raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
34
+
35
+ @spec = Pod::Specification.from_file(spec_file)
36
+ spec_file
37
+ end
38
+
39
+ def update_podspec_version
40
+ puts "开始读取podspec文件...".green
41
+ podspec_content = file_contents(@project_id, @file, @update_version_branch)
42
+ version_regex = /.*version.*/
43
+ version_match = version_regex.match(podspec_content).to_s
44
+ tag_regex = /(?<=')\w.*(?=')/
45
+ tag = tag_regex.match(version_match)
46
+ @now_tag = tag
47
+ @new_tag = @tag || auto_add_tag(tag.to_s)
48
+ replace_string = version_match.gsub(tag_regex, @new_tag)
49
+ @updated_podspec_content = podspec_content.gsub(version_match, replace_string)
50
+ puts "修改podpsec版本号成功!版本号为:#{@new_tag}".green
51
+ edit_file
52
+ mr_to_master
53
+ end
54
+
55
+ def edit_file
56
+ Gitlab.edit_file(@project_id, @file, @update_version_branch, @updated_podspec_content, "@config 更新版本号:#{@new_tag}")
57
+ end
58
+
59
+ def mr_to_master
60
+ puts "正在创建MR请求将develop分支合并到master!".green
61
+ mr = Gitlab.create_merge_request("#{Constant.NameSpace}#{@spec.name}", "更新版本podpesc版本号", { source_branch: "#{@update_version_branch}", target_branch: 'master' })
62
+ @id = mr.iid
63
+ puts mr.merge_status
64
+ if mr.merge_status == 'cannot_be_merged'
65
+ raise "Merge有冲突,请前往 https://gi-dev.ccrgt.com/#{Constant.NameSpace}#{@spec.name}/merge_requests/#{@id} 解决".red
66
+ end
67
+
68
+ mr_result = accept_merge_request
69
+ if mr_result.state == 'merged'
70
+ puts "成功合并到master分支".green
71
+ create_tag
72
+ end
73
+ end
74
+
75
+ def accept_merge_request
76
+ Gitlab.accept_merge_request("#{@project_id}", @id)
77
+ end
78
+
79
+ def create_tag
80
+ Gitlab.create_tag("#{@project_id}", "#{@new_tag}", "master")
81
+ puts "打tag成功,开始上传podspec...".green
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,57 @@
1
+ module Gct
2
+ class Command
3
+ class Update < Command
4
+ class Version < Update
5
+
6
+ self.summary = '更新版本号'
7
+ self.description = <<-DESC
8
+ 更新release分支的版本号
9
+ DESC
10
+
11
+ self.arguments = [
12
+ CLAide::Argument.new('VERSION', false),
13
+ CLAide::Argument.new('NAME', false),
14
+ ]
15
+
16
+ def initialize(argv)
17
+ @name = argv.shift_argument
18
+ @version = argv.shift_argument
19
+ name = @name ||= "iLife"
20
+ @project_id = "#{Constant.NameSpace}#{name}"
21
+ @file = "#{name}.xcodeproj/project.pbxproj"
22
+ super
23
+ end
24
+
25
+ def validate!
26
+ super
27
+ end
28
+
29
+ def run
30
+ @branch = current_branch
31
+ update_version
32
+ end
33
+
34
+ def update_version
35
+ puts @project_id
36
+ puts @file
37
+ puts @branch
38
+ content = file_contents(@project_id, @file, @branch)
39
+ puts content
40
+ if check_branch_can_be_update('release')
41
+ content = file_contents(@project_id, @file, @branch)
42
+ version_var_name = 'MARKETING_VERSION = '
43
+ version_regex = /(?<=#{version_var_name})\w.*(?=;)/
44
+ version_match = version_regex.match(content)
45
+ version = @version ||= auto_add_tag(version_match)
46
+ updated_content = content.gsub(version_regex, version)
47
+ edit_file(updated_content, version)
48
+ end
49
+ end
50
+
51
+ def edit_file(content, version)
52
+ Gitlab.edit_file(@project_id, @file, @branch, content, "@config 更新版本号:#{version}")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,6 +1,10 @@
1
1
  module Gct
2
2
  module Constant
3
3
  class << self
4
+ def GitBaseURL
5
+ "https://gi-dev.ccrgt.com/"
6
+ end
7
+
4
8
  def GitThirdURL
5
9
  "https://gi-dev.ccrgt.com/ios-thirdpart/"
6
10
  end
@@ -8,6 +12,18 @@ module Gct
8
12
  def GitURL
9
13
  "https://gi-dev.ccrgt.com/ios/"
10
14
  end
15
+
16
+ def NameSpace
17
+ "ios/"
18
+ end
19
+
20
+ def ThirdNameSpace
21
+ "ios-third/"
22
+ end
23
+
24
+ def DefaultTagBranch
25
+ "develop"
26
+ end
11
27
  end
12
28
  end
13
29
  end
@@ -0,0 +1,57 @@
1
+ module Gct
2
+ module FileBase
3
+ class << self
4
+ attr_reader :path
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ end
9
+
10
+ def yaml_write(key, value)
11
+ begin
12
+ yaml_file = File.open(@path, "w")
13
+ YAML::dump({key => value}, yaml_file)
14
+ rescue IOError => e
15
+ raise e.message
16
+ ensure
17
+ yaml_file.close unless yaml_file.nil?
18
+ end
19
+ end
20
+
21
+ def yaml_read(key)
22
+ begin
23
+ yaml_file = YAML.load(File.open(@path, "r"))
24
+ if yaml_file
25
+ yaml_file[key]
26
+ end
27
+ rescue IOError => e
28
+ raise e.message
29
+ end
30
+ end
31
+
32
+ def get_config(key)
33
+ if exist_root
34
+ @path = config_path
35
+ yaml_read(key)
36
+ end
37
+ end
38
+
39
+ def set_config(key, value)
40
+ if exist_root
41
+ @path = config_path
42
+ yaml_write(key, value)
43
+ end
44
+ end
45
+
46
+ def config_path
47
+ "#{Generator::GctFile.config_file_path}"
48
+ end
49
+
50
+ def exist_root
51
+ root_exist = File.exist?(Generator::GctFile.root_folder_path)
52
+ raise "请先运行命令:gct setup".red if !root_exist
53
+ root_exist
54
+ end
55
+ end
56
+ end
57
+ end
@@ -2,5 +2,5 @@ module Gct
2
2
  # freeze 冻结对象,将对象变成一个常量
3
3
  # unless 右边的代码块成立,才会运行左边的代码块
4
4
  # defined? 是用来判断本地变量是否存在,也可用来判断是否存在方法
5
- VERSION = "0.3.2".freeze unless defined? Gct::VERSION
5
+ VERSION = "0.3.7".freeze unless defined? Gct::VERSION
6
6
  end
@@ -0,0 +1,35 @@
1
+ module Gct
2
+ module Generator
3
+ class GctFile
4
+ def self.root_folder_path
5
+ "#{get_system_home_path.rstrip}/.gct"
6
+ end
7
+
8
+ def self.temp_folder_path
9
+ "#{get_system_home_path.rstrip}/.gct/tmp"
10
+ end
11
+
12
+ def self.config_file_path
13
+ "#{get_system_home_path.rstrip}/.gct/config"
14
+ end
15
+
16
+ # 获取系统用户名
17
+ def self.get_system_user_name
18
+ # windows
19
+ if RUBY_PLATFORM =~ /mswin|mingw/
20
+ query = `reg query HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer /v "Logon User Name"`
21
+ /Logon\ User\ Name\s+REG_SZ\s+(\S+)/ =~ query
22
+ "#{$1}"
23
+ # unix, cygwin, mac
24
+ else
25
+ "#{`whoami`}"
26
+ end
27
+ end
28
+
29
+ def self.get_system_home_path
30
+ "#{`echo ~`}"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ module Gct
2
+ # attr_accessor get and set
3
+ # attr_reader only get
4
+ # attr_writer only set
5
+ class Specification
6
+ # Pod::Dependency
7
+ attr_accessor :specification
8
+
9
+ # 优先级
10
+ attr_accessor :priority
11
+
12
+ # tag版本
13
+ attr_accessor :tag
14
+
15
+ # 发布状态
16
+ attr_accessor :status
17
+
18
+ def initialize()
19
+ @specification = specification
20
+ @priority = priority
21
+ @status = status
22
+ @tag = tag
23
+ end
24
+ end
25
+ end
26
+
27
+ module SpecPublishStatus
28
+ CREATED = '待分析'
29
+ ANALYZING = '分析中'
30
+ PREPARING = '准备中'
31
+ PENDING = '等待中'
32
+ WAITING = '待发布'
33
+ SKIPPED = '已忽略'
34
+ MERGED = '已合并'
35
+ DEPLOYING = '发布中'
36
+ SUCCESS = '发布成功'
37
+ FAILED = '发布失败'
38
+ CANCELED = '已取消'
39
+ end
@@ -0,0 +1,42 @@
1
+ module Gct
2
+ class TempLocalFile
3
+ attr_reader :content
4
+
5
+ attr_reader :file_name
6
+
7
+ def initialize(content, file_name)
8
+ @content = content
9
+ @file_name = file_name
10
+ end
11
+
12
+ def write
13
+ begin
14
+ file = File.open(tmp_folder, "w")
15
+ file.write(@content)
16
+ rescue IOError => e
17
+ raise e.message
18
+ ensure
19
+ file.close unless file.nil?
20
+ end
21
+ end
22
+
23
+ def read
24
+ begin
25
+ file = File.open(tmp_folder, "r")
26
+ file.read
27
+ rescue IOError => e
28
+ raise e.message
29
+ ensure
30
+ file.close unless file.nil?
31
+ end
32
+ end
33
+
34
+ def full_path
35
+ tmp_folder
36
+ end
37
+
38
+ def tmp_folder
39
+ "#{Generator::GctFile.temp_folder_path}/#{file_name}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,44 @@
1
+ module Gct
2
+ class TempRemoteFile
3
+ attr_reader :uri
4
+
5
+ def initialize(url, content)
6
+ @uri = URI.parse(url)
7
+ @content = content
8
+ end
9
+
10
+ def file
11
+ @file ||= Tempfile.open(tmp_filename, tmp_folder, encoding: encoding) do |f|
12
+ puts f
13
+ io.rewind
14
+ f.write(io.read)
15
+ f.close
16
+ end
17
+ end
18
+
19
+ def close
20
+ @file.close
21
+ @file.unlink
22
+ end
23
+
24
+ def io
25
+ @io ||= uri.open
26
+ end
27
+
28
+ def encoding
29
+ io.rewind
30
+ io.read.encoding
31
+ end
32
+
33
+ def tmp_filename
34
+ [
35
+ Pathname.new(uri.path).basename,
36
+ Pathname.new(uri.path).extname
37
+ ]
38
+ end
39
+
40
+ def tmp_folder
41
+ Generator::GctFile.temp_folder_path
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - jieming
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
@@ -106,6 +106,34 @@ dependencies:
106
106
  - - "<"
107
107
  - !ruby/object:Gem::Version
108
108
  version: '2.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: gitlab
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: parallel
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
109
137
  description: '"gct ios 自动化脚本工具"'
110
138
  email:
111
139
  - 307113345@qq.com
@@ -135,16 +163,25 @@ files:
135
163
  - lib/gct/command/op.rb
136
164
  - lib/gct/command/op/gems.rb
137
165
  - lib/gct/command/op/gitconf.rb
166
+ - lib/gct/command/op/root.rb
138
167
  - lib/gct/command/op/xcache.rb
139
168
  - lib/gct/command/repo.rb
140
169
  - lib/gct/command/repo/add.rb
141
170
  - lib/gct/command/repo/push.rb
142
171
  - lib/gct/command/repo/update.rb
172
+ - lib/gct/command/setup.rb
143
173
  - lib/gct/command/spec.rb
144
174
  - lib/gct/command/spec/lint.rb
145
- - lib/gct/command/tag.rb
175
+ - lib/gct/command/update.rb
176
+ - lib/gct/command/update/tag.rb
177
+ - lib/gct/command/update/version.rb
146
178
  - lib/gct/constant.rb
147
- - lib/gct/version.rb
179
+ - lib/gct/file_base.rb
180
+ - lib/gct/gct_version.rb
181
+ - lib/gct/generator/gct_file.rb
182
+ - lib/gct/specification.rb
183
+ - lib/gct/temp_local_file.rb
184
+ - lib/gct/temp_remote_file.rb
148
185
  homepage: https://gi-dev.ccrgt.com/ios-thirdpart/gct
149
186
  licenses: []
150
187
  metadata:
@@ -157,14 +194,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
194
  requirements:
158
195
  - - ">="
159
196
  - !ruby/object:Gem::Version
160
- version: '0'
197
+ version: 2.6.0
161
198
  required_rubygems_version: !ruby/object:Gem::Requirement
162
199
  requirements:
163
200
  - - ">="
164
201
  - !ruby/object:Gem::Version
165
202
  version: '0'
166
203
  requirements: []
167
- rubygems_version: 3.0.3
204
+ rubygems_version: 3.0.8
168
205
  signing_key:
169
206
  specification_version: 4
170
207
  summary: '"gct ios 自动化脚本工具"'
@@ -1,62 +0,0 @@
1
- module Gct
2
- class Command
3
- class Tag < Command
4
-
5
- self.summary = '添加tag'
6
- self.description = <<-DESC
7
- 十进制增加tag版本
8
- DESC
9
-
10
- self.arguments = [
11
- CLAide::Argument.new('TAG', false),
12
- ]
13
-
14
- def initialize(argv)
15
- @tag = argv.shift_argument
16
- super
17
- end
18
-
19
- def validate!
20
- super
21
- end
22
-
23
- def run
24
- get_now_tag
25
- add_push_new_tag
26
- end
27
-
28
- def update_tag_podspec
29
- # 更新podspec的版本号 @new_tag 创建MR推送到远端
30
-
31
- end
32
-
33
- def get_now_tag
34
- spec_file = Pathname.glob('*.podspec').first
35
- raise "在 #{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?
36
-
37
- spec = Pod::Specification.from_file(spec_file)
38
- @now_tag = spec.version
39
- end
40
-
41
- def add_push_new_tag
42
- @new_tag = @tag || autoAddTag(@now_tag.to_s)
43
- update_tag_podspec
44
- `git tag #{@new_tag}`
45
- `git push origin #{@new_tag} || { exit 1; }`
46
- end
47
-
48
- def autoAddTag(tag)
49
- tag_points = tag.to_s.split('.')
50
- index = tag_points.length - 1
51
- need_add_point = tag_points[index].to_i + 1
52
- tag_points[index] = need_add_point == 10 ? 0 : need_add_point
53
- while need_add_point == 10 && index > 0
54
- index = index - 1
55
- need_add_point = tag_points[index].to_i + 1
56
- tag_points[index] = need_add_point == 10 && index != 0 ? 0 : need_add_point
57
- end
58
- tag_points.join('.')
59
- end
60
- end
61
- end
62
- end