mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
feat: added output file name for uml generation
This commit is contained in:
15
src/cli.ts
15
src/cli.ts
@@ -199,6 +199,10 @@ commander
|
||||
'--excludeExternals',
|
||||
'Exclude external definitions',
|
||||
)
|
||||
.option(
|
||||
'--outputFileName <fileName>',
|
||||
'Defines the filename of the output',
|
||||
)
|
||||
.action(async (relativeSrcPath, plantumlserver, options) => {
|
||||
const plantUmlConfig: UMLConfig = {
|
||||
definitions:
|
||||
@@ -225,9 +229,12 @@ commander
|
||||
: false,
|
||||
showProperties:
|
||||
typeof options.showProperties !== 'undefined'
|
||||
? options.showEnumValues
|
||||
? options.showProperties
|
||||
: false,
|
||||
};
|
||||
if (typeof options.outputFileName !== 'undefined') {
|
||||
plantUmlConfig.outputFileName = options.outputFileName;
|
||||
}
|
||||
|
||||
Logger.log(`PlantUML options: ${JSON.stringify(plantUmlConfig)}`);
|
||||
|
||||
@@ -241,10 +248,10 @@ commander
|
||||
});
|
||||
|
||||
commander
|
||||
.command('plantuml-file <file> <plantumlserver>')
|
||||
.action(async (file: string, plantumlserver: string) => {
|
||||
.command('plantuml-file <inputFile> <plantumlserver> [outputFile]')
|
||||
.action(async (file: string, plantumlserver: string, outputFile: string) => {
|
||||
const fileContent = readFileSync(resolve(file)).toString();
|
||||
await createDiagramFromString(fileContent, plantumlserver);
|
||||
await createDiagramFromString(fileContent, plantumlserver, outputFile);
|
||||
});
|
||||
|
||||
commander.parse(process.argv);
|
||||
|
||||
@@ -81,7 +81,7 @@ export async function createDiagram(
|
||||
modelPlantUMLCode += definitionPlantUMLCode;
|
||||
}
|
||||
|
||||
return await createDiagramFromString(modelPlantUMLCode, plantUmlBaseURL);
|
||||
return await createDiagramFromString(modelPlantUMLCode, plantUmlBaseURL, config.outputFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,9 +90,13 @@ export async function createDiagram(
|
||||
*
|
||||
* @param modelPlantUMLCode
|
||||
*/
|
||||
export async function createDiagramFromString(modelPlantUMLCode: string, plantUmlBaseURL: string) {
|
||||
export async function createDiagramFromString(
|
||||
modelPlantUMLCode: string,
|
||||
plantUmlBaseURL: string,
|
||||
outputFile = `Diagram-${new Date().toISOString()}`,
|
||||
) {
|
||||
const plantumlEncoder = require('plantuml-encoder');
|
||||
const plantUMLCode = plantumlEncoder.encode(modelPlantUMLCode);
|
||||
const plantUMLCode = plantumlEncoder.encode(`@startuml\n${modelPlantUMLCode}\n@enduml`);
|
||||
const url = `${plantUmlBaseURL}/svg/${plantUMLCode}`;
|
||||
let response;
|
||||
try {
|
||||
@@ -105,7 +109,8 @@ export async function createDiagramFromString(modelPlantUMLCode: string, plantUm
|
||||
Logger.log(`Please try using the public plantuml server:\nhttp://www.plantuml.com/plantuml/svg/${plantUMLCode}`);
|
||||
throw e;
|
||||
}
|
||||
const fileName: string = `Diagram-${new Date().toISOString()}.svg`;
|
||||
// attach file extension
|
||||
const fileName = `${outputFile}.svg`;
|
||||
try {
|
||||
createWriteStream(fileName).write(response.body);
|
||||
Logger.log(`Writen data to file: ${fileName}`);
|
||||
|
||||
@@ -22,6 +22,11 @@ export interface UMLConfig {
|
||||
*/
|
||||
definitions: string[];
|
||||
|
||||
/**
|
||||
* Defines the output file name without file extension
|
||||
*/
|
||||
outputFileName?: string;
|
||||
|
||||
/**
|
||||
* Should the associations between definitions be shown
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user