feima-shortcuts 0.3.0-beta.0 → 0.3.0-beta.2

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/bin/feima.js CHANGED
@@ -2,6 +2,8 @@
2
2
  const inquirer = require("inquirer");
3
3
  const { Command } = require('commander')
4
4
  const feima = require("../src/generate");
5
+
6
+ const checkLocale = require('../src/scripts/check-locale')
5
7
  const { version } = require("../package.json"); // 读取 package.json 中的版本号
6
8
 
7
9
  const program = new Command()
@@ -14,7 +16,7 @@ program
14
16
  .command('check-locale')
15
17
  .description('检查未使用的 locale')
16
18
  .action(() => {
17
- require('../src/scripts/check-locale')
19
+ checkLocale.run();
18
20
  })
19
21
 
20
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feima-shortcuts",
3
- "version": "0.3.0-beta.0",
3
+ "version": "0.3.0-beta.2",
4
4
  "description": "快捷指令",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -19,7 +19,9 @@
19
19
  "commander": "^5.1.0",
20
20
  "download-git-repo": "^3.0.2",
21
21
  "fs-extra": "^9.0.1",
22
+ "glob": "^13.0.0",
22
23
  "inquirer": "^7.3.0",
24
+ "typescript": "^5.9.3",
23
25
  "uuid": "^9.0.0"
24
26
  },
25
27
  "packageManager": "pnpm@10.6.3+sha512.bb45e34d50a9a76e858a95837301bfb6bd6d35aea2c5d52094fa497a467c43f5c440103ce2511e9e0a2f89c3d6071baac3358fc68ac6fb75e2ceb3d2736065e6"
@@ -29,6 +29,7 @@ function loadLocaleKeys(localePath) {
29
29
  ts.isExportAssignment(node) &&
30
30
  ts.isObjectLiteralExpression(node.expression)
31
31
  ) {
32
+ // eval 需要谨慎,这里保持原逻辑
32
33
  obj = eval(`(${node.expression.getText()})`)
33
34
  }
34
35
  ts.forEachChild(node, visit)
@@ -109,16 +110,25 @@ function checkPageLocale(pageDir) {
109
110
 
110
111
  const localeKeys = loadLocaleKeys(localePath)
111
112
  const usedKeys = extractUsedKeys(code)
112
- const unused = localeKeys.filter((k) => !usedKeys.has(k))
113
113
 
114
+ // locale.ts 中定义但未使用的 key
115
+ const unused = localeKeys.filter((k) => !usedKeys.has(k))
114
116
  if (unused.length) {
115
117
  console.log(`\n❌ 页面未使用 locale key`)
116
118
  console.log(` ${localePath}`)
117
119
  unused.forEach((k) => console.log(` - ${k}`))
120
+ }
121
+
122
+ // 页面中用到了 locale.ts 中未定义的 key
123
+ const undefinedKeys = [...usedKeys].filter((k) => !localeKeys.includes(k))
124
+ if (undefinedKeys.length) {
125
+ console.log(`\n❌ 页面使用了 locale.ts 中未定义的 key`)
126
+ console.log(` ${indexVue}`)
127
+ undefinedKeys.forEach((k) => console.log(` - ${k}`))
118
128
  return true
119
129
  }
120
130
 
121
- return false
131
+ return unused.length > 0
122
132
  }
123
133
 
124
134
  /* 组件 locale 检测 */
@@ -157,6 +167,7 @@ function checkComponentLocale(componentDir) {
157
167
 
158
168
  let hasError = false
159
169
 
170
+ // locale.ts 中定义但未使用的 key
160
171
  const unused = localeKeys.filter((k) => !usedKeys.has(k))
161
172
  if (unused.length) {
162
173
  hasError = true
@@ -165,6 +176,15 @@ function checkComponentLocale(componentDir) {
165
176
  unused.forEach((k) => console.log(` - ${k}`))
166
177
  }
167
178
 
179
+ // 组件代码中使用但 locale.ts 未定义的 key
180
+ const undefinedKeys = [...usedKeys].filter((k) => !localeKeys.includes(k))
181
+ if (undefinedKeys.length) {
182
+ hasError = true
183
+ console.log(`\n❌ 组件使用了 locale.ts 中未定义的 key`)
184
+ console.log(` ${componentDir}`)
185
+ undefinedKeys.forEach((k) => console.log(` - ${k}`))
186
+ }
187
+
168
188
  if (invalidFiles.length) {
169
189
  hasError = true
170
190
  console.log(`\n🚫 组件存在错误的 locale 引入方式`)
@@ -174,12 +194,12 @@ function checkComponentLocale(componentDir) {
174
194
  })
175
195
  }
176
196
 
177
- if (skippedFiles.length) {
178
- console.log(`\n⚠️ 组件中以下文件未绑定本地 locale(已跳过)`)
179
- skippedFiles.forEach((f) =>
180
- console.log(` ${path.relative(process.cwd(), f)}`)
181
- )
182
- }
197
+ // if (skippedFiles.length) {
198
+ // console.log(`\n⚠️ 组件中以下文件未绑定本地 locale(已跳过)`)
199
+ // skippedFiles.forEach((f) =>
200
+ // console.log(` ${path.relative(process.cwd(), f)}`)
201
+ // )
202
+ // }
183
203
 
184
204
  return hasError
185
205
  }
@@ -203,15 +223,11 @@ function run() {
203
223
  })
204
224
 
205
225
  if (hasError) {
206
- console.log('\n❗ locale 治理未通过')
226
+ console.log('\n❗ locale 检查未通过')
207
227
  process.exit(1)
208
228
  } else {
209
- console.log('\n✅ locale 治理通过')
229
+ console.log('\n✅ locale 检查通过')
210
230
  }
211
231
  }
212
232
 
213
- if (require.main === module) {
214
- run()
215
- }
216
-
217
- module.exports = run
233
+ exports.run = run