coding-push 1.0.5

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: b1cc818d55702d334ccb98f27e7689944f800b3fd5bd23c2e448f1afe8fc5109
4
+ data.tar.gz: b9dad13252a8a868dba078508354f1fea7d32114f0cf20edf6965f6858bd0a12
5
+ SHA512:
6
+ metadata.gz: 4b53d25644efca6b65580dcf3b1054d7e6416a3a977c81e1d2ecb3a8686cf07c71d34d4371d0c032982cbb2eefe3e7e86b3f5e72338371fee07d83ca83442853
7
+ data.tar.gz: bced521bab8d52b7db641ca33e8f31a63adec606cf623cb1e9b9afbdced1738795ae0f8045ef2ddf7730c9141837a7ddbf639f24f9e04376166e2e65ede53d71
@@ -0,0 +1,3 @@
1
+ module CocoapodsCodingAr
2
+ VERSION = "1.0.5"
3
+ end
@@ -0,0 +1,69 @@
1
+ require 'coding_ar_source'
2
+ require 'coding_ar_command'
3
+ require 'coding_ar_util'
4
+
5
+ module Pod
6
+ module Downloader
7
+ class Http
8
+ def self.options
9
+ [:type, :flatten, :sha1, :sha256, :indexDownload]
10
+ end
11
+
12
+ alias_method :orig_download_file, :download_file
13
+ alias_method :orig_should_flatten?, :should_flatten?
14
+
15
+ def download_file(full_filename)
16
+ CodingArUtil.download(url, full_filename)
17
+ end
18
+
19
+ def should_flatten?
20
+ if options.key?(:indexDownload)
21
+ true
22
+ else
23
+ orig_should_flatten?
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ module Pod
31
+ class Source
32
+ class Manager
33
+ alias_method :orig_source_from_path, :source_from_path
34
+ alias_method :orig_create_source_with_url, :create_source_with_url
35
+
36
+ def source_from_path(path)
37
+ @sources_by_path ||= Hash.new do |hash, key|
38
+ hash[key] = case
39
+ when key.basename.to_s == Pod::TrunkSource::TRUNK_REPO_NAME
40
+ TrunkSource.new(key)
41
+ when (key + '.url').exist?
42
+ CDNSource.new(key)
43
+ when (key + '.coding_ar_url').exist?
44
+ CodingArSource.new(key)
45
+ else
46
+ Source.new(key)
47
+ end
48
+ end
49
+
50
+ @sources_by_path[path]
51
+ end
52
+
53
+ def create_source_with_url(url)
54
+ require 'coding_ar_util'
55
+
56
+ name = name_for_url(url)
57
+ if CodingArUtil.coding_ar_service?(url)
58
+ Command::Repo::AddCodingAr.parse([name, url]).run
59
+ else
60
+ orig_create_source_with_url(url)
61
+ end
62
+
63
+ source = source_with_url(url)
64
+ raise "Unable to create a source with URL #{url}" unless source
65
+ source
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,197 @@
1
+ module Pod
2
+ class Command
3
+ class Repo < Command
4
+ class AddCodingAr < Repo
5
+ self.summary = 'Add a CODING-AR-backed repo'
6
+ self.description = <<-DESC
7
+ Adds the remote named `NAME` to the local spec-repos directory at `#{Config.instance.repos_dir}`.
8
+ DESC
9
+
10
+ def initialize(argv)
11
+ @name, @url = argv.shift_argument, argv.shift_argument
12
+ super
13
+ end
14
+
15
+ def validate!
16
+ super
17
+ unless @name && @url
18
+ help! 'This command requires both a repo name and a url.'
19
+ end
20
+ end
21
+
22
+ def run
23
+ require 'coding_ar_util'
24
+
25
+ UI.section("Adding CODING-AR-backed repository `#@url` into local spec repo `#@name`") do
26
+ if !CodingArUtil.coding_ar_service?(@url)
27
+ raise Informative, "`#@url` seems not to be a CODING-AR-backed repository."
28
+ end
29
+
30
+ raise Informative, "Local spec repo #@name (in #{dir}) already exists." if File.exists?(dir)
31
+
32
+ FileUtils.mkdir_p dir
33
+
34
+ begin
35
+ url_path = create_coding_ar_url_file dir
36
+ rescue => e
37
+ raise Informative, "Cannot create file '#{url_path}' because : #{e.message}."
38
+ end
39
+ end
40
+ end
41
+
42
+ def create_coding_ar_url_file(repo_dir)
43
+ url_path = File.join(repo_dir, ".coding_ar_url")
44
+ url_file = File.new(url_path, "wb")
45
+ url_file << @url
46
+ url_file.close
47
+ url_path
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ module Pod
55
+ class Command
56
+ class Repo < Command
57
+ class PushCodingAr < Repo
58
+ extend Executable
59
+ executable :tar
60
+
61
+ self.summary = 'Push a pod to CODING-AR.'
62
+ self.description = <<-DESC
63
+ Push a pod include its spec to a CODINF-AR repo.
64
+ DESC
65
+
66
+ self.arguments = [
67
+ CLAide::Argument.new('REPO', true),
68
+ CLAide::Argument.new('NAME.podspec', true)
69
+ ]
70
+
71
+ def initialize(argv)
72
+ @repo = argv.shift_argument
73
+ @podspec = argv.shift_argument
74
+ super
75
+ end
76
+
77
+ def validate!
78
+ super
79
+ unless @repo && @podspec
80
+ help! 'This command requires both a repo and a podspec.'
81
+ end
82
+ end
83
+
84
+ def run
85
+ unless File.file? File.join(Config.instance.repos_dir, @repo, ".coding_ar_url")
86
+ raise Informative, "`#@repo` is not a CODING-AR repo.".red
87
+ end
88
+
89
+ FileUtils.mkdir_p tmp_dir
90
+ begin
91
+ UI.section("Pushing pod `#{spec.name} #{spec.version.to_s}`` to CODING-AR repo `#@repo`") do
92
+ pod_tar_gz_path = create_pod_tar_gz
93
+ podspec_json_path = create_spec_json
94
+
95
+ post_pod_with_spec(pod_tar_gz_path, podspec_json_path)
96
+ end
97
+ UI.puts "Successfully push pod `#{spec.name} #{spec.version.to_s}`` to CODING-AR repo `#@repo`".green
98
+ ensure
99
+ FileUtils.rm_rf tmp_dir
100
+ end
101
+ end
102
+
103
+ def create_pod_tar_gz
104
+ require 'digest/sha1'
105
+ require 'find'
106
+
107
+ pod_dir = File.join(tmp_dir, "pod")
108
+ FileUtils.mkdir_p(pod_dir)
109
+
110
+ pod_root = File.dirname Pathname(@podspec).realpath
111
+ path_list = Pod::Sandbox::PathList.new(pod_root)
112
+
113
+ file_accessors = []
114
+
115
+ # Add main spec
116
+ file_accessors += spec.available_platforms.flat_map do |platform|
117
+ Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
118
+ end
119
+
120
+ # Add subspecs
121
+ spec.subspecs.each do |subspec|
122
+ file_accessors += subspec.available_platforms.flat_map do |platform|
123
+ Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
124
+ end
125
+ end
126
+
127
+ pod_files = Pod::Sandbox::FileAccessor.all_files(file_accessors).map do |path|
128
+ Find.find(path).select { |path| File.file? path}
129
+ end
130
+
131
+ pod_files.flatten.each do |source|
132
+ target = File.join(pod_dir, Pathname(source).relative_path_from(pod_root))
133
+ FileUtils.mkdir_p(File.dirname(target))
134
+ FileUtils.copy_file(source, target)
135
+ end
136
+
137
+ tar_gz_path = File.join(tmp_dir, "#{spec.name}-#{spec.version}.tar.gz")
138
+
139
+ Dir.chdir(pod_dir) { tar!('-czf', tar_gz_path, '.') }
140
+
141
+ tar_gz_path
142
+ end
143
+
144
+ def create_spec_json
145
+ require 'json'
146
+
147
+ FileUtils.mkdir_p(tmp_dir)
148
+ podspec_json_path = File.join(tmp_dir, "#{spec.name}.podspec.json")
149
+ podspec_json = File.new(podspec_json_path, "wb")
150
+ podspec_json.puts(spec.to_pretty_json)
151
+ podspec_json.close
152
+ podspec_json_path
153
+ end
154
+
155
+ def post_pod_with_spec(pod_path, spec_path)
156
+ require 'json'
157
+
158
+ request_body = {
159
+ 'pod' => file_push_profile(pod_path),
160
+ 'spec' => file_push_profile(spec_path)
161
+ }
162
+ request_body_json_path = File.join(tmp_dir, "request_body.json")
163
+ request_body_json = File.new(request_body_json_path, "wb")
164
+ request_body_json.puts(request_body.to_json)
165
+ request_body_json.close
166
+
167
+ require 'coding_ar_util'
168
+ CodingArUtil.push_pod(coding_ar_repo_url, request_body_json_path)
169
+ end
170
+
171
+ def spec
172
+ spec_file = Pathname(@podspec)
173
+ spec = Pod::Specification.from_file(spec_file)
174
+ end
175
+
176
+ def tmp_dir
177
+ File.join(Config.instance.repos_dir, @repo, '.tmp', spec.name, spec.version.to_s)
178
+ end
179
+
180
+ def coding_ar_repo_url
181
+ File.read File.join(Config.instance.repos_dir, @repo, ".coding_ar_url")
182
+ end
183
+
184
+ def file_push_profile(path)
185
+ require 'digest/sha1'
186
+
187
+ content = File.read(path)
188
+ {
189
+ 'size' => File.lstat(path).size,
190
+ 'base64_content' => Base64.strict_encode64(content),
191
+ 'sha1_digest' => Digest::SHA1.hexdigest(content)
192
+ }
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,127 @@
1
+ module Pod
2
+ class CodingArSource < Source
3
+ def initialize(repo)
4
+ super(repo)
5
+ end
6
+
7
+ def name
8
+ repo.basename.to_s
9
+ end
10
+
11
+ def url
12
+ @url ||= File.read(repo.join('.coding_ar_url')).chomp.chomp('/')
13
+ end
14
+
15
+ def type
16
+ 'CODING-AR'
17
+ end
18
+
19
+ def specs_dir
20
+ repo
21
+ end
22
+
23
+ def pod_path(name)
24
+ specs_dir.join(name)
25
+ end
26
+
27
+ def pods
28
+ raise Informative, "Can't retrieve all the pods for a CODING-AR-backed source."
29
+ end
30
+
31
+ def versions(name)
32
+ eturn nil unless specs_dir
33
+ raise ArgumentError, 'No name' unless name
34
+
35
+ list_version(name).map do |v|
36
+ Version.new(v)
37
+ end.compact.sort.reverse
38
+ end
39
+
40
+ def specification_path(name, version)
41
+ raise ArgumentError, 'No name' unless name
42
+ raise ArgumentError, 'No version' unless version
43
+ unless versions(name).include?(Version.new(version))
44
+ raise StandardError, "Unable to find the specification #{name} " \
45
+ "(#{version}) in the #{self.name} source."
46
+ end
47
+
48
+ spec_url = "#{url}/Specs/#{name}/#{version.to_s}/#{name}.podspec.json"
49
+ spec_path = File.join(specs_dir, name, version.to_s, "#{name}.podspec.json")
50
+ FileUtils.mkdir_p File.dirname(spec_path)
51
+ require 'coding_ar_util'
52
+ CodingArUtil.download(spec_url, spec_path)
53
+
54
+ spec_path
55
+ end
56
+
57
+ def all_specs
58
+ raise Informative, "Can't retrieve all the specs for a CODING-AR-backed source."
59
+ end
60
+
61
+ def pod_sets
62
+ raise Informative, "Can't retrieve all the pod sets for a CODING-AR-backed source."
63
+ end
64
+
65
+ def search(query)
66
+ unless specs_dir
67
+ raise Informative, "Unable to find a source named: `#{name}`"
68
+ end
69
+ if query.is_a?(Dependency)
70
+ query = query.root_name
71
+ end
72
+
73
+ versions = list_version(query)
74
+ if versions.class == Array and versions.length > 0
75
+ set = set(query)
76
+ set if set.specification_name == query
77
+ end
78
+ end
79
+
80
+ def search_by_name(query, full_text_search = false)
81
+ raise Informative, "Can't search a CODING-AR-backed source by name."
82
+ end
83
+
84
+ def update(_show_output)
85
+ require 'json'
86
+ require 'coding_ar_util'
87
+
88
+ changed_spec_paths = []
89
+ UI.puts "Updating CODING-AR-backed repo #{name}".yellow if _show_output
90
+ Pathname.glob(repo.join('**/*/*.json')).map do |f|
91
+ origin_content = File.read(f)
92
+ spec = JSON.parse origin_content
93
+ spec_url = "#{url}/Specs/#{spec['name']}/#{spec['version']}/#{spec['name']}.podspec.json"
94
+ UI.puts "- Fetch #{spec_url}" if _show_output
95
+ FileUtils.mkdir_p File.dirname(f)
96
+ CodingArUtil.download(spec_url, f)
97
+ latest_content = File.read(f)
98
+ FileUtils.rm_rf(File.dirname(f)) if latest_content.to_s.start_with?('Pod not found')
99
+ JSON.parse latest_content
100
+ changed_spec_paths.push(f) if origin_content != latest_content
101
+ end
102
+ UI.puts "Successfully update CODING-AR-backed repo #{name}".green if _show_output
103
+
104
+ []
105
+ end
106
+
107
+ def updateable?
108
+ true
109
+ end
110
+
111
+ def git?
112
+ false
113
+ end
114
+
115
+ def indexable?
116
+ false
117
+ end
118
+
119
+ private
120
+
121
+ def list_version(pod)
122
+ require 'coding_ar_util'
123
+ CodingArUtil.get_json("#{url}/pods/#{pod}")
124
+ end
125
+
126
+ end
127
+ end
@@ -0,0 +1,98 @@
1
+ require 'json'
2
+ require 'typhoeus'
3
+ require 'netrc'
4
+ require 'cocoapods_coding_ar'
5
+
6
+ module Pod
7
+ class CodingArUtil
8
+ CODING_AR_NETRC_PATH_ENV = 'COCOAPODS_CODING_AR_NETRC_PATH'
9
+ JSON_CONTENT_TYPE = 'application/json; charset=utf-8'
10
+ USER_AGENT = "cocoapods-coding-ar/#{CocoapodsCodingAr::VERSION} cocoapods/#{Pod::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{IO.popen('uname -v').gets.strip})"
11
+
12
+ def self.coding_ar_service?(url)
13
+ request = Typhoeus::Request.new(
14
+ url,
15
+ :method => :get,
16
+ :headers => {
17
+ 'User-Agent' => USER_AGENT,
18
+ },
19
+ )
20
+ request.run
21
+
22
+ begin
23
+ resp = JSON.parse(request.response.body)
24
+ resp['service'] == 'CODING-AR'
25
+ rescue
26
+ return false
27
+ end
28
+ end
29
+
30
+ def self.push_pod(url, body_path)
31
+ request = Typhoeus::Request.new(
32
+ url,
33
+ :method => :post,
34
+ :netrc => :optional,
35
+ :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path,
36
+ :headers => {
37
+ 'Content-Type' => JSON_CONTENT_TYPE,
38
+ 'User-Agent' => USER_AGENT,
39
+ },
40
+ :body => File.read(body_path),
41
+ )
42
+ request.run
43
+
44
+ if request.response.code == 0
45
+ raise "fail to push pod: #{request.response.return_message}"
46
+ elsif request.response.code != 200
47
+ raise "fail to push pod: #{request.response.body}"
48
+ end
49
+ end
50
+
51
+ def self.get_json(url)
52
+ request = Typhoeus::Request.new(
53
+ url,
54
+ :method => :get,
55
+ :netrc => :optional,
56
+ :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path,
57
+ :followlocation => true,
58
+ :headers => {
59
+ 'User-Agent' => USER_AGENT,
60
+ },
61
+ )
62
+ request.run
63
+
64
+ if request.response.code == 0
65
+ raise "fail to request #{url}: #{request.response.return_message}"
66
+ elsif request.response.code != 200
67
+ raise "fail to request #{url}: #{request.response.body}"
68
+ else
69
+ JSON.parse(request.response.body)
70
+ end
71
+ end
72
+
73
+ def self.download(url, path)
74
+ request = Typhoeus::Request.new(
75
+ url,
76
+ :method => :get,
77
+ :netrc => :optional,
78
+ :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path,
79
+ :followlocation => true,
80
+ :headers => {
81
+ 'User-Agent' => USER_AGENT,
82
+ },
83
+ )
84
+ request.run
85
+
86
+ if request.response.code == 0
87
+ raise "fail to request #{url}: #{request.response.return_message}"
88
+ elsif request.response.code != 200
89
+ raise "fail to request #{url}: #{request.response.body}"
90
+ else
91
+ file = File.new(path, 'wb')
92
+ file << request.response.body
93
+ file.close
94
+ end
95
+ end
96
+
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coding-push
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
+ platform: ruby
6
+ authors:
7
+ - misoomang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-07-14 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: CODING-AR-backed repo support for Cocoapods
42
+ email:
43
+ - 18514428990@163.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods_coding_ar.rb
49
+ - lib/cocoapods_plugin.rb
50
+ - lib/coding_ar_command.rb
51
+ - lib/coding_ar_source.rb
52
+ - lib/coding_ar_util.rb
53
+ homepage: https://coding-public.coding.net/p/cocoapods-coding-ar
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.1
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: CODING-AR-backed repo support for Cocoapods
76
+ test_files: []