chore: update token-meta structure

This commit is contained in:
MadCcc 2022-12-01 20:52:35 +08:00
parent 705575a2af
commit da097e63bf
2 changed files with 23 additions and 7 deletions

View File

@ -102,12 +102,14 @@ const TokenTable: FC<TokenTableProps> = ({ type }) => {
const data = useMemo<TokenData[]>(
() =>
tokenMeta[type].map((token) => ({
name: token.token,
desc: lang === 'cn' ? token.desc : token.descEn,
type: token.type,
value: (defaultToken as any)[token.name],
})),
Object.entries(tokenMeta)
.filter(([, meta]) => meta.source === type)
.map(([token, meta]) => ({
name: token,
desc: lang === 'cn' ? meta.desc : meta.descEn,
type: meta.type,
value: (defaultToken as any)[token],
})),
[type, lang],
);

View File

@ -65,7 +65,21 @@ function main() {
(item) => !tokenMeta.seed.some((seedItem) => seedItem.token === item.token),
);
fs.writeJsonSync(output, tokenMeta, 'utf8');
const finalMeta = Object.entries(tokenMeta).reduce((acc, [key, value]) => {
value.forEach((item) => {
acc[item.token] = {
name: item.name,
nameEn: item.nameEn,
desc: item.desc,
descEn: item.descEn,
type: item.type,
source: key,
};
});
return acc;
}, {});
fs.writeJsonSync(output, finalMeta, 'utf8');
// eslint-disable-next-line no-console
console.log(`✅ Token Meta has been written to ${output}`);
}