lychee/src/gulpfile.js

150 lines
3.5 KiB
JavaScript
Raw Normal View History

2014-07-18 20:09:15 +00:00
var gulp = require('gulp'),
2014-10-21 11:12:49 +00:00
plugins = require("gulp-load-plugins")(),
paths = {}
2014-07-18 20:09:15 +00:00
2014-10-21 11:12:49 +00:00
/* Error Handler -------------------------------- */
var catchError = function(err) {
console.log(err.toString());
this.emit('end');
}
/* View ----------------------------------------- */
paths.view = {
js: [
2014-07-18 20:09:15 +00:00
'bower_components/jQuery/dist/jquery.min.js',
'bower_components/js-md5/js/md5.min.js',
'bower_components/mousetrap/mousetrap.min.js',
'bower_components/mousetrap/plugins/global-bind/mousetrap-global-bind.min.js',
2014-10-10 21:30:10 +00:00
'../src/scripts/_frameworks.js',
'../src/scripts/view/main.js'
2014-07-18 20:09:15 +00:00
],
2014-10-21 11:12:49 +00:00
coffee: [
'../src/scripts/build.coffee'
],
scripts: [
'../dist/_view--javascript.js',
'../dist/_view--coffee.js'
]
}
gulp.task('view--js', function() {
return gulp.src(paths.view.js)
.pipe(plugins.concat('_view--javascript.js', {newLine: "\n"}))
.pipe(gulp.dest('../dist/'));
});
gulp.task('view--coffee', function() {
return gulp.src(paths.view.coffee)
.pipe(plugins.coffee({bare: true}))
.on('error', catchError)
.pipe(plugins.concat('_view--coffee.js', {newLine: "\n"}))
.pipe(gulp.dest('../dist/'));
});
gulp.task('view--scripts', ['view--js', 'view--coffee'], function() {
return gulp.src(paths.view.scripts)
.pipe(plugins.concat('view.js', {newLine: "\n"}))
.pipe(plugins.uglify())
.on('error', catchError)
.pipe(gulp.dest('../dist/'));
});
/* Main ----------------------------------------- */
paths.main = {
2014-07-18 20:09:15 +00:00
js: [
'bower_components/jQuery/dist/jquery.min.js',
'bower_components/js-md5/js/md5.min.js',
'bower_components/mousetrap/mousetrap.min.js',
'bower_components/mousetrap/plugins/global-bind/mousetrap-global-bind.min.js',
2014-10-10 21:30:10 +00:00
'../src/scripts/*.js'
2014-07-18 20:09:15 +00:00
],
2014-10-21 11:12:49 +00:00
coffee: [
'../src/scripts/*.coffee'
],
scripts: [
'../dist/_main--javascript.js',
'../dist/_main--coffee.js'
],
2014-10-21 12:55:44 +00:00
scss: [
'../src/styles/*.scss'
],
2014-10-21 11:12:49 +00:00
styles: [
2014-10-10 21:30:10 +00:00
'../src/styles/main.scss'
2014-07-18 20:09:15 +00:00
]
}
2014-10-21 11:12:49 +00:00
gulp.task('main--js', function() {
2014-10-21 11:12:49 +00:00
return gulp.src(paths.main.js)
.pipe(plugins.concat('_main--javascript.js', {newLine: "\n"}))
.pipe(gulp.dest('../dist/'));
2014-10-21 11:12:49 +00:00
});
gulp.task('main--coffee', function() {
return gulp.src(paths.main.coffee)
.pipe(plugins.coffee({bare: true}))
.on('error', catchError)
.pipe(plugins.concat('_main--coffee.js', {newLine: "\n"}))
.pipe(gulp.dest('../dist/'));
});
2014-10-21 11:12:49 +00:00
gulp.task('main--scripts', ['main--js', 'main--coffee'], function() {
2014-07-18 20:09:15 +00:00
2014-10-21 11:12:49 +00:00
return gulp.src(paths.main.scripts)
.pipe(plugins.concat('main.js', {newLine: "\n"}))
.pipe(plugins.uglify())
.on('error', catchError)
.pipe(gulp.dest('../dist/'));
2014-07-18 20:09:15 +00:00
});
2014-10-21 11:12:49 +00:00
gulp.task('main--styles', function() {
2014-10-21 11:12:49 +00:00
return gulp.src(paths.main.styles)
.pipe(plugins.sass())
.on('error', catchError)
.pipe(plugins.concat('main.css', {newLine: "\n"}))
.pipe(plugins.autoprefixer('last 4 versions', '> 5%'))
.pipe(plugins.minifyCss())
.pipe(gulp.dest('../dist/'));
2014-07-18 20:09:15 +00:00
});
2014-10-21 11:12:49 +00:00
/* Clean ----------------------------------------- */
2014-07-18 20:09:15 +00:00
2014-10-21 11:12:49 +00:00
gulp.task('clean', function() {
return gulp.src('../dist/_*.*', { read: false })
.pipe(plugins.rimraf({ force: true }))
.on('error', catchError);
2014-07-18 20:09:15 +00:00
});
2014-10-21 11:12:49 +00:00
/* Tasks ----------------------------------------- */
gulp.task('default', ['view--scripts', 'main--scripts', 'main--styles', 'clean']);
2014-07-18 20:09:15 +00:00
gulp.task('watch', ['default'], function() {
2014-10-21 11:12:49 +00:00
gulp.watch(paths.view.js, ['view--scripts', 'clean']);
gulp.watch(paths.view.coffee, ['view--scripts', 'clean']);
gulp.watch(paths.main.js, ['main--scripts', 'clean']);
gulp.watch(paths.main.coffee, ['main--scripts', 'clean']);
2014-10-21 12:55:44 +00:00
gulp.watch(paths.main.scss, ['main--styles', 'clean']);
2014-10-21 11:12:49 +00:00
2014-07-18 20:09:15 +00:00
});