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