Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit ec7f76b

Browse files
committed
fix adding empty dirs
1 parent b00f05b commit ec7f76b

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/cli/commands/files/add.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,23 @@ module.exports = Command.extend({
122122
const index = inPath.lastIndexOf('/')
123123
parallelLimit(res.map((element) => (callback) => {
124124
if (!fs.statSync(element).isDirectory()) {
125+
element.substring(index + 1, element.length)
125126
i.write({
126127
path: element.substring(index + 1, element.length),
127128
stream: fs.createReadStream(element)
128129
})
130+
} else {
131+
fs.readdir(element, (err, files) => {
132+
if (err) {
133+
throw err
134+
}
135+
if (files.length === 0) {
136+
i.write({
137+
path: element.substring(index + 1, element.length),
138+
stream: null
139+
})
140+
}
141+
})
129142
}
130143
callback()
131144
}), 10, (err) => {
@@ -135,11 +148,25 @@ module.exports = Command.extend({
135148
i.end()
136149
})
137150
} else {
138-
rs = fs.createReadStream(inPath)
139-
inPath = inPath.substring(inPath.lastIndexOf('/') + 1, inPath.length)
140-
filePair = {path: inPath, stream: rs}
141-
i.write(filePair)
142-
i.end()
151+
if (!fs.statSync(inPath).isDirectory()) {
152+
rs = fs.createReadStream(inPath)
153+
inPath = inPath.substring(inPath.lastIndexOf('/') + 1, inPath.length)
154+
filePair = {path: inPath, stream: rs}
155+
i.write(filePair)
156+
i.end()
157+
} else {
158+
fs.readdir(inPath, (err, files) => {
159+
if (err) {
160+
throw err
161+
}
162+
if (files.length === 0) {
163+
i.write({
164+
path: inPath,
165+
stream: null
166+
})
167+
}
168+
})
169+
}
143170
}
144171
})
145172
}

0 commit comments

Comments
 (0)