From 28ca6c5c7a68d0bf65d314168d006948c28f98d6 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 18 Feb 2023 18:05:46 +0530 Subject: [PATCH] chore: use custom script --- .github/workflows/ci.yml | 6 ++++-- package-lock.json | 1 + package.json | 5 +++-- tools/validate-links.js | 44 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 tools/validate-links.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9e62ee15..ef2c8a6f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,9 @@ jobs: run: npm ci - name: Install playground dependencies run: npm run install:playground - - name: Run build - run: npm run build - name: Lint Files run: npm run lint + - name: Run build + run: npm run build + - name: Validate Internal Links + run: npm run validate:links diff --git a/package-lock.json b/package-lock.json index c77ff880f..908da2ae8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,6 +42,7 @@ "@babel/core": "^7.17.5", "@babel/preset-env": "^7.16.11", "@babel/preset-react": "^7.16.7", + "@munter/tap-render": "^0.2.0", "@octokit/graphql": "^4.8.0", "@octokit/rest": "^18.12.0", "babel-loader": "^8.2.3", diff --git a/package.json b/package.json index 05a3c9e9b..7296761c0 100644 --- a/package.json +++ b/package.json @@ -29,15 +29,15 @@ "start": "npm-run-all build:sass --parallel watch:*", "build": "npm-run-all install:playground build:sass build:eleventy build:webpack images", "minify:svg": "svgo -r -f ./", + "validate:links": "cross-env NODE_OPTIONS=--max-old-space-size=4096 node tools/validate-links.js", "lint:js": "eslint --ext=.js,.jsx .", "lint:md": "markdownlint \"**/*.md\" ", "lint:scss": "stylelint \"**/*.scss\"", - "lint:links": "hyperlink ./_site/index.html --canonicalroot https://eslint.org/ -r --internal ./_site/index.html --pretty --skip https:// --skip _site/sponsors --skip _site/docs > internal-links.tap; cat internal-links.tap | tap-spot", "lint": "npm-run-all --parallel lint:*", "lint:fix:js": "eslint --ext=.js,.jsx . --fix", "lint:fix:scss": "stylelint \"**/*.scss\" --fix", "lint:fix:md": "markdownlint --fix \"**/*.md\"", - "fix": "npm-run-all --parallel lint:fix:*" + "fix": "npm-run-all --parallel lint:fix:*", }, "lint-staged": { "**/*.{js,jsx}": "eslint --fix", @@ -57,6 +57,7 @@ "@babel/core": "^7.17.5", "@babel/preset-env": "^7.16.11", "@babel/preset-react": "^7.16.7", + "@munter/tap-render": "^0.2.0", "@octokit/graphql": "^4.8.0", "@octokit/rest": "^18.12.0", "babel-loader": "^8.2.3", diff --git a/tools/validate-links.js b/tools/validate-links.js new file mode 100644 index 000000000..e99d56eee --- /dev/null +++ b/tools/validate-links.js @@ -0,0 +1,44 @@ +const path = require("path"); +const TapRender = require("@munter/tap-render"); +const spot = require("tap-spot"); +const hyperlink = require("hyperlink"); + +const tapRenderInstance = new TapRender(); + +tapRenderInstance.pipe(spot()).pipe(process.stdout); + +const skipPatterns = [ + "https://", + "fragment-redirect", + "_site/sponsors", + "_site/docs" +]; + +const skipFilter = (report) => + Object.values(report).some((value) => + skipPatterns.some((pattern) => String(value).includes(pattern)) + ); + +(async () => { + try { + await hyperlink( + { + inputUrls: ["../_site/index.html"], + root: path.resolve(__dirname, "../_site"), + canonicalRoot: "https://eslint.org/", + recursive: true, + internalOnly: true, + pretty: true, + concurrency: 25, + skipFilter, + }, + tapRenderInstance + ); + } catch (err) { + console.log(err.stack); + process.exit(1); + } + const results = t.close(); + + process.exit(results.fail ? 1 : 0); +})();