cocoapods-hbh 0.1.5 → 0.1.9

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: c0ecd9739c3ee6352722b81352293df223f450498dc62d67f3b4e7398d0e6126
4
- data.tar.gz: dc5e9e4a2043e464a2f790efc8f5b79e710813529d6a6f77c9173c5d5041ce22
3
+ metadata.gz: 8bad5c1b8ce197c38234be5e45fbd18308cae43d59cf347945d0ebec29c5fdbe
4
+ data.tar.gz: 5ee039ad7e1c47dc8965d444f03290e4f069bb34ca48ac3de7c8f1ed97bd91fd
5
5
  SHA512:
6
- metadata.gz: 37ac6062b4024b8bc9cf5338efd6ba1ce5f567a6a2068251390221f2b228f69e9d267dc4b51133eaebf7914970f5586844aa6f6c9a0f02b33e0de374295d0136
7
- data.tar.gz: 38b54f1dd0e180580ebde346aa61b827d4a3f97b31222a7380a19b3c533e03e126b79fc354f81580a20bd4e9aa7e2d2f62d004f3d4386ebf5b99f98c6a919b69
6
+ metadata.gz: 75b416f95ddf8bcf7078f0e82b445d06d32a962a5d627667ba965d7d999ef2def5143b192ee723f090195c76fec228cbf47df076be11aa3d779bee4cdd15955e
7
+ data.tar.gz: 66e6b44209cd8a26c27fd59b6ccbaf41e5b056ca4972512d770ab24ce4a9f783719fc51a98c7c417cf124b8d04c76b24be929065e06f8aeee40bad20390ba3a9
@@ -0,0 +1,27 @@
1
+ require 'cocoapods-hbh/git_hooks/githooks_sync'
2
+
3
+ module Pod
4
+ class Command
5
+ class Hbh < Command
6
+ class Git < Hbh
7
+ self.summary = '自定的githook相关命令'
8
+
9
+ self.description = <<-DESC
10
+ 自定的githook相关命令.
11
+ DESC
12
+
13
+ # self.arguments = "hbhgit"
14
+
15
+ def initialize(argv)
16
+ super
17
+ end
18
+
19
+ def run
20
+ UI.puts "同步Git相关命令"
21
+ GitHooksSync.new.sync()
22
+ UI.puts "同步完成"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ 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,16 +79,16 @@ 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?
86
- result = system("cd #{path_module} && git fetch && git checkout #{moduleTag}")
86
+ result = system("cd #{path_module} && git fetch origin #{moduleTag} && git checkout #{moduleTag}")
87
87
  raise "发生错误" unless result
88
88
  # `cd #{path_module} && git fetch && git checkout #{moduleTag}`
89
89
  # Pod::UI.puts "发生错误#{result}".red
90
90
  else
91
- result = system("cd #{path_module} && git fetch && git checkout #{moduleBranch} && git pull origin #{moduleBranch}")
91
+ result = system("cd #{path_module} && git fetch origin #{moduleBranch} && git checkout #{moduleBranch} && git pull origin #{moduleBranch}")
92
92
  raise "发生错误" unless result
93
93
 
94
94
  # Pod::UI.puts "发生错误#{result}".red
@@ -3,13 +3,13 @@ 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
6
+ include Pod
9
7
  Pod::HooksManager.register('cocoapods-hbh', :post_update) do |context|
10
8
  GitHooksSync.new.sync()
9
+ Pod::UI.puts "恭喜你, 你已经 `pod update` 结束了."
11
10
  end
12
11
  Pod::HooksManager.register('cocoapods-hbh', :post_install) do |context|
12
+ GitHooksSync.new.sync()
13
13
  Pod::UI.puts "恭喜你, 你已经 `pod install` 结束了."
14
14
  end
15
15
  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.9"
3
3
  end
@@ -1,14 +1,35 @@
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
21
+
22
+ def findGitPath
23
+ _git_path = ".git"
24
+ if !File.directory?(_git_path)
25
+ _git_path = "../.git"
26
+ end
27
+ _git_path
28
+ end
9
29
 
10
- Pod::UI.puts "开始同步git拦截设置"
11
- if !File.directory?(".git")
30
+ def copyFileToGit (file_name)
31
+ git_path = findGitPath()
32
+ if !File.directory?(git_path)
12
33
  Pod::UI.puts "没有发现git工程"
13
34
  return
14
35
  end
@@ -16,27 +37,54 @@ module CocoapodsHBHGitHooks
16
37
  # 在当前ruby项目的githook文件copy到项目里去做拦截
17
38
  # 如果项目里配置了 .git-hooks 文件件,将把里面的内容copy到项目里去做拦截
18
39
  # 项目里的.git-hooks 配置优先
19
- git_hooks = "#{File.dirname(__FILE__)}/../../script_source/pre-commit"
40
+ hooks_path = "#{File.dirname(__FILE__)}/../../script_source/#{file_name}"
20
41
 
