Use coffeescript for gulp

This commit is contained in:
Oliver Davies 2016-02-02 22:01:32 +00:00
parent f1048da9ae
commit cc9b97b840
13 changed files with 79 additions and 93 deletions

4
gulp/build.coffee Normal file
View file

@ -0,0 +1,4 @@
g = require 'gulp'
g.task 'build', ->
g.start 'clean', 'styles', 'scripts', 'fonts'

9
gulp/clean.coffee Normal file
View file

@ -0,0 +1,9 @@
g = require 'gulp'
g.task 'clean', ->
g.d.sync 'source/assets/css'
g.d.sync 'source/assets/fonts'
g.d.sync 'source/assets/js'
g.d.sync 'output_*/assets/css'
g.d.sync 'output_*/assets/fonts'
g.d.sync 'output_*/assets/js'

4
gulp/default.coffee Normal file
View file

@ -0,0 +1,4 @@
g = require 'gulp'
g.task 'default', ->
g.start 'build', 'watch'

4
gulp/fonts.coffee Normal file
View file

@ -0,0 +1,4 @@
g = require 'gulp'
g.task 'fonts', ->
g.copy('./vendor/bower/font-awesome/fonts/*', './source/assets/fonts')

6
gulp/images.coffee Normal file
View file

@ -0,0 +1,6 @@
g = require 'gulp'
g.task 'images', ->
g.src 'source/assets/images/*'
.pipe g.p.imagemin()
.pipe g.dest 'source/assets/images'

View file

@ -0,0 +1,6 @@
g = require 'gulp'
g.task 'minify-prod-html', ->
g.src 'output_prod/**/*.html'
.pipe g.p.htmlmin({ collapseWhitespace: true })
.pipe g.dest 'output_prod'

10
gulp/scripts.coffee Normal file
View file

@ -0,0 +1,10 @@
g = require 'gulp'
g.task 'scripts', =>
g.src ['vendor/bower/jquery/dist/jquery.js', 'vendor/bower/bootstrap-sass/assets/javascripts/bootstrap.js']
.pipe g.p.plumber()
.pipe g.p.if g.config.sourceMaps, g.p.sourcemaps.init()
.pipe g.p.concat 'all.js'
.pipe g.p.if g.config.production, g.p.uglify()
.pipe g.p.if g.config.sourceMaps, g.p.sourcemaps.write('.')
.pipe g.dest 'source/assets/js'

11
gulp/styles.coffee Normal file
View file

@ -0,0 +1,11 @@
g = require 'gulp'
g.task 'styles', ->
g.src ['vendor/bower/font-awesome/css/font-awesome.css', 'sass/styles.scss']
.pipe g.p.plumber()
.pipe g.p.if g.config.sourceMaps, g.p.sourcemaps.init()
.pipe g.p.sass()
.pipe g.p.concat 'all.css'
.pipe g.p.if g.config.sourceMaps, g.p.sourcemaps.write('.')
.pipe g.dest 'source/assets/css'
.pipe g.p.if g.config.livereload, g.p.livereload()

5
gulp/watch.coffee Normal file
View file

@ -0,0 +1,5 @@
g = require 'gulp'
g.task 'watch', ->
g.p.livereload.listen()
g.watch 'sass/**/*.scss', ['styles']

17
gulpfile.coffee Normal file
View file

@ -0,0 +1,17 @@
g = require('gulp')
g.p = require('gulp-load-plugins')()
g.d = require('del')
g.config =
bowerDir: 'vendor/bower',
assetsDir: './source/assets',
sassPattern: './sass/**/*.scss',
production: !!g.p.util.env.production,
sourceMaps: !g.p.util.env.production,
liveReload: !g.p.util.env.production
g.copy = (srcFiles, outputDir) ->
g.src(srcFiles)
.pipe g.dest(outputDir)
require('fs').readdirSync('./gulp').forEach (task) -> require "./gulp/#{task}"

View file

@ -1,92 +1,2 @@
'use strict';
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
del = require('del');
var config = {
bowerDir: 'vendor/bower',
assetsDir: './source/assets',
sassPattern: './sass/**/*.scss',
production: !!plugins.util.env.production,
sourceMaps: !plugins.util.env.production,
liveReload: !plugins.util.env.production
};
var app = {};
app.addStyle = function(paths, filename) {
gulp.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.sass())
.pipe(plugins.concat(filename))
.pipe(config.production ? plugins.minifyCss() : plugins.util.noop())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
.pipe(gulp.dest(config.assetsDir + '/css'))
.pipe(plugins.if(config.liveReload, plugins.livereload()));
};
app.copy = function(srcFiles, outputDir) {
gulp.src(srcFiles)
.pipe(gulp.dest(outputDir));
};
app.addScript = function(paths, filename) {
gulp.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.concat(filename))
.pipe(config.production ? plugins.uglify() : plugins.util.noop())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
.pipe(gulp.dest(config.assetsDir + '/js'))
}
gulp.task('fonts', function () {
// Copy fonts from bower_components into source/asset/fonts.
app.copy(config.bowerDir + '/font-awesome/fonts/*', config.assetsDir + '/fonts');
});
gulp.task('styles', function () {
app.addStyle([
config.bowerDir + '/font-awesome/css/font-awesome.css',
'./sass/styles.scss'
], 'all.css');
});
gulp.task('scripts', function () {
app.addScript([
config.bowerDir + '/jquery/dist/jquery.js',
config.bowerDir + '/bootstrap-sass/assets/javascripts/bootstrap.js'
], 'all.js');
});
gulp.task('images', function () {
// Minify images.
gulp.src(config.imagesDir + '/*')
.pipe(plugins.imagemin())
.pipe(gulp.dest(config.imagesDir));
});
gulp.task('watch', function () {
plugins.livereload.listen();
gulp.watch(config.sassPattern, ['styles']);
});
gulp.task('clean', function () {
del.sync(config.assetsDir + '/css');
del.sync(config.assetsDir + '/fonts');
del.sync(config.assetsDir + '/js');
del.sync('./output_*/assets/css/*');
del.sync('./output_*/assets/fonts/*');
});
gulp.task('minify-prod-html', function() {
gulp.src('output_prod/**/*.html')
.pipe(plugins.htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('output_prod'));
});
gulp.task('build', ['clean', 'styles', 'scripts', 'fonts']);
gulp.task('default', ['build', 'watch']);
require('coffee-script/register');
require('./gulpfile.coffee');

View file

@ -1,6 +1,7 @@
{
"devDependencies": {
"bower": "^1.7.7",
"coffee-script": "^1.10.0",
"del": "^2.2.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",

View file

@ -1,4 +1,3 @@
@import '_variables';
@import '../vendor/bower/compass-breakpoint/stylesheets/breakpoint';