chore: 类型生成器增加注释支持

pull/49/head
moonrailgun 3 years ago
parent 7d90a1160e
commit b5bf323601

@ -14,6 +14,7 @@ export interface ExportModuleItem {
export interface DeclarationModuleItem {
name: string;
text: string;
comment?: string;
pos?: number;
}
@ -38,12 +39,25 @@ export function parseModuleDeclaration(
node.body.forEachChild((item) => {
if (ts.isVariableStatement(item)) {
let comment: string | undefined = undefined;
const commentRange = ts.getLeadingCommentRanges(
sourceFile.getFullText(),
item.pos
);
if (Array.isArray(commentRange) && commentRange.length > 0) {
comment = '';
commentRange.map(({ pos, end }) => {
comment += sourceFile.text.substring(pos, end);
});
}
item.declarationList.declarations.forEach((declaration) => {
const name = declaration.name.getText();
const pos = declaration.pos;
modules[moduleName].push({
name,
text: declaration.getText(),
comment,
pos,
});
});

@ -17,7 +17,9 @@ function exportModulesTemplate(
.map((item) => {
const findedModule = existedModules.find((m) => m.name === item.name);
if (findedModule) {
return `export const ${findedModule.text};`;
return `${
findedModule.comment ? findedModule.comment + '\n ' : ''
}export const ${findedModule.text};`;
} else {
return `export const ${item.name}: any;`;
}
@ -66,7 +68,6 @@ declare module '@capital/common' {
)}
}
/**
* Tailchat
*/

25
web/tailchat.d.ts vendored

@ -12,7 +12,30 @@
declare module '@capital/common' {
export const useGroupPanelParams: any;
export const openModal: any;
/**
*
*/
export const openModal: (
content: React.ReactNode,
props?: {
/**
*
* @default false
*/
closable?: boolean;
/**
*
*/
maskClosable?: boolean;
/**
* modal
*/
onCloseModal?: () => void;
}
) => number;
export const closeModal: any;

Loading…
Cancel
Save