Skip to content

Instantly share code, notes, and snippets.

@eamirgh
Forked from DanyHenriquez/bulma-sass-scss.rb
Created November 28, 2018 22:44
Show Gist options
  • Save eamirgh/5f9129ed327adf63c94a2529154f44e4 to your computer and use it in GitHub Desktop.
Save eamirgh/5f9129ed327adf63c94a2529154f44e4 to your computer and use it in GitHub Desktop.
Convert bulma from sass to scss
#!/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