cocoapods-hbh 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0ecd9739c3ee6352722b81352293df223f450498dc62d67f3b4e7398d0e6126
4
- data.tar.gz: dc5e9e4a2043e464a2f790efc8f5b79e710813529d6a6f77c9173c5d5041ce22
3
+ metadata.gz: 2e1e1a7718b77767e54ace762fb5420384221cc8ae52cf9fa14a35b0c1a469f7
4
+ data.tar.gz: 3889d0720f7f1bc0bd999359ff1913e9d6391b3c05bda0064895723a46bfb489
5
5
  SHA512:
6
- metadata.gz: 37ac6062b4024b8bc9cf5338efd6ba1ce5f567a6a2068251390221f2b228f69e9d267dc4b51133eaebf7914970f5586844aa6f6c9a0f02b33e0de374295d0136
7
- data.tar.gz: 38b54f1dd0e180580ebde346aa61b827d4a3f97b31222a7380a19b3c533e03e126b79fc354f81580a20bd4e9aa7e2d2f62d004f3d4386ebf5b99f98c6a919b69
6
+ metadata.gz: 5b375db806bda54a709c9cf5694a0ac1def3ff3e3591f80e9ee20de7848d2da9601589de8d9bfa42e159771baa2712a6d49447a9712d0b2743d7a1bceed01d88
7
+ data.tar.gz: 1f592af25e91098415c5d20052fe8644f2d4406a8b96dd07dfdf233cce934ce56fac8b23cffb55ee42ae2859f4f4a54a4cd0e94602d068a8eed68d06fc35d231
@@ -0,0 +1,26 @@
1
+ require 'cocoapods-hbh/git_hooks/githooks_sync'
2
+
3
+ module Pod
4
+ class Command
5
+ class HbhGit < Command
6
+ self.summary = '自定的githook相关命令'
7
+
8
+ self.description = <<-DESC
9
+ 自定的githook相关命令.
10
+ DESC
11
+
12
+ self.arguments = "hbhgit"
13
+
14
+ def initialize(argv)
15
+ super
16
+ end
17
+
18
+ def run
19
+ UI.puts "同步Git相关命令"
20
+ GitHooksSync.new.sync()
21
+ UI.puts "同步完成"
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -2,6 +2,7 @@ require 'cocoapods-hbh/command/common/install'
2
2
  require 'cocoapods-hbh/command/common/podfile'
3
3
  require 'cocoapods-hbh/command/common/push'
4
4
  require 'cocoapods-hbh/command/common/hbh_init'
5
+ require 'cocoapods-hbh/command/common/hbh_git'
5
6
  require 'cocoapods-hbh/command/native/native_install'
6
7
  require 'cocoapods-hbh/command/native/native_update'
7
8
 
@@ -68,7 +68,7 @@ module Pod
68
68
  moduleRoot = sub_config['sub_path'].blank? ? "Modules" : sub_config['sub_path']
69
69
 
70
70
  path_module = "./#{moduleRoot}/#{moduleName}"
71
- Pod::UI.puts "#{moduleName}使用本地Pod模块".yellow
71
+ Pod::UI.puts "#{moduleName}使用本地Pod模块".green
72
72
  if !File.exist?("#{path_module}/#{moduleName}.podspec")
73
73
  `git submodule add #{remoteUrl}#{moduleName}.git ./Modules/#{moduleName}`
74
74
  Pod::UI.puts "本地没有#{moduleName}模块,正在下载中..."
@@ -79,7 +79,7 @@ module Pod
79
79
  # `git config push.recurseSubmodules on-demand`
80
80
 
81
81
  if system "git submodule update --init --recursive"
82
- Pod::UI.puts "#{moduleName}模块下载完成...".yellow
82
+ Pod::UI.puts "#{moduleName}模块下载完成...".green
83
83
  end
84
84
  end
85
85
  if moduleTag != nil and !moduleTag.empty?
@@ -3,13 +3,12 @@ require 'cocoapods-hbh/command/hbh'
3
3
  require 'cocoapods-hbh/git_hooks/githooks_sync'
