diff --git a/scripts/gatsby-plugin-checker/README.md b/scripts/gatsby-plugin-checker/README.md new file mode 100644 index 0000000000000..daa095cf07ec4 --- /dev/null +++ b/scripts/gatsby-plugin-checker/README.md @@ -0,0 +1,3 @@ +# gatsby-plugin-checker + +This script searches the npm API for plugins that start with either "gatsby-source", "gatsby-plugin", or "gatsby-transformer" but don't have the "gatsby-plugin" keyword in their `package.json` and thus are not included in Gatsby's keyword search. The script will then notify those repositories by creating an issue notifying them to add the keyword to their `package.json` (This functionality will be included in the next commit). Once a repo has been notified, its `notified` attribute will be changed to `true` in `plugins.json` and won't be notified. Similarly, if a repo is a false positive or doesn't want to be notified, it can be `blacklisted`. diff --git a/scripts/gatsby-plugin-checker/index.js b/scripts/gatsby-plugin-checker/index.js index c8bd5ba5767b7..47a5847ee7e09 100644 --- a/scripts/gatsby-plugin-checker/index.js +++ b/scripts/gatsby-plugin-checker/index.js @@ -64,6 +64,37 @@ const filterNotNotified = (packages, plugins) => { return packages.filter(pkg => notified.indexOf(pkg.name) < 0) } +const removePackagesWithoutRepository = packages => + packages.filter(pkg => !!pkg.links.repository) + +const removeBadNameFormats = packages => packages.filter(p => hasGoodName(p)) + +const hasGoodName = pkg => { + const name = pkg.name + const isScopedPackage = name.startsWith(`@`) + if (!isScopedPackage) { + return startsWithAllowedPrefix(name) + } + + const nameWithoutScope = name.slice(0, name.indexOf(`/`)) + return startsWithAllowedPrefix(nameWithoutScope) +} + +const startsWithAllowedPrefix = name => + keywords.some(keyword => name.startsWith(keyword)) + +const removePackagesWithoutReadme = packages => + packages.filter(pkg => hasReadMe(pkg)) + +const hasReadMe = pkg => { + if (pkg.links.homepage || pkg.readme) return true + if (pkg.links.repository) { + return got(pkg.links.repository + `/blob/master/README.md`) + .then(response => response.statusCode === 200) + .catch(_ => false) + } else return false +} + const updatePlugins = (updates, plugins) => { let res = plugins.map(p => Object.assign({}, p)) updates.forEach(u => { @@ -84,11 +115,15 @@ const main = () => { .then(transformResults) .then(packages => filterNotBlacklisted(packages, plugins)) .then(packages => filterNotNotified(packages, plugins)) + .then(packages => removePackagesWithoutRepository(packages)) + .then(packages => removeBadNameFormats(packages)) + .then(packages => removePackagesWithoutReadme(packages)) .then(packages => packages.map(p => { // TODO: notify / comment on github console.info(`Notify package "${p.name}"`) // return update status + // will turn notified to true once notifications are created return { name: p.name, blacklist: false, notified: false } }) )