refactor: заменить shiki на самописный highlighter и обновить архитектуру
- Удалён shiki (9.5→0 МБ), создан regex-токенизатор для html/css/xml - CLI переведён с аргументов на конфиг-файл svg-sprites.config.ts - Превью переработано: React-приложение вместо инлайн HTML - Добавлен футер с названием пакета и ссылкой на репозиторий - Исправлена загрузка dev-data.js для Vite 8 - Футер прижат к низу, содержимое центрировано
This commit is contained in:
84
src/cli.ts
84
src/cli.ts
@@ -1,78 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
import { defineCommand, runMain } from 'citty'
|
||||
import { loadConfig } from './config.js'
|
||||
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)
|
||||
}
|
||||
},
|
||||
})
|
||||
async function main() {
|
||||
try {
|
||||
const config = await loadConfig()
|
||||
await generate(config)
|
||||
} catch (error) {
|
||||
log.error(error instanceof Error ? error.message : String(error))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
runMain(main)
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user