Last active
August 29, 2015 14:00
-
-
Save obenjiro/78a8b5bb0130a78dc9e5 to your computer and use it in GitHub Desktop.
promises isn't a magic tool, or simply - they don't work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('vow-fs'), | |
vow = require('vow'); | |
/** | |
* @param {String} path | |
* @returns {Promise} representing css | |
*/ | |
module.exports = function processNode(path) { | |
return fs.isDir(path) | |
.then(function(isDir) { | |
if (isDir) { | |
return fs.listDir(path) | |
.then(function(list) { | |
return vow.all(list.map(function(node) { | |
return processNode([ path, node ].join('/')); | |
})); | |
}) | |
.then(function(data) { | |
return data | |
.filter(function(item) { | |
return item; | |
}) | |
.join('\n'); | |
}); | |
} else if (/\.css$/.test(path)) { | |
return fs.read(path).then(function(data) { | |
return [ | |
'/* ' + path + ': begin */', | |
data.toString() | |
].join('\n'); | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment