From 2ccb579e06bc9aac53ccb7ed910333130b74afc7 Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Wed, 17 Mar 2021 16:14:23 -0700 Subject: [PATCH] feat(docs-infra): add profile picture size check (#41253) This commit updates the logic that validates contributors.json data and introduces a new check that verifies that profile images don't exceed specified limit. PR Close #41253 --- aio/scripts/contributors/validate-data.js | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/aio/scripts/contributors/validate-data.js b/aio/scripts/contributors/validate-data.js index 61cedc3b52..b677104fe1 100644 --- a/aio/scripts/contributors/validate-data.js +++ b/aio/scripts/contributors/validate-data.js @@ -1,15 +1,28 @@ #!/usr/bin/env node // Imports -const {existsSync, readFileSync} = require('fs'); -const {join, resolve} = require('path'); +const {existsSync, readFileSync, statSync} = require('fs'); +const {basename, join, resolve} = require('path'); // Constants +const MAX_IMAGE_SIZE = 30 * 1024; // 30kb const CONTENT_DIR = resolve(__dirname, '../../content'); const IMAGES_DIR = join(CONTENT_DIR, 'images/bios'); const CONTRIBUTORS_PATH = join(CONTENT_DIR, 'marketing/contributors.json'); const EXISTING_GROUPS = new Set(['Angular', 'GDE', 'Collaborators']); +// The list of profile images that exceed specified `MAX_IMAGE_SIZE` limit. +// These images were added before the size check was introduced. Exclude these images +// from size check for now, but still check other images (more importantly run the check +// for new PRs where profile images are added). +const EXCLUDE_FROM_SIZE_CHECK = new Set([ + 'alainchautard.png', 'ahsanayaz.jpg', 'alan-agius4.jpg', 'andrew-kushnir.jpg', + 'brian-love.jpg', 'cexbrayat.jpg', 'christianliebel.jpg', 'patovargas.png', 'gerardsans.jpg', + 'jessicajaniuk.jpg', 'JiaLiPassion.jpg', 'juristr.jpg', 'katerina.jpg', 'kimmaida.jpg', + 'kyliau.jpg', 'lacolaco.jpg', 'leonardo.jpg', 'nirkaufman.jpg', 'sajee.jpg', 'sonukapoor.jpg', + 'tracylee.jpg', 'twerske.jpg', 'wesgrimes.jpg' +]); + // Run _main(); @@ -29,6 +42,16 @@ function _main() { missingImages.map(path => `\n - ${path}`).join('')); } + // Check that there are no images that exceed the size limit. + const tooLargeImages = expectedImages + .filter(path => !EXCLUDE_FROM_SIZE_CHECK.has(basename(path))) + .filter(path => statSync(path).size > MAX_IMAGE_SIZE); + if (tooLargeImages.length > 0) { + throw new Error( + `The following pictures exceed maximum size limit of ${MAX_IMAGE_SIZE / 1024}kb:` + + tooLargeImages.map(path => `\n - ${path}`).join('')); + } + // Verify that all keys are sorted alphabetically const keys = Object.keys(contributors); for (let i = 1; i < keys.length; i++) {