const gulp = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const sourcemaps = require("gulp-sourcemaps");
const watch = require("gulp-watch");
const cleanCSS = require("gulp-clean-css");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");

gulp.task("sass-build", () => {
	return gulp.src("./public_html/scss/index.scss")
		.pipe(sourcemaps.init())
		.pipe(sass().on("error", sass.logError))
		.pipe(concat("style.css"))
		.pipe(cleanCSS())
		.pipe(sourcemaps.write("./"))
		.pipe(gulp.dest("./public_html/"));
});

// gulp.task("js-build", () => {
// 	return gulp.src("./assets/olainfarm/js/*.js")
// 		.pipe(sourcemaps.init())
// 		.pipe(concat("olainfarm.16.01.25.min.js"))
// 		.pipe(uglify())
// 		.pipe(sourcemaps.write("./"))
// 		.pipe(gulp.dest("./assets/js/olainfarm/dist"));
// });

gulp.task("build-release-sass", () => {
	return gulp.src("./public_html/scss/index.scss")
		.pipe(sass().on("error", sass.logError))
		.pipe(concat("style.css"))
		.pipe(cleanCSS())
		.pipe(gulp.dest("./public_html/"));
});

// gulp.task("build-release-js", () => {
// 	return gulp.src("./js/*.js")
// 		.pipe(concat("olainfarm.16.01.25.min.js"))
// 		.pipe(uglify())
// 		.pipe(gulp.dest("./assets/olainfarm/js/olainfarm/dist"));
// });

async function cleanMaps() {
  const { deleteAsync } = await import('del');
  return deleteAsync(["./public_html/*.map"]);
}

gulp.task("clean-maps", cleanMaps);

gulp.task("build-release", gulp.series("build-release-sass", /*"build-release-js",*/ "clean-maps"));

gulp.task("watch", () => {
	gulp.watch("./public_html/scss/**/*.scss", gulp.series("sass-build"));
	// gulp.watch("./assets/olainfarm/js/**/*.js", gulp.series("js-build"));
});