Skip to content

Instantly share code, notes, and snippets.

@alanhogan
Created October 26, 2018 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhogan/767b7cd93d2eea5e6eb3d05d03953cf5 to your computer and use it in GitHub Desktop.
Save alanhogan/767b7cd93d2eea5e6eb3d05d03953cf5 to your computer and use it in GitHub Desktop.
Convert // comments to /* */ (for .scss files)
#!/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