@varlet/cli 2.22.3 → 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 (32) hide show
  1. package/README.md +30 -18
  2. package/README.zh-CN.md +16 -4
  3. package/lib/client/index.d.ts +3 -2
  4. package/lib/client/index.js +20 -11
  5. package/lib/node/bin.js +7 -0
  6. package/lib/node/commands/styleVars.d.ts +1 -0
  7. package/lib/node/commands/styleVars.js +6 -0
  8. package/lib/node/config/varlet.config.d.ts +4 -0
  9. package/lib/node/config/varlet.default.config.js +121 -9
  10. package/lib/node/index.d.ts +1 -0
  11. package/lib/node/index.js +1 -0
  12. package/package.json +9 -9
  13. package/site/mobile/App.vue +63 -23
  14. package/site/pc/Layout.vue +7 -1
  15. package/site/pc/components/AppHeader.vue +78 -35
  16. package/site/pc/components/code-example/CodeExample.vue +1 -1
  17. package/site/pc/components/code-example/codeExample.less +1 -1
  18. package/site/pc/pages/index/index.vue +10 -9
  19. package/site/utils.ts +0 -6
  20. package/template/create/example/locale/_index.ts +4 -4
  21. package/template/create/example/locale/index.ts +4 -4
  22. package/template/generators/config/i18n/base/types/locale.d.ts +14 -10
  23. package/template/generators/config/i18n/sfc/src/button/example/BasicUse.vue +2 -2
  24. package/template/generators/config/i18n/sfc/src/button/example/ModifyColor.vue +2 -2
  25. package/template/generators/config/i18n/sfc/src/button/example/index.vue +5 -5
  26. package/template/generators/config/i18n/sfc/src/button/example/locale/index.ts +4 -4
  27. package/template/generators/config/i18n/sfc/src/locale/index.ts +31 -21
  28. package/template/generators/config/i18n/tsx/src/button/example/BasicUse.vue +2 -2
  29. package/template/generators/config/i18n/tsx/src/button/example/ModifyColor.vue +2 -2
  30. package/template/generators/config/i18n/tsx/src/button/example/index.vue +5 -5
  31. package/template/generators/config/i18n/tsx/src/button/example/locale/index.ts +4 -4
  32. package/template/generators/config/i18n/tsx/src/locale/index.ts +33 -21
@@ -2,64 +2,74 @@ import { ref } from 'vue'
2
2
  import type { Ref } from 'vue'
3
3
  import zhCN from './zh-CN'
4
4
 
