2  * Bootstrap Grunt task for Glyphicons data generation
 
   3  * http://getbootstrap.com
 
   4  * Copyright 2014-2015 Twitter, Inc.
 
   5  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 
  10 var fs = require('fs');
 
  12 module.exports = function generateGlyphiconsData(grunt) {
 
  13   // Pass encoding, utf8, so `readFileSync` will return a string instead of a
 
  15   var glyphiconsFile = fs.readFileSync('less/glyphicons.less', 'utf8');
 
  16   var glyphiconsLines = glyphiconsFile.split('\n');
 
  18   // Use any line that starts with ".glyphicon-" and capture the class name
 
  19   var iconClassName = /^\.(glyphicon-[a-zA-Z0-9-]+)/;
 
  20   var glyphiconsData = '# This file is generated via Grunt task. **Do not edit directly.**\n' +
 
  21                        '# See the \'build-glyphicons-data\' task in Gruntfile.js.\n\n';
 
  22   var glyphiconsYml = 'docs/_data/glyphicons.yml';
 
  23   for (var i = 0, len = glyphiconsLines.length; i < len; i++) {
 
  24     var match = glyphiconsLines[i].match(iconClassName);
 
  27       glyphiconsData += '- ' + match[1] + '\n';
 
  31   // Create the `_data` directory if it doesn't already exist
 
  32   if (!fs.existsSync('docs/_data')) {
 
  33     fs.mkdirSync('docs/_data');
 
  37     fs.writeFileSync(glyphiconsYml, glyphiconsData);
 
  41   grunt.log.writeln('File ' + glyphiconsYml.cyan + ' created.');