@varlet/cli 3.18.2 → 3.19.0

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.
@@ -1 +1 @@
1
- export declare function styleVars(): void;
1
+ export declare function styleVars(): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { compileStyleVars } from '../compiler/compileStyleVars.js';
2
2
  import logger from '../shared/logger.js';
3
- export function styleVars() {
4
- compileStyleVars();
3
+ export async function styleVars() {
4
+ await compileStyleVars();
5
5
  logger.success('style vars compilation success!');
6
6
  }
@@ -2,7 +2,7 @@ import { x } from 'tinyexec';
2
2
  import { VITEST_CONFIG } from '../shared/constant.js';
3
3
  export async function test({ component, watch, coverage }) {
4
4
  process.env.NODE_ENV = 'test';
5
- const args = [watch ? 'watch' : 'run', '--config', VITEST_CONFIG];
5
+ const args = [watch ? 'watch' : 'run', '--config', VITEST_CONFIG, '--update=none'];
6
6
  if (coverage) {
7
7
  args.push('--coverage');
8
8
  }
@@ -23,7 +23,7 @@ export function compileDir(path, keys, defaultLanguage) {
23
23
  }
24
24
  export async function compileStyleVars() {
25
25
  ensureDirSync(TYPES_DIR);
26
- const { defaultLanguage } = await getVarletConfig();
26
+ const { defaultLanguage = 'zh-CN' } = await getVarletConfig();
27
27
  const keys = new Set();
28
28
  compileDir(SRC_DIR, keys, defaultLanguage);
29
29
  const assistanceType = `type RemoveTwoDashes<T extends string> = T extends \`--$\{infer Rest}\` ? Rest : T
@@ -9,6 +9,11 @@ export interface TemplateHighlightCompilerOptions {
9
9
  export declare const replaceDot: (s: string) => string;
10
10
  export declare const replaceVersion: (s: string) => string;
11
11
  export declare const replaceUnderline: (s: string) => string;
12
+ export declare const camelize: (s: string) => string;
13
+ export declare function parseVModelName(name: string): {
14
+ attribute: string;
15
+ event: string;
16
+ } | null;
12
17
  export declare function parseTable(table: string): string[][];
13
18
  export declare function compileTable(md: string, titleRe: RegExp): string;
14
19
  export declare function compileWebTypes(table: Record<string, any>, webTypes: Record<string, any>, componentName: string, varletConfig: Required<VarletConfig>): void;
@@ -9,6 +9,18 @@ const TABLE_FOOT_RE = /(\|\s*$)|(\|\s*\n(?!\s*\|))/;
9
9
  export const replaceDot = (s) => s.replace(/`/g, '');
10
10
  export const replaceVersion = (s) => s.replace(/\*\*\*.+\*\*\*/g, '').trim();
11
11
  export const replaceUnderline = (s) => s.replace(/_/g, '');
12
+ export const camelize = (s) => s.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : ''));
13
+ export function parseVModelName(name) {
14
+ if (name === 'v-model') {
15
+ return { attribute: 'model-value', event: 'update:modelValue' };
16
+ }
17
+ const matched = name.match(/^v-model:(.+)$/);
18
+ if (matched) {
19
+ const arg = matched[1];
20
+ return { attribute: arg, event: `update:${camelize(arg)}` };
21
+ }
22
+ return null;
23
+ }
12
24
  export function parseTable(table) {
13
25
  const rows = table.split('\n').filter(Boolean);
14
26
  return rows.map((row) => {
@@ -43,19 +55,32 @@ export function compileTable(md, titleRe) {
43
55
  }
44
56
  export function compileWebTypes(table, webTypes, componentName, varletConfig) {
45
57
  const { attributesTable, eventsTable, slotsTable } = table;
46
- const attributes = attributesTable.map((row) => ({
47
- name: replaceVersion(replaceDot(row[0])),
48
- description: row[1],
49
- default: replaceDot(row[3]),
50
- value: {
51
- type: replaceUnderline(row[2]),
52
- kind: 'expression',
53
- },
54
- }));
58
+ const modelEvents = [];
59
+ const attributes = attributesTable.map((row) => {
60
+ const name = replaceVersion(replaceDot(row[0]));
61
+ const vModel = parseVModelName(name);
62
+ if (vModel) {
63
+ modelEvents.push({ name: vModel.event, description: row[1] });
64
+ }
65
+ return {
66
+ name: vModel ? vModel.attribute : name,
67
+ description: row[1],
68
+ default: replaceDot(row[3]),
69
+ value: {
70
+ type: replaceUnderline(row[2]),
71
+ kind: 'expression',
72
+ },
73
+ };
74
+ });
55
75
  const events = eventsTable.map((row) => ({
56
76
  name: replaceVersion(replaceDot(row[0])),
57
77
  description: row[1],
58
78
  }));
79
+ modelEvents.forEach((modelEvent) => {
80
+ if (!events.some((event) => event.name === modelEvent.name)) {
81
+ events.push(modelEvent);
82
+ }
83
+ });
59
84
  const slots = slotsTable.map((row) => ({
60
85
  name: replaceVersion(replaceDot(row[0])),
61
86
  description: row[1],
@@ -12,7 +12,7 @@ export * from '${relative(moduleDir, TYPES_DIR)}'
12
12
  }
13
13
  export async function compileTypes() {
14
14
  await ensureDir(TYPES_DIR);
15
- compileStyleVars();
15
+ await compileStyleVars();
16
16
  const { namespace = '', directives = '' } = await getVarletConfig();
17
17
  const { name: libraryName } = readJSONSync(UI_PACKAGE_JSON);
18
18
  const filenames = await readdir(TYPES_DIR);
@@ -6,7 +6,6 @@ export default defineConfig({
6
6
  port: 8080,
7
7
  title: 'VARLET',
8
8
  logo: 'varlet_icon.png',
9
- defaultLanguage: 'zh-CN',
10
9
  themeKey: 'VARLET_V3_THEME',
11
10
  defaultLightTheme: 'md3LightTheme',
12
11
  defaultDarkTheme: 'md3DarkTheme',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "3.18.2",
3
+ "version": "3.19.0",
4
4
  "description": "cli of varlet",
5
5
  "keywords": [
6
6
  "cli",
@@ -56,8 +56,8 @@
56
56
  "typescript": "5.6.3",
57
57
  "vite-plus": "0.1.18",
58
58
  "vue": "3.5.21",
59
- "@varlet/shared": "3.18.2",
60
- "@varlet/vite-plugins": "3.18.2"
59
+ "@varlet/shared": "3.19.0",
60
+ "@varlet/vite-plugins": "3.19.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/babel__core": "^7.20.1",
@@ -69,9 +69,9 @@
69
69
  "@types/node": "^20.19.0",
70
70
  "@types/sharp": "0.31.1",
71
71
  "rimraf": "^5.0.1",
72
- "@varlet/ui": "3.18.2",
73
- "@varlet/icons": "3.18.2",
74
- "@varlet/touch-emulator": "3.18.2"
72
+ "@varlet/ui": "3.19.0",
73
+ "@varlet/icons": "3.19.0",
74
+ "@varlet/touch-emulator": "3.19.0"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@vitest/coverage-istanbul": "4.1.4",
@@ -82,9 +82,9 @@
82
82
  "live-server": "^1.2.1",
83
83
  "vue": "3.5.21",
84
84
  "vue-router": "4.5.1",
85
- "@varlet/icons": "3.18.2",
86
- "@varlet/touch-emulator": "3.18.2",
87
- "@varlet/ui": "3.18.2"
85
+ "@varlet/icons": "3.19.0",
86
+ "@varlet/ui": "3.19.0",
87
+ "@varlet/touch-emulator": "3.19.0"
88
88
  },
89
89
  "engines": {
90
90
  "node": "^14.18.0 || >=16.0.0"
@@ -3,13 +3,13 @@ import config from '@config'
3
3
  import routes from '@mobile-routes'
4
4
  import Varlet from '@varlet/ui'
5
5
  import { createRouter, createWebHashHistory } from 'vue-router'
6
- import { inIframe, isPhone } from '../utils'
6
+ import { getBrowserLanguage, inIframe, isPhone } from '../utils'
7
7
  import App from './App.vue'
8
8
  import '@varlet/touch-emulator'
9
9
  import '@varlet/ui/es/style'
10
10
 
11
11
  const redirect = config?.mobile?.redirect
12
- const defaultLanguage = config?.defaultLanguage
12
+ const defaultLanguage = config?.defaultLanguage ?? getBrowserLanguage()
13
13
 
14
14
  redirect &&
15
15
  routes.push({
package/site/pc/App.vue CHANGED
@@ -2,12 +2,12 @@
2
2
  import { defineComponent, onMounted, ref } from 'vue'
3
3
  import config from '@config'
4
4
  import { getMobileIndex, getPCLocationInfo } from '@varlet/cli/client'
5
- import { isPhone } from '../utils'
5
+ import { getBrowserLanguage, isPhone } from '../utils'
6
6
 
7
7
  export default defineComponent({
8
8
  setup() {
9
9
  const useMobile = ref(config?.useMobile)
10
- const defaultLanguage = config?.defaultLanguage
10
+ const defaultLanguage = config?.defaultLanguage ?? getBrowserLanguage()
11
11
 
12
12
  const init = () => {
13
13
  const { language, menuName } = getPCLocationInfo()
package/site/pc/main.ts CHANGED
@@ -5,10 +5,11 @@ import Varlet, { Snackbar } from '@varlet/ui'
5
5
  import { createRouter, createWebHashHistory } from 'vue-router'
6
6
  import App from './App.vue'
7
7
  import CodeExample from './components/code-example'
8
+ import { getBrowserLanguage } from '../utils'
8
9
  import '@varlet/ui/es/style'
9
10
  import '@varlet/touch-emulator'
10
11
 
11
- const defaultLanguage = config?.defaultLanguage
12
+ const defaultLanguage = config?.defaultLanguage ?? getBrowserLanguage()
12
13
  const redirect = config?.pc?.redirect
13
14
  const mobileRedirect = config?.mobile?.redirect
14
15
 
package/site/utils.ts CHANGED
@@ -30,3 +30,7 @@ export function inIframe() {
30
30
  export function utoa(data: string): string {
31
31
  return btoa(unescape(encodeURIComponent(data)))
32
32
  }
33
+
34
+ export function getBrowserLanguage(): string {
35
+ return navigator.language.startsWith('zh') ? 'zh-CN' : 'en-US'
36
+ }