cocoapods-hbh 0.0.2 → 0.0.3

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: 416d296eacf21ea795f369ce67716788f512101da11b1975f95fcb31d0201d92
4
- data.tar.gz: 5dde5bfb57c073b6db07c2b7094a97f7830ba466e3c82d1c4e0a9cc998917d2e
3
+ metadata.gz: 31f2592765405050041e12717abc2b09cfd47f330e051f4de48b50ebe20dc502
4
+ data.tar.gz: 9cdb8ece30e50c8997e758a46acd773bc7bd6685ba4fbd5faa83bc54e63ecb28
5
5
  SHA512:
6
- metadata.gz: b8054f00ec0d7b35bfd1dd00263f89e9ae79987c3a33a3d3130653bc8cf9ef53e8357f63a8a73dd98de6af4c4e97f0753b2790bf29f4cd3404a2d64328add7be
7
- data.tar.gz: 327c35772d4bdb96a701f9aa2fe2328ab0b2bf106abc28da4e48a84d038d794ad6d88e9624ca7646edf81539add3cc111a79b0948e13990b1e175c936f6135b6
6
+ metadata.gz: 5047868bf505be88016941cd3b4966fa7c1e4be02af0e7db568a66ec02a7d873b4322c1988eb2d0a085b2c1da52ba329a1b143fc77a82c11f024c0625482f504
7
+ data.tar.gz: 30d0a3e632d08d03bf9ea88bcb8259ee2d52e20cf4e74873d741d98a26be6dceafe0d4ad41c093aa3f64f1f71c7c44fc9571caf847aa93685c9555c1874b94ce
@@ -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
@@ -4,30 +4,7 @@ require 'fileutils'
4
4
  module CocoapodsGitHooks
5
5
  class GitHooksManager
6
6
  class << self
7
- # @return [Array<String>]
8
- def hook_types
9
- %w(applypatch-msg commit-msg fsmonitor-watchman post-update pre-applypatch pre-commit pre-merge-commit pre-push pre-rebase prepare-commit-msg push-to-checkout)
10
- end
11
-
12
- # @return [TargetDefinition]
13
- def abstract_target_of_githooks
14
- abstract_target = nil
15
- podfile = Pod::Config.instance.podfile
16
- podfile.target_definition_list.each do |target|
17
- if target.name == 'Githooks'
18
- abstract_target = target
19
- break
20
- end
21
- end unless podfile.target_definition_list.nil?
22
-
23
- if abstract_target.nil?
24
- Pod::UI.puts 'The abstract_target of SyncGithooks is not defined.'
25
- return nil
26
- end
27
-
28
- abstract_target
29
- end
30
-
7
+
31
8
  # @param [TargetDefinition]
32
9
  # @return [Array<Dependency>]
33
10
  def dependencies_in_target(abstract_target)
@@ -39,85 +16,23 @@ module CocoapodsGitHooks
39
16
  Pod::UI.puts 'Can not find .git directory.'
40
17
  return false
41
18
  end
42
-
43
19
  true
44
20
  end
45
21
 
