@varlet/cli 2.7.1 → 2.7.3-alpha.1675176726761

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,65 +1,70 @@
1
- # @varlet/cli
1
+ # Components Library Tools
2
2
 
3
- 开箱即用的 `Vue3组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题
3
+ ### Intro
4
4
 
5
- ### 特性
6
- - 📦  开箱即用的组件库开发环境
7
- - 📦  开箱即用的组件库编译工具,支持导出 `esm`, `cjs`, `umd` 三种模块代码
8
- - 🛠️  基于配置文件的组件库文档站点,支持百度统计和主题定制
9
- - 🛠️  支持 `sfc` 和 `tsx` 两种风格的组件库编写风格
10
- - 📦  开箱即用的代码检查工具
11
- - 📦  开箱即用的单元测试工具
12
- - 📦  开箱即用的代码发布工具,同时发布到 `npm` 和 `github`, 并自动生成更新日志
13
- - 💪  支持 `Typescript`
14
- - 💪  支持 `暗黑模式`
15
- - 🌍  支持 `国际化`
16
- - 🚀  基于 `pnpm`
5
+ The out-of-the-box `Vue3 component library` rapid prototyping tool provides a series of commands and tools to solve the problem of component library development.
17
6
 
18
- ### 快速开始
7
+ ### Features
19
8
 
20
- `@varlet/cli` 内置了 `sfc` `tsx` 两种风格的组件库项目模板,可以通过 `gen` 命令直接生成。
21
- 方便您直接进入组件库开发。
9
+ - 📦  Out-of-the-box component library development environment
10
+ - 📦  An out-of-the-box component library compilation tool that supports exporting `esm`, `cjs`, `umd` module codes
11
+ - 🛠️  Configuration file-based component library documentation site, support Baidu statistics and theme customization
12
+ - 🛠️  Supports both `sfc` and `tsx` styles for writing component libraries
13
+ - 📦  Out-of-the-box code inspection tool
14
+ - 📦  Out-of-the-box unit testing tools
15
+ - 📦  Out-of-the-box code publishing tool, publishes to both `npm` and `github`, and automatically generates changelogs
16
+ - 💪  Support for `VSCode` extension development
17
+ - 💪  Support `build svg to web fonts`
18
+ - 💪  Support for `Typescript`
19
+ - 💪  Support `Dark Mode`
20
+ - 🌍  Support `Internationalization`
21
+ - 🚀  Based on `pnpm`
22
+
23
+ ### Quickstart
24
+
25
+ `@varlet/cli` has built-in `sfc` and `tsx` style component library project templates, which can be generated directly by the `gen` command.
26
+ It is convenient for you to directly enter the component library development.
22
27
 
23
28
  ```shell
24
- # 安装命令行工具
29
+ # playground-ignore
25
30
  pnpm add @varlet/cli -g
26
31
  varlet-cli gen
27
32
  ```
28
33
 
29
- 然后通过简单修改一些组件库模板的基础信息,就可以开始组件库的开发了
30
-
31
- ## 高级定制
32
-
33
- ### 配置文件
34
-
35
- 项目根目录下的 `varlet.config.mjs` 用来管理整个组件库项目的具体细节。
36
- 默认配置可查阅 [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.default.config.ts)。
37
- 也可以参考 `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs)
38
-
39
- | 参数 | 说明 | 类型 | 默认值 |
40
- | ----- | -------------- | -------- | ---------- |
41
- | `name` | 组件库全名,会作为包名 | _string_ | `Varlet` |
42
- | `namespace` | 组件库命名空间, 会作为组件前缀 | _string_ | `var` |
43
- | `host` | 开发服务器主机 | _string_ | `localhost` |
44
- | `port` | 开发服务器端口 | _number_ | `8080` |
45
- | `title` | 文档中组件库的标题 | _string_ | `VARLET` |
46
- | `logo` | 文档中组件库的logo | _string_ | `-` |
47
- | `defaultLanguage` | 文档默认语言 | _string_ | `zh-CN` |
48
- | `useMobile` | 是否显示右侧手机预览 | _boolean_ | `false` |
49
- | `lightTheme` | 亮色模式文档主题 | _Record<string, any>_ | `-` |
50
- | `darkTheme` | 暗黑模式文档主题 | _Record<string, any>_ | `-` |
51
- | `highlight` | 文档代码片段样式相关 | _{ style: string }_ | `-` |
52
- | `analysis` | 文档统计相关 | _{ baidu: string }_ | `-` |
53
- | `pc` | pc端文档结构配置 | _Record<string, any>_ | `-` |
54
- | `mobile` | mobile端文档结构配置 | _Record<string, any>_ | `-` |
55
- | `moduleCompatible` | 模块兼容配置 | _Record<string, string>_ | `-` |
56
-
57
- ### 自定义页面
58
-
59
- 如果想在组件库中插入其他页面,可以在项目根目录下的创建 `pages` 文件夹编写 vue 组件, 用来生成其他的页面。
60
- 目录结构如下:
34
+ ## Advanced customization
35
+
36
+ ### Configuration file
37
+
38
+ The `varlet.config.mjs` in the project root directory is used to manage the specific details of the entire component library project.
39
+ The default configuration can be viewed [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.default.config.ts).
40
+ Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs).
41
+
42
+ | Parameter | Description | Type | Default |
43
+ | -- | -------------- | -------- | ---------- |
44
+ | `name` | The full name of the component library, which will be used as the package name | _string_ | `Varlet` |
45
+ | `namespace` | Component library namespace, which will be used as a component prefix | _string_ | `var` |
46
+ | `host` | Development server host | _number_ | `localhost` |
47
+ | `port` | Development server port | _number_ | `8080` |
48
+ | `title` | The title of the component library in the documentation | _string_ | `VARLET` |
49
+ | `logo` | The logo of the component library in the documentation | _string_ | `-` |
50
+ | `defaultLanguage` | Documentation default language | _string_ | `zh-CN` |
51
+ | `useMobile` | Whether to show the preview of the right mobile phone | _boolean_ | `false` |
52
+ | `lightTheme` | Light Mode Documentation Theme | _Record<string, any>_ | `-` |
53
+ | `darkTheme` | Dark Mode Documentation Theme | _Record<string, any>_ | `-` |
54
+ | `highlight` | Documentation snippet style related | _{ style: string }_ | `-` |
55
+ | `analysis` | Document statistics related | _{ baidu: string }_ | `-` |
56
+ | `pc` | PC-side document structure configuration | _Record<string, any>_ | `-` |
57
+ | `mobile` | Mobile side document structure configuration | _Record<string, any>_ | `-` |
58
+ | `copy` | Copy file options | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `-` |
59
+ | `icons` | Font icon packaging related configuration | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
60
+
61
+ ### Custom pages
62
+
63
+ If you want to insert other pages into the component library, you can create a `pages` folder in the project root directory to write a vue component to generate other pages.
64
+ The directory structure is as follows:
61
65
 
