@jayson991/svg2font-cli 0.0.2

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.
Files changed (3) hide show
  1. package/README.md +147 -0
  2. package/bin/svg2font.js +33 -0
  3. package/package.json +39 -0
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # @jayson991/svg2font-cli
2
+
3
+ > Convert SVG icon sets into complete iconfont bundles — CLI tool
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@jayson991/svg2font-cli.svg)](https://www.npmjs.com/package/@jayson991/svg2font-cli)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+ [![Node.js Version](https://img.shields.io/node/v/@jayson991/svg2font-cli.svg)](https://nodejs.org/)
8
+
9
+ A pre-compiled Rust binary distributed as a platform-specific npm package. No Node.js build tools or native compilation required at install time.
10
+
11
+ For the programmatic TypeScript/napi API, see [`@jayson991/svg2font`](../svg2font/README.md).
12
+
13
+ ## Requirements
14
+
15
+ - Node.js 18 or higher
16
+ - One of: macOS (arm64/x64), Linux (arm64/x64), Windows (x64)
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ # Global CLI
22
+ npm install -g @jayson991/svg2font-cli
23
+
24
+ # Or with pnpm
25
+ pnpm add -g @jayson991/svg2font-cli
26
+
27
+ # Or with yarn
28
+ yarn global add @jayson991/svg2font-cli
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ **Step 1:** Place your SVG icons in a folder:
34
+
35
+ ```
36
+ icons/
37
+ ├── home.svg
38
+ ├── user.svg
39
+ └── settings.svg
40
+ ```
41
+
42
+ **Step 2:** Run the command:
43
+
44
+ ```bash
45
+ svg2font --src "icons/**/*.svg" --dist dist --font-name myicons
46
+ ```
47
+
48
+ **Step 3:** Unzip and use the output:
49
+
50
+ ```
51
+ dist/
52
+ └── myicons/
53
+ ├── myicons.ttf
54
+ ├── myicons.woff
55
+ ├── myicons.woff2
56
+ ├── myicons.eot
57
+ ├── myicons.svg
58
+ ├── myicons.css
59
+ ├── myicons.js
60
+ ├── myicons.symbol.svg
61
+ ├── myicons.json
62
+ ├── demo.html
63
+ └── demo.css
64
+ ```
65
+
66
+ Open `demo.html` to preview all icons and copy usage code snippets.
67
+
68
+ ## CLI Options
69
+
70
+ | Option | Alias | Default | Description |
71
+ |--------|-------|---------|-------------|
72
+ | `--src` | `-s` | `svg/**/*.svg` | Glob pattern for source SVG files |
73
+ | `--dist` | `-d` | `dist` | Output directory |
74
+ | `--font-name` | `-n` | `iconfont` | Font family name (used in file names and CSS) |
75
+ | `--prefix` | `-p` | `icon` | CSS class prefix (e.g. `icon-home`) |
76
+ | `--start-unicode` | — | `e001` | Starting Unicode codepoint (hex, e.g. `e001`) |
77
+ | `--help` | `-h` | — | Show help |
78
+ | `--version` | `-V` | — | Show version |
79
+
80
+ ## Output Bundle
81
+
82
+ The command generates a directory at `dist/{font-name}/` containing:
83
+
84
+ | File | Description |
85
+ |------|-------------|
86
+ | `{name}.ttf` | TrueType font |
87
+ | `{name}.woff` | WOFF font (zlib compressed) |
88
+ | `{name}.woff2` | WOFF2 font (brotli compressed) |
89
+ | `{name}.eot` | EOT font (IE11 support) |
90
+ | `{name}.svg` | SVG font |
91
+ | `{name}.css` | Stylesheet with `@font-face` and all three usage methods |
92
+ | `{name}.js` | SVG sprite auto-injector script |
93
+ | `{name}.symbol.svg` | SVG sprite definitions |
94
+ | `{name}.json` | Glyph metadata (names, codepoints) |
95
+ | `demo.html` | Interactive preview page |
96
+ | `demo.css` | Demo page styles |
97
+
98
+ ## Three Usage Methods
99
+
100
+ ### 1. Unicode Mode
101
+
102
+ ```html
103
+ <link rel="stylesheet" href="myicons.css">
104
+ <span class="iconfont">&#xe001;</span>
105
+ ```
106
+
107
+ ### 2. Font Class Mode (recommended)
108
+
109
+ ```html
110
+ <link rel="stylesheet" href="myicons.css">
111
+ <i class="iconfont icon-home"></i>
112
+ <i class="iconfont icon-user"></i>
113
+ ```
114
+
115
+ ### 3. SVG Symbol Mode
116
+
117
+ ```html
118
+ <script src="myicons.js"></script>
119
+ <svg class="icon" aria-hidden="true">
120
+ <use href="#icon-home"></use>
121
+ </svg>
122
+ ```
123
+
124
+ ## SVG File Requirements
125
+
126
+ - Valid SVG with `<path>` elements
127
+ - `viewBox` attribute (or `width`/`height`)
128
+ - No external dependencies (linked images, external CSS)
129
+ - Single color recommended for font mode
130
+
131
+ Filenames are automatically converted to kebab-case:
132
+ - `home.svg` → `.icon-home`
133
+ - `Arrow Right.svg` → `.icon-arrow-right`
134
+
135
+ ## Platform Support
136
+
137
+ | Platform | Architecture |
138
+ |----------|-------------|
139
+ | macOS | arm64 (Apple Silicon) |
140
+ | macOS | x64 (Intel) |
141
+ | Linux | x64 |
142
+ | Linux | arm64 |
143
+ | Windows | x64 |
144
+
145
+ ## License
146
+
147
+ MIT © [Jayson Wu](https://github.com/jaysonwu991)
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ let node_child_process = require("node:child_process");
3
+ //#region src/svg2font.ts
4
+ var TARGETS = {
5
+ darwin: {
6
+ arm64: "@jayson991/svg2font-cli-darwin-arm64/svg2font",
7
+ x64: "@jayson991/svg2font-cli-darwin-x64/svg2font"
8
+ },
9
+ linux: {
10
+ arm64: "@jayson991/svg2font-cli-linux-arm64/svg2font",
11
+ x64: "@jayson991/svg2font-cli-linux-x64/svg2font"
12
+ },
13
+ win32: { x64: "@jayson991/svg2font-cli-win32-x64/svg2font.exe" }
14
+ };
15
+ var { platform, arch } = process;
16
+ var pkgBin = process.env.SVG2FONT_BINARY ?? TARGETS[platform]?.[arch];
17
+ if (!pkgBin) {
18
+ console.error(`svg2font-cli: unsupported platform ${platform}/${arch}\n Supported: darwin/arm64, darwin/x64, linux/arm64, linux/x64, win32/x64\n You can set SVG2FONT_BINARY to a binary path to override.`);
19
+ process.exit(1);
20
+ }
21
+ var binPath;
22
+ try {
23
+ binPath = require.resolve(pkgBin);
24
+ } catch {
25
+ console.error(`svg2font-cli: could not find the binary for ${platform}/${arch}.\n Try reinstalling: npm install @jayson991/svg2font-cli\n If using --no-optional, remove that flag so platform packages are installed.`);
26
+ process.exit(1);
27
+ }
28
+ var result = (0, node_child_process.spawnSync)(binPath, process.argv.slice(2), {
29
+ stdio: "inherit",
30
+ shell: false
31
+ });
32
+ process.exitCode = result.status ?? 1;
33
+ //#endregion
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@jayson991/svg2font-cli",
3
+ "version": "0.0.2",
4
+ "description": "Generate icon fonts from SVG files — CLI",
5
+ "bin": {
6
+ "svg2font": "bin/svg2font.js"
7
+ },
8
+ "files": [
9
+ "bin/"
10
+ ],
11
+ "engines": {
12
+ "node": ">=18"
13
+ },
14
+ "scripts": {
15
+ "build": "vite build",
16
+ "typecheck": "tsc"
17
+ },
18
+ "optionalDependencies": {
19
+ "@jayson991/svg2font-cli-darwin-arm64": "0.0.2",
20
+ "@jayson991/svg2font-cli-darwin-x64": "0.0.2",
21
+ "@jayson991/svg2font-cli-linux-arm64": "0.0.2",
22
+ "@jayson991/svg2font-cli-linux-x64": "0.0.2",
23
+ "@jayson991/svg2font-cli-win32-x64": "0.0.2"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^24.0.0",
27
+ "typescript": "^5.0.0",
28
+ "vite": "^8.0.16"
29
+ },
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/jaysonwu991/svg2font"
34
+ },
35
+ "homepage": "https://github.com/jaysonwu991/svg2font/tree/main/packages/svg2font-cli",
36
+ "bugs": {
37
+ "url": "https://github.com/jaysonwu991/svg2font/issues"
38
+ }
39
+ }