svg2swiftui 0.2.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.
Files changed (3) hide show
  1. package/README.md +81 -0
  2. package/dist/cli.js +2 -0
  3. package/package.json +57 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # svg2swiftui
2
+
3
+ [![Version](https://img.shields.io/npm/v/svg2swiftui.svg)](https://npmjs.org/package/svg2swiftui)
4
+ [![Downloads/month](https://img.shields.io/npm/dm/svg2swiftui.svg)](https://npmjs.org/package/svg2swiftui)
5
+ [![License](https://img.shields.io/npm/l/svg2swiftui.svg)](LICENSE.md)
6
+
7
+ Command-line tool for converting an SVG file into a SwiftUI `Shape` struct.
8
+
9
+ No install required — run it via `npx`:
10
+
11
+ ```sh
12
+ npx svg2swiftui ./icon.svg ./Icon.swift
13
+ ```
14
+
15
+ Powered by [`svg-to-swiftui-core`](https://npmjs.org/package/svg-to-swiftui-core). For the web UI, see [SVG to SwiftUI](https://svg-to-swiftui.quassum.com).
16
+
17
+ ## Usage
18
+
19
+ ```
20
+ svg2swiftui <input> <output> [options]
21
+ ```
22
+
23
+ By default, the output struct name is derived from the output filename (PascalCased, non-alphanumerics stripped). For example, `my-icon.swift` produces `struct MyIcon: Shape`.
24
+
25
+ ### Options
26
+
27
+ | Flag | Default | Description |
28
+ |---|---|---|
29
+ | `--struct-name <name>` | derived from output filename | SwiftUI struct name. |
30
+ | `--precision <n>` | `10` | Decimal precision for path coordinates. |
31
+ | `--indentation <n>` | `4` | Indentation width in spaces. |
32
+ | `--usage-comment` | off | Prepend a SwiftUI usage example as a leading comment. |
33
+ | `-h, --help` | | Print help. |
34
+ | `-V, --version` | | Print version. |
35
+
36
+ ### Examples
37
+
38
+ Convert with all defaults:
39
+
40
+ ```sh
41
+ npx svg2swiftui ./heart.svg ./Heart.swift
42
+ ```
43
+
44
+ Override the struct name and bump precision:
45
+
46
+ ```sh
47
+ npx svg2swiftui ./heart.svg ./Heart.swift --struct-name HeartIcon --precision 12
48
+ ```
49
+
50
+ Include a usage comment at the top of the output:
51
+
52
+ ```sh
53
+ npx svg2swiftui ./heart.svg ./Heart.swift --usage-comment
54
+ ```
55
+
56
+ The `--usage-comment` flag produces output that starts with something like:
57
+
58
+ ```swift
59
+ // To use this shape, just add it to your SwiftUI View:
60
+ // Heart().fill().frame(width: 24, height: 24)
61
+
62
+ struct Heart: Shape {
63
+ func path(in rect: CGRect) -> Path {
64
+ // ...
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## Behavior notes
70
+
71
+ - If the output file already exists, it is overwritten silently.
72
+ - Missing parent directories in the output path are created automatically.
73
+ - Missing or malformed SVG input exits with code `1` and an `Error:` message on stderr.
74
+
75
+ ## How it works
76
+
77
+ `svg2swiftui` is a thin CLI wrapper around [`svg-to-swiftui-core`](https://npmjs.org/package/svg-to-swiftui-core) — the same compiler powering the web tool. Each SVG becomes a single SwiftUI `Shape` with one `Path`, combining all elements.
78
+
79
+ ## License
80
+
81
+ MIT — see [LICENSE](../../LICENSE) at the repository root.
package/dist/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var C=Object.create;var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var j=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of N(e))!I.call(t,i)&&i!==n&&m(t,i,{get:()=>e[i],enumerable:!(o=y(e,i))||o.enumerable});return t};var a=(t,e,n)=>(n=t!=null?C(x(t)):{},j(e||!t||!t.__esModule?m(n,"default",{value:t,enumerable:!0}):n,t));var v=require("commander");var u={name:"svg2swiftui",version:"0.2.0",description:"CLI for converting SVG files into SwiftUI Shape structs.",main:"dist/cli.js",bin:{svg2swiftui:"./dist/cli.js"},files:["dist","README.md"],license:"MIT",keywords:["svg","swiftui","cli","swift","converter"],author:{name:"Antoni Silvestrovic",email:"antoni.silvestrovic@gmail.com",url:"https://antoni.ai"},repository:{type:"git",url:"git+https://github.com/quassum/svg-to-swiftui-core.git"},bugs:{url:"https://github.com/quassum/svg-to-swiftui-core/issues"},homepage:"https://github.com/quassum/svg-to-swiftui-core#readme",scripts:{build:"tsup",dev:"tsup --watch",clean:"rm -rf .turbo node_modules dist",test:"jest",lint:"biome check .",format:"biome format .",typecheck:"tsc --noEmit"},dependencies:{commander:"^12.1.0","svg-to-swiftui-core":"workspace:*"},devDependencies:{"@svg-to-swiftui/tsconfig":"workspace:*","@swc/core":"^1.15.18","@swc/jest":"^0.2.39","@types/jest":"^30.0.0","@types/node":"^24.3.0",jest:"^30.2.0",tsup:"^8.5.1",typescript:"^5.9.3"}};var r=a(require("fs")),g=a(require("path")),d=require("svg-to-swiftui-core");var c=a(require("path")),p="SVGShape";function f(t){let e=c.default.extname(t),o=c.default.basename(t,e).split(/[^A-Za-z0-9]+/).filter(s=>s.length>0);if(o.length===0)return p;let i=o.map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join("");return/^[0-9]/.test(i)?p:i}function l(t){let{input:e,output:n,structName:o,precision:i,indentation:s,usageComment:w}=t;if(!r.default.existsSync(e))throw new Error(`Input file not found: ${e}`);let h=r.default.readFileSync(e,"utf8"),S=o??f(n),b=(0,d.convert)(h,{structName:S,precision:i,indentationSize:s,usageCommentPrefix:w});r.default.mkdirSync(g.default.dirname(n),{recursive:!0}),r.default.writeFileSync(n,b,"utf8")}function F(t){let e=new v.Command;e.name("svg2swiftui").description("Convert an SVG file into a SwiftUI Shape struct.").version(u.version).argument("<input>","Path to input SVG file").argument("<output>","Path to output Swift file").option("--struct-name <name>","SwiftUI struct name (default: derived from output filename)").option("--precision <n>","Decimal precision for path coordinates",Number,10).option("--indentation <n>","Indentation width in spaces",Number,4).option("--usage-comment","Include SwiftUI usage example as a leading comment",!1).action((n,o,i)=>{l({input:n,output:o,structName:i.structName,precision:i.precision,indentation:i.indentation,usageComment:i.usageComment})}),e.parse(t)}try{F(process.argv)}catch(t){let e=t instanceof Error?t.message:String(t);console.error(`Error: ${e}`),process.exit(1)}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "svg2swiftui",
3
+ "version": "0.2.0",
4
+ "description": "CLI for converting SVG files into SwiftUI Shape structs.",
5
+ "main": "dist/cli.js",
6
+ "bin": {
7
+ "svg2swiftui": "./dist/cli.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "license": "MIT",
14
+ "keywords": [
15
+ "svg",
16
+ "swiftui",
17
+ "cli",
18
+ "swift",
19
+ "converter"
20
+ ],
21
+ "author": {
22
+ "name": "Antoni Silvestrovic",
23
+ "email": "antoni.silvestrovic@gmail.com",
24
+ "url": "https://antoni.ai"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/quassum/svg-to-swiftui-core.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/quassum/svg-to-swiftui-core/issues"
32
+ },
33
+ "homepage": "https://github.com/quassum/svg-to-swiftui-core#readme",
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "dev": "tsup --watch",
37
+ "clean": "rm -rf .turbo node_modules dist",
38
+ "test": "jest",
39
+ "lint": "biome check .",
40
+ "format": "biome format .",
41
+ "typecheck": "tsc --noEmit"
42
+ },
43
+ "dependencies": {
44
+ "commander": "^12.1.0",
45
+ "svg-to-swiftui-core": "workspace:*"
46
+ },
47
+ "devDependencies": {
48
+ "@svg-to-swiftui/tsconfig": "workspace:*",
49
+ "@swc/core": "^1.15.18",
50
+ "@swc/jest": "^0.2.39",
51
+ "@types/jest": "^30.0.0",
52
+ "@types/node": "^24.3.0",
53
+ "jest": "^30.2.0",
54
+ "tsup": "^8.5.1",
55
+ "typescript": "^5.9.3"
56
+ }
57
+ }