46
- # @param [Array<Dependency>] dependencies
47
- def sync_githooks_in_dependencies(dependencies)
48
- pods_directory = "#{Dir.pwd}/Pods"
49
- hook_dependencies = Hash.new([])
50
- dependencies.each do |dependency|
51
- dependency_directory = if dependency.local?
52
- File.expand_path(dependency.external_source[:path])
53
- else
54
- "#{pods_directory}/#{dependency.name}"
55
- end
56
- hook_types.each { |hook_type|
57
- file_path = "#{dependency_directory}/githooks/#{hook_type}"
58
- if File.exist?(file_path)
59
- hook_dependencies[hook_type] += [dependency]
60
- end
61
- }
62
- end
63
- git_hook_directory = '.git/hooks'
64
- hook_dependencies.each_pair { |key, dependencies|
65
- file_path = "#{git_hook_directory}/#{key}"
66
-
67
- File.delete(file_path) if File.exist?(file_path)
68
-
69
- File.new(file_path, 'w')
70
- File.open(file_path, File::RDWR) do |file|
71
- file.write("#!/bin/sh\n")
72
- file.write("#!/usr/bin/env ruby\n")
73
- file.write("#!/usr/bin/env python\n")
74
-
75
- dependencies.each do |dependency|
76
- dependency_directory = if dependency.local?
77
- File.expand_path(dependency.external_source[:path])
78
- else
79
- "#{pods_directory}/#{dependency.name}"
80
- end
81
-
82
- hook_file_path = "#{dependency_directory}/githooks/#{key}"
83
-
84
- file.write("# #{dependency.name} githook\n")
85
- file.write("if [ -f \"#{hook_file_path}\" ]; then\n")
86
- file.write(" function #{dependency.name}(){\n")
87
- file.write(" local script_directory=#{dependency_directory}/scripts\n")
88
- File.readlines(hook_file_path).each { |line|
89
- file.write(" #{line}")
90
- }
91
- file.write("\n }\n")
92
- file.write(" #{dependency.name}\n")
93
- file.write("fi\n")
94
- end
95
-
96
- FileUtils.chmod('+x', file_path)
97
- end
98
- }
99
- end
100
-
101
22
  def sync
102
- Pod::UI.message 'Start syncing Git Hook' do
103
23
  return unless validate_git_directory?
104
-
105
- FileUtils.mkdir '.git/hooks' unless File.directory?('.git/hooks')
106
-
107
- abstract_target = abstract_target_of_githooks
108
- return if abstract_target.nil?
109
- dependencies = dependencies_in_target(abstract_target)
110
- if dependencies.nil? || dependencies.empty?
111
- Pod::UI.warn 'The dependencies of SyncGithooks is nil or empty.'
112
- return
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)
113
32
  end
114
- dependencies.each { |dependency|
115
- Pod::UI.message "- #{dependency.name}"
116
- }
117
- sync_githooks_in_dependencies(dependencies)
118
33
  end
119
- Pod::UI.message 'Githooks are synced'
120
- end
34
+
35
+
121
36
  end
122
37
  end
123
38
  end
@@ -1,6 +1,7 @@
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'
4
5
 
5
6
  module Pod
6
7
  class Command
@@ -28,16 +29,16 @@ module Pod
28
29
  婚博会组件依赖管理插件
29
30
  DESC
30
31
 
31
- self.arguments = 'hbhCocoapods插件'
32
+ # self.arguments = 'hbhCocoapods插件'
32
33
 
33
34
  def initialize(argv)
34
- @name = argv.shift_argument
35
+ @help = argv.flag?('help').blank? ? 'help' : argv.flag?('help')
35
36
  super
36
37
  end
37
38
 
38
39
  def validate!
39
40
  super
40
- help! 'A Pod name is required.' unless @name
41
+ help! '暂时还没有帮助信息' unless @help
41
42
  end
42
43
 
43
44
  def run
@@ -1,9 +1,7 @@
1
+ require 'cocoapods'
1
2
  require 'cocoapods-hbh/command/hbh'
2
3
 
3
- require 'cocoapods'
4
4
 
5
- module CocoapodsHbhHooks
6
- Pod::HooksManager.register('cocoapods-hbhhooks', :pre_install) do |_context, _|
5
+ Pod::HooksManager.register('cocoapods-hbhhooks', :pre_install) do |_context, _|
7
6
 
8
- end
9
7
  end
@@ -1,52 +1,61 @@
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
 
7
- def config_file
8
- config_file_with_configuration_env(configuration_env)
8
+ def write_config ()
9
+ {
10
+ "hbh_specs_env" =>
11
+ {
12
+ "specs_name" => "私有仓库名称",
13
+ "specs_url" => "私有仓库地址"
14
+ },
15
+ "submodule_env" =>
16
+ {
17
+ "sub_path" => "子模块存储路径",
18
+ "sub_url" => "子模块远程厂库地址"
19
+ }
20
+ }
9
21
  end
10
22
 
11
23
  def template_hash
