mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
refactor: adjust code to new configuration
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
*/
|
||||
import {asyncPool} from '@krlwlfrt/async-pool';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {basename, dirname, join} from 'path';
|
||||
import {ProjectReflection} from 'typedoc';
|
||||
import {Type} from 'typedoc/dist/lib/models';
|
||||
import {NodesWithMetaInformation, NodeWithMetaInformation, RouteWithMetaInformation} from './common';
|
||||
|
||||
/**
|
||||
@@ -32,17 +34,20 @@ export async function gatherRouteInformation(reflection: ProjectReflection): Pro
|
||||
throw new Error('Project reflection doesn\'t contain any modules.');
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
await asyncPool(2, reflection.children, async (module) => {
|
||||
if (Array.isArray(module.children) && module.children.length > 0) {
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
await asyncPool(2, module.children, (async (node) => {
|
||||
if (Array.isArray(node.extendedTypes) && node.extendedTypes.length > 0) {
|
||||
if (node.extendedTypes.some((extendedType) => {
|
||||
return (extendedType as any).name === 'SCAbstractRoute';
|
||||
// tslint:disable-next-line:completed-docs
|
||||
return (extendedType as (Type & { name: string; })).name === 'SCAbstractRoute';
|
||||
})) {
|
||||
Logger.info(`Found ${node.name} in ${module.originalName}.`);
|
||||
|
||||
if (module.originalName.match(/\.d\.ts$/)) {
|
||||
module.originalName = module.originalName.substr(0, module.originalName.length - 5);
|
||||
if (Array.isArray(module.originalName.match(/\.d\.ts$/))) {
|
||||
module.originalName = join(dirname(module.originalName), basename(module.originalName, '.d.ts'));
|
||||
Logger.info(`Using compiled version of module in ${module.originalName}.`);
|
||||
}
|
||||
|
||||
@@ -71,17 +76,18 @@ export async function gatherRouteInformation(reflection: ProjectReflection): Pro
|
||||
* @param node Node itself
|
||||
* @param humanize Whether to humanize the name or not
|
||||
*/
|
||||
export function getLinkedNameForNode(name: string, node: NodeWithMetaInformation, humanize: boolean = false): string {
|
||||
export function getLinkedNameForNode(name: string, node: NodeWithMetaInformation, humanize = false): string {
|
||||
const humanizeString = require('humanize-string');
|
||||
|
||||
let printableName = name;
|
||||
|
||||
if (humanize) {
|
||||
printableName = humanizeString(name.substr(2));
|
||||
printableName = humanizeString(name.substr('SC'.length));
|
||||
}
|
||||
|
||||
let link = `[${printableName}]`;
|
||||
link += `(${getLinkForNode(name, node)})`;
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
@@ -93,12 +99,16 @@ export function getLinkedNameForNode(name: string, node: NodeWithMetaInformation
|
||||
*/
|
||||
export function getLinkForNode(name: string, node: NodeWithMetaInformation): string {
|
||||
let link = 'https://openstapps.gitlab.io/core/';
|
||||
const module = node.module.toLowerCase().split('/').join('_');
|
||||
const module = node.module
|
||||
.toLowerCase()
|
||||
.split('/')
|
||||
.join('_');
|
||||
|
||||
if (node.type === 'Type alias') {
|
||||
link += 'modules/';
|
||||
link += `_${module}_`;
|
||||
link += `.html#${name.toLowerCase()}`;
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
@@ -110,6 +120,7 @@ export function getLinkForNode(name: string, node: NodeWithMetaInformation): str
|
||||
link += `${type}/`;
|
||||
link += `_${module}_`;
|
||||
link += `.${name.toLowerCase()}.html`;
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
@@ -117,7 +128,7 @@ export function getLinkForNode(name: string, node: NodeWithMetaInformation): str
|
||||
* Generate documentation snippet for one route
|
||||
*
|
||||
* @param routeWithInfo A route instance with its meta information
|
||||
* @param nodes
|
||||
* @param nodes Nodes with meta information
|
||||
*/
|
||||
export function generateDocumentationForRoute(routeWithInfo: RouteWithMetaInformation,
|
||||
nodes: NodesWithMetaInformation): string {
|
||||
@@ -143,14 +154,20 @@ export function generateDocumentationForRoute(routeWithInfo: RouteWithMetaInform
|
||||
| request | ${getLinkedNameForNode(route.requestBodyName, nodes[route.requestBodyName])} |
|
||||
| response | ${getLinkedNameForNode(route.responseBodyName, nodes[route.responseBodyName])} |
|
||||
| success code | ${route.statusCodeSuccess} |
|
||||
| errors | ${route.errorNames.map((error) => {
|
||||
return getLinkedNameForNode(error.name, nodes[error.name]);
|
||||
}).join('<br>')} |
|
||||
| errors | ${route.errorNames
|
||||
.map((error) => {
|
||||
return getLinkedNameForNode(error.name, nodes[error.name]);
|
||||
})
|
||||
.join('<br>')} |
|
||||
`;
|
||||
if (typeof route.obligatoryParameters === 'object' && Object.keys(route.obligatoryParameters).length > 0) {
|
||||
let parameterTable = '<table><tr><th>parameter</th><th>type</th></tr>';
|
||||
|
||||
Object.keys(route.obligatoryParameters).forEach((parameter) => {
|
||||
for (const parameter in route.obligatoryParameters) {
|
||||
if (!route.obligatoryParameters.hasOwnProperty(parameter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let type = route.obligatoryParameters![parameter];
|
||||
|
||||
if (typeof nodes[type] !== 'undefined') {
|
||||
@@ -158,7 +175,7 @@ export function generateDocumentationForRoute(routeWithInfo: RouteWithMetaInform
|
||||
}
|
||||
|
||||
parameterTable += `<tr><td>${parameter}</td><td>${type}</td></tr>`;
|
||||
});
|
||||
}
|
||||
|
||||
parameterTable += '</table>';
|
||||
|
||||
@@ -182,14 +199,14 @@ export function getNodeMetaInformationMap(projectReflection: ProjectReflection):
|
||||
}
|
||||
|
||||
// iterate over modules
|
||||
projectReflection.children.forEach((module: any) => {
|
||||
projectReflection.children.forEach((module) => {
|
||||
if (Array.isArray(module.children) && module.children.length > 0) {
|
||||
// iterate over types
|
||||
module.children.forEach((node: any) => {
|
||||
module.children.forEach((node) => {
|
||||
// add node with module and type
|
||||
nodes[node.name] = {
|
||||
module: module.name.substring(1, module.name.length - 1),
|
||||
type: node.kindString,
|
||||
type: node.kindString!,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user