2021-12-02 07:29:19 +01:00
|
|
|
/// <binding BeforeBuild='load-bundle, copy-assets, min, update-version' Clean='clean' />
|
2018-10-26 07:22:53 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var gulp = require('gulp');
|
|
|
|
var rimraf = require("rimraf");
|
|
|
|
var concat = require("gulp-concat");
|
|
|
|
var cssmin = require("gulp-cssmin");
|
|
|
|
var merge = require('merge-stream');
|
|
|
|
var del = require("del");
|
|
|
|
var replace = require("gulp-replace");
|
|
|
|
var rename = require("gulp-rename");
|
|
|
|
var git = require("git-rev-sync");
|
|
|
|
|
|
|
|
var uglifyes = require('uglify-es');
|
|
|
|
var composer = require('gulp-uglify/composer');
|
|
|
|
var uglify = composer(uglifyes, console);
|
|
|
|
|
|
|
|
var bundleconfig = require("./bundleconfig.json");
|
|
|
|
|
|
|
|
var regex = {
|
|
|
|
css: /\.css$/,
|
|
|
|
html: /\.(html|htm)$/,
|
|
|
|
js: /\.js$/
|
|
|
|
};
|
|
|
|
|
|
|
|
var assets = [
|
|
|
|
// Library JS Files
|
|
|
|
{ './node_modules/bootstrap/dist/js/bootstrap.js': 'lib/bootstrap/js' },
|
|
|
|
{ './node_modules/jquery/dist/jquery.js': 'lib/jquery/js' },
|
|
|
|
{ './node_modules/jquery-validation/dist/jquery.validate.js': 'lib/jquery/js' },
|
|
|
|
|
|
|
|
// App JS Files
|
|
|
|
{ './Scripts/**/*': 'js/app' },
|
|
|
|
|
|
|
|
// Library CSS Files
|
|
|
|
{ './node_modules/bootstrap/dist/css/bootstrap.css': 'lib/bootstrap/css' },
|
|
|
|
{ './node_modules/bootstrap/dist/css/bootstrap.css.map': 'lib/bootstrap/css' },
|
|
|
|
{ './node_modules/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css': 'lib/awesome-bootstrap-checkbox/css' },
|
|
|
|
{ './node_modules/font-awesome/css/font-awesome.css': 'lib/font-awesome/css' },
|
|
|
|
|
|
|
|
// App CSS Files
|
|
|
|
{ './Content/**/*': 'css/app' },
|
|
|
|
|
|
|
|
// Fonts
|
|
|
|
{ './node_modules/bootstrap/dist/fonts/*': 'lib/bootstrap/fonts' },
|
|
|
|
{ './node_modules/bootstrap/dist/fonts/*': 'fonts' },
|
|
|
|
{ './node_modules/font-awesome/fonts/*': 'lib/font-awesome/fonts' },
|
|
|
|
{ './node_modules/font-awesome/fonts/*': 'fonts' },
|
|
|
|
|
|
|
|
// Images
|
|
|
|
{ './Images/favicon.ico': 'images' },
|
|
|
|
{ './Images/logo-black.svg': 'images' },
|
|
|
|
{ './Images/logo-blue.svg': 'images' }
|
|
|
|
];
|
|
|
|
|
|
|
|
gulp.task("clean", function (cb) {
|
|
|
|
return rimraf("./wwwroot/*", cb);
|
|
|
|
});
|
|
|
|
|
2020-06-23 09:18:41 +02:00
|
|
|
gulp.task('copy-assets', function (done) {
|
2018-10-26 07:22:53 +02:00
|
|
|
var streams = [];
|
|
|
|
for (var asset in assets) {
|
|
|
|
for (var item in assets[asset]) {
|
|
|
|
streams.push(gulp.src(item).pipe(gulp.dest('./wwwroot/' + assets[asset][item])));
|
|
|
|
}
|
|
|
|
}
|
2020-06-23 09:18:41 +02:00
|
|
|
done();
|
2018-10-26 07:22:53 +02:00
|
|
|
});
|
|
|
|
|
2020-06-23 09:18:41 +02:00
|
|
|
gulp.task("load-bundle", function (done) {
|
2018-10-26 07:22:53 +02:00
|
|
|
bundleconfig = require("./bundleconfig.json");
|
2020-06-23 09:18:41 +02:00
|
|
|
done();
|
2018-10-26 07:22:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("min:js", function () {
|
|
|
|
var tasks = getBundles(".js").map(function (bundle) {
|
|
|
|
return gulp.src(bundle.inputFiles, { base: "." })
|
|
|
|
.pipe(concat(bundle.outputFileName))
|
|
|
|
.pipe(uglify())
|
|
|
|
.pipe(gulp.dest("."));
|
|
|
|
});
|
|
|
|
return merge(tasks);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("min:css", function () {
|
|
|
|
var tasks = getBundles(".css").map(function (bundle) {
|
|
|
|
return gulp.src(bundle.inputFiles, { base: "." })
|
|
|
|
.pipe(concat(bundle.outputFileName))
|
|
|
|
.pipe(cssmin())
|
|
|
|
.pipe(gulp.dest("."));
|
|
|
|
});
|
|
|
|
return merge(tasks);
|
|
|
|
});
|
|
|
|
|
2020-06-23 09:18:41 +02:00
|
|
|
gulp.task("min", gulp.parallel("min:js", "min:css"));
|
|
|
|
|
2018-10-26 07:22:53 +02:00
|
|
|
gulp.task("update-version", function () {
|
|
|
|
return gulp.src('./App_Data/version.template.json')
|
|
|
|
.pipe(replace('{{git_ver}}', git.tag()))
|
|
|
|
.pipe(replace('{{git_hash}}', git.long()))
|
|
|
|
.pipe(rename('version.json'))
|
|
|
|
.pipe(gulp.dest('./App_Data'));
|
|
|
|
});
|
|
|
|
|
2020-06-23 09:18:41 +02:00
|
|
|
gulp.task("watch", function (done) {
|
2018-10-26 07:22:53 +02:00
|
|
|
// Watch Source Files
|
|
|
|
assets.forEach(function (src) {
|
|
|
|
for (var key in src) {
|
2020-06-23 09:35:07 +02:00
|
|
|
gulp.watch(key, gulp.parallel("copy-assets"));
|
2018-10-26 07:22:53 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Watch Bundle File Itself
|
2020-06-23 09:35:07 +02:00
|
|
|
gulp.watch('./bundleconfig.json', gulp.series("load-bundle", "min"));
|
2018-10-26 07:22:53 +02:00
|
|
|
|
|
|
|
// Watch Bundles
|
|
|
|
getBundles(".js").forEach(function (bundle) {
|
2020-06-23 09:35:07 +02:00
|
|
|
gulp.watch(bundle.inputFiles, gulp.parallel("min:js"));
|
2018-10-26 07:22:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
getBundles(".css").forEach(function (bundle) {
|
2020-06-23 09:35:07 +02:00
|
|
|
gulp.watch(bundle.inputFiles, gulp.parallel("min:css"));
|
2018-10-26 07:22:53 +02:00
|
|
|
});
|
2020-06-23 09:18:41 +02:00
|
|
|
|
|
|
|
done();
|
2018-10-26 07:22:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function getBundles(extension) {
|
|
|
|
return bundleconfig.filter(function (bundle) {
|
|
|
|
return new RegExp(`${extension}$`).test(bundle.outputFileName);
|
|
|
|
});
|
|
|
|
}
|