From 13cb530eee8a1f059da3c3fb6c50163c5a62dbec Mon Sep 17 00:00:00 2001 From: Osmond van Hemert Date: Fri, 7 Dec 2018 18:50:52 +0100 Subject: [PATCH] plugin checker initial commit (#7062) Initial plugin checker for issue #5211 It reports found plugins to "plugins.json". Blacklist property can be manually set to avoid processing again. Notifying => see issue --- scripts/gatsby-plugin-checker/index.js | 103 +++++++++++++++++ scripts/gatsby-plugin-checker/package.json | 15 +++ scripts/gatsby-plugin-checker/plugins.json | 125 +++++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 scripts/gatsby-plugin-checker/index.js create mode 100644 scripts/gatsby-plugin-checker/package.json create mode 100644 scripts/gatsby-plugin-checker/plugins.json diff --git a/scripts/gatsby-plugin-checker/index.js b/scripts/gatsby-plugin-checker/index.js new file mode 100644 index 0000000000000..c8bd5ba5767b7 --- /dev/null +++ b/scripts/gatsby-plugin-checker/index.js @@ -0,0 +1,103 @@ +"use strict" + +const fs = require(`fs`) +const got = require(`got`) +const path = require(`path`) + +const keywords = [`gatsby-plugin`, `gatsby-source`, `gatsby-transformer`] +const pluginsFile = path.join(__dirname, `plugins.json`) + +const loadPlugins = async () => { + try { + return require(pluginsFile) + } catch (err) { + throw err + } +} + +const savePlugins = plugins => + new Promise((resolve, reject) => { + let output = `[\n\t` + output += plugins + .sort((a, b) => { + if (a.name < b.name) { + return -1 + } + if (a.name > b.name) { + return 1 + } + return 0 + }) + .map(p => JSON.stringify(p)) + .join(`,\n\t`) + output += `\n]\n` + fs.writeFile(pluginsFile, output, err => { + if (err) reject(err) + resolve() + }) + }) + +const searchNPM = () => { + const promises = keywords.map(keyword => { + const url = `https://api.npms.io/v2/search?q=${keyword}+keywords:-gatsby-plugin+not:deprecated&size=250` + return got(url).then(response => JSON.parse(response.body)) + }) + return Promise.all(promises) +} + +const transformResults = results => { + const merged = results.reduce((t, r) => t.concat(r.results), []) + const deduped = merged.reduce((t, r) => { + t[r.package.name] = t[r.package.name] || r.package + return t + }, {}) + return Object.keys(deduped).map(d => deduped[d]) +} + +const filterNotBlacklisted = (packages, plugins) => { + const blacklisted = plugins.filter(p => p.blacklist).map(p => p.name) + return packages.filter(pkg => blacklisted.indexOf(pkg.name) < 0) +} + +const filterNotNotified = (packages, plugins) => { + const notified = plugins.filter(p => p.notified).map(p => p.name) + return packages.filter(pkg => notified.indexOf(pkg.name) < 0) +} + +const updatePlugins = (updates, plugins) => { + let res = plugins.map(p => Object.assign({}, p)) + updates.forEach(u => { + const idx = res.findIndex(r => r.name === u.name) + if (idx >= 0) { + res[idx] = Object.assign({}, res[idx], u) + } else { + res.push(u) + } + }) + return updates +} + +const main = () => { + loadPlugins() + .then(plugins => + searchNPM() + .then(transformResults) + .then(packages => filterNotBlacklisted(packages, plugins)) + .then(packages => filterNotNotified(packages, plugins)) + .then(packages => + packages.map(p => { + // TODO: notify / comment on github + console.info(`Notify package "${p.name}"`) + // return update status + return { name: p.name, blacklist: false, notified: false } + }) + ) + .then(updates => updatePlugins(updates, plugins)) + .then(savePlugins) + ) + .catch(err => { + console.error(err) + }) +} + +main() diff --git a/scripts/gatsby-plugin-checker/package.json b/scripts/gatsby-plugin-checker/package.json new file mode 100644 index 0000000000000..8a8a83cdac1cd --- /dev/null +++ b/scripts/gatsby-plugin-checker/package.json @@ -0,0 +1,15 @@ +{ + "name": "gatsby-plugin-checker", + "version": "1.0.0", + "description": "Checks for Gatsby plugins on NPM without the gatsby-plugin keyword.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node index" + }, + "author": "Osmond van Hemert ", + "license": "MIT", + "dependencies": { + "got": "^9.0.0" + } +} diff --git a/scripts/gatsby-plugin-checker/plugins.json b/scripts/gatsby-plugin-checker/plugins.json new file mode 100644 index 0000000000000..1723ae1ae06e2 --- /dev/null +++ b/scripts/gatsby-plugin-checker/plugins.json @@ -0,0 +1,125 @@ +[ + {"name":"@alxandr/gatsby-plugin-feed","blacklist":false,"notified":false}, + {"name":"@alxandr/gatsby-plugin-google-analytics","blacklist":false,"notified":false}, + {"name":"@alxandr/gatsby-transformer-blog-post","blacklist":false,"notified":false}, + {"name":"@alxandr/gatsby-transformer-unified","blacklist":false,"notified":false}, + {"name":"@dylanvann/gatsby-cloudinary","blacklist":false,"notified":false}, + {"name":"@entr/gatsby-source-google-analytics-reporting-api","blacklist":false,"notified":false}, + {"name":"@jacobmischka/gatsby-plugin-copy-files","blacklist":false,"notified":false}, + {"name":"@jacobmischka/gatsby-plugin-react-svg","blacklist":false,"notified":false}, + {"name":"@jacobmischka/gatsby-plugin-styled-jsx","blacklist":false,"notified":false}, + {"name":"@oliverturner/gatsby-source-trello","blacklist":false,"notified":false}, + {"name":"@porch/gatsby-source-gitlab-files","blacklist":false,"notified":false}, + {"name":"@porch/gatsby-source-gitlab-projects","blacklist":false,"notified":false}, + {"name":"@porch/gatsby-source-newrelic-apps","blacklist":false,"notified":false}, + {"name":"@ptb/gatsby-1-config-css-modules","blacklist":false,"notified":false}, + {"name":"@ptb/gatsby-plugin-pug","blacklist":false,"notified":false}, + {"name":"@ptb/gatsby-plugin-react-helmet","blacklist":false,"notified":false}, + {"name":"@sb-konzept/gatsby-source-storyblok","blacklist":false,"notified":false}, + {"name":"@scion-scxml/sciblog","blacklist":false,"notified":false}, + {"name":"@spraoi/gatsby-plugin","blacklist":false,"notified":false}, + {"name":"@theplayerstribune/gatsby-source-wordpress-plus","blacklist":false,"notified":false}, + {"name":"@uptimeventures/gatsby-source-rss","blacklist":false,"notified":false}, + {"name":"@wyze/preact-testing-library","blacklist":false,"notified":false}, + {"name":"development-dashboards-docs","blacklist":false,"notified":false}, + {"name":"gatsby-1-config-css-modules","blacklist":true,"notified":false}, + {"name":"gatsby-1-config-extract-plugin","blacklist":true,"notified":false}, + {"name":"gatsby-directus","blacklist":false,"notified":false}, + {"name":"gatsby-matsuri","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-adroll","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-canner-schema","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-channel","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-compression","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-compression-v2","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-copy-files","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-core-js","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-countly","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-default-layout","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-drip","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-escalade-stock","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-facebook","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-facebook-sdk","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-favicon-mperkh","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-favicons","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-github-pages","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-google-fonts","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-graphql","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-iamport","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-landr","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-linkedin","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-module-local-ident-name","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-mparticle","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-mui","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-netlify-lambda","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-ngrok-tunneling","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-page-tree","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-product-markdown-pages","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-production","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-protoculture","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-purify-css","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-react-webfont-loader","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-remote-images","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-remove-serviceworker","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-retabulate","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-sass-bulk-import","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-size-analyzer","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-snowplow","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-source-john-deere","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-styled-jsx-webpack-loader","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-typescript-css-modules","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-typescript-scss-modules","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-typescript-scss-modules-cjs","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-well-known","blacklist":false,"notified":false}, + {"name":"gatsby-plugin-zygote","blacklist":false,"notified":false}, + {"name":"gatsby-remark-curlie","blacklist":false,"notified":false}, + {"name":"gatsby-remark-frontmatter-defaults","blacklist":false,"notified":false}, + {"name":"gatsby-remark-github","blacklist":false,"notified":false}, + {"name":"gatsby-remark-grid-tables","blacklist":false,"notified":false}, + {"name":"gatsby-remark-jsx","blacklist":false,"notified":false}, + {"name":"gatsby-remark-prettypaper","blacklist":false,"notified":false}, + {"name":"gatsby-remark-visualdocs","blacklist":false,"notified":false}, + {"name":"gatsby-source-aem","blacklist":false,"notified":false}, + {"name":"gatsby-source-airtable-linked","blacklist":false,"notified":false}, + {"name":"gatsby-source-anilist","blacklist":false,"notified":false}, + {"name":"gatsby-source-datocms-graphql-example","blacklist":false,"notified":false}, + {"name":"gatsby-source-docgen-requirements","blacklist":false,"notified":false}, + {"name":"gatsby-source-feliks","blacklist":false,"notified":false}, + {"name":"gatsby-source-gcloud-object","blacklist":false,"notified":false}, + {"name":"gatsby-source-gdrive-tree","blacklist":false,"notified":false}, + {"name":"gatsby-source-git","blacklist":false,"notified":false}, + {"name":"gatsby-source-github-api","blacklist":false,"notified":false}, + {"name":"gatsby-source-github-gql","blacklist":false,"notified":false}, + {"name":"gatsby-source-github-projects","blacklist":false,"notified":false}, + {"name":"gatsby-source-google-drive","blacklist":false,"notified":false}, + {"name":"gatsby-source-google-sheet","blacklist":false,"notified":false}, + {"name":"gatsby-source-jira","blacklist":false,"notified":false}, + {"name":"gatsby-source-kerckhoff","blacklist":false,"notified":false}, + {"name":"gatsby-source-mongo","blacklist":false,"notified":false}, + {"name":"gatsby-source-nba","blacklist":false,"notified":false}, + {"name":"gatsby-source-newsapi","blacklist":false,"notified":false}, + {"name":"gatsby-source-pexels","blacklist":false,"notified":false}, + {"name":"gatsby-source-product-markdown","blacklist":false,"notified":false}, + {"name":"gatsby-source-published-google-sheets","blacklist":false,"notified":false}, + {"name":"gatsby-source-remote","blacklist":false,"notified":false}, + {"name":"gatsby-source-sapcc","blacklist":false,"notified":false}, + {"name":"gatsby-source-slack","blacklist":false,"notified":false}, + {"name":"gatsby-source-soundcloud","blacklist":false,"notified":false}, + {"name":"gatsby-source-steam","blacklist":false,"notified":false}, + {"name":"gatsby-source-steem","blacklist":false,"notified":false}, + {"name":"gatsby-source-twitch","blacklist":false,"notified":false}, + {"name":"gatsby-source-utopian","blacklist":false,"notified":false}, + {"name":"gatsby-source-woocommerce","blacklist":false,"notified":false}, + {"name":"gatsby-source-wordpress-bcgdv","blacklist":false,"notified":false}, + {"name":"gatsby-source-wordpress-plus","blacklist":false,"notified":false}, + {"name":"gatsby-teamtailor-users","blacklist":false,"notified":false}, + {"name":"gatsby-transformer-blog-post","blacklist":false,"notified":false}, + {"name":"gatsby-transformer-ipynb","blacklist":false,"notified":false}, + {"name":"gatsby-transformer-nimbl","blacklist":false,"notified":false}, + {"name":"gatsby-transformer-whoa","blacklist":false,"notified":false}, + {"name":"happo-plugin-gatsby","blacklist":false,"notified":false}, + {"name":"js-gatsby-plugin-react-next","blacklist":false,"notified":false}, + {"name":"mericsson-gatsby-source-contentful","blacklist":false,"notified":false}, + {"name":"react-snipcart","blacklist":false,"notified":false}, + {"name":"smooth-doc","blacklist":false,"notified":false}, + {"name":"syncano-gatsby","blacklist":false,"notified":false} +]