cocoapods-sync-githooks 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '02281ce5f4aeb33974bfe39e5362a8d1b68743f707bcfcc98aae18285df82f31'
4
+ data.tar.gz: 84c4580751acaeaf9e650227a1b86d1cbbd8baf5203872d306ff19b8e0c3bd07
5
+ SHA512:
6
+ metadata.gz: 35a7a54241bad70d9e0e53cd2c83d66149deb35f8693d2accd1299f5c13f15e1ba9f7c325eee201497435656e478fbb7f7a885e43468ae8c3db61a2582d10405
7
+ data.tar.gz: 843fa98f679cc46d71a55d0fb93874f215a85f1163c4acd4abad0539f824448dae6b4c9fd6b789c526ebf5a143da7613f2fdef5a9067335f3b819195f09189e8
@@ -0,0 +1 @@
1
+ require 'cocoapods-sync-githooks/gem_version'
@@ -0,0 +1 @@
1
+ require 'cocoapods-sync-githooks/command/githooks'
@@ -0,0 +1,44 @@
1
+ module Pod
2
+ class Command
3
+ # This is an example of a cocoapods plugin adding a top-level subcommand
4
+ # to the 'pod' command.
5
+ #
6
+ # You can also create subcommands of existing or new commands. Say you
7
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
8
+ # (e.g. `pod list deprecated`), there are a few things that would need
9
+ # to change.
10
+ #
11
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
12
+ # the class to exist in the the Pod::Command::List namespace
13
+ # - change this class to extend from `List` instead of `Command`. This
14
+ # tells the plugin system that it is a subcommand of `list`.
15
+ # - edit `lib/cocoapods_plugins.rb` to require this file
16
+ #
17
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18
+ # in the `plugins.json` file, once your plugin is released.
19
+ #
20
+ class Githooks < Command
21
+ self.summary = 'Short description of cocoapods-sync-githooks.'
22
+
23
+ self.description = <<-DESC
24
+ Longer description of cocoapods-sync-githooks.
25
+ DESC
26
+
27
+ self.arguments = 'NAME'
28
+
29
+ def initialize(argv)
30
+ @name = argv.shift_argument
31
+ super
32
+ end
33
+
34
+ def validate!
35
+ super
36
+ help! 'A Pod name is required.' unless @name
37
+ end
38
+
39
+ def run
40
+ UI.puts "Add your implementation for the cocoapods-sync-githooks plugin in #{__FILE__}"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsSyncGithooks
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,123 @@
1
+ require 'cocoapods'
2
+ require 'fileutils'
3
+
4
+ module CocoapodsGitHooks
5
+ class GitHooksManager
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
+
31
+ # @param [TargetDefinition]
32
+ # @return [Array<Dependency>]
33
+ def dependencies_in_target(abstract_target)
34
+ abstract_target.dependencies
35
+ end
36
+
37
+ def validate_git_directory?
38
+ unless File.directory?(".git")
39
+ Pod::UI.puts 'Can not find .git directory.'
40
+ return false
41
+ end
42
+
43
+ true
44
+ end
45
+
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
+ def sync
102
+ Pod::UI.message 'Start syncing Git Hook' do
103
+ 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
113
+ end
114
+ dependencies.each { |dependency|
115
+ Pod::UI.message "- #{dependency.name}"
116
+ }
117
+ sync_githooks_in_dependencies(dependencies)
118
+ end
119
+ Pod::UI.message 'Githooks are synced'
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,11 @@
1
+ require 'cocoapods-sync-githooks/command'
2
+ require 'cocoapods-sync-githooks/sync_githooks'
3
+
4
+ module CocoapodsGitHooks
5
+ Pod::HooksManager.register('cocoapods-sync-githooks', :post_install) do |context|
6
+ CocoapodsGitHooks::GitHooksManager.sync
7
+ end
8
+ Pod::HooksManager.register('cocoapods-sync-githooks', :post_update) do |context|
9
+ CocoapodsGitHooks::GitHooksManager.sync
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-sync-githooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - dirtmelon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ description: A short description of cocoapods-sync-githooks.
42
+ email:
43
+ - 0xffdirtmelon@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-sync-githooks.rb
49
+ - lib/cocoapods-sync-githooks/command.rb
50
+ - lib/cocoapods-sync-githooks/command/githooks.rb
51
+ - lib/cocoapods-sync-githooks/gem_version.rb
52
+ - lib/cocoapods-sync-githooks/sync_githooks.rb
53
+ - lib/cocoapods_plugin.rb
54
+ homepage: https://github.com/EXAMPLE/cocoapods-sync-githooks
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.0.4
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: A longer description of cocoapods-sync-githooks.
77
+ test_files: []