@varlet/cli 2.0.5 → 2.1.0-alpha.1666877950844

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 (143) hide show
  1. package/README.en-US.md +2 -2
  2. package/README.md +2 -2
  3. package/cjs/babel.config.cjs +29 -0
  4. package/cjs/babel.sfc.transform.cjs +18 -0
  5. package/cjs/jest.config.cjs +33 -0
  6. package/cjs/jest.media.mock.cjs +1 -0
  7. package/cjs/jest.style.mock.cjs +1 -0
  8. package/client.d.ts +1 -0
  9. package/client.js +1 -0
  10. package/lib/client/appType.d.ts +4 -0
  11. package/lib/client/appType.js +7 -0
  12. package/lib/client/index.d.ts +17 -0
  13. package/lib/client/index.js +106 -0
  14. package/lib/{bin.d.ts → node/bin.d.ts} +2 -2
  15. package/lib/node/bin.js +122 -0
  16. package/lib/{commands → node/commands}/build.d.ts +1 -1
  17. package/lib/node/commands/build.js +15 -0
  18. package/lib/{commands → node/commands}/changelog.d.ts +6 -6
  19. package/lib/node/commands/changelog.js +20 -0
  20. package/lib/{commands → node/commands}/commitLint.d.ts +1 -1
  21. package/lib/node/commands/commitLint.js +45 -0
  22. package/lib/{commands → node/commands}/compile.d.ts +7 -7
  23. package/lib/node/commands/compile.js +35 -0
  24. package/lib/{commands → node/commands}/create.d.ts +8 -8
  25. package/lib/node/commands/create.js +91 -0
  26. package/lib/{commands → node/commands}/dev.d.ts +5 -5
  27. package/lib/node/commands/dev.js +38 -0
  28. package/lib/{commands → node/commands}/gen.d.ts +8 -8
  29. package/lib/node/commands/gen.js +75 -0
  30. package/lib/{commands → node/commands}/jest.d.ts +8 -8
  31. package/lib/node/commands/jest.js +27 -0
  32. package/lib/{commands → node/commands}/lint.d.ts +1 -1
  33. package/lib/node/commands/lint.js +41 -0
  34. package/lib/{commands → node/commands}/preview.d.ts +1 -1
  35. package/lib/node/commands/preview.js +18 -0
  36. package/lib/{commands → node/commands}/release.d.ts +5 -5
  37. package/lib/node/commands/release.js +146 -0
  38. package/lib/{commands → node/commands}/vite.d.ts +3 -3
  39. package/lib/node/commands/vite.js +13 -0
  40. package/lib/{compiler → node/compiler}/compileModule.d.ts +5 -5
  41. package/lib/node/compiler/compileModule.js +74 -0
  42. package/lib/{compiler → node/compiler}/compileSFC.d.ts +2 -2
  43. package/lib/node/compiler/compileSFC.js +79 -0
  44. package/lib/{compiler → node/compiler}/compileScript.d.ts +17 -17
  45. package/lib/node/compiler/compileScript.js +141 -0
  46. package/lib/{compiler → node/compiler}/compileSiteEntry.d.ts +13 -13
  47. package/lib/node/compiler/compileSiteEntry.js +128 -0
  48. package/lib/{compiler → node/compiler}/compileStyle.d.ts +11 -11
  49. package/lib/node/compiler/compileStyle.js +39 -0
  50. package/lib/{compiler → node/compiler}/compileTemplateHighlight.d.ts +10 -10
  51. package/lib/node/compiler/compileTemplateHighlight.js +133 -0
  52. package/lib/{compiler → node/compiler}/compileTypes.d.ts +2 -2
  53. package/lib/node/compiler/compileTypes.js +45 -0
  54. package/lib/{config → node/config}/varlet.config.d.ts +45 -44
  55. package/lib/node/config/varlet.config.js +27 -0
  56. package/lib/node/config/varlet.default.config.d.ts +2 -0
  57. package/lib/node/config/varlet.default.config.js +264 -0
  58. package/lib/node/config/vite.config.d.ts +6 -0
  59. package/lib/node/config/vite.config.js +144 -0
  60. package/lib/node/index.d.ts +1 -0
  61. package/lib/node/index.js +1 -0
  62. package/lib/{shared → node/shared}/constant.d.ts +42 -43
  63. package/lib/node/shared/constant.js +47 -0
  64. package/lib/{shared → node/shared}/fsUtils.d.ts +13 -12
  65. package/lib/node/shared/fsUtils.js +48 -0
  66. package/lib/{shared → node/shared}/logger.d.ts +8 -8
  67. package/lib/node/shared/logger.js +18 -0
  68. package/package.json +22 -19
  69. package/{preset.js → preset.cjs} +1 -1
  70. package/site/components/button/index.ts +10 -10
  71. package/site/components/cell/index.ts +10 -10
  72. package/site/components/code-example/CodeExample.vue +2 -1
  73. package/site/components/code-example/codeExample.less +41 -41
  74. package/site/components/code-example/index.ts +10 -10
  75. package/site/components/context/zIndex.ts +20 -20
  76. package/site/components/icon/icon.less +26 -26
  77. package/site/components/icon/index.ts +10 -10
  78. package/site/components/icon/props.ts +24 -24
  79. package/site/components/loading/index.ts +10 -10
  80. package/site/components/progress/index.ts +10 -10
  81. package/site/components/snackbar/snackbar.less +135 -135
  82. package/site/components/styles/common.less +64 -64
  83. package/site/components/styles/elevation.less +126 -126
  84. package/site/components/styles/var.less +27 -27
  85. package/site/components/utils/components.ts +1 -4
  86. package/site/components/utils/elements.ts +1 -1
  87. package/site/index.html +49 -49
  88. package/site/mobile/App.vue +27 -26
  89. package/site/mobile/components/AppHome.vue +2 -1
  90. package/site/mobile/components/app-bar/index.ts +10 -10
  91. package/site/mobile/components/app-bar/props.ts +25 -25
  92. package/site/mobile.html +41 -41
  93. package/site/module.d.ts +5 -5
  94. package/site/pc/App.vue +2 -1
  95. package/site/pc/Layout.vue +2 -1
  96. package/site/pc/components/AppHeader.vue +4 -2
  97. package/site/pc/pages/index/index.vue +8 -4
  98. package/site/tsconfig.json +11 -11
  99. package/site/useProgress.ts +2 -1
  100. package/site/utils.ts +6 -137
  101. package/template/generators/config/default/base/{varlet.config.js → varlet.config.mjs} +2 -2
  102. package/template/generators/config/i18n/base/{varlet.config.js → varlet.config.mjs} +2 -2
  103. package/tsconfig.json +2 -9
  104. package/lib/bin.js +0 -102
  105. package/lib/commands/build.js +0 -67
  106. package/lib/commands/changelog.js +0 -27
  107. package/lib/commands/commitLint.js +0 -21
  108. package/lib/commands/compile.js +0 -119
  109. package/lib/commands/create.js +0 -166
  110. package/lib/commands/dev.js +0 -123
  111. package/lib/commands/gen.js +0 -138
  112. package/lib/commands/jest.js +0 -85
  113. package/lib/commands/lint.js +0 -123
  114. package/lib/commands/preview.js +0 -74
  115. package/lib/commands/release.js +0 -270
  116. package/lib/commands/vite.js +0 -69
  117. package/lib/compiler/compileModule.js +0 -190
  118. package/lib/compiler/compileSFC.js +0 -135
  119. package/lib/compiler/compileScript.js +0 -194
  120. package/lib/compiler/compileSiteEntry.js +0 -237
  121. package/lib/compiler/compileStyle.js +0 -91
  122. package/lib/compiler/compileTemplateHighlight.js +0 -193
  123. package/lib/compiler/compileTypes.js +0 -85
  124. package/lib/config/babel.config.d.ts +0 -2
  125. package/lib/config/babel.config.js +0 -31
  126. package/lib/config/babel.sfc.transform.d.ts +0 -1
  127. package/lib/config/babel.sfc.transform.js +0 -18
  128. package/lib/config/jest.config.d.ts +0 -1
  129. package/lib/config/jest.config.js +0 -37
  130. package/lib/config/jest.media.mock.d.ts +0 -0
  131. package/lib/config/jest.media.mock.js +0 -2
  132. package/lib/config/jest.style.mock.d.ts +0 -0
  133. package/lib/config/jest.style.mock.js +0 -2
  134. package/lib/config/varlet.config.js +0 -35
  135. package/lib/config/vite.config.d.ts +0 -5
  136. package/lib/config/vite.config.js +0 -162
  137. package/lib/index.d.ts +0 -1
  138. package/lib/index.js +0 -5
  139. package/lib/shared/constant.js +0 -50
  140. package/lib/shared/fsUtils.js +0 -108
  141. package/lib/shared/logger.js +0 -23
  142. package/site/mobile/components/AppType.vue +0 -22
  143. package/varlet.default.config.js +0 -267
