Skip to content

Commit

Permalink
Finished Gulp Workflow post and refactored some of the Gulpfile and t…
Browse files Browse the repository at this point in the history
…asks.
  • Loading branch information
Matt Bengston committed Aug 29, 2015
1 parent 4c416a3 commit ad4edec
Show file tree
Hide file tree
Showing 31 changed files with 1,020 additions and 273 deletions.
5 changes: 1 addition & 4 deletions gulp-tasks/buildCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ var gulp = require('gulp'),
minifyCss = require('gulp-minify-css'),
autoprefixer = require('gulp-autoprefixer'),
/** Config */
config = require("../package.json");

/** Paths */
var paths = config.paths;
paths = require("../package.json").paths;

/**
* CSS
Expand Down
20 changes: 7 additions & 13 deletions gulp-tasks/buildJekyll.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
var spawn = require('child_process').spawn,
var exec = require('child_process').exec,
/** Utilities */
gutil = require('gulp-util');

module.exports = function buildJekyll(callback, env) {
var opts = ['build', '--config'];
gutil.log('Running Jekyll build.');
var cmd = 'jekyll build --config ';
cmd += (env === 'prod' ? '_config.build.yml' : '_config.yml');

if (env === 'prod') opts.push('_config.build.yml');
else opts.push('_config.yml');

var jekyll = spawn('jekyll', opts, {
stdio: 'inherit'
});

return jekyll.on('exit', function(code) {
return callback(code === 0 ? null : 'ERROR: Jekyll process exited with code: '+code);
return exec(cmd, function(error, stdout, stderror) {
gutil.log(stdout); // Log the output to the console
return callback(error !== null ? 'ERROR: Jekyll process exited with code: '+error.code : null);
});
};
};
6 changes: 1 addition & 5 deletions gulp-tasks/buildJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
/** Config */
config = require('../package.json');


/** Paths */
var paths = config.paths;
paths = require('../package.json').paths;

/**
* JavaScript
Expand Down
5 changes: 1 addition & 4 deletions gulp-tasks/optimizeImg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ var gulp = require('gulp'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
/** Config */
config = require("../package.json");

/** Paths */
var paths = config.paths;
paths = require("../package.json").paths;

/**
* Images
Expand Down
14 changes: 10 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/**
* Main gulpfile for aesinv.com, my Jekyll blog
* @todo: see `modular-gulpfile.js` - TO BE MOVED TO SEPARATE BRANCH
*/

var gulp = require('gulp'),

/** Utils */
lazypipe = require('lazypipe'),
watch = require('gulp-watch'),
browserSync = require('browser-sync').create('jekyll'),
requireDir = require('require-dir'),
Expand All @@ -16,7 +22,7 @@ var gulp = require('gulp'),
var utils = requireDir('gulp-tasks');
// Automagically set up tasks
gulpAutoTask('{*,**/*}.js', {
base: './gulp-tasks',
base: paths.tasks,
gulp: gulp
});

Expand All @@ -41,7 +47,7 @@ gulp.task('browser', function() {
});
});

