cocoapods-force-push 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: f23a46560a26690a5f6add393e9ace0d40fc4229d24f4d8ba61b35b9928f3200
4
+ data.tar.gz: c0114ef9925c8b930a3771f7ba87b7755e7d9073f18e1aad7f471c697eb7f595
5
+ SHA512:
6
+ metadata.gz: 81a33d34b53f906cd72b61f25104dd98aa20152c231a3ae20bd6c48ee92ab3caa77a11c90900c709e1f9138b19ca6af65dfb42ec3a87e4f5f6cf45d9aadd3612
7
+ data.tar.gz: a43726ed808f746b4fd801474c36698ca4e37a9860c74b064e0dbdb3fdbbcb106745bafadb40e11188dbc754b9fae809247ab0e5478c0abb09bcf88efea3fc0d
@@ -0,0 +1 @@
1
+ require 'cocoapods-force-push/gem_version'
@@ -0,0 +1 @@
1
+ require 'cocoapods-force-push/command/push'
@@ -0,0 +1,295 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'cocoapods'
5
+
6
+ module Pod
7
+ class Command
8
+ class Force < Command
9
+ class Repo < Force
10
+ class Push < Repo
11
+ self.summary = 'Push new specifications to a spec-repo'
12
+
13
+ self.description = <<-DESC
14
+ Validates `NAME.podspec` or `*.podspec` in the current working dir,
15
+ creates a directory and version folder for the pod in the local copy of
16
+ `REPO` (#{Config.instance.repos_dir}/[REPO]), copies the podspec file into the
17
+ version directory, and finally it pushes `REPO` to its remote.
18
+ DESC
19
+
20
+ self.arguments = [
21
+ CLAide::Argument.new('REPO', true),
22
+ CLAide::Argument.new('NAME.podspec', false),
23
+ ]
24
+
25
+ def self.options
26
+ [
27
+ ['--allow-warnings', 'Allows pushing even if there are warnings'],
28
+ ['--use-libraries', 'Linter uses static libraries to install the spec'],
29
+ ['--use-modular-headers', 'Lint uses modular headers during installation'],
30
+ ["--sources=#{Pod::TrunkSource::TRUNK_REPO_URL}", 'The sources from which to pull dependent pods ' \
31
+ '(defaults to all available repos). Multiple sources must be comma-delimited'],
32
+ ['--local-only', 'Does not perform the step of pushing REPO to its remote'],
33
+ ['--no-private', 'Lint includes checks that apply only to public repos'],
34
+ ['--skip-import-validation', 'Lint skips validating that the pod can be imported'],
35
+ ['--skip-tests', 'Lint skips building and running tests during validation'],
36
+ ['--commit-message="Fix bug in pod"', 'Add custom commit message. Opens default editor if no commit ' \
37
+ 'message is specified'],
38
+ ['--use-json', 'Convert the podspec to JSON before pushing it to the repo'],
39
+ ['--swift-version=VERSION', 'The `SWIFT_VERSION` that should be used when linting the spec. ' \
40
+ 'This takes precedence over the Swift versions specified by the spec or a `.swift-version` file'],
41
+ ['--no-overwrite', 'Disallow pushing that would overwrite an existing spec'],
42
+ ].concat(super)
43
+ end
44
+
45
+ def initialize(argv)
46
+ @allow_warnings = argv.flag?('allow-warnings')
47
+ @local_only = argv.flag?('local-only')
48
+ @repo = argv.shift_argument
49
+ @source = source_for_repo
50
+ @source_urls = argv.option('sources', config.sources_manager.all.map(&:url).append(Pod::TrunkSource::TRUNK_REPO_URL).uniq.join(',')).split(',')
51
+ @podspec = argv.shift_argument
52
+ @use_frameworks = !argv.flag?('use-libraries')
53
+ @use_modular_headers = argv.flag?('use-modular-headers', false)
54
+ @private = argv.flag?('private', true)
55
+ @message = argv.option('commit-message')
56
+ @commit_message = argv.flag?('commit-message', false)
57
+ @use_json = argv.flag?('use-json')
58
+ @swift_version = argv.option('swift-version', nil)
59
+ @skip_import_validation = argv.flag?('skip-import-validation', false)
60
+ @skip_tests = argv.flag?('skip-tests', false)
61
+ @allow_overwrite = argv.flag?('overwrite', true)
62
+ super
63
+ end
64
+
65
+ def validate!
66
+ super
67
+ help! 'A spec-repo name or url is required.' unless @repo
68
+ unless @source && @source.repo.directory?
69
+ raise Informative,
70
+ "Unable to find the `#{@repo}` repo. " \
71
+ 'If it has not yet been cloned, add it via `pod repo add`.'
72
+ end
73
+ end
74
+
75
+ def run
76
+ UI.puts "semyon: start run" # semyon
77
+ open_editor if @commit_message && @message.nil?
78
+ check_if_push_allowed
79
+ #validate_podspec_files
80
+ check_repo_status
81
+ update_repo
82
+ add_specs_to_repo
83
+ push_repo unless @local_only
84
+ UI.puts "semyon: success!" # semyon
85
+ end
86
+
87
+ #---------------------------------------------------------------------#
88
+
89
+ private
90
+
91
+ # @!group Push sub-steps
92
+
93
+ extend Executable
94
+ executable :git
95
+
96
+ # Open default editor to allow users to enter commit message
97
+ #
98
+ def open_editor
99
+ return if ENV['EDITOR'].nil?
100
+
101
+ file = Tempfile.new('cocoapods')
102
+ File.chmod(0777, file.path)
103
+ file.close
104
+
105
+ system("#{ENV['EDITOR']} #{file.path}")
106
+ @message = File.read file.path
107
+ end
108
+
109
+ # Temporary check to ensure that users do not push accidentally private
110
+ # specs to the master repo.
111
+ #
112
+ def check_if_push_allowed
113
+ if @source.is_a?(CDNSource)
114
+ raise Informative, 'Cannot push to a CDN source, as it is read-only.'
115
+ end
116
+
117
+ remotes, = Executable.capture_command('git', %w(remote --verbose), :capture => :merge, :chdir => repo_dir)
118
+ master_repo_urls = [
119
+ 'git@github.com:CocoaPods/Specs.git',
120
+ 'https://github.com/CocoaPods/Specs.git',
121
+ ]
122
+ is_master_repo = master_repo_urls.any? do |url|
123
+ remotes.include?(url)
124
+ end
125
+
126
+ if is_master_repo
127
+ raise Informative, 'To push to the CocoaPods master repo use ' \
128
+ "the `pod trunk push` command.\n\nIf you are using a fork of " \
129
+ 'the master repo for private purposes we recommend to migrate ' \
130
+ 'to a clean private repo. To disable this check remove the ' \
131
+ 'remote pointing to the CocoaPods master repo.'
132
+ end
133
+ end
134
+
135
+ # Performs a full lint against the podspecs.
136
+ #
137
+ def validate_podspec_files
138
+ # UI.puts "\nValidating #{'spec'.pluralize(count)}".yellow
139
+ # podspec_files.each do |podspec|
140
+ # validator = Validator.new(podspec, @source_urls)
141
+ # validator.allow_warnings = @allow_warnings
142
+ # validator.use_frameworks = @use_frameworks
143
+ # validator.use_modular_headers = @use_modular_headers
144
+ # validator.ignore_public_only_results = @private
145
+ # validator.swift_version = @swift_version
146
+ # validator.skip_import_validation = @skip_import_validation
147
+ # validator.skip_tests = @skip_tests
148
+ # begin
149
+ # validator.validate
150
+ # rescue => e
151
+ # raise Informative, "The `#{podspec}` specification does not validate." \
152
+ # "\n\n#{e.message}"
153
+ # end
154
+ # raise Informative, "The `#{podspec}` specification does not validate." unless validator.validated?
155
+ # end
156
+ end
157
+
158
+ # Checks that the repo is clean.
159
+ #
160
+ # @raise If the repo is not clean.
161
+ #
162
+ # @todo Add specs for staged and unstaged files.
163
+ #
164
+ # @todo Gracefully handle the case where source is not under git
165
+ # source control.
166
+ #
167
+ # @return [void]
168
+ #
169
+ def check_repo_status
170
+ porcelain_status, = Executable.capture_command('git', %w(status --porcelain), :capture => :merge, :chdir => repo_dir)
171
+ clean = porcelain_status == ''
172
+ raise Informative, "The repo `#{@repo}` at #{UI.path repo_dir} is not clean" unless clean
173
+ end
174
+
175
+ # Updates the git repo against the remote.
176
+ #
177
+ # @return [void]
178
+ #
179
+ def update_repo
180
+ UI.puts "Updating the `#{@repo}' repo\n".yellow
181
+ git!(%W(-C #{repo_dir} pull))
182
+ end
183
+
184
+ # Commits the podspecs to the source, which should be a git repo.
185
+ #
186
+ # @note The pre commit hook of the repo is skipped as the podspecs have
187
+ # already been linted.
188
+ #
189
+ # @return [void]
190
+ #
191
+ def add_specs_to_repo
192
+ UI.puts "\nAdding the #{'spec'.pluralize(count)} to the `#{@repo}' repo\n".yellow
193
+ podspec_files.each do |spec_file|
194
+ spec = Pod::Specification.from_file(spec_file)
195
+ output_path = @source.pod_path(spec.name) + spec.version.to_s
196
+ message = if @message && !@message.empty?
197
+ @message
198
+ elsif output_path.exist?
199
+ "[Fix] #{spec}"
200
+ elsif output_path.dirname.directory?
201
+ "[Update] #{spec}"
202
+ else
203
+ "[Add] #{spec}"
204
+ end
205
+
206
+ if output_path.exist? && !@allow_overwrite
207
+ raise Informative, "#{spec} already exists and overwriting has been disabled."
208
+ end
209
+
210
+ FileUtils.mkdir_p(output_path)
211
+
212
+ if @use_json
213
+ json_file_name = "#{spec.name}.podspec.json"
214
+ json_file = File.join(output_path, json_file_name)
215
+ File.open(json_file, 'w') { |file| file.write(spec.to_pretty_json) }
216
+ else
217
+ FileUtils.cp(spec_file, output_path)
218
+ end
219
+
220
+ # only commit if modified
221
+ if repo_git('status', '--porcelain').include?(spec.name)
222
+ UI.puts " - #{message}"
223
+ repo_git('add', spec.name)
224
+ repo_git('commit', '--no-verify', '-m', message)
225
+ else
226
+ UI.puts " - [No change] #{spec}"
227
+ end
228
+ end
229
+ end
230
+
231
+ # Pushes the git repo against the remote.
232
+ #
233
+ # @return [void]
234
+ #
235
+ def push_repo
236
+ UI.puts "\nPushing the `#{@repo}' repo\n".yellow
237
+ repo_git('push', 'origin', 'HEAD')
238
+ end
239
+
240
+ #---------------------------------------------------------------------#
241
+
242
+ private
243
+
244
+ # @!group Private helpers
245
+
246
+ # @return result of calling the git! with args in repo_dir
247
+ #
248
+ def repo_git(*args)
249
+ git!(['-C', repo_dir] + args)
250
+ end
251
+
252
+ # @return [Pathname] The directory of the repository.
253
+ #
254
+ def repo_dir
255
+ @source.specs_dir
256
+ end
257
+
258
+ # @return [Array<Pathname>] The path of the specifications to push.
259
+ #
260
+ def podspec_files
261
+ if @podspec
262
+ path = Pathname(@podspec)
263
+ raise Informative, "Couldn't find #{@podspec}" unless path.exist?
264
+ [path]
265
+ else
266
+ files = Pathname.glob('*.podspec{,.json}')
267
+ raise Informative, "Couldn't find any podspec files in current directory" if files.empty?
268
+ files
269
+ end
270
+ end
271
+
272
+ # @return [Integer] The number of the podspec files to push.
273
+ #
274
+ def count
275
+ podspec_files.count
276
+ end
277
+
278
+ # Returns source for @repo
279
+ #
280
+ # @note If URL is invalid or repo doesn't exist, validate! will throw the error
281
+ #
282
+ # @return [Source]
283
+ #
284
+ def source_for_repo
285
+ config.sources_manager.source_with_name_or_url(@repo) unless @repo.nil?
286
+ rescue
287
+ nil
288
+ end
289
+
290
+ #---------------------------------------------------------------------#
291
+ end
292
+ end
293
+ end
294
+ end
295
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsForcePush
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'cocoapods-force-push/command'
2
+
3
+ # 引用 cocoapods 包
4
+ require 'cocoapods'
5
+
6
+ module CocoapodsForcePush
7
+ # 注册 pod install 钩子
8
+ Pod::HooksManager.register('cocoapods-force-push', :post_install) do |context|
9
+ p "hello world!"
10
+ puts "semyon: hello world!"
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-force-push
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - xunianqiang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-27 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: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-force-push.
42
+ email:
43
+ - xunianqiang@smzdm.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-force-push.rb
49
+ - lib/cocoapods-force-push/command.rb
50
+ - lib/cocoapods-force-push/command/push.rb
51
+ - lib/cocoapods-force-push/gem_version.rb
52
+ - lib/cocoapods_plugin.rb
53
+ homepage: https://github.com/EXAMPLE/cocoapods-force-push
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.0.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A longer description of cocoapods-force-push.
76
+ test_files: []