4
4
 
5
5
  module CocoapodsHBHGitHooks
6
- Pod::HooksManager.register('cocoapods-hbh', :post_install) do |context|
7
- GitHooksSync.new.sync()
8
- end
9
6
  Pod::HooksManager.register('cocoapods-hbh', :post_update) do |context|
10
7
  GitHooksSync.new.sync()
8
+ Pod::UI.puts "恭喜你, 你已经 `pod update` 结束了."
11
9
  end
12
10
  Pod::HooksManager.register('cocoapods-hbh', :post_install) do |context|
11
+ GitHooksSync.new.sync()
13
12
  Pod::UI.puts "恭喜你, 你已经 `pod install` 结束了."
14
13
  end
15
14
  end
@@ -17,7 +17,8 @@ module HBHConfig
17
17
  'sub_path' => '子模块存储路径' ,
18
18
  'sub_url' => '子模块厂库地址' ,
19
19
  },
20
- 'is_git_hooks' => 'false',
20
+ 'is_turn_swiftint' => false,
21
+ 'is_turn_tinypng' => true,
21
22
  'cocoapods_version' => '1.10.1',
22
23
  }
23
24
  end
@@ -56,7 +57,8 @@ module HBHConfig
56
57
  if aFile
57
58
  aFile.syswrite(template_hash.to_yaml)
58
59
  end
59
- raise "请在你的根目录配置创建并配置HBHConfig.yml文件"
60
+ YAML.load_file(config_name)
61
+ # raise "请在你的根目录配置创建并配置HBHConfig.yml文件"
60
62
  end
61
63
  end
62
64
 
@@ -1,3 +1,3 @@
1
1
  module CocoapodsHbh
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -1,13 +1,25 @@
1
1
  require 'cocoapods'
2
2
  require 'fileutils'
3
-
4
- module CocoapodsHBHGitHooks
3
+ module Pod
5
4
  class GitHooksSync
6
5
  def sync
7
6
 
8
- return unless HBHConfig.config.is_git_hooks
7
+ copyFileToGit("pre-commit")
8
+
9
+ if HBHConfig.config.is_turn_swiftint
10
+ copyFileToGit("swiftlint.sh")
11
+ else
12
+ deleteFileInGit("swiftlint.sh")
13
+ end
14
+
15
+ if HBHConfig.config.is_turn_tinypng
16
+ copyFileToGit("imageTinypng.rb")
17
+ else
18
+ deleteFileInGit("imageTinypng.rb")
19
+ end
20
+ end
9
21
 
10
- Pod::UI.puts "开始同步git拦截设置"
22
+ def copyFileToGit (file_name)
11
23
  if !File.directory?(".git")
12
24
  Pod::UI.puts "没有发现git工程"
13
25
  return
@@ -16,27 +28,44 @@ module CocoapodsHBHGitHooks
16
28
  # 在当前ruby项目的githook文件copy到项目里去做拦截
17
29
  # 如果项目里配置了 .git-hooks 文件件,将把里面的内容copy到项目里去做拦截
18
30
  # 项目里的.git-hooks 配置优先
19
- git_hooks = "#{File.dirname(__FILE__)}/../../script_source/pre-commit"
31
+ git_hooks = "#{File.dirname(__FILE__)}/../../script_source/#{file_name}"
20
32
 
21
- # if File.directory?(".git-hooks")
22
-
23
- # end
33
+ if !File.exist?(git_hooks)
34
+ Pod::UI.puts "同步文件不存在"
35
+ return
36
+ end
24
37
 
25
- git_hooks = '.git-hooks/.' unless Dir['.git-hooks/*'].empty?
38
+ # git_hooks = '.git-hooks/.' unless Dir['.git-hooks/*'].empty?
26
39
 
27
40
  if !File.directory?(".git/hooks")
28
41
  FileUtils.mkdir ".git/hooks"
29
42
  end
