gem-analyzer
Advanced tools
Comparing version 1.7.0 to 1.7.1
import type { SourceFile, ClassDeclaration } from 'ts-morph'; | ||
interface StaticProperty { | ||
name: string; | ||
deprecated?: boolean; | ||
slot?: string; | ||
@@ -11,2 +12,3 @@ part?: string; | ||
name: string; | ||
deprecated?: boolean; | ||
type?: string; | ||
@@ -18,2 +20,3 @@ description?: string; | ||
reactive: boolean; | ||
deprecated?: boolean; | ||
attribute?: string; | ||
@@ -31,2 +34,3 @@ slot?: string; | ||
name: string; | ||
deprecated?: boolean; | ||
event?: string; | ||
@@ -60,3 +64,11 @@ isGlobalEvent?: boolean; | ||
export declare const getElements: (file: SourceFile) => ElementDetail[]; | ||
export interface ExportDetail { | ||
name: string; | ||
kindName: string; | ||
type: string; | ||
deprecated?: boolean; | ||
description?: string; | ||
} | ||
export declare const getExports: (file: SourceFile) => ExportDetail[]; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
87
index.js
import { camelToKebabCase } from '@mantou/gem/lib/utils'; | ||
import { getJsDoc } from './lib/utils'; | ||
const elementDecoratorName = ['customElement']; | ||
@@ -34,22 +35,24 @@ const attrDecoratorName = ['attribute', 'boolattribute', 'numattribute']; | ||
declaration.getJsDocs().forEach((jsDoc) => appendElementDesc(jsDoc.getCommentText())); | ||
if (constructor && className && constructorExtendsName) { | ||
const params = {}; | ||
const jsDocs = constructor.getJsDocs(); | ||
jsDocs.forEach((jsDoc) => { | ||
appendElementDesc(jsDoc.getDescription()); | ||
jsDoc | ||
.getTags() | ||
.map((tag) => ({ tagName: tag.getTagName(), name: tag.getName(), comment: tag.getCommentText() })) | ||
.filter(({ tagName, comment, name }) => tagName === 'param' && comment && name) | ||
.forEach(({ name, comment }) => { | ||
params[name] = comment; | ||
}); | ||
}); | ||
if (className && constructorExtendsName) { | ||
detail.constructorName = className; | ||
detail.constructorExtendsName = constructorExtendsName; | ||
detail.constructorParams = constructor.getParameters().map((param) => ({ | ||
name: param.getName(), | ||
type: param.getType().getText(), | ||
description: params[param.getName()], | ||
})); | ||
if (constructor) { | ||
const params = {}; | ||
const jsDocs = constructor.getJsDocs(); | ||
jsDocs.forEach((jsDoc) => { | ||
appendElementDesc(jsDoc.getDescription()); | ||
jsDoc | ||
.getTags() | ||
.map((tag) => ({ tagName: tag.getTagName(), name: tag.getName(), comment: tag.getCommentText() })) | ||
.filter(({ tagName, comment, name }) => tagName === 'param' && comment && name) | ||
.forEach(({ name, comment }) => { | ||
params[name] = comment; | ||
}); | ||
}); | ||
detail.constructorParams = constructor.getParameters().map((param) => ({ | ||
name: param.getName(), | ||
type: param.getType().getText(), | ||
description: params[param.getName()], | ||
})); | ||
} | ||
} | ||
@@ -64,6 +67,3 @@ const staticPropertiesDeclarations = declaration.getStaticProperties(); | ||
type: staticPropDeclaration.getType().getText(), | ||
description: staticPropDeclaration | ||
.getJsDocs() | ||
.map((jsDoc) => jsDoc.getCommentText()) | ||
.join('\n\n') || undefined, | ||
...getJsDoc(staticPropDeclaration), | ||
}; | ||
@@ -97,6 +97,3 @@ let isPartOrSlot = false; | ||
type: staticMethodDeclaration.getType().getText(), | ||
description: staticMethodDeclaration | ||
.getJsDocs() | ||
.map((jsDoc) => jsDoc.getCommentText()) | ||
.join('\n\n') || undefined, | ||
...getJsDoc(staticMethodDeclaration), | ||
}; | ||
@@ -116,8 +113,3 @@ detail.staticMethods.push(method); | ||
type: propDeclaration.getType().getText(), | ||
description: ('getJsDocs' in propDeclaration && | ||
propDeclaration | ||
.getJsDocs() | ||
.map((jsDoc) => jsDoc.getCommentText()) | ||
.join('\n\n')) || | ||
undefined, | ||
...getJsDoc(propDeclaration), | ||
}; | ||
@@ -170,6 +162,3 @@ detail.properties.push(prop); | ||
type: methodDeclaration.getType().getText(), | ||
description: methodDeclaration | ||
.getJsDocs() | ||
.map((jsDoc) => jsDoc.getCommentText()) | ||
.join('\n\n') || undefined, | ||
...getJsDoc(methodDeclaration), | ||
}; | ||
@@ -213,2 +202,28 @@ detail.methods.push(method); | ||
}; | ||
export const getExports = (file) => { | ||
const result = []; | ||
for (const [name, declarations] of file.getExportedDeclarations()) { | ||
let deprecated = false; | ||
let description = ''; | ||
declarations.forEach((declaration) => { | ||
// 只支持 1 份有效的 jsDoc | ||
const jsDoc = getJsDoc(declaration); | ||
if ((jsDoc === null || jsDoc === void 0 ? void 0 : jsDoc.deprecated) || (jsDoc === null || jsDoc === void 0 ? void 0 : jsDoc.description)) { | ||
deprecated = jsDoc.deprecated; | ||
description = jsDoc.description; | ||
} | ||
}); | ||
result.push({ | ||
name, | ||
kindName: declarations[0].getKindName(), | ||
type: declarations | ||
.map((declaration) => declaration.getType().getText()) | ||
.filter((e) => !!e) | ||
.join(';'), | ||
deprecated, | ||
description, | ||
}); | ||
} | ||
return result; | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "gem-analyzer", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "gem analyzer", | ||
"main": "index.js", | ||
"files": [ | ||
"/lib", | ||
"/index.*" | ||
@@ -15,3 +16,3 @@ ], | ||
"dependencies": { | ||
"@mantou/gem": "^1.7.0" | ||
"@mantou/gem": "^1.7.2" | ||
}, | ||
@@ -21,3 +22,3 @@ "devDependencies": { | ||
"ts-morph": "^13.0.0", | ||
"typescript": "^4.5.0" | ||
"typescript": "^5.3.2" | ||
}, | ||
@@ -24,0 +25,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23707
10
310
Updated@mantou/gem@^1.7.2