/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
canary
docs/scripts/syncTeamMembers.ts
86 строк
3 KB
Brijesh Bittu
[code-infra] Automate team sync on about page (#48794)
15 июл 2026, 17:22
Не верифицирован
15 июл 2026, 17:22
7dd3a10
Код
Авторство
О чём код?
/* eslint-disable no-console */ import url from 'url'; import * as fs from 'fs/promises'; import path from 'path'; import getMemberImageFile from '../src/components/about/getMemberImageFile'; interface Person { name: string; } const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url)); const teamMembersPath = path.resolve(currentDirectory, '../data/about/teamMembers.json'); const imagesDirectory = path.resolve(currentDirectory, '../public/static/branding/about'); async function fileExists(filePath: string) { try { await fs.access(filePath); return true; } catch { return false; } } async function readCurrentMembers(): Promise<Person[]> { if (!(await fileExists(teamMembersPath))) { return []; } return JSON.parse(await fs.readFile(teamMembersPath, 'utf8')); } // Delete images of removed members and report new members missing a photo. async function syncImagesAndSummary(previousMembers: Person[], people: Person[]) { const previousNames = new Set(previousMembers.map((person) => person.name)); const nextNames = new Set(people.map((person) => person.name)); const added = people.filter((person) => !previousNames.has(person.name)); const removed = previousMembers.filter((person) => !nextNames.has(person.name)); // Delete images of members who are no longer part of the team. await Promise.all( removed.map(async (person) => { const imagePath = path.join(imagesDirectory, getMemberImageFile(person)); if (await fileExists(imagePath)) { await fs.unlink(imagePath); } }), ); // Flag new members whose image still needs to be added manually. const missingImages = ( await Promise.all( added.map(async (person) => { const fileName = getMemberImageFile(person); const exists = await fileExists(path.join(imagesDirectory, fileName)); return exists ? null : `${person.name} (\`${fileName}\`)`; }), ) ).filter((item): item is string => item !== null); const summary = missingImages.length ? `### ⚠️ Missing images Add a photo for the following new members to \`docs/public/static/branding/about/\`: ${missingImages.map((entry) => `- ${entry}`).join('\n')}` : ''; if (summary) { console.log(summary); } } async function run() { const previousMembers = await readCurrentMembers(); const response = await fetch('https://frontend-public.mui.com/api/mui-about'); if (!response.ok || response.status !== 200) { throw new Error(`Failed to fetch team members: ${response.status} ${response.statusText}`); } const { people }: { people: Person[] } = await response.json(); await fs.writeFile(teamMembersPath, JSON.stringify(people), 'utf8'); await syncImagesAndSummary(previousMembers, people); } run();