From b0f552f3f845742deac9cc0eaeccb9627e71c5c5 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Mon, 21 Aug 2017 15:42:32 -0400 Subject: [PATCH] Refactor gulp tasks as a directory (WIP). --- gulpfile.js | 125 ------------------------------------- gulpfile/index.js | 4 ++ gulpfile/tasks/compress.js | 50 +++++++++++++++ gulpfile/tasks/default.js | 4 ++ gulpfile/tasks/extras.js | 11 ++++ gulpfile/tasks/scripts.js | 34 ++++++++++ gulpfile/tasks/styles.js | 30 +++++++++ package.json | 1 + 8 files changed, 134 insertions(+), 125 deletions(-) delete mode 100644 gulpfile.js create mode 100644 gulpfile/index.js create mode 100644 gulpfile/tasks/compress.js create mode 100644 gulpfile/tasks/default.js create mode 100644 gulpfile/tasks/extras.js create mode 100644 gulpfile/tasks/scripts.js create mode 100644 gulpfile/tasks/styles.js diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index d844ab1b..00000000 --- a/gulpfile.js +++ /dev/null @@ -1,125 +0,0 @@ -var gulp = require('gulp'); - -var concat = require('gulp-concat'); -var csso = require('gulp-csso'); -var pump = require('pump'); -var sass = require('gulp-sass'); -var sassGlob = require('gulp-sass-glob'); -var uglify = require('gulp-uglify'); - -/* APP FILES */ - -gulp.task('app:scripts', function() { - return gulp.src([ - 'babyblotter/static_site/js/babyblotter.js', - 'api/static/js/*.js', - 'core/static/js/*.js', - 'dashboard/static/js/*.js' - ]) - .pipe(concat('app.js')) - .pipe(gulp.dest('babyblotter/static/babyblotter/js/')); -}); - -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 - ); -}); - -gulp.task('app', ['app:scripts', 'app:styles']); - -/* VENDOR FILES */ - -gulp.task('vendor:scripts', function() { - return 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' - ]) - .pipe(concat('vendor.js')) - .pipe(gulp.dest('babyblotter/static/babyblotter/js/')); -}); - -gulp.task('vendor:styles', function() { - return gulp.src([ - //'node_modules/bootstrap/dist/css/bootstrap.css', - 'node_modules/tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.css', - 'node_modules/font-awesome/css/font-awesome.css' - ]) - .pipe(concat('vendor.css')) - .pipe(gulp.dest('babyblotter/static/babyblotter/css/')); -}); - -gulp.task('vendor:fonts', function() { - return gulp.src([ - 'node_modules/font-awesome/fonts/*' - ]) - .pipe(gulp.dest('babyblotter/static/babyblotter/fonts/')); -}); - -gulp.task('vendor', ['vendor:styles', 'vendor:scripts', 'vendor:fonts']); - -/* COMPRESSION */ - -gulp.task('compress:app:scripts', ['app:scripts'], function (cb) { - pump([ - gulp.src('babyblotter/static/babyblotter/js/app.js'), - concat('app.min.js'), - uglify(), - gulp.dest('babyblotter/static/babyblotter/js/') - ], - cb - ); -}); - -gulp.task('compress:app:styles', ['app:styles'], function (cb) { - pump([ - gulp.src('babyblotter/static/babyblotter/css/app.css'), - concat('app.min.css'), - csso(), - gulp.dest('babyblotter/static/babyblotter/css/') - ], - cb - ); -}); - -gulp.task('compress:vendor:scripts', ['vendor:scripts'], function (cb) { - pump([ - gulp.src('babyblotter/static/babyblotter/js/vendor.js'), - concat('vendor.min.js'), - uglify(), - gulp.dest('babyblotter/static/babyblotter/js/') - ], - cb - ); -}); - -gulp.task('compress:vendor:styles', ['vendor:styles'], function (cb) { - pump([ - gulp.src('babyblotter/static/babyblotter/css/vendor.css'), - concat('vendor.min.css'), - csso(), - gulp.dest('babyblotter/static/babyblotter/css/') - ], - cb - ); -}); - -gulp.task('compress', [ - 'compress:app:scripts', - 'compress:app:styles', - 'compress:vendor:scripts', - 'compress:vendor:styles' -]); - -/* DEFAULT */ - -gulp.task('default', ['vendor', 'app', 'compress']); \ No newline at end of file diff --git a/gulpfile/index.js b/gulpfile/index.js new file mode 100644 index 00000000..0dbf69b2 --- /dev/null +++ b/gulpfile/index.js @@ -0,0 +1,4 @@ +const requireDir = require('require-dir'); + + +requireDir('./tasks', { recurse: true }); diff --git a/gulpfile/tasks/compress.js b/gulpfile/tasks/compress.js new file mode 100644 index 00000000..6f28d1f6 --- /dev/null +++ b/gulpfile/tasks/compress.js @@ -0,0 +1,50 @@ +var gulp = require('gulp'); + +var concat = require('gulp-concat'); +var csso = require('gulp-csso'); +var pump = require('pump'); +var uglify = require('gulp-uglify'); + + +gulp.task('compress', [ + 'compress:scripts:app', + 'compress:styles:app', + 'compress:scripts:vendor', + 'compress:styles:vendor' +]); + +gulp.task('compress:scripts:app', ['scripts:app'], function (cb) { + pump([ + gulp.src('babyblotter/static/babyblotter/js/app.js'), + concat('app.min.js'), + uglify(), + gulp.dest('babyblotter/static/babyblotter/js/') + ], cb); +}); + +gulp.task('compress:scripts:vendor', ['scripts:vendor'], function (cb) { + pump([ + gulp.src('babyblotter/static/babyblotter/js/vendor.js'), + concat('vendor.min.js'), + uglify(), + gulp.dest('babyblotter/static/babyblotter/js/') + ], cb); +}); + +gulp.task('compress:styles:app', ['styles:app'], function (cb) { + pump([ + gulp.src('babyblotter/static/babyblotter/css/app.css'), + concat('app.min.css'), + csso(), + gulp.dest('babyblotter/static/babyblotter/css/') + ], cb); +}); + +gulp.task('compress:styles:vendor', ['styles:vendor'], function (cb) { + pump([ + gulp.src('babyblotter/static/babyblotter/css/vendor.css'), + concat('vendor.min.css'), + csso(), + gulp.dest('babyblotter/static/babyblotter/css/') + ], cb); +}); diff --git a/gulpfile/tasks/default.js b/gulpfile/tasks/default.js new file mode 100644 index 00000000..bcd85d10 --- /dev/null +++ b/gulpfile/tasks/default.js @@ -0,0 +1,4 @@ +const gulp = require('gulp'); + + +gulp.task('default', ['scripts', 'styles', 'compress', 'extras']); diff --git a/gulpfile/tasks/extras.js b/gulpfile/tasks/extras.js new file mode 100644 index 00000000..558f3af3 --- /dev/null +++ b/gulpfile/tasks/extras.js @@ -0,0 +1,11 @@ +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); +}); \ No newline at end of file diff --git a/gulpfile/tasks/scripts.js b/gulpfile/tasks/scripts.js new file mode 100644 index 00000000..e5d2520e --- /dev/null +++ b/gulpfile/tasks/scripts.js @@ -0,0 +1,34 @@ +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); +}); diff --git a/gulpfile/tasks/styles.js b/gulpfile/tasks/styles.js new file mode 100644 index 00000000..adc98d8f --- /dev/null +++ b/gulpfile/tasks/styles.js @@ -0,0 +1,30 @@ +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); +}); diff --git a/package.json b/package.json index ea89839e..7a767e43 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "moment": "^2.18.1", "popper.js": "^1.12.3", "pump": "^1.0.2", + "require-dir": "^0.3.2", "tempusdominus-bootstrap-4": "^5.0.0-alpha9" } }