Permalink
Browse files

Don't check for the sub-directory availability, let the exceptions to…

… trigger
  • Loading branch information...
1 parent 0c26956 commit 96c479e43b53b29301a238fca17e45ee4245bbf7 @laktek committed Apr 2, 2012
Showing with 16 additions and 47 deletions.
  1. +10 −6 lib/punch.js
  2. +1 −1 package.json
  3. +5 −40 spec/punch.spec.js
View
@@ -303,12 +303,16 @@ module.exports = {
var output_path = path.split("/");
output_path[0] = config.output_dir;
- fs.stat(config.output_dir, function(err, stats){
- if(err || !stats.isDirectory()){
- // Create the output directory
- fs.mkdirSync(output_path.join("/"));
- }
- });
+ try {
+ // Create the output directory
+ fs.mkdirSync(output_path.join("/"));
+ }
+ catch(err){
+ // we can ignore the errors
+ // since failing to create a directory means
+ // it already exists.
+ // or destination is not writeable.
+ }
}
files.forEach(function(file){
View
@@ -2,7 +2,7 @@
"name": "punch"
, "description": "Generate static sites with mustache templates & json"
, "keywords": ["static", "sites", "mustache", "json", "markdown"]
- , "version": "0.0.6-beta"
+ , "version": "0.0.7-beta"
, "homepage": "https://github.com/laktek/punch"
, "author": "Lakshan Perera <lakshan@web2media.net> (http://laktek.com)"
, "licenses" : ["MIT"]
View
@@ -95,11 +95,8 @@ describe("traversing templates", function() {
callback(null, ["sub.mustache"]);
}
});
-
- spyOn(fs, 'stat').andCallFake(function(path, callback){
- callback(null, {isDirectory: function(){ return true }} );
- });
+ spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");
punch.traverseTemplates(config);
@@ -111,10 +108,6 @@ describe("traversing templates", function() {
it("creates sub-directories in the output path", function(){
var config = {"template_dir": "templates", "output_dir": "public"};
- spyOn(fs, 'stat').andCallFake(function(path, callback){
- callback(null, {isDirectory: function(){ return false }} );
- });
-
spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");
@@ -132,30 +125,6 @@ describe("traversing templates", function() {
});
- it("will skip creating already existing sub-directories in the output path", function(){
- var config = {"template_dir": "templates", "output_dir": "public"};
-
- spyOn(fs, 'stat').andCallFake(function(path, callback){
- callback(null, {isDirectory: function(){ return true }} );
- });
-
- spyOn(fs, 'mkdirSync');
- spyOn(punch, "fetchAndRender");
-
- spyOn(fs, 'readdir').andCallFake(function(path, callback){
- if(fs.readdir.mostRecentCall.args[0] === "templates"){
- callback(null, ["index.mustache", "sub_dir"]);
- } else {
- callback(null, ["sub.mustache"]);
- }
- });
-
- punch.traverseTemplates(config);
-
- expect(fs.mkdirSync).not.toHaveBeenCalled();
-
- });
-
it("calls to render content when a template is found", function(){
var config = {"template_dir": "templates"};
@@ -167,10 +136,7 @@ describe("traversing templates", function() {
}
});
- spyOn(fs, 'stat').andCallFake(function(path, callback){
- callback(null, {isDirectory: function(){ return true }} );
- });
-
+ spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");
punch.traverseTemplates(config);
@@ -190,10 +156,7 @@ describe("traversing templates", function() {
}
});
- spyOn(fs, 'stat').andCallFake(function(path, callback){
- callback(null, {isDirectory: function(){ return true }} );
- });
-
+ spyOn(fs, 'mkdirSync');
spyOn(punch, "fetchAndRender");
punch.traverseTemplates(config);
@@ -214,6 +177,7 @@ describe("traversing templates", function() {
}
});
+ spyOn(fs, 'mkdirSync');
spyOn(punch, "staticFileHandler");
punch.traverseTemplates(config);
@@ -222,6 +186,7 @@ describe("traversing templates", function() {
});
+
});
describe("handling static files", function(){

0 comments on commit 96c479e

Please sign in to comment.