From 928bf178d5bae2ae490bc124480951439247d760 Mon Sep 17 00:00:00 2001 From: nginnever Date: Tue, 24 May 2016 13:08:17 -0700 Subject: [PATCH] fix adding empty dirs --- src/cli/commands/files/add.js | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 3693702c45..cd2b69aa92 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -122,10 +122,23 @@ module.exports = Command.extend({ const index = inPath.lastIndexOf('/') parallelLimit(res.map((element) => (callback) => { if (!fs.statSync(element).isDirectory()) { + element.substring(index + 1, element.length) i.write({ path: element.substring(index + 1, element.length), stream: fs.createReadStream(element) }) + } else { + fs.readdir(element, (err, files) => { + if (err) { + throw err + } + if (files.length === 0) { + i.write({ + path: element.substring(index + 1, element.length), + stream: null + }) + } + }) } callback() }), 10, (err) => { @@ -135,11 +148,25 @@ module.exports = Command.extend({ i.end() }) } else { - rs = fs.createReadStream(inPath) - inPath = inPath.substring(inPath.lastIndexOf('/') + 1, inPath.length) - filePair = {path: inPath, stream: rs} - i.write(filePair) - i.end() + if (!fs.statSync(inPath).isDirectory()) { + rs = fs.createReadStream(inPath) + inPath = inPath.substring(inPath.lastIndexOf('/') + 1, inPath.length) + filePair = {path: inPath, stream: rs} + i.write(filePair) + i.end() + } else { + fs.readdir(inPath, (err, files) => { + if (err) { + throw err + } + if (files.length === 0) { + i.write({ + path: inPath, + stream: null + }) + } + }) + } } }) }