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