2024-03-01 16:11:51 +00:00
|
|
|
import fs from "fs";
|
|
|
|
import gulp from "gulp";
|
|
|
|
import cleanCSS from "gulp-clean-css";
|
2024-03-01 16:25:44 +00:00
|
|
|
import {deleteSync} from "del";
|
2024-03-01 16:11:51 +00:00
|
|
|
import noop from "gulp-noop";
|
|
|
|
import rename from "gulp-rename";
|
|
|
|
import gulpSass from "gulp-sass";
|
|
|
|
import * as nodeSass from "sass";
|
|
|
|
const sass = gulpSass(nodeSass);
|
|
|
|
import sourcemaps from "gulp-sourcemaps";
|
|
|
|
import ts from "gulp-typescript";
|
|
|
|
import webpack from "webpack-stream";
|
2024-03-01 16:25:44 +00:00
|
|
|
import vinylPaths from "vinyl-paths";
|
2023-08-04 12:45:10 +01:00
|
|
|
|
2024-02-26 00:43:57 +00:00
|
|
|
const srcDir = "src";
|
2024-03-01 17:10:20 +00:00
|
|
|
const tmpDir = "tmp";
|
2024-02-26 00:43:57 +00:00
|
|
|
const destDir = "OliverBooth/wwwroot";
|
2024-03-01 17:06:48 +00:00
|
|
|
const isDevelopment = !!process.env.DEVELOPMENT;
|
2023-08-04 12:45:10 +01:00
|
|
|
|
2024-03-01 16:25:44 +00:00
|
|
|
function cleanTMP() {
|
2024-03-01 17:10:20 +00:00
|
|
|
return gulp.src(tmpDir, {allowEmpty: true})
|
2024-03-01 16:25:44 +00:00
|
|
|
.pipe(vinylPaths(deleteSync));
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanWWWRoot() {
|
|
|
|
return gulp.src(destDir, {allowEmpty: true})
|
|
|
|
.pipe(vinylPaths(deleteSync));
|
|
|
|
}
|
|
|
|
|
2023-08-04 12:45:10 +01:00
|
|
|
function compileSCSS() {
|
2023-08-04 12:55:16 +01:00
|
|
|
return gulp.src(`${srcDir}/scss/**/*.scss`)
|
2024-03-01 17:06:48 +00:00
|
|
|
.pipe(isDevelopment ? sourcemaps.init() : noop())
|
2024-02-26 00:43:57 +00:00
|
|
|
.pipe(sass().on("error", sass.logError))
|
|
|
|
.pipe(cleanCSS({compatibility: "ie11"}))
|
|
|
|
.pipe(rename({suffix: ".min"}))
|
2024-03-01 17:06:48 +00:00
|
|
|
.pipe(isDevelopment ? sourcemaps.write() : noop())
|
2023-08-04 12:55:16 +01:00
|
|
|
.pipe(gulp.dest(`${destDir}/css`));
|
|
|
|
}
|
|
|
|
|
|
|
|
function compileTS() {
|
2023-08-10 14:34:01 +01:00
|
|
|
return gulp.src(`${srcDir}/ts/**/*.ts`)
|
2024-03-01 17:06:48 +00:00
|
|
|
.pipe(isDevelopment ? sourcemaps.init() : noop())
|
2023-08-10 04:56:12 +01:00
|
|
|
.pipe(ts("tsconfig.json"))
|
2024-03-01 17:08:23 +00:00
|
|
|
.pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
|
2024-03-01 17:10:20 +00:00
|
|
|
.pipe(gulp.dest(`${tmpDir}/js`));
|
2023-08-10 14:34:01 +01:00
|
|
|
}
|
2023-08-10 04:56:12 +01:00
|
|
|
|
2024-02-27 14:49:29 +00:00
|
|
|
function bundleJS(done) {
|
2024-03-01 17:10:20 +00:00
|
|
|
const tasks = fs.readdirSync(`${tmpDir}/js`, {withFileTypes: true})
|
2024-02-27 14:49:29 +00:00
|
|
|
.filter(dirent => dirent.isDirectory())
|
|
|
|
.map(d => bundleDir(d.name));
|
2024-03-01 17:08:23 +00:00
|
|
|
return gulp.parallel(...tasks, writeSourcemaps)(done);
|
2024-02-27 14:49:29 +00:00
|
|
|
|
|
|
|
function bundleDir(directory) {
|
2024-03-01 17:10:20 +00:00
|
|
|
return () => gulp.src(`${tmpDir}/js/${directory}/${directory}.js`)
|
2024-03-01 17:06:48 +00:00
|
|
|
.pipe(isDevelopment ? sourcemaps.init() : noop())
|
2024-03-01 17:08:23 +00:00
|
|
|
.pipe(webpack({mode: "production", output: {filename: `${directory}.min.js`}, devtool: "source-map"}))
|
|
|
|
.pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
|
|
|
|
.pipe(gulp.dest(`${destDir}/js`));
|
|
|
|
}
|
|
|
|
|
|
|
|
function writeSourcemaps() {
|
|
|
|
return gulp.src(`${destDir}/js/**/*.js`)
|
|
|
|
.pipe(isDevelopment ? sourcemaps.init({ loadMaps: true }) : noop())
|
|
|
|
.pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
|
2024-02-27 14:49:29 +00:00
|
|
|
.pipe(gulp.dest(`${destDir}/js`));
|
|
|
|
}
|
2023-08-04 12:45:10 +01:00
|
|
|
}
|
|
|
|
|
2023-08-08 01:20:11 +01:00
|
|
|
function copyJS() {
|
|
|
|
return gulp.src(`${srcDir}/ts/**/*.js`)
|
2024-02-26 00:43:57 +00:00
|
|
|
.pipe(rename({suffix: ".min"}))
|
2023-08-08 01:20:11 +01:00
|
|
|
.pipe(gulp.dest(`${destDir}/js`));
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyCSS() {
|
|
|
|
return gulp.src(`${srcDir}/scss/**/*.css`)
|
2024-02-26 00:43:57 +00:00
|
|
|
.pipe(rename({suffix: ".min"}))
|
2023-08-08 01:20:11 +01:00
|
|
|
.pipe(gulp.dest(`${destDir}/css`));
|
|
|
|
}
|
|
|
|
|
2023-08-06 16:05:44 +01:00
|
|
|
function copyImages() {
|
|
|
|
return gulp.src(`${srcDir}/img/**/*.*`)
|
|
|
|
.pipe(gulp.dest(`${destDir}/img`));
|
|
|
|
}
|
|
|
|
|
2024-03-01 16:25:44 +00:00
|
|
|
function exists(path) {
|
|
|
|
try {
|
|
|
|
return fs.existsSync(path);
|
|
|
|
} catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task("clean", gulp.parallel(cleanTMP, cleanWWWRoot));
|
2024-03-01 16:11:51 +00:00
|
|
|
gulp.task("assets", copyImages);
|
|
|
|
gulp.task("styles", gulp.parallel(compileSCSS, copyCSS));
|
|
|
|
gulp.task("scripts", gulp.parallel(copyJS, gulp.series(compileTS, bundleJS)));
|
2024-03-01 16:25:44 +00:00
|
|
|
gulp.task("default", gulp.series("clean", gulp.parallel("styles", "scripts", "assets"), cleanTMP));
|