Skip to content

Instantly share code, notes, and snippets.

@mironal
Created December 19, 2017 10:10
Show Gist options
  • Select an option

  • Save mironal/364561f9fbb4bc9f71cd37cc5eaf1fd6 to your computer and use it in GitHub Desktop.

Select an option

Save mironal/364561f9fbb4bc9f71cd37cc5eaf1fd6 to your computer and use it in GitHub Desktop.
Collect license files for Carthage and cocoapods.
#
# ruby collect_lisence.rb > ALL_LISENCE.md
#
cart_licenses = File.readlines("./Cartfile").map { |line|
line[/.* \".+\/([^\"]+)\".*$/, 1]
}.flat_map { |line|
path = Dir.glob("./Carthage/Checkouts/#{line}/LICENSE*").first
if path
# STDERR.puts "Found: #{line}"
{:name => line, :path => path}
else
STDERR.puts "Not found: #{line}"
nil
end
}.compact.map { |cart|
cart[:body] = File.read(cart[:path])
cart
}
pod_licenses = Dir.glob("./Pods/**/*-acknowledgements.markdown").reject { |path|
## Change here depending on the environment
path.include?("Tests/") || path.include?("TestHelper/")
}.map { |path|
# STDERR.puts "Found markdown: #{path}"
lines = File.readlines(path, rs = "")
lines.inject([]){ |pods, line|
if line.start_with?("## ")
# STDERR.puts "Found pod: #{line}"
pods.push([])
pods.last.push(line.chomp)
elsif line.start_with?("Generated by CocoaPods")
else
pods.last&.push(line.chomp)
end
pods
}
}.flat_map { |pods|
pods.map { |pod|
name = pod.first[/^## (.+)$/, 1]
body = pod.drop(1).join("\n")
{:name => name, :body => body}
}
}
puts "# Acknowledgements"
puts "This application makes use of the following third party libraries:"
puts ""
puts (cart_licenses + pod_licenses)
.uniq { |l|
l[:name]
}
.sort {|a, b|
a[:name] <=> b[:name]
}
.map { |l|
# STDERR.puts "Output: #{l[:name]}"
puts ""
puts "## #{l[:name]}"
puts ""
puts l[:body]
}
puts ""
puts "(◍•ᴗ•◍)"
puts ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment