@varlet/cli 3.0.0-alpha.1704352780759 → 3.0.0-alpha.1707916363117

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 (33) hide show
  1. package/README.md +30 -18
  2. package/README.zh-CN.md +16 -4
  3. package/lib/node/bin.js +7 -0
  4. package/lib/node/commands/icons.js +2 -1
  5. package/lib/node/commands/lint.js +1 -1
  6. package/lib/node/commands/styleVars.d.ts +1 -0
  7. package/lib/node/commands/styleVars.js +6 -0
  8. package/lib/node/compiler/compileSFC.js +14 -4
  9. package/lib/node/compiler/compileScript.js +2 -2
  10. package/lib/node/config/varlet.default.config.js +7 -11
  11. package/lib/node/index.d.ts +1 -0
  12. package/lib/node/index.js +1 -0
  13. package/package.json +17 -17
  14. package/site/mobile/App.vue +1 -1
  15. package/site/mobile.html +3 -0
  16. package/site/pc/Layout.vue +6 -0
  17. package/site/pc/components/AppSidebar.vue +1 -0
  18. package/template/create/example/locale/_index.ts +4 -4
  19. package/template/create/example/locale/index.ts +4 -4
  20. package/template/generators/base/package.json +2 -2
  21. package/template/generators/config/default/base/varlet.config.mjs +1 -0
  22. package/template/generators/config/i18n/base/types/locale.d.ts +14 -10
  23. package/template/generators/config/i18n/base/varlet.config.mjs +1 -0
  24. package/template/generators/config/i18n/sfc/src/button/example/BasicUse.vue +2 -2
  25. package/template/generators/config/i18n/sfc/src/button/example/ModifyColor.vue +2 -2
  26. package/template/generators/config/i18n/sfc/src/button/example/index.vue +5 -5
  27. package/template/generators/config/i18n/sfc/src/button/example/locale/index.ts +4 -4
  28. package/template/generators/config/i18n/sfc/src/locale/index.ts +31 -21
  29. package/template/generators/config/i18n/tsx/src/button/example/BasicUse.vue +2 -2
  30. package/template/generators/config/i18n/tsx/src/button/example/ModifyColor.vue +2 -2
  31. package/template/generators/config/i18n/tsx/src/button/example/index.vue +5 -5
  32. package/template/generators/config/i18n/tsx/src/button/example/locale/index.ts +4 -4
  33. package/template/generators/config/i18n/tsx/src/locale/index.ts +33 -21
package/README.md CHANGED
@@ -16,7 +16,7 @@ The out-of-the-box `Vue3 component library` rapid prototyping tool provides a se
16
16
  - 💪  Support for `VSCode` extension development
17
17
  - 💪  Support `build svg to web fonts`
18
18
  - 💪  Support for `Typescript`
19
- - 💪  Support `Dark Mode`
19
+ - 💪  Support `Various themes, including md2, md3, dark mode`
20
20
  - 🌍  Support `Internationalization`
21
21
  - 🚀  Based on `pnpm`
22
22
 
@@ -40,30 +40,35 @@ The default configuration can be viewed [varlet.default.config.ts](https://githu
40
40
  Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varlet/blob/dev/packages/varlet-ui/varlet.config.mjs).
41
41
 
42
42
  | Parameter | Description | Type | Default |
43
- | -- | -------------- | -------- | ---------- |
43
+ | --- | -------------- | -------- | ---------- |
44
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` |
45
+ | `namespace` | Component library namespace, will be used as component prefix | _string_ | `var` |
46
46
  | `host` | Development server host | _number_ | `localhost` |
47
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 }_ | `-` |
48
+ | `title` | The title of the component library in the document | _string_ | `VARLET` |
49
+ | `logo` | The logo of the component library in the document | _string_ | `-` |
50
+ | `defaultLanguage` | Document default language | _string_ | `zh-CN` |
51
+ | `defaultLightTheme` | The default light theme | _string_ | `md3LightTheme` |
52
+ | `defaultDarkTheme` | The default dark theme | _string_ | `md3DarkTheme` |
53
+ | `useMobile` | Whether to display the mobile phone preview on the right | _boolean_ | `false` |
54
+ | `themeKey` | The key of the theme in local storage | _string_ | `VARLET_THEME` |
55
+ | `lightTheme` | md2 light mode document theme | _Record<string, any>_ | `-` |
56
+ | `darkTheme` | md2 dark mode document theme | _Record<string, any>_ | `-` |
57
+ | `md3LightTheme` | md3 light mode document theme | _Record<string, any>_ | `-` |
58
+ | `md3DarkTheme` | md3 dark mode document theme | _Record<string, any>_ | `-` |
59
+ | `highlight` | Document code snippet style related | _{ style: string }_ | `-` |
55
60
  | `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
