cocoapods-hbh 0.0.1 → 0.1.2

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: ce18e2b95339d2db022c65c616c7ca55fb29c372a3fa534ddd3fb7b4430e46d9
4
- data.tar.gz: 4ad932b3d91390c27f7d9895e016a3ebdacbbe7146a8d5c2972e728d62138889
3
+ metadata.gz: da626f7b976f6a16457e2733f07349f4845f02bd52f963494355ff3ed55f2086
4
+ data.tar.gz: 273c9e9e84053abf887b4427d357bf29505ef01cea7666b60285f210d304cea0
5
5
  SHA512:
6
- metadata.gz: 0edef73beae1ffcd658707c201e120eed4df01958c402db5ea92d61147648c824628ec3ba3a71f1adb71427af415d5e36c86921e246bc9115b2abbbbb56fb0b8
7
- data.tar.gz: c44f0b8a99668bf891432d7a1edff04eb5f8c784837e30caf1eabcad8cb82797a0f5dad14b7af318f5a6d525077ef7f99958e8d99dfd067b4933025a080f920c
6
+ metadata.gz: b5efe9375d521087fc6ee69c60e9fc77f1d13684860ec43db86a29e3781080aa98ac9ca3c5c048e1583ae5f97f352ea12a8619f5525398d64b7cc6c818068e4c
7
+ data.tar.gz: ac52e0157181febf6795126d03a8a40c16a04ff4f7f7d058d3100ce835539b47f8e55175ccd394d98afa14a0d94e98aee14ddbfade003384448f6b80c2b07b25
@@ -0,0 +1,52 @@
1
+ require 'cocoapods-hbh/config/config_asker'
2
+ require 'cocoapods/generate'
3
+
4
+ module Pod
5
+ class Command
6
+ class Hbh < Command
7
+ class Init < Hbh
8
+ def initialize(argv)
9
+
10
+ end
11
+
12
+ def validate!
13
+
14
+ end
15
+
16
+ def run()
17
+ if File.exist?("./HBHConfig.yml")
18
+ Pod::UI.puts "当前目录已有配置文件".yellow
19
+ return
20
+ end
21
+
22
+ Pod::UI.message '开始生成配置文件' do
23
+ config_with_asker
24
+ end
25
+ end
26
+
27
+ def config_with_asker
28
+ asker = HBHConfig::Config::Asker.new
29
+ asker.wellcome_message
30
+
31
+ # config = {}
32
+ # template_hash = HBHConfig.config.template_hash
33
+ # template_hash.each do |k, v|
34
+ # default = begin
35
+ # HBHConfig.config.send(k)
36
+ # rescue StandardError
37
+ # nil
38
+ # end
39
+ # config[k] = asker.ask_with_answer(v[:description], default, v[:selection])
40
+ # end
41
+
42
+ HBHConfig.config.sync_config(HBHConfig.config.write_config)
43
+ asker.done_message
44
+ end
45
+ end
46
+
47
+ def generate_obj ()
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  require 'cocoapods'
2
- require 'cocoapods-hbh/command/sub_module/add_submodule'
2
+ require 'cocoapods-hbh/command/module/add_module'
3
3
 
4
4
 
5
5
  module Pod
@@ -11,11 +11,17 @@ module Pod
11
11
  unless name
12
12
  raise StandardError, 'A dependency requires a name.'
13
13
  end
14
- add_sub_module = AddSubModule.new(@current_target_definition)
15
- add_sub_module.pod_moudle(name, *requirements)
16
- # current_target_definition.store_pod(name, *requirements)
14
+ add_sub_module = AddModule.new(@current_target_definition)
15
+ add_sub_module.pod_submoudle(name, *requirements)
17
16
  end
18
17
 
18
+ def pod_hbh(name = nil, *requirements)
19
+ unless name
20
+ raise StandardError, 'A dependency requires a name.'
21
+ end
22
+ add_sub_module = AddModule.new(@current_target_definition)
23
+ add_sub_module.pod_private(name, *requirements)
24
+ end
19
25
  end
20
26
 
21
27
  end
@@ -5,8 +5,6 @@ module Pod
5
5
  class Repo < Command
6
6
  class Push < Repo
7
7
  class HBH < Push
