iconfont-preview-cli 1.0.0 → 1.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.
package/README.md CHANGED
@@ -1,53 +1,55 @@
1
1
  # iconfont-preview-cli
2
2
 
3
- 一个用于预览本地字体图标的命令行工具。它可以扫描指定目录下的 CSS 文件,解析出图标类名,并提供一个可视化的 Web 界面来预览、搜索和复制图标代码。
3
+ [中文文档](./README_zh.md) | [English](./README.md)
4
4
 
5
- ## 功能特性
5
+ A command-line tool for previewing local font icons. It scans CSS files in a specified directory, extracts icon class names, and provides a web interface to preview, search, and copy icon codes.
6
6
 
7
- - 🔍 **自动扫描**: 递归扫描指定目录下的所有 CSS 文件。
8
- - 🎨 **可视化预览**: 解析 CSS 中的 `content` 属性,展示图标及其类名。
9
- - 📋 **一键复制**: 点击图标即可复制类名到剪贴板。
10
- - ⚡ **即时搜索**: 支持通过类名关键词快速筛选图标。
11
- - 🛠 **Vite 插件集成**: 提供 Vite 插件,方便在开发环境中直接集成图标预览服务。
7
+ ## Features
12
8
 
13
- ## 🚀 快速开始
9
+ - **Auto Scan**: Recursively scans all CSS files in the specified directory.
10
+ - **Visual Preview**: Parses `content` properties in CSS to display icons and their class names.
11
+ - **One-Click Copy**: Click any icon to copy its class name to the clipboard.
12
+ - **Instant Search**: Quickly filter icons by class name keywords.
13
+ - **Vite Integration**: Includes a Vite plugin to integrate icon preview into the development environment.
14
14
 
15
- ### 安装
15
+ ## Quick Start
16
+
17
+ ### Installation
16
18
 
17
19
  ```bash
18
- # 全局安装
20
+ # Global installation
19
21
  npm install -g iconfont-preview-cli
20
22
 
21
23
 
22
- # 或者在项目中安装
24
+ # Or install as a dev dependency
23
25
  npm install -D iconfont-preview-cli
24
26
  ```
25
27
 
26
- ### 命令行使用 (CLI)
28
+ ### CLI Usage
27
29
 
28
- 在项目根目录下,你可以通过以下命令启动预览服务:
30
+ Run the preview server from your project root:
29
31
 
30
32
  ```bash
31
- # 预览指定目录下的字体图标
33
+ # Preview font icons in a specific directory
32
34
  iconfont-preview-cli --dir ./path/to/your/fonts
33
35
 
34
36
 
35
- # 指定端口 (默认 3000)
37
+ # Specify a custom port (default: 3000)
36
38
  iconfont-preview-cli --dir ./path/to/your/fonts --port 8080
37
39
  ```
38
40
 
39
- ### 参数说明
41
+ ### Options
40
42
 
41
- | 参数 | 简写 | 描述 | 默认值 |
42
- | -------- | ---- | -------------------------------------------- | ------ |
43
- | `--dir` | `-d` | **(必填)** 包含字体图标 CSS 文件的文件夹路径 | - |
44
- | `--port` | `-p` | 服务启动端口 | `3000` |
43
+ | Option | Alias | Description | Default |
44
+ | -------- | ----- | ------------------------------------------------ | ------- |
45
+ | `--dir` | `-d` | **(Required)** Path to the folder containing CSS | - |
46
+ | `--port` | `-p` | Server port | `3000` |
45
47
 
46
- ## 📦 安装与集成
48
+ ## Installation & Integration
47
49
 
48
- ### 作为 Vite 插件使用
50
+ ### Using as a Vite Plugin
49
51
 
50
- 如果你正在开发一个 Vite 项目,可以将此工具作为插件集成,在开发服务器中同时提供图标预览功能。
52
+ For Vite projects, use the plugin to enable icon preview with the dev server.
51
53
 
