Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / CSS / bootstrap / grunt / bs-glyphicons-data-generator.js
1 /*!
2  * Bootstrap Grunt task for Glyphicons data generation
3  * http://getbootstrap.com
4  * Copyright 2014 Twitter, Inc.
5  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
6  */
7 'use strict';
8 var fs = require('fs');
9
10 module.exports = function generateGlyphiconsData(grunt) {
11   // Pass encoding, utf8, so `readFileSync` will return a string instead of a
12   // buffer
13   var glyphiconsFile = fs.readFileSync('less/glyphicons.less', 'utf8');
14   var glyphiconsLines = glyphiconsFile.split('\n');
15
16   // Use any line that starts with ".glyphicon-" and capture the class name
17   var iconClassName = /^\.(glyphicon-[a-zA-Z0-9-]+)/;
18   var glyphiconsData = '# This file is generated via Grunt task. **Do not edit directly.**\n' +
19                        '# See the \'build-glyphicons-data\' task in Gruntfile.js.\n\n';
20   var glyphiconsYml = 'docs/_data/glyphicons.yml';
21   for (var i = 0, len = glyphiconsLines.length; i < len; i++) {
22     var match = glyphiconsLines[i].match(iconClassName);
23
24     if (match !== null) {
25       glyphiconsData += '- ' + match[1] + '\n';
26     }
27   }
28
29   // Create the `_data` directory if it doesn't already exist
30   if (!fs.existsSync('docs/_data')) {
31     fs.mkdirSync('docs/_data');
32   }
33
34   try {
35     fs.writeFileSync(glyphiconsYml, glyphiconsData);
36   }
37   catch (err) {
38     grunt.fail.warn(err);
39   }
40   grunt.log.writeln('File ' + glyphiconsYml.cyan + ' created.');
41 };