2022-11-25 14:23:11 +08:00
|
|
|
const TypeDoc = require('typedoc');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
const getTokenList = (list, source) =>
|
|
|
|
list
|
2022-12-26 10:54:53 +08:00
|
|
|
.filter(
|
|
|
|
(item) =>
|
|
|
|
!item.comment?.blockTags.some((tag) => tag.tag === '@internal' || tag.tag === '@private'),
|
|
|
|
)
|
2022-11-25 14:23:11 +08:00
|
|
|
.map((item) => ({
|
|
|
|
source,
|
2022-11-30 11:48:47 +08:00
|
|
|
token: item.name,
|
2022-11-25 14:23:11 +08:00
|
|
|
type: item.type.toString(),
|
2022-12-02 14:18:14 +08:00
|
|
|
desc:
|
|
|
|
item.comment?.blockTags
|
|
|
|
?.find((tag) => tag.tag === '@desc')
|
2022-12-07 20:22:15 +08:00
|
|
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
2022-11-25 14:23:11 +08:00
|
|
|
descEn:
|
2022-12-02 14:18:14 +08:00
|
|
|
item.comment?.blockTags
|
|
|
|
?.find((tag) => tag.tag === '@descEN')
|
2022-12-07 20:22:15 +08:00
|
|
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
2022-12-02 14:18:14 +08:00
|
|
|
name:
|
|
|
|
item.comment?.blockTags
|
|
|
|
?.find((tag) => tag.tag === '@nameZH')
|
2022-12-07 20:22:15 +08:00
|
|
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
2022-11-30 11:48:47 +08:00
|
|
|
nameEn:
|
2022-12-02 14:18:14 +08:00
|
|
|
item.comment?.blockTags
|
|
|
|
?.find((tag) => tag.tag === '@nameEN')
|
2022-12-07 20:22:15 +08:00
|
|
|
?.content.reduce((result, str) => result.concat(str.text), '') || '',
|
2022-11-25 14:23:11 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
const app = new TypeDoc.Application();
|
|
|
|
|
|
|
|
// If you want TypeDoc to load tsconfig.json / typedoc.json files
|
|
|
|
app.options.addReader(new TypeDoc.TSConfigReader());
|
|
|
|
app.options.addReader(new TypeDoc.TypeDocReader());
|
|
|
|
|
|
|
|
app.bootstrap({
|
|
|
|
// typedoc options here
|
2022-11-30 11:48:47 +08:00
|
|
|
entryPoints: ['components/theme/interface/index.ts'],
|
2022-11-25 14:23:11 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const project = app.convert();
|
|
|
|
|
|
|
|
if (project) {
|
|
|
|
// Project may not have converted correctly
|
|
|
|
const output = 'components/version/token-meta.json';
|
|
|
|
const tokenMeta = {};
|
|
|
|
let presetColors = [];
|
|
|
|
project.children.forEach((type) => {
|
|
|
|
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') {
|
|
|
|
presetColors = type.type.target.elements.map((item) => item.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Exclude preset colors
|
|
|
|
tokenMeta.seed = tokenMeta.seed.filter(
|
2022-11-30 11:48:47 +08:00
|
|
|
(item) => !presetColors.some((color) => item.token.startsWith(color)),
|
2022-11-25 14:23:11 +08:00
|
|
|
);
|
|
|
|
tokenMeta.map = tokenMeta.map.filter(
|
2022-11-30 11:48:47 +08:00
|
|
|
(item) => !presetColors.some((color) => item.token.startsWith(color)),
|
2022-11-25 14:23:11 +08:00
|
|
|
);
|
|
|
|
tokenMeta.alias = tokenMeta.alias.filter(
|
2022-11-30 11:48:47 +08:00
|
|
|
(item) => !presetColors.some((color) => item.token.startsWith(color)),
|
2022-11-25 14:23:11 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
tokenMeta.alias = tokenMeta.alias.filter(
|
2022-11-30 11:48:47 +08:00
|
|
|
(item) => !tokenMeta.map.some((mapItem) => mapItem.token === item.token),
|
2022-11-25 14:23:11 +08:00
|
|
|
);
|
|
|
|
tokenMeta.map = tokenMeta.map.filter(
|
2022-11-30 11:48:47 +08:00
|
|
|
(item) => !tokenMeta.seed.some((seedItem) => seedItem.token === item.token),
|
2022-11-25 14:23:11 +08:00
|
|
|
);
|
|
|
|
|
2022-12-01 20:52:35 +08:00
|
|
|
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');
|
2022-11-25 14:23:11 +08:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(`✅ Token Meta has been written to ${output}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|