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