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

110 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-04-05 21:24:04 +00:00
'use strict';
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,
2016-04-05 23:40:06 +00:00
liveReload: !plugins.util.env.production,
notify: !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())
2016-04-05 20:17:57 +00:00
.pipe(plugins.autoprefixer({
browsers: ['last 2 versions']
}))
2016-03-29 22:49:18 +00:00
.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-04-05 23:40:06 +00:00
.pipe(config.notify ? plugins.notify() : plugins.util.noop())
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-04-05 10:58:59 +00:00
.pipe(gulp.dest(config.outputDir + '/js'))
2016-04-05 23:40:06 +00:00
.pipe(config.notify ? plugins.notify() : plugins.util.noop());
};
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',
2016-04-05 21:23:53 +00:00
config.assetsDir + '/sass/site.sass'
2016-03-30 12:56:01 +00:00
], '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',
2016-04-05 19:38:55 +00:00
config.assetsDir + '/' + config.jsPattern
2016-03-30 12:56:01 +00:00
], 'site.js');
2016-04-05 21:23:53 +00:00
});
2016-03-30 12:56:01 +00:00
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('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({
2016-03-30 13:15:54 +00:00
height: '80'
}))
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'));
});