-
-
Save alloy/632094beb7d8200f99ac to your computer and use it in GitHub Desktop.
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 | |
require 'pathname' | |
code_files = ARGV | |
code_files.each do |file| | |
file = Pathname(file) | |
contents = file.read | |
contents.gsub!(/(^#import .*\n)+/) do |imports| | |
imports = imports.split("\n") | |
imports.map! do |import| | |
if import =~ /^#import\s+<(.+?)\// | |
"@import #{$1};" | |
else | |
import | |
end | |
end | |
imports.sort.uniq.join("\n") << "\n" | |
end | |
file.open('w') { |f| f.write contents } | |
end |
sort_imports
!/usr/bin/env ruby
require 'pathname'
code_files = ARGV
code_files.each do |file|
file = Pathname(file)
contents = file.read
contents.gsub!(/(^#import .*\n)+/) do |imports|
imports = imports.split("\n")
imports.map! do |import|
if import =~ /^#import\s+<(.+?)//
"@import #{$1};"
else
import
end
end
imports.sort.uniq.join("\n") << "\n"
end
file.open('w') { |f| f.write contents }
end
Comment on gist
Comment
Desktop version
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Im know to this whatnam I supposed to do