52
54
  ```typescript
53
55
  // vite.config.ts
@@ -56,27 +58,27 @@ import { iconfontServer } from "iconfont-preview-cli/server";
56
58
  export default {
57
59
  plugins: [
58
60
  iconfontServer({
59
- iconDir: "./src/assets/fonts", // 字体图标存放目录
60
- urlPrefix: "/iconfont-proxy" // 代理路径前缀 (可选)
61
+ iconDir: "./src/assets/fonts", // Directory containing font icons
62
+ urlPrefix: "/iconfont-proxy" // Proxy path prefix (optional)
61
63
  })
62
64
  ]
63
65
  };
64
66
  ```
65
67
 
66
- ### 组件
68
+ ### Components
67
69
 
68
- 除了 CLI 工具,本项目还导出了核心组件 `RenderIconList`,方便你在自己的 Vue 项目中定制图标预览页面。
70
+ The project also exports the `RenderIconList` component for custom Vue integrations.
69
71
 
70
- ### 引入
72
+ ### Import
71
73
 
72
74
  ```typescript
73
75
  import { RenderIconList } from "iconfont-preview-cli/components";
74
- // 引入样式
76
+ // Import styles
75
77
  import "iconfont-preview-cli/components/index.css";
76
78
  import axios from "axios";
77
79
  ```
78
80
 
79
- ### 基本用法
81
+ ### Basic Usage
80
82
 
81
83
  ```vue
82
84
  <template>
@@ -84,7 +86,7 @@ import axios from "axios";
84
86
  <div class="local-icon-demo__header">
85
87
  <el-input
86
88
  v-model="keyword"
87
- placeholder="输入关键字,回车搜索"
89
+ placeholder="Enter keyword to search"
88
90
  clearable
89
91
  @change="onSearch"
90
92
  />
@@ -103,7 +105,7 @@ import axios from "axios";
103
105
  :key="className"
104
106
  class="local-icon-demo__icon-li"
105
107
  >
106
- <!-- 使用 renderIcon 组件渲染图标 -->
108
+ <!-- Render icon using the renderIcon component -->
107
109
  <component
108
110
  :is="renderIcon"
109
111
  :icon-class="className"
@@ -120,30 +122,33 @@ import axios from "axios";
120
122
  <script setup lang="ts">
121
123
  import { ref } from "vue";
122
124
  import { RenderIconList } from "iconfont-preview-cli/components";
123
- // 引入样式
125
+ // Import styles
124
126
  import "iconfont-preview-cli/components/index.css";
125
127
  import axios from "axios";
126
- import type { RenderIconListInstance, IconInfo } from "iconfont-preview-cli/components";
128
+ import type {
129
+ RenderIconListInstance,
130
+ IconInfo
131
+ } from "iconfont-preview-cli/components";
127
132
 
128
- /** 搜索关键字 */
133
+ /** Search keyword */
129
134
  const keyword = ref("");
130
135
  const renderIconListRef = ref<RenderIconListInstance>();
131
136
 
132
- // 获取图标数据的函数
137
+ // Function to fetch icon data
133
138
  const getIconsInfo = async (): Promise<IconInfo[]> => {
134
- // 这里请求接口前缀替换为vite插件iconfontServer中urlPrefix的值
139
+ // Replace the request prefix with the urlPrefix defined in the Vite plugin
135
140
  const res = await axios.get("/iconfont-proxy/api/iconsInfo");
136
141
  const iconsInfo = res.data.data;
137
142
  return iconsInfo;
138
143
  };
139
144
 
140
- // 动态加载字体样式
145
+ // Dynamically load font styles
141
146
  const cssLinkFormat = (href: string) => {
142
- // 这里根据需求替换为字体样式的路径
147
+ // Adjust the path to your font styles as needed
143
148
  return href && `/@/assets/font-icon${href}`;
144
149
  };
145
150
 
146
- // 调用搜索
151
+ // Trigger search
147
152
  const onSearch = (query: string) => {
148
153
  renderIconListRef.value?.onSearch(query);
149
154
  };
@@ -161,8 +166,6 @@ const onSearch = (query: string) => {
161
166
  }
162
167
  .local-icon-demo__icon-li {
163
168
  height: 120px;
164
- border-right: 1px solid getCssVar(border-color);
165
- border-bottom: 1px solid getCssVar(border-color);
166
169
  }
167
170
  </style>
168
171
  ```