@@ -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,2 @@
1
+ declare const _default: import("./varlet.config.js").VarletConfig;
2
+ export default _default;
@@ -0,0 +1,264 @@
1
+ import { defineConfig } from './varlet.config.js';
2
+ export default defineConfig({
3
+ name: 'Varlet',
4
+ namespace: 'var',
5
+ host: 'localhost',
6
+ port: 8080,
7
+ title: 'VARLET',
8
+ logo: 'https://varlet.gitee.io/varlet-ui/varlet_icon.png',
9
+ defaultLanguage: 'zh-CN',
10
+ highlight: {
11
+ /**
12
+ * @see https://highlightjs.org/
13
+ */
14
+ style: '//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/styles/nord.min.css',
15
+ },
16
+ analysis: {
17
+ baidu: '',
18
+ },
19
+ useMobile: false,
20
+ pc: {
21
+ menu: [],
22
+ redirect: '/index',
23
+ indexPage: {
24
+ description: {
25
+ 'zh-CN': 'Varlet 是一个基于 Vue3 开发的 Material 风格移动端组件库,全面拥抱 Vue3 生态,由社区团队维护。支持 Typescript、按需引入、暗黑模式、主题定制、国际化,并提供 VSCode 插件保障良好的开发体验',
26
+ 'en-US': 'Varlet is a Material design mobile component library developed based on Vue3, developed and maintained by partners in the community. Support Typescript, import on demand, dark mode, theme customization, internationalization, and provide VSCode plugin to ensure a good development experience',
27
+ },
28
+ started: {
29
+ 'zh-CN': '起步',
30
+ 'en-US': 'GET STARTED',
31
+ },
32
+ features: [
33
+ {
34
+ name: {
35
+ 'zh-CN': '组件丰富',
36
+ 'en-US': 'Rich components',
37
+ },
38
+ description: {
39
+ 'zh-CN': '提供 50 个高质量通用组件',
40
+ 'en-US': 'Provide 50 high quality general purpose components',
41
+ },
42
+ },
43
+ {
44
+ name: {
45
+ 'zh-CN': '按需引入',
46
+ 'en-US': 'On-Demand',
47
+ },
48
+ description: {
49
+ 'zh-CN': '每一个组件都可单独引入,并有着良好的 tree-shaking 优化',
50
+ 'en-US': 'Each component can be imported separately and has good tree-shaking optimization',
51
+ },
52
+ },
53
+ {
54
+ name: {
55
+ 'zh-CN': '主题定制',
56
+ 'en-US': 'Theme customization',
57
+ },
58
+ description: {
59
+ 'zh-CN': '内置亮色和暗色两种主题,支持组件的样式自定义',
60
+ 'en-US': 'Built-in light and dark themes, support style customization of components',
61
+ },
62
+ },
63
+ {
64
+ name: {
65
+ 'zh-CN': '国际化',
66
+ 'en-US': 'Locale',
67
+ },
68
+ description: {
69
+ 'zh-CN': '内置国际化 API,内置中文和英文的语言包',
70
+ 'en-US': 'Built-in i18n API, which supports both Chinese and English languages by default',
71
+ },
72
+ },
73
+ {
74
+ name: {
75
+ 'zh-CN': '支持 Typescript',
76
+ 'en-US': 'Support typescript',
77
+ },
78
+ description: {
79
+ 'zh-CN': '使用 Typescript 构建,提供良好的组件类型系统',
80
+ 'en-US': 'Built with typescript, which provides a nice components type system',
81
+ },
82
+ },
83
+ {
84
+ name: {
85
+ 'zh-CN': '服务端渲染',
86
+ 'en-US': 'Server-side rendering',
87
+ },
88
+ description: {
89
+ 'zh-CN': '对服务端渲染支持良好,并对 Nuxt 进行了适配',
90
+ 'en-US': 'Good support for server-side rendering and adaptation to Nuxt',
91
+ },
92
+ },
93
+ {
94
+ name: {
95
+ 'zh-CN': '国人开发',
96
+ 'en-US': 'Developed by Chinese',
97
+ },
98
+ description: {
99
+ 'zh-CN': '由国人开发,完善的中英文文档和后勤保障',
100
+ 'en-US': 'Complete Chinese and English documentation and logistics support',
101
+ },
102
+ },
103
+ {
104
+ name: {
105
+ 'zh-CN': 'IDE 支持',
106
+ 'en-US': 'IDE Code Support',
107
+ },
108
+ description: {
109
+ 'zh-CN': '支持在 webstorm,vscode 中的组件语法高亮, 并提供 vscode 插件为开发提升效率',
110
+ 'en-US': 'Supports to highlight the component syntax for webstorm and vscode, and provides a separate helper plugin for vscode',
111
+ },
112
+ },
113
+ {
114
+ name: {
115
+ 'zh-CN': '组件库快速成型工具',
116
+ 'en-US': 'Component library toolchain',
117
+ },
118
+ description: {
119
+ 'zh-CN': '开源了搭建本组件库的所有工具链,提供快速开发组件库的能力',
120
+ 'en-US': 'Open-sourced the toolchain for building this component library, providing the ability to rapidly develop the component library',
121
+ },
122
+ },
123
+ ],
124
+ contributors: {
125
+ label: {
126
+ 'zh-CN': '贡献者',
127
+ 'en-US': 'Contributors',
128
+ },
129
+ link: 'https://github.com/varletjs/varlet/graphs/contributors',
130
+ image: 'https://contrib.rocks/image?repo=varletjs/varlet',
131
+ },
132
+ license: {
133
+ 'zh-CN': '组件库基于 MIT 协议,您可以自由的使用和分享',
134
+ 'en-US': 'Released under the MIT License, You can use and share freely.',
135
+ },
136
+ copyright: {
137
+ 'zh-CN': 'Copyright © 2022 varletjs 组织成员以及 varlet 的贡献者们',
138
+ 'en-US': 'Copyright © 2022 varletjs member and varlet contributors.',
139
+ },
140
+ },
141
+ title: {
142
+ 'zh-CN': '面向 Vue3 的 Material 风格移动端组件库',
143
+ 'en-US': 'Material design mobile components built for Vue3',
144
+ },
145
+ header: {
146
+ i18n: {
147
+ 'zh-CN': '中文',
148
+ 'en-US': 'English',
149
+ },
150
+ versions: null,
151
+ github: 'https://github.com/varletjs/varlet',
152
+ playground: 'https://varlet.gitee.io/varlet-ui-playground',
153
+ darkMode: true,
154
+ },
155
+ clipboard: {
156
+ 'zh-CN': '代码已复制到剪切板',
157
+ 'en-US': 'The code has been copied to the clipboard',
158
+ },
159
+ fold: {
160
+ defaultFold: false,
161
+ foldHeight: 50,
162
+ },
163
+ },
164
+ mobile: {
165
+ redirect: '/home',
166
+ title: {
167
+ 'zh-CN': '面向 Vue3 的 Material 风格移动端组件库',
168
+ 'en-US': 'Material design mobile components built for Vue3',
169
+ },
170
+ header: {
171
+ i18n: {
172
+ 'zh-CN': '中文',
173
+ 'en-US': 'English',
174
+ },
175
+ github: 'https://github.com/varletjs/varlet',
176
+ darkMode: true,
177
+ },
178
+ },
179
+ themeKey: 'VARLET_THEME',
180
+ lightTheme: {
181
+ 'color-body': '#fff',
182
+ 'color-index-page-background': '#f2f2f2',
183
+ 'color-index-page-feature-background': '#fff',
184
+ 'color-index-page-logo-mask-background': 'linear-gradient(-45deg, #8baff8 50%, #84e0ff 50%)',
185
+ 'color-index-page-second-text-color': 'rgba(60, 60, 60, .7)',
186
+ 'color-index-page-divider-color': '#ddd',
187
+ 'color-bar': '#fff',
188
+ 'color-sub-bar': '#f5f5f5',
189
+ 'color-text': '#555',
190
+ 'color-sub-text': '#888',
191
+ 'color-border': 'rgba(0, 0, 0, 0.12)',
192
+ 'color-shadow': '#eee',
193
+ 'color-introduce-border': '#2196f3',
194
+ 'color-primary': '#2196f3',
195
+ 'color-link': '#00c48f',
196
+ 'color-type': '#00c48f',
197
+ 'color-progress': '#1d92e9',
198
+ 'color-progress-track': 'transparent',
199
+ 'color-side-bar': '#3a7afe',
200
+ 'color-side-bar-active-background': '#3a7afe1a',
201
+ 'color-app-bar': '#3a7afe',
202
+ 'color-nav-button-hover-background': 'rgba(0, 0, 0, 0.08)',
203
+ 'color-mobile-cell-hover': '#3a7afe',
204
+ 'color-pc-language-active': '#3a7afe',
205
+ 'color-pc-language-active-background': '#edf5ff',
206
+ 'color-pc-github-active-background': '#212121',
207
+ 'color-mobile-language-active': '#3a7afe',
208
+ 'color-mobile-language-active-background': '#edf5ff',
209
+ 'color-hl-background': '#fafafa',
210
+ 'color-hl-code': '#58727e',
211
+ 'color-hl-border': '#f3f3f3',
212
+ 'color-hl-group-a': '#7c7c7c',
213
+ 'color-hl-group-b': '#2196f3',
214
+ 'color-hl-group-c': '#ff9422',
215
+ 'color-hl-group-d': '#58c193',
216
+ 'color-hl-group-e': '#ff9422',
217
+ 'color-hl-group-f': '#ff9422',
218
+ 'color-hl-group-g': '#ff9422',
219
+ 'color-hl-group-h': '#06a6e9',
220
+ 'color-hl-group-i': '#f23733',
221
+ },
222
+ darkTheme: {
223
+ 'color-body': '#121212',
224
+ 'color-index-page-background': '#1e1e1e',
225
+ 'color-index-page-feature-background': '#303030',
226
+ 'color-index-page-logo-mask-background': 'linear-gradient(-45deg, #729dfc 50%, #6859f4 50%)',
227
+ 'color-index-page-second-text-color': 'rgba(255, 255, 255, .75)',
228
+ 'color-index-page-divider-color': 'rgba(84, 84, 84, .8)',
229
+ 'color-bar': '#1e1e1e',
230
+ 'color-sub-bar': '#272727',
231
+ 'color-text': '#fff',
232
+ 'color-sub-text': '#aaa',
233
+ 'color-border': '#333',
234
+ 'color-shadow': '#121212',
235
+ 'color-introduce-border': '#555',
236
+ 'color-primary': '#96cbfe',
237
+ 'color-link': '#A8FFC4',
238
+ 'color-type': '#A8FFC4',
239
+ 'color-progress': '#5580f8',
240
+ 'color-progress-track': 'transparent',
241
+ 'color-side-bar': '#4a7afe',
242
+ 'color-side-bar-active-background': '#4a7afe1a',
243
+ 'color-app-bar': '#272727',
244
+ 'color-nav-button-hover-background': 'rgba(255, 255, 255, 0.08)',
245
+ 'color-mobile-cell-hover': '#4a7afe',
246
+ 'color-pc-language-active': '#4a7afe',
247
+ 'color-pc-language-active-background': '#4a7afe20',
248
+ 'color-pc-github-active-background': '#303030',
249
+ 'color-mobile-language-active': '#4a7afe',
250
+ 'color-mobile-language-active-background': '#4a7afe20',
251
+ 'color-hl-background': '#272727',
252
+ 'color-hl-code': '#fff',
253
+ 'color-hl-border': '#272727',
254
+ 'color-hl-group-a': '#7c7c7c',
255
+ 'color-hl-group-b': '#96cbfe',
256
+ 'color-hl-group-c': '#ff7b1e',
257
+ 'color-hl-group-d': '#A8FFC4',
258
+ 'color-hl-group-e': '#ff7b1e',
259
+ 'color-hl-group-f': '#ff7b1e',
260
+ 'color-hl-group-g': '#ff7b1e',
261
+ 'color-hl-group-h': '#14a6e9',
262
+ 'color-hl-group-i': '#ed4648',
263
+ },
264
+ });
@@ -0,0 +1,6 @@
1
+ import { InlineConfig } from 'vite';
2
+ import { VarletConfig } from './varlet.config';
3
+ export declare function getDevConfig(varletConfig: Required<VarletConfig>): InlineConfig;
4
+ export declare function getBuildConfig(varletConfig: Required<VarletConfig>): InlineConfig;
5
+ export declare function getESMBundleConfig(varletConfig: Required<VarletConfig>): InlineConfig;
6
+ export declare function getUMDConfig(varletConfig: Required<VarletConfig>): InlineConfig;
@@ -0,0 +1,144 @@
1
+ import vue from '@vitejs/plugin-vue';
2
+ import md from '@varlet/markdown-vite-plugin';
3
+ import jsx from '@vitejs/plugin-vue-jsx';
4
+ import fse from 'fs-extra';
5
+ import { injectHtml } from 'vite-plugin-html';
6
+ import { CWD, ES_DIR, LIB_DIR, SITE_CONFIG, SITE_DIR, SITE_MOBILE_ROUTES, SITE_OUTPUT_PATH, SITE_PC_ROUTES, SITE_PUBLIC_PATH, UMD_DIR, VITE_RESOLVE_EXTENSIONS, } from '../shared/constant.js';
7
+ import { get } from 'lodash-es';
8
+ import { kebabCase } from '@varlet/shared';
9
+ import { resolve } from 'path';
10
+ const { copyFileSync, pathExistsSync, readFileSync, removeSync, writeFileSync } = fse;
11
+ export function getDevConfig(varletConfig) {
12
+ const defaultLanguage = get(varletConfig, 'defaultLanguage');
13
+ const host = get(varletConfig, 'host');
14
+ return {
15
+ root: SITE_DIR,
16
+ resolve: {
17
+ extensions: VITE_RESOLVE_EXTENSIONS,
18
+ alias: {
19
+ '@config': SITE_CONFIG,
20
+ '@pc-routes': SITE_PC_ROUTES,
21
+ '@mobile-routes': SITE_MOBILE_ROUTES,
22
+ },
23
+ },
24
+ server: {
25
+ port: get(varletConfig, 'port'),
26
+ host: host === 'localhost' ? '0.0.0.0' : host,
27
+ },
28
+ publicDir: SITE_PUBLIC_PATH,
29
+ plugins: [
30
+ vue({
31
+ include: [/\.vue$/, /\.md$/],
32
+ }),
33
+ md({ style: get(varletConfig, 'highlight.style') }),
34
+ jsx(),
35
+ injectHtml({
36
+ data: {
37
+ pcTitle: get(varletConfig, `pc.title['${defaultLanguage}']`),
38
+ mobileTitle: get(varletConfig, `mobile.title['${defaultLanguage}']`),
39
+ logo: get(varletConfig, `logo`),
40
+ baidu: get(varletConfig, `analysis.baidu`, ''),
41
+ },
42
+ }),
43
+ ],
44
+ };
45
+ }
46
+ export function getBuildConfig(varletConfig) {
47
+ const devConfig = getDevConfig(varletConfig);
48
+ return Object.assign(Object.assign({}, devConfig), { base: './', build: {
49
+ outDir: SITE_OUTPUT_PATH,
50
+ reportCompressedSize: false,
51
+ emptyOutDir: true,
52
+ cssTarget: 'chrome61',
53
+ rollupOptions: {
54
+ input: {
55
+ main: resolve(SITE_DIR, 'index.html'),
56
+ mobile: resolve(SITE_DIR, 'mobile.html'),
57
+ },
58
+ },
59
+ } });
60
+ }
61
+ function inlineCSS(fileName, dir) {
62
+ return {
63
+ name: 'varlet-inline-css-vite-plugin',
64
+ apply: 'build',
65
+ closeBundle() {
66
+ const cssFile = resolve(dir, 'style.css');
67
+ if (!pathExistsSync(cssFile)) {
68
+ return;
69
+ }
70
+ const jsFile = resolve(dir, fileName);
71
+ const cssCode = readFileSync(cssFile, 'utf-8');
72
+ const jsCode = readFileSync(jsFile, 'utf-8');
73
+ const injectCode = `;(function(){var style=document.createElement('style');style.type='text/css';\
74
+ style.rel='stylesheet';style.appendChild(document.createTextNode(\`${cssCode.replace(/\\/g, '\\\\')}\`));\
75
+ var head=document.querySelector('head');head.appendChild(style)})();`;
76
+ writeFileSync(jsFile, `${injectCode}${jsCode}`);
77
+ copyFileSync(cssFile, resolve(LIB_DIR, 'style.css'));
78
+ removeSync(cssFile);
79
+ },
80
+ };
81
+ }
82
+ function clear() {
83
+ return {
84
+ name: 'varlet-clear-vite-plugin',
85
+ apply: 'build',
86
+ closeBundle() {
87
+ removeSync(resolve(CWD, 'dist'));
88
+ },
89
+ };
90
+ }
91
+ export function getESMBundleConfig(varletConfig) {
92
+ const name = get(varletConfig, 'name');
93
+ const fileName = `${kebabCase(name)}.esm.js`;
94
+ return {
95
+ logLevel: 'silent',
96
+ build: {
97
+ emptyOutDir: true,
98
+ lib: {
99
+ name,
100
+ formats: ['es'],
101
+ fileName: () => fileName,
102
+ entry: resolve(ES_DIR, 'umdIndex.js'),
103
+ },
104
+ rollupOptions: {
105
+ external: ['vue'],
106
+ output: {
107
+ dir: ES_DIR,
108
+ exports: 'named',
109
+ globals: {
110
+ vue: 'Vue',
111
+ },
112
+ },
113
+ },
114
+ },
115
+ plugins: [clear()],
116
+ };
117
+ }
118
+ export function getUMDConfig(varletConfig) {
119
+ const name = get(varletConfig, 'name');
120
+ const fileName = `${kebabCase(name)}.js`;
121
+ return {
122
+ logLevel: 'silent',
123
+ build: {
124
+ emptyOutDir: true,
125
+ lib: {
126
+ name,
127
+ formats: ['umd'],
128
+ fileName: () => fileName,
129
+ entry: resolve(ES_DIR, 'umdIndex.js'),
130
+ },
131
+ rollupOptions: {
132
+ external: ['vue'],
133
+ output: {
134
+ dir: UMD_DIR,
135
+ exports: 'named',
136
+ globals: {
137
+ vue: 'Vue',
138
+ },
139
+ },
140
+ },
141
+ },
142
+ plugins: [inlineCSS(fileName, UMD_DIR), clear()],
143
+ };
144
+ }
@@ -0,0 +1 @@
1
+ export { defineConfig } from './config/varlet.config.js';
@@ -0,0 +1 @@
1
+ export { defineConfig } from './config/varlet.config.js';
@@ -1,43 +1,42 @@
1
- export declare const CWD: string;
2
- export declare const VARLET_CONFIG: string;
3
- export declare const SRC_DIR: string;
4
- export declare const ES_DIR: string;
5
- export declare const LIB_DIR: string;
6
- export declare const UMD_DIR: string;
7
- export declare const TYPES_DIR: string;
8
- export declare const ROOT_DOCS_DIR: string;
9
- export declare const ROOT_PAGES_DIR: string;
10
- export declare const ESLINT_EXTENSIONS: string[];
11
- export declare const VITE_RESOLVE_EXTENSIONS: string[];
12
- export declare const SCRIPTS_EXTENSIONS: string[];
13
- export declare const PUBLIC_DIR_INDEXES: string[];
14
- export declare const STYLE_DIR_NAME = "style";
15
- export declare const EXAMPLE_DIR_NAME = "example";
16
- export declare const LOCALE_DIR_NAME = "locale";
17
- export declare const DOCS_DIR_NAME = "docs";
18
- export declare const DIR_INDEX = "index.vue";
19
- export declare const TESTS_DIR_NAME = "__tests__";
20
- export declare const GENERATORS_DIR: string;
21
- export declare const UI_PACKAGE_JSON: string;
22
- export declare const CLI_PACKAGE_JSON: string;
23
- export declare const SITE: string;
24
- export declare const SITE_OUTPUT_PATH: string;
25
- export declare const SITE_PUBLIC_PATH: string;
26
- export declare const SITE_DIR: string;
27
- export declare const SITE_PC_DIR: string;
28
- export declare const SITE_PC_ROUTES: string;
29
- export declare const SITE_MOBILE_ROUTES: string;
30
- export declare const SITE_CONFIG: string;
31
- export declare const HL_COMPONENT_NAME_RE: RegExp;
32
- export declare const HL_API_RE: RegExp;
33
- export declare const HL_TITLE_ATTRIBUTES_RE: RegExp;
34
- export declare const HL_TITLE_EVENTS_RE: RegExp;
35
- export declare const HL_TITLE_SLOTS_RE: RegExp;
36
- export declare const HL_MD = "zh-CN.md";
37
- export declare const HL_DIR: string;
38
- export declare const HL_TAGS_JSON: string;
39
- export declare const HL_ATTRIBUTES_JSON: string;
40
- export declare const HL_WEB_TYPES_JSON: string;
41
- export declare const JEST_CONFIG: string;
42
- export declare const JEST_MEDIA_MOCK: string;
43
- export declare const JEST_STYLE_MOCK: string;
1
+ export declare const dirname: string;
2
+ export declare const CWD: string;
3
+ export declare const VARLET_CONFIG: string;
4
+ export declare const SRC_DIR: string;
5
+ export declare const ES_DIR: string;
6
+ export declare const LIB_DIR: string;
7
+ export declare const UMD_DIR: string;
8
+ export declare const TYPES_DIR: string;
9
+ export declare const ROOT_DOCS_DIR: string;
10
+ export declare const ROOT_PAGES_DIR: string;
11
+ export declare const ESLINT_EXTENSIONS: string[];
12
+ export declare const VITE_RESOLVE_EXTENSIONS: string[];
13
+ export declare const SCRIPTS_EXTENSIONS: string[];
14
+ export declare const PUBLIC_DIR_INDEXES: string[];
15
+ export declare const STYLE_DIR_NAME = "style";
16
+ export declare const EXAMPLE_DIR_NAME = "example";
17
+ export declare const LOCALE_DIR_NAME = "locale";
18
+ export declare const DOCS_DIR_NAME = "docs";
19
+ export declare const DIR_INDEX = "index.vue";
20
+ export declare const TESTS_DIR_NAME = "__tests__";
21
+ export declare const GENERATORS_DIR: string;
22
+ export declare const UI_PACKAGE_JSON: string;
23
+ export declare const CLI_PACKAGE_JSON: string;
24
+ export declare const SITE: string;
25
+ export declare const SITE_OUTPUT_PATH: string;
26
+ export declare const SITE_PUBLIC_PATH: string;
27
+ export declare const SITE_DIR: string;
28
+ export declare const SITE_PC_DIR: string;
29
+ export declare const SITE_PC_ROUTES: string;
30
+ export declare const SITE_MOBILE_ROUTES: string;
31
+ export declare const SITE_CONFIG: string;
32
+ export declare const HL_COMPONENT_NAME_RE: RegExp;
33
+ export declare const HL_API_RE: RegExp;
34
+ export declare const HL_TITLE_ATTRIBUTES_RE: RegExp;
35
+ export declare const HL_TITLE_EVENTS_RE: RegExp;
36
+ export declare const HL_TITLE_SLOTS_RE: RegExp;
37
+ export declare const HL_MD = "zh-CN.md";
38
+ export declare const HL_DIR: string;
39
+ export declare const HL_TAGS_JSON: string;
40
+ export declare const HL_ATTRIBUTES_JSON: string;
41
+ export declare const HL_WEB_TYPES_JSON: string;
42
+ export declare const JEST_CONFIG: string;
@@ -0,0 +1,47 @@
1
+ import { resolve } from 'path';
2
+ import { getDirname } from './fsUtils.js';
3
+ export const dirname = getDirname(import.meta.url);
4
+ export const CWD = process.cwd();
5
+ export const VARLET_CONFIG = resolve(CWD, 'varlet.config.mjs');
6
+ export const SRC_DIR = resolve(CWD, 'src');
7
+ export const ES_DIR = resolve(CWD, 'es');
8
+ export const LIB_DIR = resolve(CWD, 'lib');
9
+ export const UMD_DIR = resolve(CWD, 'umd');
10
+ export const TYPES_DIR = resolve(CWD, 'types');
11
+ export const ROOT_DOCS_DIR = resolve(CWD, 'docs');
12
+ export const ROOT_PAGES_DIR = resolve(CWD, 'pages');
13
+ export const ESLINT_EXTENSIONS = ['.vue', '.ts', '.js', '.mjs', '.tsx', '.jsx'];
14
+ export const VITE_RESOLVE_EXTENSIONS = ['.vue', '.tsx', '.ts', '.jsx', '.js', '.less', '.css'];
15
+ export const SCRIPTS_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js'];
16
+ export const PUBLIC_DIR_INDEXES = ['index.vue', 'index.tsx', 'index.ts', 'index.jsx', 'index.js'];
17
+ export const STYLE_DIR_NAME = 'style';
18
+ export const EXAMPLE_DIR_NAME = 'example';
19
+ export const LOCALE_DIR_NAME = 'locale';
20
+ export const DOCS_DIR_NAME = 'docs';
21
+ export const DIR_INDEX = 'index.vue';
22
+ export const TESTS_DIR_NAME = '__tests__';
23
+ export const GENERATORS_DIR = resolve(dirname, '../../../template/generators');
24
+ export const UI_PACKAGE_JSON = resolve(CWD, 'package.json');
25
+ export const CLI_PACKAGE_JSON = resolve(dirname, '../../../package.json');
26
+ // site
27
+ export const SITE = resolve(dirname, '../../../site');
28
+ export const SITE_OUTPUT_PATH = resolve(CWD, 'site');
29
+ export const SITE_PUBLIC_PATH = resolve(CWD, 'public');
30
+ export const SITE_DIR = resolve(CWD, '.varlet/site');
31
+ export const SITE_PC_DIR = resolve(CWD, '.varlet/site/pc');
32
+ export const SITE_PC_ROUTES = resolve(CWD, '.varlet/pc.routes.ts');
33
+ export const SITE_MOBILE_ROUTES = resolve(CWD, '.varlet/mobile.routes.ts');
34
+ export const SITE_CONFIG = resolve(CWD, '.varlet/site.config.json');
35
+ // template highlight
36
+ export const HL_COMPONENT_NAME_RE = /.*(\/|\\)(.+)(\/|\\)docs(\/|\\)/;
37
+ export const HL_API_RE = /##\s*API\n+/;
38
+ export const HL_TITLE_ATTRIBUTES_RE = /###\s*属性\s*\n+/;
39
+ export const HL_TITLE_EVENTS_RE = /###\s*事件\s*\n+/;
40
+ export const HL_TITLE_SLOTS_RE = /###\s*插槽\s*\n+/;
41
+ export const HL_MD = 'zh-CN.md';
42
+ export const HL_DIR = resolve(CWD, 'highlight');
43
+ export const HL_TAGS_JSON = resolve(HL_DIR, 'tags.json');
44
+ export const HL_ATTRIBUTES_JSON = resolve(HL_DIR, 'attributes.json');
45
+ export const HL_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.json');
46
+ // jest
47
+ export const JEST_CONFIG = resolve(dirname, '../../../cjs/jest.config.cjs');
@@ -1,12 +1,13 @@
1
- export declare function getPublicDirs(): Promise<string[]>;
2
- export declare const isMD: (file: string) => boolean;
3
- export declare const isDir: (file: string) => boolean;
4
- export declare const isSFC: (file: string) => boolean;
5
- export declare const isDTS: (file: string) => boolean;
6
- export declare const isScript: (file: string) => boolean;
7
- export declare const isLess: (file: string) => boolean;
8
- export declare const isPublicDir: (dir: string) => boolean;
9
- export declare const replaceExt: (file: string, ext: string) => string;
10
- export declare function smartAppendFileSync(file: string, code: string): void;
11
- export declare function outputFileSyncOnChange(path: string, code: string): void;
12
- export declare function glob(pattern: string): Promise<string[]>;
1
+ export declare function getPublicDirs(): Promise<string[]>;
2
+ export declare const isMD: (file: string) => boolean;
3
+ export declare const isDir: (file: string) => boolean;
4
+ export declare const isSFC: (file: string) => boolean;
5
+ export declare const isDTS: (file: string) => boolean;
6
+ export declare const isScript: (file: string) => boolean;
7
+ export declare const isLess: (file: string) => boolean;
8
+ export declare const isPublicDir: (dir: string) => boolean;
9
+ export declare const replaceExt: (file: string, ext: string) => string;
10
+ export declare function smartAppendFileSync(file: string, code: string): void;
11
+ export declare function outputFileSyncOnChange(path: string, code: string): void;
12
+ export declare function glob(pattern: string): Promise<string[]>;
13
+ export declare function getDirname(url: string): string;
@@ -0,0 +1,48 @@
1
+ import globSync from 'glob';
2
+ import fse from 'fs-extra';
3
+ import { extname, resolve } from 'path';
4
+ import { PUBLIC_DIR_INDEXES, SCRIPTS_EXTENSIONS, SRC_DIR } from './constant.js';
5
+ import { fileURLToPath } from 'url';
6
+ const { appendFileSync, ensureFileSync, lstatSync, outputFileSync, pathExistsSync, readdir, readFileSync } = fse;
7
+ export async function getPublicDirs() {
8
+ const srcDir = await readdir(SRC_DIR);
9
+ return srcDir.filter((filename) => isPublicDir(resolve(SRC_DIR, filename)));
10
+ }
11
+ export const isMD = (file) => pathExistsSync(file) && extname(file) === '.md';
12
+ export const isDir = (file) => pathExistsSync(file) && lstatSync(file).isDirectory();
13
+ export const isSFC = (file) => pathExistsSync(file) && extname(file) === '.vue';
14
+ export const isDTS = (file) => pathExistsSync(file) && file.endsWith('.d.ts');
15
+ export const isScript = (file) => pathExistsSync(file) && SCRIPTS_EXTENSIONS.includes(extname(file));
16
+ export const isLess = (file) => pathExistsSync(file) && extname(file) === '.less';
17
+ export const isPublicDir = (dir) => PUBLIC_DIR_INDEXES.some((index) => pathExistsSync(resolve(dir, index)));
18
+ export const replaceExt = (file, ext) => file.replace(extname(file), ext);
19
+ export function smartAppendFileSync(file, code) {
20
+ if (pathExistsSync(file)) {
21
+ const content = readFileSync(file, 'utf-8');
22
+ if (!content.includes(code)) {
23
+ appendFileSync(file, code);
24
+ }
25
+ }
26
+ }
27
+ export function outputFileSyncOnChange(path, code) {
28
+ ensureFileSync(path);
29
+ const content = readFileSync(path, 'utf-8');
30
+ if (content !== code) {
31
+ outputFileSync(path, code);
32
+ }
33
+ }
34
+ export function glob(pattern) {
35
+ return new Promise((resolve, reject) => {
36
+ globSync(pattern, (err, files) => {
37
+ if (err) {
38
+ reject(err);
39
+ }
40
+ else {
41
+ resolve(files);
42
+ }
43
+ });
44
+ });
45
+ }
46
+ export function getDirname(url) {
47
+ return fileURLToPath(new URL('.', url));
48
+ }