re-svg-pack 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +49 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +44 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Garik Harutyunyan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE OR OTHERWISE,
|
|
20
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
21
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# re-svg
|
|
2
|
+
|
|
3
|
+
A modern CLI tool and library for generating icon fonts from SVG files.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **CLI command**: `icon-gen` - Generate icon fonts from SVG folders directly from terminal
|
|
8
|
+
- **Library API**: Programmatic access to icon font generation
|
|
9
|
+
- **Multiple formats**: Generates WOFF2, WOFF, TTF, and EOT fonts
|
|
10
|
+
- **CSS output**: Automatic CSS stylesheet generation for easy font usage
|
|
11
|
+
- **TypeScript**: Full TypeScript support with type definitions
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### Global CLI
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g re-svg
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then use the CLI:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
icon-gen --input ./icons --output ./fonts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### As a Library
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install re-svg
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then use programmatically:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { generateIconFont } from 're-svg';
|
|
37
|
+
|
|
38
|
+
await generateIconFont({
|
|
39
|
+
inputDir: './icons',
|
|
40
|
+
outputDir: './fonts',
|
|
41
|
+
fontName: 'my-icons'
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## CLI Usage
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
icon-gen --input <path> --output <path> [options]
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Required Arguments
|
|
52
|
+
|
|
53
|
+
- `--input, -i <path>` — Directory containing SVG files to convert
|
|
54
|
+
- `--output, -o <path>` — Directory where generated fonts will be saved
|
|
55
|
+
|
|
56
|
+
### Optional Arguments
|
|
57
|
+
|
|
58
|
+
- `--name, -n <name>` — Font family name (default: `re-svg-icons`)
|
|
59
|
+
- `--formats, -f <formats>` — Comma-separated list of font formats (default: `woff2,woff,ttf`)
|
|
60
|
+
- Available: `woff2`, `woff`, `ttf`, `eot`
|
|
61
|
+
|
|
62
|
+
### Examples
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Basic usage with defaults
|
|
66
|
+
icon-gen --input ./my-icons --output ./dist
|
|
67
|
+
|
|
68
|
+
# Custom font name and specific formats
|
|
69
|
+
icon-gen -i ./icons -o ./fonts -n "custom-icons" -f "woff2,ttf"
|
|
70
|
+
|
|
71
|
+
# Help
|
|
72
|
+
icon-gen --help
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Library API
|
|
76
|
+
|
|
77
|
+
### `generateIconFont(config)`
|
|
78
|
+
|
|
79
|
+
Generate icon fonts programmatically.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { generateIconFont } from 're-svg';
|
|
83
|
+
|
|
84
|
+
interface IconFontConfig {
|
|
85
|
+
inputDir: string; // Required: Input SVG directory
|
|
86
|
+
outputDir: string; // Required: Output directory
|
|
87
|
+
fontName?: string; // Optional: Font family name (default: 're-svg-icons')
|
|
88
|
+
formats?: string[]; // Optional: Font formats array (default: ['woff2', 'woff', 'ttf'])
|
|
89
|
+
fontsUrl?: string; // Optional: CSS font URL path
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const config: IconFontConfig = {
|
|
93
|
+
inputDir: './icons',
|
|
94
|
+
outputDir: './dist',
|
|
95
|
+
fontName: 'my-icons',
|
|
96
|
+
formats: ['woff2', 'ttf']
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
await generateIconFont(config);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## System Requirements
|
|
103
|
+
|
|
104
|
+
### fontforge
|
|
105
|
+
|
|
106
|
+
`re-svg` requires `fontforge` to be installed on your system:
|
|
107
|
+
|
|
108
|
+
- **macOS**: `brew install fonttools`
|
|
109
|
+
- **Ubuntu/Debian**: `sudo apt-get install fontforge`
|
|
110
|
+
- **Windows**: Included with Node.js build tools. If missing, install via [FontForge releases](https://fontforge.org/en-US/downloads/)
|
|
111
|
+
|
|
112
|
+
## v0.1.0 Scope
|
|
113
|
+
|
|
114
|
+
This is the minimal viable product (MVP) version of re-svg. It focuses on:
|
|
115
|
+
|
|
116
|
+
- ✅ Simple CLI interface for font generation
|
|
117
|
+
- ✅ Basic library wrapper around Fantasticon
|
|
118
|
+
- ✅ Standard font formats (WOFF2, WOFF, TTF, EOT)
|
|
119
|
+
- ✅ CSS stylesheet generation
|
|
120
|
+
|
|
121
|
+
Future versions will include:
|
|
122
|
+
|
|
123
|
+
- Custom templates
|
|
124
|
+
- Icon aliasing
|
|
125
|
+
- SCSS/LESS stylesheet support
|
|
126
|
+
- Multiple font variants
|
|
127
|
+
- Icon metadata export
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
package/lib/cli.d.ts
ADDED
package/lib/cli.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const package_json_1 = require("../package.json");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
async function main() {
|
|
8
|
+
commander_1.program
|
|
9
|
+
.name('icon-gen')
|
|
10
|
+
.description('Generate icon fonts from SVG files')
|
|
11
|
+
.version(package_json_1.version);
|
|
12
|
+
commander_1.program
|
|
13
|
+
.requiredOption('-i, --input <path>', 'Input directory containing SVG files')
|
|
14
|
+
.requiredOption('-o, --output <path>', 'Output directory for generated fonts')
|
|
15
|
+
.option('-n, --name <name>', 'Font family name', 're-svg-icons')
|
|
16
|
+
.option('-f, --formats <formats>', 'Comma-separated font formats (woff2,woff,ttf,eot)', 'woff2,woff,ttf,eot')
|
|
17
|
+
.option('--fonts-url <url>', 'CSS font URL path', '')
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
try {
|
|
20
|
+
const fontTypes = options.formats.split(',').map((f) => f.trim());
|
|
21
|
+
console.log(`Generating icon font from: ${options.input}`);
|
|
22
|
+
console.log(`Output directory: ${options.output}`);
|
|
23
|
+
console.log(`Font name: ${options.name}`);
|
|
24
|
+
console.log(`Formats: ${fontTypes.join(', ')}`);
|
|
25
|
+
await (0, index_1.generateIconFont)({
|
|
26
|
+
inputDir: options.input,
|
|
27
|
+
outputDir: options.output,
|
|
28
|
+
name: options.name,
|
|
29
|
+
fontTypes,
|
|
30
|
+
fontsUrl: options.fontsUrl
|
|
31
|
+
});
|
|
32
|
+
console.log('✓ Icon font generated successfully!');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error instanceof Error) {
|
|
36
|
+
console.error('✗ Error:', error.message);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.error('✗ Unknown error occurred');
|
|
40
|
+
}
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
commander_1.program.parse(process.argv);
|
|
45
|
+
}
|
|
46
|
+
main().catch((error) => {
|
|
47
|
+
console.error('Fatal error:', error);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface IconFontConfig {
|
|
2
|
+
inputDir: string;
|
|
3
|
+
outputDir: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
fontTypes?: string[];
|
|
6
|
+
assetTypes?: string[];
|
|
7
|
+
fontsUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate icon fonts from SVG files
|
|
11
|
+
* @param config Configuration for icon font generation
|
|
12
|
+
* @throws Error if inputDir doesn't exist or SVG files cannot be processed
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateIconFont(config: IconFontConfig): Promise<void>;
|
|
15
|
+
export default generateIconFont;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateIconFont = generateIconFont;
|
|
4
|
+
const fantasticon_1 = require("fantasticon");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
/**
|
|
7
|
+
* Generate icon fonts from SVG files
|
|
8
|
+
* @param config Configuration for icon font generation
|
|
9
|
+
* @throws Error if inputDir doesn't exist or SVG files cannot be processed
|
|
10
|
+
*/
|
|
11
|
+
async function generateIconFont(config) {
|
|
12
|
+
const { inputDir, outputDir, name = 're-svg-icons', fontTypes = [fantasticon_1.FontAssetType.WOFF2, fantasticon_1.FontAssetType.WOFF, fantasticon_1.FontAssetType.TTF, fantasticon_1.FontAssetType.EOT], assetTypes = [fantasticon_1.OtherAssetType.CSS, fantasticon_1.OtherAssetType.JSON, fantasticon_1.OtherAssetType.HTML], fontsUrl = './' } = config;
|
|
13
|
+
// Validate input directory exists
|
|
14
|
+
try {
|
|
15
|
+
await fs_1.promises.access(inputDir);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error(`Input directory does not exist: ${inputDir}`);
|
|
19
|
+
}
|
|
20
|
+
// Create output directory if it doesn't exist
|
|
21
|
+
try {
|
|
22
|
+
await fs_1.promises.mkdir(outputDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`Cannot create output directory: ${outputDir}`);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await (0, fantasticon_1.generateFonts)({
|
|
29
|
+
inputDir,
|
|
30
|
+
outputDir,
|
|
31
|
+
name,
|
|
32
|
+
fontTypes: fontTypes,
|
|
33
|
+
assetTypes: assetTypes,
|
|
34
|
+
fontsUrl
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof Error) {
|
|
39
|
+
throw new Error(`Font generation failed: ${error.message}`);
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = generateIconFont;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "re-svg-pack",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A CLI tool and library for generating icon fonts from SVG files.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Garik Harutyunyan",
|
|
7
|
+
"homepage": "https://github.com/GarikHarutyunyan/re-svg",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/GarikHarutyunyan/re-svg.git"
|
|
11
|
+
},
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"types": "lib/index.d.ts",
|
|
14
|
+
"bin": {
|
|
15
|
+
"icon-gen": "lib/cli.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"types",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"prepublishOnly": "npm run build && npm run test:pack",
|
|
27
|
+
"test:pack": "npm pack --dry-run"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"svg",
|
|
31
|
+
"icon",
|
|
32
|
+
"font",
|
|
33
|
+
"icon-font",
|
|
34
|
+
"cli",
|
|
35
|
+
"fantasticon"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"fantasticon": "^2.0.0",
|
|
39
|
+
"commander": "^11.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"typescript": "^5.3.3",
|
|
43
|
+
"@types/node": "^20.10.6"
|
|
44
|
+
},
|
|
45
|
+
"overrides": {
|
|
46
|
+
"fantasticon": {
|
|
47
|
+
"glob": "7.2.0"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|