8
- # pod repo push HBHSpecs HBHNetwork.podspec、
9
- # --sources='http://gitlab.jiehun.tech/App/iOS/Modularization/HBHSpecs.git,https://github.com/CocoaPods/Specs' --allow-warnings
10
8
  def initialize(argv)
11
9
  super
12
10
  hbh_specs_env = HBHConfig.config.hbh_specs_env
@@ -0,0 +1,38 @@
1
+ require 'cocoapods'
2
+ require 'fileutils'
3
+
4
+ module CocoapodsGitHooks
5
+ class GitHooksManager
6
+ class << self
7
+
8
+ # @param [TargetDefinition]
9
+ # @return [Array<Dependency>]
10
+ def dependencies_in_target(abstract_target)
11
+ abstract_target.dependencies
12
+ end
13
+
14
+ def validate_git_directory?
15
+ unless File.directory?(".git")
16
+ Pod::UI.puts 'Can not find .git directory.'
17
+ return false
18
+ end
19
+ true
20
+ end
21
+
22
+ def sync
23
+ return unless validate_git_directory?
24
+ scr_path = "./Script/pre-commit"
25
+ return unless File::exist?(scr_path)
26
+ pre_path = ".git/hooks/pre-commit"
27
+
28
+ FileUtils.mkdir '.git/hooks' unless File.directory?('.git/hooks')
29
+ if File::exist?(pre_path)
30
+ FileUtils.cp(scr_path, ".git/hooks/")
31
+ FileUtils.chmod('+x', pre_path)
32
+ end
33
+ end
34
+
35
+
36
+ end
37
+ end
38
+ end
@@ -1,6 +1,9 @@
1
1
  require 'cocoapods-hbh/command/common/install'
2
2
  require 'cocoapods-hbh/command/common/podfile'
3
3
  require 'cocoapods-hbh/command/common/push'
4
+ require 'cocoapods-hbh/command/common/hbh_init'
5
+ require 'cocoapods-hbh/command/native/native_install'
6
+ require 'cocoapods-hbh/command/native/native_update'
4
7
 
5
8
  module Pod
6
9
  class Command
@@ -28,16 +31,16 @@ module Pod
28
31
  婚博会组件依赖管理插件
29
32
  DESC
30
33
 
31
- self.arguments = 'hbhCocoapods插件'
34
+ # self.arguments = 'hbhCocoapods插件'
32
35
 
33
36
  def initialize(argv)
34
- @name = argv.shift_argument
37
+ @help = argv.flag?('help').blank? ? 'help' : argv.flag?('help')
35
38
  super
36
39
  end
37
40
 
38
41
  def validate!
39
42
  super
40
- help! 'A Pod name is required.' unless @name
43
+ help! '暂时还没有帮助信息' unless @help
41
44
  end
42
45
 
43
46
  def run
@@ -4,7 +4,7 @@ require 'cocoapods/user_interface'
4
4
 
5
5
  module Pod
6
6
  class Podfile
7
- class AddSubModule
7
+ class AddModule
8
8
  UI = Pod::UserInterface unless defined? UI
9
9
  # @return [TargetDefinition] The current target definition to which the DSL
10
10
  # commands apply.
@@ -23,39 +23,47 @@ module Pod
23
23
  return default
24
24
  end
25
25
  end
26
+
27
+ def pod_private (moduleName, *requirements)
28
+ info = requirements.last
29
+ git = get_info(info, :git, nil)
30
+ sub_config = HBHConfig.config.submodule_env
31
+ remoteUrl = sub_config['sub_url']
32
+ if git.blank?
33
+ if moduleName.include?('/')
34
+ name = moduleName.split('/').first
35
+ requirements.last[:git] = "#{remoteUrl}/#{name}.git"
36
+ else
37
+ requirements.last[:git] = "#{remoteUrl}/#{moduleName}.git"
38
+ end
39
+ end
40
+ Pod::UI.puts "#{moduleName}使用私有库".yellow
41
+ current_target_definition.store_pod moduleName, *requirements
42
+ end
26
43
 
27
44
 
28
45
  # 添加模块 模块名称为podspec的名称,路径默认为Module/下的模块,tag或者branch 优先使用tag,默认develop分支
