Skip to content

Commit

Permalink
CWD solution for local paths
Browse files Browse the repository at this point in the history
  • Loading branch information
robashton committed Mar 26, 2012
1 parent b97a2b1 commit 1a86a2e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/builder.js
Expand Up @@ -18,15 +18,20 @@ module.exports = (function(require) {
Builder.prototype = { Builder.prototype = {


run: function() { run: function() {
var oldWd = process.cwd();
process.chdir(this.cfg.root || oldWd);

var root = new DirectoryWalker(this.cfg.in); var root = new DirectoryWalker(this.cfg.in);
var self = this; var self = this;


root.on('error', function(err) { root.on('error', function(err) {
self.emit('error', err); self.emit('error', err);
process.chdir(oldWd);
}); });


root.on('completed', function() { root.on('completed', function() {
self.completed = true; self.completed = true;
process.chdir(oldWd);
}); });


root.on('file', function(path) { root.on('file', function(path) {
Expand Down Expand Up @@ -62,9 +67,6 @@ module.exports = (function(require) {
} }
handler.handle(path, function(err, data) { handler.handle(path, function(err, data) {
if(err) { self.emit('error', err); return; } if(err) { self.emit('error', err); return; }
if(self.cfg.root) {
path = path.replace(self.cfg.root, '');
}
self.data[path] = data; self.data[path] = data;
self.notifyPendingDecrease(); self.notifyPendingDecrease();
}); });
Expand Down
2 changes: 1 addition & 1 deletion test/out/packaging_directory_with_root_specified.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/out/packing_directory_additional_handler.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/out/packing_directory_default_options.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions test/tests.js
Expand Up @@ -91,9 +91,9 @@ describe("Packaging a directory with a root specified", function() {


before(function(done) { before(function(done) {
swallowTests.packageDirectoryAndLoadPackage({ swallowTests.packageDirectoryAndLoadPackage({
in: './in/assets', in: './assets',
out: './out/packaging_directory_with_root_specified.json', out: './out/packaging_directory_with_root_specified.json',
root: 'in/assets' root: 'in'
}, },
function(err, pkg) { function(err, pkg) {
if(err) throw err; if(err) throw err;
Expand All @@ -103,8 +103,8 @@ describe("Packaging a directory with a root specified", function() {
}); });


it("Should remove the root from the path", function() { it("Should remove the root from the path", function() {
var packageJson = builtPackage.getRaw('/models/hovercraft.json'); var packageJson = builtPackage.getRaw('assets/models/hovercraft.json');
assert(packageJson) assert(packageJson);
}); });
}); });


Expand Down

0 comments on commit 1a86a2e

Please sign in to comment.