Skip to content

Commit 7ec926f

Browse files
ksheedloIgorMinar
authored andcommitted
fix(writer): fix makeDir directory tree bug
1 parent 031da1f commit 7ec926f

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

docs/src/writer.js

+21-20
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,32 @@ exports.output = output;
1313
function output(file, content) {
1414
var fullPath = pathUtils.join(OUTPUT_DIR,file);
1515
var dir = pathUtils.dirname(fullPath);
16-
return Q.when(exports.makeDir(dir), function(error) {
17-
qfs.write(fullPath, exports.toString(content));
16+
return Q.when(exports.makeDir(dir), function () {
17+
return qfs.write(fullPath, exports.toString(content));
1818
});
1919
}
2020

2121
//recursively create directory
2222
exports.makeDir = function(p) {
23-
p = pathUtils.normalize(p);
24-
var parts = p.split(pathUtils.sep);
25-
var path = ".";
26-
27-
// Recursively rebuild directory structure
28-
return qfs.exists(p).
29-
then(function createPart(exists) {
30-
if(!exists && parts.length) {
31-
path = pathUtils.join(path, parts.shift());
32-
return qfs.exists(path).then(function(exists) {
33-
if (!exists) {
34-
return qfs.makeDirectory(path).then(createPart, createPart);
35-
} else {
36-
return createPart();
37-
}
38-
});
39-
}
40-
});
23+
p = pathUtils.normalize(p);
24+
var parts = p.split(pathUtils.sep);
25+
26+
var makePartialDir = function makePartialDir(path) {
27+
return qfs.makeDirectory(path).then(function() {
28+
if (parts.length) {
29+
return makePartialDir(pathUtils.join(path, parts.shift()));
30+
}
31+
}, function(error) {
32+
if (error.code !== 'EEXIST') {
33+
throw error;
34+
}
35+
if (parts.length) {
36+
return makePartialDir(pathUtils.join(path, parts.shift()));
37+
}
38+
});
39+
};
40+
41+
return makePartialDir(pathUtils.join('.', parts.shift()));
4142
};
4243

4344
exports.copyTemplate = function(filename) {

0 commit comments

Comments
 (0)