Created
August 18, 2017 10:49
-
-
Save DanyHenriquez/e72e77e0f35352f5fcf5881b73b7d81b to your computer and use it in GitHub Desktop.
Convert bulma from sass to scss
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 'tmpdir' | |
require 'fileutils' | |
dir = Dir.tmpdir() | |
if File.directory?("#{dir}/bulma") | |
FileUtils.remove_dir("#{dir}/bulma") | |
end | |
system "bash", "-c", "git clone https://github.com/jgthms/bulma.git #{dir}/bulma >> /dev/null" | |
unless $?.exitstatus == 0 | |
puts "Cannot clone Bulma repo. Is git installed?" | |
end | |
FileUtils.mv("#{dir}/bulma/bulma.sass", "#{dir}/bulma/sass/bulma.sass") | |
Dir.chdir "#{dir}/bulma/sass" | |
system "bash", "-c", "sass-convert -R --from sass --to scss . >> /dev/null" | |
unless $?.exitstatus == 0 | |
puts "Cannot execute sass-convert. Is it installed and in path?" | |
end | |
system "bash", "-c", "rm -rf */*.sass >> /dev/null" | |
system "bash", "-c", "rm -rf bulma.sass >> /dev/null" | |
import_files = ['bulma.scss', 'base/_all.scss', 'components/_all.scss', 'elements/_all.scss', 'grid/_all.scss', 'layout/_all.scss', 'utilities/_all.scss'] | |
import_files.each do |import_file| | |
lines = [] | |
File.readlines(import_file).each do |line| | |
next if line.include?('@charset "utf-8";') | |
next if line.strip().empty? | |
line = line.gsub('.sass', '') | |
line = line.gsub('sass/', '') | |
lines << line | |
end | |
File.open(import_file, "w") do |file| | |
file.puts lines.join() | |
end | |
end | |
Dir.glob('*/*.scss').each do |scss_file| | |
next if scss_file.include?('_') | |
FileUtils.mv(scss_file, scss_file.gsub('/', '/_')) | |
end | |
puts "Bulma has been converted to scss. The files are available in #{dir}/bulma/sass" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment