Created
May 27, 2017 16:04
-
-
Save EmilEriksen/9973b71d53d2a0be23366d9555d124cf to your computer and use it in GitHub Desktop.
Bourbon 4 -> Bourbon 5 find replace script for replacing em()-calls with a pre-calculated value.
This file contains hidden or 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
var glob = require('glob'); | |
var fs = require('fs'); | |
// Find files to replace in. | |
glob('src/sass/**/*.scss', function(err, files) { | |
if (err) { throw err; } | |
files.forEach(function(item, index, array) { | |
fs.readFile(item, 'utf8', function (err, data) { | |
if (err) { | |
return console.log(err); | |
} | |
// Perform replacement. | |
var result = data.replace(/em\( ?([\d]+) ?px ?\)/g, function(match, value) { | |
return value / 16 + 'em'; | |
}); | |
fs.writeFile(item, result, 'utf8', function (err) { | |
if (err) return console.log(err); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment