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

gulpfile.js (1 issue)

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 potomo          = require('gulp-potomo');
12
var pseudo          = require('gulp-pseudo-i18n');
13
var pump            = require('pump');
14
var rename          = require('gulp-rename');
15
var runSequence     = require('run-sequence');
16
var sass            = require('gulp-sass');
17
var sort            = require('gulp-sort');
18
var uglify          = require('gulp-uglify');
19
var wpPot           = require('gulp-wp-pot');
20
var yaml            = require('yamljs');
21
22
var config = yaml.load('+/config.yml');
23
24
/* JSHint Task
25
 -------------------------------------------------- */
26
gulp.task('jshint', function() {
27
  pump([
28
    gulp.src(config.watch.js),
29
    jshint(),
30
    jshint.reporter('jshint-stylish'),
31
    jshint.reporter('fail'),
32
  ]);
33
});
34
35
/* JS Task
36
 -------------------------------------------------- */
37
gulp.task('js', function() {
38
  var streams = mergeStream();
39
  for(var key in config.scripts) {
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
  ]);
49
});
50
51
/* CSS Task
52
 -------------------------------------------------- */
53
gulp.task('css', function() {
54
  var streams = mergeStream();
55
  for(var key in config.styles) {
56
    streams.add(gulp.src(config.styles[key]).pipe(concat(key)));
57
  }
58
  pump([
59
    streams,
60
    gulpif(args.production, cssnano()),
61
    gulp.dest(config.dest.css),
62
  ]);
63
});
64
65
/* SCSS Task
66
 -------------------------------------------------- */
67
gulp.task('scss', function() {
68
  pump([
69
    gulp.src(config.watch.scss),
70
    sass({
71
      outputStyle: 'expanded',
72
    }).on('error', sass.logError),
73
    autoprefixer('last 2 versions'),
74
    gulpif(args.production, cssnano({
75
      minifyFontValues: false,
76
      discardComments: { removeAll: true }
77
    })),
78
    gulp.dest(config.dest.css),
79
  ]);
80
});
81
82
/* Language Tasks
83
 -------------------------------------------------- */
84
gulp.task('languages', function() {
85
  return runSequence('po', 'mo')
86
});
87
88
gulp.task('po', function() {
89
  return pump([
90
    gulp.src(config.watch.php),
91
    checktextdomain({
92
      text_domain: config.language.domain,
93
      keywords: [
94
        '__:1,2d',
95
        '_e:1,2d',
96
        '_x:1,2c,3d',
97
        'esc_html__:1,2d',
98
        'esc_html_e:1,2d',
99
        'esc_html_x:1,2c,3d',
100
        'esc_attr__:1,2d',
101
        'esc_attr_e:1,2d',
102
        'esc_attr_x:1,2c,3d',
103
        '_ex:1,2c,3d',
104
        '_n:1,2,4d',
105
        '_nx:1,2,4c,5d',
106
        '_n_noop:1,2,3d',
107
        '_nx_noop:1,2,3c,4d',
108
      ],
109
    }),
110
    sort(),
111
    wpPot({
112
      domain: config.language.domain,
113
      lastTranslator: config.language.translator,
114
      team: config.language.team,
115
    }),
116
    pseudo({
117
      charMap: {},
118
    }),
119
    rename(config.language.domain + '-en_US.po'),
120
    gulp.dest(config.dest.lang),
121
  ]);
122
});
123
124
gulp.task('mo', function() {
125
  return pump([
126
    gulp.src(config.dest.lang + '*.po'),
127
    potomo(),
128
    gulp.dest(config.dest.lang),
129
  ]);
130
});
131
132
/* Version Task
133
 -------------------------------------------------- */
134
gulp.task('bump', function() {
135
  ['patch', 'minor', 'major'].some(function(arg) {
136
    if(!args[arg])return;
137
    for(var key in config.bump) {
138
      if(!config.bump.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...
139
      pump([
140
        gulp.src(config.bump[key]),
141
        bump({type:arg,key:key}),
142
        gulp.dest('.'),
143
      ]);
144
    }
145
  });
146
});
147
148
/* Watch Task
149
 -------------------------------------------------- */
150
gulp.task('watch', function() {
151
  gulp.watch(config.watch.css, ['css']);
152
  gulp.watch(config.watch.js, ['jshint', 'js']);
153
  gulp.watch(config.watch.scss, ['scss']);
154
});
155
156
/* Default Task
157
 -------------------------------------------------- */
158
gulp.task('default', function() {
159
  gulp.start('css', 'scss', 'jshint', 'js')
160
});
161
162
/* Build Task
163
 -------------------------------------------------- */
164
gulp.task('build', function() {
165
  gulp.start('css', 'scss', 'jshint', 'js', 'languages')
166
});
167