Skip to content

Instantly share code, notes, and snippets.

@dfreedm
Created November 16, 2013 02:06
Show Gist options
  • Select an option

  • Save dfreedm/7494961 to your computer and use it in GitHub Desktop.

Select an option

Save dfreedm/7494961 to your computer and use it in GitHub Desktop.
Generate Bower.json from HTMLImports
#!/usr/bin/env node
// builtin
var fs = require('fs');
var path = require('path');
// modules
var cheerio = require('cheerio');
var url = /\s*(?:\.\.\/)?components\/([\w-]+)\/.*/;
var dirDepends = {platform: 'Polymer/platform#master'};
function readFileDepends(map, f) {
var $ = cheerio.load(fs.readFileSync(f, 'utf8'));
$('link[rel="import"]').each(function() {
var href = this.attr('href');
if (href) {
var match = url.exec(href);
if (match && !map[match[1]]) {
map[match[1]] = 'Polymer/' + match[1] + '#master';
}
}
});
}
process.argv.slice(2).forEach(function(f) {
readFileDepends(dirDepends, f);
});
var bower = {
name: path.basename(process.cwd()),
private: true,
dependencies: dirDepends
};
console.log(JSON.stringify(bower, null, 2));
find . ! -path "*/components/*" -name "*.html" | xargs node ../configure-imports.js > bower.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment