Skip to content
Browse files

Merge pull request #21 from stefankutko/master

Compiling snockets.js from updated source .coffee and bumping version
  • Loading branch information...
2 parents eeed703 + 03c9af9 commit 87a9afc05ab16eb43b1cde5b72f277f04381b754 @TrevorBurnham committed May 28, 2012
Showing with 124 additions and 63 deletions.
  1. +123 −62 lib/snockets.js
  2. +1 −1 package.json
View
185 lib/snockets.js
@@ -1,6 +1,8 @@
+// Generated by CoffeeScript 1.3.3
(function() {
- var CoffeeScript, DIRECTIVE, DepGraph, EXPLICIT_PATH, HEADER, HoldingQueue, Snockets, compilers, fs, jsExts, minify, parseDirectives, path, stripExt, timeEq, uglify, _;
- var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (__hasProp.call(this, i) && this[i] === item) return i; } return -1; };
+ var CoffeeScript, DIRECTIVE, DepGraph, EXPLICIT_PATH, HEADER, HoldingQueue, Snockets, compilers, fs, jsExts, minify, parseDirectives, path, stripExt, timeEq, uglify, _,
+ __slice = [].slice,
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
DepGraph = require('dep-graph');
@@ -17,24 +19,32 @@
module.exports = Snockets = (function() {
function Snockets(options) {
- var _base, _base2, _ref, _ref2;
+ var _base, _base1, _ref, _ref1;
this.options = options != null ? options : {};
- if ((_ref = (_base = this.options).src) == null) _base.src = '.';
- if ((_ref2 = (_base2 = this.options).async) == null) _base2.async = true;
+ if ((_ref = (_base = this.options).src) == null) {
+ _base.src = '.';
+ }
+ if ((_ref1 = (_base1 = this.options).async) == null) {
+ _base1.async = true;
+ }
this.cache = {};
this.concatCache = {};
this.depGraph = new DepGraph;
}
Snockets.prototype.scan = function(filePath, flags, callback) {
- var _ref;
- var _this = this;
+ var _ref,
+ _this = this;
if (typeof flags === 'function') {
callback = flags;
flags = {};
}
- if (flags == null) flags = {};
- if ((_ref = flags.async) == null) flags.async = this.options.async;
+ if (flags == null) {
+ flags = {};
+ }
+ if ((_ref = flags.async) == null) {
+ flags.async = this.options.async;
+ }
return this.updateDirectives(filePath, flags, function(err, graphChanged) {
if (err) {
if (callback) {
@@ -51,14 +61,18 @@
};
Snockets.prototype.getCompiledChain = function(filePath, flags, callback) {
- var _ref;
- var _this = this;
+ var _ref,
+ _this = this;
if (typeof flags === 'function') {
callback = flags;
flags = {};
}
- if (flags == null) flags = {};
- if ((_ref = flags.async) == null) flags.async = this.options.async;
+ if (flags == null) {
+ flags = {};
+ }
+ if ((_ref = flags.async) == null) {
+ flags.async = this.options.async;
+ }
return this.updateDirectives(filePath, flags, function(err, graphChanged) {
var chain, compiledChain, link, o;
if (err) {
@@ -78,11 +92,11 @@
}
}
compiledChain = (function() {
- var _i, _len, _ref2, _results;
- _ref2 = chain.concat(filePath);
+ var _i, _len, _ref1, _results;
+ _ref1 = chain.concat(filePath);
_results = [];
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
- link = _ref2[_i];
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+ link = _ref1[_i];
o = {};
if (this.compileFile(link)) {
o.filename = stripExt(link) + '.js';
@@ -102,17 +116,21 @@
};
Snockets.prototype.getConcatenation = function(filePath, flags, callback) {
- var concatenationChanged, _ref;
- var _this = this;
+ var concatenationChanged, _ref,
+ _this = this;
if (typeof flags === 'function') {
callback = flags;
flags = {};
}
- if (flags == null) flags = {};
- if ((_ref = flags.async) == null) flags.async = this.options.async;
+ if (flags == null) {
+ flags = {};
+ }
+ if ((_ref = flags.async) == null) {
+ flags.async = this.options.async;
+ }
concatenationChanged = true;
return this.updateDirectives(filePath, flags, function(err, graphChanged) {
- var chain, concatenation, link, result, _ref2, _ref3;
+ var chain, concatenation, link, result, _ref1, _ref2;
if (err) {
if (callback) {
return callback(err);
@@ -121,17 +139,19 @@
}
}
try {
- if ((_ref2 = _this.concatCache[filePath]) != null ? _ref2.data : void 0) {
+ if ((_ref1 = _this.concatCache[filePath]) != null ? _ref1.data : void 0) {
concatenation = _this.concatCache[filePath].data.toString('utf8');
- if (!flags.minify) concatenationChanged = false;
+ if (!flags.minify) {
+ concatenationChanged = false;
+ }
} else {
chain = _this.depGraph.getChain(filePath);
concatenation = ((function() {
- var _i, _len, _ref3, _results;
- _ref3 = chain.concat(filePath);
+ var _i, _len, _ref2, _results;
+ _ref2 = chain.concat(filePath);
_results = [];
- for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
- link = _ref3[_i];
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ link = _ref2[_i];
this.compileFile(link);
_results.push(this.cache[link].js.toString('utf8'));
}
@@ -149,7 +169,7 @@
}
}
if (flags.minify) {
- if ((_ref3 = _this.concatCache[filePath]) != null ? _ref3.minifiedData : void 0) {
+ if ((_ref2 = _this.concatCache[filePath]) != null ? _ref2.minifiedData : void 0) {
result = _this.concatCache[filePath].minifiedData.toString('utf8');
concatenationChanged = false;
} else {
@@ -167,10 +187,12 @@
};
Snockets.prototype.updateDirectives = function() {
- var callback, depList, excludes, filePath, flags, graphChanged, q, require, requireTree, _i;
- var _this = this;
+ var callback, depList, excludes, filePath, flags, graphChanged, q, require, requireTree, _i,
+ _this = this;
filePath = arguments[0], flags = arguments[1], excludes = 4 <= arguments.length ? __slice.call(arguments, 2, _i = arguments.length - 1) : (_i = 2, []), callback = arguments[_i++];
- if (__indexOf.call(excludes, filePath) >= 0) return callback();
+ if (__indexOf.call(excludes, filePath) >= 0) {
+ return callback();
+ }
excludes.push(filePath);
depList = [];
graphChanged = false;
@@ -184,9 +206,13 @@
err = new Error("Script tries to require itself: " + filePath);
return callback(err);
}
- if (__indexOf.call(depList, depPath) < 0) depList.push(depPath);
+ if (__indexOf.call(depList, depPath) < 0) {
+ depList.push(depPath);
+ }
return _this.updateDirectives.apply(_this, [depPath, flags].concat(__slice.call(excludes), [function(err) {
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
return next();
}]));
},
@@ -195,7 +221,9 @@
_this.depGraph.map[filePath] = depList;
graphChanged = true;
}
- if (graphChanged) _this.concatCache[filePath] = null;
+ if (graphChanged) {
+ _this.concatCache[filePath] = null;
+ }
return callback(null, graphChanged);
}
});
@@ -206,9 +234,11 @@
depPath = relName + '.js';
return q.perform(relName, depPath);
} else {
- depName = path.join(path.dirname(filePath), relName);
+ depName = _this.joinPath(path.dirname(filePath), relName);
return _this.findMatchingFile(depName, flags, function(err, depPath) {
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
return q.perform(relName, depPath);
});
}
@@ -217,17 +247,23 @@
q.waitFor(dirName);
return _this.readdir(_this.absPath(dirName), flags, function(err, items) {
var item, itemPath, _j, _len, _results;
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
q.unwaitFor(dirName);
_results = [];
for (_j = 0, _len = items.length; _j < _len; _j++) {
item = items[_j];
- itemPath = path.join(dirName, item);
- if (_this.absPath(itemPath) === _this.absPath(filePath)) continue;
+ itemPath = _this.joinPath(dirName, item);
+ if (_this.absPath(itemPath) === _this.absPath(filePath)) {
+ continue;
+ }
q.waitFor(itemPath);
_results.push((function(itemPath) {
return _this.stat(_this.absPath(itemPath), flags, function(err, stats) {
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
if (stats.isFile()) {
return q.perform(itemPath, itemPath);
} else {
@@ -241,25 +277,29 @@
});
};
return this.readFile(filePath, flags, function(err, fileChanged) {
- var command, directive, relPath, relPaths, words, _j, _k, _l, _len, _len2, _len3, _ref;
- if (err) return callback(err);
- if (fileChanged) graphChanged = true;
+ var command, directive, relPath, relPaths, words, _j, _k, _l, _len, _len1, _len2, _ref;
+ if (err) {
+ return callback(err);
+ }
+ if (fileChanged) {
+ graphChanged = true;
+ }
_ref = parseDirectives(_this.cache[filePath].data.toString('utf8'));
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
directive = _ref[_j];
words = directive.replace(/['"]/g, '').split(/\s+/);
command = words[0], relPaths = 2 <= words.length ? __slice.call(words, 1) : [];
switch (command) {
case 'require':
- for (_k = 0, _len2 = relPaths.length; _k < _len2; _k++) {
+ for (_k = 0, _len1 = relPaths.length; _k < _len1; _k++) {
relPath = relPaths[_k];
require(relPath);
}
break;
case 'require_tree':
- for (_l = 0, _len3 = relPaths.length; _l < _len3; _l++) {
+ for (_l = 0, _len2 = relPaths.length; _l < _len2; _l++) {
relPath = relPaths[_l];
- requireTree(path.join(path.dirname(filePath), relPath));
+ requireTree(_this.joinPath(path.dirname(filePath), relPath));
}
}
}
@@ -268,8 +308,8 @@
};
Snockets.prototype.findMatchingFile = function(filename, flags, callback) {
- var tryFiles;
- var _this = this;
+ var tryFiles,
+ _this = this;
tryFiles = function(filePaths) {
var filePath, _i, _len;
for (_i = 0, _len = filePaths.length; _i < _len; _i++) {
@@ -280,19 +320,23 @@
}
}
};
- if (tryFiles(_.keys(this.cache))) return;
+ if (tryFiles(_.keys(this.cache))) {
+ return;
+ }
return this.readdir(path.dirname(this.absPath(filename)), flags, function(err, files) {
var file;
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
if (tryFiles((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
- _results.push(path.join(path.dirname(filename), file));
+ _results.push(this.joinPath(path.dirname(filename), file));
}
return _results;
- })())) {
+ }).call(_this))) {
return;
}
return callback(new Error("File not found: '" + filename + "'"));
@@ -331,13 +375,17 @@
var _this = this;
return this.stat(filePath, flags, function(err, stats) {
var data, _ref;
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
if (timeEq((_ref = _this.cache[filePath]) != null ? _ref.mtime : void 0, stats.mtime)) {
return callback(null, false);
}
if (flags.async) {
return fs.readFile(_this.absPath(filePath), function(err, data) {
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
_this.cache[filePath] = {
mtime: stats.mtime,
data: data
@@ -376,9 +424,20 @@
if (relPath.match(EXPLICIT_PATH)) {
return relPath;
} else if (this.options.src.match(EXPLICIT_PATH)) {
- return path.join(this.options.src, relPath);
+ return this.joinPath(this.options.src, relPath);
+ } else {
+ return this.joinPath(process.cwd(), this.options.src, relPath);
+ }
+ };
+
+ Snockets.prototype.joinPath = function() {
+ var filePath, slash;
+ filePath = path.join.apply(path, arguments);
+ if (process.platform === 'win32') {
+ slash = '/';
+ return filePath.replace(/\\/g, slash);
} else {
- return path.join(process.cwd(), this.options.src, relPath);
+ return filePath;
}
};
@@ -419,17 +478,17 @@
};
HoldingQueue.prototype.perform = function() {
- var args, key;
- var _this = this;
+ var args, key,
+ _this = this;
key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return this.task.apply(this, __slice.call(args).concat([function() {
return _this.unwaitFor(key);
}]));
};
HoldingQueue.prototype.finalize = function() {
- var h;
- var _this = this;
+ var h,
+ _this = this;
if (this.holdKeys.length === 0) {
return this.onComplete();
} else {
@@ -449,7 +508,9 @@
parseDirectives = function(code) {
var header, match, _results;
code = code.replace(/[\r\t ]+$/gm, '\n');
- if (!(match = HEADER.exec(code))) return [];
+ if (!(match = HEADER.exec(code))) {
+ return [];
+ }
header = match[0];
_results = [];
while (match = DIRECTIVE.exec(header)) {
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Trevor Burnham (http://trevorburnham.com)",
"name": "snockets",
"description": "Sprockets-esque script concatenation for Node",
- "version": "1.3.6",
+ "version": "1.3.7",
"homepage": "http://github.com/TrevorBurnham/snockets",
"repository": {
"type": "git",

0 comments on commit 87a9afc

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