62
66
  ```text
67
+ // playground-ignore
63
68
  |-- varlet-ui
64
69
  |-- src
65
70
  |-- docs
@@ -75,122 +80,157 @@ varlet-cli gen
75
80
  |-- zh-CN.ts
76
81
  |-- en-US.ts
77
82
  |-- index.vue
83
+
78
84
  ```
79
85
 
80
- 生成的路由如下:
86
+ The resulting route is as follows:
81
87
 
82
88
  ```text
89
+ // playground-ignore
83
90
  /zh-CN/sponsor
84
91
  /en-US/contributor
85
92
  /zh-CN/changelog
86
93
  /en-US/changelog
87
94
  ```
88
95
 
89
- ### 命令相关
96
+ ### Command related
90
97
 
91
- #### 启动开发服务器
98
+ #### Start the development server
92
99
 
93
100
  ```shell
101
+ # playground-ignore
94
102
  varlet-cli dev
95
103
  ```
96
104
 
97
- #### 构建文档站点
105
+ #### Build a documentation site
98
106
 
99
107
  ```shell
108
+ # playground-ignore
100
109
  varlet-cli build
101
110
  ```
102
111
 
103
- #### 预览文档站点
112
+ #### Preview documentation site
104
113
 
105
114
  ```shell
115
+ # playground-ignore
106
116
  varlet-cli preview
107
117
  ```
108
118
 
109
- #### 构建组件库代码
119
+ #### Compile component library
110
120
 
111
121
  ```shell
122
+ # playground-ignore
112
123
  varlet-cli compile
113
124
  ```
114
125
 
115
- #### 执行所有的单元测试
126
+ #### Run VSCode extension development environment
127
+
128
+ ```shell
129
+ # playground-ignore
130
+ varlet-cli dev:extension
131
+ ```
132
+
133
+ #### Build VSCode extension for production
134
+
135
+ ```shell
136
+ # playground-ignore
137
+ varlet-cli build:extension
138
+ ```
139
+
140
+ #### Build svg to web fonts
141
+
142
+ ```shell
143
+ # playground-ignore
144
+ varlet-cli build:icons
145
+ ```
146
+
147
+ #### Execute all unit tests
116
148
 
117
149
  ```shell
150
+ # playground-ignore
118
151
  varlet-cli test
119
152
  ```
120
153
 
121
- #### watch 模式执行单元测试
154
+ #### Execute unit tests in watch mode
122
155
 
123
156
  ```shell
157
+ # playground-ignore
124
158
  varlet-cli test -w
125
159
  or
126
160
  varlet-cli test -wa
127
161
  ```
128
162
 
129
- #### 检查代码
163
+ #### Lint the code
130
164
 
131
165
  ```shell
166
+ # playground-ignore
132
167
  varlet-cli lint
133
168
  ```
134
169
 
135
- #### 校验提交信息
170
+ #### Lint git commit message
136
171
 
137
172
  ```shell
173
+ # playground-ignore
138
174
  varlet-cli commit-lint
139
175
  ```
140
176
 
141
- #### 生成更新日志
177
+ #### Generate changelog
142
178
 
143
179
  ```shell
180
+ # playground-ignore
144
181
  varlet-cli changelog
145
182
  ```
146
183
 
147
- #### 发布组件库
184
+ #### Release component library
148
185
 
149
186
  ```shell
187
+ # playground-ignore
150
188
  varlet-cli release
151
189
  ```
152
190
 
153
- #### 生成一个项目模板
191
+ #### Generate a project template
154
192
 
155
193
  ```shell
194
+ # playground-ignore
156
195
  varlet-cli gen
157
196
 
158
197
  # Options
159
198
  -n
160
199
  --name
161
- 项目名
200
+ project name
162
201
  -s
163
202
  --sfc
164
- 生成 sfc 风格的项目模板
203
+ Generate sfc-style project templates
165
204
  -t
166
205
  --tsx
167
- 生成 tsx 格式项目
206
+ Generate tsx-style project templates
168
207
  -l
169
208
  --locale
170
- 需要支持国际化
209
+ Need to support internationalization
171
210
  ```
172
211
 
