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

resources/assets/bootstrap/grunt/bs-commonjs-generator.js   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 23
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
wmc 3
c 1
b 0
f 1
nc 1
mnd 1
bc 4
fnc 2
dl 0
loc 23
rs 10
bpm 2
cpm 1.5
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A bs-commonjs-generator.js ➔ generateCommonJSModule 0 16 2
1
/*!
2
 * Bootstrap Grunt task for the CommonJS module 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
var path = require('path');
12
13
var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
14
15
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
16
  var destDir = path.dirname(destFilepath);
17
18
  function srcPathToDestRequire(srcFilepath) {
19
    var requirePath = path.relative(destDir, srcFilepath).replace(/\\/g, '/');
20
    return 'require(\'' + requirePath + '\')';
21
  }
22
23
  var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
24
  try {
25
    fs.writeFileSync(destFilepath, moduleOutputJs);
26
  } catch (err) {
27
    grunt.fail.warn(err);
28
  }
29
  grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
30
};
31