cherrypick/gulpfile.ts

81 lines
2.1 KiB
TypeScript
Raw Permalink Normal View History

2016-12-29 07:49:51 +09:00
/**
* Gulp tasks
*/
import * as fs from 'fs';
2016-12-29 07:49:51 +09:00
import * as gulp from 'gulp';
2021-05-31 11:05:34 +09:00
import rimraf from 'rimraf';
2021-04-25 11:30:02 +09:00
const replace = require('gulp-replace');
2020-12-26 10:01:32 +09:00
const terser = require('gulp-terser');
const cssnano = require('gulp-cssnano');
2017-12-08 02:44:50 +09:00
const locales: { [x: string]: any } = require('./locales');
const meta = require('./package.json');
2017-01-18 16:42:01 +09:00
gulp.task('build:copy:views', () =>
gulp.src('./src/server/web/views/**/*').pipe(gulp.dest('./built/server/web/views'))
);
gulp.task('build:copy:fonts', () =>
2021-03-06 13:23:59 +09:00
gulp.src('./node_modules/three/examples/fonts/**/*').pipe(gulp.dest('./built/assets/fonts/'))
);
gulp.task('build:copy:locales', cb => {
2021-03-06 13:23:59 +09:00
fs.mkdirSync('./built/assets/locales', { recursive: true });
const v = { '_version_': meta.version };
for (const [lang, locale] of Object.entries(locales)) {
2021-03-06 13:23:59 +09:00
fs.writeFileSync(`./built/assets/locales/${lang}.${meta.version}.json`, JSON.stringify({ ...locale, ...v }), 'utf-8');
}
cb();
});
2020-12-26 10:01:32 +09:00
gulp.task('build:client:script', () => {
2021-03-03 01:03:29 +09:00
return gulp.src(['./src/server/web/boot.js', './src/server/web/bios.js', './src/server/web/cli.js'])
2020-12-26 10:01:32 +09:00
.pipe(replace('VERSION', JSON.stringify(meta.version)))
.pipe(replace('LANGS', JSON.stringify(Object.keys(locales))))
.pipe(terser({
toplevel: true
}))
.pipe(gulp.dest('./built/server/web/'));
});
gulp.task('build:client:style', () => {
2021-03-03 01:03:29 +09:00
return gulp.src(['./src/server/web/style.css', './src/server/web/bios.css', './src/server/web/cli.css'])
2021-03-05 13:51:22 +09:00
.pipe(cssnano({
zindex: false
}))
2020-12-26 10:01:32 +09:00
.pipe(gulp.dest('./built/server/web/'));
});
gulp.task('build:copy', gulp.parallel('build:copy:locales', 'build:copy:views', 'build:client:script', 'build:client:style', 'build:copy:fonts', () =>
2017-12-17 01:41:22 +09:00
gulp.src([
'./src/emojilist.json',
2017-12-17 01:41:22 +09:00
'./src/**/assets/**/*',
'!./src/client/assets/**/*'
2017-12-17 01:41:22 +09:00
]).pipe(gulp.dest('./built/'))
));
2016-12-29 07:49:51 +09:00
gulp.task('clean', cb =>
rimraf('./built', cb)
);
gulp.task('cleanall', gulp.parallel('clean', cb =>
2016-12-29 07:49:51 +09:00
rimraf('./node_modules', cb)
));
2016-12-29 07:49:51 +09:00
2019-01-29 16:31:05 +09:00
gulp.task('build', gulp.parallel(
'build:copy',
));
gulp.task('default', gulp.task('build'));
2021-03-13 00:40:35 +09:00
gulp.task('watch', () => {
gulp.watch([
'./src/**/*',
'!./src/client/**/*'
], { ignoreInitial: false }, gulp.task('build'));
});