@varlet/cli 2.7.0 → 2.7.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 +91 -75
- package/README.zh-CN.md +211 -0
- package/lib/node/compiler/compileSFC.js +2 -2
- package/lib/node/config/varlet.config.d.ts +2 -1
- package/lib/node/config/vite.config.js +2 -1
- package/lib/varlet-cli/src/node/config/varlet.config.d.ts +44 -0
- package/lib/varlet-cli/src/node/config/varlet.config.js +27 -0
- package/lib/varlet-vite-plugins/src/copy.d.ts +9 -0
- package/lib/varlet-vite-plugins/src/copy.js +17 -0
- package/package.json +7 -7
- package/README.en-US.md +0 -198
package/README.md
CHANGED
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
# @varlet/cli
|
|
1
|
+
# Components Library Tools(@varlet/cli)
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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 `Typescript`
|
|
17
|
+
- 💪 Support `Dark Mode`
|
|
18
|
+
- 🌍 Support `Internationalization`
|
|
19
|
+
- 🚀 Based on `pnpm`
|
|
20
|
+
|
|
21
|
+
### Quickstart
|
|
22
|
+
|
|
23
|
+
`@varlet/cli` has built-in `sfc` and `tsx` style component library project templates, which can be generated directly by the `gen` command.
|
|
24
|
+
It is convenient for you to directly enter the component library development.
|
|
22
25
|
|
|
23
26
|
```shell
|
|
24
|
-
#
|
|
27
|
+
# playground-ignore
|
|
25
28
|
pnpm add @varlet/cli -g
|
|
26
29
|
varlet-cli gen
|
|
27
30
|
```
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
如果想在组件库中插入其他页面,可以在项目根目录下的创建 `pages` 文件夹编写 vue 组件, 用来生成其他的页面。
|
|
60
|
-
目录结构如下:
|
|
32
|
+
## Advanced customization
|
|
33
|
+
|
|
34
|
+
### Configuration file
|
|
35
|
+
|
|
36
|
+
The `varlet.config.mjs` in the project root directory is used to manage the specific details of the entire component library project.
|
|
37
|
+
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).
|
|
38
|
+
Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs).
|
|
39
|
+
|
|
40
|
+
| Parameter | Description | Type | Default |
|
|
41
|
+
| -- | -------------- | -------- | ---------- |
|
|
42
|
+
| `name` | The full name of the component library, which will be used as the package name | _string_ | `Varlet` |
|
|
43
|
+
| `namespace` | Component library namespace, which will be used as a component prefix | _string_ | `var` |
|
|
44
|
+
| `host` | Development server host | _number_ | `localhost` |
|
|
45
|
+
| `port` | Development server port | _number_ | `8080` |
|
|
46
|
+
| `title` | The title of the component library in the documentation | _string_ | `VARLET` |
|
|
47
|
+
| `logo` | The logo of the component library in the documentation | _string_ | `-` |
|
|
48
|
+
| `defaultLanguage` | Documentation default language | _string_ | `zh-CN` |
|
|
49
|
+
| `useMobile` | Whether to show the preview of the right mobile phone | _boolean_ | `false` |
|
|
50
|
+
| `lightTheme` | Light Mode Documentation Theme | _Record<string, any>_ | `-` |
|
|
51
|
+
| `darkTheme` | Dark Mode Documentation Theme | _Record<string, any>_ | `-` |
|
|
52
|
+
| `highlight` | Documentation snippet style related | _{ style: string }_ | `-` |
|
|
53
|
+
| `analysis` | Document statistics related | _{ baidu: string }_ | `-` |
|
|
54
|
+
| `pc` | PC-side document structure configuration | _Record<string, any>_ | `-` |
|
|
55
|
+
| `mobile` | Mobile side document structure configuration | _Record<string, any>_ | `-` |
|
|
56
|
+
| `copy` | Copy file options | _{ from: string, to: string, type: 'folder' | 'file' }[]_ | `-` |
|
|
57
|
+
|
|
58
|
+
### Custom pages
|
|
59
|
+
|
|
60
|
+
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.
|
|
61
|
+
The directory structure is as follows:
|
|
61
62
|
|
|
62
63
|
```text
|
|
64
|
+
// playground-ignore
|
|
63
65
|
|-- varlet-ui
|
|
64
66
|
|-- src
|
|
65
67
|
|-- docs
|
|
@@ -75,122 +77,136 @@ varlet-cli gen
|
|
|
75
77
|
|-- zh-CN.ts
|
|
76
78
|
|-- en-US.ts
|
|
77
79
|
|-- index.vue
|
|
80
|
+
|
|
78
81
|
```
|
|
79
82
|
|
|
80
|
-
|
|
83
|
+
The resulting route is as follows:
|
|
81
84
|
|
|
82
85
|
```text
|
|
86
|
+
// playground-ignore
|
|
83
87
|
/zh-CN/sponsor
|
|
84
88
|
/en-US/contributor
|
|
85
89
|
/zh-CN/changelog
|
|
86
90
|
/en-US/changelog
|
|
87
91
|
```
|
|
88
92
|
|
|
89
|
-
###
|
|
93
|
+
### Command related
|
|
90
94
|
|
|
91
|
-
####
|
|
95
|
+
#### Start the development server
|
|
92
96
|
|
|
93
97
|
```shell
|
|
98
|
+
# playground-ignore
|
|
94
99
|
varlet-cli dev
|
|
95
100
|
```
|
|
96
101
|
|
|
97
|
-
####
|
|
102
|
+
#### Build a documentation site
|
|
98
103
|
|
|
99
104
|
```shell
|
|
105
|
+
# playground-ignore
|
|
100
106
|
varlet-cli build
|
|
101
107
|
```
|
|
102
108
|
|
|
103
|
-
####
|
|
109
|
+
#### Preview documentation site
|
|
104
110
|
|
|
105
111
|
```shell
|
|
112
|
+
# playground-ignore
|
|
106
113
|
varlet-cli preview
|
|
107
114
|
```
|
|
108
115
|
|
|
109
|
-
####
|
|
116
|
+
#### Compile component library
|
|
110
117
|
|
|
111
118
|
```shell
|
|
119
|
+
# playground-ignore
|
|
112
120
|
varlet-cli compile
|
|
113
121
|
```
|
|
114
122
|
|
|
115
|
-
####
|
|
123
|
+
#### Execute all unit tests
|
|
116
124
|
|
|
117
125
|
```shell
|
|
126
|
+
# playground-ignore
|
|
118
127
|
varlet-cli test
|
|
119
128
|
```
|
|
120
129
|
|
|
121
|
-
####
|
|
130
|
+
#### Execute unit tests in watch mode
|
|
122
131
|
|
|
123
132
|
```shell
|
|
133
|
+
# playground-ignore
|
|
124
134
|
varlet-cli test -w
|
|
125
135
|
or
|
|
126
136
|
varlet-cli test -wa
|
|
127
137
|
```
|
|
128
138
|
|
|
129
|
-
####
|
|
139
|
+
#### Lint the code
|
|
130
140
|
|
|
131
141
|
```shell
|
|
142
|
+
# playground-ignore
|
|
132
143
|
varlet-cli lint
|
|
133
144
|
```
|
|
134
145
|
|
|
135
|
-
####
|
|
146
|
+
#### Lint git commit message
|
|
136
147
|
|
|
137
148
|
```shell
|
|
149
|
+
# playground-ignore
|
|
138
150
|
varlet-cli commit-lint
|
|
139
151
|
```
|
|
140
152
|
|
|
141
|
-
####
|
|
153
|
+
#### Generate changelog
|
|
142
154
|
|
|
143
155
|
```shell
|
|
156
|
+
# playground-ignore
|
|
144
157
|
varlet-cli changelog
|
|
145
158
|
```
|
|
146
159
|
|
|
147
|
-
####
|
|
160
|
+
#### Release component library
|
|
148
161
|
|
|
149
162
|
```shell
|
|
163
|
+
# playground-ignore
|
|
150
164
|
varlet-cli release
|
|
151
165
|
```
|
|
152
166
|
|
|
153
|
-
####
|
|
167
|
+
#### Generate a project template
|
|
154
168
|
|
|
155
169
|
```shell
|
|
170
|
+
# playground-ignore
|
|
156
171
|
varlet-cli gen
|
|
157
172
|
|
|
158
173
|
# Options
|
|
159
174
|
-n
|
|
160
175
|
--name
|
|
161
|
-
|
|
176
|
+
project name
|
|
162
177
|
-s
|
|
163
178
|
--sfc
|
|
164
|
-
|
|
179
|
+
Generate sfc-style project templates
|
|
165
180
|
-t
|
|
166
181
|
--tsx
|
|
167
|
-
|
|
182
|
+
Generate tsx-style project templates
|
|
168
183
|
-l
|
|
169
184
|
--locale
|
|
170
|
-
|
|
185
|
+
Need to support internationalization
|
|
171
186
|
```
|
|
172
187
|
|
|
173
|
-
####
|
|
188
|
+
#### Create a component template file
|
|
174
189
|
|
|
175
190
|
```shell
|
|
191
|
+
# playground-ignore
|
|
176
192
|
varlet-cli create
|
|
177
193
|
|
|
178
194
|
# Options
|
|
179
195
|
-n
|
|
180
196
|
--name
|
|
181
|
-
|
|
197
|
+
project name
|
|
182
198
|
-s
|
|
183
199
|
--sfc
|
|
184
|
-
|
|
200
|
+
Generate sfc-style component
|
|
185
201
|
-t
|
|
186
202
|
--tsx
|
|
187
|
-
|
|
203
|
+
Generate tsx-style component
|
|
188
204
|
-l
|
|
189
205
|
--locale
|
|
190
|
-
|
|
206
|
+
Need to support internationalization
|
|
191
207
|
```
|
|
192
208
|
|
|
193
|
-
###
|
|
209
|
+
### Note before publish
|
|
194
210
|
|
|
195
|
-
1
|
|
196
|
-
2.
|
|
211
|
+
- 1.`npm` repository registry must set to `npm` official mirror
|
|
212
|
+
- 2.Execute `npm login` to log in
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# 组件库快速成型工具(@varlet/cli)
|
|
2
|
+
|
|
3
|
+
### 介绍
|
|
4
|
+
|
|
5
|
+
开箱即用的 `Vue3组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题。
|
|
6
|
+
|
|
7
|
+
### 特性
|
|
8
|
+
|
|
9
|
+
- 📦 开箱即用的组件库开发环境
|
|
10
|
+
- 📦 开箱即用的组件库编译工具,支持导出 `esm`, `cjs`, `umd` 三种模块代码
|
|
11
|
+
- 🛠️ 基于配置文件的组件库文档站点,支持百度统计和主题定制
|
|
12
|
+
- 🛠️ 支持 `sfc` 和 `tsx` 两种风格的组件库编写风格
|
|
13
|
+
- 📦 开箱即用的代码检查工具
|
|
14
|
+
- 📦 开箱即用的单元测试工具
|
|
15
|
+
- 📦 开箱即用的代码发布工具,同时发布到 `npm` 和 `github`, 并自动生成更新日志
|
|
16
|
+
- 💪 支持 `Typescript`
|
|
17
|
+
- 💪 支持 `暗黑模式`
|
|
18
|
+
- 🌍 支持 `国际化`
|
|
19
|
+
- 🚀 基于 `pnpm`
|
|
20
|
+
|
|
21
|
+
### 快速开始
|
|
22
|
+
|
|
23
|
+
`@varlet/cli` 内置了 `sfc` 和 `tsx` 两种风格的组件库项目模板,可以通过 `gen` 命令直接生成。
|
|
24
|
+
方便您直接进入组件库开发。
|
|
25
|
+
|
|
26
|
+
```shell
|
|
27
|
+
# playground-ignore
|
|
28
|
+
pnpm add @varlet/cli -g
|
|
29
|
+
varlet-cli gen
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 高级定制
|
|
33
|
+
|
|
34
|
+
### 配置文件
|
|
35
|
+
|
|
36
|
+
项目根目录下的 `varlet.config.mjs` 用来管理整个组件库项目的具体细节。
|
|
37
|
+
默认配置可查阅 [varlet.default.config.ts](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.default.config.ts)。
|
|
38
|
+
也可以参考 `@varlet/ui` 的 [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs)。
|
|
39
|
+
|
|
40
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
41
|
+
| -- | -------------- | -------- | ---------- |
|
|
42
|
+
| `name` | 组件库全名,会作为包名 | _string_ | `Varlet` |
|
|
43
|
+
| `namespace` | 组件库命名空间, 会作为组件前缀 | _string_ | `var` |
|
|
44
|
+
| `host` | 开发服务器主机 | _number_ | `localhost` |
|
|
45
|
+
| `port` | 开发服务器端口 | _number_ | `8080` |
|
|
46
|
+
| `title` | 文档中组件库的标题 | _string_ | `VARLET` |
|
|
47
|
+
| `logo` | 文档中组件库的logo | _string_ | `-` |
|
|
48
|
+
| `defaultLanguage` | 文档默认语言 | _string_ | `zh-CN` |
|
|
49
|
+
| `useMobile` | 是否显示右侧手机预览 | _boolean_ | `false` |
|
|
50
|
+
| `lightTheme` | 亮色模式文档主题 | _Record<string, any>_ | `-` |
|
|
51
|
+
| `darkTheme` | 暗黑模式文档主题 | _Record<string, any>_ | `-` |
|
|
52
|
+
| `highlight` | 文档代码片段样式相关 | _{ style: string }_ | `-` |
|
|
53
|
+
| `analysis` | 文档统计相关 | _{ baidu: string }_ | `-` |
|
|
54
|
+
| `pc` | pc 端文档结构配置 | _Record<string, any>_ | `-` |
|
|
55
|
+
| `mobile` | mobile 端文档结构配置 | _Record<string, any>_ | `-` |
|
|
56
|
+
| `copy` | 复制文件配置 | _{ from: string, to: string, type: 'folder' | 'file' }[]_ | `-` |
|
|
57
|
+
|
|
58
|
+
### 自定义页面
|
|
59
|
+
|
|
60
|
+
如果想在组件库中插入其他页面,可以在项目根目录下的创建 `pages` 文件夹编写 vue 组件, 用来生成其他的页面。
|
|
61
|
+
目录结构如下:
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
// playground-ignore
|
|
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
|
+
生成的路由如下:
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
// playground-ignore
|
|
86
|
+
/zh-CN/sponsor
|
|
87
|
+
/en-US/contributor
|
|
88
|
+
/zh-CN/changelog
|
|
89
|
+
/en-US/changelog
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 命令相关
|
|
93
|
+
|
|
94
|
+
#### 启动开发服务器
|
|
95
|
+
|
|
96
|
+
```shell
|
|
97
|
+
# playground-ignore
|
|
98
|
+
varlet-cli dev
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### 构建文档站点
|
|
102
|
+
|
|
103
|
+
```shell
|
|
104
|
+
# playground-ignore
|
|
105
|
+
varlet-cli build
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### 预览文档站点
|
|
109
|
+
|
|
110
|
+
```shell
|
|
111
|
+
# playground-ignore
|
|
112
|
+
varlet-cli preview
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### 构建组件库
|
|
116
|
+
|
|
117
|
+
```shell
|
|
118
|
+
# playground-ignore
|
|
119
|
+
varlet-cli compile
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### 执行所有的单元测试
|
|
123
|
+
|
|
124
|
+
```shell
|
|
125
|
+
# playground-ignore
|
|
126
|
+
varlet-cli test
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### 以 watch 模式执行单元测试
|
|
130
|
+
|
|
131
|
+
```shell
|
|
132
|
+
# playground-ignore
|
|
133
|
+
varlet-cli test -w
|
|
134
|
+
or
|
|
135
|
+
varlet-cli test -wa
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### 检查代码
|
|
139
|
+
|
|
140
|
+
```shell
|
|
141
|
+
# playground-ignore
|
|
142
|
+
varlet-cli lint
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### 校验提交信息
|
|
146
|
+
|
|
147
|
+
```shell
|
|
148
|
+
# playground-ignore
|
|
149
|
+
varlet-cli commit-lint
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### 生成更新日志
|
|
153
|
+
|
|
154
|
+
```shell
|
|
155
|
+
# playground-ignore
|
|
156
|
+
varlet-cli changelog
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### 发布组件库
|
|
160
|
+
|
|
161
|
+
```shell
|
|
162
|
+
# playground-ignore
|
|
163
|
+
varlet-cli release
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### 生成一个项目模板
|
|
167
|
+
|
|
168
|
+
```shell
|
|
169
|
+
# playground-ignore
|
|
170
|
+
varlet-cli gen
|
|
171
|
+
|
|
172
|
+
# Options
|
|
173
|
+
-n
|
|
174
|
+
--name
|
|
175
|
+
项目名
|
|
176
|
+
-s
|
|
177
|
+
--sfc
|
|
178
|
+
生成 sfc 风格的项目模板
|
|
179
|
+
-t
|
|
180
|
+
--tsx
|
|
181
|
+
生成 tsx 格式项目
|
|
182
|
+
-l
|
|
183
|
+
--locale
|
|
184
|
+
需要支持国际化
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### 创建组件模板文件
|
|
188
|
+
|
|
189
|
+
```shell
|
|
190
|
+
# playground-ignore
|
|
191
|
+
varlet-cli create
|
|
192
|
+
|
|
193
|
+
# Options
|
|
194
|
+
-n
|
|
195
|
+
--name
|
|
196
|
+
组件名
|
|
197
|
+
-s
|
|
198
|
+
--sfc
|
|
199
|
+
生成 sfc 风格的组件
|
|
200
|
+
-t
|
|
201
|
+
--tsx
|
|
202
|
+
生成 tsx 风格的文件
|
|
203
|
+
-l
|
|
204
|
+
--locale
|
|
205
|
+
需要支持国际化
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 发布前注意
|
|
209
|
+
|
|
210
|
+
- 1.`npm` 的仓库源必须指向 `npm` 官方镜像
|
|
211
|
+
- 2.执行 `npm login` 进行登录
|
|
@@ -3,7 +3,7 @@ import hash from 'hash-sum';
|
|
|
3
3
|
import { parse, resolve } from 'path';
|
|
4
4
|
import { parse as parseSFC, compileTemplate, compileStyle } from '@vue/compiler-sfc';
|
|
5
5
|
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
6
|
-
import { compileScript } from './compileScript.js';
|
|
6
|
+
import { compileScript, getScriptExtname } from './compileScript.js';
|
|
7
7
|
import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
|
|
8
8
|
import logger from '../shared/logger.js';
|
|
9
9
|
const { readFile, writeFileSync } = fse;
|
|
@@ -59,7 +59,7 @@ export async function compileSFC(sfc) {
|
|
|
59
59
|
const file = replaceExt(sfc, `Sfc${index || ''}.${style.lang || 'css'}`);
|
|
60
60
|
const { base, dir } = parse(file);
|
|
61
61
|
const dependencyPath = normalizeStyleDependency(base, STYLE_IMPORT_RE);
|
|
62
|
-
const cssFile = resolve(dir,
|
|
62
|
+
const cssFile = resolve(dir, `./style/index${getScriptExtname()}`);
|
|
63
63
|
let { code } = compileStyle({
|
|
64
64
|
source: style.content,
|
|
65
65
|
filename: file,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CopyOptions } from '@varlet/vite-plugins';
|
|
1
2
|
export interface VarletConfig {
|
|
2
3
|
/**
|
|
3
4
|
* @default `Varlet`
|
|
@@ -38,7 +39,7 @@ export interface VarletConfig {
|
|
|
38
39
|
};
|
|
39
40
|
pc?: Record<string, any>;
|
|
40
41
|
mobile?: Record<string, any>;
|
|
41
|
-
|
|
42
|
+
copy?: CopyOptions['paths'];
|
|
42
43
|
}
|
|
43
44
|
export declare function defineConfig(config: VarletConfig): VarletConfig;
|
|
44
45
|
export declare function mergeStrategy(value: any, srcValue: any, key: string): any[] | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
|
3
|
+
import { markdown, html, inlineCss, copy } from '@varlet/vite-plugins';
|
|
4
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';
|
|
5
5
|
import { get } from 'lodash-es';
|
|
6
6
|
import { resolve } from 'path';
|
|
@@ -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`),
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface VarletConfig {
|
|
2
|
+
/**
|
|
3
|
+
* @default `Varlet`
|
|
4
|
+
* UI library name.
|
|
5
|
+
*/
|
|
6
|
+
name?: string;
|
|
7
|
+
/**
|
|
8
|
+
* @default `var`
|
|
9
|
+
* Component name prefix
|
|
10
|
+
*/
|
|
11
|
+
namespace?: string;
|
|
12
|
+
/**
|
|
13
|
+
* @default `localhost`
|
|
14
|
+
* Local dev server host
|
|
15
|
+
*/
|
|
16
|
+
host?: string;
|
|
17
|
+
/**
|
|
18
|
+
* @default `8080`
|
|
19
|
+
* Local dev server port
|
|
20
|
+
*/
|
|
21
|
+
port?: number;
|
|
22
|
+
title?: string;
|
|
23
|
+
logo?: string;
|
|
24
|
+
themeKey?: string;
|
|
25
|
+
defaultLanguage?: 'zh-CN' | 'en-US';
|
|
26
|
+
/**
|
|
27
|
+
* @default `false`
|
|
28
|
+
* Show mobile component on the right.
|
|
29
|
+
*/
|
|
30
|
+
useMobile?: boolean;
|
|
31
|
+
lightTheme?: Record<string, string>;
|
|
32
|
+
darkTheme?: Record<string, string>;
|
|
33
|
+
highlight?: {
|
|
34
|
+
style: string;
|
|
35
|
+
};
|
|
36
|
+
analysis?: {
|
|
37
|
+
baidu: string;
|
|
38
|
+
};
|
|
39
|
+
pc?: Record<string, any>;
|
|
40
|
+
mobile?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
export declare function defineConfig(config: VarletConfig): VarletConfig;
|
|
43
|
+
export declare function mergeStrategy(value: any, srcValue: any, key: string): any[] | undefined;
|
|
44
|
+
export declare function getVarletConfig(emit?: boolean): Promise<Required<VarletConfig>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
import { mergeWith } from 'lodash-es';
|
|
3
|
+
import { VARLET_CONFIG, SITE_CONFIG } from '../shared/constant.js';
|
|
4
|
+
import { outputFileSyncOnChange } from '../shared/fsUtils.js';
|
|
5
|
+
import { isArray } from '@varlet/shared';
|
|
6
|
+
import { pathToFileURL } from 'url';
|
|
7
|
+
const { pathExistsSync, statSync } = fse;
|
|
8
|
+
export function defineConfig(config) {
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
11
|
+
export function mergeStrategy(value, srcValue, key) {
|
|
12
|
+
if (key === 'features' && isArray(srcValue)) {
|
|
13
|
+
return srcValue;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function getVarletConfig(emit = false) {
|
|
17
|
+
const defaultConfig = (await import('./varlet.default.config.js')).default;
|
|
18
|
+
const config = pathExistsSync(VARLET_CONFIG)
|
|
19
|
+
? (await import(`${pathToFileURL(VARLET_CONFIG).href}?_t=${statSync(VARLET_CONFIG).mtimeMs}`)).default
|
|
20
|
+
: {};
|
|
21
|
+
const mergedConfig = mergeWith(defaultConfig, config, mergeStrategy);
|
|
22
|
+
if (emit) {
|
|
23
|
+
const source = JSON.stringify(mergedConfig, null, 2);
|
|
24
|
+
outputFileSyncOnChange(SITE_CONFIG, source);
|
|
25
|
+
}
|
|
26
|
+
return mergedConfig;
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
const { copyFileSync } = fse;
|
|
3
|
+
export function copy(options) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'vite-plugin-varlet-copy',
|
|
6
|
+
buildStart() {
|
|
7
|
+
options.paths.forEach((copyPath) => {
|
|
8
|
+
try {
|
|
9
|
+
copyFileSync(copyPath.from, copyPath.to);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
this.warn(e);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"vite": "4.0.4",
|
|
67
67
|
"vue": "3.2.25",
|
|
68
68
|
"vue-jest": "^5.0.0-alpha.8",
|
|
69
|
-
"@varlet/vite-plugins": "2.7.
|
|
70
|
-
"@varlet/shared": "2.7.
|
|
69
|
+
"@varlet/vite-plugins": "2.7.2",
|
|
70
|
+
"@varlet/shared": "2.7.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/babel__core": "^7.1.12",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"@types/node": "^18.7.20",
|
|
80
80
|
"@types/semver": "^7.3.9",
|
|
81
81
|
"@types/inquirer": "^9.0.2",
|
|
82
|
-
"@varlet/
|
|
83
|
-
"@varlet/
|
|
82
|
+
"@varlet/touch-emulator": "2.7.2",
|
|
83
|
+
"@varlet/icons": "2.7.2"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@vue/runtime-core": "3.2.16",
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"lodash-es": "^4.17.21",
|
|
91
91
|
"vue": "3.2.25",
|
|
92
92
|
"vue-router": "4.0.12",
|
|
93
|
-
"@varlet/icons": "2.7.
|
|
94
|
-
"@varlet/touch-emulator": "2.7.
|
|
93
|
+
"@varlet/icons": "2.7.2",
|
|
94
|
+
"@varlet/touch-emulator": "2.7.2"
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
97
|
"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
|
-
- 📦 Out-of-the-box component library development environment
|
|
8
|
-
- 📦 An out-of-the-box component library compilation tool that supports exporting `esm`, `cjs`, `umd` module codes
|
|
9
|
-
- 🛠️ Configuration file-based component library documentation site, support Baidu statistics and theme customization
|
|
10
|
-
- 🛠️ Supports both `sfc` and `tsx` styles for writing component libraries
|
|
11
|
-
- 📦 Out-of-the-box code inspection tool
|
|
12
|
-
- 📦 Out-of-the-box unit testing tools
|
|
13
|
-
- 📦 Out-of-the-box code publishing tool, publishes to both `npm` and `github`, and automatically generates changelogs
|
|
14
|
-
- 💪 Support for `Typescript`
|
|
15
|
-
- 💪 Support `Dark Mode`
|
|
16
|
-
- 🌍 Support `Internationalization`
|
|
17
|
-
- 🚀 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
|