ci: check that there are no unused contributor images (#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 #41290
This commit is contained in:
parent
ac66b0199e
commit
80f11a9b86
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
// Imports
|
// Imports
|
||||||
const {existsSync, readFileSync, statSync} = require('fs');
|
const {readdirSync, readFileSync, statSync} = require('fs');
|
||||||
const {join, resolve} = require('path');
|
const {join, resolve} = require('path');
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
@ -17,19 +17,29 @@ _main();
|
||||||
// Functions - Definitions
|
// Functions - Definitions
|
||||||
function _main() {
|
function _main() {
|
||||||
const contributors = JSON.parse(readFileSync(CONTRIBUTORS_PATH, 'utf8'));
|
const contributors = JSON.parse(readFileSync(CONTRIBUTORS_PATH, 'utf8'));
|
||||||
|
|
||||||
// Check that there are no missing images.
|
|
||||||
const expectedImages = Object.keys(contributors)
|
const expectedImages = Object.keys(contributors)
|
||||||
.filter(key => !!contributors[key].picture)
|
.filter(key => !!contributors[key].picture)
|
||||||
.map(key => join(IMAGES_DIR, contributors[key].picture));
|
.map(key => join(IMAGES_DIR, contributors[key].picture));
|
||||||
const missingImages = expectedImages.filter(path => !existsSync(path));
|
const existingImages = readdirSync(IMAGES_DIR)
|
||||||
|
.filter(name => name !== '_no-one.jpg')
|
||||||
|
.map(name => join(IMAGES_DIR, name));
|
||||||
|
|
||||||
|
// Check that there are no missing images.
|
||||||
|
const missingImages = expectedImages.filter(path => !existingImages.includes(path));
|
||||||
if (missingImages.length > 0) {
|
if (missingImages.length > 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The following pictures are referenced in \'contributors.json\' but do not exist:' +
|
'The following pictures are referenced in \'contributors.json\' but do not exist:' +
|
||||||
missingImages.map(path => `\n - ${path}`).join(''));
|
missingImages.map(path => `\n - ${path}`).join(''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that there are no unused images.
|
||||||
|
const unusedImages = existingImages.filter(path => !expectedImages.includes(path));
|
||||||
|
if (unusedImages.length > 0) {
|
||||||
|
throw new Error(
|
||||||
|
'The following pictures are not referenced in \'contributors.json\' and should be deleted:' +
|
||||||
|
unusedImages.map(path => `\n - ${path}`).join(''));
|
||||||
|
}
|
||||||
|
|
||||||
// Check that there are no images that exceed the size limit.
|
// Check that there are no images that exceed the size limit.
|
||||||
const tooLargeImages = expectedImages.filter(path => statSync(path).size > MAX_IMAGE_SIZE);
|
const tooLargeImages = expectedImages.filter(path => statSync(path).size > MAX_IMAGE_SIZE);
|
||||||
if (tooLargeImages.length > 0) {
|
if (tooLargeImages.length > 0) {
|
||||||
|
|
Loading…
Reference in New Issue