2021-08-21 12:26:31 +01:00
|
|
|
const gulp = require("gulp")
|
2021-06-29 22:23:24 +01:00
|
|
|
const browserSync = require("browser-sync").create();
|
|
|
|
const htmlMin = require("gulp-htmlmin");
|
|
|
|
const cssMin = require("gulp-clean-css")
|
2021-07-31 15:39:40 +01:00
|
|
|
const terser = require("gulp-terser");
|
2021-08-21 12:26:31 +01:00
|
|
|
const ftp = require("vinyl-ftp");
|
|
|
|
const env = require("gulp-env");
|
2021-09-02 22:31:45 +01:00
|
|
|
|
2021-08-31 18:50:08 +01:00
|
|
|
env({
|
2021-08-21 12:26:31 +01:00
|
|
|
file: ".env",
|
|
|
|
type: ".ini"
|
2021-08-31 18:50:08 +01:00
|
|
|
});
|
2021-06-29 22:23:24 +01:00
|
|
|
|
|
|
|
gulp.task("minifyHTML", () =>
|
|
|
|
{
|
|
|
|
return gulp.src("src/*.html" )
|
|
|
|
.pipe(htmlMin({collapseWhitespace: true}))
|
|
|
|
.pipe(gulp.dest("dist"));
|
2021-07-02 13:18:52 +01:00
|
|
|
});
|
2021-06-29 22:23:24 +01:00
|
|
|
|
|
|
|
gulp.task("minifyCSS", () =>
|
|
|
|
{
|
2021-09-01 20:37:31 +01:00
|
|
|
return gulp.src("src/css/main.css")
|
2021-06-29 22:23:24 +01:00
|
|
|
.pipe(cssMin({compatibility: "ie8"}))
|
|
|
|
.pipe(gulp.dest("dist/css"));
|
2021-07-02 13:18:52 +01:00
|
|
|
});
|
2021-06-29 22:23:24 +01:00
|
|
|
|
|
|
|
gulp.task("minifyJS", () =>
|
|
|
|
{
|
2021-08-21 12:26:31 +01:00
|
|
|
function createErrorHandler(name)
|
|
|
|
{
|
|
|
|
return function (err)
|
|
|
|
{
|
2021-06-29 22:23:24 +01:00
|
|
|
console.error("Error from " + name + " in compress task", err.toString());
|
|
|
|
};
|
|
|
|
}
|
2021-08-31 18:50:08 +01:00
|
|
|
|
2021-06-29 22:23:24 +01:00
|
|
|
return gulp.src("src/js/*.js")
|
2021-08-31 18:50:08 +01:00
|
|
|
.on("error", createErrorHandler("gulp.src"))
|
|
|
|
.pipe(terser())
|
|
|
|
.on("error", createErrorHandler("terser"))
|
|
|
|
.pipe(gulp.dest("dist/js"))
|
|
|
|
.on("error", createErrorHandler("gulp.dest"));
|
2021-07-02 13:18:52 +01:00
|
|
|
});
|
2021-06-29 22:23:24 +01:00
|
|
|
|
2021-08-22 10:44:49 +01:00
|
|
|
gulp.task("movePHPFiles", () =>
|
|
|
|
{
|
|
|
|
return gulp.src("src/api/*.php")
|
|
|
|
.pipe(gulp.dest("dist/api"))
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("watchFiles", () =>
|
2021-08-21 12:26:31 +01:00
|
|
|
{
|
|
|
|
gulp.watch("src/*.html", gulp.task("minifyHTML"));
|
|
|
|
gulp.watch("src/css/*.css", gulp.task("minifyCSS"));
|
|
|
|
gulp.watch("src/js/*.js", gulp.task("minifyJS"));
|
2021-08-22 10:44:49 +01:00
|
|
|
gulp.watch("src/api/*.php", gulp.task("movePHPFiles"))
|
2021-08-21 12:26:31 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("ftp", () =>
|
|
|
|
{
|
|
|
|
let conn = ftp.create(
|
|
|
|
{
|
|
|
|
host: process.env.host,
|
|
|
|
user: process.env.user,
|
|
|
|
pass: process.env.pass,
|
|
|
|
parallel: 1,
|
|
|
|
});
|
|
|
|
return gulp.src("dist/**", {base: "dist", dot: true})
|
|
|
|
.pipe(conn.newer("/"))
|
|
|
|
.pipe(conn.dest("/"));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("deploy", () =>
|
|
|
|
{
|
|
|
|
gulp.watch("dist", gulp.task("ftp"));
|
|
|
|
});
|
|
|
|
|
2021-06-29 22:23:24 +01:00
|
|
|
gulp.task("browserSync", () =>
|
|
|
|
{
|
|
|
|
browserSync.init({
|
|
|
|
server: {
|
|
|
|
baseDir: "dist"
|
|
|
|
}
|
2021-07-02 13:18:52 +01:00
|
|
|
});
|
|
|
|
gulp.watch("dist").on("change", browserSync.reload)
|
2021-06-29 22:23:24 +01:00
|
|
|
});
|
|
|
|
|
2021-08-31 18:50:08 +01:00
|
|
|
gulp.task("default", gulp.series(gulp.parallel("watchFiles", "deploy")));
|