5
- export type Pack = {
5
+ export type Message = {
6
6
  // Button component
7
7
  button: string
8
8
 
9
9
  // internal
10
10
  lang?: string
11
+ [key: PropertyKey]: any
11
12
  }
12
13
 
13
- function useLocale<T = Pack>() {
14
- const packs: Record<string, Partial<T>> = {}
15
- const pack: Ref<Partial<T>> = ref({})
14
+ function useLocale<T = Message>() {
15
+ const messages: Record<string, Partial<T>> = {}
16
+ const currentMessage: Ref<Partial<T>> = ref({})
16
17
 
17
- const add = (lang: string, pack: Partial<T> & { lang?: string }) => {
18
- pack.lang = lang
19
- packs[lang] = pack
18
+ const add = (lang: string, message: Partial<T> & { lang?: string }) => {
19
+ message.lang = lang
20
+ messages[lang] = message
20
21
  }
21
22
 
22
23
  const use = (lang: string) => {
23
- if (!packs[lang]) {
24
- console.warn(`The ${lang} does not exist. You can mount a language package using the add method`)
24
+ if (!messages[lang]) {
25
+ console.warn(`The ${lang} does not exist. You can mount a language message using the add method`)
25
26
  return {}
26
27
  }
27
28
 
28
- pack.value = packs[lang]
29
+ currentMessage.value = messages[lang]
29
30
  }
30
31
 
31
- const merge = (lang: string, pack: Partial<T>) => {
32
- if (!packs[lang]) {
33
- console.warn(`The ${lang} does not exist. You can mount a language package using the add method`)
32
+ const merge = (lang: string, message: Partial<T>) => {
33
+ if (!messages[lang]) {
34
+ console.warn(`The ${lang} does not exist. You can mount a language message using the add method`)
34
35
  return
35
36
  }
36
37
 
37
- packs[lang] = { ...packs[lang], ...pack }
38
+ messages[lang] = { ...messages[lang], ...message }
38
39
 
39
40
  use(lang)
40
41
  }
41
42
 
43
+ const t = (id: string) => {
44
+ if (Object.prototype.hasOwnProperty.call(currentMessage.value, id)) {
45
+ return currentMessage.value[id]
46
+ }
47
+
48
+ return id
49
+ }
50
+
42
51
  return {
43
- packs,
44
- pack,
52
+ messages,
53
+ currentMessage,
45
54
  add,
46
55
  use,
47
56
  merge,
57
+ t
48
58
  }
49
59
  }
50
60
 
51
- const { packs, pack, add, use, merge } = useLocale()
61
+ const { messages, currentMessage, add, use, merge } = useLocale()
52
62
 
53
63
  add('zh-CN', zhCN)
54
64
  use('zh-CN')
55
65
 
56
- export { packs, pack, add, use, merge, useLocale }
66
+ export { messages, currentMessage, add, use, merge, useLocale }
57
67
 
58
- export const _LocaleComponent = { packs, pack, add, use, merge, useLocale }
68
+ export const _LocaleComponent = { messages, currentMessage, add, use, merge, useLocale }
59
69
 
60
70
  export default {
61
- packs,
62
- pack,
71
+ messages,
72
+ currentMessage,
63
73
  add,
64
74
  use,
65
75
  merge,
@@ -1,11 +1,11 @@
1
1
  <script setup>
2
2
  import VaButton from '..'
3
3
  import { watchLang } from '@varlet/cli/client'
4
- import { pack, use } from './locale'
4
+ import { t, use } from './locale'
5
5
 
6
6
  watchLang(use, 'pc')
7
7
  </script>
8
8
 
9
9
  <template>
10
- <va-button>{{ pack.start }}</va-button>
10
+ <va-button>{{ t('start') }}</va-button>
11
11
  </template>
@@ -1,11 +1,11 @@
1
1
  <script setup>
2
2
  import VaButton from '..'
3
3
  import { watchLang } from '@varlet/cli/client'
4
- import { pack, use } from './locale'
4
+ import { t, use } from './locale'
5
5
 
6
6
  watchLang(use, 'pc')
7
7
  </script>
8
8
 
9
9
  <template>
10
- <va-button color="#03A9F4">{{ pack.start }}</va-button>
10
+ <va-button color="#03A9F4">{{ t('start') }}</va-button>
11
11
  </template>
@@ -1,15 +1,15 @@
1
1
  <script setup>
2
2
  import VaButton from '..'
3
3
  import { watchLang, AppType } from '@varlet/cli/client'
4
- import { pack, use } from './locale'
4
+ import { t, use } from './locale'
5
5
 
6
6
  watchLang(use)
7
7
  </script>
8
8
 
9
9
  <template>
10
- <app-type>{{ pack.basicUse }}</app-type>
11
- <va-button>{{ pack.start }}</va-button>
10
+ <app-type>{{ t('basicUse') }}</app-type>
11
+ <va-button>{{ t('start') }}</va-button>
12
12
 
13
- <app-type>{{ pack.modifyColor }}</app-type>
14
- <va-button color="#03A9F4">{{ pack.start }}</va-button>
13
+ <app-type>{{ t('modifyColor') }}</app-type>
14
+ <va-button color="#03A9F4">{{ t('start') }}</va-button>
15
15
  </template>
@@ -6,18 +6,18 @@ import zhCN from './zh-CN'
6
6
  import enUS from './en-US'
7
7
  import { useLocale, add as _add, use as _use } from '../../../locale'
8
8
 
9
- const { add, use: exampleUse, pack, packs, merge } = useLocale()
9
+ const { add, use: exampleUse, t, merge } = useLocale()
10
10
 
11
11
  const use = (lang: string) => {
12
12
  _use(lang)
13
13
  exampleUse(lang)
14
14
  }
15
15
 
16
- export { add, pack, packs, merge, use }
16
+ export { add, t, merge, use }
17
17
 
18
18
  // lib
19
19
  _add('zh-CN', _zhCN)
20
20
  _add('en-US', _enCN)
21
21
  // mobile example doc
22
- add('zh-CN', zhCN as any)
23
- add('en-US', enUS as any)
22
+ add('zh-CN', zhCN)
23
+ add('en-US', enUS)
@@ -2,66 +2,78 @@ import { ref } from 'vue'
2
2
  import type { Ref } from 'vue'
3
3
  import zhCN from './zh-CN'
4
4
 
5
- export type Pack = {
5
+ export type Message = {
6
6
  // Button component
7
7
  button: string
8
8
 
9
9
  // internal
10
10
  lang?: string
11
+
12
+ [key: PropertyKey]: any
11
13
  }
12
14
 
13
- function useLocale<T = Pack>() {
14
- const packs: Record<string, Partial<T>> = {}
15
- const pack: Ref<Partial<T>> = ref({})
15
+ function useLocale<T = Message>() {
16
+ const messages: Record<string, Partial<T>> = {}
17
+ const currentMessage: Ref<Partial<T>> = ref({})
16
18
 
17
- const add = (lang: string, pack: Partial<T> & { lang?: string }) => {
18
- pack.lang = lang
19
- packs[lang] = pack
19
+ const add = (lang: string, message: Partial<T> & { lang?: string }) => {
20
+ message.lang = lang
21
+ messages[lang] = message
20
22
  }
21
23
 
22
24
  const use = (lang: string) => {
23
- if (!packs[lang]) {
24
- console.warn(`The ${lang} does not exist. You can mount a language package using the add method`)
25
+ if (!messages[lang]) {
26
+ console.warn(`The ${lang} does not exist. You can mount a language message using the add method`)
25
27
  return {}
26
28
  }
27
29
 
28
- pack.value = packs[lang]
30
+ currentMessage.value = messages[lang]
29
31
  }
30
32
 
31
- const merge = (lang: string, pack: Partial<T>) => {
32
- if (!packs[lang]) {
33
- console.warn(`The ${lang} does not exist. You can mount a language package using the add method`)
33
+ const merge = (lang: string, message: Partial<T>) => {
34
+ if (!messages[lang]) {
35
+ console.warn(`The ${lang} does not exist. You can mount a language message using the add method`)
34
36
  return
35
37
  }
36
38
 
37
- packs[lang] = { ...packs[lang], ...pack }
39
+ messages[lang] = { ...messages[lang], ...message }
38
40
 
39
41
  use(lang)
40
42
  }
41
43
 
44
+ const t = (id: string) => {
45
+ if (Object.prototype.hasOwnProperty.call(currentMessage.value, id)) {
46
+ return currentMessage.value[id]
47
+ }
48
+
49
+ return id
50
+ }
51
+
42
52
  return {
43
- packs,
44
- pack,
53
+ messages,
54
+ currentMessage,
45
55
  add,
46
56
  use,
47
57
  merge,
58
+ t
48
59
  }
49
60
  }
50
61
 
51
- const { packs, pack, add, use, merge } = useLocale()
62
+ const { messages, currentMessage, t, add, use, merge } = useLocale()
52
63
 
53
64
  add('zh-CN', zhCN)
54
65
  use('zh-CN')
55
66
 
56
- export { packs, pack, add, use, merge, useLocale }
67
+ export { messages, currentMessage, t, add, use, merge, useLocale }
57
68
 
58
- export const _LocaleComponent = { packs, pack, add, use, merge, useLocale }
69
+ export const _LocaleComponent = { messages, currentMessage, t, add, use, merge, useLocale }
59
70
 
60
71
  export default {
61
- packs,
62
- pack,
72
+ messages,
73
+ currentMessage,
63
74
  add,
64
75
  use,
65
76
  merge,
77
+ t,
66
78
  useLocale,
67
79
  }