29
- # (moduleName, submodule: true, moduleTag: nil, moduleBranch: 'develop', appspecs: nil)
30
- def pod_moudle (moduleName, *requirements)
46
+ # (moduleName, : true, moduleTag: nil, moduleBranch: 'develop', appspecs: nil)
47
+ def pod_submoudle (moduleName, *requirements)
31
48
  info = requirements.last
32
- # git = get_info(info, :git, nil)
33
-
34
-
35
- # if git.blank?
36
- # hbh_git = get_info(info, :hbh_git, nil)
37
- # if moduleName.include?('/')
38
- # name = moduleName.split('/').first
39
- # requirements.last[:git] = "#{remoteUrl}/#{name}.git"
40
- # else
41
- # requirements.last[:git] = "#{remoteUrl}/#{moduleName}.git"
42
- # end
43
- # requirements.last.delete(:hbh_git)
44
- # end
45
-
46
49
  is_submodule = get_info(info, :submodule, true)
47
50
  if is_submodule
48
51
  if info.nil? then raise "请输入正确的参数" end
49
52
  return requirements unless info.is_a?(Hash)
50
53
 
51
54
  moduleTag = get_info(info, :tag, nil)
52
- moduleBranch = get_info(info, :branch, "develop")
55
+ moduleBranch = get_info(info, :branch, nil)
56
+ if moduleTag.nil? && moduleBranch.nil?
57
+ Pod::UI.puts "请配置依赖tag或者branch".red
58
+ exit()
59
+ end
60
+
53
61
  appspecs = get_info(info, :appspecs, nil)
54
62
  sub_config = HBHConfig.config.submodule_env
55
63
  remoteUrl = sub_config['sub_url']
56
64
  if remoteUrl.blank?
57
65
  Pod::UI.puts "请配置subModule的sub_url".red
58
- raise "注意: 请配置subModule的sub_url"
66
+ exit()
59
67
  end
60
68
  moduleRoot = sub_config['sub_path'].blank? ? "Modules" : sub_config['sub_path']
61
69
 
@@ -0,0 +1,19 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class Installer
5
+ alias old_prepare prepare
6
+ def prepare
7
+ if podfile.plugins.keys.include?('cocoapods-hbh')
8
+ Pod::UI.puts "使用cocoapods-hbh插件"
9
+ spec_version = HBHConfig.config.cocoapods_version
10
+ cocoapods_version = Pod::VERSION
11
+ if spec_version != cocoapods_version
12
+ Pod::UI.puts "注意: 你当前的pod版本和指定的版本不一致,当前指定版本为#{spec_version},您的版本为#{cocoapods_version}".red
13
+ exit()
14
+ end
15
+ end
16
+ old_prepare()
17
+ end
18
+ end
19
+ end
File without changes
@@ -1,9 +1,15 @@
1
- require 'cocoapods-hbh/command/hbh'
2
-
3
1
  require 'cocoapods'
2
+ require 'cocoapods-hbh/command/hbh'
3
+ require 'cocoapods-hbh/git_hooks/githooks_sync'
4
4
 
5
- module CocoapodsHbhHooks
6
- Pod::HooksManager.register('cocoapods-hbhhooks', :pre_install) do |_context, _|
7
-
5
+ module CocoapodsHBHGitHooks
6
+ Pod::HooksManager.register('cocoapods-hbh', :post_install) do |context|
7
+ GitHooksSync.new.sync()
8
+ end
9
+ Pod::HooksManager.register('cocoapods-hbh', :post_update) do |context|
10
+ GitHooksSync.new.sync()
8
11
  end
12
+ Pod::HooksManager.register('cocoapods-hbh', :post_install) do |context|
13
+ Pod::UI.puts "恭喜你, 你已经 `pod install` 结束了."
14
+ end
9
15
  end
@@ -1,52 +1,45 @@
1
1
  require 'yaml'
2
-
2
+ require 'cocoapods-hbh/gem_version'
3
+ # require 'cocoapods/generate'
3
4
 
4
5
  module HBHConfig
5
6
  class Config
