Skip to content

Instantly share code, notes, and snippets.

@obenjiro
Last active August 29, 2015 14:00
Show Gist options
  • Save obenjiro/78a8b5bb0130a78dc9e5 to your computer and use it in GitHub Desktop.
Save obenjiro/78a8b5bb0130a78dc9e5 to your computer and use it in GitHub Desktop.
promises isn't a magic tool, or simply - they don't work
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