feima-shortcuts 0.3.0-beta.1 → 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/package.json
CHANGED
|
@@ -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
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
}
|