@@ -171,76 +174,76 @@ const onSearch = (query: string) => {
171
174
 
172
175
  #### Props
173
176
 
174
- | 属性名 | 类型 | 必填 | 描述 |
175
- | --------------- | ----------------------------------------- | ---- | ------------------------------------------------- |
176
- | `getIconsInfo` | `() => Promise<IconInfo[]> \| IconInfo[]` | | 获取图标信息的函数,返回图标数据数组。 |
177
- | `cssLinkFormat` | `(href: string) => string` | | 格式化 CSS 文件链接的函数,用于动态加载字体样式。 |
177
+ | Prop Name | Type | Required | Description |
178
+ | --------------- | ----------------------------------------- | -------- | ---------------------------------------------------------------------------- |
179
+ | `getIconsInfo` | `() => Promise<IconInfo[]> \| IconInfo[]` | Yes | Function to retrieve icon data. Returns an array of icon info. |
180
+ | `cssLinkFormat` | `(href: string) => string` | No | Function to format CSS file links, used for dynamically loading font styles. |
178
181
 
179
182
  #### Methods (Exposed)
180
183
 
181
- | 方法名 | 参数 | 描述 |
182
- | ---------- | ----------------- | ------------------------------------- |
183
- | `onSearch` | `(query: string)` | 执行模糊搜索,过滤 `iconsInfo` 数据。 |
184
+ | Method Name | Parameters | Description |
185
+ | ----------- | ----------------- | ---------------------------------------------- |
186
+ | `onSearch` | `(query: string)` | Performs a fuzzy search to filter `iconsInfo`. |
184
187
 
185
188
  #### Slots
186
189
 
187
- | 插槽名 | 参数 | 描述 |
188
- | --------- | ------------------------------------------------------- | --------------------------------------------------------------- |
189
- | `default` | `{ iconsInfo: InnerIconInfo[], renderIcon: Component }` | 自定义渲染列表内容。`renderIcon` 是一个用于渲染单个图标的组件。 |
190
+ | Slot Name | Parameters | Description |
191
+ | --------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------- |
192
+ | `default` | `{ iconsInfo: InnerIconInfo[], renderIcon: Component }` | Customizes the list content. `renderIcon` is a component for rendering a single icon. |
190
193
 
191
194
  ### renderIcon API
192
195
 
193
196
  #### Props
194
197
 
195
- | 属性名 | 类型 | 必填 | 描述 |
196
- | ------------- | --------------------------------------------- | ---- | ------------------ |
197
- | `copyHandler` | `(iconName: string) => void \| Promise<void>` | | 自定义图标点击复制 |
198
+ | Prop Name | Type | Required | Description |
199
+ | ------------- | --------------------------------------------- | -------- | ------------------------------------------ |
200
+ | `copyHandler` | `(iconName: string) => void \| Promise<void>` | No | Custom handler for icon click/copy action. |
198
201
 
199
202
  #### Type Definitions
200
203
 
201
204
  ```typescript
202
205
  interface IconInfo {
203
- /** CSS 文件相对路径 */
206
+ /** Relative path to the CSS file */
204
207
  filePath: string;
205
- /** 基础类名 ( iconfont) */
208
+ /** Base class name (e.g., iconfont) */
206
209
  baseClassName: string;
207
- /** 图标类名列表 */
210
+ /** List of icon class names */
208
211
  classNames: string[];
209
- /** 自定义渲染图标的函数,返回一个组件 */
212
+ /** Custom render function returning a component */
210
213
  renderIcon?: (iconName: string) => Component;
211
214
  }
212
215
  ```
213
216
 
214
- ## 🛠 本地开发
217
+ ## Local Development
215
218
 
216
- 本项目采用 Monorepo 结构,使用 pnpm workspace 管理。
219
+ This project is a Monorepo managed by pnpm workspaces.
217
220
 
218
- ### 目录结构
221
+ ### Directory Structure
219
222
 
220
- - **`app/`**: 前端预览应用 (Vue 3 + Element Plus)
221
- - **`server/`**: 服务端核心逻辑、CLI 实现及 Vite 插件 (Koa + Commander)
222
- - **`font-icon/`**: 示例字体图标文件
223
+ - **`app/`**: Frontend preview application (Vue 3 + Element Plus)
224
+ - **`server/`**: Server-side core logic, CLI implementation, and Vite plugin (Koa + Commander)
225
+ - **`font-icon/`**: Example font icon files
223
226
 
224
- ### 开发命令
227
+ ### Development Commands
225
228
 
226
- 1. **安装依赖**
229
+ 1. **Install Dependencies**
227
230
 
228
231
  ```bash
229
232
  pnpm install
230
233
  ```
231
234
 
232
- 2. **启动开发环境**
235
+ 2. **Start Development Environment**
233
236
 
234
- 同时启动服务端和前端应用的开发模式:
237
+ Starts both the server and the frontend application in development mode:
235
238
 
236
239
  ```bash
237
240
  pnpm dev
238
241
  ```
239
242
 
240
- - Server 运行在 `http://localhost:3000` (默认)
241
- - App 运行在 Vite 开发服务器端口
243
+ - Server runs at `http://localhost:3000` (default)
244
+ - App runs on the Vite dev server port
242
245
 
243
- 3. **构建项目**
246
+ 3. **Build Project**
244
247
 
245
248
  ```bash
246
249
  pnpm build
@@ -248,7 +251,7 @@ interface IconInfo {
248
251
 
249
252
  ### FAQ
250
253
 
251
- 1. 报错:Error: Cannot find module '@rolldown/binding-darwin-universal'
254
+ 1. Error: Cannot find module '@rolldown/binding-darwin-universal'
252
255
 
253
256
  ```shell
254
257
  pnpm i -f
package/README_zh.md ADDED
@@ -0,0 +1,255 @@
1
+ # iconfont-preview-cli
2
+
3
+ [English](./README.md) | [中文文档](./README_zh.md)
4
+
5
+ 一个用于预览本地字体图标的命令行工具。它可以扫描指定目录下的 CSS 文件,解析出图标类名,并提供一个可视化的 Web 界面来预览、搜索和复制图标代码。
6
+
7
+ ## 功能特性
8
+
9
+ - **自动扫描**: 递归扫描指定目录下的所有 CSS 文件。
10
+ - **可视化预览**: 解析 CSS 中的 `content` 属性,展示图标及其类名。
11
+ - **一键复制**: 点击图标即可复制类名到剪贴板。
12
+ - **即时搜索**: 支持通过类名关键词快速筛选图标。
13
+ - **Vite 插件集成**: 提供 Vite 插件,方便在开发环境中直接集成图标预览服务。
14
+
15
+ ## 快速开始
16
+
17
+ ### 安装
18
+
19
+ ```bash
20
+ # 全局安装
21
+ npm install -g iconfont-preview-cli
22
+
23
+
24
+ # 或者在项目中安装
25
+ npm install -D iconfont-preview-cli
26
+ ```
27
+
28
+ ### 命令行使用 (CLI)
29
+
30
+ 在项目根目录下,你可以通过以下命令启动预览服务:
31
+
32
+ ```bash
33
+ # 预览指定目录下的字体图标
34
+ iconfont-preview-cli --dir ./path/to/your/fonts
35
+
36
+
37
+ # 指定端口 (默认 3000)
38
+ iconfont-preview-cli --dir ./path/to/your/fonts --port 8080
39
+ ```
40
+
41
+ ### 参数说明
42
+
43
+ | 参数 | 简写 | 描述 | 默认值 |
44
+ | -------- | ---- | -------------------------------------------- | ------ |
45
+ | `--dir` | `-d` | **(必填)** 包含字体图标 CSS 文件的文件夹路径 | - |
46
+ | `--port` | `-p` | 服务启动端口 | `3000` |
47
+
48
+ ## 安装与集成
49
+
50
+ ### 作为 Vite 插件使用
51
+
52
+ 如果你正在开发一个 Vite 项目,可以将此工具作为插件集成,在开发服务器中同时提供图标预览功能。
53
+
54
+ ```typescript
55
+ // vite.config.ts
56
+ import { iconfontServer } from "iconfont-preview-cli/server";
57
+
58
+ export default {
59
+ plugins: [
60
+ iconfontServer({
61
+ iconDir: "./src/assets/fonts", // 字体图标存放目录
62
+ urlPrefix: "/iconfont-proxy" // 代理路径前缀 (可选)
63
+ })
64
+ ]
65
+ };
66
+ ```
67
+
68
+ ### 组件
69
+
70
+ 除了 CLI 工具,本项目还导出了核心组件 `RenderIconList`,方便你在自己的 Vue 项目中定制图标预览页面。
71
+
72
+ ### 引入
73
+
74
+ ```typescript
75
+ import { RenderIconList } from "iconfont-preview-cli/components";
76
+ // 引入样式
77
+ import "iconfont-preview-cli/components/index.css";
78
+ import axios from "axios";
79
+ ```
80
+
81
+ ### 基本用法
82
+
83
+ ```vue
84
+ <template>
85
+ <div class="local-icon-demo">
86
+ <div class="local-icon-demo__header">
87
+ <el-input
88
+ v-model="keyword"
89
+ placeholder="输入关键字,回车搜索"
90
+ clearable
91
+ @change="onSearch"
92
+ />
93
+ </div>
94
+ <RenderIconList
95
+ ref="renderIconListRef"
96
+ :get-icons-info="getIconsInfo"
97
+ :css-link-format="cssLinkFormat"
98
+ >
99
+ <template #default="{ iconsInfo, renderIcon }">
100
+ <div v-for="info in iconsInfo" :key="info.filePath">
101
+ <h3>{{ info.filePath }}</h3>
102
+ <ul class="local-icon-demo__icon-list">
103
+ <li
104
+ v-for="className in info.classNames"
105
+ :key="className"
106
+ class="local-icon-demo__icon-li"
107
+ >
108
+ <!-- 使用 renderIcon 组件渲染图标 -->
109
+ <component
110
+ :is="renderIcon"
111
+ :icon-class="className"
112
+ :iconInfo="info"
113
+ />
114
+ </li>
115
+ </ul>
116
+ </div>
117
+ </template>
118
+ </RenderIconList>
119
+ </div>
120
+ </template>
121
+
122
+ <script setup lang="ts">
123
+ import { ref } from "vue";
124
+ import { RenderIconList } from "iconfont-preview-cli/components";
125
+ // 引入样式
126
+ import "iconfont-preview-cli/components/index.css";
127
+ import axios from "axios";
128
+ import type { RenderIconListInstance, IconInfo } from "iconfont-preview-cli/components";
129
+
130
+ /** 搜索关键字 */
131
+ const keyword = ref("");
132
+ const renderIconListRef = ref<RenderIconListInstance>();
133
+
134
+ // 获取图标数据的函数
135
+ const getIconsInfo = async (): Promise<IconInfo[]> => {
136
+ // 这里请求接口前缀替换为vite插件iconfontServer中urlPrefix的值
137
+ const res = await axios.get("/iconfont-proxy/api/iconsInfo");
138
+ const iconsInfo = res.data.data;
139
+ return iconsInfo;
140
+ };
141
+
142
+ // 动态加载字体样式
143
+ const cssLinkFormat = (href: string) => {
144
+ // 这里根据需求替换为字体样式的路径
145
+ return href && `/@/assets/font-icon${href}`;
146
+ };
147
+
148
+ // 调用搜索
149
+ const onSearch = (query: string) => {
150
+ renderIconListRef.value?.onSearch(query);
151
+ };
152
+ </script>
153
+
154
+ <style>
155
+ .local-icon-demo__header {
156
+ margin-bottom: 12px;
157
+ }
158
+
159
+ .local-icon-demo__icon-list {
160
+ display: grid;
161
+ grid-template-columns: repeat(7, minmax(120px, 1fr));
162
+ list-style: none;
163
+ }
164
+ .local-icon-demo__icon-li {
165
+ height: 120px;
166
+ }
167
+ </style>
168
+ ```
169
+
170
+ ### API
171
+
172
+ #### Props
173
+
174
+ | 属性名 | 类型 | 必填 | 描述 |
175
+ | --------------- | ----------------------------------------- | ---- | ------------------------------------------------- |
176
+ | `getIconsInfo` | `() => Promise<IconInfo[]> \| IconInfo[]` | 是 | 获取图标信息的函数,返回图标数据数组。 |
177
+ | `cssLinkFormat` | `(href: string) => string` | 否 | 格式化 CSS 文件链接的函数,用于动态加载字体样式。 |
178
+
179
+ #### Methods (Exposed)
180
+
181
+ | 方法名 | 参数 | 描述 |
182
+ | ---------- | ----------------- | ------------------------------------- |
183
+ | `onSearch` | `(query: string)` | 执行模糊搜索,过滤 `iconsInfo` 数据。 |
184
+
185
+ #### Slots
186
+
187
+ | 插槽名 | 参数 | 描述 |
188
+ | --------- | ------------------------------------------------------- | --------------------------------------------------------------- |
189
+ | `default` | `{ iconsInfo: InnerIconInfo[], renderIcon: Component }` | 自定义渲染列表内容。`renderIcon` 是一个用于渲染单个图标的组件。 |
190
+
191
+ ### renderIcon API
192
+
193
+ #### Props
194
+
195
+ | 属性名 | 类型 | 必填 | 描述 |
196
+ | ------------- | --------------------------------------------- | ---- | ------------------ |
197
+ | `copyHandler` | `(iconName: string) => void \| Promise<void>` | 否 | 自定义图标点击复制 |
198
+
199
+ #### Type Definitions
200
+
201
+ ```typescript
202
+ interface IconInfo {
203
+ /** CSS 文件相对路径 */
204
+ filePath: string;
205
+ /** 基础类名 (如 iconfont) */
206
+ baseClassName: string;
207
+ /** 图标类名列表 */
208
+ classNames: string[];
209
+ /** 自定义渲染图标的函数,返回一个组件 */
210
+ renderIcon?: (iconName: string) => Component;
211
+ }
212
+ ```
213
+
214
+ ## 本地开发
215
+
216
+ 本项目采用 Monorepo 结构,使用 pnpm workspace 管理。
217
+
218
+ ### 目录结构
219
+
220
+ - **`app/`**: 前端预览应用 (Vue 3 + Element Plus)
221
+ - **`server/`**: 服务端核心逻辑、CLI 实现及 Vite 插件 (Koa + Commander)
222
+ - **`font-icon/`**: 示例字体图标文件
223
+
224
+ ### 开发命令
225
+
226
+ 1. **安装依赖**
227
+
228
+ ```bash
229
+ pnpm install
230
+ ```
231
+
232
+ 2. **启动开发环境**
233
+
234
+ 同时启动服务端和前端应用的开发模式:
235
+
236
+ ```bash
237
+ pnpm dev
238
+ ```
239
+
240
+ - Server 运行在 `http://localhost:3000` (默认)
241
+ - App 运行在 Vite 开发服务器端口
242
+
243
+ 3. **构建项目**
244
+
245
+ ```bash
246
+ pnpm build
247
+ ```
248
+
249
+ ### FAQ
250
+
251
+ 1. Error: Cannot find module '@rolldown/binding-darwin-universal'
252
+
253
+ ```shell
254
+ pnpm i -f
255
+ ```