gulp/tasks/html.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1.29

Size

Lines of Code 60
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 46
mnd 2
bc 2
fnc 7
dl 0
loc 60
rs 10
bpm 0.2857
cpm 1.2857
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
C html.js ➔ html 0 39 9
1
const fs = require('fs');
2
3
// stringify functions https://gist.github.com/cowboy/3749767
4
var stringify = function (obj) {
5
  var placeholder = '____PLACEHOLDER____';
6
  var fns = [];
7
  var json = JSON.stringify(obj, function (key, value) {
8
    if (typeof value === 'function') {
9
      fns.push(value);
10
      return placeholder;
11
    }
12
    return value;
13
  }, 2);
14
  json = json.replace(new RegExp('"' + placeholder + '"', 'g'), function () {
15
    return fns.shift();
16
  });
17
  return json;
18
};
19
20
module.exports = function (gulp, plugins, config, env) {
21
  return function html() {
22
    return gulp.src(env.production() ? config.build + '/*.html' : 'html/*.html')
23
      .pipe(plugins.realFavicon.injectFaviconMarkups(JSON.parse(fs.readFileSync(config.faviconData)).favicon.html_code))
24
      .pipe(env.production(plugins.inlineSource({ compress: false })))
25
      .pipe(plugins.inject(gulp.src(['config.js']), {
26
        removeTags: true,
27
        starttag: '<!-- inject:config -->',
28
        transform: function () {
29
          delete require.cache[require.resolve('../../config.default')];
30
          delete require.cache[require.resolve('../../config')];
31
          var buildConfig = Object.assign({}, require('../../config.default')(), require('../../config')());
32
          return '<title>' + buildConfig.siteName + ' - loading...</title>' +
33
            '<script>window.config =' +
34
            stringify(buildConfig)
35
              .replace('<!-- inject:cache-breaker -->',
36
                Math.random().toString(12).substring(7)) +
37
            ';</script>';
38
        }
39
      }))
40
      .pipe(plugins.inject(gulp.src(['config.js']), {
41
        removeTags: true,
42
        starttag: '<!-- inject:title -->',
43
        transform: function () {
44
          delete require.cache[require.resolve('../../config.default')];
45
          delete require.cache[require.resolve('../../config')];
46
          var buildConfig = Object.assign({}, require('../../config.default')(), require('../../config')());
47
          return buildConfig.siteName;
48
        }
49
      }))
50
      .pipe(plugins.cacheBust({
51
        type: 'timestamp'
52
      }))
53
      .pipe(plugins.htmlmin({
54
        removeComments: true,
55
        collapseWhitespace: true,
56
        minifyJS: true
57
      }))
58
      .pipe(gulp.dest(config.build));
59
  };
60
};
61