Test Failed
Push — master ( a95317...fac2f0 )
by Paul
03:50
created

gulpfile.js (2 issues)

1
var args            = require('yargs').argv;
2
var autoprefixer    = require('gulp-autoprefixer');
3
var bump            = require('gulp-bump');
4
var checktextdomain = require('gulp-checktextdomain');
5
var concat          = require('gulp-concat');
6
var cssnano         = require('gulp-cssnano');
7
var gulp            = require('gulp');
8
var gulpif          = require('gulp-if');
9
var jshint          = require('gulp-jshint');
10
var mergeStream     = require('merge-stream');
11
var potomo          = require('gulp-potomo');
12
var pottopo         = require('gulp-pottopo');
13
var pump            = require('pump');
14
var sass            = require('gulp-sass');
15
var sort            = require('gulp-sort');
16
var uglify          = require('gulp-uglify');
17
var wpPot           = require('gulp-wp-pot');
18
var yaml            = require('yamljs');
19
20
var config = yaml.load('+/config.yml');
21
22
gulp.task('bump', function(cb) {
23
  var type = 'patch';
24
  ['prerelease','patch','minor','major'].some(function(arg) {
25
    if( !args[arg] )return;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
26
    type = arg;
27
    return true;
28
  });
29
  pump([
30
    gulp.src(config.bump),
31
    bump({type:type,keys:['stable tag','version']}),
32
    gulp.dest('.'),
33
  ], cb);
34
});
35
36
gulp.task('js', function(cb) {
37
  var streams = mergeStream();
38
  for(var key in config.scripts) {
39
    if(!config.scripts.hasOwnProperty(key))continue;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
40
    streams.add(gulp.src(config.scripts[key]).pipe(concat(key)));
41
  }
42
  pump([
43
    streams,
44
    gulpif(args.production, uglify({
45
      output: {comments: 'some'},
46
    })),
47
    gulp.dest(config.dest.js),
48
  ], cb);
49
});
50
51
gulp.task('jshint', function(cb) {
52
  pump([
53
    gulp.src(config.watch.js),
54
    jshint(),
55
    jshint.reporter('jshint-stylish'),
56
    jshint.reporter('fail'),
57
  ], cb);
58
});
59
60
gulp.task('po-to-mo', function(cb) {
61
  pump([
62
    gulp.src(config.dest.lang + '*.po'),
63
    potomo(),
64
    gulp.dest(config.dest.lang),
65
  ], cb);
66
});
67
68
gulp.task('pot', function(cb) {
69
  pump([
70
    gulp.src(config.watch.php),
71
    checktextdomain({
72
      text_domain: config.language.domain,
73
      keywords: [
74
        '__:1,2d',
75
        '_e:1,2d',
76
        '_x:1,2c,3d',
77
        'esc_html__:1,2d',
78
        'esc_html_e:1,2d',
79
        'esc_html_x:1,2c,3d',
80
        'esc_attr__:1,2d',
81
        'esc_attr_e:1,2d',
82
        'esc_attr_x:1,2c,3d',
83
        '_ex:1,2c,3d',
84
        '_n:1,2,4d',
85
        '_nx:1,2,4c,5d',
86
        '_n_noop:1,2,3d',
87
        '_nx_noop:1,2,3c,4d',
88
      ],
89
    }),
90
    sort(),
91
    wpPot({
92
      domain: config.language.domain,
93
      lastTranslator: config.language.translator,
94
      team: config.language.team,
95
    }),
96
    gulp.dest(config.dest.lang + config.language.domain + '.pot'),
97
  ], cb);
98
});
99
100
gulp.task('pot-to-po', function(cb) {
101
  pump([
102
    gulp.src(config.dest.lang + '*.pot'),
103
    pottopo(),
104
    gulp.dest(config.dest.lang),
105
  ], cb);
106
});
107
108
gulp.task('scss', function(cb) {
109
  pump([
110
    gulp.src(config.watch.scss),
111
    sass({
112
      outputStyle: 'expanded',
113
    }).on('error', sass.logError),
114
    autoprefixer('last 2 versions'),
115
    gulpif(args.production, cssnano({
116
      minifyFontValues: false,
117
      discardComments: {removeAll: true},
118
      zindex: false,
119
    })),
120
    gulp.dest(config.dest.css),
121
  ], cb);
122
});
123
124
gulp.task('watch', function() {
125
  gulp.watch(config.watch.js, gulp.parallel('jshint', 'js'));
126
  gulp.watch(config.watch.scss, gulp.parallel('scss'));
127
});
128
129
gulp.task('languages', gulp.series('pot', 'pot-to-po', 'po-to-mo'));
130
gulp.task('default', gulp.parallel('scss', 'jshint', 'js'));
131
gulp.task('build', gulp.parallel('default', 'languages'));
132