Ensure relative paths work with --output and template=… build options.

Former-commit-id: 2447466a006dc8d968969bba70a0e44f91610154
This commit is contained in:
John-David Dalton
2013-02-24 11:40:56 -08:00
parent 8cbbc47043
commit c1e9dd3373
2 changed files with 69 additions and 37 deletions

View File

@@ -19,19 +19,22 @@
* @param {Number|String} mode The permission mode.
*/
function mkdirpSync(dirname, mode) {
var separator = path.sep,
segments = dirname.split(separator),
var sep = path.sep,
type = typeof mode;
// ensure relative paths are prefixed with `./`
if (!RegExp('^\\.?' + sep).test(dirname)) {
dirname = '.' + sep + dirname;
}
if (!(type == 'number' || type == 'string')) {
mode = '0777';
}
segments.reduce(function(currPath, segment, index) {
dirname.split(sep).reduce(function(currPath, segment, index) {
// skip leading separator of absolute paths
if (index === 0 && currPath === '') {
return separator;
return sep;
}
segment = currPath + (currPath === separator ? segment : separator + segment);
segment = currPath + (currPath === sep ? segment : sep + segment);
try {
segment = fs.realpathSync(segment);
} catch(e) {