mizzkey/gulpfile.ts

110 lines
2.6 KiB
TypeScript
Raw Normal View History

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