jormungandr-bite/gulpfile.js

101 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-11-11 10:02:25 -07:00
/**
* Gulp tasks
*/
2023-06-05 18:27:40 -06:00
const fs = require("fs");
const gulp = require("gulp");
const replace = require("gulp-replace");
const terser = require("gulp-terser");
const cssnano = require("gulp-cssnano");
const locales = require("./locales");
const meta = require("./package.json");
const customDir = process.env.ICESHRIMP_CUSTOM_DIR ?? "./custom";
2023-06-05 18:27:40 -06:00
gulp.task("copy:backend:views", () =>
gulp
.src("./packages/backend/src/server/web/views/**/*")
.pipe(gulp.dest("./packages/backend/built/server/web/views")),
2021-11-11 10:02:25 -07:00
);
2023-06-05 18:27:40 -06:00
gulp.task("copy:backend:custom", () =>
gulp
.src(`${customDir}/assets/**/*`)
2023-06-05 18:27:40 -06:00
.pipe(gulp.dest("./packages/backend/assets/")),
);
2023-06-05 18:27:40 -06:00
gulp.task("copy:client:fonts", () =>
gulp
.src("./packages/client/node_modules/three/examples/fonts/**/*")
.pipe(gulp.dest("./built/_client_dist_/fonts/")),
2021-11-11 10:02:25 -07:00
);
2023-06-05 18:27:40 -06:00
gulp.task("copy:client:locales", (cb) => {
fs.mkdirSync("./built/_client_dist_/locales", { recursive: true });
2021-11-11 10:02:25 -07:00
2023-06-05 18:27:40 -06:00
const v = { _version_: meta.version };
2021-11-11 10:02:25 -07:00
for (const [lang, locale] of Object.entries(locales)) {
2023-06-05 18:27:40 -06:00
fs.writeFileSync(
`./built/_client_dist_/locales/${lang}.${meta.version}.json`,
JSON.stringify({ ...locale, ...v }),
"utf-8",
);
2021-11-11 10:02:25 -07:00
}
cb();
});
2023-06-05 18:27:40 -06:00
gulp.task("build:backend:script", () => {
return gulp
.src([
"./packages/backend/src/server/web/boot.js",
"./packages/backend/src/server/web/bios.js",
"./packages/backend/src/server/web/cli.js",
])
.pipe(replace("LANGS", JSON.stringify(Object.keys(locales))))
.pipe(
terser({
toplevel: true,
}),
)
.pipe(gulp.dest("./packages/backend/built/server/web/"));
2021-11-11 10:02:25 -07:00
});
2023-06-05 18:27:40 -06:00
gulp.task("build:backend:style", () => {
return gulp
.src([
"./packages/backend/src/server/web/style.css",
"./packages/backend/src/server/web/bios.css",
"./packages/backend/src/server/web/cli.css",
])
.pipe(
cssnano({
zindex: false,
}),
)
.pipe(gulp.dest("./packages/backend/built/server/web/"));
2021-11-11 10:02:25 -07:00
});
2023-06-05 18:27:40 -06:00
gulp.task(
"build",
gulp.parallel(
"copy:client:locales",
"copy:backend:views",
"copy:backend:custom",
"build:backend:script",
"build:backend:style",
"copy:client:fonts",
),
);
2021-11-11 10:02:25 -07:00
2023-06-05 18:27:40 -06:00
gulp.task("default", gulp.task("build"));
2021-11-11 10:02:25 -07:00
2023-06-05 18:27:40 -06:00
gulp.task("watch", () => {
gulp.watch(
["./packages/*/src/**/*"],
{ ignoreInitial: false },
gulp.task("build"),
);
2021-11-11 10:02:25 -07:00
});