2014-11-23 22:26:05 +00:00
|
|
|
var gulp = require('gulp'),
|
2014-11-23 22:50:30 +00:00
|
|
|
notify = require('gulp-notify'),
|
|
|
|
plumber = require('gulp-plumber'),
|
2014-11-23 22:26:05 +00:00
|
|
|
config = require('./config');
|
2014-11-23 16:52:45 +00:00
|
|
|
|
2014-11-23 22:50:30 +00:00
|
|
|
function errorHandler() {
|
|
|
|
return plumber({
|
|
|
|
errorHandler: notify.onError('Error: <%= error.message %>')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-04-11 17:59:23 +00:00
|
|
|
gulp.task('default', ['server', 'docs'], function() {
|
2014-11-23 22:26:05 +00:00
|
|
|
gulp.watch(config.globs.other, ['static']);
|
2014-12-21 19:39:00 +00:00
|
|
|
gulp.watch([config.globs.html, config.templateFile, config.globs.sass], ['markup']);
|
2015-04-11 17:59:23 +00:00
|
|
|
gulp.watch(config.globs.js, ['browserify', 'docs']);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('docs', ['docs:files'], function() {
|
|
|
|
var folderToc = require('folder-toc');
|
|
|
|
|
|
|
|
folderToc('./docs', {
|
|
|
|
filter: '*.html'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('docs:files', function() {
|
|
|
|
var docco = require('gulp-docco');
|
|
|
|
|
|
|
|
return gulp.src(config.globs.js)
|
|
|
|
.pipe(docco())
|
|
|
|
.pipe(gulp.dest('./docs'));
|
2014-11-23 16:52:45 +00:00
|
|
|
});
|
2014-11-23 17:00:07 +00:00
|
|
|
|
2014-11-23 22:13:24 +00:00
|
|
|
gulp.task('server', ['build'], function() {
|
2014-11-23 22:17:29 +00:00
|
|
|
var connect = require('gulp-connect'),
|
|
|
|
watch = require('gulp-watch');
|
|
|
|
|
2014-11-30 19:39:56 +00:00
|
|
|
watch(config.buildPath('**/*'), { name: 'Server' })
|
2014-11-23 17:24:03 +00:00
|
|
|
.pipe(connect.reload());
|
2014-11-23 22:50:30 +00:00
|
|
|
|
2014-11-23 17:24:03 +00:00
|
|
|
return connect.server({
|
2014-11-30 19:39:56 +00:00
|
|
|
root: config.buildRoot,
|
2014-11-23 17:24:03 +00:00
|
|
|
livereload: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-23 22:13:24 +00:00
|
|
|
gulp.task('build', ['static', 'markup', 'compass', 'browserify']);
|
|
|
|
|
2014-11-23 21:29:40 +00:00
|
|
|
gulp.task('static', function() {
|
2014-11-30 19:39:56 +00:00
|
|
|
return gulp.src(config.globs.other, { base: './src' })
|
2014-11-23 22:50:30 +00:00
|
|
|
.pipe(errorHandler())
|
2014-11-30 19:39:56 +00:00
|
|
|
.pipe(gulp.dest(config.buildRoot));
|
2014-11-23 21:29:40 +00:00
|
|
|
});
|
|
|
|
|
2014-12-21 19:39:00 +00:00
|
|
|
gulp.task('markup', ['compass'], function() {
|
2014-12-21 06:42:48 +00:00
|
|
|
var wrap = require('gulp-wrap'),
|
2014-12-21 19:39:00 +00:00
|
|
|
path = require('path'),
|
|
|
|
fs = require('fs');
|
2014-11-23 22:17:29 +00:00
|
|
|
|
2014-11-30 19:39:56 +00:00
|
|
|
return gulp.src(config.globs.html, { base: './src' })
|
2014-11-23 22:50:30 +00:00
|
|
|
.pipe(errorHandler())
|
2014-12-21 06:42:48 +00:00
|
|
|
.pipe(wrap({ src: config.templateFile }, {
|
2014-12-24 01:23:37 +00:00
|
|
|
date: new Date().toISOString(),
|
2014-12-21 06:42:48 +00:00
|
|
|
title: function() {
|
|
|
|
var root = path.join(this.file.cwd, this.file.base),
|
|
|
|
file = path.relative(root, this.file.history[0]);
|
|
|
|
|
|
|
|
return config.titles[file] || config.titles['_'];
|
2014-12-21 19:39:00 +00:00
|
|
|
},
|
|
|
|
svgStyles: fs.readFileSync(path.join(config.compass.css, 'svg.css'), {
|
|
|
|
encoding: 'utf-8'
|
|
|
|
})
|
2014-12-21 06:42:48 +00:00
|
|
|
}))
|
2014-11-30 19:39:56 +00:00
|
|
|
.pipe(gulp.dest(config.buildRoot));
|
2014-11-23 21:16:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('compass', function() {
|
2014-11-23 22:17:29 +00:00
|
|
|
var compass = require('gulp-compass');
|
|
|
|
|
2014-11-23 22:26:05 +00:00
|
|
|
return gulp.src(config.globs.sass)
|
2014-11-23 22:50:30 +00:00
|
|
|
.pipe(errorHandler())
|
2014-11-23 22:26:05 +00:00
|
|
|
.pipe(compass(config.compass));
|
2014-11-23 17:00:07 +00:00
|
|
|
});
|
2014-11-23 22:00:01 +00:00
|
|
|
|
|
|
|
gulp.task('browserify', function() {
|
2014-11-25 13:55:07 +00:00
|
|
|
var browserify = require('browserify'),
|
2015-01-19 14:58:51 +00:00
|
|
|
tap = require('gulp-tap');
|
2014-11-25 13:55:07 +00:00
|
|
|
|
2014-11-23 22:50:30 +00:00
|
|
|
return gulp.src('./src/js/main.js', { read: false })
|
|
|
|
.pipe(errorHandler())
|
2014-11-25 13:55:07 +00:00
|
|
|
.pipe(tap(function(file) {
|
|
|
|
var bundler = browserify(config.browserify);
|
|
|
|
|
2014-11-30 19:39:56 +00:00
|
|
|
config.browserify.prebundle(bundler);
|
2014-11-25 13:55:07 +00:00
|
|
|
|
2014-12-04 23:34:35 +00:00
|
|
|
bundler.add(file.path);
|
|
|
|
|
2015-01-19 14:58:51 +00:00
|
|
|
file.contents = bundler.bundle();
|
2014-11-30 14:58:27 +00:00
|
|
|
}))
|
2014-11-30 19:39:56 +00:00
|
|
|
.pipe(gulp.dest(config.buildPath('js')));
|
2014-11-23 23:55:32 +00:00
|
|
|
});
|
2014-11-23 22:00:01 +00:00
|
|
|
|
2014-11-25 02:44:50 +00:00
|
|
|
gulp.task('karma', function(done) {
|
|
|
|
var karma = require('karma'),
|
|
|
|
path = require('path');
|
2014-11-23 22:50:30 +00:00
|
|
|
|
2014-11-25 02:44:50 +00:00
|
|
|
karma.server.start({
|
|
|
|
configFile: path.join(__dirname, 'karma.conf.js')
|
|
|
|
}, done);
|
2014-11-23 22:00:01 +00:00
|
|
|
});
|
2014-12-22 16:20:41 +00:00
|
|
|
|
|
|
|
gulp.task('karma:single', function(done) {
|
|
|
|
var karma = require('karma'),
|
|
|
|
path = require('path');
|
|
|
|
|
|
|
|
karma.server.start({
|
|
|
|
configFile: path.join(__dirname, 'karma.conf.js'),
|
|
|
|
singleRun: true
|
|
|
|
}, done);
|
|
|
|
});
|