Last active
February 4, 2016 12:03
-
-
Save trusch/27d4aa8da40eacc57c68 to your computer and use it in GitHub Desktop.
Grunttask to generate a stylus file from an icon folder
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
var walk = require('fs-walk'); | |
var fs = require('fs'); | |
grunt.registerTask('generateIconStylus', 'generate a stylus file with all icons', function task() { | |
console.log('run it'); | |
var done = this.async(); | |
var fd = fs.open('src/atoms/icons.styl', 'w', function(err,fd){ | |
fs.writeSync(fd,".icon\n"); | |
walk.walk('src/images/icons', function (basedir, filename, stats, next) { | |
var data = fs.readFile(basedir+'/'+filename, 'utf8', function(err,data){ | |
var name = filename.replace(/\.[^/.]+$/, ""); | |
var data = new Buffer(data).toString('base64'); | |
console.log('processing ',name); | |
var item = " ."+name+"\n background-image: url(data:svg/xml;base64,"+data+")\n\n"; | |
fs.writeSync(fd, item); | |
next(); | |
}); | |
}, done); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment