Passed
Push — master ( e65c11...9fa456 )
by Julien
10:18 queued 05:55
created

resources/assets/bootstrap/grunt/bs-glyphicons-data-generator.js   A

Complexity

Total Complexity 5
Complexity/F 5

Size

Lines of Code 35
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
wmc 5
c 1
b 0
f 1
nc 1
mnd 2
bc 6
fnc 1
dl 0
loc 35
rs 10
bpm 6
cpm 5
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B bs-glyphicons-data-generator.js ➔ generateGlyphiconsData 0 31 5
1
/*!
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)
6
 */
7
8
'use strict';
9
10
var fs = require('fs');
11
12
module.exports = function generateGlyphiconsData(grunt) {
13
  // Pass encoding, utf8, so `readFileSync` will return a string instead of a
14
  // buffer
15
  var glyphiconsFile = fs.readFileSync('less/glyphicons.less', 'utf8');
16
  var glyphiconsLines = glyphiconsFile.split('\n');
17
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);
25
26
    if (match !== null) {
27
      glyphiconsData += '- ' + match[1] + '\n';
28
    }
29
  }
30
31
  // Create the `_data` directory if it doesn't already exist
32
  if (!fs.existsSync('docs/_data')) {
33
    fs.mkdirSync('docs/_data');
34
  }
35
36
  try {
37
    fs.writeFileSync(glyphiconsYml, glyphiconsData);
38
  } catch (err) {
39
    grunt.fail.warn(err);
40
  }
41
  grunt.log.writeln('File ' + glyphiconsYml.cyan + ' created.');
42
};
43