Skip to content
Browse files

Fix a couple bugs

  • Loading branch information...
1 parent db4721e commit 7e64d61747f622793fe8e224314cc7b55466d4b9 @tim-smart committed
Showing with 88 additions and 91 deletions.
  1. +47 −49 lib/node-asset/index.js
  2. +41 −42 src/index.coffee
View
96 lib/node-asset/index.js
@@ -1,4 +1,4 @@
-var Asset, Buffer, Gzip, Package, Parallel, compiler, compressGzip, fs, log, makePackage, path, resolveContents, sys, watch, yui_compile;
+var Asset, Buffer, Gzip, Package, Parallel, compiler, compressGzip, fs, log, path, resolveContents, sys, watch, yui_compile;
var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
return function() {
return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);
@@ -40,71 +40,69 @@ Package.prototype.serve = function() {
}, this));
this.contents = contents;
this.dirs = dirs;
- makePackage(this);
+ this.make();
if (this.watch === true) {
return watch(this);
}
}, this));
};
-
-exports.Package = Package;
-makePackage = function(package) {
+Package.prototype.make = function() {
var compile, compress, read_task, result, write;
- if (package.contents.length <= 0) {
- return null;
- }
read_task = new Parallel();
- package.contents.forEach(function(asset) {
+ this.contents.forEach(function(asset) {
return read_task.add(asset.path, [fs.readFile, asset.path]);
});
- package.type === 'js' || package.type === 'coffee' ? (compile = function(data) {
- return compiler(data, function(data) {
- if (package.compress) {
- return compress(data);
- } else {
- return write(data);
- }
- });
- }) : null;
- package.type === 'css' ? (compile = function(data) {
- return yui_compile(data, {
- type: 'css'
- }, function(data) {
- if (package.compress) {
- return compress(data);
- } else {
- return write(data);
- }
- });
- }) : null;
+ this.type === 'js' || this.type === 'coffee' ? (compile = __bind(function(data) {
+ return compiler(data, __bind(function(data) {
+ if (this.compress) {
+ return compress(data);
+ } else {
+ return write(data);
+ }
+ }, this));
+ }, this)) : null;
+ this.type === 'css' ? (compile = __bind(function(data) {
+ return yui_compile(data, {
+ type: 'css'
+ }, __bind(function(data) {
+ if (this.compress) {
+ return compress(data);
+ } else {
+ return write(data);
+ }
+ }, this));
+ }, this)) : null;
compress = function(data) {
+ data.length <= 0 ? (data = ' ') : null;
return compressGzip(data, function(data) {
return write(data);
});
};
- write = function(data) {
- return fs.writeFile(package.filename, data, 'binary', function() {
- return log(("Successfuly made a " + package.type + " package"));
- });
- };
+ write = __bind(function(data) {
+ return fs.writeFile(this.filename, data, 'binary', __bind(function() {
+ return log(("Successfuly made a " + this.type + " package"));
+ }, this));
+ }, this);
result = '';
- return read_task.run(function(filename, err, data) {
- if (filename === null) {
- package.type === 'coffee' ? (result = require('coffee-script').compile(result, {
- no_wrap: true
- })) : null;
- if (package.compile) {
- return compile(result);
- } else if (package.compress) {
- return compress(result);
+ return read_task.run(__bind(function(filename, err, data) {
+ if (filename === null) {
+ this.type === 'coffee' ? (result = require('coffee-script').compile(result, {
+ no_wrap: true
+ })) : null;
+ if (this.compile) {
+ return compile(result);
+ } else if (this.compress) {
+ return compress(result);
+ } else {
+ return write(result);
+ }
} else {
- return write(result);
+ return result += data.toString() + "\n";
}
- } else {
- return result += data.toString() + "\n";
- }
- });
+ }, this));
};
+
+exports.Package = Package;
Asset = function(pathname, dir) {
if (dir === true) {
this.dir = true;
@@ -185,7 +183,7 @@ watch = function(package) {
return package.contents.forEach(function(asset) {
return fs.watchFile(asset.path, function(stat, prev) {
log(("Updating a " + package.type + " package"));
- return makePackage(package);
+ return package.make();
});
});
};
View
83 src/index.coffee
@@ -43,52 +43,51 @@ class Package
@contents: contents
@dirs: dirs
- makePackage @
+ @make()
if @watch is true
watch @
-exports.Package: Package
-
-makePackage: (package) ->
- if package.contents.length <= 0 then return
+ make: ->
+ read_task: new Parallel()
+ @contents.forEach (asset) ->
+ read_task.add asset.path, [fs.readFile, asset.path]
+
+ if @type is 'js' or @type is 'coffee'
+ compile: (data) =>
+ compiler data, (data) =>
+ if @compress then compress data
+ else write data
+
+ if @type is 'css'
+ compile: (data) =>
+ yui_compile data, { type: 'css' }, (data) =>
+ if @compress then compress data
+ else write data
+
+ compress: (data) ->
+ if data.length <= 0 then data: ' '
+ compressGzip data, (data) ->
+ write data
+ write: (data) =>
+ fs.writeFile @filename, data, 'binary', =>
+ log "Successfuly made a $@type package"
+
+ result: ''
+ read_task.run (filename, err, data) =>
+ if filename is null
+ if @type is 'coffee'
+ result: require('coffee-script').compile result, {
+ no_wrap: true
+ }
+
+ if @compile then compile result
+ else if @compress then compress result
+ else write result
+ else
+ result: + data.toString() + "\n"
- read_task: new Parallel()
- package.contents.forEach (asset) ->
- read_task.add asset.path, [fs.readFile, asset.path]
-
- if package.type is 'js' or package.type is 'coffee'
- compile: (data) ->
- compiler data, (data) ->
- if package.compress then compress data
- else write data
-
- if package.type is 'css'
- compile: (data) ->
- yui_compile data, { type: 'css' }, (data) ->
- if package.compress then compress data
- else write data
-
- compress: (data) ->
- compressGzip data, (data) ->
- write data
- write: (data) ->
- fs.writeFile package.filename, data, 'binary', ->
- log "Successfuly made a $package.type package"
-
- result: ''
- read_task.run (filename, err, data) ->
- if filename is null
- if package.type is 'coffee'
- result: require('coffee-script').compile result, {
- no_wrap: true
- }
-
- if package.compile then compile result
- else if package.compress then compress result
- else write result
- else
- result: + data.toString() + "\n"
+exports.Package: Package
class Asset
constructor: (pathname, dir) ->
@@ -150,4 +149,4 @@ watch: (package) ->
package.contents.forEach (asset) ->
fs.watchFile asset.path, (stat, prev) ->
log "Updating a $package.type package"
- makePackage package
+ package.make()

0 comments on commit 7e64d61

Please sign in to comment.
Something went wrong with that request. Please try again.