Skip to content

Instantly share code, notes, and snippets.

@EmilEriksen
Created May 27, 2017 16:04
Show Gist options
  • Save EmilEriksen/9973b71d53d2a0be23366d9555d124cf to your computer and use it in GitHub Desktop.
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.
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