2016-01-04 11:36:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var gulp = require('gulp'),
|
2016-01-05 23:21:51 +00:00
|
|
|
plugins = require('gulp-load-plugins')(),
|
|
|
|
del = require('del');
|
2016-01-04 11:36:14 +00:00
|
|
|
|
2016-01-04 17:11:19 +00:00
|
|
|
var config = {
|
2016-01-09 17:20:23 +00:00
|
|
|
bowerDir: 'vendor/bower',
|
2016-01-08 01:44:44 +00:00
|
|
|
assetsDir: './source/assets',
|
2016-01-06 05:24:00 +00:00
|
|
|
sassPattern: './sass/**/*.scss',
|
|
|
|
production: !!plugins.util.env.production,
|
2016-01-08 01:44:44 +00:00
|
|
|
sourceMaps: !plugins.util.env.production,
|
2016-01-08 09:36:38 +00:00
|
|
|
liveReload: !plugins.util.env.production
|
2016-01-04 17:11:19 +00:00
|
|
|
};
|
|
|
|
|
2016-01-08 01:44:44 +00:00
|
|
|
var app = {};
|
|
|
|
|
|
|
|
app.addStyle = function(paths, filename) {
|
|
|
|
gulp.src(paths)
|
|
|
|
.pipe(plugins.plumber())
|
|
|
|
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
|
|
|
|
.pipe(plugins.sass())
|
|
|
|
.pipe(plugins.concat(filename))
|
|
|
|
.pipe(config.production ? plugins.minifyCss() : plugins.util.noop())
|
|
|
|
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
|
|
|
|
.pipe(gulp.dest(config.assetsDir + '/css'))
|
2016-01-08 11:32:22 +00:00
|
|
|
.pipe(plugins.if(config.liveReload, plugins.livereload()));
|
2016-01-08 09:36:38 +00:00
|
|
|
};
|
2016-01-08 01:44:44 +00:00
|
|
|
|
|
|
|
app.copy = function(srcFiles, outputDir) {
|
|
|
|
gulp.src(srcFiles)
|
|
|
|
.pipe(gulp.dest(outputDir));
|
2016-01-08 09:36:38 +00:00
|
|
|
};
|
2016-01-08 01:44:44 +00:00
|
|
|
|
2016-01-11 01:44:07 +00:00
|
|
|
app.addScript = function(paths, filename) {
|
|
|
|
gulp.src(paths)
|
|
|
|
.pipe(plugins.plumber())
|
|
|
|
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
|
|
|
|
.pipe(plugins.concat(filename))
|
|
|
|
.pipe(config.production ? plugins.uglify() : plugins.util.noop())
|
|
|
|
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
|
|
|
|
.pipe(gulp.dest(config.assetsDir + '/js'))
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:44:44 +00:00
|
|
|
gulp.task('fonts', function () {
|
|
|
|
// Copy fonts from bower_components into source/asset/fonts.
|
|
|
|
app.copy(config.bowerDir + '/font-awesome/fonts/*', config.assetsDir + '/fonts');
|
|
|
|
});
|
|
|
|
|
2016-01-05 23:13:07 +00:00
|
|
|
gulp.task('styles', function () {
|
2016-01-08 01:44:44 +00:00
|
|
|
app.addStyle([
|
|
|
|
config.bowerDir + '/font-awesome/css/font-awesome.css',
|
|
|
|
'./sass/styles.scss'
|
2016-01-11 01:44:07 +00:00
|
|
|
], 'all.css');
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('scripts', function () {
|
|
|
|
app.addScript([
|
|
|
|
config.bowerDir + '/jquery/dist/jquery.js',
|
|
|
|
config.bowerDir + '/bootstrap-sass/assets/javascripts/bootstrap.js'
|
|
|
|
], 'all.js');
|
2016-01-04 12:20:00 +00:00
|
|
|
});
|
|
|
|
|
2016-01-05 18:57:18 +00:00
|
|
|
gulp.task('images', function () {
|
2016-01-04 11:38:34 +00:00
|
|
|
// Minify images.
|
2016-01-05 18:57:18 +00:00
|
|
|
gulp.src(config.imagesDir + '/*')
|
2016-01-04 17:07:01 +00:00
|
|
|
.pipe(plugins.imagemin())
|
2016-01-04 17:11:19 +00:00
|
|
|
.pipe(gulp.dest(config.imagesDir));
|
2016-01-04 11:36:14 +00:00
|
|
|
});
|
|
|
|
|
2016-01-04 12:20:00 +00:00
|
|
|
gulp.task('watch', function () {
|
2016-01-08 01:44:44 +00:00
|
|
|
plugins.livereload.listen();
|
2016-01-05 23:13:07 +00:00
|
|
|
gulp.watch(config.sassPattern, ['styles']);
|
2016-01-04 12:20:00 +00:00
|
|
|
});
|
|
|
|
|
2016-01-05 23:21:51 +00:00
|
|
|
gulp.task('clean', function () {
|
2016-01-08 01:44:44 +00:00
|
|
|
del.sync(config.assetsDir + '/css');
|
|
|
|
del.sync(config.assetsDir + '/fonts');
|
2016-01-11 01:44:07 +00:00
|
|
|
del.sync(config.assetsDir + '/js');
|
2016-01-05 23:21:51 +00:00
|
|
|
del.sync('./output_*/assets/css/*');
|
2016-01-08 01:44:44 +00:00
|
|
|
del.sync('./output_*/assets/fonts/*');
|
2016-01-05 23:21:51 +00:00
|
|
|
});
|
|
|
|
|
2016-01-11 02:28:43 +00:00
|
|
|
gulp.task('minify-prod-html', function() {
|
|
|
|
gulp.src('output_prod/**/*.html')
|
|
|
|
.pipe(plugins.htmlmin({ collapseWhitespace: true }))
|
|
|
|
.pipe(gulp.dest('output_prod'));
|
|
|
|
});
|
|
|
|
|
2016-01-11 01:44:07 +00:00
|
|
|
gulp.task('build', ['clean', 'styles', 'scripts', 'fonts']);
|
2016-01-08 11:34:38 +00:00
|
|
|
|
|
|
|
gulp.task('default', ['build', 'watch']);
|