Created
April 2, 2014 18:23
-
-
Save malixsys/9940061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var lr = require('tiny-lr'); | |
var server = lr(); | |
var browserify = require('gulp-browserify'); | |
var spawn = require('child_process').spawn; | |
var rename = require('gulp-rename'); | |
var plumber = require('gulp-plumber'); | |
var refresh = require('gulp-livereload'); | |
var uglify = require('gulp-uglify'); | |
var templates = require('gulp-angular-templatecache'); | |
var minifyHTML = require('gulp-minify-html'); | |
var gulpif = require('gulp-if'); | |
//var runSequence = require('run-sequence'); | |
var sections = ['anonymous', 'admin', 'user']; | |
sections.forEach(function(section) { | |
gulp.task(section, function(cb) { | |
var isBuild = gutil.env.build; | |
//single entry point to browserify | |
return gulp.src(['./client/' + section + '/' + section + '.js']) | |
.pipe(plumber(true)) | |
.pipe(browserify({ | |
insertGlobals: true, | |
debug: true | |
}).on('error', function() { | |
gutil.log(gutil.colors.red('**************** ERROR ****************'), arguments); | |
//cb(); | |
})) | |
.pipe(gulpif(isBuild, uglify({hoist_funs: false}))) | |
.pipe(rename(section + '.js')) | |
.pipe(gulp.dest('./www/js')) | |
; | |
}); | |
}); | |
gulp.task('lr-server', function() { | |
server.listen(35729, function(err) { | |
if (err) { | |
gutil.log(gutil.colors.red('ERROR'), err); | |
return; | |
} | |
}); | |
}); | |
gulp.task('templates', function() { | |
gulp.src(["www/partials/**/*.html"]) | |
.pipe(minifyHTML({ | |
quotes: true | |
})) | |
.pipe(templates('templates.js', { | |
module: 'app', | |
root: 'partials' | |
})) | |
.pipe(uglify({hoist_funs: false})) | |
.pipe(gulp.dest('./www/js')) | |
}); | |
gulp.task('html', function() { | |
gulp.src(["www/*.html"]) | |
.pipe(refresh(server)); | |
}); | |
gulp.task('nodemon', function(cb) { | |
spawn('./node_modules/.bin/nodemon', ['--watch', 'server', 'server/server.js', '--ext', 'js,coffee'], { | |
stdio: 'inherit' | |
}) | |
.on('close', function() { | |
cb(); | |
}); | |
}); | |
gulp.task('default', function() { | |
gutil.log(gutil.colors.green('Default'), gutil.env); | |
gulp.run.apply(gulp, ['lr-server', 'nodemon'].concat(sections)); | |
gulp.watch('client/common/**/*.js', function(evt) { | |
gutil.log(gutil.colors.cyan('common'), 'changed'); | |
gulp.run.apply(gulp, sections); | |
}); | |
sections.forEach(function(section) { | |
gulp.watch('client/' + | |
section + | |
'/**/*.js', function(evt) { | |
gutil.log(gutil.colors.cyan(section), 'changed'); | |
gulp.run(section); | |
}); | |
}); | |
gulp.watch('www/css/**/*.css', function(evt) { | |
gutil.log(gutil.colors.cyan('css'), 'changed'); | |
server.changed({ | |
body: { | |
files: [evt.path] | |
} | |
}); | |
}); | |
gulp.watch('www/js/*.js', function(evt) { | |
gutil.log(gutil.colors.cyan('js'), 'changed', gutil.colors.gray(evt.path)); | |
server.changed({ | |
body: { | |
files: [evt.path] | |
} | |
}); | |
}); | |
gulp.watch('www/**/*.html', function(evt) { | |
gulp.run('html'); | |
}); | |
}); | |
gulp.task('build', function() { | |
gutil.env.build = true; | |
gutil.log(gutil.colors.green('Build'), gutil.env); | |
// gulp.run.apply(gulp, ['templates'].concat(sections)); | |
gulp.run.apply(gulp, [].concat(sections)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment