feat: 1.统一右侧抽屉关闭按钮布局 2.统一 UI 组件为 Ant Design 移除 radix-ui、floating-ui 组件 3. 修复 ESLint 文件格式错误的问题
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
import { readFile, readdir } from 'node:fs/promises';
|
||||
import { createHash } from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { Linter } from 'eslint';
|
||||
|
||||
const root = fileURLToPath(new URL('../', import.meta.url));
|
||||
const forbidden = [
|
||||
/^@radix-ui\//,
|
||||
/^@floating-ui\//,
|
||||
/^@lobehub\/(?:ui|icons)(?:\/|$)/,
|
||||
/^@douyinfe\/semi-(?:ui|icons|foundation)(?:\/|$)/,
|
||||
/^@headlessui\//,
|
||||
/^@mui\//,
|
||||
/^@chakra-ui\//,
|
||||
/^(?:leva|antd-style|react-layout-kit)(?:\/|$)/,
|
||||
];
|
||||
export const isForbiddenUiDependency = (name) =>
|
||||
forbidden.some((pattern) => pattern.test(name));
|
||||
|
||||
export function auditManifest(manifest, lock) {
|
||||
const issues = [];
|
||||
for (const section of [
|
||||
'dependencies',
|
||||
'devDependencies',
|
||||
'optionalDependencies',
|
||||
'peerDependencies',
|
||||
]) {
|
||||
for (const name of Object.keys(manifest[section] || {})) {
|
||||
if (isForbiddenUiDependency(name))
|
||||
issues.push(`package.json ${section}: ${name}`);
|
||||
}
|
||||
}
|
||||
for (const location of Object.keys(lock.packages || {})) {
|
||||
if (isForbiddenUiDependency(location.split('node_modules/').at(-1))) {
|
||||
issues.push(`package-lock.json: ${location}`);
|
||||
}
|
||||
}
|
||||
if (!lock.packages || lock.lockfileVersion < 2)
|
||||
issues.push('Expected an npm lockfile with a packages graph.');
|
||||
return issues;
|
||||
}
|
||||
|
||||
export function auditSource(source, filename) {
|
||||
const linter = new Linter();
|
||||
linter.defineRule('ui-dependencies', {
|
||||
create(context) {
|
||||
const inspect = (node) => {
|
||||
if (
|
||||
node?.type === 'Literal' &&
|
||||
typeof node.value === 'string' &&
|
||||
isForbiddenUiDependency(node.value)
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
message: `Use Ant Design or the audited local brand assets: ${node.value}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
return {
|
||||
ImportDeclaration: (node) => inspect(node.source),
|
||||
ExportNamedDeclaration: (node) => inspect(node.source),
|
||||
ExportAllDeclaration: (node) => inspect(node.source),
|
||||
ImportExpression: (node) => inspect(node.source),
|
||||
CallExpression: (node) => {
|
||||
if (
|
||||
node.callee.type === 'Identifier' &&
|
||||
node.callee.name === 'require'
|
||||
)
|
||||
inspect(node.arguments[0]);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
return linter
|
||||
.verify(
|
||||
source,
|
||||
{
|
||||
parserOptions: {
|
||||
ecmaVersion: 2022,
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: { jsx: true },
|
||||
},
|
||||
rules: { 'ui-dependencies': 'error' },
|
||||
},
|
||||
{ filename, allowInlineConfig: false },
|
||||
)
|
||||
.map((issue) => `${filename}:${issue.line}: ${issue.message}`);
|
||||
}
|
||||
|
||||
async function sourceFiles(dir) {
|
||||
const files = [];
|
||||
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
||||
const name = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) files.push(...(await sourceFiles(name)));
|
||||
else if (/\.[cm]?[jt]sx?$/.test(entry.name)) files.push(name);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
export async function checkUiDependencies(directory = root) {
|
||||
const manifest = JSON.parse(
|
||||
await readFile(path.join(directory, 'package.json'), 'utf8'),
|
||||
);
|
||||
const lock = JSON.parse(
|
||||
await readFile(path.join(directory, 'package-lock.json'), 'utf8'),
|
||||
);
|
||||
const issues = auditManifest(manifest, lock);
|
||||
const files = await sourceFiles(path.join(directory, 'src'));
|
||||
for (const filename of files) {
|
||||
issues.push(
|
||||
...auditSource(
|
||||
await readFile(filename, 'utf8'),
|
||||
path.relative(directory, filename),
|
||||
),
|
||||
);
|
||||
}
|
||||
const assets = path.join(directory, 'src/assets/brand-icons');
|
||||
const provenance = JSON.parse(
|
||||
await readFile(path.join(assets, 'manifest.json'), 'utf8'),
|
||||
);
|
||||
const generated = (await readdir(assets))
|
||||
.filter((name) => name.endsWith('.js'))
|
||||
.sort();
|
||||
if (
|
||||
JSON.stringify(generated) !==
|
||||
JSON.stringify(Object.keys(provenance.files).sort())
|
||||
)
|
||||
issues.push(
|
||||
'Brand icon provenance must list every generated JavaScript file.',
|
||||
);
|
||||
for (const [name, hash] of Object.entries(provenance.files)) {
|
||||
if (!/^(?:lobehub|primitives|shared-[A-Z0-9]+)\.js$/.test(name)) {
|
||||
issues.push(`Invalid generated icon filename: ${name}`);
|
||||
continue;
|
||||
}
|
||||
const icons = await readFile(path.join(assets, name));
|
||||
if (createHash('sha256').update(icons).digest('hex') !== hash)
|
||||
issues.push(
|
||||
`Generated brand icons differ from their provenance hash: ${name}; regenerate them.`,
|
||||
);
|
||||
}
|
||||
return {
|
||||
issues,
|
||||
files: files.length,
|
||||
packages: Object.keys(lock.packages).length - 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
process.argv[1] &&
|
||||
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
||||
) {
|
||||
const result = await checkUiDependencies();
|
||||
if (result.issues.length) {
|
||||
console.error(result.issues.join('\n'));
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
console.log(
|
||||
`UI dependency audit passed: ${result.files} source files, ${result.packages} locked packages.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,12 @@ function walk(dir, files = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name.startsWith('.')) continue;
|
||||
if (
|
||||
entry.name === 'node_modules' ||
|
||||
entry.name === 'dist' ||
|
||||
entry.name.startsWith('.')
|
||||
)
|
||||
continue;
|
||||
walk(full, files);
|
||||
} else if (/\.(jsx?|tsx?)$/.test(entry.name)) {
|
||||
files.push(full);
|
||||
@@ -93,13 +98,13 @@ function main() {
|
||||
totalKeysUsedInSource: allKeys.size,
|
||||
missingByLocale: missing,
|
||||
keyToFiles: Object.fromEntries(
|
||||
[...keyToFiles.entries()].map(([k, v]) => [k, v.slice(0, 3)])
|
||||
[...keyToFiles.entries()].map(([k, v]) => [k, v.slice(0, 3)]),
|
||||
),
|
||||
};
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, 'missing_i18n.json'),
|
||||
JSON.stringify(out, null, 2),
|
||||
'utf8'
|
||||
'utf8',
|
||||
);
|
||||
console.log(`\nWrote ${path.join(__dirname, 'missing_i18n.json')}`);
|
||||
|
||||
|
||||
+174
-21
@@ -23,27 +23,136 @@ const MAX_COUNT = 300;
|
||||
|
||||
// 优先级分层:数字越小越先翻译。一个 key 被多个区域引用时取最小值(最高优先级)。
|
||||
const TIERS = [
|
||||
{ tier: 1, name: '入口/认证', areas: ['components/auth', 'pages/OrgLogin', 'pages/OrgRegister', 'pages/Setup', 'components/setup'] },
|
||||
{ tier: 2, name: '全局外壳', areas: ['components/layout', 'components/common', 'helpers', 'pages/NotFound', 'pages/Forbidden'] },
|
||||
{ tier: 3, name: '个人高频主链路', areas: ['pages/UserCenter', 'pages/KeyManagement', 'pages/Token', 'pages/Recharge', 'pages/TopUp', 'components/topup', 'pages/Home', 'pages/Dashboard', 'pages/Pricing'] },
|
||||
{ tier: 4, name: '核心业务', areas: ['pages/ExperienceCenter', 'pages/CloudBrain', 'pages/SkillMarket', 'pages/Chat', 'pages/Chat2Link', 'pages/Playground', 'pages/ImageGeneration', 'pages/Midjourney', 'components/playground', 'components/image', 'components/skill'] },
|
||||
{ tier: 5, name: '通用交互层', areas: ['hooks', 'components/table', 'components/customer-service', 'pages/Log', 'pages/Task', 'pages/Subscription', 'components/membership', 'pages/Tutorial', 'pages/Docs', 'pages/About', 'pages/PrivacyPolicy', 'pages/UserAgreement', 'pages/Status'] },
|
||||
{ tier: 6, name: '企业侧', areas: ['pages/Organization', 'pages/ExpertPlatform', 'pages/SkillPlatform', 'pages/ExperienceCenterAudit'] },
|
||||
{ tier: 7, name: '管理/运营后台', areas: ['pages/Setting', 'components/settings', 'pages/AdminOrganizations', 'pages/AdminInvoice', 'pages/AdminOrder', 'pages/Channel', 'pages/Model', 'pages/Redemption', 'pages/Monitoring', 'pages/MonitorCenter', 'pages/ServiceDashboard', 'pages/Analytics', 'pages/User', 'components/analytics', 'components/dashboard'] },
|
||||
{ tier: 8, name: '提成/合作伙伴', areas: ['pages/MyCommission', 'pages/PartnerPortal', 'components/promotion'] },
|
||||
{
|
||||
tier: 1,
|
||||
name: '入口/认证',
|
||||
areas: [
|
||||
'components/auth',
|
||||
'pages/OrgLogin',
|
||||
'pages/OrgRegister',
|
||||
'pages/Setup',
|
||||
'components/setup',
|
||||
],
|
||||
},
|
||||
{
|
||||
tier: 2,
|
||||
name: '全局外壳',
|
||||
areas: [
|
||||
'components/layout',
|
||||
'components/common',
|
||||
'helpers',
|
||||
'pages/NotFound',
|
||||
'pages/Forbidden',
|
||||
],
|
||||
},
|
||||
{
|
||||
tier: 3,
|
||||
name: '个人高频主链路',
|
||||
areas: [
|
||||
'pages/UserCenter',
|
||||
'pages/KeyManagement',
|
||||
'pages/Token',
|
||||
'pages/Recharge',
|
||||
'pages/TopUp',
|
||||
'components/topup',
|
||||
'pages/Home',
|
||||
'pages/Dashboard',
|
||||
'pages/Pricing',
|
||||
],
|
||||
},
|
||||
{
|
||||
tier: 4,
|
||||
name: '核心业务',
|
||||
areas: [
|
||||
'pages/ExperienceCenter',
|
||||
'pages/CloudBrain',
|
||||
'pages/SkillMarket',
|
||||
'pages/Chat',
|
||||
'pages/Chat2Link',
|
||||
'pages/Playground',
|
||||
'pages/ImageGeneration',
|
||||
'pages/Midjourney',
|
||||
'components/playground',
|
||||
'components/image',
|
||||
'components/skill',
|
||||
],
|
||||
},
|
||||
{
|
||||
tier: 5,
|
||||
name: '通用交互层',
|
||||
areas: [
|
||||
'hooks',
|
||||
'components/table',
|
||||
'components/customer-service',
|
||||
'pages/Log',
|
||||
'pages/Task',
|
||||
'pages/Subscription',
|
||||
'components/membership',
|
||||
'pages/Tutorial',
|
||||
'pages/Docs',
|
||||
'pages/About',
|
||||
'pages/PrivacyPolicy',
|
||||
'pages/UserAgreement',
|
||||
'pages/Status',
|
||||
],
|
||||
},
|
||||
{
|
||||
tier: 6,
|
||||
name: '企业侧',
|
||||
areas: [
|
||||
'pages/Organization',
|
||||
'pages/ExpertPlatform',
|
||||
'pages/SkillPlatform',
|
||||
'pages/ExperienceCenterAudit',
|
||||
],
|
||||
},
|
||||
{
|
||||
tier: 7,
|
||||
name: '管理/运营后台',
|
||||
areas: [
|
||||
'pages/Setting',
|
||||
'components/settings',
|
||||
'pages/AdminOrganizations',
|
||||
'pages/AdminInvoice',
|
||||
'pages/AdminOrder',
|
||||
'pages/Channel',
|
||||
'pages/Model',
|
||||
'pages/Redemption',
|
||||
'pages/Monitoring',
|
||||
'pages/MonitorCenter',
|
||||
'pages/ServiceDashboard',
|
||||
'pages/Analytics',
|
||||
'pages/User',
|
||||
'components/analytics',
|
||||
'components/dashboard',
|
||||
],
|
||||
},
|
||||
{
|
||||
tier: 8,
|
||||
name: '提成/合作伙伴',
|
||||
areas: [
|
||||
'pages/MyCommission',
|
||||
'pages/PartnerPortal',
|
||||
'components/promotion',
|
||||
],
|
||||
},
|
||||
];
|
||||
const TIER_OTHER = 9; // 源码中有引用但未归入上表的区域
|
||||
const TIER_DEAD = 99; // 源码已无引用的历史 key(en.json 里还在,为「一一对应」保留)
|
||||
|
||||
const AREA_TIER = new Map();
|
||||
const TIER_NAME = new Map([[TIER_OTHER, '其他区域'], [TIER_DEAD, '无调用点(历史键)']]);
|
||||
const TIER_NAME = new Map([
|
||||
[TIER_OTHER, '其他区域'],
|
||||
[TIER_DEAD, '无调用点(历史键)'],
|
||||
]);
|
||||
for (const { tier, name, areas } of TIERS) {
|
||||
TIER_NAME.set(tier, name);
|
||||
for (const a of areas) AREA_TIER.set(a, tier);
|
||||
}
|
||||
|
||||
const load = (n) =>
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8')).translation;
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8'))
|
||||
.translation;
|
||||
// 已译状态唯一事实源就是 locales/{ko,th}.json 本身;不另存快照文件,避免两份
|
||||
// 数据漂移(快照落后时会把已译 key 重新切进批次,覆盖掉已有译文)。
|
||||
const loadDone = (l) => {
|
||||
@@ -62,7 +171,11 @@ function walk(dir, files = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (['node_modules', 'dist'].includes(entry.name) || entry.name.startsWith('.')) continue;
|
||||
if (
|
||||
['node_modules', 'dist'].includes(entry.name) ||
|
||||
entry.name.startsWith('.')
|
||||
)
|
||||
continue;
|
||||
walk(full, files);
|
||||
} else if (/\.(jsx?|tsx?)$/.test(entry.name)) {
|
||||
files.push(full);
|
||||
@@ -72,15 +185,24 @@ function walk(dir, files = []) {
|
||||
}
|
||||
|
||||
const unescape = (raw) =>
|
||||
raw.replace(/\\'/g, "'").replace(/\\"/g, '"').replace(/\\\\/g, '\\').replace(/\\n/g, '\n');
|
||||
raw
|
||||
.replace(/\\'/g, "'")
|
||||
.replace(/\\"/g, '"')
|
||||
.replace(/\\\\/g, '\\')
|
||||
.replace(/\\n/g, '\n');
|
||||
|
||||
// 1) 建立 key -> 最高优先级 + 代表区域
|
||||
const keyTier = new Map();
|
||||
const keyArea = new Map();
|
||||
for (const file of walk(SRC_DIR).filter((f) => !f.includes(path.join('src', 'i18n')))) {
|
||||
for (const file of walk(SRC_DIR).filter(
|
||||
(f) => !f.includes(path.join('src', 'i18n')),
|
||||
)) {
|
||||
const content = fs.readFileSync(file, 'utf8');
|
||||
const rel = path.relative(SRC_DIR, file).split(path.sep);
|
||||
const area = rel[0] === 'pages' || rel[0] === 'components' ? `${rel[0]}/${rel[1]}` : rel[0];
|
||||
const area =
|
||||
rel[0] === 'pages' || rel[0] === 'components'
|
||||
? `${rel[0]}/${rel[1]}`
|
||||
: rel[0];
|
||||
const tier = AREA_TIER.get(area) ?? TIER_OTHER;
|
||||
let m;
|
||||
T_CALL_RE.lastIndex = 0;
|
||||
@@ -117,7 +239,11 @@ const flush = () => {
|
||||
if (!batch.length) return;
|
||||
n += 1;
|
||||
const name = `batch_${String(n).padStart(3, '0')}.json`;
|
||||
fs.writeFileSync(path.join(OUT_DIR, name), JSON.stringify(batch, null, 2), 'utf8');
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, name),
|
||||
JSON.stringify(batch, null, 2),
|
||||
'utf8',
|
||||
);
|
||||
const areas = [...new Set(batch.map((x) => x.area))];
|
||||
manifest.push({
|
||||
file: name,
|
||||
@@ -134,29 +260,56 @@ const flush = () => {
|
||||
for (const { k, tier } of pending) {
|
||||
const zhText = k in zh ? zh[k] || k : k;
|
||||
// 优先级换档必须断批:一批只属于一个层级,进度才能对应到「哪些页面已可用」
|
||||
if (batch.length && (tier !== curTier || used + zhText.length > CHAR_BUDGET || batch.length >= MAX_COUNT)) {
|
||||
if (
|
||||
batch.length &&
|
||||
(tier !== curTier ||
|
||||
used + zhText.length > CHAR_BUDGET ||
|
||||
batch.length >= MAX_COUNT)
|
||||
) {
|
||||
flush();
|
||||
}
|
||||
curTier = tier;
|
||||
// cur:各语种已有译文。批次按「任一语种未译」切,已译的那一侧回填 "" 即保留原值
|
||||
const cur = Object.fromEntries(LANGS.map((l) => [l, done[l][k] || '']));
|
||||
batch.push({ key: k, zh: zhText, en: en[k], cur, area: keyArea.get(k) || '-', tier });
|
||||
batch.push({
|
||||
key: k,
|
||||
zh: zhText,
|
||||
en: en[k],
|
||||
cur,
|
||||
area: keyArea.get(k) || '-',
|
||||
tier,
|
||||
});
|
||||
used += zhText.length;
|
||||
}
|
||||
flush();
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, '_manifest.json'),
|
||||
JSON.stringify({ langs: LANGS, totalEnKeys: enKeys.length, pending: pending.length, batches: manifest }, null, 2),
|
||||
JSON.stringify(
|
||||
{
|
||||
langs: LANGS,
|
||||
totalEnKeys: enKeys.length,
|
||||
pending: pending.length,
|
||||
batches: manifest,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
const perTier = new Map();
|
||||
for (const { tier } of pending) perTier.set(tier, (perTier.get(tier) || 0) + 1);
|
||||
const doneSummary = LANGS.map((l) => `${l}已译 ${enKeys.filter((k) => done[l][k]).length}`).join(' / ');
|
||||
console.log(`en 全集 ${enKeys.length} | ${doneSummary} | 待译(任一语种缺) ${pending.length} | 切成 ${n} 批`);
|
||||
const doneSummary = LANGS.map(
|
||||
(l) => `${l}已译 ${enKeys.filter((k) => done[l][k]).length}`,
|
||||
).join(' / ');
|
||||
console.log(
|
||||
`en 全集 ${enKeys.length} | ${doneSummary} | 待译(任一语种缺) ${pending.length} | 切成 ${n} 批`,
|
||||
);
|
||||
console.log('待译量按优先级:');
|
||||
for (const [tier, cnt] of [...perTier.entries()].sort((a, b) => a[0] - b[0])) {
|
||||
const bs = manifest.filter((b) => b.tier === tier).length;
|
||||
console.log(` T${String(tier).padStart(2)} ${String(TIER_NAME.get(tier)).padEnd(16)} ${String(cnt).padStart(5)} 条 / ${String(bs).padStart(2)} 批`);
|
||||
console.log(
|
||||
` T${String(tier).padStart(2)} ${String(TIER_NAME.get(tier)).padEnd(16)} ${String(cnt).padStart(5)} 条 / ${String(bs).padStart(2)} 批`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ const BATCH_DIR = path.join(__dirname, 'kt_batches');
|
||||
const OUT_DIR = path.join(__dirname, 'kt_out');
|
||||
const LANGS = require('./i18n_langs.cjs');
|
||||
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(BATCH_DIR, '_manifest.json'), 'utf8'));
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(BATCH_DIR, '_manifest.json'), 'utf8'),
|
||||
);
|
||||
// kt_out/ 按批次号对位,换一组语种重切批次后,旧语种的 {lng}_NNN.json 仍留在目录里,
|
||||
// 却对应的是上一轮的批次内容;若靠长度校验兜底,同长批次会被静默错位回填。
|
||||
// 这里要求本次语种必须属于当前批次清单的语种(旧清单无 langs 字段时按 ko,th)。
|
||||
@@ -33,11 +35,13 @@ if (foreign.length) {
|
||||
process.exit(1);
|
||||
}
|
||||
const enKeys = Object.keys(
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'en.json'), 'utf8')).translation,
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'en.json'), 'utf8'))
|
||||
.translation,
|
||||
);
|
||||
|
||||
const PH = /\{\{[^}]*\}\}/g;
|
||||
const placeholders = (s) => new Set((String(s).match(PH) || []).map((x) => x.replace(/\s+/g, '')));
|
||||
const placeholders = (s) =>
|
||||
new Set((String(s).match(PH) || []).map((x) => x.replace(/\s+/g, '')));
|
||||
|
||||
let hardFail = false;
|
||||
|
||||
@@ -54,7 +58,9 @@ for (const lng of LANGS) {
|
||||
|
||||
for (const b of manifest.batches) {
|
||||
const idx = b.file.match(/batch_(\d+)\.json/)[1];
|
||||
const batch = JSON.parse(fs.readFileSync(path.join(BATCH_DIR, b.file), 'utf8'));
|
||||
const batch = JSON.parse(
|
||||
fs.readFileSync(path.join(BATCH_DIR, b.file), 'utf8'),
|
||||
);
|
||||
const outFile = path.join(OUT_DIR, `${lng}_${idx}.json`);
|
||||
if (!fs.existsSync(outFile)) continue;
|
||||
|
||||
@@ -69,7 +75,10 @@ for (const lng of LANGS) {
|
||||
batch.forEach((item, i) => {
|
||||
const v = typeof vals[i] === 'string' ? vals[i] : '';
|
||||
if (!v) return;
|
||||
const allowed = new Set([...placeholders(item.zh), ...placeholders(item.en)]);
|
||||
const allowed = new Set([
|
||||
...placeholders(item.zh),
|
||||
...placeholders(item.en),
|
||||
]);
|
||||
const unknown = [...placeholders(v)].filter((x) => !allowed.has(x));
|
||||
if (unknown.length) {
|
||||
problems.push(
|
||||
@@ -92,7 +101,9 @@ for (const lng of LANGS) {
|
||||
if (!v) continue;
|
||||
if (k.startsWith('_')) continue; // "_" 前缀留给文件内注释
|
||||
if (!enKeys.includes(k)) {
|
||||
console.error(`[${lng}] 覆盖项 ${JSON.stringify(k)} 不在 en.json 中,已跳过`);
|
||||
console.error(
|
||||
`[${lng}] 覆盖项 ${JSON.stringify(k)} 不在 en.json 中,已跳过`,
|
||||
);
|
||||
hardFail = true;
|
||||
continue;
|
||||
}
|
||||
@@ -110,7 +121,11 @@ for (const lng of LANGS) {
|
||||
Object.keys(ordered).length === enKeys.length &&
|
||||
Object.keys(ordered).every((k, i) => k === enKeys[i]);
|
||||
|
||||
fs.writeFileSync(localePath, JSON.stringify({ translation: ordered }, null, 2) + '\n', 'utf8');
|
||||
fs.writeFileSync(
|
||||
localePath,
|
||||
JSON.stringify({ translation: ordered }, null, 2) + '\n',
|
||||
'utf8',
|
||||
);
|
||||
|
||||
console.log(
|
||||
`[${lng}] keys=${enKeys.length} 已译=${filled} (原有${baseCount} + 新增${added} + 覆盖${overridden}) 待译=${enKeys.length - filled} key与en一一对应=${okKeys ? 'YES' : 'NO'}`,
|
||||
|
||||
@@ -10,7 +10,8 @@ const SRC_DIR = path.join(__dirname, '..', 'src');
|
||||
const LANGS = require('./i18n_langs.cjs');
|
||||
|
||||
const load = (n) =>
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8')).translation;
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8'))
|
||||
.translation;
|
||||
|
||||
const T_CALL_RE = /\bt\(\s*(['"`])((?:\\.|(?!\1).)*?)\1/g;
|
||||
const CJK_RE = /[一-鿿]/;
|
||||
@@ -19,7 +20,11 @@ function walk(dir, files = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (['node_modules', 'dist'].includes(entry.name) || entry.name.startsWith('.')) continue;
|
||||
if (
|
||||
['node_modules', 'dist'].includes(entry.name) ||
|
||||
entry.name.startsWith('.')
|
||||
)
|
||||
continue;
|
||||
walk(full, files);
|
||||
} else if (/\.(jsx?|tsx?)$/.test(entry.name)) {
|
||||
files.push(full);
|
||||
@@ -38,7 +43,9 @@ function unescape(raw) {
|
||||
|
||||
const dicts = Object.fromEntries(LANGS.map((l) => [l, load(l)]));
|
||||
const primary = dicts[LANGS[0]];
|
||||
const files = walk(SRC_DIR).filter((f) => !f.includes(path.join('src', 'i18n')));
|
||||
const files = walk(SRC_DIR).filter(
|
||||
(f) => !f.includes(path.join('src', 'i18n')),
|
||||
);
|
||||
|
||||
const byArea = new Map();
|
||||
const allUsed = new Set();
|
||||
@@ -49,7 +56,9 @@ for (const file of files) {
|
||||
// 粒度必须与 i18n_kt_batches.cjs 的分层一致:components 也要拆到子目录,
|
||||
// 否则 2800 多个 key 全折叠成一个 'components',看不出各子区域是否打满。
|
||||
const area =
|
||||
rel[0] === 'pages' || rel[0] === 'components' ? `${rel[0]}/${rel[1]}` : rel[0];
|
||||
rel[0] === 'pages' || rel[0] === 'components'
|
||||
? `${rel[0]}/${rel[1]}`
|
||||
: rel[0];
|
||||
let m;
|
||||
T_CALL_RE.lastIndex = 0;
|
||||
while ((m = T_CALL_RE.exec(content)) !== null) {
|
||||
@@ -68,13 +77,20 @@ for (const l of LANGS) {
|
||||
console.log(` ${l} 已译:${d} (${Math.round((d / used.length) * 100)}%)`);
|
||||
}
|
||||
const absent = used.filter((k) => !(k in primary)).length;
|
||||
console.log(` 不在 ${LANGS[0]}.json 中(en.json 也缺,运行时回退中文):${absent}`);
|
||||
console.log(
|
||||
` 不在 ${LANGS[0]}.json 中(en.json 也缺,运行时回退中文):${absent}`,
|
||||
);
|
||||
|
||||
const stats = [...byArea.entries()]
|
||||
.map(([area, set]) => {
|
||||
const arr = [...set];
|
||||
const done = arr.filter((k) => primary[k]).length;
|
||||
return { area, total: arr.length, done, pct: Math.round((done / arr.length) * 100) };
|
||||
return {
|
||||
area,
|
||||
total: arr.length,
|
||||
done,
|
||||
pct: Math.round((done / arr.length) * 100),
|
||||
};
|
||||
})
|
||||
.filter((r) => r.total >= 25)
|
||||
.sort((a, b) => a.pct - b.pct);
|
||||
|
||||
@@ -12,7 +12,8 @@ const path = require('path');
|
||||
const SRC_DIR = path.join(__dirname, '..', 'src');
|
||||
const LOCALES_DIR = path.join(__dirname, '..', 'src', 'i18n', 'locales');
|
||||
const load = (n) =>
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8')).translation;
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8'))
|
||||
.translation;
|
||||
const LANGS = require('./i18n_langs.cjs');
|
||||
const DICTS = LANGS.map((l) => [l, load(l)]);
|
||||
|
||||
@@ -25,7 +26,11 @@ function walk(dir, files = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (['node_modules', 'dist'].includes(entry.name) || entry.name.startsWith('.')) continue;
|
||||
if (
|
||||
['node_modules', 'dist'].includes(entry.name) ||
|
||||
entry.name.startsWith('.')
|
||||
)
|
||||
continue;
|
||||
walk(full, files);
|
||||
} else if (/\.(jsx?|tsx?)$/.test(entry.name)) files.push(full);
|
||||
}
|
||||
@@ -43,7 +48,9 @@ const COL_RE2 =
|
||||
const CJK = /[一-鿿]/;
|
||||
const rows = [];
|
||||
|
||||
for (const file of walk(SRC_DIR).filter((f) => !f.includes(path.join('src', 'i18n')))) {
|
||||
for (const file of walk(SRC_DIR).filter(
|
||||
(f) => !f.includes(path.join('src', 'i18n')),
|
||||
)) {
|
||||
const c = fs.readFileSync(file, 'utf8');
|
||||
const rel = path.relative(SRC_DIR, file);
|
||||
const push = (key, width) => {
|
||||
@@ -83,7 +90,9 @@ const uniq = rows.filter((r) => {
|
||||
return true;
|
||||
});
|
||||
|
||||
const perLang = LANGS.map((l) => `${l} ${uniq.filter((r) => r.lng === l).length}`).join(' / ');
|
||||
const perLang = LANGS.map(
|
||||
(l) => `${l} ${uniq.filter((r) => r.lng === l).length}`,
|
||||
).join(' / ');
|
||||
console.log(`固定列宽装不下译文的位置:${uniq.length} 处(${perLang})\n`);
|
||||
const LIMIT = Number(process.argv[2]) || 30; // 可传参查看全部
|
||||
for (const r of uniq.slice(0, LIMIT)) {
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
// 不传时保持历史行为(ko,th)。同一轮 batches → 回填 → build 必须用同一组语种,
|
||||
// 因为 kt_batches/ 按这组语种的「任一未译」切批。
|
||||
const arg = process.argv.find((a) => a.startsWith('--langs='));
|
||||
const raw = arg ? arg.slice('--langs='.length) : process.env.I18N_LANGS || 'ko,th';
|
||||
const raw = arg
|
||||
? arg.slice('--langs='.length)
|
||||
: process.env.I18N_LANGS || 'ko,th';
|
||||
|
||||
module.exports = raw
|
||||
.split(',')
|
||||
|
||||
@@ -17,13 +17,16 @@ let OpenCC;
|
||||
try {
|
||||
OpenCC = require(process.env.OPENCC_JS || 'opencc-js');
|
||||
} catch (e) {
|
||||
console.error('找不到 opencc-js:先 `npm i opencc-js`(可装在仓库外),再设置 OPENCC_JS 指向该包目录');
|
||||
console.error(
|
||||
'找不到 opencc-js:先 `npm i opencc-js`(可装在仓库外),再设置 OPENCC_JS 指向该包目录',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const LOCALES_DIR = path.join(__dirname, '..', 'src', 'i18n', 'locales');
|
||||
const load = (n) =>
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8')).translation;
|
||||
JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, `${n}.json`), 'utf8'))
|
||||
.translation;
|
||||
|
||||
// 转换前先钉住(作用在简体源上):OpenCC 会把 审核 与 审计 都转成「稽核」,
|
||||
// 转换后已无法区分,只能在源文本上先把 审核 定成繁体「審核」(OpenCC 不再改动繁体字)。
|
||||
@@ -71,14 +74,17 @@ for (const k of enKeys) {
|
||||
const src = zh[k] || k.replace(/_(zero|one|two|few|many|other)$/, '');
|
||||
const v = convert(src);
|
||||
// 占位符是 ASCII,转换不应动到;这里兜底校验,防止词典误伤插值名
|
||||
if (phList(v) !== phList(src)) problems.push(`${JSON.stringify(k)} 占位符被改动 -> ${JSON.stringify(v)}`);
|
||||
if (phList(v) !== phList(src))
|
||||
problems.push(`${JSON.stringify(k)} 占位符被改动 -> ${JSON.stringify(v)}`);
|
||||
out[k] = v;
|
||||
}
|
||||
|
||||
const ovPath = path.join(__dirname, 'zhtw_overrides.json');
|
||||
let overridden = 0;
|
||||
if (fs.existsSync(ovPath)) {
|
||||
for (const [k, v] of Object.entries(JSON.parse(fs.readFileSync(ovPath, 'utf8')))) {
|
||||
for (const [k, v] of Object.entries(
|
||||
JSON.parse(fs.readFileSync(ovPath, 'utf8')),
|
||||
)) {
|
||||
if (k.startsWith('_') || !v) continue;
|
||||
if (!(k in out)) {
|
||||
problems.push(`覆盖项 ${JSON.stringify(k)} 不在 en.json 中`);
|
||||
@@ -95,7 +101,9 @@ fs.writeFileSync(
|
||||
'utf8',
|
||||
);
|
||||
const changed = enKeys.filter((k) => out[k] !== (zh[k] || k)).length;
|
||||
console.log(`[zh-TW] keys=${enKeys.length} 与简体不同=${changed} 人工覆盖=${overridden}`);
|
||||
console.log(
|
||||
`[zh-TW] keys=${enKeys.length} 与简体不同=${changed} 人工覆盖=${overridden}`,
|
||||
);
|
||||
if (problems.length) {
|
||||
console.error(`[zh-TW] 异常 ${problems.length} 条:`);
|
||||
problems.slice(0, 30).forEach((p) => console.error(' ' + p));
|
||||
|
||||
+1946
-5836
File diff suppressed because it is too large
Load Diff
@@ -1833,4 +1833,4 @@
|
||||
"累计已用",
|
||||
"会员期间总消耗",
|
||||
"数据分析"
|
||||
]
|
||||
]
|
||||
|
||||
@@ -2284,4 +2284,4 @@
|
||||
"累计已用",
|
||||
"会员期间总消耗",
|
||||
"数据分析"
|
||||
]
|
||||
]
|
||||
|
||||
@@ -2354,4 +2354,4 @@
|
||||
"累计已用",
|
||||
"会员期间总消耗",
|
||||
"数据分析"
|
||||
]
|
||||
]
|
||||
|
||||
@@ -2285,4 +2285,4 @@
|
||||
"累计已用",
|
||||
"会员期间总消耗",
|
||||
"数据分析"
|
||||
]
|
||||
]
|
||||
|
||||
@@ -2287,4 +2287,4 @@
|
||||
"累计已用",
|
||||
"会员期间总消耗",
|
||||
"数据分析"
|
||||
]
|
||||
]
|
||||
|
||||
@@ -1884,4 +1884,4 @@
|
||||
"累计已用",
|
||||
"会员期间总消耗",
|
||||
"数据分析"
|
||||
]
|
||||
]
|
||||
|
||||
@@ -12,7 +12,7 @@ for (const lng of Object.keys(data.missingByLocale)) {
|
||||
fs.writeFileSync(
|
||||
path.join(OUT_DIR, `missing_keys_${lng}.json`),
|
||||
JSON.stringify(keys, null, 2),
|
||||
'utf8'
|
||||
'utf8',
|
||||
);
|
||||
console.log(`Wrote missing_keys_${lng}.json (${keys.length} keys)`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { readdir } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { spawn } from 'node:child_process';
|
||||
|
||||
export async function findUnitTests(root) {
|
||||
const files = [];
|
||||
async function visit(directory) {
|
||||
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
||||
const filename = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) await visit(filename);
|
||||
else if (entry.isFile() && /\.test\.[cm]?[jt]sx?$/.test(entry.name))
|
||||
files.push(filename);
|
||||
}
|
||||
}
|
||||
// Reports contain local browser capture tools and historical snapshots, not unit suites.
|
||||
for (const directory of ['src', 'tests', 'test/unit'])
|
||||
await visit(path.join(root, directory));
|
||||
return files.sort();
|
||||
}
|
||||
|
||||
if (
|
||||
process.argv[1] &&
|
||||
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
||||
) {
|
||||
const root = fileURLToPath(new URL('../', import.meta.url));
|
||||
const files = await findUnitTests(root);
|
||||
if (!files.length)
|
||||
throw new Error('No unit tests found in src/, tests/, or test/unit/.');
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
['--test', ...process.argv.slice(2), ...files],
|
||||
{
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
},
|
||||
);
|
||||
child.on('error', (error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
child.on('exit', (code) => {
|
||||
process.exitCode = code ?? 1;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import { readFile, mkdir, writeFile, copyFile, access } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { build } from 'esbuild';
|
||||
import { format } from 'prettier';
|
||||
|
||||
const root = fileURLToPath(new URL('../', import.meta.url));
|
||||
const source = path.resolve(
|
||||
root,
|
||||
process.argv[2] || 'node_modules/@lobehub/icons',
|
||||
);
|
||||
const upstream = JSON.parse(
|
||||
await readFile(path.join(source, 'package.json'), 'utf8'),
|
||||
);
|
||||
if (upstream.name !== '@lobehub/icons' || upstream.version !== '1.97.2') {
|
||||
throw new Error('Use the audited @lobehub/icons@1.97.2 source package.');
|
||||
}
|
||||
const brands = [
|
||||
'OpenAI',
|
||||
'Claude',
|
||||
'Gemini',
|
||||
'Moonshot',
|
||||
'Zhipu',
|
||||
'Qwen',
|
||||
'DeepSeek',
|
||||
'Minimax',
|
||||
'Wenxin',
|
||||
'Spark',
|
||||
'Midjourney',
|
||||
'Hunyuan',
|
||||
'Cohere',
|
||||
'Cloudflare',
|
||||
'Ai360',
|
||||
'Yi',
|
||||
'Jina',
|
||||
'Mistral',
|
||||
'XAI',
|
||||
'Ollama',
|
||||
'Doubao',
|
||||
'Suno',
|
||||
'Xinference',
|
||||
'OpenRouter',
|
||||
'Dify',
|
||||
'Coze',
|
||||
'SiliconCloud',
|
||||
'Kling',
|
||||
'Perplexity',
|
||||
'Replicate',
|
||||
];
|
||||
const external = new Set(['react', 'react/jsx-runtime']);
|
||||
const entries = [];
|
||||
const primitiveEntries = [];
|
||||
for (const brand of brands) {
|
||||
entries.push(`export { default as ${brand} } from './es/${brand}/index.js';`);
|
||||
for (const variant of ['Mono', 'Color']) {
|
||||
const modulePath = `./es/${brand}/components/${variant}.js`;
|
||||
try {
|
||||
await access(path.join(source, modulePath));
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
primitiveEntries.push(
|
||||
`export { default as ${brand}${variant} } from '${modulePath}';`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const result = await build({
|
||||
absWorkingDir: source,
|
||||
entryPoints: { lobehub: 'brand:variants', primitives: 'brand:primitives' },
|
||||
outdir: path.join(root, 'src/assets/brand-icons'),
|
||||
splitting: true,
|
||||
chunkNames: 'shared-[hash]',
|
||||
bundle: true,
|
||||
write: false,
|
||||
metafile: true,
|
||||
format: 'esm',
|
||||
target: 'es2015',
|
||||
minifySyntax: true,
|
||||
plugins: [
|
||||
{
|
||||
name: 'brand-primitives-only',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^brand:/ }, ({ path }) => ({
|
||||
path,
|
||||
namespace: 'brand',
|
||||
}));
|
||||
build.onLoad(
|
||||
{ filter: /.*/, namespace: 'brand' },
|
||||
({ path: name }) => ({
|
||||
contents: (name === 'brand:variants'
|
||||
? entries
|
||||
: primitiveEntries
|
||||
).join('\n'),
|
||||
resolveDir: source,
|
||||
}),
|
||||
);
|
||||
build.onResolve(
|
||||
{ filter: /features\/Icon(Avatar|Combine)$/ },
|
||||
({ path: name }) => ({
|
||||
path: `../../components/common/brand-icons/${path.basename(name)}.jsx`,
|
||||
external: true,
|
||||
}),
|
||||
);
|
||||
build.onResolve({ filter: /^[^./]/ }, ({ path: name }) => {
|
||||
if (name === 'antd-style')
|
||||
return {
|
||||
path: '../../components/common/brand-icons/useThemeMode.js',
|
||||
external: true,
|
||||
};
|
||||
if (!external.has(name))
|
||||
throw new Error(`Unexpected icon dependency: ${name}`);
|
||||
return { path: name, external: true };
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
const output = path.join(root, 'src/assets/brand-icons');
|
||||
await mkdir(output, { recursive: true });
|
||||
const files = {};
|
||||
for (const file of result.outputFiles) {
|
||||
const code = await format(
|
||||
'// Generated from @lobehub/icons@1.97.2. See LICENSE and README.md.\n' +
|
||||
file.text,
|
||||
{ parser: 'babel', singleQuote: true },
|
||||
);
|
||||
await writeFile(file.path, code);
|
||||
files[path.basename(file.path)] = createHash('sha256')
|
||||
.update(code)
|
||||
.digest('hex');
|
||||
}
|
||||
await copyFile(path.join(source, 'LICENSE'), path.join(output, 'LICENSE'));
|
||||
await writeFile(
|
||||
path.join(output, 'manifest.json'),
|
||||
JSON.stringify(
|
||||
{
|
||||
source: '@lobehub/icons',
|
||||
version: upstream.version,
|
||||
license: upstream.license,
|
||||
brands,
|
||||
moduleCount: Object.keys(result.metafile.inputs).filter(
|
||||
(name) => !name.startsWith('brand:'),
|
||||
).length,
|
||||
files,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + '\n',
|
||||
);
|
||||
console.log(
|
||||
`Vendored ${brands.length} brands in ${Object.keys(files).length} modules.`,
|
||||
);
|
||||
Reference in New Issue
Block a user