30
- FileUtils.cp_r(git_hooks, ".git/hooks/")
31
- path = ".git/hooks/"
32
- Dir.open(path).each do |p|
33
- filename = File.basename(p, File.extname(p))
34
- if File.extname(p) == ".sh"
35
- FileUtils.mv("#{path}/#{p}", "#{path}/#{filename}")
36
- end
37
- FileUtils.chmod("+x", "#{path}/#{filename}")
43
+ path = ".git/hooks"
44
+
45
+ FileUtils.cp_r(git_hooks, path)
46
+
47
+ FileUtils.chmod("+x", "#{path}/#{file_name}")
48
+ # Dir.open(path).each do |p|
49
+ # filename = File.basename(p, File.extname(p))
50
+ # if File.extname(p) == ".sh"
51
+ # FileUtils.mv("#{path}/#{p}", "#{path}/#{filename}")
52
+ # end
53
+ # FileUtils.chmod("+x", "#{path}/#{filename}")
54
+ # end
55
+ end
56
+
57
+ def deleteFileInGit (file_name)
58
+ if !File.directory?(".git")
59
+ Pod::UI.puts "没有发现git工程"
60
+ return
61
+ end
62
+
63
+ path = ".git/hooks/#{file_name}"
64
+ if File.exist?(path)
65
+ FileUtils.rm(path)
38
66
  end
39
- Pod::UI.puts "结束同步git拦截设置"
67
+
68
+
40
69
  end
41
70
  end
42
71
  end
