cocoapods-hbh 0.1.4 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cocoapods-hbh/command/common/hbh_git.rb +27 -0
- data/lib/cocoapods-hbh/command/hbh.rb +1 -0
- data/lib/cocoapods-hbh/command/module/add_module.rb +9 -6
- data/lib/cocoapods-hbh/command.rb +3 -3
- data/lib/cocoapods-hbh/config/config.rb +4 -2
- data/lib/cocoapods-hbh/gem_version.rb +1 -1
- data/lib/cocoapods-hbh/git_hooks/githooks_sync.rb +47 -18
- data/lib/script_source/imageTinypng.rb +57 -0
- data/lib/script_source/pre-commit +10 -36
- data/lib/script_source/swiftlint.sh +39 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68cb2128e5a916a9c9e8b1e8b030facbfce360cb253b7d3efd9317c55e687521
|
4
|
+
data.tar.gz: e20133b18410c6f992a2987358f93f2d96a264bae8ce9d0416b4d0bcf6b79ec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0a64f0d1c9f39e727bb88e2c96fc5ef2b586bff21b55ca551a6fdd8bb0d5cb7d81dea2a2bde1d48f4673e22f828e79225664029bd8f39e1b4ecd3327e5cd80
|
7
|
+
data.tar.gz: 8998baf5668e58f1ee26ac2d19ba0def65813a8ebcc572e78a762e138fd81c877d70ee9916f990d7f497e2d06ca5c6032cd2782e470f705ca875f072d63530aa
|
@@ -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模块".
|
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,19 @@ 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}模块下载完成...".
|
82
|
+
Pod::UI.puts "#{moduleName}模块下载完成...".green
|
83
83
|
end
|
84
84
|
end
|
85
85
|
if moduleTag != nil and !moduleTag.empty?
|
86
|
-
|
86
|
+
result = system("cd #{path_module} && git fetch && git checkout #{moduleTag}")
|
87
|
+
raise "发生错误" unless result
|
87
88
|
# `cd #{path_module} && git fetch && git checkout #{moduleTag}`
|
88
|
-
Pod::UI.puts "发生错误#{
|
89
|
+
# Pod::UI.puts "发生错误#{result}".red
|
89
90
|
else
|
90
|
-
|
91
|
-
|
91
|
+
result = system("cd #{path_module} && git fetch && git checkout #{moduleBranch} && git pull origin #{moduleBranch}")
|
92
|
+
raise "发生错误" unless result
|
93
|
+
|
94
|
+
# Pod::UI.puts "发生错误#{result}".red
|
92
95
|
# `cd #{path_module} && git fetch && git checkout #{moduleBranch} && git pull origin #{moduleBranch}`
|
93
96
|
end
|
94
97
|
if appspecs != nil
|
@@ -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
|
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
|
-
'
|
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
|
-
|
60
|
+
YAML.load_file(config_name)
|
61
|
+
# raise "请在你的根目录配置创建并配置HBHConfig.yml文件"
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
@@ -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
|
-
|
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
|
-
|
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
|
31
|
+
git_hooks = "#{File.dirname(__FILE__)}/../../script_source/#{file_name}"
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
67
|
+
|
68
|
+
|
40
69
|
end
|
41
70
|
end
|
42
71
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
then
|
5
|
-
|
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
|
-
|
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.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zanju
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-23 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.
|
144
|
+
rubygems_version: 3.3.11
|
128
145
|
signing_key:
|
129
146
|
specification_version: 4
|
130
147
|
summary: A longer description of cocoapods-hbh.
|