Permalink
Browse files

Minor cleanup to embrace coffeescript more

  • Loading branch information...
1 parent 374f090 commit 443ed78c45c3143eae887e982bee9cadd1c17e0e @mwawrusch mwawrusch committed Nov 7, 2011
Showing with 78 additions and 67 deletions.
  1. BIN .DS_Store
  2. +1 −0 .gitignore
  3. +1 −2 .npmignore
  4. +14 −3 README.md
  5. +3 −2 package.json
  6. +59 −60 src/index.coffee
View
Binary file not shown.
View
@@ -2,3 +2,4 @@ node_modules
config.json
tmp
.DS_Store
+*.log
View
@@ -1,6 +1,5 @@
support
-assets
-assets_source
tmp
.DS_Store
config.json
+*.log
View
@@ -67,16 +67,27 @@ The package config contains experimental hook.io schema definitions. The definit
## Advertising :)
-Check out http://freshfugu.com and http://scottyapp.com
+Check out
-Follow us on Twitter at @getscottyapp and @freshfugu and like us on Facebook please. Every mention is welcome and we follow back.
+* http://scottyapp.com
+
+Follow us on Twitter at
+
+* @getscottyapp
+* @martin_sunset
+
+and like us on Facebook please. Every mention is welcome and we follow back.
## Trivia
Listened to lots of M.I.A. and Soundgarden while writing this.
## Release Notes
+### 0.0.2
+
+* Minor cleanups, including coffee-script beautification
+
### 0.0.1
* First version
@@ -88,7 +99,7 @@ Listened to lots of M.I.A. and Soundgarden while writing this.
# Publish new version
* Change version in package.json
-* git tag -a v0.0.1 -m 'version 0.0.1'
+* git tag -a v0.0.2 -m 'version 0.0.2'
* git push --tags
* npm publish
View
@@ -19,7 +19,7 @@
"hook.io","compress","uncompress","gzbz2","node-gzbz2","gzip","bzip2"
],
"scripts": {
- "test": "vows --spec spec/*-spec.coffee",
+ "test": "node_modules/.bin/vows --spec spec/*-spec.coffee",
"watch" : "coffee -c -w -o lib src"
},
"engines": {
@@ -33,7 +33,8 @@
"devDependencies": {
"underscore" : "1.2.x",
"async" : "0.1.x",
- "should" : ">=0.2.1",
+ "should" : ">=0.2.1",
+ "coffee-script" : ">= 1.1.2",
"vows" : ">= 0.5.9"
},
"bugs": { "url": "http://github.com/scottyapp/hook.io-gzbz2/issues" },
View
@@ -7,83 +7,82 @@ spawn = require("child_process").spawn
require('pkginfo')(module,'version','hook')
-Gzbz2 = exports.Gzbz2 = (options) ->
- self = @
- Hook.call self, options
+class exports.Gzbz2 extends Hook
+ constructor: (options) ->
+ self = @
+ Hook.call self, options
- self.on "hook::ready", ->
+ self.on "hook::ready", ->
- self.on "gzbz2::compress", (data)->
- self._compress(data)
+ self.on "gzbz2::compress", (data)->
+ self._compress(data)
- self.on "gzbz2::uncompress", (data)->
- self._uncompress(data)
+ self.on "gzbz2::uncompress", (data)->
+ self._uncompress(data)
- for compress in (self.compresss || [])
- self.emit "gzbz2::compress",
- source : compress.source
- target : compress.target
- mode : compress.mode
+ for compress in (self.compresss || [])
+ self.emit "gzbz2::compress",
+ source : compress.source
+ target : compress.target
+ mode : compress.mode
- for uncompress in (self.uncompresss || [])
- self.emit "gzbz2::uncompress",
- source : uncompress.source
- target : uncompress.target
+ for uncompress in (self.uncompresss || [])
+ self.emit "gzbz2::uncompress",
+ source : uncompress.source
+ target : uncompress.target
-util.inherits Gzbz2, Hook
+ _runCommand : (cmd,args,eventName,data) =>
+ fd = fs.openSync data.target, "w", 0644
-Gzbz2.prototype._runCommand = (cmd,args,eventName,data) ->
- fd = fs.openSync data.target, "w", 0644
+ zip = spawn(cmd,args)
- zip = spawn(cmd,args)
+ zip.stdout.on "data", (data) =>
+ fs.writeSync fd, data, 0, data.length, null
- zip.stdout.on "data", (data) =>
- fs.writeSync fd, data, 0, data.length, null
-
- zip.stderr.on "data", (data) =>
- console.log "ERROR: #{data}"
+ zip.stderr.on "data", (data) =>
+ console.log "ERROR: #{data}"
- zip.on "exit", (code) =>
- fs.closeSync fd
+ zip.on "exit", (code) =>
+ fs.closeSync fd
- #console.log "EXIT #{code}"
- if code != 0
- try
- fs.unlinkSync data.target # cleanup
- catch ignore
+ #console.log "EXIT #{code}"
+ if code != 0
+ try
+ fs.unlinkSync data.target # cleanup
+ catch ignore
- @emit "gzbz2::error",
- source: data.source
- target: data.target
- mode: data.mode
- code: code
- else
- @emit eventName,
- source: data.source
- target: data.target
- mode: data.mode
+ @emit "gzbz2::error",
+ source: data.source
+ target: data.target
+ mode: data.mode
+ code: code
+ else
+ @emit eventName,
+ source: data.source
+ target: data.target
+ mode: data.mode
-Gzbz2.prototype._compress = (data) ->
- console.log "Compressing #{data.source} to #{data.target}".cyan
+ _compress : (data) =>
+ console.log "Compressing #{data.source} to #{data.target}".cyan
- data.mode = 'gzip' unless data.mode == 'bzip2'
+ data.mode = 'gzip' unless data.mode == 'bzip2'
- data.target = path.normalize data.target
- if data.mode == 'gzip'
- @_runCommand "gzip",[ "-c", data.source ],"gzbz2::compress-complete",data
- else
- @_runCommand "bzip2",[ "-c", data.source ],"gzbz2::compress-complete",data
+ data.target = path.normalize data.target
+ if data.mode == 'gzip'
+ @_runCommand "gzip",[ "-c", data.source ],"gzbz2::compress-complete",data
+ else
+ @_runCommand "bzip2",[ "-c", data.source ],"gzbz2::compress-complete",data
-Gzbz2.prototype._uncompress = (data) ->
- console.log "Uncompress for #{data.source}".cyan
-
- data.mode = 'gzip' unless data.mode == 'bzip2'
+ _uncompress : (data) =>
+ console.log "Uncompress for #{data.source}".cyan
- data.target = path.normalize data.target
+ data.mode = 'gzip' unless data.mode == 'bzip2'
- if data.mode == 'gzip'
- @_runCommand "gunzip",[ "-c", data.source ],"gzbz2::uncompress-complete",data
- else
- @_runCommand "bzip2",[ "-dc", data.source ],"gzbz2::uncompress-complete",data
+ data.target = path.normalize data.target
+ if data.mode == 'gzip'
+ @_runCommand "gunzip",[ "-c", data.source ],"gzbz2::uncompress-complete",data
+ else
+ @_runCommand "bzip2",[ "-dc", data.source ],"gzbz2::uncompress-complete",data
+

0 comments on commit 443ed78

Please sign in to comment.