|
@@ -0,0 +1,118 @@
|
|
|
+import { Request, Response } from "express";
|
|
|
+import { HttpMethod, Route, StatusCodes } from "org.crazydoctor.expressts";
|
|
|
+import ServerApp from "..";
|
|
|
+import { ClassMapEntity, PackageEntity, Sources } from "../sources/Sources";
|
|
|
+import { CommentsManager } from "../comments/CommentsManager";
|
|
|
+
|
|
|
+type DocumentedClassInfo = {
|
|
|
+ documentable: number,
|
|
|
+ documented: number
|
|
|
+};
|
|
|
+
|
|
|
+type DocumentedPackageInfo = DocumentedClassInfo & {
|
|
|
+ children?: { [key: string]: DocumentedPackageInfo }
|
|
|
+};
|
|
|
+
|
|
|
+class GetDocumentedInfo extends Route {
|
|
|
+ protected action = (req: Request, res: Response) => {
|
|
|
+ const params = req.body;
|
|
|
+
|
|
|
+ if(ServerApp.SourcesUpdating) {
|
|
|
+ res.status(StatusCodes.ACCEPTED).render('sources-update');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const root = params.root;
|
|
|
+ const packageName = params.packageName;
|
|
|
+ const className = params.className;
|
|
|
+
|
|
|
+ const cls: ClassMapEntity | null = Sources.findClass(className);
|
|
|
+ const pck: PackageEntity | null = Sources.findPackage(root, packageName);
|
|
|
+
|
|
|
+ if(!root && !packageName && !className) {
|
|
|
+ this.getRootsDocumentedInfo().then((result) => {
|
|
|
+ res.status(StatusCodes.OK).type('application/json').send(JSON.stringify(result));
|
|
|
+ });
|
|
|
+ } else if(!cls && !pck) {
|
|
|
+ res.status(StatusCodes.NOT_FOUND).type('application/json').send({ success: false });
|
|
|
+ } else if(cls) {
|
|
|
+ this.getClassDocumentedInfo(cls).then((result) => {
|
|
|
+ res.status(StatusCodes.OK).type('application/json').send(JSON.stringify(result));
|
|
|
+ });
|
|
|
+ } else if(pck) {
|
|
|
+ this.getPackageDocumentedInfo(pck).then((result) => {
|
|
|
+ res.status(StatusCodes.OK).type('application/json').send(JSON.stringify(result));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ private async getRootsDocumentedInfo(): Promise<{ [key: string]: DocumentedClassInfo }> {
|
|
|
+ const roots = Sources.getRepoNames();
|
|
|
+ const result: { [key: string]: DocumentedClassInfo } = {};
|
|
|
+
|
|
|
+ for(let root of roots) {
|
|
|
+ let sumDocumentable = 0;
|
|
|
+ let sumDocumented = 0;
|
|
|
+ const classes = Sources.findClassesByRoot(root);
|
|
|
+
|
|
|
+ if(!classes)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ for(let cls of classes) {
|
|
|
+ const res = await this.getClassDocumentedInfo(cls);
|
|
|
+ sumDocumentable += res.documentable;
|
|
|
+ sumDocumented += res.documented;
|
|
|
+ }
|
|
|
+
|
|
|
+ result[root] = { documented: sumDocumented, documentable: sumDocumentable };
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async getPackageDocumentedInfo(pck: PackageEntity): Promise<DocumentedPackageInfo> {
|
|
|
+ const results: Map<string, DocumentedPackageInfo> = new Map();
|
|
|
+
|
|
|
+ let sumDocumentable = 0;
|
|
|
+ let sumDocumented = 0;
|
|
|
+
|
|
|
+ const promises = pck.children.map(async (child) => {
|
|
|
+ const found = Sources.findClass(child);
|
|
|
+ if(found) {
|
|
|
+ const result = await this.getClassDocumentedInfo(found);
|
|
|
+ results.set(child, result);
|
|
|
+ sumDocumentable += result.documentable;
|
|
|
+ sumDocumented += result.documented;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ await Promise.all(promises);
|
|
|
+
|
|
|
+ return { documented: sumDocumented, documentable: sumDocumentable, children: Object.fromEntries(results) };
|
|
|
+ }
|
|
|
+
|
|
|
+ private async getClassDocumentedInfo(cls: ClassMapEntity): Promise<DocumentedClassInfo> {
|
|
|
+ const excludeList = ['callParent', 'newInstance'];
|
|
|
+ let documentable = cls.documentableProperties;
|
|
|
+ let documented = 0;
|
|
|
+
|
|
|
+ const commentsResult = await CommentsManager.getCommentsByClass(cls.root, cls.name);
|
|
|
+
|
|
|
+ if(!commentsResult.success)
|
|
|
+ return { documentable: 0, documented: 0 };
|
|
|
+
|
|
|
+ commentsResult.comments?.forEach((comment) => {
|
|
|
+ if(comment.text && comment.text.length > 0 && !excludeList.includes(comment.propertyName))
|
|
|
+ documented++;
|
|
|
+ });
|
|
|
+
|
|
|
+ return { documentable, documented }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected method = HttpMethod.POST;
|
|
|
+ protected order = 10;
|
|
|
+ protected route = '/docinfo';
|
|
|
+}
|
|
|
+
|
|
|
+export default GetDocumentedInfo;
|