144 lines
No EOL
5 KiB
JavaScript
144 lines
No EOL
5 KiB
JavaScript
const { dest, parallel, series, src, watch } = require('gulp'),
|
|
changed = require('gulp-changed'),
|
|
conventionalChangelog = require('gulp-conventional-changelog'),
|
|
dateFormat = require('dateformat'),
|
|
del = require('del'),
|
|
path = require('path'),
|
|
rename = require('gulp-rename'),
|
|
sass = require('gulp-sass'),
|
|
ts = require('gulp-typescript'),
|
|
uglifycss = require('gulp-uglifycss'),
|
|
webpack = require('webpack-stream');
|
|
|
|
|
|
require('dotenv').config();
|
|
|
|
function clean() {
|
|
return del(
|
|
[
|
|
'./dist/',
|
|
'./../webapp/assets/css/',
|
|
'./../webapp/assets/fonts/',
|
|
'./../webapp/assets/js/',
|
|
], { force: true }); // Force option needed to delete files outside of project dir
|
|
}
|
|
|
|
function compileJavaScript() {
|
|
return src('./../webapp/src/js/app.js')
|
|
.pipe(webpack({
|
|
entry: {
|
|
app: './../webapp/src/js/app.js',
|
|
},
|
|
output: {
|
|
filename: '[name].js',
|
|
},
|
|
optimization: {
|
|
splitChunks: {
|
|
chunks: 'all',
|
|
},
|
|
},
|
|
mode: process.env.PRODUCTION ? 'production' : 'development',
|
|
resolve: {
|
|
modules: [
|
|
path.resolve('./../server/node_modules'),
|
|
],
|
|
extensions: ['.js', '.json'],
|
|
// alias: {
|
|
// handlebars: 'handlebars/dist/handlebars.min.js',
|
|
// },
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
loader: 'babel-loader',
|
|
query: {
|
|
presets: [
|
|
[
|
|
'@babel/preset-env',
|
|
{
|
|
targets: {
|
|
chrome: 78,
|
|
},
|
|
},
|
|
],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
},
|
|
}).on('error', function () { this.emit('end'); }))
|
|
.pipe(dest('./../webapp/assets/js/'));
|
|
}
|
|
|
|
function compileScss() {
|
|
return src('./../webapp/src/scss/*.scss')
|
|
.pipe(sass({ outputStyle: 'compressed', includePaths: ['./../server/node_modules/'] })).on('error', sass.logError)
|
|
.pipe(dest('./../webapp/assets/css/'));
|
|
}
|
|
|
|
function compileTypeScript() {
|
|
const tsProject = ts.createProject('tsconfig.json');
|
|
// do not compile tests in production
|
|
tsProject.config.exclude = !tsProject.config.exclude ? ['test'] : tsProject.config.exclude.push('test');
|
|
return tsProject.src()
|
|
.pipe(tsProject())
|
|
.js.pipe(dest('./dist/'));
|
|
}
|
|
|
|
function installMaterialIcons() {
|
|
src(
|
|
'./node_modules/material-design-icons/iconfont/*.css')
|
|
.pipe(uglifycss())
|
|
.pipe(changed('./../webapp/assets/fonts/material-icons/'))
|
|
.pipe(dest('./../webapp/assets/fonts/material-icons/'));
|
|
return src(
|
|
'./node_modules/material-design-icons/iconfont/*',
|
|
{ ignore: ['**/README.md', '**/codepoints', '**/*.ijmap'] })
|
|
.pipe(changed('./../webapp/assets/fonts/material-icons/'))
|
|
.pipe(dest('./../webapp/assets/fonts/material-icons/'));
|
|
}
|
|
|
|
function installRoboto() {
|
|
src('./node_modules/typeface-roboto/files/*')
|
|
.pipe(changed('./../webapp/assets/fonts/roboto/files/'))
|
|
.pipe(dest('./../webapp/assets/fonts/roboto/files/'));
|
|
return src('./node_modules/typeface-roboto/index.css')
|
|
.pipe(rename('roboto.css'))
|
|
.pipe(uglifycss())
|
|
.pipe(changed('./../webapp/assets/fonts/roboto/'))
|
|
.pipe(dest('./../webapp/assets/fonts/roboto/'));
|
|
}
|
|
|
|
function watchCompile() {
|
|
watch('./../webapp/src/scss/*.scss', { ignoreInitial: false }, compileScss);
|
|
watch('./../webapp/src/js/*.js', { ignoreInitial: false }, compileJavaScript);
|
|
}
|
|
|
|
function changelog() {
|
|
return src('../CHANGELOG.md')
|
|
.pipe(conventionalChangelog({
|
|
// conventional-changelog options go here
|
|
preset: 'angular',
|
|
// releaseCount: 0, // Uncomment to regenerate whole changelog
|
|
}, {
|
|
// context goes here
|
|
commit: 'commit',
|
|
date: dateFormat(new Date(), 'dd.mm.yyyy', true),
|
|
}, {
|
|
// git-raw-commits options go here
|
|
}, {
|
|
// conventional-commits-parser options go here
|
|
}, {
|
|
// conventional-changelog-writer options go here
|
|
}))
|
|
.pipe(dest('../'));
|
|
}
|
|
|
|
exports.clean = clean;
|
|
exports.compileFonts = parallel(installMaterialIcons, installRoboto);
|
|
exports.compile = parallel(compileScss, compileJavaScript, compileTypeScript, exports.compileFonts);
|
|
exports.watchCompile = series(clean, exports.compileFonts, watchCompile);
|
|
exports.build = series(clean, exports.compile);
|
|
exports.changelog = changelog;
|
|
exports.default = exports.build; |