regexper-static/gulpfile.js

173 lines
5.1 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'),
sass = require('gulp-sass'),
bourbon = require('node-bourbon'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
sourcemaps = require('gulp-sourcemaps'),
canopy = require('./lib/canopy-transform'),
babelify = require('babelify'),
karma = require('karma'),
path = require('path'),
jscs = require('gulp-jscs'),
2015-11-01 16:32:05 +00:00
uglify = require('gulp-uglify'),
2015-11-01 15:45:09 +00:00
config = require('./config');
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(config.globs.sass, ['styles']);
2015-11-01 12:07:17 +00:00
gulp.watch(config.globs.js, ['scripts', '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
});
});
2015-11-01 16:05:12 +00:00
gulp.task('build', 'Build site into ./build directory.', ['static', 'markup', 'styles', 'scripts']);
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));
});
2015-11-01 16:05:12 +00:00
gulp.task('markup', 'Build markup into ./build directory.', ['markup:svg_styles'], function() {
return gulp.src(config.globs.templates)
.pipe(frontMatter())
.pipe(hb({
data: config.globs.data,
helpers: config.globs.helpers,
partials: _.flatten([
config.globs.partials,
'./tmp/build/svg_styles.hbs'
]),
parsePartialName: function(file) {
return _.last(file.shortPath.split('/'));
},
bustCache: true
}))
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
});
2015-11-01 16:05:12 +00:00
gulp.task('markup:svg_styles', false, function() {
return gulp.src('./src/sass/svg.scss')
.pipe(sass({
2015-11-01 16:32:05 +00:00
includePaths: bourbon.includePaths,
outputStyle: 'compressed'
}))
.on('error', notify.onError())
2015-11-01 16:10:22 +00:00
.pipe(rename({
dirname: '',
basename: 'svg_styles',
extname: '.hbs'
}))
.pipe(gulp.dest('./tmp/build'))
});
2015-11-01 16:05:12 +00:00
gulp.task('styles', 'Build stylesheets into ./build directory.', function() {
2015-11-01 16:44:27 +00:00
return gulp.src('./src/sass/main.scss', { base: '.' })
.pipe(sourcemaps.init())
.pipe(sass({
2015-11-01 16:32:05 +00:00
includePaths: bourbon.includePaths,
outputStyle: 'compressed'
}))
2015-11-01 12:21:17 +00:00
.on('error', notify.onError())
2015-11-01 16:10:22 +00:00
.pipe(rename({ dirname: '' }))
.pipe(sourcemaps.write('.'))
2015-11-01 12:21:17 +00:00
.pipe(gulp.dest(config.buildPath('css')))
});
2014-11-23 22:00:01 +00:00
2015-11-01 16:05:12 +00:00
gulp.task('scripts', 'Build scripts into ./build directory', function() {
2015-11-11 02:40:35 +00:00
return browserify([require.resolve('babel-polyfill'), './src/js/main.js'], config.browserify)
2015-11-01 15:45:09 +00:00
.transform(canopy)
.transform(babelify)
2015-11-01 15:28:37 +00:00
.bundle()
2015-11-01 12:21:17 +00:00
.on('error', notify.onError())
2015-11-01 16:44:27 +00:00
.pipe(source('main.js'))
2015-11-01 12:07:17 +00:00
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
2015-11-01 16:32:05 +00:00
.pipe(uglify())
2015-11-01 12:07:17 +00:00
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.buildPath('js')));
2014-11-23 23:55:32 +00:00
});
2014-11-23 22:00:01 +00:00
2015-11-01 16:05:12 +00:00
gulp.task('verify', 'Verify (lint and run tests) scripts.', ['karma:single', 'lint']);
2015-11-01 15:11:36 +00:00
2015-11-01 16:05:12 +00:00
gulp.task('verify:watch', 'Auto-verify scripts.', ['karma', 'lint:watch']);
2015-11-01 15:11:36 +00:00
2015-11-01 16:05:12 +00:00
gulp.task('karma', 'Auto-run scripting tests.', function(done) {
2015-11-01 15:45:09 +00:00
new karma.Server({
configFile: path.join(__dirname, 'karma.conf.js')
}, done).start();
2014-11-23 22:00:01 +00:00
});
2015-11-01 16:05:12 +00:00
gulp.task('karma:single', 'Run scripting tests', function(done) {
2015-11-01 15:45:09 +00:00
new karma.Server({
configFile: path.join(__dirname, 'karma.conf.js'),
singleRun: true
}, done).start();
});
2015-11-01 15:11:36 +00:00
2015-11-01 16:05:12 +00:00
gulp.task('lint', 'Lint scripts', function() {
2015-11-01 15:11:36 +00:00
return gulp.src(config.globs.lint)
.pipe(jscs())
.pipe(jscs.reporter())
.pipe(jscs.reporter('fail'))
.on('error', notify.onError())
});
2015-11-01 16:05:12 +00:00
gulp.task('lint:watch', 'Auto-lint scripts', function() {
2015-11-01 15:11:36 +00:00
gulp.watch(config.globs.lint, ['lint']);
});
2015-11-01 16:05:12 +00:00
gulp.task('lint:fix', 'Fix some lint errors.', config.lintRoots.map(function(root) {
2015-11-01 15:11:36 +00:00
return 'lint:fix:' + root;
}), function() {
return gulp.src('./*.js')
.pipe(jscs({fix: true}))
.pipe(gulp.dest('.'));
});
config.lintRoots.forEach(function(root) {
2015-11-01 16:05:12 +00:00
gulp.task('lint:fix:' + root, false, function() {
2015-11-01 15:11:36 +00:00
return gulp.src('./' + root + '/**/*.js')
.pipe(jscs({fix: true}))
.pipe(gulp.dest('./' + root));
});
});