Created
February 12, 2016 17:27
-
-
Save Melindrea/4b4ae9da4ac555023400 to your computer and use it in GitHub Desktop.
The assemblefile
This file contains hidden or 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
'use strict'; | |
var path = require('path'), | |
merge = require('mixin-deep'), | |
extname = require('gulp-extname'), | |
permalinks = require('assemble-permalinks'), | |
getDest = require('./plugins/get-dest'), | |
viewEvents = require('./plugins/view-events'), | |
git = require('gulp-git'), | |
bump = require('gulp-bump'), | |
filter = require('gulp-filter'), | |
tagVersion = require('gulp-tag-version'), | |
browserSync = require('browser-sync'), | |
gp = require('gulp-load-plugins')(), | |
reload = browserSync.reload, | |
assemble = require('assemble'), | |
app = assemble(); | |
/** | |
* Plugins | |
*/ | |
app.use(viewEvents('permalink')); | |
app.use(permalinks()); | |
app.use(getDest()); | |
app.onPermalink(/./, function (file, next) { | |
file.data = merge({}, app.cache.data, file.data); | |
next(); | |
}); | |
var buildDir = 'build', | |
tempDir = '.tmp'; | |
app.data({ | |
site: { | |
base: buildDir | |
} | |
}); | |
/** | |
* Create views collection for our site pages and blog posts. | |
* Posts will be written in markdown. | |
*/ | |
app.create('pages'); | |
app.create('posts', { | |
pager: true, | |
renameKey: function (key, view) { | |
return view ? view.basename : path.basename(key); | |
} | |
}); | |
app.posts.use(permalinks(':site.base/blog/:filename.html')); | |
app.pages.use(permalinks(':site.base/:filename.html')); | |
/** | |
* Register a handlebars helper for processing markdown. | |
* This could also be done with a gulp plugin, or a | |
* middleware, but helpers are really easy and provide | |
* the most control. | |
*/ | |
app.helper('markdown', require('helper-markdown')); | |
app.helpers('helpers/*.js'); | |
app.helper('log', function (val) { | |
console.log(val); | |
}); | |
/** | |
* Tasks for loading and rendering our templates | |
*/ | |
app.task('load', function (cb) { | |
app.partials('templates/includes/*.hbs'); | |
app.layouts('templates/layouts/*.hbs'); | |
app.pages('content/pages/*.hbs'); | |
app.posts('content/posts/*.md'); | |
cb(); | |
}); | |
app.task('clean', require('del').bind(null, [tempDir, buildDir])); | |
app.task('resources', function () { | |
app.copy('resources/**/*', buildDir); | |
}); | |
function bumpAndTag(importance) { | |
// get all the files to bump version in | |
return app.src(['./package.json'], {layout: null}) | |
// bump the version number in those files | |
.pipe(bump({type: importance})) | |
// save it back to filesystem | |
.pipe(app.dest('./')) | |
// commit the changed version number | |
.pipe(git.commit('Bump site version')) | |
// read only one file to get the version number | |
.pipe(filter('package.json')) | |
// **tag it in the repository** | |
.pipe(tagVersion()); | |
} | |
app.task('patch', function () { return bumpAndTag('patch'); }); | |
app.task('feature', function () { return bumpAndTag('minor'); }); | |
app.task('release', function () { return bumpAndTag('major'); }); | |
app.task('jshint', function () { | |
return app.src( | |
[ | |
'assets/scripts/**/*.js', | |
'*.js', | |
'helpers/**/*.js' | |
] | |
) | |
.pipe(reload({stream: true, once: true})) | |
.pipe(gp.jshint()) | |
.pipe(gp.jshint.reporter('jshint-stylish')) | |
.pipe(gp.if(! browserSync.active, gp.jshint.reporter('fail'))); | |
}); | |
/** | |
* Default task | |
*/ | |
app.task('default', ['clean', 'load'], function () { | |
return app.toStream('pages') | |
.pipe(app.toStream('posts')) | |
.on('error', console.log) | |
.pipe(app.renderFile('md')) | |
.on('error', console.log) | |
.pipe(extname()) | |
.pipe(app.dest(function (file) { | |
file.path = file.data.permalink; | |
file.base = path.dirname(file.path); | |
return file.base; | |
})); | |
}); | |
/** | |
* Expose your instance of assemble to the CLI | |
*/ | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment