feat: инициализировать пакет генерации SVG-спрайтов

- создан NPM-пакет @gromlab/svg-sprites (ESM, TypeScript)
- реализован CLI через citty и программный API
- добавлена компиляция SVG в спрайты (stack/symbol) через svg-sprite
- добавлена генерация TypeScript union-типов имён иконок
- реализованы SVG-трансформации: замена цветов на CSS-переменные,
  удаление width/height, добавление transition к элементам с цветом
- добавлен генератор HTML-превью с color picker-ами, авто-темой,
  синхронизацией currentColor с темой и поиском по иконкам
- добавлены тестовые SVG-файлы (icons, logos)
This commit is contained in:
2026-04-21 23:07:34 +03:00
commit aad1c97f50
24 changed files with 3888 additions and 0 deletions

78
src/cli.ts Normal file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/env node
import { defineCommand, runMain } from 'citty'
import { generate } from './generate.js'
import { log } from './logger.js'
const main = defineCommand({
meta: {
name: 'svg-sprites',
version: '0.1.0',
description: 'Generate SVG sprites and TypeScript icon name types',
},
args: {
input: {
type: 'string',
alias: 'i',
description: 'Directory with SVG subfolders (each subfolder = one sprite)',
required: true,
},
output: {
type: 'string',
alias: 'o',
description: 'Output directory for generated SVG sprite files',
required: true,
},
types: {
type: 'boolean',
alias: 't',
description: 'Generate TypeScript union types for icon names (default: true)',
default: true,
},
typesOutput: {
type: 'string',
description: 'Output directory for .generated.ts files (default: same as input)',
},
removeSize: {
type: 'boolean',
description: 'Remove width/height from root <svg> (default: true)',
default: true,
},
replaceColors: {
type: 'boolean',
description: 'Replace colors with CSS variables var(--icon-color-N) (default: true)',
default: true,
},
addTransition: {
type: 'boolean',
description: 'Add transition:fill,stroke to colored elements (default: true)',
default: true,
},
preview: {
type: 'boolean',
alias: 'p',
description: 'Generate HTML preview page with all icons (default: true)',
default: true,
},
},
async run({ args }) {
try {
await generate({
input: args.input,
output: args.output,
types: args.types,
typesOutput: args.typesOutput,
transform: {
removeSize: args.removeSize,
replaceColors: args.replaceColors,
addTransition: args.addTransition,
},
preview: args.preview,
})
} catch (error) {
log.error(error instanceof Error ? error.message : String(error))
process.exit(1)
}
},
})
runMain(main)