diff --git a/.gitignore b/.gitignore index 27fed5b100f0..4e48114757ad 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ package-lock.json internal-links.tap stats.json printable.md +repositories/*.json diff --git a/package.json b/package.json index 747faad9900b..31530dd4ebda 100644 --- a/package.json +++ b/package.json @@ -27,17 +27,17 @@ "clean-dist": "rimraf ./dist", "clean-printable": "rimraf src/content/**/printable.md", "preclean": "run-s clean-dist clean-printable", - "clean": "rimraf src/content/**/_*.md src/**/_*.json", + "clean": "rimraf src/content/**/_*.md src/**/_*.json repositories/*.json", "start": "npm run clean-dist && cross-env NODE_ENV=development webpack-dev-server --config webpack.dev.js --env.dev", - "update-repos": "node src/utilities/fetch-package-repos.js", "content": "node src/scripts/build-content-tree.js ./src/content ./src/_content.json", "bundle-analyze": "run-s clean fetch printable content && cross-env NODE_ENV=production webpack --config webpack.ssg.js && run-s clean-printable content && cross-env NODE_ENV=production webpack --config webpack.prod.js --profile --json > stats.json && webpack-bundle-analyzer stats.json", + "fetch-repos": "node src/utilities/fetch-package-repos.js", "fetch": "run-p fetch:*", "fetch:readmes": "node src/utilities/fetch-package-readmes.js", "fetch:supporters": "node src/utilities/fetch-supporters.js", "fetch:starter-kits": "node src/utilities/fetch-starter-kits.js", "prebuild": "npm run clean", - "build": "run-s fetch printable content && cross-env NODE_ENV=production webpack --config webpack.ssg.js && run-s clean-printable content && cross-env NODE_ENV=production webpack --config webpack.prod.js", + "build": "run-s fetch-repos fetch printable content && cross-env NODE_ENV=production webpack --config webpack.ssg.js && run-s clean-printable content && cross-env NODE_ENV=production webpack --config webpack.prod.js", "postbuild": "npm run sitemap", "build-test": "npm run build && http-server dist/", "test": "npm run lint", diff --git a/repositories/loaders.json b/repositories/loaders.json deleted file mode 100644 index 549653235fc1..000000000000 --- a/repositories/loaders.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - "webpack-contrib/raw-loader", - "webpack-contrib/coffee-loader", - "webpack-contrib/css-loader", - "webpack-contrib/style-loader", - "webpack-contrib/less-loader", - "webpack-contrib/val-loader", - "webpack-contrib/file-loader", - "webpack-contrib/url-loader", - "webpack-contrib/json5-loader", - "webpack-contrib/worker-loader", - "webpack-contrib/imports-loader", - "webpack-contrib/exports-loader", - "webpack-contrib/mocha-loader", - "webpack-contrib/expose-loader", - "webpack-contrib/node-loader", - "webpack-contrib/html-loader", - "webpack-contrib/sass-loader", - "webpack-contrib/source-map-loader", - "webpack-contrib/null-loader", - "webpack-contrib/istanbul-instrumenter-loader", - "webpack-contrib/eslint-loader", - "webpack-contrib/svg-inline-loader", - "webpack-contrib/cache-loader", - "webpack-contrib/thread-loader", - "webpack-contrib/polymer-webpack-loader", - "babel/babel-loader", - "webpack-contrib/postcss-loader", - "peerigon/extract-loader", - "webpack-contrib/remark-loader", - "webpack-contrib/stylus-loader" -] diff --git a/repositories/plugins.json b/repositories/plugins.json deleted file mode 100644 index 7a48ea691b40..000000000000 --- a/repositories/plugins.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - "webpack-contrib/compression-webpack-plugin", - "webpack-contrib/copy-webpack-plugin", - "webpack-contrib/npm-install-webpack-plugin", - "webpack-contrib/stylelint-webpack-plugin", - "webpack-contrib/closure-webpack-plugin", - "webpack-contrib/mini-css-extract-plugin", - "webpack-contrib/terser-webpack-plugin", - "webpack-contrib/css-minimizer-webpack-plugin", - "webpack-contrib/eslint-webpack-plugin" -] \ No newline at end of file diff --git a/src/utilities/constants.js b/src/utilities/constants.js new file mode 100644 index 000000000000..b78983813880 --- /dev/null +++ b/src/utilities/constants.js @@ -0,0 +1,30 @@ +const excludedLoaders = [ + 'webpack-contrib/config-loader', + 'webpack-contrib/eslint-loader', + 'webpack-contrib/transform-loader', + 'webpack-contrib/json-loader', + 'webpack-contrib/script-loader', + 'webpack-contrib/bundle-loader', + 'webpack-contrib/i18n-loader', + 'webpack-contrib/jshint-loader', + 'webpack-contrib/coverjs-loader', + 'webpack-contrib/coffee-redux-loader', + 'webpack-contrib/react-proxy-loader', + 'webpack-contrib/multi-loader', + 'webpack-contrib/yaml-frontmatter-loader', + 'webpack-contrib/restyle-loader', + 'webpack-contrib/gzip-loader' +]; +const excludedPlugins = [ + 'webpack-contrib/component-webpack-plugin', + 'webpack-contrib/extract-text-webpack-plugin', + 'webpack-contrib/i18n-webpack-plugin', + 'webpack-contrib/babel-minify-webpack-plugin', + 'webpack-contrib/uglifyjs-webpack-plugin', + 'webpack-contrib/zopfli-webpack-plugin' +]; + +module.exports = { + excludedLoaders, + excludedPlugins +}; diff --git a/src/utilities/fetch-package-repos.js b/src/utilities/fetch-package-repos.js index 11beca1bd9c7..bda740f0d0e4 100644 --- a/src/utilities/fetch-package-repos.js +++ b/src/utilities/fetch-package-repos.js @@ -3,23 +3,24 @@ const path = require('path'); const mkdirp = require('mkdirp'); const _ = require('lodash'); const GithubAPI = require('@octokit/rest'); +const { excludedLoaders, excludedPlugins } = require('./constants'); const fetch = { loaders: [ { organization: 'webpack-contrib', suffixes: ['-loader'], - hides: ['webpack-contrib/config-loader'] + hides: excludedLoaders }, 'babel/babel-loader', - 'postcss/postcss-loader', - 'peerigon/extract-loader' + 'peerigon/extract-loader', + 'Banno/polymer-webpack-loader' ], plugins: [ { organization: 'webpack-contrib', suffixes: ['-webpack-plugin', '-extract-plugin'], - hides: ['webpack-contrib/component-webpack-plugin'] + hides: excludedPlugins } ] }; diff --git a/src/utilities/process-readme.js b/src/utilities/process-readme.js index 9ad917f40ae8..e08b08bbad82 100644 --- a/src/utilities/process-readme.js +++ b/src/utilities/process-readme.js @@ -1,4 +1,5 @@ const url = require('url'); +const { excludedLoaders, excludedPlugins } = require('./constants'); const beginsWithDocsDomainRegex = /^(?:https?:)\/\/webpack\.js\.org/; const inlineLinkRegex = /\[[^\]]*\]\(([^)]+)\)/g; @@ -66,8 +67,18 @@ function linkFixerFactory(sourceUrl) { }; } +function getMatches(string, regex) { + const matches = []; + let match; + // eslint-disable-next-line + while (match = regex.exec(string)) { + matches.push(match); + } + return matches; +} + module.exports = function processREADME(body, options = {}) { - return body + let processingString = body .replace(/[^]*?
([^]*?)<\/div>/, (match, content) => { let parsed = content.match(/

([^]*?)<\/?p>/); return parsed ? parsed[1] : ''; @@ -82,12 +93,28 @@ module.exports = function processREADME(body, options = {}) { // EXAMPLE: [line-identifier]: https://webpack.js.org/loaders/ .replace(inlineLinkRegex, linkFixerFactory(options.source)) .replace(externalLinkRegex, linkFixerFactory(options.source)) - // Modify links to keep them within the site - .replace(/https?:\/\/github.com\/(webpack|webpack-contrib)\/([-A-za-z0-9]+-loader\/?)([)"])/g, '/loaders/$2/$3') - .replace(/https?:\/\/github.com\/(webpack|webpack-contrib)\/([-A-za-z0-9]+-plugin\/?)([)"])/g, '/plugins/$2/$3') // Replace any

with `##` .replace(/]*>/g, '## ') .replace(/<\/h2>/g, '') // Drop any comments .replace(//g, ''); + + // find the laoders links + const loaderMatches = getMatches(processingString, /https?:\/\/github.com\/(webpack|webpack-contrib)\/([-A-za-z0-9]+-loader\/?)([)"])/g); + // dont make relative links for excluded loaders + loaderMatches.forEach((match) => { + if (!excludedLoaders.includes(`${match[1]}/${match[2]}`)) { + processingString = processingString.replace(match[0], `/loaders/${match[2]}`); + } + }); + + const pluginMatches = getMatches(processingString, /https?:\/\/github.com\/(webpack|webpack-contrib)\/([-A-za-z0-9]+-plugin\/?)([)"])/g); + // dont make relative links for excluded loaders + pluginMatches.forEach((match) => { + if (!excludedPlugins.includes(`${match[1]}/${match[2]}`)) { + processingString = processingString.replace(match[0], `/plugins/${match[2]}`); + } + }); + + return processingString; };