-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished Gulp Workflow post and refactored some of the Gulpfile and t…
…asks.
- Loading branch information
Matt Bengston
committed
Aug 29, 2015
1 parent
4c416a3
commit ad4edec
Showing
31 changed files
with
1,020 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.