forked from themeum/tutor-divi-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
145 lines (121 loc) · 3.04 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var gulp = require("gulp"),
sass = require("gulp-sass"),
rename = require("gulp-rename"),
sourcemaps = require("gulp-sourcemaps"),
notify = require("gulp-notify"),
wpPot = require('gulp-wp-pot'),
clean = require("gulp-clean"),
plumber = require("gulp-plumber");
var tasks = {
tutor_divi: {src: "assets/scss/main.scss", mode: 'expanded', destination: 'tutor-divi-style.css'},
tutor_divi_min: {src: "assets/scss/main.scss", mode: 'compressed', destination: 'tutor-divi-style.min.css'},
};
var task_keys = Object.keys(tasks);
var onError = function (err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Basso",
})(err);
this.emit("end");
};
for(let task in tasks) {
let blueprint = tasks[task];
gulp.task(task, function () {
return gulp
.src(blueprint.src)
.pipe(plumber({
errorHandler: onError
}))
.pipe(sass({
outputStyle: blueprint.mode
}))
.pipe(rename(blueprint.destination))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("assets/css"));
});
}
/*
* series for doing multiple task in order 1->2->3
* src is for getting files from the computer
* dest is for transfer file to destination
*/
const { series, src, dest } = require('gulp');
//install plugins
const uglify = require('gulp-uglify');
const zip = require('gulp-zip');
const babel = require('gulp-babel');
// minify all js
function minifyJs(cb) {
return src('assets/js/*.js')
.pipe(babel())
.pipe(uglify())
.pipe(rename('scripts.min.js'))
.pipe(dest('assets/js/'));
cb();
}
//clean existing build zip file
function cleanZip(cb) {
return gulp.src("./tutor-lms-divi-modules.zip", {
read: false,
allowEmpty: true
}).pipe(clean());
cb();
}
//clean file & folders from build
function cleanBuild(cb) {
return gulp.src("./build", {
read: false,
allowEmpty: true
}).pipe(clean());
cb();
};
//create pot file
function makePot(cb) {
return gulp
.src('**/*.php')
.pipe(plumber({
errorHandler: onError
}))
.pipe(wpPot({
domain: 'tutor-lms-divi-modules',
package: 'Tutor Divi Modules'
}))
.pipe(gulp.dest('languages/tutor-lms-divi-modules.pot'));
cb();
};
// bundle all files export to destination directory
function bundleFiles(cb){
return src([
"./**/*.*",
"!./build/**",
"!./assets/scss/**",
"!./media/**",
"!./node_modules/**",
"!./**/*.zip",
"!.github",
"!./gulpfile.js",
"!./readme.md",
"!./README.md",
"!.DS_Store",
"!./**/.DS_Store",
"!./LICENSE.txt",
"!./package.json",
"!./asset-manifest.json",
"!./package-lock.json",
"!./includes/modules/**/*.jsx",
])
.pipe(dest("build/"));
cb();
}
// from destination directory take all files make zip
function exportZip(cb) {
return src("./build/**/*.*").pipe(zip("tutor-lms-divi-modules.zip")).pipe(dest("./"));
cb();
}
gulp.task("watch", function () {
gulp.watch("assets/scss/**/*.scss", gulp.series(...task_keys));
});
exports.default = series(...task_keys, "watch");
exports.build = series(cleanZip,cleanBuild,makePot,bundleFiles, exportZip);