cocoapods-dylint 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cocoapods-dylint.gemspec +2 -2
- data/lib/pod/command.rb +1 -0
- data/lib/pod/command/lib/dylint.rb +2 -1
- data/lib/pod/command/repo/dypush.rb +291 -0
- data/lib/pod/gem_version.rb +1 -1
- data/lib/{pod/command/lib/validator.rb → validator.rb} +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9c0a644e9cd0acc1f2d7b1a020e135d48ce895e
|
4
|
+
data.tar.gz: 5803803ba9c3ed40c1e64751d147c4d691ba6817
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbe3ac62b834e9cf087eafbf1dcea50e5ab928315943fba504aeac2b1fea94a1ace3dc7386e7bd70b3c648f6349647caad46d4fc1ce1087ddcb3014d7daf7a46
|
7
|
+
data.tar.gz: ad97a1b31e62ea5c470ef0b8d78149d5b686e7f33d9e4a75a155e55fba6793b1a09fa2cb09559e68c0dc7e1f526e8db0e66d37e75160b6de75d0a1d09f179473
|
data/cocoapods-dylint.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = CocoapodsDylint::VERSION
|
9
9
|
spec.authors = ['黄露洋']
|
10
10
|
spec.email = ['huangluyang@douyu.tv']
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
11
|
+
spec.description = 'Validates a Pod without simulator.'
|
12
|
+
spec.summary = 'Validates the Pod using the files in the working directory without simulator.'
|
13
13
|
spec.homepage = 'http://gitlab.douyuios.com/douyu-ios/cocoapods-dylint'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
data/lib/pod/command.rb
CHANGED
@@ -0,0 +1,291 @@
|
|
1
|
+
# require File.expand_path('../../../../validator.rb', __FILE__)
|
2
|
+
require 'validator'
|
3
|
+
module Pod
|
4
|
+
class Command
|
5
|
+
# This is an example of a cocoapods plugin adding a top-level subcommand
|
6
|
+
# to the 'pod' command.
|
7
|
+
#
|
8
|
+
# You can also create subcommands of existing or new commands. Say you
|
9
|
+
# wanted to add a subcommand to `list` to show newly deprecated pods,
|
10
|
+
# (e.g. `pod list deprecated`), there are a few things that would need
|
11
|
+
# to change.
|
12
|
+
#
|
13
|
+
# - move this file to `lib/pod/command/list/deprecated.rb` and update
|
14
|
+
# the class to exist in the the Pod::Command::List namespace
|
15
|
+
# - change this class to extend from `List` instead of `Command`. This
|
16
|
+
# tells the plugin system that it is a subcommand of `list`.
|
17
|
+
# - edit `lib/cocoapods_plugins.rb` to require this file
|
18
|
+
#
|
19
|
+
# @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
|
20
|
+
# in the `plugins.json` file, once your plugin is released.
|
21
|
+
#
|
22
|
+
class Repo < Command
|
23
|
+
class Dypush < Repo
|
24
|
+
self.summary = 'Push new specifications to a spec-repo'
|
25
|
+
|
26
|
+
self.description = <<-DESC
|
27
|
+
Validates `NAME.podspec` or `*.podspec` in the current working dir,
|
28
|
+
creates a directory and version folder for the pod in the local copy of
|
29
|
+
`REPO` (~/.cocoapods/repos/[REPO]), copies the podspec file into the
|
30
|
+
version directory, and finally it pushes `REPO` to its remote.
|
31
|
+
DESC
|
32
|
+
|
33
|
+
self.arguments = [
|
34
|
+
CLAide::Argument.new('REPO', true),
|
35
|
+
CLAide::Argument.new('NAME.podspec', false),
|
36
|
+
]
|
37
|
+
|
38
|
+
def self.options
|
39
|
+
[
|
40
|
+
['--allow-warnings', 'Allows pushing even if there are warnings'],
|
41
|
+
['--use-libraries', 'Linter uses static libraries to install the spec'],
|
42
|
+
['--sources=https://github.com/artsy/Specs,master', 'The sources from which to pull dependent pods ' \
|
43
|
+
'(defaults to all available repos). ' \
|
44
|
+
'Multiple sources must be comma-delimited.'],
|
45
|
+
['--local-only', 'Does not perform the step of pushing REPO to its remote'],
|
46
|
+
['--no-private', 'Lint includes checks that apply only to public repos'],
|
47
|
+
['--skip-import-validation', 'Lint skips validating that the pod can be imported'],
|
48
|
+
['--skip-tests', 'Lint skips building and running tests during validation'],
|
49
|
+
['--commit-message="Fix bug in pod"', 'Add custom commit message. ' \
|
50
|
+
'Opens default editor if no commit message is specified.'],
|
51
|
+
['--use-json', 'Push JSON spec to repo'],
|
52
|
+
['--swift-version=VERSION', 'The SWIFT_VERSION that should be used when linting the spec. ' \
|
53
|
+
'This takes precedence over a .swift-version file.'],
|
54
|
+
].concat(super)
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(argv)
|
58
|
+
@allow_warnings = argv.flag?('allow-warnings')
|
59
|
+
@local_only = argv.flag?('local-only')
|
60
|
+
@repo = argv.shift_argument
|
61
|
+
@source = source_for_repo
|
62
|
+
@source_urls = argv.option('sources', config.sources_manager.all.map(&:url).join(',')).split(',')
|
63
|
+
@podspec = argv.shift_argument
|
64
|
+
@use_frameworks = !argv.flag?('use-libraries')
|
65
|
+
@private = argv.flag?('private', true)
|
66
|
+
@message = argv.option('commit-message')
|
67
|
+
@commit_message = argv.flag?('commit-message', false)
|
68
|
+
@use_json = argv.flag?('use-json')
|
69
|
+
@swift_version = argv.option('swift-version', nil)
|
70
|
+
@skip_import_validation = argv.flag?('skip-import-validation', false)
|
71
|
+
@skip_tests = argv.flag?('skip-tests', false)
|
72
|
+
super
|
73
|
+
end
|
74
|
+
|
75
|
+
def validate!
|
76
|
+
super
|
77
|
+
help! 'A spec-repo name or url is required.' unless @repo
|
78
|
+
unless @source && @source.repo.directory?
|
79
|
+
raise Informative,
|
80
|
+
"Unable to find the `#{@repo}` repo. " \
|
81
|
+
'If it has not yet been cloned, add it via `pod repo add`.'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def run
|
86
|
+
open_editor if @commit_message && @message.nil?
|
87
|
+
check_if_master_repo
|
88
|
+
validate_podspec_files
|
89
|
+
check_repo_status
|
90
|
+
update_repo
|
91
|
+
add_specs_to_repo
|
92
|
+
push_repo unless @local_only
|
93
|
+
end
|
94
|
+
|
95
|
+
#---------------------------------------------------------------------#
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
# @!group Push sub-steps
|
100
|
+
|
101
|
+
extend Executable
|
102
|
+
executable :git
|
103
|
+
|
104
|
+
# Open default editor to allow users to enter commit message
|
105
|
+
#
|
106
|
+
def open_editor
|
107
|
+
return if ENV['EDITOR'].nil?
|
108
|
+
|
109
|
+
file = Tempfile.new('cocoapods')
|
110
|
+
File.chmod(0777, file.path)
|
111
|
+
file.close
|
112
|
+
|
113
|
+
system("#{ENV['EDITOR']} #{file.path}")
|
114
|
+
@message = File.read file.path
|
115
|
+
end
|
116
|
+
|
117
|
+
# Temporary check to ensure that users do not push accidentally private
|
118
|
+
# specs to the master repo.
|
119
|
+
#
|
120
|
+
def check_if_master_repo
|
121
|
+
remotes = `git -C "#{repo_dir}" remote -v 2>&1`
|
122
|
+
master_repo_urls = [
|
123
|
+
'git@github.com:CocoaPods/Specs.git',
|
124
|
+
'https://github.com/CocoaPods/Specs.git',
|
125
|
+
]
|
126
|
+
is_master_repo = master_repo_urls.any? do |url|
|
127
|
+
remotes.include?(url)
|
128
|
+
end
|
129
|
+
|
130
|
+
if is_master_repo
|
131
|
+
raise Informative, 'To push to the CocoaPods master repo use ' \
|
132
|
+
"the `pod trunk push` command.\n\nIf you are using a fork of " \
|
133
|
+
'the master repo for private purposes we recommend to migrate ' \
|
134
|
+
'to a clean private repo. To disable this check remove the ' \
|
135
|
+
'remote pointing to the CocoaPods master repo.'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Performs a full lint against the podspecs.
|
140
|
+
#
|
141
|
+
def validate_podspec_files
|
142
|
+
UI.puts "\nValidating #{'spec'.pluralize(count)}".yellow
|
143
|
+
podspec_files.each do |podspec|
|
144
|
+
validator = DyValidator.new(podspec, @source_urls)
|
145
|
+
validator.allow_warnings = @allow_warnings
|
146
|
+
validator.use_frameworks = @use_frameworks
|
147
|
+
validator.ignore_public_only_results = @private
|
148
|
+
validator.swift_version = @swift_version
|
149
|
+
validator.skip_import_validation = @skip_import_validation
|
150
|
+
validator.skip_tests = @skip_tests
|
151
|
+
begin
|
152
|
+
validator.validate
|
153
|
+
rescue => e
|
154
|
+
raise Informative, "The `#{podspec}` specification does not validate." \
|
155
|
+
"\n\n#{e.message}"
|
156
|
+
end
|
157
|
+
raise Informative, "The `#{podspec}` specification does not validate." unless validator.validated?
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Checks that the repo is clean.
|
162
|
+
#
|
163
|
+
# @raise If the repo is not clean.
|
164
|
+
#
|
165
|
+
# @todo Add specs for staged and unstaged files.
|
166
|
+
#
|
167
|
+
# @todo Gracefully handle the case where source is not under git
|
168
|
+
# source control.
|
169
|
+
#
|
170
|
+
# @return [void]
|
171
|
+
#
|
172
|
+
def check_repo_status
|
173
|
+
clean = `git -C "#{repo_dir}" status --porcelain 2>&1` == ''
|
174
|
+
raise Informative, "The repo `#{@repo}` at #{UI.path repo_dir} is not clean" unless clean
|
175
|
+
end
|
176
|
+
|
177
|
+
# Updates the git repo against the remote.
|
178
|
+
#
|
179
|
+
# @return [void]
|
180
|
+
#
|
181
|
+
def update_repo
|
182
|
+
UI.puts "Updating the `#{@repo}' repo\n".yellow
|
183
|
+
UI.puts `git -C "#{repo_dir}" pull 2>&1`
|
184
|
+
end
|
185
|
+
|
186
|
+
# Commits the podspecs to the source, which should be a git repo.
|
187
|
+
#
|
188
|
+
# @note The pre commit hook of the repo is skipped as the podspecs have
|
189
|
+
# already been linted.
|
190
|
+
#
|
191
|
+
# @return [void]
|
192
|
+
#
|
193
|
+
def add_specs_to_repo
|
194
|
+
UI.puts "\nAdding the #{'spec'.pluralize(count)} to the `#{@repo}' repo\n".yellow
|
195
|
+
podspec_files.each do |spec_file|
|
196
|
+
spec = Pod::Specification.from_file(spec_file)
|
197
|
+
output_path = @source.pod_path(spec.name) + spec.version.to_s
|
198
|
+
if @message && !@message.empty?
|
199
|
+
message = @message
|
200
|
+
elsif output_path.exist?
|
201
|
+
message = "[Fix] #{spec}"
|
202
|
+
elsif output_path.dirname.directory?
|
203
|
+
message = "[Update] #{spec}"
|
204
|
+
else
|
205
|
+
message = "[Add] #{spec}"
|
206
|
+
end
|
207
|
+
FileUtils.mkdir_p(output_path)
|
208
|
+
|
209
|
+
if @use_json
|
210
|
+
json_file_name = "#{spec.name}.podspec.json"
|
211
|
+
json_file = File.join(output_path, json_file_name)
|
212
|
+
File.open(json_file, 'w') { |file| file.write(spec.to_pretty_json) }
|
213
|
+
else
|
214
|
+
FileUtils.cp(spec_file, output_path)
|
215
|
+
end
|
216
|
+
|
217
|
+
# only commit if modified
|
218
|
+
if repo_git('status', '--porcelain').include?(spec.name)
|
219
|
+
UI.puts " - #{message}"
|
220
|
+
repo_git('add', spec.name)
|
221
|
+
repo_git('commit', '--no-verify', '-m', message)
|
222
|
+
else
|
223
|
+
UI.puts " - [No change] #{spec}"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# Pushes the git repo against the remote.
|
229
|
+
#
|
230
|
+
# @return [void]
|
231
|
+
#
|
232
|
+
def push_repo
|
233
|
+
UI.puts "\nPushing the `#{@repo}' repo\n".yellow
|
234
|
+
repo_git('-C', repo_dir, 'push', 'origin', 'master')
|
235
|
+
end
|
236
|
+
|
237
|
+
#---------------------------------------------------------------------#
|
238
|
+
|
239
|
+
private
|
240
|
+
|
241
|
+
# @!group Private helpers
|
242
|
+
|
243
|
+
# @return result of calling the git! with args in repo_dir
|
244
|
+
#
|
245
|
+
def repo_git(*args)
|
246
|
+
git!(['-C', repo_dir] + args)
|
247
|
+
end
|
248
|
+
|
249
|
+
# @return [Pathname] The directory of the repository.
|
250
|
+
#
|
251
|
+
def repo_dir
|
252
|
+
@source.specs_dir
|
253
|
+
end
|
254
|
+
|
255
|
+
# @return [Array<Pathname>] The path of the specifications to push.
|
256
|
+
#
|
257
|
+
def podspec_files
|
258
|
+
if @podspec
|
259
|
+
path = Pathname(@podspec)
|
260
|
+
raise Informative, "Couldn't find #{@podspec}" unless path.exist?
|
261
|
+
[path]
|
262
|
+
else
|
263
|
+
files = Pathname.glob('*.podspec{,.json}')
|
264
|
+
raise Informative, "Couldn't find any podspec files in current directory" if files.empty?
|
265
|
+
files
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
# @return [Integer] The number of the podspec files to push.
|
270
|
+
#
|
271
|
+
def count
|
272
|
+
podspec_files.count
|
273
|
+
end
|
274
|
+
|
275
|
+
# Returns source for @repo
|
276
|
+
#
|
277
|
+
# @note If URL is invalid or repo doesn't exist, validate! will throw the error
|
278
|
+
#
|
279
|
+
# @return [Source]
|
280
|
+
#
|
281
|
+
def source_for_repo
|
282
|
+
config.sources_manager.source_with_name_or_url(@repo) unless @repo.nil?
|
283
|
+
rescue
|
284
|
+
nil
|
285
|
+
end
|
286
|
+
|
287
|
+
#---------------------------------------------------------------------#
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
data/lib/pod/gem_version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-dylint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 黄露洋
|
@@ -55,8 +55,9 @@ files:
|
|
55
55
|
- lib/cocoapods_plugin.rb
|
56
56
|
- lib/pod/command.rb
|
57
57
|
- lib/pod/command/lib/dylint.rb
|
58
|
-
- lib/pod/command/
|
58
|
+
- lib/pod/command/repo/dypush.rb
|
59
59
|
- lib/pod/gem_version.rb
|
60
|
+
- lib/validator.rb
|
60
61
|
- spec/command/dylint_spec.rb
|
61
62
|
- spec/spec_helper.rb
|
62
63
|
homepage: http://gitlab.douyuios.com/douyu-ios/cocoapods-dylint
|