@@ -0,0 +1,54 @@
1
+ require 'tinify'
2
+ require 'yaml'
3
+ class TinyPngImage
4
+ ### 正则匹配所有图片资源
5
+ def get_all_img(items)
6
+ filter = /[\s\S]*\.(png|jpeg|jpg|pjpg|svg)/
7
+ items.select { |i| i[filter] }
8
+ end
9
+ def template_hash
10
+ {
11
+ 'info' => "配置tinypng_key, 可访问获取对应Key https://tinypng.com/",
12
+ 'tinypng_key' => "",
13
+ }
14
+ end
15
+ ### 通过本地配置文件获取tinypng的key
16
+ def get_config
17
+ configPath = ".git/hbh_git_config"
18
+ if !File.exist?(configPath)
19
+ File.new(configPath, "w+").syswrite(template_hash().to_yaml)
20
+ end
21
+
22
+ config = OpenStruct.new YAML.load_file(configPath)
23
+ config.tinypng_key
24
+ end
25
+ ### 根据条件开始使用tinypng压缩图片
26
+ def start_tinypng
27
+ is_turn_tinypng = get_config()
28
+
29
+ if !is_turn_tinypng.nil? && !is_turn_tinypng.empty?
30
+ Tinify.key = is_turn_tinypng
31
+ # diffFile = %x(git diff --cached --name-only --diff-filter=ACM)
32
+ diffFile = %x(git diff --cached --name-only --diff-filter=ACM -- '*.jpg' '*.png' '*.jpeg')
33
+ diffArr = diffFile.split("\n")
34
+ imgArr = get_all_img(diffArr)
35
+ puts "开始使用tinypng压缩图片"
36
+ for item in imgArr do
37
+ fileSize =%x(du -sh #{item})
38
+ puts "原文件大小:#{fileSize}"
39
+ Tinify.from_file("#{item}").to_file("#{item}")
40
+ addChangeFile = %x(git add #{item})
41
+ optimizedFileSize =%x(du -sh #{item})
42
+ puts "压缩后文件:#{optimizedFileSize}"
43
+ end
44
+ else
45
+ puts "请到.git/hbh_git_config文件里配置tinypng_key"
46
+ system("open .git/hbh_git_config")
47
+ end
48
+ end
49
+ end
50
+
51
+ tinify = TinyPngImage.new
52
+ tinify.start_tinypng()
53
+
54
+
@@ -1,37 +1,10 @@
1
- STAGE_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.swift')
2
- swiftLintPath="./Pods/SwiftLint/swiftlint"
3
- if test ${#STAGE_FILES} -gt 0
4
- then
5
- echo '检查提交的文件'
6
- echo $(pwd)
7
- if [ ! -e $swiftLintPath ]; then
8
- echo '没安装SwiftLint'
9
- exit 1
10
- fi
11
-
12
- PASS=true
13
- PATH="./swiftLint"
14
-
15
- for FILE in $STAGE_FILES
16
- do
17
- warning="*warning*"
18
- $swiftLintPath lint --strict $FILE > $PATH
19
- /bin/cat $PATH
20
- Result=$(/bin/cat $PATH)
21
- if [[ $Result == *$warning* ]]; then
22
- PASS=false
23
- fi
24
- done
25
- /bin/rm -rf $PATH
26
- if ! $PASS; then
27
- echo "SwiftLint检查没通过!"
28
- exit 1
29
- else
30
- echo "SwiftLint检查完毕"
31
- fi
32
-
33
- else
34
- echo '没有swift文件需要检查'
1
+ #!/bin/bash
2
+ path=".git/hooks"
3
+ #判断Swiftlint文件是否存在
4
+ if [ -f ${path}/swiftlint.sh ]; then
5
+ sh .git/hooks/swiftlint.sh
35
6
  fi
36
-
37
- exit 0
7
+ #判断Tinypng图片压缩文件是否存在
8
+ if [ -f ${path}/imageTinypng.rb ]; then
9
+ ruby .git/hooks/imageTinypng.rb
10
+ fi
@@ -0,0 +1,39 @@
1
+ #!/bin/bash
2
+
3
+ STAGE_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.swift')
4
+ swiftLintPath="./Pods/SwiftLint/swiftlint"
5
+ if test ${#STAGE_FILES} -gt 0
6
+ then
7
+ echo '检查提交的文件'
8
+ echo $(pwd)
9
+ if [ ! -e $swiftLintPath ]; then
10
+ echo '没安装SwiftLint'
11
+ exit 1
12
+ fi
13
+
14
+ PASS=true
15
+ PATH="./swiftLint"
16
+
17
+ for FILE in $STAGE_FILES
18
+ do
19
+ warning="*warning*"
20
+ $swiftLintPath lint --strict $FILE > $PATH
21
+ /bin/cat $PATH
22
+ Result=$(/bin/cat $PATH)
23
+ if [[ $Result == *$warning* ]]; then
24
+ PASS=false
25
+ fi
26
+ done
27
+ /bin/rm -rf $PATH
28
+ if ! $PASS; then
29
+ echo "SwiftLint检查没通过!"
30
+ exit 1
31
+ else
32
+ echo "SwiftLint检查完毕"
33
+ fi
34
+
35
+ else
36
+ echo '没有swift文件需要检查'
37
+ fi
38
+
39
+ exit 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-hbh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - zanju
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-29 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tinify
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +103,7 @@ extra_rdoc_files: []
89
103
  files:
90
104
  - lib/cocoapods-hbh.rb
91
105
  - lib/cocoapods-hbh/command.rb
106
+ - lib/cocoapods-hbh/command/common/hbh_git.rb
92
107
  - lib/cocoapods-hbh/command/common/hbh_init.rb
93
108
  - lib/cocoapods-hbh/command/common/install.rb
94
109
  - lib/cocoapods-hbh/command/common/podfile.rb
@@ -104,7 +119,9 @@ files:
104
119
  - lib/cocoapods-hbh/git_hooks/githooks_sync.rb
105
120
  - lib/cocoapods-hbh/helpers/git_depend.rb
106
121
  - lib/cocoapods_plugin.rb
122
+ - lib/script_source/imageTinypng.rb
107
123
  - lib/script_source/pre-commit
124
+ - lib/script_source/swiftlint.sh
108
125
  homepage: https://github.com/EXAMPLE/cocoapods-hbh
109
126
  licenses:
110
127
  - MIT
@@ -124,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
141
  - !ruby/object:Gem::Version
125
142
  version: '0'
126
143
  requirements: []
127
- rubygems_version: 3.2.22
144
+ rubygems_version: 3.3.11
128
145
  signing_key:
129
146
  specification_version: 4
130
147
  summary: A longer description of cocoapods-hbh.