feat: add the uml generator

This commit is contained in:
Michel Jonathan Schmitz
2019-05-27 13:10:41 +02:00
parent a9c0fddb23
commit 0f21da4a92
24 changed files with 2310 additions and 96 deletions

View File

@@ -16,10 +16,22 @@ import {Logger} from '@openstapps/logger';
import * as commander from 'commander';
import {existsSync, readFileSync, writeFileSync} from 'fs';
import {join, resolve} from 'path';
import {getProjectReflection, mkdirPromisified, readFilePromisified} from './common';
import {
getProjectReflection,
mkdirPromisified,
readFilePromisified,
toArray,
} from './common';
import {pack} from './pack';
import {gatherRouteInformation, generateDocumentationForRoute, getNodeMetaInformationMap} from './routes';
import {
gatherRouteInformation,
generateDocumentationForRoute,
getNodeMetaInformationMap,
} from './routes';
import {Converter, getValidatableTypesFromReflection} from './schema';
import {createDiagram, createDiagramFromString} from './uml/createDiagram';
import {readDefinitions} from './uml/readDefinitions';
import {UMLConfig} from './uml/umlConfig';
import {validateFiles, writeReport} from './validate';
// handle unhandled promise rejections
@@ -53,7 +65,10 @@ commander
// generate documentation for all routes
routes.forEach((routeWithMetaInformation) => {
output += generateDocumentationForRoute(routeWithMetaInformation, getNodeMetaInformationMap(projectReflection));
output += generateDocumentationForRoute(
routeWithMetaInformation,
getNodeMetaInformationMap(projectReflection),
);
});
// write documentation to file
@@ -76,7 +91,9 @@ commander
const projectReflection = getProjectReflection(srcPath);
// get validatable types
const validatableTypes = getValidatableTypesFromReflection(projectReflection);
const validatableTypes = getValidatableTypesFromReflection(
projectReflection,
);
Logger.info(`Found ${validatableTypes.length} type(s) to generate schemas for.`);
@@ -152,14 +169,85 @@ commander
}
});
commander.command('pack').action(async () => {
await pack();
});
commander
.command('pack')
.action(async () => {
await pack();
.command('plantuml <srcPath> <plantumlserver>')
.option(
'--definitions <definitions>',
'Shows these specific definitions (class or enum)',
toArray,
)
.option('--showAssociations', 'Shows associations of classes')
.option(
'--showInheritance',
'Shows extensions and implementations of classes',
)
.option('--showEnumValues', 'Show enum values')
.option('--showProperties', 'Show attributes')
.option(
'--showInheritedProperties',
'Shows inherited attributes, needs --showProperties',
)
.option(
'--showOptionalProperties',
'Shows optional attributes and relations, needs --showProperties',
)
.option(
'--excludeExternals',
'Exclude external definitions',
)
.action(async (relativeSrcPath, plantumlserver, options) => {
const plantUmlConfig: UMLConfig = {
definitions:
typeof options.definitions !== 'undefined' ? options.definitions : [],
showAssociations:
typeof options.showAssociations !== 'undefined'
? options.showAssociations
: false,
showEnumValues:
typeof options.showEnumValues !== 'undefined'
? options.showEnumValues
: false,
showInheritance:
typeof options.showInheritance !== 'undefined'
? options.showInheritance
: false,
showInheritedProperties:
typeof options.showInheritedProperties !== 'undefined'
? options.showInheritedProperties
: false,
showOptionalProperties:
typeof options.showOptionalProperties !== 'undefined'
? options.showOptionalProperties
: false,
showProperties:
typeof options.showProperties !== 'undefined'
? options.showEnumValues
: false,
};
Logger.log(`PlantUML options: ${JSON.stringify(plantUmlConfig)}`);
const srcPath = resolve(relativeSrcPath);
const projectReflection = getProjectReflection(srcPath, !options.excludeExternals ? false : true);
const definitions = readDefinitions(projectReflection);
await createDiagram(definitions, plantUmlConfig, plantumlserver);
});
commander
.parse(process.argv);
.command('plantuml-file <file> <plantumlserver>')
.action(async (file: string, plantumlserver: string) => {
const fileContent = readFileSync(resolve(file)).toString();
await createDiagramFromString(fileContent, plantumlserver);
});
commander.parse(process.argv);
if (commander.args.length < 1) {
commander.outputHelp();