2019-02-15 08:53:44 +01:00
|
|
|
"use strict";
|
|
|
|
|
2018-12-23 05:53:41 +01:00
|
|
|
// Load plugins
|
|
|
|
const autoprefixer = require("gulp-autoprefixer");
|
|
|
|
const browsersync = require("browser-sync").create();
|
|
|
|
const cleanCSS = require("gulp-clean-css");
|
2019-02-15 08:53:44 +01:00
|
|
|
const del = require("del");
|
2018-12-23 05:53:41 +01:00
|
|
|
const gulp = require("gulp");
|
|
|
|
const header = require("gulp-header");
|
2019-02-15 08:53:44 +01:00
|
|
|
const merge = require("merge-stream");
|
2018-12-23 05:53:41 +01:00
|
|
|
const plumber = require("gulp-plumber");
|
|
|
|
const rename = require("gulp-rename");
|
|
|
|
const sass = require("gulp-sass");
|
|
|
|
const uglify = require("gulp-uglify");
|
2019-02-15 08:53:44 +01:00
|
|
|
|
|
|
|
// Load package.json for banner
|
2018-12-23 05:53:41 +01:00
|
|
|
const pkg = require('./package.json');
|
2016-06-22 00:23:31 +02:00
|
|
|
|
2016-06-22 22:39:59 +02:00
|
|
|
// Set the banner content
|
2018-12-23 05:53:41 +01:00
|
|
|
const banner = ['/*!\n',
|
2017-08-11 21:12:34 +02:00
|
|
|
' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
|
|
|
|
' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
|
|
|
|
' * Licensed under <%= pkg.license %> (https://github.com/BlackrockDigital/<%= pkg.name %>/blob/master/LICENSE)\n',
|
|
|
|
' */\n',
|
2018-08-24 00:21:13 +02:00
|
|
|
'\n'
|
2016-06-22 22:39:59 +02:00
|
|
|
].join('');
|
|
|
|
|
2019-02-15 08:53:44 +01:00
|
|
|
// BrowserSync
|
|
|
|
function browserSync(done) {
|
|
|
|
browsersync.init({
|
|
|
|
server: {
|
|
|
|
baseDir: "./"
|
|
|
|
},
|
|
|
|
port: 3000
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
}
|
2018-01-20 00:37:06 +01:00
|
|
|
|
2019-02-15 08:53:44 +01:00
|
|
|
// BrowserSync reload
|
|
|
|
function browserSyncReload(done) {
|
|
|
|
browsersync.reload();
|
|
|
|
done();
|
|
|
|
}
|
2018-01-20 00:37:06 +01:00
|
|
|
|
2019-02-15 08:53:44 +01:00
|
|
|
// Clean vendor
|
|
|
|
function clean() {
|
|
|
|
return del(["./vendor/"]);
|
|
|
|
}
|
2018-01-20 00:37:06 +01:00
|
|
|
|
2019-02-15 08:53:44 +01:00
|
|
|
// Bring third party dependencies from node_modules into vendor directory
|
|
|
|
function modules() {
|
|
|
|
// Bootstrap
|
|
|
|
var bootstrap = gulp.src('./node_modules/bootstrap/dist/**/*')
|
|
|
|
.pipe(gulp.dest('./vendor/bootstrap'));
|
|
|
|
// Font Awesome
|
|
|
|
var fontAwesome = gulp.src('./node_modules/@fortawesome/**/*')
|
|
|
|
.pipe(gulp.dest('./vendor'));
|
|
|
|
// jQuery Easing
|
|
|
|
var jqueryEasing = gulp.src('./node_modules/jquery.easing/*.js')
|
|
|
|
.pipe(gulp.dest('./vendor/jquery-easing'));
|
2018-01-20 00:37:06 +01:00
|
|
|
// jQuery
|
2019-02-15 08:53:44 +01:00
|
|
|
var jquery = gulp.src([
|
2018-01-20 00:37:06 +01:00
|
|
|
'./node_modules/jquery/dist/*',
|
|
|
|
'!./node_modules/jquery/dist/core.js'
|
|
|
|
])
|
2019-02-15 08:53:44 +01:00
|
|
|
.pipe(gulp.dest('./vendor/jquery'));
|
|
|
|
return merge(bootstrap, fontAwesome, jquery, jqueryEasing);
|
|
|
|
}
|
2016-06-22 22:39:59 +02:00
|
|
|
|
2018-12-23 05:53:41 +01:00
|
|
|
// CSS task
|
|
|
|
function css() {
|
|
|
|
return gulp
|
2019-02-15 08:53:44 +01:00
|
|
|
.src("./scss/**/*.scss")
|
2018-12-23 05:53:41 +01:00
|
|
|
.pipe(plumber())
|
|
|
|
.pipe(sass({
|
2019-02-15 08:53:44 +01:00
|
|
|
outputStyle: "expanded",
|
|
|
|
includePaths: "./node_modules",
|
2018-12-23 05:53:41 +01:00
|
|
|
}))
|
|
|
|
.on("error", sass.logError)
|
2018-08-24 00:21:13 +02:00
|
|
|
.pipe(autoprefixer({
|
|
|
|
browsers: ['last 2 versions'],
|
|
|
|
cascade: false
|
|
|
|
}))
|
2018-05-03 07:38:23 +02:00
|
|
|
.pipe(header(banner, {
|
|
|
|
pkg: pkg
|
|
|
|
}))
|
2018-12-23 05:53:41 +01:00
|
|
|
.pipe(gulp.dest("./css"))
|
2017-08-11 21:12:34 +02:00
|
|
|
.pipe(rename({
|
2018-12-23 05:53:41 +01:00
|
|
|
suffix: ".min"
|
2017-08-11 21:12:34 +02:00
|
|
|
}))
|
2018-12-23 05:53:41 +01:00
|
|
|
.pipe(cleanCSS())
|
|
|
|
.pipe(gulp.dest("./css"))
|
|
|
|
.pipe(browsersync.stream());
|
|
|
|
}
|
2018-01-20 00:37:06 +01:00
|
|
|
|
2018-12-23 05:53:41 +01:00
|
|
|
// JS task
|
|
|
|
function js() {
|
|
|
|
return gulp
|
|
|
|
.src([
|
2018-01-20 00:37:06 +01:00
|
|
|
'./js/*.js',
|
2018-12-23 05:53:41 +01:00
|
|
|
'!./js/*.min.js',
|
|
|
|
'!./js/contact_me.js',
|
|
|
|
'!./js/jqBootstrapValidation.js'
|
2018-01-20 00:37:06 +01:00
|
|
|
])
|
2017-08-11 21:12:34 +02:00
|
|
|
.pipe(uglify())
|
2018-05-03 07:38:23 +02:00
|
|
|
.pipe(header(banner, {
|
|
|
|
pkg: pkg
|
|
|
|
}))
|
2018-12-23 05:53:41 +01:00
|
|
|
.pipe(rename({
|
|
|
|
suffix: '.min'
|
|
|
|
}))
|
2018-01-20 00:37:06 +01:00
|
|
|
.pipe(gulp.dest('./js'))
|
2018-12-23 05:53:41 +01:00
|
|
|
.pipe(browsersync.stream());
|
|
|
|
}
|
2016-06-22 00:23:31 +02:00
|
|
|
|
2018-12-23 05:53:41 +01:00
|
|
|
// Watch files
|
|
|
|
function watchFiles() {
|
|
|
|
gulp.watch("./scss/**/*", css);
|
2019-05-29 20:04:40 +02:00
|
|
|
gulp.watch(["./js/**/*", "!./js/**/*.min.js"], js);
|
2018-12-23 05:53:41 +01:00
|
|
|
gulp.watch("./**/*.html", browserSyncReload);
|
|
|
|
}
|
|
|
|
|
2019-02-15 08:53:44 +01:00
|
|
|
// Define complex tasks
|
|
|
|
const vendor = gulp.series(clean, modules);
|
|
|
|
const build = gulp.series(vendor, gulp.parallel(css, js));
|
|
|
|
const watch = gulp.series(build, gulp.parallel(watchFiles, browserSync));
|
|
|
|
|
|
|
|
// Export tasks
|
|
|
|
exports.css = css;
|
|
|
|
exports.js = js;
|
|
|
|
exports.clean = clean;
|
|
|
|
exports.vendor = vendor;
|
|
|
|
exports.build = build;
|
|
|
|
exports.watch = watch;
|
|
|
|
exports.default = build;
|