From 5013f79e8d78d11e992d522e71c3b9949bba8257 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 1 Oct 2011 16:50:31 +0200 Subject: [PATCH] Make "jake clean" and "jake distclean" check deleted directory existence Closes GH-52. --- Jakefile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Jakefile b/Jakefile index 5cd8e09..5bc5a1d 100644 --- a/Jakefile +++ b/Jakefile @@ -88,6 +88,16 @@ function copyDir(src, dest) { }); } +function dirExists(dir) { + try { + var stats = fs.statSync(file); + } catch (e) { + return false; + } + + return stats.isDirectory(); +} + function removeDir(dir) { fs.readdirSync(dir).every(function(file) { var file = dir + "/" + file; @@ -151,7 +161,9 @@ task("build", [], function() { desc("Remove built peg.js file (created by \"build\")"); task("clean", [], function() { - removeDir(LIB_DIR); + if (dirExists(LIB_DIR)) { + removeDir(LIB_DIR); + } }); desc("Prepare the distribution files"); @@ -189,7 +201,9 @@ task("dist", ["build"], function() { desc("Remove the distribution files (created by \"dist\")"); task("distclean", [], function() { - removeDir(DIST_DIR); + if (dirExists(DIST_DIR)) { + removeDir(DIST_DIR); + } }); desc("Run the test suite");