Passed
Push — develop ( e7ec38...725177 )
by Paul
06:49
created

gulpfile.js (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 minify          = require('gulp-babel-minify');
12
var potomo          = require('gulp-potomo');
13
var pottopo         = require('gulp-pottopo');
14
var pump            = require('pump');
15
var sass            = require('gulp-sass');
16
var sort            = require('gulp-sort');
17
var uglify          = require('gulp-uglify');
18
var wpPot           = require('gulp-wp-pot');
19
var yaml            = require('yamljs');
20
21
var config = yaml.load('+/config.yml');
22
23
gulp.task('bump', function(cb) {
24
  var type = 'patch';
25
  ['prerelease','patch','minor','major'].some(function(arg) {
26
    if( !args[arg] )return;
0 ignored issues
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...
27
    type = arg;
28
    return true;
29
  });
30
  pump([
31
    gulp.src(config.bump),
32
    bump({type:type,keys:['stable tag','version']}),
33
    gulp.dest('.'),
34
  ], cb);
35
});
36
37
gulp.task('css', function(cb) {
38
  var streams = mergeStream();
39
  for(var key in config.styles) {
40
    if(!config.styles.hasOwnProperty(key))continue;
0 ignored issues
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...
41
    streams.add(gulp.src(config.styles[key]).pipe(concat(key)));
42
  }
43
  pump([
44
    streams,
45
    gulpif(args.production, cssnano()),
46
    gulp.dest(config.dest.css),
47
  ], cb);
48
});
49
50
gulp.task('js', function(cb) {
51
  var streams = mergeStream();
52
  for(var key in config.scripts) {
53
    if(!config.scripts.hasOwnProperty(key))continue;
54
    streams.add(gulp.src(config.scripts[key]).pipe(concat(key)));
55
  }
56
  pump([
57
    streams,
58
    // gulpif(args.production, uglify({
59
    //   output: {comments: 'some'},
60
    // })),
61
    gulpif(args.production, minify({
62
      // mangle: {keepClassName: true},
63
    })),
64
    gulp.dest(config.dest.js),
65
  ], cb);
66
});
67
68
gulp.task('jshint', function(cb) {
69
  pump([
70
    gulp.src(config.watch.js),
71
    jshint(),
72
    jshint.reporter('jshint-stylish'),
73
    jshint.reporter('fail'),
74
  ], cb);
75
});
76
77
gulp.task('po-to-mo', function(cb) {
78
  pump([
79
    gulp.src(config.dest.lang + '*.po'),
80
    potomo(),
81
    gulp.dest(config.dest.lang),
82
  ], cb);
83
});
84
85
gulp.task('pot', function(cb) {
86
  pump([
87
    gulp.src(config.watch.php),
88
    checktextdomain({
89
      text_domain: config.language.domain,
90
      keywords: [
91
        '__:1,2d',
92
        '_e:1,2d',
93
        '_x:1,2c,3d',
94
        'esc_html__:1,2d',
95
        'esc_html_e:1,2d',
96
        'esc_html_x:1,2c,3d',
97
        'esc_attr__:1,2d',
98
        'esc_attr_e:1,2d',
99
        'esc_attr_x:1,2c,3d',
100
        '_ex:1,2c,3d',
101
        '_n:1,2,4d',
102
        '_nx:1,2,4c,5d',
103
        '_n_noop:1,2,3d',
104
        '_nx_noop:1,2,3c,4d',
105
      ],
106
    }),
107
    sort(),
108
    wpPot({
109
      domain: config.language.domain,
110
      lastTranslator: config.language.translator,
111
      team: config.language.team,
112
    }),
113
    gulp.dest(config.dest.lang + config.language.domain + '.pot'),
114
  ], cb);
115
});
116
117
gulp.task('pot-to-po', function(cb) {
118
  pump([
119
    gulp.src(config.dest.lang + '*.pot'),
120
    pottopo(),
121
    gulp.dest(config.dest.lang),
122
  ], cb);
123
});
124
125
gulp.task('scss', function(cb) {
126
  pump([
127
    gulp.src(config.watch.scss),
128
    sass({
129
      outputStyle: 'expanded',
130
    }).on('error', sass.logError),
131
    autoprefixer('last 2 versions'),
132
    gulpif(args.production, cssnano({
133
      minifyFontValues: false,
134
      discardComments: {removeAll: true},
135
      zindex: false,
136
    })),
137
    gulp.dest(config.dest.css),
138
  ], cb);
139
});
140
141
gulp.task('watch', function() {
142
  gulp.watch(config.watch.css, gulp.parallel('css'));
143
  gulp.watch(config.watch.js, gulp.parallel('jshint', 'js'));
144
  gulp.watch(config.watch.scss, gulp.parallel('scss'));
145
});
146
147
gulp.task('languages', gulp.series('pot', 'pot-to-po', 'po-to-mo'));
148
gulp.task('default', gulp.parallel('css', 'js', 'jshint', 'scss'));
149
gulp.task('build', gulp.parallel('default', 'languages'));
150