Last active
August 29, 2015 14:16
-
-
Save quidmonkey/460809dc96c883fa7e5d to your computer and use it in GitHub Desktop.
Get All Bower Components in Node
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
'use strict'; | |
var fs = require('fs'); | |
var globule = require('globule'); | |
var path = require('path'); | |
var bowerComponents = globule | |
.find('bower_components/**/bower.json') | |
.map(function (fileName) { | |
var bowerJson = fs.readFileSync(fileName); | |
var componentFile = JSON.parse(bowerJson).main; | |
var componentPath = fileName.replace('bower.json', ''); | |
// main may be an array of files | |
if (componentFile instanceof Array) { | |
return componentFile.map(function (component) { | |
return path.join(componentPath, component); | |
}); | |
} else { | |
return path.join(componentPath, componentFile); | |
} | |
}) | |
// reverse sorting | |
// so that jquery loads before jquery-ui | |
// and angular prior to its plugins | |
// TODO fix with more permanent solution later | |
.sort(function (a, b) { | |
return b > a; | |
}); | |
// flatten array | |
module.exports = [].concat.apply([], bowerComponents); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment