2018-03-12 19:31:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const autoprefixer = require('../../node_modules/gulp-autoprefixer'),
|
|
|
|
babel = require('../../node_modules/gulp-babel'),
|
|
|
|
concat = require('../../node_modules/gulp-concat'),
|
2020-12-11 22:47:40 +00:00
|
|
|
cleancss = require('../../node_modules/gulp-clean-css'),
|
2018-03-12 19:31:14 +00:00
|
|
|
del = require('../../node_modules/del'),
|
|
|
|
eslint = require('../../node_modules/gulp-eslint'),
|
|
|
|
gulp = require('../../node_modules/gulp'),
|
|
|
|
notify = require('../../node_modules/gulp-notify'),
|
|
|
|
plumber = require('../../node_modules/gulp-plumber'),
|
|
|
|
rename = require('../../node_modules/gulp-rename'),
|
|
|
|
sass = require('../../node_modules/gulp-sass'),
|
|
|
|
sourcemaps = require('../../node_modules/gulp-sourcemaps'),
|
|
|
|
stylelint = require('../../node_modules/gulp-stylelint'),
|
2018-07-05 01:18:42 +00:00
|
|
|
uglify = require('../../node_modules/gulp-uglify'),
|
2018-07-05 04:07:30 +00:00
|
|
|
webpack = require('../../node_modules/webpack-stream');
|
2018-03-12 19:31:14 +00:00
|
|
|
|
|
|
|
function customPlumber (errTitle) {
|
|
|
|
return plumber({
|
|
|
|
errorHandler: notify.onError({
|
|
|
|
title: errTitle || "Ouch! Error running Gulp",
|
|
|
|
message: "Error: <%= error.message %>"
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Styles
|
2020-12-11 22:47:40 +00:00
|
|
|
gulp.task('styles:lint', function() {
|
2018-03-12 19:31:14 +00:00
|
|
|
return gulp.src('source/assets/scss/**/*.scss')
|
|
|
|
.pipe(customPlumber('Ouch! Error Running StyleLint'))
|
|
|
|
.pipe(stylelint({
|
|
|
|
failAfterError: false,
|
|
|
|
reporters: [
|
|
|
|
{formatter: 'verbose', console: true}
|
|
|
|
]
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('styles:serve', function() {
|
|
|
|
return gulp.src('source/assets/scss/main.scss')
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(customPlumber('Ouch! Error Running Sass'))
|
|
|
|
.pipe(sass({errLogToConsole: true}))
|
2019-03-23 20:23:36 +00:00
|
|
|
.pipe(autoprefixer(['last 3 versions', 'IE 10', 'iOS 9', 'Android 4']))
|
2018-03-12 19:31:14 +00:00
|
|
|
.pipe(rename({ suffix: '.min' })) // for using in dev mode
|
|
|
|
.pipe(sourcemaps.write('./'))
|
|
|
|
.pipe(gulp.dest('source/css'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('styles:build', function() {
|
|
|
|
return gulp.src('source/assets/scss/main.scss')
|
|
|
|
.pipe(customPlumber('Ouch! Error Running Sass'))
|
|
|
|
.pipe(sass({errLogToConsole: true}))
|
2019-03-23 20:23:36 +00:00
|
|
|
.pipe(autoprefixer(['last 3 versions', 'IE 10', 'iOS 9', 'Android 4']))
|
2018-03-12 19:31:14 +00:00
|
|
|
.pipe(rename({ suffix: '.min' }))
|
2020-12-11 22:47:40 +00:00
|
|
|
.pipe(cleancss({level: 2}))
|
2018-03-12 19:31:14 +00:00
|
|
|
.pipe(gulp.dest('source/css/'))
|
|
|
|
});
|
|
|
|
|
2020-12-11 22:47:40 +00:00
|
|
|
gulp.task('webpack', function() {
|
2018-07-05 04:07:30 +00:00
|
|
|
return gulp.src('source/assets/scripts/crystalball.js')
|
|
|
|
.pipe(webpack( require('./webpack.config.js') ))
|
|
|
|
.pipe(gulp.dest('source/js/'));
|
|
|
|
});
|
|
|
|
|
2018-03-12 19:31:14 +00:00
|
|
|
// Scripts
|
|
|
|
gulp.task('scripts:serve', function() {
|
2018-07-05 04:07:30 +00:00
|
|
|
return gulp.src(['source/assets/scripts/*.js', '!source/assets/scripts/*ball.js'])
|
2018-03-12 19:31:14 +00:00
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(babel({
|
2019-03-23 20:23:36 +00:00
|
|
|
presets: ["@babel/preset-env"]
|
2018-03-12 19:31:14 +00:00
|
|
|
}))
|
|
|
|
.pipe(customPlumber('Ouch! Error Running Scripts'))
|
|
|
|
.pipe(eslint())
|
|
|
|
.pipe(eslint.format())
|
|
|
|
//.pipe(concat('main.js'))
|
2018-07-05 04:07:30 +00:00
|
|
|
.pipe(rename({ suffix: '.min' }))
|
2018-03-12 19:31:14 +00:00
|
|
|
.pipe(sourcemaps.write('./'))
|
|
|
|
.pipe(gulp.dest('source/js/'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('scripts:build', function() {
|
2018-07-05 04:07:30 +00:00
|
|
|
return gulp.src(['source/assets/scripts/*.js', '!source/assets/scripts/*ball.js'])
|
2018-03-12 19:31:14 +00:00
|
|
|
.pipe(babel({
|
2019-03-23 20:23:36 +00:00
|
|
|
presets: ["@babel/preset-env"]
|
2018-03-12 19:31:14 +00:00
|
|
|
}))
|
|
|
|
.pipe(customPlumber('Ouch! Error Running Scripts'))
|
|
|
|
//.pipe(concat('main.js'))
|
|
|
|
.pipe(rename({suffix: '.min'}) )
|
|
|
|
.pipe(uglify())
|
|
|
|
.pipe(gulp.dest('source/js/'))
|
|
|
|
});
|
|
|
|
|
|
|
|
// Clean
|
|
|
|
gulp.task('clean', function () {
|
|
|
|
return del(['source/js/*', 'source/css/*']);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Watch
|
|
|
|
gulp.task('watch', function() {
|
2019-01-14 23:01:54 +00:00
|
|
|
gulp.watch('./source/assets/scss/**/*.scss', gulp.series('styles:serve'));
|
|
|
|
gulp.watch('./source/assets/scripts/**/*.js', gulp.series('scripts:serve'));
|
2018-03-12 19:31:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Development Mode
|
2019-03-23 20:23:36 +00:00
|
|
|
gulp.task('default', gulp.series('styles:lint', 'styles:serve', 'webpack', 'scripts:serve', 'watch'));
|
2018-03-12 19:31:14 +00:00
|
|
|
|
|
|
|
// Production Mode
|
2019-03-23 20:23:36 +00:00
|
|
|
gulp.task('build', gulp.series('clean', gulp.parallel('styles:build', 'webpack', 'scripts:build')));
|