feat: добавить entry-point для React-модуля

- добавлена генерация index.ts рядом с React-компонентом

- добавлен тест генерации directory import

- обновлена документация ожидаемого output
This commit is contained in:
2026-05-20 14:02:28 +03:00
parent dab7685cf2
commit 3a60b5c6ae
5 changed files with 69 additions and 3 deletions

View File

@@ -17,10 +17,10 @@ function getIconNames(folder: SpriteFolder): string[] {
}
/**
* Генерирует [name].tsx и [name].module.css — React-компонент с типами.
* Генерирует index.ts, [name].tsx и [name].module.css — React-компонент с типами.
*
* Имена файлов берутся из basename папки outputDir.
* Например: outputDir = 'src/ui/svg-sprite' → svg-sprite.tsx + svg-sprite.module.css.
* Например: outputDir = 'src/ui/svg-sprite' → index.ts + svg-sprite.tsx + svg-sprite.module.css.
*
* Содержит:
* - union-типы имён иконок для каждого спрайта (IconsIconName, LogosIconName, ...)
@@ -175,5 +175,21 @@ export function generateReactModule(
const cssPath = path.join(outputDir, `${baseName}.module.css`)
fs.writeFileSync(cssPath, css)
const index = [
'/** @generated — this file is auto-generated, do not edit manually. */',
`export { SvgSprite } from './${baseName}'`,
'export type {',
' SvgSpriteProps,',
' SpriteName,',
' SpriteMap,',
' IconName,',
' DefaultSprite,',
`} from './${baseName}'`,
'',
].join('\n')
const indexPath = path.join(outputDir, 'index.ts')
fs.writeFileSync(indexPath, index)
return outputPath
}