11#!/usr/bin/env node
22
33// Imports
4- const { existsSync, readFileSync} = require ( 'fs' ) ;
5- const { join, resolve} = require ( 'path' ) ;
4+ const { existsSync, readFileSync, statSync } = require ( 'fs' ) ;
5+ const { basename , join, resolve} = require ( 'path' ) ;
66
77// Constants
8+ const MAX_IMAGE_SIZE = 30 * 1024 ; // 30kb
89const CONTENT_DIR = resolve ( __dirname , '../../content' ) ;
910const IMAGES_DIR = join ( CONTENT_DIR , 'images/bios' ) ;
1011const CONTRIBUTORS_PATH = join ( CONTENT_DIR , 'marketing/contributors.json' ) ;
1112const EXISTING_GROUPS = new Set ( [ 'Angular' , 'GDE' , 'Collaborators' ] ) ;
1213
14+ // The list of profile images that exceed specified `MAX_IMAGE_SIZE` limit.
15+ // These images were added before the size check was introduced. Exclude these images
16+ // from size check for now, but still check other images (more importantly run the check
17+ // for new PRs where profile images are added).
18+ const EXCLUDE_FROM_SIZE_CHECK = new Set ( [
19+ 'alainchautard.png' , 'ahsanayaz.jpg' , 'alan-agius4.jpg' , 'andrew-kushnir.jpg' ,
20+ 'brian-love.jpg' , 'cexbrayat.jpg' , 'christianliebel.jpg' , 'patovargas.png' , 'gerardsans.jpg' ,
21+ 'jessicajaniuk.jpg' , 'JiaLiPassion.jpg' , 'juristr.jpg' , 'katerina.jpg' , 'kimmaida.jpg' ,
22+ 'kyliau.jpg' , 'lacolaco.jpg' , 'leonardo.jpg' , 'nirkaufman.jpg' , 'sajee.jpg' , 'sonukapoor.jpg' ,
23+ 'tracylee.jpg' , 'twerske.jpg' , 'wesgrimes.jpg'
24+ ] ) ;
25+
1326// Run
1427_main ( ) ;
1528
@@ -29,6 +42,16 @@ function _main() {
2942 missingImages . map ( path => `\n - ${ path } ` ) . join ( '' ) ) ;
3043 }
3144
45+ // Check that there are no images that exceed the size limit.
46+ const tooLargeImages = expectedImages
47+ . filter ( path => ! EXCLUDE_FROM_SIZE_CHECK . has ( basename ( path ) ) )
48+ . filter ( path => statSync ( path ) . size > MAX_IMAGE_SIZE ) ;
49+ if ( tooLargeImages . length > 0 ) {
50+ throw new Error (
51+ `The following pictures exceed maximum size limit of ${ MAX_IMAGE_SIZE / 1024 } kb:` +
52+ tooLargeImages . map ( path => `\n - ${ path } ` ) . join ( '' ) ) ;
53+ }
54+
3255 // Verify that all keys are sorted alphabetically
3356 const keys = Object . keys ( contributors ) ;
3457 for ( let i = 1 ; i < keys . length ; i ++ ) {
0 commit comments