Skip to content

Commit 80f11a9

Browse files
gkalpakjosephperrott
authored andcommitted
ci: check that there are no unused contributor images (angular#41290)
When a contributor was removed from `contributors.json`, the corresponding image should also be removed from `aio/content/images/bios/`. However, this was often overlooked, resulting in unused images remaining in `aio/content/images/bios/`. This commit adds a check to ensure that all images in `aio/content/images/bios/` are referenced in `contributors.json`. PR Close angular#41290
1 parent ac66b01 commit 80f11a9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

aio/scripts/contributors/validate-data.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
// Imports
4-
const {existsSync, readFileSync, statSync} = require('fs');
4+
const {readdirSync, readFileSync, statSync} = require('fs');
55
const {join, resolve} = require('path');
66

77
// Constants
@@ -17,19 +17,29 @@ _main();
1717
// Functions - Definitions
1818
function _main() {
1919
const contributors = JSON.parse(readFileSync(CONTRIBUTORS_PATH, 'utf8'));
20-
21-
// Check that there are no missing images.
2220
const expectedImages = Object.keys(contributors)
2321
.filter(key => !!contributors[key].picture)
2422
.map(key => join(IMAGES_DIR, contributors[key].picture));
25-
const missingImages = expectedImages.filter(path => !existsSync(path));
23+
const existingImages = readdirSync(IMAGES_DIR)
24+
.filter(name => name !== '_no-one.jpg')
25+
.map(name => join(IMAGES_DIR, name));
2626

27+
// Check that there are no missing images.
28+
const missingImages = expectedImages.filter(path => !existingImages.includes(path));
2729
if (missingImages.length > 0) {
2830
throw new Error(
2931
'The following pictures are referenced in \'contributors.json\' but do not exist:' +
3032
missingImages.map(path => `\n - ${path}`).join(''));
3133
}
3234

35+
// Check that there are no unused images.
36+
const unusedImages = existingImages.filter(path => !expectedImages.includes(path));
37+
if (unusedImages.length > 0) {
38+
throw new Error(
39+
'The following pictures are not referenced in \'contributors.json\' and should be deleted:' +
40+
unusedImages.map(path => `\n - ${path}`).join(''));
41+
}
42+
3343
// Check that there are no images that exceed the size limit.
3444
const tooLargeImages = expectedImages.filter(path => statSync(path).size > MAX_IMAGE_SIZE);
3545
if (tooLargeImages.length > 0) {

0 commit comments

Comments
 (0)