You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.4 KiB
104 lines
3.4 KiB
2 years ago
|
import fs from 'fs-extra';
|
||
|
import type { DeclarationReflection } from 'typedoc';
|
||
|
import { Application, TSConfigReader, TypeDocReader } from 'typedoc';
|
||
2 years ago
|
|
||
2 years ago
|
function getTokenList(list?: DeclarationReflection[], source?: string) {
|
||
|
return (list || [])
|
||
2 years ago
|
.filter(
|
||
|
(item) =>
|
||
|
!item.comment?.blockTags.some((tag) => tag.tag === '@internal' || tag.tag === '@private'),
|
||
|
)
|
||
2 years ago
|
.map((item) => ({
|
||
|
source,
|
||
2 years ago
|
token: item.name,
|
||
2 years ago
|
type: item?.type?.toString(),
|
||
2 years ago
|
desc:
|
||
|
item.comment?.blockTags
|
||
|
?.find((tag) => tag.tag === '@desc')
|
||
2 years ago
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
||
2 years ago
|
descEn:
|
||
2 years ago
|
item.comment?.blockTags
|
||
|
?.find((tag) => tag.tag === '@descEN')
|
||
2 years ago
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
||
2 years ago
|
name:
|
||
|
item.comment?.blockTags
|
||
|
?.find((tag) => tag.tag === '@nameZH')
|
||
2 years ago
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
||
2 years ago
|
nameEn:
|
||
2 years ago
|
item.comment?.blockTags
|
||
|
?.find((tag) => tag.tag === '@nameEN')
|
||
2 years ago
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
||
2 years ago
|
}));
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
const main = () => {
|
||
|
const app = new Application();
|
||
2 years ago
|
|
||
|
// If you want TypeDoc to load tsconfig.json / typedoc.json files
|
||
2 years ago
|
app.options.addReader(new TSConfigReader());
|
||
|
app.options.addReader(new TypeDocReader());
|
||
2 years ago
|
|
||
|
app.bootstrap({
|
||
|
// typedoc options here
|
||
2 years ago
|
entryPoints: ['components/theme/interface/index.ts'],
|
||
2 years ago
|
});
|
||
|
|
||
|
const project = app.convert();
|
||
|
|
||
|
if (project) {
|
||
|
// Project may not have converted correctly
|
||
|
const output = 'components/version/token-meta.json';
|
||
2 years ago
|
const tokenMeta: Record<PropertyKey, ReturnType<typeof getTokenList>> = {};
|
||
|
let presetColors: string[] = [];
|
||
|
project.children?.forEach((type) => {
|
||
2 years ago
|
if (type.name === 'SeedToken') {
|
||
|
tokenMeta.seed = getTokenList(type.children, 'seed');
|
||
|
} else if (type.name === 'MapToken') {
|
||
|
tokenMeta.map = getTokenList(type.children, 'map');
|
||
|
} else if (type.name === 'AliasToken') {
|
||
|
tokenMeta.alias = getTokenList(type.children, 'alias');
|
||
|
} else if (type.name === 'PresetColors') {
|
||
2 years ago
|
presetColors = (type?.type as any)?.target?.elements?.map((item: any) => item.value);
|
||
2 years ago
|
}
|
||
|
});
|
||
|
|
||
|
// Exclude preset colors
|
||
|
tokenMeta.seed = tokenMeta.seed.filter(
|
||
2 years ago
|
(item) => !presetColors.some((color) => item.token.startsWith(color)),
|
||
2 years ago
|
);
|
||
|
tokenMeta.map = tokenMeta.map.filter(
|
||
2 years ago
|
(item) => !presetColors.some((color) => item.token.startsWith(color)),
|
||
2 years ago
|
);
|
||
|
tokenMeta.alias = tokenMeta.alias.filter(
|
||
2 years ago
|
(item) => !presetColors.some((color) => item.token.startsWith(color)),
|
||
2 years ago
|
);
|
||
|
|
||
|
tokenMeta.alias = tokenMeta.alias.filter(
|
||
2 years ago
|
(item) => !tokenMeta.map.some((mapItem) => mapItem.token === item.token),
|
||
2 years ago
|
);
|
||
|
tokenMeta.map = tokenMeta.map.filter(
|
||
2 years ago
|
(item) => !tokenMeta.seed.some((seedItem) => seedItem.token === item.token),
|
||
2 years ago
|
);
|
||
|
|
||
2 years ago
|
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;
|
||
2 years ago
|
}, {} as any);
|
||
2 years ago
|
|
||
|
fs.writeJsonSync(output, finalMeta, 'utf8');
|
||
2 years ago
|
// eslint-disable-next-line no-console
|
||
|
console.log(`✅ Token Meta has been written to ${output}`);
|
||
|
}
|
||
2 years ago
|
};
|
||
2 years ago
|
|
||
|
main();
|