Sharkey/gulpfile.js

66 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-11-11 19:02:25 +02:00
/**
* Gulp tasks
*/
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');
gulp.task('copy:backend:views', () =>
gulp.src('./packages/backend/src/server/web/views/**/*').pipe(gulp.dest('./packages/backend/built/server/web/views'))
);
2022-12-27 07:36:33 +02:00
gulp.task('copy:frontend:fonts', () =>
gulp.src('./packages/frontend/node_modules/three/examples/fonts/**/*').pipe(gulp.dest('./built/_frontend_dist_/fonts/'))
2021-11-11 19:02:25 +02:00
);
2022-12-27 07:36:33 +02:00
gulp.task('copy:frontend:tabler-icons', () =>
2023-01-24 07:49:29 +02:00
gulp.src('./packages/frontend/node_modules/@tabler/icons-webfont/**/*').pipe(gulp.dest('./built/_frontend_dist_/tabler-icons/'))
);
2022-12-27 07:36:33 +02:00
gulp.task('copy:frontend:locales', cb => {
fs.mkdirSync('./built/_frontend_dist_/locales', { recursive: true });
2021-11-11 19:02:25 +02:00
const v = { '_version_': meta.version };
for (const [lang, locale] of Object.entries(locales)) {
2022-12-27 07:36:33 +02:00
fs.writeFileSync(`./built/_frontend_dist_/locales/${lang}.${meta.version}.json`, JSON.stringify({ ...locale, ...v }), 'utf-8');
2021-11-11 19:02:25 +02:00
}
cb();
});
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/'));
});
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', './packages/backend/src/server/web/error.css'])
2021-11-11 19:02:25 +02:00
.pipe(cssnano({
zindex: false
}))
.pipe(gulp.dest('./packages/backend/built/server/web/'));
});
gulp.task('build', gulp.parallel(
2022-12-27 07:36:33 +02:00
'copy:frontend:locales', 'copy:backend:views', 'build:backend:script', 'build:backend:style', 'copy:frontend:fonts', 'copy:frontend:tabler-icons'
2021-11-11 19:02:25 +02:00
));
gulp.task('default', gulp.task('build'));
gulp.task('watch', () => {
gulp.watch([
2021-11-19 07:48:59 +02:00
'./packages/*/src/**/*',
2021-11-11 19:02:25 +02:00
], { ignoreInitial: false }, gulp.task('build'));
});