Created
October 26, 2018 23:56
-
-
Save alanhogan/767b7cd93d2eea5e6eb3d05d03953cf5 to your computer and use it in GitHub Desktop.
Convert // comments to /* */ (for .scss files)
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 'find' | |
puts "Yo dawg, i only work on .scss files, not .sass. just a warning." | |
nonMatchingFiles = 0 | |
def fileContents(filename) | |
data = '' | |
f = File.open(filename, "r") | |
f.each_line do |line| | |
data += line | |
end | |
f.close | |
return data | |
end | |
Find.find('.') do |path| | |
if FileTest.directory?(path) | |
if ['npm-packages-offline-cache', 'node_modules'].include? File.basename(path) | |
puts "Skipping #{File.basename(path)}" | |
Find.prune # Don't look any further into this directory. | |
else | |
next | |
end | |
elsif File.basename(path) =~ /\.scss$/ | |
# Add filename as comment to beginning and end of file | |
beginning = "/* BEGIN #{path} */" | |
ending = "/* END #{path} */" | |
puts "Adding comments to #{File.basename(path)}" | |
orig = fileContents(path) | |
f = File.open(path, "w") | |
f.write "#{beginning}\n\n#{orig}\n\n#{ending}" | |
f.close | |
else | |
nonMatchingFiles += 1 | |
end | |
end | |
puts "#{nonMatchingFiles} non-.scss files skipped" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment