Tooling@accelint/smeegle
smeegl
Programmatic API for generating spritesheets and React components from SVG files
Usage
import { smeegl } from '@accelint/smeegl/lib';
// Generate spritesheet
await smeegl(
process.cwd(),
'**/*.svg',
'./atlas',
'spreet',
null,
'./icons',
'',
'SPRITESHEET'
);
// Generate React components
await smeegl(
process.cwd(),
'',
'./components',
'spreet',
null,
'./icons',
'',
'REACT'
);Reference
async function smeegl(
rootPath: string,
glob: string,
out: string,
spreet?: string,
crcMode?: CrcType | null,
inOpt?: string,
outOpt?: string,
target?: TargetType
): Promise<void>Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
rootPath | string | Root directory path for resolving relative paths | |
glob | string | Glob pattern for finding SVG files. Can be blank if inOpt is provided. | |
out | string | Base output path for generated files | |
spreet | string | undefined | Path to spreet binary | 'spreet' |
crcMode | CrcType | null | Convert sprite names to CRC32 ('DEC' or 'HEX') | null |
inOpt | string | Input directory to scan for SVG files (alternative to glob) | '' |
outOpt | string | Override output path (takes precedence over out) | '' |
target | TargetType | Output type: 'SPRITESHEET' or 'REACT' | 'SPRITESHEET' |
Returns
Returns a Promise<void> that resolves when generation is complete.
Type Parameters
CrcType: 'DEC' | 'HEX'
- Controls whether CRC32 sprite names use decimal or hexadecimal encoding
TargetType: 'SPRITESHEET' | 'REACT'
SPRITESHEET- Generates PNG atlas + JSON index + TypeScript constantsREACT- Generates folder of React SVG components
Examples
Example: Generate spritesheet with glob pattern
import { smeegl } from '@accelint/smeegl/lib';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
await smeegl(
__dirname, // rootPath
'assets/icons/**/*.svg', // glob pattern
'./public/sprites', // output path
'spreet', // spreet binary
null, // no CRC encoding
'', // no input dir (using glob)
'', // no output override
'SPRITESHEET' // target type
);
// Generates:
// ./public/sprites/atlas.png
// ./public/sprites/atlas.json
// ./public/sprites/atlas.tsExample: Generate React components from directory
import { smeegl } from '@accelint/smeegl/lib';
await smeegl(
process.cwd(),
'', // no glob (using directory)
'./src/components/icons', // output path
'spreet',
null,
'./design-system/icons', // input directory
'',
'REACT'
);
// Generates:
// ./src/components/icons/arrow.tsx
// ./src/components/icons/arrow-down.tsx
// ./src/components/icons/index.tsExample: CRC-encoded sprite names
import { smeegl } from '@accelint/smeegl/lib';
await smeegl(
process.cwd(),
'icons/**/*.svg',
'./sprites',
'spreet',
'HEX', // Use hexadecimal CRC32
'',
'',
'SPRITESHEET'
);
// Sprite names become CRC32 hashes:
// arrow.svg → a3f2d4e1
// arrow-down.svg → b7c8e9f3Example: Custom spreet binary path
import { smeegl } from '@accelint/smeegl/lib';
await smeegl(
process.cwd(),
'icons/**/*.svg',
'./atlas',
'/usr/local/bin/spreet-custom', // Custom binary
null,
'',
'',
'SPRITESHEET'
);Example: Build script integration
// build-sprites.ts
import { smeegl } from '@accelint/smeegl/lib';
async function buildSprites() {
console.log('Building spritesheets...');
await smeegl(
process.cwd(),
'assets/ui/**/*.svg',
'./public/sprites/ui',
'spreet',
null,
'',
'',
'SPRITESHEET'
);
await smeegl(
process.cwd(),
'assets/markers/**/*.svg',
'./public/sprites/markers',
'spreet',
'HEX',
'',
'',
'SPRITESHEET'
);
console.log('✓ Spritesheets built');
}
buildSprites().catch(console.error);Good to know: The function validates input parameters and creates temporary directories automatically. Errors during generation are thrown as exceptions.
Good to know: When
globis empty,inOptmust be a valid directory path. Whenglobis provided, it takes precedence overinOpt.
Related
- buildSpritesheet - Core spritesheet generation logic
- buildReactFiles - Core React component generation logic
- validateInput - Input validation utilities