Refactor gulp tasks as a directory.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-21 16:03:16 -04:00
parent b0f552f3f8
commit 7daa691b21
10 changed files with 123 additions and 83 deletions

43
gulpfile.js/config.js Normal file
View File

@ -0,0 +1,43 @@
var basePath = 'babyblotter/static/babyblotter/';
module.exports = {
basePath: basePath,
compressConfig: {
scripts: {
dest: basePath + 'js/'
},
styles: {
dest: basePath + 'css/'
}
},
extrasConfig: {
fonts: {
dest: basePath + 'fonts/',
extras: 'node_modules/font-awesome/fonts/*'
}
},
scriptsConfig: {
dest: basePath + 'js/',
vendor: [
'node_modules/jquery/dist/jquery.js',
'node_modules/popper.js/dist/umd/popper.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/moment/moment.js',
'node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.js'
],
app: [
'babyblotter/static_site/js/babyblotter.js',
'api/static/js/*.js',
'core/static/js/*.js',
'dashboard/static/js/*.js'
]
},
stylesConfig: {
dest: basePath + 'css/',
vendor: [
'node_modules/tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.css',
'node_modules/font-awesome/css/font-awesome.css'
],
app: 'babyblotter/static_site/scss/babyblotter.scss'
}
};

View File

@ -5,6 +5,9 @@ var csso = require('gulp-csso');
var pump = require('pump'); var pump = require('pump');
var uglify = require('gulp-uglify'); var uglify = require('gulp-uglify');
var basePath = require('../config.js').basePath;
var compressConfig = require('../config.js').compressConfig;
gulp.task('compress', [ gulp.task('compress', [
'compress:scripts:app', 'compress:scripts:app',
@ -15,36 +18,36 @@ gulp.task('compress', [
gulp.task('compress:scripts:app', ['scripts:app'], function (cb) { gulp.task('compress:scripts:app', ['scripts:app'], function (cb) {
pump([ pump([
gulp.src('babyblotter/static/babyblotter/js/app.js'), gulp.src(basePath + 'js/app.js'),
concat('app.min.js'), concat('app.min.js'),
uglify(), uglify(),
gulp.dest('babyblotter/static/babyblotter/js/') gulp.dest(compressConfig.scripts.dest)
], cb); ], cb);
}); });
gulp.task('compress:scripts:vendor', ['scripts:vendor'], function (cb) { gulp.task('compress:scripts:vendor', ['scripts:vendor'], function (cb) {
pump([ pump([
gulp.src('babyblotter/static/babyblotter/js/vendor.js'), gulp.src(basePath + 'js/vendor.js'),
concat('vendor.min.js'), concat('vendor.min.js'),
uglify(), uglify(),
gulp.dest('babyblotter/static/babyblotter/js/') gulp.dest(compressConfig.scripts.dest)
], cb); ], cb);
}); });
gulp.task('compress:styles:app', ['styles:app'], function (cb) { gulp.task('compress:styles:app', ['styles:app'], function (cb) {
pump([ pump([
gulp.src('babyblotter/static/babyblotter/css/app.css'), gulp.src(basePath + 'css/app.css'),
concat('app.min.css'), concat('app.min.css'),
csso(), csso(),
gulp.dest('babyblotter/static/babyblotter/css/') gulp.dest(compressConfig.styles.dest)
], cb); ], cb);
}); });
gulp.task('compress:styles:vendor', ['styles:vendor'], function (cb) { gulp.task('compress:styles:vendor', ['styles:vendor'], function (cb) {
pump([ pump([
gulp.src('babyblotter/static/babyblotter/css/vendor.css'), gulp.src(basePath + 'css/vendor.css'),
concat('vendor.min.css'), concat('vendor.min.css'),
csso(), csso(),
gulp.dest('babyblotter/static/babyblotter/css/') gulp.dest(compressConfig.styles.dest)
], cb); ], cb);
}); });

View File

@ -0,0 +1,15 @@
var gulp = require('gulp');
var pump = require('pump');
var extrasConfig = require('../config.js').extrasConfig;
gulp.task('extras', ['extras:fonts']);
gulp.task('extras:fonts', function(cb) {
pump([
gulp.src(extrasConfig.fonts.extras),
gulp.dest(extrasConfig.fonts.dest)
], cb);
});

View File

@ -0,0 +1,25 @@
var gulp = require('gulp');
var concat = require('gulp-concat');
var pump = require('pump');
var scriptsConfig = require('../config.js').scriptsConfig;
gulp.task('scripts', ['scripts:vendor', 'scripts:app']);
gulp.task('scripts:vendor', function(cb) {
pump([
gulp.src(scriptsConfig.vendor),
concat('vendor.js'),
gulp.dest(scriptsConfig.dest)
], cb);
});
gulp.task('scripts:app', function(cb) {
pump([
gulp.src(scriptsConfig.app),
concat('app.js'),
gulp.dest(scriptsConfig.dest)
], cb);
});

View File

@ -0,0 +1,29 @@
var gulp = require('gulp');
var concat = require('gulp-concat');
var pump = require('pump');
var sass = require('gulp-sass');
var sassGlob = require('gulp-sass-glob');
var stylesConfig = require('../config.js').stylesConfig;
gulp.task('styles', ['styles:vendor', 'styles:app']);
gulp.task('styles:vendor', function(cb) {
pump([
gulp.src(stylesConfig.vendor),
concat('vendor.css'),
gulp.dest(stylesConfig.dest)
], cb);
});
gulp.task('styles:app', function (cb) {
pump([
gulp.src(stylesConfig.app),
sassGlob(),
sass().on('error', sass.logError),
concat('app.css'),
gulp.dest(stylesConfig.dest)
], cb);
});

View File

@ -1,11 +0,0 @@
var gulp = require('gulp');
gulp.task('extras', ['extras:fonts']);
gulp.task('extras:fonts', function(cb) {
pump([
gulp.src('node_modules/font-awesome/fonts/*'),
gulp.dest('babyblotter/static/babyblotter/fonts/')
], cb);
});

View File

@ -1,34 +0,0 @@
var gulp = require('gulp');
var concat = require('gulp-concat');
var pump = require('pump');
gulp.task('scripts', ['scripts:vendor', 'scripts:app']);
gulp.task('scripts:vendor', function(cb) {
pump([
gulp.src([
'node_modules/jquery/dist/jquery.js',
'node_modules/popper.js/dist/umd/popper.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/moment/moment.js',
'node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.js'
]),
concat('vendor.js'),
gulp.dest('babyblotter/static/babyblotter/js/')
], cb);
});
gulp.task('scripts:app', function(cb) {
pump([
gulp.src([
'babyblotter/static_site/js/babyblotter.js',
'api/static/js/*.js',
'core/static/js/*.js',
'dashboard/static/js/*.js'
]),
concat('app.js'),
gulp.dest('babyblotter/static/babyblotter/js/')
], cb);
});

View File

@ -1,30 +0,0 @@
var gulp = require('gulp');
var concat = require('gulp-concat');
var pump = require('pump');
var sass = require('gulp-sass');
var sassGlob = require('gulp-sass-glob');
gulp.task('styles', ['styles:vendor', 'styles:app']);
gulp.task('scripts:vendor', function(cb) {
pump([
gulp.src([
'node_modules/tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.css',
'node_modules/font-awesome/css/font-awesome.css'
]),
concat('vendor.css'),
gulp.dest('babyblotter/static/babyblotter/css/')
], cb);
});
gulp.task('app:styles', function (cb) {
pump([
gulp.src('babyblotter/static_site/scss/babyblotter.scss'),
sassGlob(),
sass().on('error', sass.logError),
concat('app.css'),
gulp.dest('babyblotter/static/babyblotter/css/')
], cb);
});