173
- #### 创建组件模板文件
212
+ #### Create a component template file
174
213
 
175
214
  ```shell
215
+ # playground-ignore
176
216
  varlet-cli create
177
217
 
178
218
  # Options
179
219
  -n
180
220
  --name
181
- 组件名
221
+ project name
182
222
  -s
183
223
  --sfc
184
- 生成 sfc 风格的组件
224
+ Generate sfc-style component
185
225
  -t
186
226
  --tsx
187
- 生成 tsx 风格的文件
227
+ Generate tsx-style component
188
228
  -l
189
229
  --locale
190
- 需要支持国际化
230
+ Need to support internationalization
191
231
  ```
192
232
 
193
- ### 发布前注意
233
+ ### Note before publish
194
234
 
195
- 1. `npm` 的仓库源必须指向 `npm` 官方镜像
196
- 2. 执行 `npm login` 进行登录
235
+ - 1.`npm` repository registry must set to `npm` official mirror
236
+ - 2.Execute `npm login` to log in
@@ -0,0 +1,235 @@
1
+ # 组件库快速成型工具
2
+
3
+ ### 介绍
4
+
5
+ 开箱即用的 `Vue3组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题。
6
+
7
+ ### 特性
8
+
9
+ - 📦 &nbsp;开箱即用的组件库开发环境
10
+ - 📦 &nbsp;开箱即用的组件库编译工具,支持导出 `esm`, `cjs`, `umd` 三种模块代码
11
+ - 🛠️ &nbsp;基于配置文件的组件库文档站点,支持百度统计和主题定制
12
+ - 🛠️ &nbsp;支持 `sfc` 和 `tsx` 两种风格的组件库编写风格
13
+ - 📦 &nbsp;开箱即用的代码检查工具
14
+ - 📦 &nbsp;开箱即用的单元测试工具
15
+ - 📦 &nbsp;开箱即用的代码发布工具,同时发布到 `npm` 和 `github`, 并自动生成更新日志
16
+ - 💪 &nbsp;支持 `VSCode` 插件开发
17
+ - 💪 &nbsp;支持 `字体图标打包`
18
+ - 💪 &nbsp;支持 `Typescript`
19
+ - 💪 &nbsp;支持 `暗黑模式`
20
+ - 🌍 &nbsp;支持 `国际化`
21
+ - 🚀 &nbsp;基于 `pnpm`
22
+
23
+ ### 快速开始
24
+
25
+ `@varlet/cli` 内置了 `sfc` 和 `tsx` 两种风格的组件库项目模板,可以通过 `gen` 命令直接生成。
26
+ 方便您直接进入组件库开发。
27
+
28
+ ```shell
29
+ # playground-ignore
30
+ pnpm add @varlet/cli -g
31
+ varlet-cli gen
32
+ ```
33
+
34
+ ## 高级定制
35
+
36
+ ### 配置文件
37
+
38
+ 项目根目录下的 `varlet.config.mjs` 用来管理整个组件库项目的具体细节。
39
+ 默认配置可查阅 [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.default.config.ts)。
40
+ 也可以参考 `@varlet/ui` 的 [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs)。
41
+
42
+ | 参数 | 说明 | 类型 | 默认值 |
43
+ | -- | -------------- | -------- | ---------- |
44
+ | `name` | 组件库全名,会作为包名 | _string_ | `Varlet` |
45
+ | `namespace` | 组件库命名空间, 会作为组件前缀 | _string_ | `var` |
46
+ | `host` | 开发服务器主机 | _number_ | `localhost` |
47
+ | `port` | 开发服务器端口 | _number_ | `8080` |
48
+ | `title` | 文档中组件库的标题 | _string_ | `VARLET` |
49
+ | `logo` | 文档中组件库的logo | _string_ | `-` |
50
+ | `defaultLanguage` | 文档默认语言 | _string_ | `zh-CN` |
51
+ | `useMobile` | 是否显示右侧手机预览 | _boolean_ | `false` |
52
+ | `lightTheme` | 亮色模式文档主题 | _Record<string, any>_ | `-` |
53
+ | `darkTheme` | 暗黑模式文档主题 | _Record<string, any>_ | `-` |
54
+ | `highlight` | 文档代码片段样式相关 | _{ style: string }_ | `-` |
55
+ | `analysis` | 文档统计相关 | _{ baidu: string }_ | `-` |
56
+ | `pc` | pc 端文档结构配置 | _Record<string, any>_ | `-` |
57
+ | `mobile` | mobile 端文档结构配置 | _Record<string, any>_ | `-` |
58
+ | `copy` | 复制文件配置 | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `-` |
59
+ | `icons` | 字体图标打包相关配置 | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
60
+
61
+ ### 自定义页面
62
+
63
+ 如果想在组件库中插入其他页面,可以在项目根目录下的创建 `pages` 文件夹编写 vue 组件, 用来生成其他的页面。
64
+ 目录结构如下:
65
+
66
+ ```text
67
+ // playground-ignore
68
+ |-- varlet-ui
69
+ |-- src
70
+ |-- docs
71
+ |-- pages
72
+ |-- sponsor
73
+ |-- index.vue
74
+ |-- contributor
75
+ |-- locale
76
+ |-- en-US.ts
77
+ |-- index.vue
78
+ |-- changelog
79
+ |-- locale
80
+ |-- zh-CN.ts
81
+ |-- en-US.ts
82
+ |-- index.vue
83
+ ```
84
+
85
+ 生成的路由如下:
86
+
87
+ ```text
88
+ // playground-ignore
89
+ /zh-CN/sponsor
90
+ /en-US/contributor
91
+ /zh-CN/changelog
92
+ /en-US/changelog
93
+ ```
94
+
95
+ ### 命令相关
96
+
97
+ #### 启动开发服务器
98
+
99
+ ```shell
100
+ # playground-ignore
101
+ varlet-cli dev
102
+ ```
103
+
104
+ #### 构建文档站点
105
+
106
+ ```shell
107
+ # playground-ignore
108
+ varlet-cli build
109
+ ```
110
+
111
+ #### 预览文档站点
112
+
113
+ ```shell
114
+ # playground-ignore
115
+ varlet-cli preview
116
+ ```
117
+
118
+ #### 构建组件库
119
+
120
+ ```shell
121
+ # playground-ignore
122
+ varlet-cli compile
123
+ ```
124
+
125
+ #### 启动 VSCode 插件开发环境
126
+
127
+ ```shell
128
+ # playground-ignore
129
+ varlet-cli dev:extension
130
+ ```
131
+
132
+ #### 构建 VSCode 插件
133
+
134
+ ```shell
135
+ # playground-ignore
136
+ varlet-cli build:extension
137
+ ```
138
+
139
+ #### 打包字体图标
140
+
141
+ ```shell
142
+ # playground-ignore
143
+ varlet-cli build:icons
144
+ ```
145
+
146
+ #### 执行所有的单元测试
147
+
148
+ ```shell
149
+ # playground-ignore
150
+ varlet-cli test
151
+ ```
152
+
153
+ #### 以 watch 模式执行单元测试
154
+
155
+ ```shell
156
+ # playground-ignore
157
+ varlet-cli test -w
158
+ or
159
+ varlet-cli test -wa
160
+ ```
161
+
162
+ #### 检查代码
163
+
164
+ ```shell
165
+ # playground-ignore
166
+ varlet-cli lint
167
+ ```
168
+
169
+ #### 校验提交信息
170
+
171
+ ```shell
172
+ # playground-ignore
173
+ varlet-cli commit-lint
174
+ ```
175
+
176
+ #### 生成更新日志
177
+
178
+ ```shell
179
+ # playground-ignore
180
+ varlet-cli changelog
181
+ ```
182
+
183
+ #### 发布组件库
184
+
185
+ ```shell
186
+ # playground-ignore
187
+ varlet-cli release
188
+ ```
189
+
190
+ #### 生成一个项目模板
191
+
192
+ ```shell
193
+ # playground-ignore
194
+ varlet-cli gen
195
+
196
+ # Options
197
+ -n
198
+ --name
199
+ 项目名
200
+ -s
201
+ --sfc
202
+ 生成 sfc 风格的项目模板
203
+ -t
204
+ --tsx
205
+ 生成 tsx 格式项目
206
+ -l
207
+ --locale
208
+ 需要支持国际化
209
+ ```
210
+
211
+ #### 创建组件模板文件
212
+
213
+ ```shell
214
+ # playground-ignore
215
+ varlet-cli create
216
+
217
+ # Options
218
+ -n
219
+ --name
220
+ 组件名
221
+ -s
222
+ --sfc
223
+ 生成 sfc 风格的组件
224
+ -t
225
+ --tsx
226
+ 生成 tsx 风格的文件
227
+ -l
228
+ --locale
229
+ 需要支持国际化
230
+ ```
231
+
232
+ ### 发布前注意
233
+
234
+ - 1.`npm` 的仓库源必须指向 `npm` 官方镜像
235
+ - 2.执行 `npm login` 进行登录
package/lib/node/bin.js CHANGED
@@ -18,6 +18,13 @@ program
18
18
  const { build } = await import('./commands/build.js');
19
19
  return build();
20
20
  });
21
+ program
22
+ .command('dev:vite')
23
+ .description('Use vite start server for development')
24
+ .action(async () => {
25
+ const { vite } = await import('./commands/vite.js');
26
+ return vite('dev');
27
+ });
21
28
  program
22
29
  .command('build:vite')
23
30
  .description('Use vite build app for production')
@@ -26,11 +33,25 @@ program
26
33
  return vite('build');
27
34
  });
28
35
  program
29
- .command('dev:vite')
30
- .description('Use vite start server for development')
36
+ .command('dev:extension')
37
+ .description('Run VSCode extension development environment')
31
38
  .action(async () => {
32
- const { vite } = await import('./commands/vite.js');
33
- return vite('dev');
39
+ const { extension } = await import('./commands/extension.js');
40
+ return extension('dev');
41
+ });
42
+ program
43
+ .command('build:extension')
44
+ .description('Build VSCode extension for production')
45
+ .action(async () => {
46
+ const { extension } = await import('./commands/extension.js');
47
+ return extension('build');
48
+ });
49
+ program
50
+ .command('build:icons')
51
+ .description('Build icons')
52
+ .action(async () => {
53
+ const { icons } = await import('./commands/icons.js');
54
+ return icons();
34
55
  });
35
56
  program
36
57
  .command('preview')
@@ -1,6 +1,5 @@
1
- interface ChangelogCommandOptions {
1
+ export interface ChangelogCommandOptions {
2
2
  file?: string;
3
3
  releaseCount?: number;
4
4
  }
5
5
  export declare function changelog({ releaseCount, file }?: ChangelogCommandOptions): Promise<void>;
6
- export {};
@@ -1,8 +1,7 @@
1
- interface CreateCommandOptions {
1
+ export interface CreateCommandOptions {
2
2
  name?: string;
3
3
  locale?: boolean;
4
4
  sfc?: boolean;
5
5
  tsx?: boolean;
6
6
  }
7
7
  export declare function create(options: CreateCommandOptions): Promise<void>;
8
- export {};
@@ -0,0 +1,3 @@
1
+ import { type ExtensionMode } from '../config/vite.config.js';
2
+ export declare type ExtensionCommandMode = ExtensionMode;
3
+ export declare function extension(mode: ExtensionCommandMode): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import { build } from 'vite';
2
+ import { getExtensionConfig } from '../config/vite.config.js';
3
+ export async function extension(mode) {
4
+ await build(getExtensionConfig(mode));
5
+ }
@@ -1,8 +1,7 @@
1
- interface GenCommandOptions {
1
+ export interface GenCommandOptions {
2
2
  name?: string;
3
3
  i18n?: boolean;
4
4
  sfc?: boolean;
5
5
  tsx?: boolean;
6
6
  }
7
7
  export declare function gen(options: GenCommandOptions): Promise<void>;
8
- export {};
@@ -0,0 +1 @@
1
+ export declare function icons(): Promise<void>;
@@ -0,0 +1,105 @@
1
+ import fse from 'fs-extra';
2
+ import sharp from 'sharp';
3
+ import webfont from 'webfont';
4
+ import logger from '../shared/logger.js';
5
+ import { parse, resolve } from 'path';
6
+ import { ICONS_DIST_DIR, ICONS_CSS_DIR, ICONS_PNG_DIR, ICONS_FONTS_DIR, ICONS_SVG_DIR } from '../shared/constant.js';
7
+ import { getVarletConfig } from '../config/varlet.config.js';
8
+ import { get } from 'lodash-es';
9
+ const { removeSync, ensureDir, writeFile, readdirSync } = fse;
10
+ async function removeDir() {
11
+ removeSync(ICONS_DIST_DIR);
12
+ await Promise.all([ensureDir(ICONS_FONTS_DIR), ensureDir(ICONS_CSS_DIR), ensureDir(ICONS_PNG_DIR)]);
13
+ }
14
+ async function buildPNG(svgFiles) {
15
+ await Promise.all(svgFiles.map((svg) => {
16
+ return new Promise((done) => {
17
+ const { name } = parse(svg);
18
+ sharp(resolve(ICONS_SVG_DIR, svg))
19
+ .resize({ height: 100 })
20
+ .toBuffer()
21
+ .then((buffer) => {
22
+ sharp({
23
+ create: {
24
+ width: 100,
25
+ height: 100,
26
+ channels: 4,
27
+ background: '#4a7afe',
28
+ },
29
+ })
30
+ .composite([
31
+ {
32
+ input: buffer,
33
+ blend: 'dest-in',
34
+ },
35
+ ])
36
+ .png()
37
+ .toFile(resolve(ICONS_PNG_DIR, `${name}.png`))
38
+ .then(() => {
39
+ done();
40
+ });
41
+ });
42
+ });
43
+ }));
44
+ }
45
+ function buildWebFont(name) {
46
+ return webfont.default({
47
+ files: `${ICONS_SVG_DIR}/*.svg`,
48
+ fontName: name,
49
+ formats: ['ttf'],
50
+ fontHeight: 512,
51
+ descent: 64,
52
+ });
53
+ }
54
+ export async function icons() {
55
+ const varletConfig = await getVarletConfig();
56
+ const { name, namespace, base64, publicPath, fontFamilyClassName, fontWeight, fontStyle } = get(varletConfig, 'icons');
57
+ await removeDir();
58
+ const svgFiles = readdirSync(ICONS_SVG_DIR);
59
+ const [{ ttf }] = await Promise.all([buildWebFont(name), buildPNG(svgFiles)]);
60
+ const icons = svgFiles.map((svgName) => {
61
+ const i = svgName.indexOf('-');
62
+ const extIndex = svgName.lastIndexOf('.');
63
+ return {
64
+ name: svgName.slice(i + 1, extIndex),
65
+ pointCode: svgName.slice(1, i),
66
+ };
67
+ });
68
+ const iconNames = icons.map((iconName) => ` '${iconName.name}'`);
69
+ const indexTemplate = `\
70
+ export const pointCodes = {
71
+ ${icons.map(({ pointCode, name }) => `'${name}': '${pointCode}'`).join(',\n ')}
72
+ }
73
+
74
+ export default [
75
+ ${iconNames.join(',\n')}
76
+ ]
77
+ `;
78
+ const cssTemplate = `\
79
+ @font-face {
80
+ font-family: "${name}";
81
+ src: url("${base64 ? `data:font/truetype;charset=utf-8;base64,${ttf.toString('base64')}` : `${publicPath}${name}-webfont.ttf`}") format("truetype");
82
+ font-weight: ${fontWeight};
83
+ font-style: ${fontStyle};
84
+ }
85
+
86
+ .${fontFamilyClassName} {
87
+ font-family: "${name}";
88
+ }
89
+
90
+ ${icons
91
+ .map((icon) => {
92
+ return `.${namespace}-${icon.name}::before {
93
+ content: "\\${icon.pointCode}";
94
+ }`;
95
+ })
96
+ .join('\n\n')}
97
+ `;
98
+ await Promise.all([
99
+ writeFile(resolve(ICONS_FONTS_DIR, `${name}-webfont.ttf`), ttf),
100
+ writeFile(resolve(ICONS_CSS_DIR, `${name}.css`), cssTemplate),
101
+ writeFile(resolve(ICONS_CSS_DIR, `${name}.less`), cssTemplate),
102
+ writeFile(resolve(ICONS_DIST_DIR, 'index.js'), indexTemplate),
103
+ ]);
104
+ logger.success('build success!');
105
+ }
@@ -1,8 +1,7 @@
1
- interface JestCommandOptions {
1
+ export interface JestCommandOptions {
2
2
  watch?: boolean;
3
3
  watchAll?: boolean;
4
4
  component?: string;
5
5
  clearCache?: boolean;
6
6
  }
7
7
  export declare function jest(cmd: JestCommandOptions): Promise<void>;
8
- export {};
@@ -1,6 +1,5 @@
1
- interface ReleaseCommandOptions {
1
+ export interface ReleaseCommandOptions {
2
2
  remote?: string;
3
3
  task?(): Promise<void>;
4
4
  }
5
5
  export declare function release(options: ReleaseCommandOptions): Promise<void>;
6
- export {};
@@ -1,3 +1,2 @@
1
- declare type ViteCommandMode = 'dev' | 'build';
1
+ export declare type ViteCommandMode = 'dev' | 'build';
2
2
  export declare function vite(mode: ViteCommandMode): Promise<void>;
3
- export {};
@@ -1,3 +1,25 @@
1
+ import { type CopyOptions } from '@varlet/vite-plugins';
2
+ export interface VarletConfigIcons {
3
+ /**
4
+ * @default `varlet-icons`
5
+ * Font name.
6
+ */
7
+ name?: string;
8
+ /**
9
+ * @default `var-icon`
10
+ * Font name prefix.
11
+ */
12
+ namespace?: string;
13
+ /**
14
+ * @default `true`
15
+ * Output base64
16
+ */
17
+ base64?: boolean;
18
+ publicPath?: string;
19
+ fontFamilyClassName?: string;
20
+ fontWeight?: string;
21
+ fontStyle?: string;
22
+ }
1
23
  export interface VarletConfig {
2
24
  /**
3
25
  * @default `Varlet`
@@ -38,7 +60,8 @@ export interface VarletConfig {
38
60
  };
39
61
  pc?: Record<string, any>;
40
62
  mobile?: Record<string, any>;
41
- moduleCompatible?: Record<string, string>;
63
+ copy?: CopyOptions['paths'];
64
+ icons?: VarletConfigIcons;
42
65
  }
43
66
  export declare function defineConfig(config: VarletConfig): VarletConfig;
44
67
  export declare function mergeStrategy(value: any, srcValue: any, key: string): any[] | undefined;
@@ -259,4 +259,12 @@ export default defineConfig({
259
259
  'color-hl-group-h': '#14a6e9',
260
260
  'color-hl-group-i': '#ed4648',
261
261
  },
262
+ icons: {
263
+ name: 'varlet-icons',
264
+ namespace: 'var-icon',
265
+ fontStyle: 'normal',
266
+ fontWeight: 'normal',
267
+ fontFamilyClassName: 'var-icon--set',
268
+ base64: true,
269
+ },
262
270
  });
@@ -9,3 +9,5 @@ export interface BundleBuildOptions {
9
9
  emptyOutDir: boolean;
10
10
  }
11
11
  export declare function getBundleConfig(varletConfig: Required<VarletConfig>, buildOptions: BundleBuildOptions): InlineConfig;
12
+ export declare type ExtensionMode = 'dev' | 'build';
13
+ export declare function getExtensionConfig(mode: ExtensionMode): InlineConfig;
@@ -1,7 +1,7 @@
1
1
  import vue from '@vitejs/plugin-vue';
2
2
  import jsx from '@vitejs/plugin-vue-jsx';
3
- import { markdown, html, inlineCss } from '@varlet/vite-plugins';
4
- import { ES_DIR, SITE_CONFIG, SITE_DIR, SITE_MOBILE_ROUTES, SITE_OUTPUT_PATH, SITE_PC_ROUTES, SITE_PUBLIC_PATH, VITE_RESOLVE_EXTENSIONS, } from '../shared/constant.js';
3
+ import { markdown, html, inlineCss, copy } from '@varlet/vite-plugins';
4
+ import { ES_DIR, SITE_CONFIG, SITE_DIR, SITE_MOBILE_ROUTES, SITE_OUTPUT_PATH, SITE_PC_ROUTES, SITE_PUBLIC_PATH, VITE_RESOLVE_EXTENSIONS, EXTENSION_ENTRY, } from '../shared/constant.js';
5
5
  import { get } from 'lodash-es';
6
6
  import { resolve } from 'path';
7
7
  export function getDevConfig(varletConfig) {
@@ -28,6 +28,7 @@ export function getDevConfig(varletConfig) {
28
28
  }),
29
29
  jsx(),
30
30
  markdown({ style: get(varletConfig, 'highlight.style') }),
31
+ copy({ paths: get(varletConfig, 'copy', []) }),
31
32
  html({
32
33
  data: {
33
34
  logo: get(varletConfig, `logo`),
@@ -89,3 +90,19 @@ export function getBundleConfig(varletConfig, buildOptions) {
89
90
  },
90
91
  };
91
92
  }
93
+ export function getExtensionConfig(mode) {
94
+ return {
95
+ build: {
96
+ sourcemap: mode === 'dev' ? 'inline' : false,
97
+ watch: mode === 'dev' ? {} : null,
98
+ lib: {
99
+ entry: EXTENSION_ENTRY,
100
+ fileName: 'extension',
101
+ formats: ['cjs'],
102
+ },
103
+ rollupOptions: {
104
+ external: ['vscode'],
105
+ },
106
+ },
107
+ };
108
+ }
@@ -11,3 +11,4 @@ export * from './commands/lint.js';
11
11
  export * from './commands/changelog.js';
12
12
  export * from './commands/preview.js';
13
13
  export * from './commands/vite.js';
14
+ export * from './commands/extension.js';
package/lib/node/index.js CHANGED
@@ -11,3 +11,4 @@ export * from './commands/lint.js';
11
11
  export * from './commands/changelog.js';
12
12
  export * from './commands/preview.js';
13
13
  export * from './commands/vite.js';
14
+ export * from './commands/extension.js';
@@ -39,4 +39,10 @@ export declare const HL_DIR: string;
39
39
  export declare const HL_TAGS_JSON: string;
40
40
  export declare const HL_ATTRIBUTES_JSON: string;
41
41
  export declare const HL_WEB_TYPES_JSON: string;
42
+ export declare const ICONS_DIST_DIR: string;
43
+ export declare const ICONS_CSS_DIR: string;
44
+ export declare const ICONS_PNG_DIR: string;
45
+ export declare const ICONS_FONTS_DIR: string;
46
+ export declare const ICONS_SVG_DIR: string;
47
+ export declare const EXTENSION_ENTRY: string;
42
48
  export declare const JEST_CONFIG: string;
@@ -43,5 +43,13 @@ export const HL_DIR = resolve(CWD, 'highlight');
43
43
  export const HL_TAGS_JSON = resolve(HL_DIR, 'tags.json');
44
44
  export const HL_ATTRIBUTES_JSON = resolve(HL_DIR, 'attributes.json');
45
45
  export const HL_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.json');
46
+ // icons
47
+ export const ICONS_DIST_DIR = resolve(CWD, 'dist');
48
+ export const ICONS_CSS_DIR = resolve(ICONS_DIST_DIR, 'css');
49
+ export const ICONS_PNG_DIR = resolve(ICONS_DIST_DIR, 'png');
50
+ export const ICONS_FONTS_DIR = resolve(ICONS_DIST_DIR, 'fonts');
51
+ export const ICONS_SVG_DIR = resolve(CWD, 'svg');
52
+ // extension
53
+ export const EXTENSION_ENTRY = resolve(CWD, 'src/extension.ts');
46
54
  // jest
47
55
  export const JEST_CONFIG = resolve(dirname, '../../../cjs/jest.config.cjs');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.7.1",
3
+ "version": "2.7.3-alpha.1675176726761",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -44,6 +44,8 @@
44
44
  "@vue/babel-plugin-jsx": "1.1.1",
45
45
  "@vue/compiler-sfc": "3.2.25",
46
46
  "@vue/runtime-core": "3.2.25",
47
+ "webfont": "^9.0.0",
48
+ "sharp": "0.31.3",
47
49
  "babel-jest": "26.6.3",
48
50
  "chalk": "^4.1.0",
49
51
  "chokidar": "^3.5.2",
@@ -66,8 +68,8 @@
66
68
  "vite": "4.0.4",
67
69
  "vue": "3.2.25",
68
70
  "vue-jest": "^5.0.0-alpha.8",
69
- "@varlet/shared": "2.7.1",
70
- "@varlet/vite-plugins": "2.7.1"
71
+ "@varlet/vite-plugins": "2.7.3-alpha.1675176726761",
72
+ "@varlet/shared": "2.7.3-alpha.1675176726761"
71
73
  },
72
74
  "devDependencies": {
73
75
  "@types/babel__core": "^7.1.12",
@@ -79,8 +81,9 @@
79
81
  "@types/node": "^18.7.20",
80
82
  "@types/semver": "^7.3.9",
81
83
  "@types/inquirer": "^9.0.2",
82
- "@varlet/icons": "2.7.1",
83
- "@varlet/touch-emulator": "2.7.1"
84
+ "@types/sharp": "0.31.1",
85
+ "@varlet/icons": "2.7.3-alpha.1675176726761",
86
+ "@varlet/touch-emulator": "2.7.3-alpha.1675176726761"
84
87
  },
85
88
  "peerDependencies": {
86
89
  "@vue/runtime-core": "3.2.16",
@@ -90,8 +93,8 @@
90
93
  "lodash-es": "^4.17.21",
91
94
  "vue": "3.2.25",
92
95
  "vue-router": "4.0.12",
93
- "@varlet/icons": "2.7.1",
94
- "@varlet/touch-emulator": "2.7.1"
96
+ "@varlet/icons": "2.7.3-alpha.1675176726761",
97
+ "@varlet/touch-emulator": "2.7.3-alpha.1675176726761"
95
98
  },
96
99
  "scripts": {
97
100
  "dev": "tsc --watch",
package/README.en-US.md DELETED
@@ -1,198 +0,0 @@
1
- # @varlet/cli
2
-
3
- The out-of-the-box `Vue3 component library` rapid prototyping tool provides a series of commands and tools to solve the problem of component library development
4
-
5
- ### Feature
6
-
7
- - 📦 &nbsp;Out-of-the-box component library development environment
8
- - 📦 &nbsp;An out-of-the-box component library compilation tool that supports exporting `esm`, `cjs`, `umd` module codes
9
- - 🛠️ &nbsp;Configuration file-based component library documentation site, support Baidu statistics and theme customization
10
- - 🛠️ &nbsp;Supports both `sfc` and `tsx` styles for writing component libraries
11
- - 📦 &nbsp;Out-of-the-box code inspection tool
12
- - 📦 &nbsp;Out-of-the-box unit testing tools
13
- - 📦 &nbsp;Out-of-the-box code publishing tool, publishes to both `npm` and `github`, and automatically generates changelogs
14
- - 💪 &nbsp;Support for `Typescript`
15
- - 💪 &nbsp;Support `Dark Mode`
16
- - 🌍 &nbsp;Support `Internationalization`
17
- - 🚀 &nbsp;Based on `pnpm`
18
-
19
- ### Quickstart
20
-
21
- `@varlet/cli` has built-in `sfc` and `tsx` style component library project templates, which can be generated directly by the `gen` command.
22
- It is convenient for you to directly enter the component library development.
23
-
24
- ```shell
25
- # Install command line tools
26
- pnpm add @varlet/cli -g
27
- varlet-cli gen
28
- ```
29
-
30
- Then by simply modifying some basic information of the component library template,
31
- you can start the development of the component library
32
-
33
- ## Advanced customization
34
-
35
- ### Configuration file
36
-
37
- The `varlet.config.mjs` in the project root directory is used to manage the specific details of the entire component library project.
38
- The default configuration can be viewed [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.default.config.ts)。
39
- Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs)
40
-
41
- | Parameter | Description | Type | Default |
42
- | -- | -------------- | -------- | ---------- |
43
- | `name` | The full name of the component library, which will be used as the package name | _string_ | `Varlet` |
44
- | `namespace` | Component library namespace, which will be used as a component prefix | _string_ | `var` |
45
- | `host` | Development server host | _string_ | `localhost` |
46
- | `port` | Development server port | _number_ | `8080` |
47
- | `title` | The title of the component library in the documentation | _string_ | `VARLET` |
48
- | `logo` | The logo of the component library in the documentation | _string_ | `-` |
49
- | `defaultLanguage` | Documentation default language | _string_ | `zh-CN` |
50
- | `useMobile` | Whether to show the preview of the right mobile phone | _boolean_ | `false` |
51
- | `lightTheme` | Light Mode Documentation Theme | _Record<string, any>_ | `-` |
52
- | `darkTheme` | Dark Mode Documentation Theme | _Record<string, any>_ | `-` |
53
- | `highlight` | Documentation snippet style related | _{ style: string }_ | `-` |
54
- | `analysis` | Document statistics related | _{ baidu: string }_ | `-` |
55
- | `pc` | PC-side document structure configuration | _Record<string, any>_ | `-` |
56
- | `mobile` | Mobile side document structure configuration | _Record<string, any>_ | `-` |
57
- | `moduleCompatible` | Module Compatible Configurations | _Record<string, string>_ | `-` |
58
-
59
- ### Custom pages
60
-
61
- If you want to insert other pages into the component library, you can create a `pages` folder in the project root directory to write a vue component to generate other pages.
62
- The directory structure is as follows:
63
-
64
- ```text
65
- |-- varlet-ui
66
- |-- src
67
- |-- docs
68
- |-- pages
69
- |-- sponsor
70
- |-- index.vue
71
- |-- contributor
72
- |-- locale
73
- |-- en-US.ts
74
- |-- index.vue
75
- |-- changelog
76
- |-- locale
77
- |-- zh-CN.ts
78
- |-- en-US.ts
79
- |-- index.vue
80
- ```
81
-
82
- The resulting route is as follows:
83
-
84
- ```text
85
- /zh-CN/sponsor
86
- /en-US/contributor
87
- /zh-CN/changelog
88
- /en-US/changelog
89
- ```
90
-
91
- ### Commands related
92
-
93
- #### Start the development server
94
-
95
- ```shell
96
- varlet-cli dev
97
- ```
98
-
99
- #### Build documentation site
100
-
101
- ```shell
102
- varlet-cli build
103
- ```
104
-
105
- #### Preview documentation site
106
-
107
- ```shell
108
- varlet-cli preview
109
- ```
110
-
111
- #### Build component library code
112
-
113
- ```shell
114
- varlet-cli compile
115
- ```
116
-
117
- #### Perform all unit tests
118
-
119
- ```shell
120
- varlet-cli test
121
- ```
122
-
123
- #### Execute unit tests in watch mode
124
-
125
- ```shell
126
- varlet-cli test -w
127
- or
128
- varlet-cli test -wa
129
- ```
130
-
131
- #### Lint code
132
-
133
- ```shell
134
- varlet-cli lint
135
- ```
136
-
137
- #### Lint commit message
138
-
139
- ```shell
140
- varlet-cli commit-lint
141
- ```
142
-
143
- #### Generate changelog
144
-
145
- ```shell
146
- varlet-cli changelog
147
- ```
148
-
149
- #### Release component library
150
-
151
- ```shell
152
- varlet-cli release
153
- ```
154
-
155
- #### Generate a project template
156
-
157
- ```shell
158
- varlet-cli gen
159
-
160
- # Options
161
- -n
162
- --name
163
- project name
164
- -s
165
- --sfc
166
- Generate sfc-style project templates
167
- -t
168
- --tsx
169
- Generate tsx-style project templates
170
- -l
171
- --locale
172
- Need to support internationalization
173
- ```
174
-
175
- #### Create a component template file
176
-
177
- ```shell
178
- varlet-cli create
179
-
180
- # Options
181
- -n
182
- --name
183
- project name
184
- -s
185
- --sfc
186
- Generate sfc-style component
187
- -t
188
- --tsx
189
- Generate tsx-style component
190
- -l
191
- --locale
192
- Need to support internationalization
193
- ```
194
-
195
- ### Note before release
196
-
197
- - 1.`npm` repository registry must set to `npm` official mirror
198
- - 2.Execute `npm login` to log in