6
-
7
- def config_file
8
- config_file_with_configuration_env(configuration_env)
7
+
8
+ def template_hash
9
+ {
10
+ 'hbh_specs_env' => {
11
+ 'description' => '私有仓库环境配置',
12
+ 'specs_name' => '私有仓库名称',
13
+ 'specs_url' => '私有仓库地址',
14
+ },
15
+ 'submodule_env' => {
16
+ 'description' => '子仓库环境配置',
17
+ 'sub_path' => '子模块存储路径' ,
18
+ 'sub_url' => '子模块厂库地址' ,
19
+ },
20
+ 'is_git_hooks' => 'false',
21
+ 'cocoapods_version' => '1.10.1',
22
+ }
9
23
  end
10
24
 
11
- def template_hash
12
- {
13
- 'configuration_env' => { description: '编译环境', default: 'dev', selection: %w[dev debug_iphoneos release_iphoneos] },
14
- }
25
+ def sync_config(config)
26
+ File.open(config_file_with_configuration(), 'w+') do |f|
27
+ f.write(config.to_yaml)
28
+ end
15
29
  end
16
30
 
17
- def configuration_env
18
- #如果是dev 再去 podfile的配置文件中获取,确保是正确的, pod update时会用到
19
- if @configuration_env == "dev" || @configuration_env == nil
20
- if Pod::Config.instance.podfile
21
- configuration_env ||= Pod::Config.instance.podfile.configuration_env
22
- end
23
- configuration_env ||= "dev"
24
- @configuration_env = configuration_env
25
- end
26
- @configuration_env
27
- end
28
31
 
29
32
  def config_file
30
- "HBHConfig.yml"
33
+ config_file_with_configuration()
31
34
  end
32
-
33
- def set_configuration_env(env)
34
- @configuration_env = env
35
+
36
+ def config_name
37
+ "HBHConfig.yml"
35
38
  end
36
39
 
37
- def config_file_with_configuration_env(configuration_env)
38
- file = config_file
39
- if configuration_env == "release_iphoneos"
40
- file = config_release_iphoneos_file
41
- puts "\n====== #{configuration_env} 环境 ========"
42
- elsif configuration_env == "debug_iphoneos"
43
- file = config_debug_iphoneos_file
44
- puts "\n====== #{configuration_env} 环境 ========"
45
- elsif configuration_env == "dev"
46
- puts "\n====== #{configuration_env} 环境 ========"
47
- else
48
- raise "\n===== #{configuration_env} 参数有误,请检查%w[dev debug_iphoneos release_iphoneos]===="
49
- end
40
+
41
+ def config_file_with_configuration()
42
+ file = config_name
50
43
  file_path = "#{Pod::Config.instance.installation_root}/#{file}"
51
44
  if file_path.blank?
52
45
  file_path = "#{Pod::Config.instance.home_dir}/#{file}"
@@ -56,12 +49,20 @@ module HBHConfig
56
49
  end
57
50
 
58
51
  def load_config
59
- if File.exist?(config_file)
60
- YAML.load_file(config_file)
52
+ if File.exist?(config_name)
53
+ YAML.load_file(config_name)
61
54
  else
62
- default_config
55
+ aFile = File.new(config_name, "w+")
56
+ if aFile
57
+ aFile.syswrite(template_hash.to_yaml)
58
+ end
59
+ raise "请在你的根目录配置创建并配置HBHConfig.yml文件"
63
60
  end
64
61
  end
62
+
63
+ def default_config
64
+ @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
65
+ end
65
66
 
66
67
  def initialize
67
68
 
@@ -71,7 +72,11 @@ module HBHConfig
71
72
  if config.respond_to?(method)
72
73
  config.send(method, *args)
73
74
  elsif template_hash.keys.include?(method.to_s)
74
- raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_file} 中设置, 请执行 init 命令配置或手动修改配置文件".red
75
+ if method.to_s == "is_git_hooks"
76
+
77
+ else
78
+ raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_name} 中设置, 请执行 init 命令配置或手动修改配置文件".red
79
+ end
75
80
  else
76
81
  super
