Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
Fix web-component recognition! 🔨
Browse files Browse the repository at this point in the history
Closes #78.
  • Loading branch information
dunnkers committed Nov 20, 2017
1 parent dca492a commit 4e7f6f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ElementBundler = require('./lib/bundler');
const ElementWriter = require('./lib/writer');
// internals
const Config = require('./lib/config');
const scrapeDeps = require('./lib/scraper');
const { scrapeDeps } = require('./lib/scraper');
const extractDeps = require('./lib/extractor');

module.exports = {
Expand Down
19 changes: 14 additions & 5 deletions lib/scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ const fs = require('fs');
const fileExists = fs.existsSync;
const path = require('path');

module.exports = (deps, dir, pkgFilename) =>
exports.isWebComponent = (pkg) => {
let { keywords, main } = pkg;
let hasAnyKeyword = keywords && (keywords.includes('web-component') ||
keywords.includes('web-components'));
let hasEntryPoint = main && main.includes(`${pkg.name}.html`);
// TODO has package `webcomponents.org published` badge

return [ hasAnyKeyword, hasEntryPoint ].some(t => t);
};

exports.scrapeDeps = (deps, dir, pkgFilename) =>
Object.keys(deps).reduce((stack, name) => {
let elementPath = path.join(dir, name, `${name}.html`);
let allPath = path.join(dir, name, 'all-imports.html');
let pkg = require(path.join(dir, name, pkgFilename));

if (pkg.keywords && pkg.keywords.includes('web-components')
&& fileExists(elementPath)) {
// verify whether webcomponent and entrypoint existance
if (exports.isWebComponent(pkg) && fileExists(elementPath)) {
let allPath = path.join(dir, name, 'all-imports.html');
elementPath = fileExists(allPath) ? allPath : elementPath;

stack.push({ name, elementPath });
}

Expand Down

0 comments on commit 4e7f6f2

Please sign in to comment.