Created
December 8, 2016 09:28
-
-
Save stefancrowe/11f163aada50d7906ff67e90d90a1b07 to your computer and use it in GitHub Desktop.
Gulp Task to generate a JSON array of Font Awesome 4.* icons from the package
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
require('fs'); | |
require('gulp'); | |
/** | |
* Create JSON array of icons from Font Awesome _icons.scss (based on v4.*). | |
* Replace PATH_TO_FONT_AWESOME and PATH_TO_SAVE with your relevant paths. | |
*/ | |
gulp.task('icons', function() { | |
// Pattern to only match the icon name (excluding "fa-") | |
var re = /^.\#\{\$fa\-css\-prefix\}\-([a-z0-9\-]*)\:before { content: \$fa\-var\-[a-z0-9\-]*\; }$/gmi; | |
// Read the SASS file line-by-line | |
fs.readFile("PATH_TO_FONT_AWESOME/font-awesome/scss/_icons.scss", "utf-8", function(err, _data) { | |
var icons = []; | |
// Extract icon name (if any) on this line | |
while ((icon = re.exec(_data)) != null) { | |
icons.push(icon[1]); | |
} | |
// Save icons as a JSON string | |
fs.writeFile('PATH_TO_SAVE/icons.json', JSON.stringify(icons), function(err) {}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment