/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/src/modules/material/sourceMaterialTemplates.ts
42 строки
1 KB
Siriwat K
[material-ui][docs] Open Material UI template with CodeSandbox/StackBlitz (#43604)
11 сен 2024, 12:30
Не верифицирован
11 сен 2024, 12:30
ff9406a
Код
Авторство
О чём код?
const templateMap = new Map<string, { files: Record<string, string>; codeVariant: 'TS' | 'JS' }>(); let sharedTheme: { files: Record<string, string>; codeVariant: 'TS' | 'JS' } | null = null; // @ts-ignore const req = require.context( '../../../data/material/getting-started/templates/?raw', true, /^\.\/[^/]+\/.*\.(js|tsx|ts)$/, ); req.keys().forEach((key: string) => { const match = /\/(?<name>[^/]+)\/(?<filePath>.*)/.exec(key); if (match) { const name = match.groups?.name; const filePath = match.groups?.filePath; if (name && filePath?.match(/\.(ts|tsx)$/)) { if (name === 'shared-theme') { sharedTheme = { files: { ...sharedTheme?.files, [`theme/${filePath}`]: req(key) }, codeVariant: 'TS', }; } else { templateMap.set(name, { files: { ...templateMap.get(name)?.files, [filePath]: req(key) }, codeVariant: 'TS', }); } } } }); export interface TemplateData { files: Record<string, string>; codeVariant: 'TS' | 'JS'; } export default function sourceMaterialTemplates() { return { names: Array.from(templateMap.keys()), templates: Array.from(templateMap.values()), map: new Map(templateMap), sharedTheme, }; }