2022-12-04 20:26:31 +00:00
|
|
|
import browserSync, { BrowserSyncInstance } from "browser-sync";
|
|
|
|
import GulpClient, { TaskFunction } from "gulp";
|
|
|
|
import path from "upath";
|
2022-12-04 19:47:18 +00:00
|
|
|
import { Context } from "./gulp/Context.js";
|
|
|
|
|
2022-12-05 17:48:19 +00:00
|
|
|
const { dest, parallel, series, src, watch } = GulpClient;
|
2022-12-04 20:26:31 +00:00
|
|
|
const { join } = path;
|
|
|
|
|
2022-12-04 19:47:18 +00:00
|
|
|
const context = new Context();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds javascript files.
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* The resulting stream.
|
|
|
|
*/
|
|
|
|
export function JavaScript(): NodeJS.ReadWriteStream
|
|
|
|
{
|
|
|
|
return src(context.SourcePath(context.JSDirName, "**", "*.js")).pipe(
|
|
|
|
dest(context.StaticPath(context.JSDirName)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds css files.
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* The resulting stream.
|
|
|
|
*/
|
|
|
|
export function Styles(): NodeJS.ReadWriteStream
|
|
|
|
{
|
|
|
|
return src(context.SourcePath(context.StyleDirName, "**", "*.css")).pipe(
|
|
|
|
dest(context.StaticPath(context.StyleDirName)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds asset files.
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* The resulting stream.
|
|
|
|
*/
|
|
|
|
export function Assets(): NodeJS.ReadWriteStream
|
|
|
|
{
|
|
|
|
return src(context.SourcePath(context.AssetDirName, "**", "*")).pipe(
|
|
|
|
dest(context.StaticPath(context.AssetDirName)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the web pages.
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* The resulting stream.
|
|
|
|
*/
|
|
|
|
export function WebPages(): NodeJS.ReadWriteStream
|
|
|
|
{
|
|
|
|
return src(context.SourcePath("**", "*.html")).pipe(
|
|
|
|
dest(context.StaticPath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds all files.
|
|
|
|
*/
|
|
|
|
export function Build(): Promise<void>
|
|
|
|
{
|
|
|
|
return new Promise<void>(
|
|
|
|
(resolve, reject) =>
|
|
|
|
{
|
|
|
|
parallel(
|
|
|
|
[
|
|
|
|
JavaScript,
|
|
|
|
Styles,
|
|
|
|
Assets,
|
|
|
|
WebPages
|
|
|
|
])(
|
|
|
|
(error) =>
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-12-04 20:26:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reloads all browsers using `browser-sync`.
|
|
|
|
*
|
|
|
|
* @param syncer
|
|
|
|
* The browser-sync instance to work on.
|
|
|
|
*
|
|
|
|
* @param filePath
|
|
|
|
* A glob-path which points to the files which must be reloaded.
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* The actual task.
|
|
|
|
*/
|
|
|
|
function BrowserSync(syncer: BrowserSyncInstance, filePath?: string): TaskFunction
|
|
|
|
{
|
|
|
|
let BrowserSync: TaskFunction = (done) =>
|
|
|
|
{
|
|
|
|
if (filePath)
|
|
|
|
{
|
|
|
|
syncer.reload(filePath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
syncer.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
|
|
|
return BrowserSync;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds and watches the files for changes.
|
|
|
|
*/
|
2022-12-05 17:45:55 +00:00
|
|
|
export let Watch: TaskFunction = async (): Promise<void> =>
|
2022-12-04 20:26:31 +00:00
|
|
|
{
|
2022-12-05 17:45:55 +00:00
|
|
|
return new Promise<void>(
|
|
|
|
(resolve, reject) =>
|
|
|
|
{
|
|
|
|
series(Build)(
|
|
|
|
(error) =>
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
let syncer = browserSync.create();
|
|
|
|
|
|
|
|
syncer.init({
|
|
|
|
open: false,
|
2022-12-14 08:49:56 +00:00
|
|
|
proxy: "http://localhost:1337",
|
2022-12-05 17:45:55 +00:00
|
|
|
online: false
|
|
|
|
});
|
2022-12-09 23:29:14 +00:00
|
|
|
|
2022-12-05 17:45:55 +00:00
|
|
|
watch(
|
|
|
|
context.SourcePath(context.JSDirName),
|
|
|
|
series(
|
|
|
|
JavaScript,
|
|
|
|
BrowserSync(syncer, "*.js")));
|
2022-12-09 23:29:14 +00:00
|
|
|
|
2022-12-05 17:45:55 +00:00
|
|
|
watch(
|
|
|
|
context.SourcePath(context.StyleDirName, "**", "*.css"),
|
|
|
|
series(
|
|
|
|
Styles,
|
|
|
|
BrowserSync(syncer, "*.css")));
|
2022-12-09 23:29:14 +00:00
|
|
|
|
2022-12-05 17:45:55 +00:00
|
|
|
watch(
|
|
|
|
context.SourcePath(context.AssetDirName),
|
|
|
|
series(
|
|
|
|
Assets,
|
|
|
|
BrowserSync(syncer, join(context.AssetDirName, "**", "*"))));
|
2022-12-09 23:29:14 +00:00
|
|
|
|
2022-12-05 17:45:55 +00:00
|
|
|
watch(
|
|
|
|
context.SourcePath("**", "*.html"),
|
|
|
|
series(
|
|
|
|
WebPages,
|
|
|
|
BrowserSync(syncer, "*.html")));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-12-09 23:29:14 +00:00
|
|
|
};
|