Refactoring

* Removed needless dependencies
* All functionality should be like earlier
This commit is contained in:
Riku Rouvila
2015-05-20 23:13:01 +03:00
parent 71af2bbb28
commit 6eaa314e82
2 changed files with 39 additions and 58 deletions

View File

@@ -1,16 +1,13 @@
browserify = require 'browserify'
browserSync = require 'browser-sync'
chalk = require 'chalk'
CSSmin = require 'gulp-minify-css'
duration = require 'gulp-duration'
ecstatic = require 'ecstatic'
filter = require 'gulp-filter'
gulp = require 'gulp'
gutil = require 'gulp-util'
jade = require 'gulp-jade'
notify = require 'gulp-notify'
path = require 'path'
prefix = require 'gulp-autoprefixer'
prettyTime = require 'pretty-hrtime'
source = require 'vinyl-source-stream'
sourcemaps = require 'gulp-sourcemaps'
streamify = require 'gulp-streamify'
@@ -18,7 +15,7 @@ stylus = require 'gulp-stylus'
uglify = require 'gulp-uglify'
watchify = require 'watchify'
production = process.env.NODE_ENV is 'production'
production = process.env.NODE_ENV is 'production'
config =
scripts:
@@ -39,60 +36,57 @@ config =
watch: './src/assets/**/*.*'
destination: './public/'
browserifyConfig =
entries: [config.scripts.source]
extensions: config.scripts.extensions
debug: not production
cache: {}
packageCache: {}
handleError = (err) ->
gutil.log err
gutil.beep()
notify
.onError title: 'Compile Error', message: '<%= error.message %>'
.apply this, Array::slice.call(arguments)
title: 'Compile Error'
message: err.message
this.emit 'end'
gulp.task 'scripts', ->
bundle = browserify
entries: [config.scripts.source]
extensions: config.scripts.extensions
debug: not production
build = bundle.bundle()
pipeline = browserify(browserifyConfig)
.bundle()
.on 'error', handleError
.pipe source config.scripts.filename
build.pipe(streamify(uglify())) if production
pipeline = build.pipe(streamify(uglify())) if production
build
.pipe gulp.dest config.scripts.destination
pipeline.pipe gulp.dest config.scripts.destination
gulp.task 'templates', ->
pipeline = gulp
.src config.templates.source
.pipe(jade(pretty: not production))
.pipe jade pretty: not production
.on 'error', handleError
.pipe gulp.dest config.templates.destination
pipeline = pipeline.pipe browserSync.reload(stream: true) unless production
pipeline
if production then pipeline else pipeline.pipe browserSync.reload(stream: true)
gulp.task 'styles', ->
styles = gulp.src config.styles.source
styles = styles.pipe(sourcemaps.init()) unless production
styles = styles.pipe stylus
'include css': true
pipeline = gulp.src config.styles.source
.on 'error', handleError
.pipe prefix 'last 2 versions', 'Chrome 34', 'Firefox 28', 'iOS 7'
pipeline = pipeline.pipe(sourcemaps.init()) unless production
styles = styles.pipe(CSSmin()) if production
styles = styles.pipe(sourcemaps.write '.') unless production
styles = styles.pipe gulp.dest config.styles.destination
pipeline = pipeline.pipe stylus
'include css': true
compress: production
.on 'error', handleError
.pipe prefix 'last 2 versions', 'Chrome 34', 'Firefox 28', 'iOS 7'
unless production
styles = styles
.pipe filter '**/*.css'
.pipe browserSync.reload(stream: true)
pipeline = pipeline.pipe(sourcemaps.write '.') unless production
pipeline = pipeline.pipe gulp.dest config.styles.destination
styles
if production then pipeline else pipeline.pipe browserSync.stream match: '**/*.css'
gulp.task 'assets', ->
gulp
@@ -111,31 +105,21 @@ gulp.task 'watch', ->
gulp.watch config.styles.watch, ['styles']
gulp.watch config.assets.watch, ['assets']
bundle = watchify browserify
entries: [config.scripts.source]
extensions: config.scripts.extensions
debug: not production
cache: {}
packageCache: {}
fullPaths: true
bundle = watchify browserify browserifyConfig
bundle.on 'update', ->
gutil.log "Starting '#{chalk.cyan 'rebundle'}'..."
start = process.hrtime()
build = bundle.bundle()
.on 'error', handleError
.pipe source config.scripts.filename
build
.pipe gulp.dest config.scripts.destination
.pipe(duration('Rebundling browserify bundle'))
.pipe(browserSync.reload(stream: true))
gutil.log "Finished '#{chalk.cyan 'rebundle'}' after #{chalk.magenta prettyTime process.hrtime start}"
.emit 'update'
gulp.task 'no-js', ['templates', 'styles', 'assets']
gulp.task 'build', ['scripts', 'no-js']
# scripts and watch conflict and will produce invalid js upon first run
# which is why the no-js task exists.
gulp.task 'default', ['watch', 'no-js', 'server']
buildTasks = ['templates', 'styles', 'assets']
gulp.task 'build', buildTasks.concat ['scripts']
gulp.task 'default', buildTasks.concat ['watch', 'server']