2019-10-02 22:42:27 +02:00
|
|
|
const { src, dest, watch, parallel } = require('gulp');
|
2019-06-23 19:03:16 +02:00
|
|
|
const ts = require('gulp-typescript');
|
|
|
|
const fs = require('fs');
|
2019-06-24 00:01:50 +02:00
|
|
|
const sourcemaps = require('gulp-sourcemaps');
|
2019-10-02 22:42:27 +02:00
|
|
|
const minimist = require('minimist');
|
|
|
|
const tsConfig = require('./tsconfig.json');
|
|
|
|
const webpack = require('webpack-stream');
|
|
|
|
const webpackConfig = require('./webpack.config');
|
2019-06-23 19:03:16 +02:00
|
|
|
|
2019-10-02 22:42:27 +02:00
|
|
|
const argv = minimist(process.argv);
|
2019-06-23 19:03:16 +02:00
|
|
|
const tsProject = ts.createProject('tsconfig.json');
|
|
|
|
|
2019-10-02 22:42:27 +02:00
|
|
|
function buildFrontend() {
|
|
|
|
let config = webpackConfig;
|
|
|
|
if (argv.dev) {
|
|
|
|
config = { ...config, ...{ mode: 'development' } };
|
|
|
|
}
|
|
|
|
if (argv.watch) {
|
|
|
|
config = { ...config, ...{ watch: true } };
|
|
|
|
}
|
|
|
|
|
|
|
|
return src(config.entry)
|
|
|
|
.pipe(webpack(config))
|
|
|
|
.pipe(dest(config.output.path));
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyIndexHtml(cb) {
|
|
|
|
let indexHtml = 'index.prod.html';
|
|
|
|
if (argv.dev) {
|
|
|
|
indexHtml = 'index.dev.html';
|
|
|
|
}
|
|
|
|
fs.copyFileSync(indexHtml, 'index.html');
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
|
2019-10-05 03:09:34 +02:00
|
|
|
function transpileTypescript() {
|
2019-06-23 19:03:16 +02:00
|
|
|
return tsProject
|
|
|
|
.src()
|
2019-06-24 00:01:50 +02:00
|
|
|
.pipe(sourcemaps.init())
|
2019-06-23 19:03:16 +02:00
|
|
|
.pipe(tsProject())
|
2019-10-02 22:42:27 +02:00
|
|
|
.pipe(sourcemaps.write('.'))
|
2019-10-05 03:09:34 +02:00
|
|
|
.pipe(dest('.'));
|
2019-06-23 19:03:16 +02:00
|
|
|
}
|
|
|
|
|
2019-10-02 22:42:27 +02:00
|
|
|
function build(cb) {
|
|
|
|
if (argv.watch) {
|
2019-10-05 03:09:34 +02:00
|
|
|
watch(tsConfig.include, { ignoreInitial: false }, transpileTypescript);
|
2019-10-02 22:42:27 +02:00
|
|
|
watch('index.*.html', { ignoreInitial: false }, copyIndexHtml);
|
|
|
|
buildFrontend();
|
|
|
|
} else {
|
2019-10-05 03:09:34 +02:00
|
|
|
parallel(transpileTypescript, copyIndexHtml, buildFrontend)(cb);
|
2019-10-02 22:42:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
build.flags = {
|
|
|
|
'--dev': 'builds in development mode',
|
|
|
|
'--watch': 'watches the files',
|
2019-06-23 19:03:16 +02:00
|
|
|
};
|
2019-10-02 22:42:27 +02:00
|
|
|
|
|
|
|
exports.build = build;
|