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

fix(writer): fix makeDir directory tree bug #3235

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 21 additions & 20 deletions docs/src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,32 @@ exports.output = output;
function output(file, content) {
var fullPath = pathUtils.join(OUTPUT_DIR,file);
var dir = pathUtils.dirname(fullPath);
return Q.when(exports.makeDir(dir), function(error) {
qfs.write(fullPath, exports.toString(content));
return Q.when(exports.makeDir(dir), function () {
return qfs.write(fullPath, exports.toString(content));
});
}

//recursively create directory
exports.makeDir = function(p) {
p = pathUtils.normalize(p);
var parts = p.split(pathUtils.sep);
var path = ".";

// Recursively rebuild directory structure
return qfs.exists(p).
then(function createPart(exists) {
if(!exists && parts.length) {
path = pathUtils.join(path, parts.shift());
return qfs.exists(path).then(function(exists) {
if (!exists) {
return qfs.makeDirectory(path).then(createPart, createPart);
} else {
return createPart();
}
});
}
});
p = pathUtils.normalize(p);
var parts = p.split(pathUtils.sep);

var makePartialDir = function makePartialDir(path) {
return qfs.makeDirectory(path).then(function() {
if (parts.length) {
return makePartialDir(pathUtils.join(path, parts.shift()));
}
}, function(error) {
if (error.code !== 'EEXIST') {
throw error;
}
if (parts.length) {
return makePartialDir(pathUtils.join(path, parts.shift()));
}
});
};

return makePartialDir(pathUtils.join('.', parts.shift()));
};

exports.copyTemplate = function(filename) {
Expand Down