- | `directives` | Directive folder names | _string[]_ | `[]` |
59
- | `copy` | Copy file options | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `-` |
60
- | `icons` | Font icon packaging related configuration | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
61
- | `esbuild` | Esbuild configuration | _[VarletConfigEsbuild](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
61
+ | `pc` | PC side document structure configuration | _Record<string, any>_ | `-` |
62
+ | `mobile` | Mobile document structure configuration | _Record<string, any>_ | `-` |
63
+ | `directives` | Component library directive folder name | _string[]_ | `[]` |
64
+ | `copy` | Copy file configuration | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `- ` |
65
+ | `icons` | Font icon packaging related configurations | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts) _ | `-` |
66
+ | `esbuild` | esbuild configuration | _[VarletConfigEsbuild](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | ` -` |
62
67
 
63
68
  #### Menu
64
69
 
65
- | 参数 | 说明 | 类型 | 默认值 |
66
- | -- | -------------- | -------- | ---------- |
70
+ | Parameter | Description | Type | Default |
71
+ | --- | -------------- | -------- | ---------- |
67
72
  | `doc` | The document page corresponds to the matching file name, required | _string_ | `-` |
68
73
  | `type` | The type of menu, when the type is `1`, it means the category menu, when the type is `2`, the doc field matches the component file under src, when the type is `3`, the doc field matches the md file under docs, required | _MenuTypes_ | `-` |
69
74
  | `text` | The text displayed in the menu, English display text can be configured when internationalization is set, required | _Record<string, string>_ | `-` |
@@ -138,6 +143,13 @@ varlet-cli preview
138
143
  varlet-cli compile
139
144
  ```
140
145
 
146
+ #### Compile style vars types declaration file
147
+
148
+ ```shell
149
+ # playground-ignore
150
+ varlet-cli compile:style-vars
151
+ ```
152
+
141
153
  #### Run VSCode extension development environment
142
154
 
143
155
  ```shell
package/README.zh-CN.md CHANGED
@@ -16,7 +16,7 @@
16
16
  - 💪 &nbsp;支持 `VSCode` 插件开发
17
17
  - 💪 &nbsp;支持 `字体图标打包`
18
18
  - 💪 &nbsp;支持 `Typescript`
19
- - 💪 &nbsp;支持 `暗黑模式`
19
+ - 💪 &nbsp;支持 `多种主题, 包含 md2、md3、暗黑模式`
20
20
  - 🌍 &nbsp;支持 `国际化`
21
21
  - 🚀 &nbsp;基于 `pnpm`
22
22
 
@@ -48,9 +48,14 @@ varlet-cli gen
48
48
  | `title` | 文档中组件库的标题 | _string_ | `VARLET` |
49
49
  | `logo` | 文档中组件库的logo | _string_ | `-` |
50
50
  | `defaultLanguage` | 文档默认语言 | _string_ | `zh-CN` |
51
+ | `defaultLightTheme` | 默认的亮色主题 | _string_ | `md3LightTheme` |
52
+ | `defaultDarkTheme` | 默认的暗色主题 | _string_ | `md3DarkTheme` |
51
53
  | `useMobile` | 是否显示右侧手机预览 | _boolean_ | `false` |
52
- | `lightTheme` | 亮色模式文档主题 | _Record<string, any>_ | `-` |
53
- | `darkTheme` | 暗黑模式文档主题 | _Record<string, any>_ | `-` |
54
+ | `themeKey` | 主题在本地存储中的 key | _string_ | `VARLET_THEME` |
55
+ | `lightTheme` | md2 亮色模式文档主题 | _Record<string, any>_ | `-` |
56
+ | `darkTheme` | md2 暗黑模式文档主题 | _Record<string, any>_ | `-` |
57
+ | `md3LightTheme` | md3 亮色模式文档主题 | _Record<string, any>_ | `-` |
58
+ | `md3DarkTheme` | md3 暗黑模式文档主题 | _Record<string, any>_ | `-` |
54
59
  | `highlight` | 文档代码片段样式相关 | _{ style: string }_ | `-` |
55
60
  | `analysis` | 文档统计相关 | _{ baidu: string }_ | `-` |
56
61
  | `pc` | pc 端文档结构配置 | _Record<string, any>_ | `-` |
@@ -58,7 +63,7 @@ varlet-cli gen
58
63
  | `directives` | 组件库指令文件夹名称 | _string[]_ | `[]` |
59
64
  | `copy` | 复制文件配置 | _[CopyPath[]](https://github.com/varletjs/varlet/blob/dev/packages/varlet-vite-plugins/src/copy.ts)_ | `-` |
60
65
  | `icons` | 字体图标打包相关配置 | _[VarletConfigIcons](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
61
- | `esbuild` | Esbuild 配置 | _[VarletConfigEsbuild](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
66
+ | `esbuild` | esbuild 配置 | _[VarletConfigEsbuild](https://github.com/varletjs/varlet/blob/dev/packages/varlet-cli/src/node/config/varlet.config.ts)_ | `-` |
62
67
 
63
68
  #### Menu
64
69
 
@@ -137,6 +142,13 @@ varlet-cli preview
137
142
  varlet-cli compile
138
143
  ```
139
144
 
145
+ #### 构建样式变量类型声明文件
146
+
147
+ ```shell
148
+ # playground-ignore
149
+ varlet-cli compile:style-vars
150
+ ```
151
+
140
152
  #### 启动 VSCode 插件开发环境
141
153
 
142
154
  ```shell
package/lib/node/bin.js CHANGED
@@ -68,6 +68,13 @@ program
68
68
  const { compile } = await import('./commands/compile.js');
69
69
  return compile();
70
70
  });
71
+ program
72
+ .command('compile:style-vars')
73
+ .description('Compile varlet style vars')
74
+ .action(async () => {
75
+ const { styleVars } = await import('./commands/styleVars.js');
76
+ return styleVars();
77
+ });
71
78
  program
72
79
  .command('lint')
73
80
  .description('Lint code')
@@ -1,5 +1,6 @@
1
1
  import fse from 'fs-extra';
2
2
  import sharp from 'sharp';
3
+ import slash from 'slash';
3
4
  import webfont from 'webfont';
4
5
  import logger from '../shared/logger.js';
5
6
  import { parse, resolve } from 'path';
@@ -42,7 +43,7 @@ async function buildPNG(entry, pngDir, svgFiles) {
42
43
  }
43
44
  function buildWebFont(name, entry) {
44
45
  return webfont.default({
45
- files: `${entry}/*.svg`,
46
+ files: `${slash(entry)}/*.svg`,
46
47
  fontName: name,
47
48
  formats: ['ttf'],
48
49
  fontHeight: 512,
@@ -14,7 +14,7 @@ export async function lint() {
14
14
  './src',
15
15
  './packages/varlet-cli/src',
16
16
  './packages/varlet-ui/src',
17
- './packages/varlet-icons/lib',
17
+ './packages/varlet-shared/src',
18
18
  './packages/varlet-vite-plugins/src',
19
19
  './packages/varlet-use/src',
20
20
  './packages/varlet-touch-emulator',
@@ -0,0 +1 @@
1
+ export declare function styleVars(): void;
@@ -0,0 +1,6 @@
1
+ import { compileStyleVars } from '../compiler/compileStyleVars.js';
2
+ import logger from '../shared/logger.js';
3
+ export function styleVars() {
4
+ compileStyleVars();
5
+ logger.success('style vars compilation success!');
6
+ }
@@ -1,11 +1,14 @@
1
1
  import fse from 'fs-extra';
2
2
  import hash from 'hash-sum';
3
3
  import { parse, resolve } from 'path';
4
- import { parse as parseSFC, compileTemplate, compileStyle, compileScript as compileScriptSFC } from '@vue/compiler-sfc';
4
+ import { parse as parseSFC, compileTemplate, compileStyle, compileScript as compileScriptSFC, registerTS, } from '@vue/compiler-sfc';
5
5
  import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
6
+ import { SRC_DIR, ES_DIR } from '../shared/constant.js';
6
7
  import { compileScript, getScriptExtname } from './compileScript.js';
8
+ import ts from 'typescript';
7
9
  import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
8
- const { readFile, writeFileSync } = fse;
10
+ const { readFile, existsSync, readFileSync, writeFileSync } = fse;
11
+ registerTS(() => ts);
9
12
  const EXPORT = 'export default';
10
13
  const SFC = '__sfc__';
11
14
  const SFC_DECLARE = `const ${SFC} = `;
@@ -34,13 +37,20 @@ export function injectRender(script, render) {
34
37
  export async function compileSFC(sfc) {
35
38
  const sources = await readFile(sfc, 'utf-8');
36
39
  const id = hash(sources);
37
- const { descriptor } = parseSFC(sources, { sourceMap: false });
40
+ const { descriptor } = parseSFC(sources, { filename: sfc, sourceMap: false });
38
41
  const { script, scriptSetup, template, styles } = descriptor;
39
42
  let scriptContent;
40
43
  let bindingMetadata;
41
44
  if (script || scriptSetup) {
42
45
  if (scriptSetup) {
43
- const { content, bindings } = compileScriptSFC(descriptor, { id });
46
+ const { content, bindings } = compileScriptSFC(descriptor, {
47
+ id,
48
+ // issue https://github.com/varletjs/varlet/issues/1458
49
+ fs: {
50
+ fileExists: (file) => existsSync(file.replace(ES_DIR, SRC_DIR)),
51
+ readFile: (file) => readFileSync(file.replace(ES_DIR, SRC_DIR), 'utf-8'),
52
+ },
53
+ });
44
54
  scriptContent = content;
45
55
  bindingMetadata = bindings;
46
56
  }
@@ -113,9 +113,9 @@ export async function compileScript(script, file) {
113
113
  code = resolveDependence(file, code);
114
114
  code = extractStyleDependencies(file, code, IMPORT_CSS_RE);
115
115
  code = extractStyleDependencies(file, code, IMPORT_LESS_RE);
116
- removeSync(file);
117
- writeFileSync(replaceExt(file, getScriptExtname()), code, 'utf8');
118
116
  }
117
+ removeSync(file);
118
+ writeFileSync(replaceExt(file, getScriptExtname()), code, 'utf8');
119
119
  }
120
120
  export async function compileScriptFile(file) {
121
121
  const sources = readFileSync(file, 'utf-8');
@@ -418,13 +418,13 @@ export default defineConfig({
418
418
  'zh-CN': '中文',
419
419
  'en-US': 'English',
420
420
  },
421
- currentVersion: 'Latest',
421
+ currentVersion: 'latest',
422
422
  versions: [
423
423
  {
424
424
  name: 'varlet.gitee.io',
425
425
  items: [
426
426
  {
427
- label: 'Latest',
427
+ label: 'latest',
428
428
  link: 'https://varlet.gitee.io/varlet-ui',
429
429
  },
430
430
  {
@@ -450,10 +450,6 @@ export default defineConfig({
450
450
  github: 'https://github.com/varletjs/varlet',
451
451
  changelog: 'https://github.com/varletjs/varlet/blob/main/CHANGELOG.md',
452
452
  playground: 'https://varlet.gitee.io/varlet-ui-playground',
453
- /**
454
- * @deprecated
455
- */
456
- darkMode: true,
457
453
  themes: [
458
454
  { 'zh-CN': 'Md2 亮色', 'en-US': 'Md2 Light', value: 'lightTheme' },
459
455
  { 'zh-CN': 'Md2 暗色', 'en-US': 'Md2 Dark', value: 'darkTheme' },
@@ -489,7 +485,7 @@ export default defineConfig({
489
485
  ],
490
486
  },
491
487
  },
492
- themeKey: 'VARLET_THEME',
488
+ themeKey: 'VARLET_V3_THEME',
493
489
  defaultLightTheme: 'md3LightTheme',
494
490
  defaultDarkTheme: 'md3DarkTheme',
495
491
  lightTheme: {
@@ -600,8 +596,8 @@ export default defineConfig({
600
596
  'color-shadow': '#eee',
601
597
  'color-introduce-border': '#6750A4',
602
598
  'color-primary': '#6750A4',
603
- 'color-link': '#21005D',
604
- 'color-type': '#21005D',
599
+ 'color-link': '#536525',
600
+ 'color-type': '#536525',
605
601
  'color-loading-bar': '#6750A4',
606
602
  'color-side-bar': '#6750A4',
607
603
  'color-side-bar-active-background': '#E8DEF8',
@@ -646,8 +642,8 @@ export default defineConfig({
646
642
  'color-shadow': '#090909',
647
643
  'color-introduce-border': '#555',
648
644
  'color-primary': '#D0BCFF',
649
- 'color-link': '#EADDFF',
650
- 'color-type': '#EADDFF',
645
+ 'color-link': '#BACF83',
646
+ 'color-type': '#BACF83',
651
647
  'color-loading-bar': '#D0BCFF',
652
648
  'color-side-bar': '#D0BCFF',
653
649
  'color-side-bar-active-background': '#4A4458',
@@ -11,3 +11,4 @@ export * from './commands/preview.js';
11
11
  export * from './commands/vite.js';
12
12
  export * from './commands/extension.js';
13
13
  export * from './commands/checklist.js';
14
+ export * from './commands/styleVars.js';
package/lib/node/index.js CHANGED
@@ -11,3 +11,4 @@ export * from './commands/preview.js';
11
11
  export * from './commands/vite.js';
12
12
  export * from './commands/extension.js';
13
13
  export * from './commands/checklist.js';
14
+ export * from './commands/styleVars.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "3.0.0-alpha.1704352780759",
3
+ "version": "3.0.0-alpha.1707916363117",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -34,15 +34,15 @@
34
34
  "url": "https://github.com/varletjs/varlet/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@varlet/release": "^0.1.2",
37
+ "@varlet/release": "^0.2.1",
38
38
  "@babel/core": "^7.22.5",
39
39
  "@babel/preset-typescript": "^7.22.5",
40
- "@vitejs/plugin-vue": "5.0.1",
40
+ "@vitejs/plugin-vue": "5.0.3",
41
41
  "@vitejs/plugin-vue-jsx": "3.1.0",
42
- "@vue/babel-plugin-jsx": "1.1.5",
43
- "@vue/compiler-sfc": "3.4.3",
44
- "@vue/runtime-core": "3.4.3",
45
- "vue": "3.4.3",
42
+ "@vue/babel-plugin-jsx": "1.2.1",
43
+ "@vue/compiler-sfc": "3.4.15",
44
+ "@vue/runtime-core": "3.4.15",
45
+ "vue": "3.4.15",
46
46
  "vite": "5.0.10",
47
47
  "esbuild": "0.19.3",
48
48
  "vitest": "1.1.0",
@@ -64,8 +64,8 @@
64
64
  "slash": "^3.0.0",
65
65
  "typescript": "^5.1.5",
66
66
  "webfont": "11.2.26",
67
- "@varlet/shared": "3.0.0-alpha.1704352780759",
68
- "@varlet/vite-plugins": "3.0.0-alpha.1704352780759"
67
+ "@varlet/shared": "3.0.0-alpha.1707916363117",
68
+ "@varlet/vite-plugins": "3.0.0-alpha.1707916363117"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/babel__core": "^7.20.1",
@@ -80,12 +80,12 @@
80
80
  "@types/semver": "^7.3.9",
81
81
  "@types/sharp": "0.31.1",
82
82
  "rimraf": "^5.0.1",
83
- "@varlet/ui": "3.0.0-alpha.1704352780759",
84
- "@varlet/icons": "3.0.0-alpha.1704352780759",
85
- "@varlet/touch-emulator": "3.0.0-alpha.1704352780759"
83
+ "@varlet/icons": "3.0.0-alpha.1707916363117",
84
+ "@varlet/touch-emulator": "3.0.0-alpha.1707916363117",
85
+ "@varlet/ui": "3.0.0-alpha.1707916363117"
86
86
  },
87
87
  "peerDependencies": {
88
- "@vue/runtime-core": "3.4.3",
88
+ "@vue/runtime-core": "3.4.15",
89
89
  "@vue/test-utils": "2.4.1",
90
90
  "@vitest/coverage-istanbul": "1.1.0",
91
91
  "vitest": "1.1.0",
@@ -93,11 +93,11 @@
93
93
  "clipboard": "^2.0.6",
94
94
  "live-server": "^1.2.1",
95
95
  "lodash-es": "^4.17.21",
96
- "vue": "3.4.3",
96
+ "vue": "3.4.15",
97
97
  "vue-router": "4.2.0",
98
- "@varlet/ui": "3.0.0-alpha.1704352780759",
99
- "@varlet/icons": "3.0.0-alpha.1704352780759",
100
- "@varlet/touch-emulator": "3.0.0-alpha.1704352780759"
98
+ "@varlet/icons": "3.0.0-alpha.1707916363117",
99
+ "@varlet/touch-emulator": "3.0.0-alpha.1707916363117",
100
+ "@varlet/ui": "3.0.0-alpha.1707916363117"
101
101
  },
102
102
  "scripts": {
103
103
  "dev": "tsc --watch",
@@ -82,7 +82,7 @@
82
82
 
83
83
  <script lang="ts">
84
84
  import config from '@config'
85
- import { computed, ComputedRef, defineComponent, ref, Ref, watch } from 'vue'
85
+ import { computed, defineComponent, ref, watch, type Ref, type ComputedRef } from 'vue'
86
86
  import { useRoute } from 'vue-router'
87
87
  import {
88
88
  getBrowserTheme,