feima-shortcuts 0.3.0-beta.4 → 0.3.0-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feima-shortcuts",
3
- "version": "0.3.0-beta.4",
3
+ "version": "0.3.0-beta.5",
4
4
  "description": "快捷指令",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -4,7 +4,8 @@ const path = require('path')
4
4
  const glob = require('glob')
5
5
  const ts = require('typescript')
6
6
 
7
- /* 工具函数,保持你原逻辑 */
7
+ /* ================= 工具函数 ================= */
8
+
8
9
  function flattenLocale(obj, prefix = '') {
9
10
  let res = []
10
11
  for (const k in obj) {
@@ -38,11 +39,19 @@ function loadLocaleKeys(localePath) {
38
39
  return obj ? flattenLocale(obj) : []
39
40
  }
40
41
 
42
+ /**
43
+ * 提取使用到的 locale key
44
+ * 兼容:
45
+ * t('a.b.c')
46
+ * t('a.b.c', 'fallback')
47
+ */
41
48
  function extractUsedKeys(code) {
42
- const reg = /t\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g
49
+ const reg = /t\s*\(\s*['"`]([^'"`]+)['"`]\s*(?:,|\))/g
43
50
  const set = new Set()
44
51
  let m
45
- while ((m = reg.exec(code))) set.add(m[1])
52
+ while ((m = reg.exec(code))) {
53
+ set.add(m[1])
54
+ }
46
55
  return set
47
56
  }
48
57
 
@@ -77,7 +86,8 @@ function detectUseLocale(code) {
77
86
  }
78
87
  }
79
88
 
80
- /* 页面 locale 检测 */
89
+ /* ================= 页面 locale 检测 ================= */
90
+
81
91
  function checkPageLocale(pageDir) {
82
92
  const localePath = path.join(pageDir, 'locale.ts')
83
93
  const indexVue = path.join(pageDir, 'index.vue')
@@ -121,7 +131,8 @@ function checkPageLocale(pageDir) {
121
131
  return false
122
132
  }
123
133
 
124
- /* 组件 locale 检测 */
134
+ /* ================= 组件 locale 检测 ================= */
135
+
125
136
  function checkComponentLocale(componentDir) {
126
137
  const localePath = path.join(componentDir, 'locale.ts')
127
138
  if (!fs.existsSync(localePath)) return false
@@ -184,7 +195,7 @@ function checkComponentLocale(componentDir) {
184
195
  return hasError
185
196
  }
186
197
 
187
- /* 主入口 */
198
+ /* ================= 主入口 ================= */
188
199
 
189
200
  function run() {
190
201
  const root = path.resolve(process.cwd(), 'src/views')