Created
April 14, 2015 16:21
-
-
Save chrisladd/f05cf6f07bb27c913a22 to your computer and use it in GitHub Desktop.
A simple little script I use to keep the readme for my local podspecs up to date.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
puts '' | |
puts 'Generating README...' | |
readme = '' | |
specs = Dir.glob('./*').select { |fn| File.directory?(fn) } | |
summaryRegEx = /\s*s.summary\s*=\s*\"(.*)\"/ | |
dependencyRegEx = /\s*s.dependency\s*'(\w*)',\s*'(.*)'/ | |
entryCount = 0 | |
specs.each do |specFolder| | |
entryCount = entryCount + 1 | |
versions = Dir.glob(specFolder + '/*').select { |fn| File.directory?(fn) } | |
version = versions[-1] | |
frameworkName = version.split('/')[-2] | |
frameworkVersion = version.split('/')[-1] | |
readme += "## " + frameworkName + " (" + frameworkVersion + ")\n" | |
specFiles = Dir.glob(version + '/*').select { |fn| !File.directory?(fn) } | |
specFiles.each do |file| | |
contents = File.open(file).read | |
summary = contents.match(summaryRegEx) | |
if summary | |
readme += "\n" + summary[1] + "\n" | |
end | |
dependencies = contents.scan(dependencyRegEx) | |
if dependencies.count > 0 | |
readme += "\n#### Depends on\n" | |
dependencies.each do |dependencyMatch| | |
readme += "\n - " + dependencyMatch[0] + " " + dependencyMatch[1] + "\n" | |
end | |
end | |
readme += "\n\n" | |
end | |
end | |
File.open("README.md", 'w') { |file| file.write(readme) } | |
puts entryCount.to_s + ' entries written to README.md.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment