This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/gulpfile.js

119 lines
3.6 KiB
JavaScript
Raw Normal View History

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var del = require('del');
var config = {
assetsDir: './assets',
2016-03-30 12:56:01 +00:00
bowerDir: './vendor/bower',
outputDir: './source/assets',
sassPattern: './assets/sass/**/*.sass',
2016-03-30 12:56:01 +00:00
jsPattern: 'js/**/*.js',
production: !!plugins.util.env.production,
sourceMaps: !plugins.util.env.production,
liveReload: !plugins.util.env.production
};
var app = {};
app.css = function (paths, filename) {
2016-03-29 22:49:18 +00:00
gulp.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sassGlob())
.pipe(plugins.sass())
.pipe(plugins.concat(filename))
.pipe(config.production ? plugins.cleanCss() : plugins.util.noop())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
2016-03-30 12:56:01 +00:00
.pipe(gulp.dest(config.outputDir + '/css'))
2016-03-29 22:49:18 +00:00
.pipe(plugins.if(config.liveReload, plugins.livereload()));
};
app.js = function (paths, filename) {
2016-03-29 22:49:18 +00:00
gulp.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat(filename))
.pipe(config.production ? plugins.uglify() : plugins.util.noop())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
2016-03-30 12:56:01 +00:00
.pipe(gulp.dest(config.outputDir + '/js'));
};
app.copy = function (srcFiles, outputDir) {
2016-03-29 22:49:18 +00:00
gulp.src(srcFiles)
.pipe(gulp.dest(outputDir));
};
gulp.task('styles', function () {
2016-03-30 12:56:01 +00:00
app.css([
config.bowerDir + '/font-awesome/css/font-awesome.css',
config.assetsDir + '/sass/site.sass',
], 'site.css');
});
2016-03-30 12:56:01 +00:00
gulp.task('scripts', function () {
app.js([
config.bowerDir + '/jquery/dist/jquery.js',
config.bowerDir + '/bootstrap-sass/assets/javascripts/bootstrap.js',
config.assetsDir + config.jsPattern
], 'site.js');
})
gulp.task('watch', function () {
gulp.watch(config.sassPattern, ['styles']);
2016-03-30 12:56:01 +00:00
gulp.watch(config.assetsDir + config.jsPattern, ['scripts']);
});
gulp.task('clean', function () {
2016-03-30 12:56:01 +00:00
del.sync('output_*/assets/{css,fonts,images,js}');
del.sync(config.outputDir + '/{css,fonts,images,js}');
});
gulp.task('vendor-styles', function () {
app.css([
config.assetsDir + '/sass/vendor.sass',
'vendor/bower/font-awesome/css/font-awesome.css'
], 'vendor.css')
});
gulp.task('vendor-scripts', function () {
app.js([
'vendor/bower/jquery/dist/jquery.js',
'vendor/bower/bootstrap-sass/assets/javascripts/bootstrap/collapse.js',
'scripts/vendor/**/*.js'
], 'vendor.js');
});
gulp.task('vendor', ['vendor-styles', 'vendor-scripts']);
gulp.task('fonts', function () {
2016-03-30 12:56:01 +00:00
app.copy(config.bowerDir + '/font-awesome/fonts/*', config.outputDir + '/fonts');
});
gulp.task('meetup-thumbnails', function () {
gulp.src(config.assetsDir + '/images/meetups/originals/*')
.pipe(plugins.imageResize({
height: '50'
}))
2016-03-30 12:56:01 +00:00
.pipe(gulp.dest(config.outputDir + '/images/meetups/thumbnails'))
});
gulp.task('copy-images', function () {
2016-03-30 12:56:01 +00:00
app.copy(config.assetsDir + '/images/**/*', config.outputDir + '/images');
});
gulp.task('images', ['meetup-thumbnails', 'copy-images']);
2016-03-30 12:56:01 +00:00
gulp.task('build', ['clean', 'styles', 'scripts', 'fonts', 'images']);
gulp.task('default', ['build', 'watch']);
gulp.task('minify-prod-html', function () {
gulp.src('output_prod/**/*.html')
.pipe(plugins.htmlmin({
'collapseWhitespace': true
}))
.pipe(gulp.dest('output_prod'));
});