Skip to content

Instantly share code, notes, and snippets.

@cyrusdavid
Last active August 29, 2015 14:01
Show Gist options
  • Save cyrusdavid/1317b2b88e48b05b3758 to your computer and use it in GitHub Desktop.
Save cyrusdavid/1317b2b88e48b05b3758 to your computer and use it in GitHub Desktop.
// jshint node:true, latedef:nofunc
'use strict';
var flo = require('fb-flo'),
gulp = require('gulp'),
path = require('path'),
map = require('map-stream'),
minimatch = require('minimatch'),
lazypipe = require('lazypipe'),
rimraf = require('rimraf'),
PassThrough = require('stream').PassThrough,
$ = require('gulp-load-plugins')(),
lazy = {},
server,
reloader,
globs;
require('longjohn');
globs = {
less: 'less/**/*.less',
js: 'js/**/*.js',
extras: '*.*'
};
lazy.less = lazypipe()
.pipe($.less)
.pipe($.csso)
.pipe(gulp.dest, 'dest/css')
.pipe(reload)
.pipe(exclude);
lazy.js = lazypipe()
.pipe($.uglify)
.pipe(gulp.dest, 'dest/js')
.pipe(reload)
.pipe(exclude);
gulp.task('flo', function(done) {
server = flo('app', {
port: 8888,
host: 'localhost',
verbose: 1,
glob: ['**/*', '!**/*.tmp']
}, resolver)
.once('ready', done);
});
gulp.task('less', function() {
return gulp.src(path.join('app', globs.less))
.pipe(lazy.less());
});
gulp.task('js', function() {
return gulp.src(path.join('app', globs.js))
.pipe(lazy.js());
});
gulp.task('extras', function () {
return gulp.src(path.join('app', globs.extras), { dot: true })
.pipe(gulp.dest('dest'));
});
gulp.task('clean', function(done) {
rimraf('dest', done);
});
gulp.task('build', ['less', 'js', 'extras']);
gulp.task('rebuild', ['clean'], function() {
gulp.start('build');
});
function resolver(filepath, callback) {
reloader = map(function(file, cb) {
callback({
reload: !!reload,
resourceURL: path.relative('dest', file.path).replace('\\', '/'),
contents: file.contents.toString()
});
cb(null, file);
});
gulp
.src(path.resolve('app', filepath))
.pipe($.if(minimatch(filepath, globs.less), lazy.less()))
.pipe($.if(minimatch(filepath, globs.js), lazy.js()))
.pipe(gulp.dest('dest'))
.pipe(reload(1));
}
function exclude() {
return map(function(file, callback) {
callback();
});
}
function reload() {
if (typeof reloader !== 'undefined') return reloader;
return new PassThrough({ objectMode: true });
}
@tcoopman
Copy link

Nice update with the build step. Maybe you could also add a default step (that builds and starts flo)?

Maybe it would be nice to integrate a server (maybe with livereloading for html) to serve the files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment