This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
/
cocoapods-simple.rb
executable file
·148 lines (117 loc) · 4.97 KB
/
cocoapods-simple.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env ruby
# Usage: cocoadocs-simple [podspec_url]
# Will generate a README, CHANGELOG, and metrics for CocoaDocs
require 'cocoapods-downloader'
require 'cocoapods-core'
require 'cocoapods'
require 'open-uri'
current_dir = File.dirname(File.expand_path(__FILE__))
# Ensure all the class files exist in scope
Dir[File.join(current_dir, 'classes/*.rb')].each do |file|
require_relative(file)
end
# These all still need to be set, as the rest of the system basically relies on them :D
$specs_repo = 'CocoaPods/Specs'
$s3_bucket = 'cocoadocs.org'
$website_home = 'http://cocoadocs.org/'
$cocoadocs_specs_name = 'cocoadocs_specs'
$active_folder = 'activity_pods'
def run
specs_repo = 'CocoaPods/Specs'
s3_bucket = 'cocoadocs.org'
website_home = 'http://cocoadocs.org/'
active_folder_name = $active_folder
current_dir = File.dirname(File.expand_path(__FILE__))
active_folder = File.join(current_dir, active_folder_name)
# Assume the full url is first arg
url = ARGV[0]
spec = nil
# Verify we're working with a CP Spec
unless url.start_with? 'https://raw.githubusercontent.com/CocoaPods/Specs'
puts 'Not running non-CocoaPods Spec URL'
puts 'Needs to be: https://raw.githubusercontent.com/CocoaPods/Specs/XXX'
return
end
# Setup a local copy
spec_name = url.split('/')[-1]
podspec_path = active_folder + '/podspecs/' + spec_name
# Put it in the filesystem
FileUtils.mkdir_p(File.dirname(podspec_path))
open(url) { |f| File.open(podspec_path, 'w') { |tmp| tmp.write(f.read) } }
# Eval it, and process
spec = Pod::Specification.from_file(podspec_path)
download_location = active_folder + "/download/#{spec.name}/#{spec.version}/#{spec.name}"
docset_location = active_folder + "/docsets/#{spec.name}/#{spec.version}/"
readme_location = active_folder + "/readme/#{spec.name}/#{spec.version}/README.html"
changelog_location = active_folder + "/changelog/#{spec.name}/#{spec.version}/CHANGELOG.html"
api_json_location = active_folder + "/docsets/#{spec.name}/#{spec.version}/stats.json"
# Download the source code
downloader = SourceDownloader.new(spec: spec, download_location: download_location, overwrite: true)
FileUtils.rm_r download_location if File.directory?(download_location)
downloader.download_pod_source_files
# Generate a settings object for the downloaded source
settings = CocoaDocsSettings.settings_at_location download_location
# Create a README and CHANGELOG
readme = ReadmeGenerator.new(spec: spec, readme_location: readme_location, changelog_location: changelog_location, settings: settings)
readme.create_readme
readme.create_changelog
# We should only update trunk metrics for the most recent version
version_metadata = SpecMetadataGenerator.new(spec: spec, docset_path: docset_location)
version_metadata.generate
if version_metadata.latest_version?
# Generate CLOC stats for the metrics
cloc = ClocStatsGenerator.new(spec: spec, source_download_location: download_location)
cloc_results = cloc.generate
# Generate testing info for the downloaded source
tester = TestingIdealist.new(spec: spec, download_location: download_location)
testing_estimate = tester.testimate
# Upload stats
stats = StatsGenerator.new(
spec: spec,
cloc_results: cloc_results,
cloc_top: cloc.get_top_cloc(cloc_results),
readme_location: readme_location,
changelog_location: changelog_location,
download_location: download_location,
doc_percent: nil,
test_carthage: false,
testing_estimate: testing_estimate,
docset_location: docset_location
)
stats.upload
end
# Upload the files to S3
generator = WebsiteGenerator.new(generate_json: false, spec: spec)
server_folder = "docsets"
rendered_readme_path = "/readme/#{spec.name}/#{spec.version}/README.html"
rendered_changelog_path = "/changelog/#{spec.name}/#{spec.version}/CHANGELOG.html"
generator.upload_folder rendered_readme_path, "/#{server_folder}/#{spec.name}/", "put" if File.exist? rendered_readme_path
generator.upload_folder rendered_changelog_path, "/#{server_folder}/#{spec.name}/", "put" if File.exist? rendered_changelog_path
# Give a clickable link
puts '* [pods] - ' + website_home + 'docsets/' + spec.name + '/' + spec.version.to_s + '/'
rescue StandardError => e
log_error(spec, e) unless spec.nil?
open('error_log.txt', 'a') do |f|
f.puts "\n\n\n --------------#{spec}-------------"
f.puts e.message
f.puts '------'
f.puts e.backtrace.inspect
end
puts "--------------#{spec}-------------".red
puts e.message.red
puts '------'
puts e.backtrace.inspect.red
end
def log_error(spec, e)
error_path = "errors/#{spec.name}/#{spec.version}/error.json"
FileUtils.mkdir_p(File.dirname(error_path))
FileUtils.rm(error_path) if File.exist? error_path
open(error_path, 'a') do |f|
report = {
'message' => e.message.encode('utf-8', 'binary', undef: :replace),
'trace' => e.backtrace
}
f.puts report.to_json.to_s
end
end
run