Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions lib/middleware/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
1 change: 1 addition & 0 deletions test/fixtures/cli-test-6.surge.sh/Not.a.directory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is not a directory....duh
10 changes: 10 additions & 0 deletions test/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down