Created
November 16, 2013 02:06
-
-
Save dfreedm/7494961 to your computer and use it in GitHub Desktop.
Generate Bower.json from HTMLImports
This file contains hidden or 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
| #!/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)); |
This file contains hidden or 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
| 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