Small refactor

This commit is contained in:
Oliver Davies 2016-12-13 23:57:59 +00:00
parent 48284952a3
commit 1306fe32fa
2 changed files with 28 additions and 25 deletions

View file

@ -1,22 +1,24 @@
module.exports = function (plugins) { module.exports = function (plugins) {
var config = { return {
autoprefixer: { autoprefixer: {
browsers: ["last 2 versions", "> 5%"] browsers: ["last 2 versions", "> 5%"]
}, },
bowerDir: 'vendor/bower_components', bower: {
fontsDir: 'source/assets/fonts', path: 'vendor/bower_components',
},
fonts: {
destination: 'source/assets/fonts',
},
js: { js: {
sourceDir: 'assets/js', source: 'assets/js',
outputDir: 'source/assets/js', pattern: '/**/*.js',
pattern: '/**/*.js' destination: 'source/assets/js',
}, },
production: !!plugins.util.env.production, production: !!plugins.util.env.production,
sass: { sass: {
sourceDir: 'assets/sass', source: 'assets/sass',
pattern: '/**/*.sass', pattern: '/**/*.sass',
outputDir: 'source/assets/css' destination: 'source/assets/css',
} }
} }
return config;
} }

View file

@ -2,9 +2,10 @@
var gulp = require('gulp'); var gulp = require('gulp');
var plugins = require('gulp-load-plugins')(); var plugins = require('gulp-load-plugins')();
var config = require('./gulpfile.config.js')(plugins);
var del = require('del'); var del = require('del');
var config = require('./gulpfile.config.js')(plugins);
var app = {}; var app = {};
app.sass = function(paths, filename) { app.sass = function(paths, filename) {
@ -22,7 +23,7 @@ app.sass = function(paths, filename) {
.pipe(plugins.concat(filename)) .pipe(plugins.concat(filename))
.pipe(plugins.if(!config.production, plugins.sourcemaps.write('.'))) .pipe(plugins.if(!config.production, plugins.sourcemaps.write('.')))
.pipe(plugins.if(!config.production, plugins.refresh())) .pipe(plugins.if(!config.production, plugins.refresh()))
.pipe(gulp.dest(config.sass.outputDir)); .pipe(gulp.dest(config.sass.destination));
}; };
app.js = function(paths, filename) { app.js = function(paths, filename) {
@ -32,7 +33,7 @@ app.js = function(paths, filename) {
.pipe(plugins.concat(filename)) .pipe(plugins.concat(filename))
.pipe(plugins.if(config.production, plugins.uglify())) .pipe(plugins.if(config.production, plugins.uglify()))
.pipe(plugins.if(!config.production, plugins.sourcemaps.write('.'))) .pipe(plugins.if(!config.production, plugins.sourcemaps.write('.')))
.pipe(gulp.dest(config.js.outputDir)); .pipe(gulp.dest(config.js.destination));
}; };
app.copy = function(source, destination) { app.copy = function(source, destination) {
@ -41,9 +42,9 @@ app.copy = function(source, destination) {
}; };
gulp.task('clean', function() { gulp.task('clean', function() {
del.sync(config.fontsDir); del.sync(config.fonts.destination);
del.sync(config.js.outputDir); del.sync(config.js.destination);
del.sync(config.sass.outputDir); del.sync(config.sass.destination);
del.sync('output_*/assets/css'); del.sync('output_*/assets/css');
del.sync('output_*/assets/fonts'); del.sync('output_*/assets/fonts');
del.sync('output_*/assets/js'); del.sync('output_*/assets/js');
@ -51,23 +52,23 @@ gulp.task('clean', function() {
gulp.task('fonts', function() { gulp.task('fonts', function() {
return app.copy( return app.copy(
config.bowerDir + "/font-awesome/fonts/*", config.bower.path + "/font-awesome/fonts/*",
config.fontsDir config.fonts.destination
); );
}); });
gulp.task('styles', function() { gulp.task('styles', function() {
return app.sass([ return app.sass([
config.bowerDir + '/font-awesome/css/font-awesome.css', config.bower.path + '/font-awesome/css/font-awesome.css',
config.sass.sourceDir + config.sass.pattern config.sass.source + config.sass.pattern
], 'site.css'); ], 'site.css');
}); });
gulp.task('scripts', function() { gulp.task('scripts', function() {
return app.js([ return app.js([
config.bowerDir + '/jquery2/jquery.js', config.bower.path + '/jquery2/jquery.js',
config.bowerDir + '/bootstrap-sass/assets/javascripts/bootstrap.js', config.bower.path + '/bootstrap-sass/assets/javascripts/bootstrap.js',
config.js.sourceDir + config.js.pattern config.js.source + config.js.pattern
], 'site.js'); ], 'site.js');
}); });
@ -78,6 +79,6 @@ gulp.task('default', ['build']);
gulp.task('watch', ['build'], function() { gulp.task('watch', ['build'], function() {
plugins.refresh.listen(); plugins.refresh.listen();
gulp.watch(config.sass.sourceDir + config.sass.pattern, ['styles']); gulp.watch(config.sass.source + config.sass.pattern, ['styles']);
gulp.watch(config.js.sourceDir + config.js.pattern, ['scripts']); gulp.watch(config.js.source + config.js.pattern, ['scripts']);
}); });