Last active
August 29, 2015 14:22
-
-
Save pcreux/e742663998351cdc8a7d to your computer and use it in GitHub Desktop.
Generate graph of dependency for scss stylesheets
This file contains 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 | |
# | |
# Generate a graph of dependencies for your stylesheets. | |
# | |
# Requires graphviz | |
# | |
# Run `ruby dependencies.rb | fdp -Tpng > out.png; open out.png` | |
PATH = "app/assets/stylesheets/" | |
puts "digraph stylesheets {" | |
Dir.glob("#{PATH}**/*.scss").each do |file| | |
human_file = file.gsub('app/assets/stylesheets/', '').gsub('.css.scss', '') | |
human_dir = human_file.split('/')[0..-2].join('/') | |
content = File.open(file).each_line do |line| | |
dependency = nil | |
if line["@import"] | |
dependency = line[/["'].+["']/][1..-2] | |
end | |
if line["//= require"] | |
dependency = line.gsub("//= require", "").strip | |
end | |
if dependency | |
puts %|"#{human_file}" -> "#{[human_dir, dependency].reject { |f| f.nil? || f == "" }.join("/")}";|; | |
end | |
end | |
end | |
puts "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment