regexper-static/gulpfile.js

92 lines
2.7 KiB
JavaScript
Raw Normal View History

2015-11-01 16:05:12 +00:00
const gulp = require('gulp-help')(require('gulp')),
2015-11-01 15:45:09 +00:00
_ = require('lodash'),
notify = require('gulp-notify'),
folderToc = require('folder-toc'),
docco = require('gulp-docco'),
connect = require('gulp-connect'),
hb = require('gulp-hb'),
frontMatter = require('gulp-front-matter'),
rename = require('gulp-rename'),
config = require('./config'),
gutil = require('gulp-util'),
webpack = require('webpack')
webpackConfig = require('./webpack.config'),
fs = require('fs');
2015-11-01 16:05:12 +00:00
gulp.task('default', 'Auto-rebuild site on changes.', ['server', 'docs'], function() {
gulp.watch(config.globs.other, ['static']);
gulp.watch(_.flatten([
config.globs.templates,
config.globs.data,
config.globs.helpers,
config.globs.partials,
config.globs.svg_sass
]), ['markup']);
gulp.watch(_.flatten([
config.globs.sass,
config.globs.js
]), ['webpack']);
2016-10-15 16:20:01 +00:00
gulp.watch(config.globs.js, ['docs']);
2015-04-11 17:59:23 +00:00
});
2015-11-01 16:05:12 +00:00
gulp.task('docs', 'Build documentation into ./docs directory.', ['docs:files'], function() {
2015-04-11 17:59:23 +00:00
folderToc('./docs', {
filter: '*.html'
});
});
2015-11-01 16:05:12 +00:00
gulp.task('docs:files', false, function() {
2015-04-11 17:59:23 +00:00
return gulp.src(config.globs.js)
.pipe(docco())
.pipe(gulp.dest('./docs'));
});
2015-11-01 16:05:12 +00:00
gulp.task('server', 'Start development server.', ['build'], function() {
2015-10-31 13:32:34 +00:00
gulp.watch(config.buildPath('**/*'), function(file) {
return gulp.src(file.path).pipe(connect.reload());
});
2014-11-23 17:24:03 +00:00
return connect.server({
root: config.buildRoot,
2014-11-23 17:24:03 +00:00
livereload: true
});
});
gulp.task('build', 'Build site into ./build directory.', ['static', 'webpack', 'markup']);
2015-11-01 16:05:12 +00:00
gulp.task('static', 'Build static files into ./build directory.', function() {
return gulp.src(config.globs.other, { base: './src' })
.pipe(gulp.dest(config.buildRoot));
});
gulp.task('markup', 'Build markup into ./build directory.', ['webpack'], function() {
var hbStream = hb({
data: config.globs.data,
helpers: config.globs.helpers,
partials: config.globs.partials,
parsePartialName: function(option, file) {
return _.last(file.path.split(/\\|\//)).replace('.hbs', '');
},
bustCache: true
});
hbStream.partials({
svg_styles: fs.readFileSync(__dirname + '/build/css/svg.css').toString()
});
return gulp.src(config.globs.templates)
.pipe(frontMatter())
.pipe(hbStream)
2015-11-01 12:21:17 +00:00
.on('error', notify.onError())
2015-11-01 16:10:22 +00:00
.pipe(rename({ extname: '.html' }))
.pipe(gulp.dest(config.buildRoot));
2014-11-23 21:16:10 +00:00
});
gulp.task('webpack', 'Build JS & CSS into ./build directory.', function(callback) {
webpack(webpackConfig, function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString());
callback();
});
});