forked from ibericode/mailchimp-for-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·80 lines (68 loc) · 2.33 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const rename = require("gulp-rename");
const cssmin = require('gulp-cssmin');
const source = require('vinyl-source-stream');
const browserify = require('browserify');
const replace = require('gulp-replace');
const merge = require('merge-stream');
const streamify = require('gulp-streamify');
const globby = require('globby');
const buffer = require('vinyl-buffer');
const through = require('through2');
const sourcemaps = require('gulp-sourcemaps');
const wrap = require('gulp-wrap');
const wpPot = require('gulp-wp-pot');
gulp.task('default', ['sass', 'browserify', 'uglify', 'pot']);
gulp.task('sass', function () {
let files = './assets/sass/[^_]*.scss';
return gulp.src(files)
// create .css file
.pipe(sass())
.pipe(rename({ extname: '.css' }))
.pipe(gulp.dest('./assets/css'))
// create .min.css
.pipe(cssmin())
.pipe(rename({extname: '.min.css'}))
.pipe(gulp.dest("./assets/css"));
});
gulp.task('browserify', function () {
let bundledStream = through()
.pipe(buffer());
globby("./assets/browserify/[^_]*.js").then(function(entries) {
merge(entries.map(function(entry) {
let filename = entry.split('/').pop();
return browserify({entries: [entry]})
.transform("babelify", {presets: ["es2015"]})
.bundle()
.pipe(source(filename))
.pipe(wrap('(function () { var require = undefined; var define = undefined; <%=contents%> })();'))
// create .js file
.pipe(rename({ extname: '.js' }))
.pipe(gulp.dest('./assets/js'));
})).pipe(bundledStream);
}).catch(function(err) {
console.log(err);
});
return bundledStream;
});
gulp.task('uglify', ['browserify'], function() {
return gulp.src(['./assets/js/**/*.js','!./assets/js/**/*.min.js'])
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(streamify(uglify()))
.pipe(rename({extname: '.min.js'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./assets/js'));
});
gulp.task('pot', function () {
const domain = 'mailchimp-for-wp';
return gulp.src('includes/**/**/*.php')
.pipe(wpPot({ domain: domain}))
.pipe(gulp.dest(`languages/${domain}.pot`));
});
gulp.task('watch', function () {
gulp.watch('./assets/sass/**/*.scss', ['sass']);
gulp.watch('./assets/browserify/**/*.js', ['browserify']);
});