21
- # if File.directory?(".git-hooks")
22
-
23
- # end
42
+ if !File.exist?(hooks_path)
43
+ Pod::UI.puts "同步文件不存在"
44
+ return
45
+ end
46
+ git_hooks_path = "#{git_path}/hooks"
47
+ if !File.exist?(git_hooks_path)
48
+ FileUtils.mkdir_p git_hooks_path
49
+ end
50
+ FileUtils.cp_r(hooks_path, git_hooks_path)
51
+ FileUtils.chmod("+x", "#{git_hooks_path}/#{file_name}")
52
+ findSubmodulesHooks(hooks_path, git_path, file_name)
53
+ end
24
54
 
25
- git_hooks = '.git-hooks/.' unless Dir['.git-hooks/*'].empty?
55
+ def findSubmodulesHooks (git_hooks_path, git_path, file_name)
56
+ subGitHookPath = walk(git_path)
57
+ subGitHookPath.each do |path|
58
+ FileUtils.cp_r(git_hooks_path, path)
59
+ FileUtils.chmod("+x", "#{path}/#{file_name}")
60
+ end
61
+ end
26
62
 
27
- if !File.directory?(".git/hooks")
28
- FileUtils.mkdir ".git/hooks"
63
+ def walk (startPath, dirName = "hooks", first = true)
64
+ @pathArr=Array.new unless !first
65
+ Dir.foreach(startPath) do |x|
66
+ path = File.join(startPath, x)
67
+ if x =="." or x ==".."
68
+ next
69
+ elsif File.directory?(path)
70
+ if path.include?(dirName)
71
+ @pathArr << path
72
+ end
73
+ walk(path, dirName, false)
74
+ end
75
+ end
76
+ @pathArr
77
+ end
78
+
79
+ def deleteFileInGit (file_name)
80
+ if !File.directory?(findGitPath())
81
+ Pod::UI.puts "没有发现git工程"
82
+ return
29
83
  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}")
84
+ path = ".git/hooks/#{file_name}"
85
+ if File.exist?(path)
86
+ FileUtils.rm(path)
38
87
  end
39
- Pod::UI.puts "结束同步git拦截设置"
40
88
  end
41
89
  end
42
90
  end
@@ -0,0 +1,57 @@
1
+
2
+ require 'tinify'
3
+ require 'yaml'
4
+ class TinyPngImage
5
+ ### 正则匹配所有图片资源
6
+ def get_all_img(items)
7
+ filter = /[\s\S]*\.(png|jpeg|jpg|pjpg|svg)/
8
+ items.select { |i| i[filter] }
9
+ end
10
+ def template_hash
11
+ {
12
+ 'info' => "配置tinypng_key, 可访问获取对应Key https://tinypng.com/",
13
+ 'tinypng_key' => "",
14
+ }
15
+ end
16
+ ### 通过本地配置文件获取tinypng的key
17
+ def get_config
18
+ configPath = ".git/hbh_git_config"
19
+ if !File.exist?(configPath)
20
+ File.new(configPath, "w+").syswrite(template_hash().to_yaml)
21
+ end
22
+
23
+ config = OpenStruct.new YAML.load_file(configPath)
24
+ config.tinypng_key
25
+ end
26
+ ### 根据条件开始使用tinypng压缩图片
27
+ def start_tinypng
28
+ tinypng_key = get_config()
29
+
30
+ if !tinypng_key.nil? && !tinypng_key.empty?
31
+ Tinify.key = tinypng_key
32
+ # diffFile = %x(git diff --cached --name-only --diff-filter=ACM)
33
+ diffFile = %x(git diff --cached --name-only --diff-filter=ACM -- '*.jpg' '*.png' '*.jpeg')
34
+ diffArr = diffFile.split("\n")
35
+ imgArr = get_all_img(diffArr)
36
+ if imgArr.count > 0
37
+ puts "开始使用tinypng压缩图片"
38
+ for item in imgArr do
39
+ fileSize =%x(du -sh #{item})
40
+ puts "原文件大小:#{fileSize}"
41
+ Tinify.from_file("#{item}").to_file("#{item}")
42
+ addChangeFile = %x(git add #{item})
43
+ optimizedFileSize =%x(du -sh #{item})
44
+ puts "压缩后文件:#{optimizedFileSize}"
45
+ end
46
+ end
47
+ else
48
+ puts "请到.git/hbh_git_config文件里配置tinypng_key"
49
+ system("open .git/hbh_git_config")
50
+ end
51
+ end
52
+ end
53
+
54
+ tinify = TinyPngImage.new
55
+ tinify.start_tinypng()
56
+
57
+
@@ -1,37 +1,11 @@
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=$(which ruby)
10
+ ruby .git/hooks/imageTinypng.rb
11
+ 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.9
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-30 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.