2021-11-12 02:02:25 +09:00
|
|
|
/**
|
|
|
|
* Gulp tasks
|
|
|
|
*/
|
|
|
|
|
2023-07-09 17:19:07 +09:00
|
|
|
import * as fs from 'node:fs';
|
|
|
|
import gulp from 'gulp';
|
2023-07-29 07:26:34 +09:00
|
|
|
import rename from 'gulp-rename';
|
2023-07-09 17:19:07 +09:00
|
|
|
import replace from 'gulp-replace';
|
|
|
|
import terser from 'gulp-terser';
|
|
|
|
import cssnano from 'gulp-cssnano';
|
2021-11-12 02:02:25 +09:00
|
|
|
|
2023-07-09 17:19:07 +09:00
|
|
|
import locales from './locales/index.js';
|
|
|
|
import meta from './package.json' assert { type: "json" };
|
2021-11-12 02:02:25 +09:00
|
|
|
|
|
|
|
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 14:36:33 +09:00
|
|
|
gulp.task('copy:frontend:fonts', () =>
|
|
|
|
gulp.src('./packages/frontend/node_modules/three/examples/fonts/**/*').pipe(gulp.dest('./built/_frontend_dist_/fonts/'))
|
2021-11-12 02:02:25 +09:00
|
|
|
);
|
|
|
|
|
2022-12-27 14:36:33 +09:00
|
|
|
gulp.task('copy:frontend:tabler-icons', () =>
|
2023-01-24 14:49:29 +09:00
|
|
|
gulp.src('./packages/frontend/node_modules/@tabler/icons-webfont/**/*').pipe(gulp.dest('./built/_frontend_dist_/tabler-icons/'))
|
2022-02-09 13:23:29 +09:00
|
|
|
);
|
|
|
|
|
2022-12-27 14:36:33 +09:00
|
|
|
gulp.task('copy:frontend:locales', cb => {
|
|
|
|
fs.mkdirSync('./built/_frontend_dist_/locales', { recursive: true });
|
2021-11-12 02:02:25 +09:00
|
|
|
|
|
|
|
const v = { '_version_': meta.version };
|
|
|
|
|
|
|
|
for (const [lang, locale] of Object.entries(locales)) {
|
2022-12-27 14:36:33 +09:00
|
|
|
fs.writeFileSync(`./built/_frontend_dist_/locales/${lang}.${meta.version}.json`, JSON.stringify({ ...locale, ...v }), 'utf-8');
|
2021-11-12 02:02:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build:backend:script', () => {
|
2023-02-11 21:20:45 +09:00
|
|
|
const clientManifestExists = fs.existsSync('./built/_vite_/manifest.json');
|
|
|
|
const clientEntry = clientManifestExists ?
|
2023-06-13 17:05:18 +09:00
|
|
|
JSON.parse(fs.readFileSync('./built/_vite_/manifest.json', 'utf-8'))['src/_boot_.ts'].file
|
|
|
|
: 'src/_boot_.ts'
|
2023-02-11 21:20:45 +09:00
|
|
|
|
|
|
|
return gulp.src(['./packages/backend/src/server/web/boot.js', './packages/backend/src/server/web/bios.js', './packages/backend/src/server/web/cli.js', './packages/backend/src/server/web/flush.js'])
|
2021-11-12 02:02:25 +09:00
|
|
|
.pipe(replace('LANGS', JSON.stringify(Object.keys(locales))))
|
2023-02-11 21:20:45 +09:00
|
|
|
.pipe(replace('CLIENT_ENTRY', JSON.stringify(clientEntry)))
|
2021-11-12 02:02:25 +09:00
|
|
|
.pipe(terser({
|
|
|
|
toplevel: true
|
|
|
|
}))
|
2023-07-29 07:26:34 +09:00
|
|
|
.pipe(rename({ suffix: `.${meta.version}` }))
|
2023-02-11 21:20:45 +09:00
|
|
|
.pipe(gulp.dest('./built/_frontend_dist_/'));
|
2021-11-12 02:02:25 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build:backend:style', () => {
|
2023-04-12 12:52:14 +09:00
|
|
|
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-12 02:02:25 +09:00
|
|
|
.pipe(cssnano({
|
|
|
|
zindex: false
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./packages/backend/built/server/web/'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build', gulp.parallel(
|
2022-12-27 14:36:33 +09:00
|
|
|
'copy:frontend:locales', 'copy:backend:views', 'build:backend:script', 'build:backend:style', 'copy:frontend:fonts', 'copy:frontend:tabler-icons'
|
2021-11-12 02:02:25 +09:00
|
|
|
));
|
|
|
|
|
|
|
|
gulp.task('default', gulp.task('build'));
|
|
|
|
|
|
|
|
gulp.task('watch', () => {
|
|
|
|
gulp.watch([
|
2021-11-19 14:48:59 +09:00
|
|
|
'./packages/*/src/**/*',
|
2021-11-12 02:02:25 +09:00
|
|
|
], { ignoreInitial: false }, gulp.task('build'));
|
|
|
|
});
|