diff options
| author | Ken Sheedlo | 2013-07-15 14:15:02 -0700 |
|---|---|---|
| committer | Igor Minar | 2013-07-16 11:13:36 -0700 |
| commit | 7ec926ff56fca50bf55191c7f056746fa77d8aa2 (patch) | |
| tree | 5f9fd20b359e0ee8f9acdf5ffdc6541da619f6c7 /docs/src | |
| parent | 031da1f96b3e0074e682e35ac909256c37c91864 (diff) | |
| download | angular.js-7ec926ff56fca50bf55191c7f056746fa77d8aa2.tar.bz2 | |
fix(writer): fix makeDir directory tree bug
Diffstat (limited to 'docs/src')
| -rw-r--r-- | docs/src/writer.js | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/docs/src/writer.js b/docs/src/writer.js index cdfa12d6..412d5437 100644 --- a/docs/src/writer.js +++ b/docs/src/writer.js @@ -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) { |
