-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
112 lines (93 loc) · 2.74 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
const gulp = require("gulp");
const nib = require("nib");
const plugins = require("gulp-load-plugins")();
const argv = require("yargs").argv;
const sourcemaps = require("gulp-sourcemaps");
const del = require("del");
const minimist = require("minimist");
const log = require("fancy-log");
const browserSync = require("browser-sync").create();
const defaultOptions = {
importance: null,
version: null,
};
const options = minimist(process.argv.slice(2), { default: defaultOptions });
log.info("Options:", options);
function start(done) {
const port = argv.port || 8890;
const host = argv.host || "localhost";
let projectUrl = "https://" + host;
if (port) {
projectUrl += ":" + port;
}
projectUrl += "/wp-admin/admin.php?page=ninja-forms";
const options = {
proxy: projectUrl,
browser: "google chrome",
port,
open: false,
injectChanges: true,
};
// http://www.browsersync.io/docs/options/
browserSync.init(options, done);
}
function bundle() {
return (
gulp
.src("src/js/main.js")
.pipe(sourcemaps.init())
.pipe(plugins.uglify())
.pipe(plugins.rename({ suffix: ".min" }))
// todo fix, sourcemaps do not seem to work (switch to webpack?)
.pipe(sourcemaps.write())
.pipe(gulp.dest("target/js"))
);
}
function copyVideomailClient() {
return gulp
.src("node_modules/videomail-client/dist/umd/index.js")
.pipe(gulp.dest("target/js/videomail-client"));
}
function css() {
return gulp
.src("src/styl/main.styl")
.pipe(plugins.plumber())
.pipe(
plugins.stylus({
use: [nib()],
errors: true,
}),
)
.pipe(plugins.autoprefixer("last 3 versions", "> 2%"))
.pipe(plugins.bytediff.start())
.pipe(plugins.cssnano())
.pipe(plugins.rename({ suffix: ".min" }))
.pipe(plugins.bytediff.stop())
.pipe(browserSync.stream())
.pipe(gulp.dest("target/css"));
}
function cleanPhp() {
return del(["target/**/*.{php,html}"]);
}
function copyPhp() {
return gulp.src("src/**/*.{php,html}").pipe(gulp.dest("target"));
}
const php = gulp.series(cleanPhp, copyPhp);
function watch() {
gulp.watch("src/**/*.{php,html}", php).on("change", browserSync.reload);
gulp.watch("src/js/**/*.js", bundle).on("change", browserSync.reload);
gulp.watch("src/styl/**/*.styl", css).on("change", browserSync.reload);
}
function zip() {
return gulp
.src(["index.php", "readme.txt", "videomail-for-ninja-forms.php", "target/**"], {
base: "./",
})
.pipe(plugins.zip("videomail-for-ninja-forms.zip"))
.pipe(gulp.dest("dist"));
}
// just builds assets once, nothing else
const build = gulp.series(css, bundle, copyVideomailClient, php);
exports.build = build;
exports.zip = zip;
exports.watch = gulp.series(build, start, watch);