diff --git a/lib/middleware/size.js b/lib/middleware/size.js index ff35cc8..95aa81a 100644 --- a/lib/middleware/size.js +++ b/lib/middleware/size.js @@ -18,21 +18,30 @@ function humanFileSize(bytes, si) { module.exports = function(req, next){ //process.stdout.write(" size:".grey, "checking...") - process.stdout.write(" size: ".grey) - req.projectSize = 0; - req.fileCount = 0 - var project = fsReader({ 'path': req.project, ignoreFiles: [".surgeignore"] }) - project.addIgnoreRules(ignore) + fs.stat(req.project, getDirStats) - project.on("child", function (c) { - fs.lstat(c.path, function(err, stats) { - req.projectSize += stats.size - if (!stats.isDirectory()) req.fileCount++ - }) - }).on("close", function(){ - helpers.log(req.fileCount + " files,", humanFileSize(req.projectSize)) - next() - }) + function getDirStats(err, stats) { + if(stats.isDirectory()){ + process.stdout.write(" size: ".grey) + req.projectSize = 0; + req.fileCount = 0 + var project = fsReader({ 'path': req.project, ignoreFiles: [".surgeignore"] }) + project.addIgnoreRules(ignore) + project.on("child", function (c) { + fs.lstat(c.path, function(err, stats) { + req.projectSize += stats.size + if (!stats.isDirectory()) req.fileCount++ + }) + }).on("close", function(){ + helpers.log(req.fileCount + " files,", humanFileSize(req.projectSize)) + next() + }) + } else { + helpers.log() + helpers.log(" Aborted".yellow, "-", req.project.red + " is not a directory.") + helpers.log() + } + } } diff --git a/test/fixtures/cli-test-6.surge.sh/Not.a.directory b/test/fixtures/cli-test-6.surge.sh/Not.a.directory new file mode 100644 index 0000000..752d439 --- /dev/null +++ b/test/fixtures/cli-test-6.surge.sh/Not.a.directory @@ -0,0 +1 @@ +This file is not a directory....duh diff --git a/test/publish.js b/test/publish.js index 3c291ee..81a5d27 100644 --- a/test/publish.js +++ b/test/publish.js @@ -119,6 +119,16 @@ describe('publish', function (done) { }) .end(done) }) + it('Should not publish a project if the path provided is not a directory', function(done) { + this.timeout(5000) + nixt(opts) + .run(surge + './test/fixtures/cli-test-6.surge.sh/Not.a.directory') + .expect(function (result) { + should(result.stdout).match(/Aborted/) + should(result.stdout).match(/is not a directory/) + }) + .end(done) + }) after(function (done) { nixt(opts)