12
- {
13
- 'configuration_env' => { description: '编译环境', default: 'dev', selection: %w[dev debug_iphoneos release_iphoneos] },
14
- }
24
+ {
25
+ 'hbh_specs_env' => { description: '私有仓库环境',
26
+ default: {
27
+ 'specs_name' => { description: '私有仓库名称' },
28
+ 'specs_url' => { description: '私有仓库地址' },
29
+ }
30
+ },
31
+
32
+ 'submodule_env' => { description: '子仓库环境',
33
+ default: {
34
+ 'sub_path' => { description: '子模块存储路径' },
35
+ 'sub_url' => { description: '子模块厂库地址' },
36
+ }
37
+ },
38
+ }
15
39
  end
16
40
 
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
41
+ def sync_config(config)
42
+ File.open(config_file_with_configuration(), 'w+') do |f|
43
+ f.write(config.to_yaml)
44
+ end
27
45
  end
28
46
 
47
+
29
48
  def config_file
30
- "HBHConfig.yml"
49
+ config_file_with_configuration()
31
50
  end
32
-
33
- def set_configuration_env(env)
34
- @configuration_env = env
51
+
52
+ def config_name
53
+ "HBHConfig.yml"
35
54
  end
36
55
 
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
56
+
57
+ def config_file_with_configuration()
58
+ file = config_name
50
59
  file_path = "#{Pod::Config.instance.installation_root}/#{file}"
51
60
  if file_path.blank?
52
61
  file_path = "#{Pod::Config.instance.home_dir}/#{file}"
@@ -56,12 +65,16 @@ module HBHConfig
56
65
  end
57
66
 
58
67
  def load_config
59
- if File.exist?(config_file)
60
- YAML.load_file(config_file)
68
+ if File.exist?(config_name)
69
+ YAML.load_file(config_name)
61
70
  else
62
71
  default_config
63
72
  end
64
73
  end
74
+
75
+ def default_config
76
+ @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
77
+ end
65
78
 
66
79
  def initialize
67
80
 
@@ -71,7 +84,7 @@ module HBHConfig
71
84
  if config.respond_to?(method)
72
85
  config.send(method, *args)
73
86
  elsif template_hash.keys.include?(method.to_s)
74
- raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_file} 中设置, 请执行 init 命令配置或手动修改配置文件".red
87
+ raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_name} 中设置, 请执行 init 命令配置或手动修改配置文件".red
75
88
  else
76
89
  super
77
90
  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.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,2 +1 @@
1
1
  require 'cocoapods-hbh/command'
2
- require 'cocoapods-hbh/source_provider_hook'
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.2
4
+ version: 0.0.3
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-13 00:00:00.000000000 Z
11
+ date: 2021-09-14 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,17 +89,17 @@ 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
82
96
  - lib/cocoapods-hbh/command/custom/sync_githooks.rb
83
97
  - lib/cocoapods-hbh/command/hbh.rb
84
98
  - lib/cocoapods-hbh/command/module/add_module.rb
85
99
  - lib/cocoapods-hbh/config/config.rb
100
+ - lib/cocoapods-hbh/config/config_asker.rb
86
101
  - lib/cocoapods-hbh/gem_version.rb
87
102
  - lib/cocoapods-hbh/helpers/git_depend.rb
88
- - lib/cocoapods-hbh/source_provider_hook.rb
89
103
  - lib/cocoapods_plugin.rb
90
104
  homepage: https://github.com/EXAMPLE/cocoapods-hbh
91
105
  licenses:
@@ -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
@@ -1,11 +0,0 @@
1
-
2
- require 'cocoapods-hbh/command/custom/sync_githooks'
3
-
4
- module CocoapodsGitHooks
5
- Pod::HooksManager.register('cocoapods-hbh', :post_install) do |context|
6
- CocoapodsGitHooks::GitHooksManager.sync
7
- end
8
- Pod::HooksManager.register('cocoapods-hbh', :post_update) do |context|
9
- CocoapodsGitHooks::GitHooksManager.sync
10
- end
11
- end