svger-cli 2.0.6 → 2.0.7
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/.svgerconfig.example.json +119 -119
- package/CHANGELOG.md +144 -156
- package/DEVELOPMENT.md +352 -352
- package/LICENSE +20 -20
- package/README.md +2340 -2654
- package/SECURITY.md +68 -68
- package/bin/svg-tool.js +2 -2
- package/dist/core/framework-templates.d.ts +1 -0
- package/dist/core/framework-templates.js +373 -285
- package/dist/core/style-compiler.js +201 -201
- package/dist/core/template-manager.js +348 -348
- package/dist/services/svg-service.js +12 -12
- package/dist/templates/ComponentTemplate.js +17 -17
- package/dist/types/index.d.ts +1 -1
- package/docs/ADR-SVG-INTRGRATION-METHODS-001.adr.md +157 -157
- package/docs/ADR-SVG-INTRGRATION-METHODS-002.adr.md +549 -549
- package/docs/FRAMEWORK-GUIDE.md +768 -768
- package/docs/IMPLEMENTATION-SUMMARY.md +376 -376
- package/package.json +179 -177
|
@@ -281,18 +281,18 @@ export class SVGService {
|
|
|
281
281
|
const imports = componentNames
|
|
282
282
|
.map(name => `export { default as ${name} } from './${name}';`)
|
|
283
283
|
.join('\n');
|
|
284
|
-
return `/**
|
|
285
|
-
* SVG Components Index
|
|
286
|
-
* Generated by svger-cli
|
|
287
|
-
*
|
|
288
|
-
* Import individual components:
|
|
289
|
-
* import { ${componentNames[0] || 'ComponentName'} } from './components';
|
|
290
|
-
*
|
|
291
|
-
* Import all components:
|
|
292
|
-
* import * as Icons from './components';
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
${imports}
|
|
284
|
+
return `/**
|
|
285
|
+
* SVG Components Index
|
|
286
|
+
* Generated by svger-cli
|
|
287
|
+
*
|
|
288
|
+
* Import individual components:
|
|
289
|
+
* import { ${componentNames[0] || 'ComponentName'} } from './components';
|
|
290
|
+
*
|
|
291
|
+
* Import all components:
|
|
292
|
+
* import * as Icons from './components';
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
${imports}
|
|
296
296
|
`;
|
|
297
297
|
}
|
|
298
298
|
/**
|
|
@@ -23,22 +23,22 @@ export function reactTemplate({ componentName, svgContent, defaultWidth = 24, de
|
|
|
23
23
|
.replace(/\s+xmlns(:xlink)?="[^"]*"/g, '')
|
|
24
24
|
.trim()
|
|
25
25
|
.replace(/^.*?<svg[^>]*>(.*?)<\/svg>.*$/i, '$1');
|
|
26
|
-
return `import type { SVGProps } from "react";
|
|
27
|
-
const Svg${componentName} = (props: SVGProps<SVGSVGElement>) => (
|
|
28
|
-
<svg
|
|
29
|
-
viewBox="0 0 ${defaultWidth} ${defaultHeight}"
|
|
30
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
31
|
-
xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
32
|
-
width={props.width || ${defaultWidth}}
|
|
33
|
-
height={props.height || ${defaultHeight}}
|
|
34
|
-
fill={props.fill || "${defaultFill}"}
|
|
35
|
-
stroke={props.stroke || "none"}
|
|
36
|
-
className={props.className}
|
|
37
|
-
{...props}
|
|
38
|
-
>
|
|
39
|
-
${cleaned}
|
|
40
|
-
</svg>
|
|
41
|
-
);
|
|
42
|
-
export default Svg${componentName};
|
|
26
|
+
return `import type { SVGProps } from "react";
|
|
27
|
+
const Svg${componentName} = (props: SVGProps<SVGSVGElement>) => (
|
|
28
|
+
<svg
|
|
29
|
+
viewBox="0 0 ${defaultWidth} ${defaultHeight}"
|
|
30
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
31
|
+
xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
32
|
+
width={props.width || ${defaultWidth}}
|
|
33
|
+
height={props.height || ${defaultHeight}}
|
|
34
|
+
fill={props.fill || "${defaultFill}"}
|
|
35
|
+
stroke={props.stroke || "none"}
|
|
36
|
+
className={props.className}
|
|
37
|
+
{...props}
|
|
38
|
+
>
|
|
39
|
+
${cleaned}
|
|
40
|
+
</svg>
|
|
41
|
+
);
|
|
42
|
+
export default Svg${componentName};
|
|
43
43
|
`;
|
|
44
44
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type definitions for svger-cli
|
|
3
3
|
*/
|
|
4
|
-
export type FrameworkType = 'react' | 'vue' | 'svelte' | 'angular' | 'solid' | 'preact' | 'lit' | 'vanilla';
|
|
4
|
+
export type FrameworkType = 'react' | 'react-native' | 'vue' | 'svelte' | 'angular' | 'solid' | 'preact' | 'lit' | 'vanilla';
|
|
5
5
|
export type NamingConvention = 'kebab' | 'pascal' | 'camel';
|
|
6
6
|
export type ComponentType = 'functional' | 'class' | 'arrow';
|
|
7
7
|
export type ErrorHandlingStrategy = 'continue' | 'stop' | 'retry';
|
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
**ADR** How to implement correctly SVG Integration Methods in React
|
|
2
|
-
|
|
3
|
-
**Version: 1.0.0**
|
|
4
|
-
**Date: 10/14/2025**
|
|
5
|
-
**Author: Engineer Navid Rezadoost**
|
|
6
|
-
**TDR Document ID: [TDR-SVG-INTRGRATION-METHODS-001](https://docs.google.com/document/d/1b04_V01xOvLiSMzuPdaRynANlnt2wYdJ_vjs9MAqtn4/edit?tab=t.0)**
|
|
7
|
-
**Status**: Proposed
|
|
8
|
-
|
|
9
|
-
**Context**
|
|
10
|
-
This service is responsible for managing svg files. Given the documentation provided in the TDR for implementing Method 3, which covers the weaknesses of svgr, it was decided to release this package as an open source service on npm.
|
|
11
|
-
|
|
12
|
-
**Similar Weaknesses That We Are Looking To Solve In This Process**
|
|
13
|
-
|
|
14
|
-
* Add more commands for more control and mastery over svg file management
|
|
15
|
-
* Add different commands for rendering and rebuilding svg components with more control over files that we do not want to be rebuilt
|
|
16
|
-
* Add a command to create a component for new files that are added
|
|
17
|
-
* A command to componentize a specific svg
|
|
18
|
-
* Add settings for files that should remain unchanged due to specific styling
|
|
19
|
-
* Introduce the folder and run the build as \--watch as soon as a new svg file is added to the specified folder, the svg will be built automatically
|
|
20
|
-
* Create a config file or command on the command line to specify the source file to monitor or process and specify the destination directory
|
|
21
|
-
* Specify rules for building components in width and height dimensions and even styles that should be set as default
|
|
22
|
-
|
|
23
|
-
#### **Decision**
|
|
24
|
-
|
|
25
|
-
We will develop a custom SVG integration CLI and runtime service for React that:
|
|
26
|
-
|
|
27
|
-
* Watches directories for new SVG files.
|
|
28
|
-
* Generates React components automatically with flexible configuration.
|
|
29
|
-
* Allows selective rebuilds and fine-grained control over output styles and props.
|
|
30
|
-
|
|
31
|
-
#### **Rationale**
|
|
32
|
-
|
|
33
|
-
SVGR, while popular, has the following shortcomings:
|
|
34
|
-
|
|
35
|
-
* Lacks a flexible CLI API for selective component generation.
|
|
36
|
-
* No built-in `--watch` mode for automatic builds on new file additions.
|
|
37
|
-
* Limited support for default dimension and styling rules.
|
|
38
|
-
* Difficult to exclude or lock specific SVGs from rebuilds.
|
|
39
|
-
|
|
40
|
-
#### **Consequences**
|
|
41
|
-
|
|
42
|
-
* More control and automation for developers.
|
|
43
|
-
* Slightly increased setup complexity.
|
|
44
|
-
* Responsibility to maintain a custom build tool.
|
|
45
|
-
|
|
46
|
-
## **Example Configuration and Commands**
|
|
47
|
-
|
|
48
|
-
**Include examples so developers can easily visualize the usage.**
|
|
49
|
-
|
|
50
|
-
### Example `.svgconfig.json`
|
|
51
|
-
|
|
52
|
-
| { "source": "./src/assets/svg", "output": "./src/components/icons", "watch": true, "defaultWidth": "24", "defaultHeight": "24", "defaultFill": "currentColor", "exclude": \["logo.svg", "brand-icon.svg"\], "styleRules": { "fill": "inherit", "stroke": "none" }} |
|
|
53
|
-
| :---- |
|
|
54
|
-
|
|
55
|
-
**Commands**
|
|
56
|
-
|
|
57
|
-
**Build Command**
|
|
58
|
-
Builds React components from all SVG files in the specified source directory.
|
|
59
|
-
|
|
60
|
-
| svg-tool build \[options\] |
|
|
61
|
-
| :---- |
|
|
62
|
-
|
|
63
|
-
| svg-tool build \--src ./src/assets/svg \--out ./src/components/icons |
|
|
64
|
-
| :---- |
|
|
65
|
-
|
|
66
|
-
### **What It Does**
|
|
67
|
-
|
|
68
|
-
* Converts every `.svg` in the source folder to a React component.
|
|
69
|
-
* Applies rules from `.svgconfig.json` if present.
|
|
70
|
-
* Generates file names based on kebab-case or PascalCase (configurable).
|
|
71
|
-
|
|
72
|
-
**Watch Command**
|
|
73
|
-
Continuously watches the source directory for new or updated SVG files, and automatically builds them.
|
|
74
|
-
|
|
75
|
-
| svg-tool watch \[options\] |
|
|
76
|
-
| :---- |
|
|
77
|
-
|
|
78
|
-
| svg-tool watch \--src ./src/assets/svg \--out ./src/components/icons |
|
|
79
|
-
| :---- |
|
|
80
|
-
|
|
81
|
-
### **What It Does**
|
|
82
|
-
|
|
83
|
-
* Automatically rebuilds when an SVG file is added, updated, or removed.
|
|
84
|
-
* Skips locked SVG files.
|
|
85
|
-
* Ideal for active development environments.
|
|
86
|
-
|
|
87
|
-
## **Generate Command**
|
|
88
|
-
|
|
89
|
-
Converts a specific SVG file into a React component on demand.
|
|
90
|
-
|
|
91
|
-
| svg-tool generate \<svgFile\> \[options\] |
|
|
92
|
-
| :---- |
|
|
93
|
-
|
|
94
|
-
| svg-tool generate ./src/assets/svg/heart.svg \--out ./src/components/icons |
|
|
95
|
-
| :---- |
|
|
96
|
-
|
|
97
|
-
### **What It Does**
|
|
98
|
-
|
|
99
|
-
* Converts only the specified file.
|
|
100
|
-
* Ideal for adding individual icons to an existing collection.
|
|
101
|
-
|
|
102
|
-
## **Lock Command**
|
|
103
|
-
|
|
104
|
-
Locks one or more SVG files to prevent them from being rebuilt or overwritten during batch operations.
|
|
105
|
-
|
|
106
|
-
| svg-tool lock \<svgFile\> \[options\] |
|
|
107
|
-
| :---- |
|
|
108
|
-
|
|
109
|
-
| svg-tool lock ./src/assets/svg/logo.svg |
|
|
110
|
-
| :---- |
|
|
111
|
-
|
|
112
|
-
### **What It Does**
|
|
113
|
-
|
|
114
|
-
* Adds the specified file(s) to a `.svg-lock` or `.svgconfig.json` list.
|
|
115
|
-
* Protects specific SVGs with custom branding or styling.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
## **Unlock Command**
|
|
119
|
-
|
|
120
|
-
Unlocks one or more SVG files previously marked as locked, allowing them to be rebuilt.
|
|
121
|
-
|
|
122
|
-
| svg-tool unlock \<svgFile\> \[options\] |
|
|
123
|
-
| :---- |
|
|
124
|
-
|
|
125
|
-
| svg-tool unlock ./src/assets/svg/logo.svg |
|
|
126
|
-
| :---- |
|
|
127
|
-
|
|
128
|
-
## **Config Command**
|
|
129
|
-
|
|
130
|
-
Creates or modifies a `.svgconfig.json` file with default settings for builds and watches.
|
|
131
|
-
|
|
132
|
-
| svg-tool config \[options\] |
|
|
133
|
-
| :---- |
|
|
134
|
-
|
|
135
|
-
| svg-tool config \--init |
|
|
136
|
-
| :---- |
|
|
137
|
-
|
|
138
|
-
**\--init**
|
|
139
|
-
|
|
140
|
-
| svg-tool config \--init |
|
|
141
|
-
| :---- |
|
|
142
|
-
|
|
143
|
-
**\--set \<key=value\>**
|
|
144
|
-
|
|
145
|
-
| svg-tool config \--set defaultWidth=32 |
|
|
146
|
-
| :---- |
|
|
147
|
-
|
|
148
|
-
**`--show`**
|
|
149
|
-
|
|
150
|
-
| svg-tool config \--show |
|
|
151
|
-
| :---- |
|
|
152
|
-
|
|
153
|
-
**`Full One-Line Command Closet (for Bash / Mac / Linux / PowerShell)`**
|
|
154
|
-
|
|
155
|
-
| svg-tool config \--init && svg-tool config \--set source=./src/assets/svg && svg-tool config \--set output=./src/components/icons && svg-tool config \--set watch=true && svg-tool config \--set defaultWidth=24 && svg-tool config \--set defaultHeight=24 && svg-tool config \--set defaultFill=currentColor && svg-tool lock ./src/assets/svg/logo.svg && svg-tool build \--src ./src/assets/svg \--out ./src/components/icons \--verbose && svg-tool generate ./src/assets/svg/new-icon.svg \--out ./src/components/icons && svg-tool unlock ./src/assets/svg/logo.svg && svg-tool watch \--src ./src/assets/svg \--out ./src/components/icons && svg-tool clean \--out ./src/components/icons |
|
|
156
|
-
| :---- |
|
|
157
|
-
|
|
1
|
+
**ADR** How to implement correctly SVG Integration Methods in React
|
|
2
|
+
|
|
3
|
+
**Version: 1.0.0**
|
|
4
|
+
**Date: 10/14/2025**
|
|
5
|
+
**Author: Engineer Navid Rezadoost**
|
|
6
|
+
**TDR Document ID: [TDR-SVG-INTRGRATION-METHODS-001](https://docs.google.com/document/d/1b04_V01xOvLiSMzuPdaRynANlnt2wYdJ_vjs9MAqtn4/edit?tab=t.0)**
|
|
7
|
+
**Status**: Proposed
|
|
8
|
+
|
|
9
|
+
**Context**
|
|
10
|
+
This service is responsible for managing svg files. Given the documentation provided in the TDR for implementing Method 3, which covers the weaknesses of svgr, it was decided to release this package as an open source service on npm.
|
|
11
|
+
|
|
12
|
+
**Similar Weaknesses That We Are Looking To Solve In This Process**
|
|
13
|
+
|
|
14
|
+
* Add more commands for more control and mastery over svg file management
|
|
15
|
+
* Add different commands for rendering and rebuilding svg components with more control over files that we do not want to be rebuilt
|
|
16
|
+
* Add a command to create a component for new files that are added
|
|
17
|
+
* A command to componentize a specific svg
|
|
18
|
+
* Add settings for files that should remain unchanged due to specific styling
|
|
19
|
+
* Introduce the folder and run the build as \--watch as soon as a new svg file is added to the specified folder, the svg will be built automatically
|
|
20
|
+
* Create a config file or command on the command line to specify the source file to monitor or process and specify the destination directory
|
|
21
|
+
* Specify rules for building components in width and height dimensions and even styles that should be set as default
|
|
22
|
+
|
|
23
|
+
#### **Decision**
|
|
24
|
+
|
|
25
|
+
We will develop a custom SVG integration CLI and runtime service for React that:
|
|
26
|
+
|
|
27
|
+
* Watches directories for new SVG files.
|
|
28
|
+
* Generates React components automatically with flexible configuration.
|
|
29
|
+
* Allows selective rebuilds and fine-grained control over output styles and props.
|
|
30
|
+
|
|
31
|
+
#### **Rationale**
|
|
32
|
+
|
|
33
|
+
SVGR, while popular, has the following shortcomings:
|
|
34
|
+
|
|
35
|
+
* Lacks a flexible CLI API for selective component generation.
|
|
36
|
+
* No built-in `--watch` mode for automatic builds on new file additions.
|
|
37
|
+
* Limited support for default dimension and styling rules.
|
|
38
|
+
* Difficult to exclude or lock specific SVGs from rebuilds.
|
|
39
|
+
|
|
40
|
+
#### **Consequences**
|
|
41
|
+
|
|
42
|
+
* More control and automation for developers.
|
|
43
|
+
* Slightly increased setup complexity.
|
|
44
|
+
* Responsibility to maintain a custom build tool.
|
|
45
|
+
|
|
46
|
+
## **Example Configuration and Commands**
|
|
47
|
+
|
|
48
|
+
**Include examples so developers can easily visualize the usage.**
|
|
49
|
+
|
|
50
|
+
### Example `.svgconfig.json`
|
|
51
|
+
|
|
52
|
+
| { "source": "./src/assets/svg", "output": "./src/components/icons", "watch": true, "defaultWidth": "24", "defaultHeight": "24", "defaultFill": "currentColor", "exclude": \["logo.svg", "brand-icon.svg"\], "styleRules": { "fill": "inherit", "stroke": "none" }} |
|
|
53
|
+
| :---- |
|
|
54
|
+
|
|
55
|
+
**Commands**
|
|
56
|
+
|
|
57
|
+
**Build Command**
|
|
58
|
+
Builds React components from all SVG files in the specified source directory.
|
|
59
|
+
|
|
60
|
+
| svg-tool build \[options\] |
|
|
61
|
+
| :---- |
|
|
62
|
+
|
|
63
|
+
| svg-tool build \--src ./src/assets/svg \--out ./src/components/icons |
|
|
64
|
+
| :---- |
|
|
65
|
+
|
|
66
|
+
### **What It Does**
|
|
67
|
+
|
|
68
|
+
* Converts every `.svg` in the source folder to a React component.
|
|
69
|
+
* Applies rules from `.svgconfig.json` if present.
|
|
70
|
+
* Generates file names based on kebab-case or PascalCase (configurable).
|
|
71
|
+
|
|
72
|
+
**Watch Command**
|
|
73
|
+
Continuously watches the source directory for new or updated SVG files, and automatically builds them.
|
|
74
|
+
|
|
75
|
+
| svg-tool watch \[options\] |
|
|
76
|
+
| :---- |
|
|
77
|
+
|
|
78
|
+
| svg-tool watch \--src ./src/assets/svg \--out ./src/components/icons |
|
|
79
|
+
| :---- |
|
|
80
|
+
|
|
81
|
+
### **What It Does**
|
|
82
|
+
|
|
83
|
+
* Automatically rebuilds when an SVG file is added, updated, or removed.
|
|
84
|
+
* Skips locked SVG files.
|
|
85
|
+
* Ideal for active development environments.
|
|
86
|
+
|
|
87
|
+
## **Generate Command**
|
|
88
|
+
|
|
89
|
+
Converts a specific SVG file into a React component on demand.
|
|
90
|
+
|
|
91
|
+
| svg-tool generate \<svgFile\> \[options\] |
|
|
92
|
+
| :---- |
|
|
93
|
+
|
|
94
|
+
| svg-tool generate ./src/assets/svg/heart.svg \--out ./src/components/icons |
|
|
95
|
+
| :---- |
|
|
96
|
+
|
|
97
|
+
### **What It Does**
|
|
98
|
+
|
|
99
|
+
* Converts only the specified file.
|
|
100
|
+
* Ideal for adding individual icons to an existing collection.
|
|
101
|
+
|
|
102
|
+
## **Lock Command**
|
|
103
|
+
|
|
104
|
+
Locks one or more SVG files to prevent them from being rebuilt or overwritten during batch operations.
|
|
105
|
+
|
|
106
|
+
| svg-tool lock \<svgFile\> \[options\] |
|
|
107
|
+
| :---- |
|
|
108
|
+
|
|
109
|
+
| svg-tool lock ./src/assets/svg/logo.svg |
|
|
110
|
+
| :---- |
|
|
111
|
+
|
|
112
|
+
### **What It Does**
|
|
113
|
+
|
|
114
|
+
* Adds the specified file(s) to a `.svg-lock` or `.svgconfig.json` list.
|
|
115
|
+
* Protects specific SVGs with custom branding or styling.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## **Unlock Command**
|
|
119
|
+
|
|
120
|
+
Unlocks one or more SVG files previously marked as locked, allowing them to be rebuilt.
|
|
121
|
+
|
|
122
|
+
| svg-tool unlock \<svgFile\> \[options\] |
|
|
123
|
+
| :---- |
|
|
124
|
+
|
|
125
|
+
| svg-tool unlock ./src/assets/svg/logo.svg |
|
|
126
|
+
| :---- |
|
|
127
|
+
|
|
128
|
+
## **Config Command**
|
|
129
|
+
|
|
130
|
+
Creates or modifies a `.svgconfig.json` file with default settings for builds and watches.
|
|
131
|
+
|
|
132
|
+
| svg-tool config \[options\] |
|
|
133
|
+
| :---- |
|
|
134
|
+
|
|
135
|
+
| svg-tool config \--init |
|
|
136
|
+
| :---- |
|
|
137
|
+
|
|
138
|
+
**\--init**
|
|
139
|
+
|
|
140
|
+
| svg-tool config \--init |
|
|
141
|
+
| :---- |
|
|
142
|
+
|
|
143
|
+
**\--set \<key=value\>**
|
|
144
|
+
|
|
145
|
+
| svg-tool config \--set defaultWidth=32 |
|
|
146
|
+
| :---- |
|
|
147
|
+
|
|
148
|
+
**`--show`**
|
|
149
|
+
|
|
150
|
+
| svg-tool config \--show |
|
|
151
|
+
| :---- |
|
|
152
|
+
|
|
153
|
+
**`Full One-Line Command Closet (for Bash / Mac / Linux / PowerShell)`**
|
|
154
|
+
|
|
155
|
+
| svg-tool config \--init && svg-tool config \--set source=./src/assets/svg && svg-tool config \--set output=./src/components/icons && svg-tool config \--set watch=true && svg-tool config \--set defaultWidth=24 && svg-tool config \--set defaultHeight=24 && svg-tool config \--set defaultFill=currentColor && svg-tool lock ./src/assets/svg/logo.svg && svg-tool build \--src ./src/assets/svg \--out ./src/components/icons \--verbose && svg-tool generate ./src/assets/svg/new-icon.svg \--out ./src/components/icons && svg-tool unlock ./src/assets/svg/logo.svg && svg-tool watch \--src ./src/assets/svg \--out ./src/components/icons && svg-tool clean \--out ./src/components/icons |
|
|
156
|
+
| :---- |
|
|
157
|
+
|