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");
|
2022-01-01 00:26:39 +00:00
|
|
|
|
|
|
|
const github = (process.env.github) ? true : false;
|
2021-06-29 22:23:24 +01:00
|
|
|
|
|
|
|
gulp.task("minifyHTML", () =>
|
|
|
|
{
|
2022-07-29 20:00:36 +01:00
|
|
|
return gulp.src("src/**/*.html" )
|
2021-06-29 22:23:24 +01:00
|
|
|
.pipe(htmlMin({collapseWhitespace: true}))
|
2022-07-29 20:00:36 +01:00
|
|
|
.pipe(gulp.dest("dist/"));
|
2021-07-02 13:18:52 +01:00
|
|
|
});
|
2021-06-29 22:23:24 +01:00
|
|
|
|
|
|
|
gulp.task("minifyCSS", () =>
|
|
|
|
{
|
2022-07-29 20:00:36 +01:00
|
|
|
return gulp.src("src/**/main.css")
|
2021-06-29 22:23:24 +01:00
|
|
|
.pipe(cssMin({compatibility: "ie8"}))
|
2022-07-29 20:00:36 +01:00
|
|
|
.pipe(gulp.dest("dist/"));
|
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
|
|
|
|
2022-07-29 20:00:36 +01:00
|
|
|
return gulp.src("src/**/*.js")
|
2021-08-31 18:50:08 +01:00
|
|
|
.on("error", createErrorHandler("gulp.src"))
|
|
|
|
.pipe(terser())
|
|
|
|
.on("error", createErrorHandler("terser"))
|
2022-07-29 20:00:36 +01:00
|
|
|
.pipe(gulp.dest("dist/"))
|
2021-08-31 18:50:08 +01:00
|
|
|
.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", () =>
|
|
|
|
{
|
2023-06-08 15:10:27 +01:00
|
|
|
return gulp.src("src/api/**/*.php")
|
|
|
|
.pipe(gulp.dest("dist/api/"))
|
2021-08-22 10:44:49 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("watchFiles", () =>
|
2021-08-21 12:26:31 +01:00
|
|
|
{
|
2022-07-29 20:00:36 +01:00
|
|
|
gulp.watch("src/**/*.html", gulp.task("minifyHTML"));
|
|
|
|
gulp.watch("src/**/*.css", gulp.task("minifyCSS"));
|
|
|
|
gulp.watch("src/**/*.js", gulp.task("minifyJS"));
|
2023-06-08 15:10:27 +01:00
|
|
|
gulp.watch("src/api/**/*.php", gulp.task("movePHPFiles"))
|
2021-08-21 12:26:31 +01:00
|
|
|
});
|
|
|
|
|
2021-06-29 22:23:24 +01:00
|
|
|
gulp.task("browserSync", () =>
|
|
|
|
{
|
|
|
|
browserSync.init({
|
2022-03-31 21:19:30 +01:00
|
|
|
proxy: "https://rohitpai.co.uk/",
|
2021-09-23 15:25:38 +01:00
|
|
|
serveStatic: ["./dist"]
|
|
|
|
|
2021-07-02 13:18:52 +01:00
|
|
|
});
|
|
|
|
gulp.watch("dist").on("change", browserSync.reload)
|
2021-06-29 22:23:24 +01:00
|
|
|
});
|
|
|
|
|
2022-01-01 00:34:03 +00:00
|
|
|
gulp.task("default", async () =>
|
2022-01-01 00:26:39 +00:00
|
|
|
{
|
|
|
|
if(github)
|
|
|
|
{
|
|
|
|
(gulp.series("movePHPFiles", "minifyJS", "minifyHTML", "minifyCSS")());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-11 19:51:53 +00:00
|
|
|
(gulp.series(gulp.parallel("watchFiles", "browserSync"))());
|
2022-01-01 00:26:39 +00:00
|
|
|
}
|
2022-01-01 00:28:26 +00:00
|
|
|
});
|