// Force reload
// Force reload across all devices
gulp.task('browser:reload', function() {
browserSync.reload();
});
Expand All @@ -62,11 +68,11 @@ gulp.task('serve', ['browser'], function() {
});
// JS
watch([paths.js.src +'*.js', paths.vendor.src +'*.js'], function() {
gulp.start('buildJs', ['browser:reload']);
runSequence('buildJs', ['browser:reload']);
});
// Images
watch([paths.img.src +'*', paths.img.src +'**/*'], function() {
gulp.start('optimizeImg', ['browser:reload']);
runSequence('optimizeImg', ['browser:reload']);
});
// Markup / Posts/ Data
watch([
Expand Down
137 changes: 137 additions & 0 deletions modular-gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Main gulpfile for aesinv.com, my Jekyll blog
* @todo: refactor and to see if runSequence can be eliminated
* https://strongloop.com/strongblog/node-js-callback-hell-promises-generators/
*/

var gulp = require('gulp'),

/** Utils */
watch = require('gulp-watch'),
browserSync = require('browser-sync').create('jekyll'),
requireDir = require('require-dir'),
runSequence = require('run-sequence'),
gutil = require('gulp-util'),
gulpAutoTask = require('gulp-auto-task'),

/** Config */
paths = require('./package.json').paths;

/** Import Main Tasks */
// Require them so they can be called as functions
var utils = requireDir('gulp-tasks');
// Automagically set up tasks
gulpAutoTask('{*,**/*}.js', {
base: paths.tasks,
gulp: gulp
});

/** Helper Tasks */
var runTasks = function runTasks(array) {
return (function runTask(task, index, arr) {
if (arr.length === array.length) return arr;

gutil.log('Running task '+gutil.colors.red(task));

var results = utils[task]();

results.on('error', function(error) {
throw new Error("There was an error: "+error);
});

results.on('end', function() {
arr.push(true);
gutil.log('Task '+gutil.colors.red(task)+' completed.');
runTask(array[index + 1], index + 1, arr);
});
})(array[0], 0, []);
};

var build = function build(callback) {
return utils.buildJekyll(callback, 'serve');
};

var buildProduction = function buildProduction(callback) {
return utils.buildJekyll(callback, 'prod');
};

var buildAssets = function buildAssets() {
return runTasks(['buildCss', 'buildJs', 'optimizeImg']);
}

// gulp.task('build', function(callback) {
// return utils.buildJekyll(callback, 'serve');
// });

// gulp.task('build:prod', function(callback) {
// return utils.buildJekyll(callback, 'prod');
// });

// gulp.task('build:assets', ['buildCss', 'buildJs', 'optimizeImg']);

/**
* BrowserSync
*/
// Init server to build directory
gulp.task('browser', function() {
browserSync.init({
server: "./" + paths.build,
});
});

// Force reload across all devices
gulp.task('browser:reload', function() {
browserSync.reload();
});

/**
* Main Builds
*/
gulp.task('serve', ['browser'], function() {

runSequence('build', ['build:assets']);
// CSS/SCSS
watch([
paths.src +'fonts/*',
paths.sass.src +'*.scss',
paths.css.src +'main.scss',
paths.sass.src +'**/*.scss',
], function() {
runSequence('buildCss', ['browser:reload']);
});
// JS
watch([paths.js.src +'*.js', paths.vendor.src +'*.js'], function() {
runSequence('buildJs', ['browser:reload']);
});
// Images
watch([paths.img.src +'*', paths.img.src +'**/*'], function() {
runSequence('optimizeImg', ['browser:reload']);
});
// Markup / Posts/ Data
watch([
paths.src +'*',
paths.src +'_data/*',
paths.src +'_plugins/*',
paths.src +'**/*.md',
paths.src +'**/*.html',
paths.src +'**/*.markdown',
paths.src +'_includes/**/*.md',
paths.src +'_includes/**/*.svg',
paths.src +'_includes/**/*.html',
], function() {
// runSequence('build', ['build:assets', 'browser:reload']);
build({
buildAssets();
browserSync.reload();
});
});

gutil.log('Watching for changes.');
});

gulp.task('deploy', function() {
// runSequence('build:prod', ['build:assets']);
buildProduction(function() {
buildAssets();
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "Matt Bengston <matt@aesinv.com> (http://mattbengston.com)",
"license": "ISC",
"paths": {
"tasks": "gulp-tasks/",
"src": "project/",
"build": "_dist/",
"bower": "bower_components/",
Expand Down
Binary file added project/_assets/gulp-vid.mov
Binary file not shown.
107 changes: 107 additions & 0 deletions project/_assets/gulp-white-text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added project/_assets/gulp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions project/_assets/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added project/_assets/logo-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ad4edec

Please sign in to comment.