gulp = require 'gulp'
browserSync = require 'browser-sync'
reload = browserSync.reload
data = require 'gulp-data'
util = require('gulp-util')
debug = require 'gulp-debug'
newer = require 'gulp-newer'
compass = require 'gulp-compass'
sourcemaps = require 'gulp-sourcemaps'
minify = require 'gulp-minify-css'
del = require('del')
browserify = require 'browserify'
debowerify = require 'debowerify'
licensify = require 'licensify'
source = require 'vinyl-source-stream'
streamify = require 'gulp-streamify'
uglify = require 'gulp-uglify'
buffer = require 'vinyl-buffer'
jade = require 'gulp-jade'
pngmin = require 'gulp-pngmin'
imagemin = require 'gulp-imagemin'
jpegtran = require 'imagemin-jpegtran'
watch = require 'gulp-watch'
scp = require 'scp'
src =
js : './src/javascript'
css : './src/sass'
html : './src/jade'
image : './src/image'
copy : './src/copy'
build =
js : './build/public'
css : './build/public'
html : './build'
image : './build/public/image'
env =
isProduct : false
deployToProduct : false
rootDev: '/path/to/staging'
rootPro: '/path/to/production'
gulp.task 'deploy', ->
dest = env.rootDev
if env.deployToProduct
dest = env.rootPro
else
dest = env.rootDev
scp.send(
file : './deploy/*'
host : 'hostname'
user : 'username'
path : dest
, (e) ->
util.beep()
console.log e
)
gulp.task 'changeEnv', ->
env.isProduct = true
build =
js : './deploy/public'
css : './deploy/public'
html : './deploy'
image : './deploy/public/image'
gulp.task 'changeDeployEnv', ->
env.deployToProduct = true
gulp.task 'css', ->
if env.isProduct
gulp.src(src.css + '/*.sass')
.pipe compass(
css : build.css
sass : src.css
)
.pipe minify()
.pipe gulp.dest(build.css)
else
gulp.src(src.css + '/*.sass')
.pipe sourcemaps.init()
.pipe compass(
css : build.css
sass : src.css
)
.pipe sourcemaps.write('./')
.pipe gulp.dest(build.css)
gulp.task 'html', ->
if env.isProduct
opt = pretty : false
else
opt = pretty : true
gulp.src(src.html + '/*.jade')
.pipe data (file) ->
return require src.html + '/index.json'
.pipe(jade(opt))
.pipe gulp.dest(build.html)
.on 'error', (e) ->
util.beep();
console.log e
return
gulp.task 'js', ->
if env.isProduct
browserify
entries : [src.js + '/index.coffee']
extensions : ['.coffee', '.js']
.plugin licensify
.transform 'coffeeify'
.transform 'debowerify'
.bundle()
.pipe source('bundle.min.js')
.pipe buffer()
.pipe streamify uglify()
.pipe gulp.dest(build.js)
else
browserify
entries : [src.js + '/index.coffee']
extensions : ['.coffee', '.js']
.plugin licensify
.transform 'coffeeify'
.transform 'debowerify'
.bundle()
.pipe source('bundle.min.js')
.pipe buffer()
.pipe sourcemaps.init
loadMaps : true
.pipe streamify uglify()
.pipe sourcemaps.write('./')
.pipe gulp.dest(build.js)
gulp.task 'pngmin', ->
gulp.src([
src.image + '/*.png'
src.image + '/**/*.png'
])
.pipe newer build.image
.pipe pngmin()
.pipe gulp.dest build.image
gulp.task 'jpgmin', ->
gulp.src([
src.image + '/*.jpg'
src.image + '/**/*.jpg'
])
.pipe imagemin(
prpgressive : true
svgoPlugins : [{removeViewBox : false}]
use : [jpegtran()]
)
.pipe gulp.dest build.image
gulp.task 'copy-dir', ->
gulp.src([
src.copy + "/*"
src.copy + "/**/*"
src.copy + "/**/**/*"
])
.pipe(gulp.dest(build.html))
gulp.task 'copy-img', ->
gulp.src([
src.image + '/*.gif'
src.image + '/**/*.gif'
src.image + '/**/**/*.gif'
])
.pipe(gulp.dest(build.image))
gulp.task 'img', [
'pngmin'
'jpgmin'
'copy-img'
]
gulp.task 'browser', ->
browserSync server :
baseDir : 'build'
directory : true
return
gulp.task 'clean', (cb) ->
del([
'deploy/'
], cb)
gulp.task 'watch', ->
gulp.watch([
src.js + '/*.coffee'
src.js + '/**/*.coffee'
], [
'js'
reload
])
gulp.watch([
src.html + '/*.jade'
src.html + '/**/*.jade'
], [
'html'
reload
])
gulp.watch([
src.css + '/*.sass'
src.css + '/**/*.sass'
], [
'css'
reload
])
gulp.watch([
src.image + '/*'
src.image + '/**/*'
], [
'img'
reload
])
return
gulp.task 'default', [
'css'
'js'
'html'
'img'
'copy-dir'
]
gulp.task 'server', [
'default'
'browser'
'watch'
]
gulp.task 'build', [
'clean'
'changeEnv'
], ->
gulp.run 'default'
gulp.task 'staging', [
'deploy'
]
gulp.task 'production', [
'changeDeployEnv'
'deploy'
]