77
82
  end
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'cocoapods-hbh/config/config'
3
+
4
+ module HBHConfig
5
+ class Config
6
+ class Asker
7
+ def show_prompt
8
+ print ' > '.green
9
+ end
10
+
11
+ def ask_with_answer(question, pre_answer, selection)
12
+ print "\n#{question}\n"
13
+
14
+ print_selection_info = lambda {
15
+ print "可选值:[ #{selection.join(' / ')} ]\n" if selection
16
+ }
17
+ print_selection_info.call
18
+ print "旧值:#{pre_answer}\n" unless pre_answer.nil?
19
+
20
+ answer = ''
21
+ loop do
22
+ show_prompt
23
+ answer = STDIN.gets.chomp.strip
24
+
25
+ if answer == '' && !pre_answer.nil?
26
+ answer = pre_answer
27
+ print answer.yellow
28
+ print "\n"
29
+ end
30
+
31
+ next if answer.empty?
32
+ break if !selection || selection.include?(answer)
33
+
34
+ print_selection_info.call
35
+ end
36
+
37
+ answer
38
+ end
39
+
40
+ def wellcome_message
41
+ print <<~EOF
42
+
43
+ 开始设置二进制化初始信息.
44
+ 所有的信息都会保存在 #{HBHConfig.config.config_file} 文件中.
45
+
46
+ 你可以在对应目录下手动添加编辑该文件. 文件包含的配置信息样式如下:
47
+
48
+ #{HBHConfig.config.default_config.to_yaml}
49
+ EOF
50
+ end
51
+
52
+ def done_message
53
+ print "\n设置完成.\n".green
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module CocoapodsHbh
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'cocoapods'
2
+ require 'fileutils'
3
+
4
+ module CocoapodsHBHGitHooks
5
+ class GitHooksSync
6
+ def sync
7
+
8
+ return unless HBHConfig.config.is_git_hooks
9
+
10
+ Pod::UI.puts "开始同步git拦截设置"
11
+ if !File.directory?(".git")
12
+ Pod::UI.puts "没有发现git工程"
13
+ return
14
+ end
15
+
16
+ # 在当前ruby项目的githook文件copy到项目里去做拦截
17
+ # 如果项目里配置了 .git-hooks 文件件,将把里面的内容copy到项目里去做拦截
18
+ # 项目里的.git-hooks 配置优先
19
+ git_hooks = "#{File.dirname(__FILE__)}/../../script_source/pre-commit"
20
+
21
+ # if File.directory?(".git-hooks")
22
+
23
+ # end
24
+
25
+ git_hooks = '.git-hooks/.' unless Dir['.git-hooks/*'].empty?
26
+
27
+ if !File.directory?(".git/hooks")
28
+ FileUtils.mkdir ".git/hooks"
29
+ 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}")
38
+ end
39
+ Pod::UI.puts "结束同步git拦截设置"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,37 @@
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文件需要检查'
35
+ fi
36
+
37
+ 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.0.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zanju
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-10 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cocoapods-generate
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -75,16 +89,22 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - lib/cocoapods-hbh.rb
77
91
  - lib/cocoapods-hbh/command.rb
92
+ - lib/cocoapods-hbh/command/common/hbh_init.rb
78
93
  - lib/cocoapods-hbh/command/common/install.rb
79
94
  - lib/cocoapods-hbh/command/common/podfile.rb
80
95
  - lib/cocoapods-hbh/command/common/push.rb
81
- - lib/cocoapods-hbh/command/custom/pod_push.rb
96
+ - lib/cocoapods-hbh/command/custom/sync_githooks.rb
82
97
  - lib/cocoapods-hbh/command/hbh.rb
83
- - lib/cocoapods-hbh/command/sub_module/add_submodule.rb
98
+ - lib/cocoapods-hbh/command/module/add_module.rb
99
+ - lib/cocoapods-hbh/command/native/native_install.rb
100
+ - lib/cocoapods-hbh/command/native/native_update.rb
84
101
  - lib/cocoapods-hbh/config/config.rb
102
+ - lib/cocoapods-hbh/config/config_asker.rb
85
103
  - lib/cocoapods-hbh/gem_version.rb
104
+ - lib/cocoapods-hbh/git_hooks/githooks_sync.rb
86
105
  - lib/cocoapods-hbh/helpers/git_depend.rb
87
106
  - lib/cocoapods_plugin.rb
107
+ - lib/script_source/pre-commit
88
108
  homepage: https://github.com/EXAMPLE/cocoapods-hbh
89
109
  licenses:
90
110
  - MIT
@@ -1 +0,0 @@
1
- pod repo push HBHSpecs HBHNetwork.podspec --sources='http://gitlab.jiehun.tech/App/iOS/Modularization/HBHSpecs.git,https://github.com/CocoaPods/Specs' --allow-warnings