Skip to content

Add UMD support #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
fs = require 'fs'
{exec} = require 'child_process'
util = require 'util'
umdify = require 'libumd'

binDir = "./node_modules/.bin/"

Expand All @@ -15,7 +16,7 @@ task 'watch', 'Watch for changes in coffee files to build and test', ->
watchDir 'test', ->
invoke 'build:test'
watchDir 'dist/test', (file)->
# We only want to run tests once (a second),
# We only want to run tests once (a second),
# even if a bunch of test files change
time = new Date().getTime()
if (time-lastTest) > 1000
Expand All @@ -24,7 +25,7 @@ task 'watch', 'Watch for changes in coffee files to build and test', ->

task 'test', 'Run the tests', ->
util.log "Running tests..."
exec binDir + "jasmine-node --nocolor dist/test", (err, stdout, stderr) ->
exec binDir + "jasmine-node --nocolor dist/test", (err, stdout, stderr) ->
if err
handleError(parseTestResults(stdout), stderr)
else
Expand All @@ -38,22 +39,37 @@ task 'build', 'Build source and tests', ->

task 'build:src', 'Build the src files into lib', ->
util.log "Compiling src..."
exec binDir + "coffee -o lib/ -c src/", (err, stdout, stderr) ->
invoke 'build:node'
invoke 'build:umd'

task 'build:node', 'Build node version of the lib', ->
util.log "Compiling node version..."
exec binDir + "coffee -j lib/stomp-node.js -c src/stomp-node.coffee", (err, stdout, stderr) ->
handleError(err) if err

task 'build:umd', 'Build UMD version of the lib', ->
util.log "Compiling UMD version..."
exec binDir + "coffee -b -j lib/stomp.js -c src/stomp.coffee", (err, stdout, stderr) ->
handleError(err) if err
fs.readFile "lib/stomp.js", (err, data) ->
handleError(err) if err
result = umdify String(data), { globalAlias: 'Stomp' }
fs.writeFile "lib/stomp.js", result, (err) ->
handleError(err) if err

task 'build:min', 'Build the minified files into lib', ->
util.log "Minify src..."
exec binDir + "uglifyjs -m --comments all -o lib/stomp.min.js lib/stomp.js", (err, stdout, stderr) ->
handleError(err) if err

task 'build:doc', 'Build docco documentation', ->
util.log "Building doc..."
exec binDir + "docco -o doc/ src/*.coffee", (err, stdout, stderr) ->
exec binDir + "docco -o doc/ src/*.coffee", (err, stdout, stderr) ->
handleError(err) if err

task 'build:test', 'Build the test files into lib/test', ->
util.log "Compiling test..."
exec binDir + "coffee -o dist/test/ -c test/", (err, stdout, stderr) ->
exec binDir + "coffee -o dist/test/ -c test/", (err, stdout, stderr) ->
handleError(err) if err

watchDir = (dir, callback) ->
Expand All @@ -73,14 +89,14 @@ parseTestResults = (data) ->
lastLine = (data) ->
(line for line in data.split('\n') when line.length > 5).pop()

handleError = (error, stderr) ->
handleError = (error, stderr) ->
if stderr? and !error
util.log stderr
displayNotification stderr.match(/\n(Error:[^\n]+)/)?[1]
else
util.log error
displayNotification error
displayNotification = (message = '') ->

displayNotification = (message = '') ->
options = { title: 'CoffeeScript' }
try require('growl').notify message, options
10 changes: 5 additions & 5 deletions lib/stomp-node.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading