@nanawan/icon-builder 0.6.1

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 +233 -0
  2. package/bin/index.js +39 -0
  3. package/package.json +63 -0
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ ## Intro
2
+
3
+ `@pui/icon-builder` is a tool to build svg images to icon fonts.
4
+
5
+ ## Installation
6
+
7
+ ### npm
8
+
9
+ ```shell
10
+ npm i @pui/icon-builder -D
11
+ ```
12
+
13
+ ### yarn
14
+
15
+ ```shell
16
+ yarn add @pui/icon-builder -D
17
+ ```
18
+
19
+ ### pnpm
20
+
21
+ ```shell
22
+ pnpm add @pui/icon-builder -D
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Commands
28
+
29
+ #### build
30
+
31
+ Build svg into icon font.
32
+
33
+ ```shell
34
+ npx vi build
35
+
36
+ # watch mode
37
+ npx vi build -w
38
+ ```
39
+
40
+ #### generate
41
+
42
+ Generate components from svg, support esm, cjs, sfc, types.
43
+
44
+ ```shell
45
+ npx vi generate
46
+ ```
47
+
48
+ #### figma
49
+
50
+ Pull the svg icon in the figma document to the local.
51
+
52
+ ```shell
53
+ npx vi figma -f <file> -t <token>
54
+ #or token from process.env
55
+ VI_FIGMA_TOKEN=<token> npx vi figma -f <file>
56
+ ```
57
+
58
+ ## Configuration File
59
+
60
+ ```js
61
+ // vi.config.ts
62
+ import { defineConfig } from '@pui/icon-builder'
63
+
64
+ export default defineConfig({
65
+ name: 'i-icons',
66
+ namespace: 'i',
67
+ fontFamilyClassName: 'i--set',
68
+ entry: './svg-icons',
69
+ output: './icons',
70
+ figma: {},
71
+ generate: {}
72
+ })
73
+ ```
74
+
75
+ ## Configuration Type Declaration
76
+
77
+ ```ts
78
+ export interface VIConfig {
79
+ /**
80
+ * @default `pui-icons`
81
+ * font name.
82
+ */
83
+ name?: string
84
+ /**
85
+ * @default `var-icon`
86
+ * font name prefix.
87
+ */
88
+ namespace?: string
89
+ /**
90
+ * @default `true`
91
+ * output base64
92
+ */
93
+ base64?: boolean
94
+ /**
95
+ * @default `./svg`
96
+ * svg icons folder path.
97
+ */
98
+ entry?: string
99
+ /**
100
+ * @default `./dist`
101
+ * svg icons folder path.
102
+ */
103
+ output?: string
104
+ /**
105
+ * @default `var-icon--set`
106
+ * icon font family class name.
107
+ */
108
+ fontFamilyClassName?: string
109
+ /**
110
+ * @default `normal`
111
+ * icon font weight.
112
+ */
113
+ fontWeight?: string
114
+ /**
115
+ * @default `normal`
116
+ * icon font style.
117
+ */
118
+ fontStyle?: string
119
+ /**
120
+ * @default `false`
121
+ * Whether to output files
122
+ */
123
+ emitFile?: boolean
124
+ /**
125
+ * icon font public path
126
+ */
127
+ publicPath?: string
128
+ /**
129
+ * icon font public url
130
+ */
131
+ publicURL?: string
132
+ /**
133
+ * icon filenames, e.g. ['window-close', 'cog']
134
+ */
135
+ filenames?: string[]
136
+ /**
137
+ * generate command related options
138
+ */
139
+ generate?: {
140
+ /**
141
+ * @default `./svg`
142
+ * svg icons folder path
143
+ */
144
+ entry?: string
145
+ /**
146
+ * @default `XIcon`
147
+ * wrapper component name, svg file names should avoid using names like x-icon.svg
148
+ */
149
+ wrapperComponentName?: string
150
+ /**
151
+ * @default `x`
152
+ * unplugin-vue-components resolver namespace, please same as `wrapperComponentName` namespace
153
+ */
154
+ resolverNamespace?: string
155
+ /**
156
+ * @default `vue3`
157
+ * frameworks supported by the icon library
158
+ */
159
+ framework?: 'vue3' | 'react'
160
+ /**
161
+ * @default `false`
162
+ * only generate components, do not generate cjs, esm modules and types
163
+ */
164
+ componentsOnly?: boolean
165
+ /**
166
+ * @default () => false
167
+ * is colorful icon
168
+ */
169
+ colorful?: (name: string, content: string) => boolean
170
+ output?: {
171
+ /**
172
+ * @default `./svg-components`
173
+ * component output path
174
+ */
175
+ component?: string
176
+ /**
177
+ * @default `./svg-types`
178
+ * ts declaration output path
179
+ */
180
+ types?: string
181
+ /**
182
+ * @default `./svg-esm`
183
+ * es module format output path
184
+ */
185
+ esm?: string
186
+ /**
187
+ * @default `./svg-cjs`
188
+ * commonjs module format output path
189
+ */
190
+ cjs?: string
191
+ /**
192
+ * @default `./resolver`
193
+ * unplugin-vue-components resolver output path
194
+ */
195
+ resolver?: string
196
+ }
197
+ }
198
+ /**
199
+ * figma parsing options
200
+ */
201
+ figma?: {
202
+ /**
203
+ * figma token
204
+ * @see https://www.figma.com/developers/api#authentication
205
+ */
206
+ token?: string
207
+ /**
208
+ * figma file id
209
+ */
210
+ file?: string
211
+ /**
212
+ * @default `Icons`
213
+ * figma icons page name
214
+ */
215
+ pageName?: string
216
+ /**
217
+ * @default `false`
218
+ * whether to skip downloading svg files when a file with the same name exists locally
219
+ */
220
+ skipExisting?: boolean
221
+ /**
222
+ * @default `false`
223
+ * whether to clear the output directory before downloading
224
+ */
225
+ clean?: boolean
226
+ /**
227
+ * @default `./svg-figma`
228
+ * output path
229
+ */
230
+ output?: string
231
+ }
232
+ }
233
+ ```
package/bin/index.js ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander'
3
+ import { build, figma, generate } from '../dist/index.js'
4
+
5
+ const program = new Command()
6
+
7
+ program
8
+ .command('build')
9
+ .option('-w --watch', 'Watch icons for changes and rebuild')
10
+ .description('Build icon fonts from svg files')
11
+ .action(build)
12
+
13
+ program
14
+ .command('generate')
15
+ .option('-e --entry <entry>', 'Svg files directory')
16
+ .option('-f --framework <framework>', 'Framework name, such as vue3, react')
17
+ .option('--componentsOnly <componentsOnly>', 'Only generate components, do not generate cjs, esm modules and types')
18
+ .option('--resolverNamespace <resolverNamespace>', 'Resolver namespace')
19
+ .option('--wrapperComponentName <wrapperComponentName>', 'Wrapper component name')
20
+ .option('--outputComponents <outputComponents>', 'Output svg component directory')
21
+ .option('--outputTypes <outputTypes>', 'Output types directory')
22
+ .option('--outputEsm <outputEsm>', 'Output esm directory')
23
+ .option('--outputCjs <outputCjs>', 'Output cjs directory')
24
+ .option('--outputResolver <outputResolver>', 'Output resolver directory')
25
+ .description('Generate icon components from svg files')
26
+ .action(generate)
27
+
28
+ program
29
+ .command('figma')
30
+ .option('-t --token <token>', 'Figma token')
31
+ .option('-f --file <file>', 'Figma file id')
32
+ .option('-p --pageName <pageName>', 'Figma icons page name')
33
+ .option('-s --skipExisting', 'Whether to skip downloading svg files when a file with the same name exists locally')
34
+ .option('-c --clean', 'Whether to clear the output directory before downloading')
35
+ .option('-o --output', 'Output path')
36
+ .description('Parse icons from figma')
37
+ .action(figma)
38
+
39
+ program.parse()
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@nanawan/icon-builder",
3
+ "type": "module",
4
+ "version": "0.6.1",
5
+ "description": "icon builder of pui",
6
+ "keywords": [
7
+ "pui",
8
+ "icon",
9
+ "builder"
10
+ ],
11
+ "author": "haoziqaq <357229046@qq.com>",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/puijs/pui-iconx"
16
+ },
17
+ "bugs": "https://github.com/puijs/pui-iconx/issues",
18
+ "main": "./dist/index.js",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "require": "./dist/index.cjs"
26
+ }
27
+ },
28
+ "bin": {
29
+ "vi": "bin/index.js"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "scripts": {
35
+ "dev": "tsup --watch",
36
+ "build": "tsup"
37
+ },
38
+ "dependencies": {
39
+ "commander": "^11.1.0",
40
+ "@pui/webfont": "0.0.9",
41
+ "chokidar": "3.6.0",
42
+ "fs-extra": "^11.1.1",
43
+ "picocolors": "^1.0.0",
44
+ "unconfig": "0.3.13",
45
+ "@vue/compiler-sfc": "^3.4.29",
46
+ "typescript": "^5.2.2",
47
+ "esbuild": "0.21.5",
48
+ "hash-sum": "^2.0.0",
49
+ "@pui/axle": "^0.9.0",
50
+ "rattail": "^1.0.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/fs-extra": "^11.0.4",
54
+ "@types/node": "^20.9.0",
55
+ "@types/hash-sum": "^1.0.2",
56
+ "@pui/eslint-config": "^3.1.4",
57
+ "@pui/release": "0.2.5",
58
+ "eslint": "^8.53.0",
59
+ "prettier": "^3.1.0",
60
+ "simple-git-hooks": "^2.9.0",
61
+ "tsup": "^8.0.1"
62
+ }
63
+ }