Skip to content
Permalink
Browse files

perf(lib): boost performance by minifying the published javascript fi…

…les in the lib directory
  • Loading branch information
jyounce committed Apr 1, 2016
1 parent 7f7fd95 commit 9b2a6a05147911fafbe9d0cb2cefaa5a54a03356
Showing with 57 additions and 29 deletions.
  1. +57 −29 scripts/create-lib/create-lib.coffee
@@ -3,46 +3,74 @@
module.exports = (rbRoot) ->
gulp = require 'gulp'
coffee = require 'gulp-coffee'
minifyJs = require 'gulp-uglify'
async = require 'asyncawait/async'
await = require 'asyncawait/await'
Promise = require 'bluebird'
fse = Promise.promisifyAll require 'fs-extra'

SRC = "#{rbRoot}/src"
LIB = "#{rbRoot}/lib" # lib is created from src
LIB_GLOB = "#{LIB}/**/*.coffee"
SRC = "#{rbRoot}/src"
LIB = "#{rbRoot}/lib" # lib is created from src
glob =
lib:
js: "#{LIB}/**/*.js"
coffee: "#{LIB}/**/*.coffee"

# tasks
# =====
cleanLib = ->
fse.removeAsync LIB

copySrc = ->
fse.copyAsync SRC, LIB

compileLibCoffee = ->
src = LIB_GLOB
dest = LIB
opts = bare: true
new Promise (resolve, reject) ->
gulp.src src
.pipe coffee opts
.on 'error', (e) ->
e.message += "\nFile: #{e.filename}"
reject e
.pipe gulp.dest dest
.on 'end', -> resolve()

cleanLibCoffeeFiles = ->
fse.removeAsync LIB_GLOB
tasks =
cleanLib: ->
fse.removeAsync(LIB).then ->
console.log 'lib cleaned'.info

copySrc: ->
fse.copyAsync(SRC, LIB).then ->
console.log 'copied src to lib'.info

compileLibCoffee: ->
src = glob.lib.coffee
dest = LIB
opts = bare: true
promise = new Promise (resolve, reject) ->
gulp.src src
.pipe coffee opts
.on 'error', (e) ->
e.message += "\nFile: #{e.filename}"
reject e
.pipe gulp.dest dest
.on 'end', ->
resolve()
promise.then ->
console.log 'compiled lib coffee files'.info

cleanLibCoffeeFiles: ->
fse.removeAsync(glob.lib.coffee).then ->
console.log 'cleaned lib coffee files'.info

minifyJs: ->
src = glob.lib.js
dest = LIB
opts = mangle: true
promise = new Promise (resolve, reject) ->
gulp.src src
.pipe minifyJs opts
.on 'error', (e) ->
e.message += "\nFile: #{e.filename}"
reject e
.pipe gulp.dest dest
.on 'end', ->
resolve()
promise.then ->
console.log 'minified lib js files'.info

# run tasks (in order)
# =========
# ====================
runTasks = async ->
await cleanLib().then -> console.log 'lib cleaned'.info
await copySrc().then -> console.log 'copied src to lib'.info
await compileLibCoffee().then -> console.log 'compiled lib coffee files'.info
await cleanLibCoffeeFiles().then -> console.log 'cleaned lib coffee files'.info
await tasks.cleanLib()
await tasks.copySrc()
await tasks.compileLibCoffee()
await tasks.cleanLibCoffeeFiles()
await tasks.minifyJs()

# run it!
# =======

0 comments on commit 9b2a6a0

Please sign in to comment.
You can’t perform that action at this time.