mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: tests
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {createWriteStream} from 'fs';
|
||||
import * as request from 'got';
|
||||
import {
|
||||
expandTypeValue,
|
||||
@@ -22,9 +21,10 @@ import {
|
||||
LightweightClassDefinition,
|
||||
LightweightDefinition,
|
||||
LightweightProperty,
|
||||
LightweightType
|
||||
LightweightType,
|
||||
} from '@openstapps/easy-ast';
|
||||
import {UMLConfig} from './uml-config.js';
|
||||
import {writeFile} from 'fs/promises';
|
||||
|
||||
/**
|
||||
* Converts the lightweight class/enum definitions according to the configuration,
|
||||
@@ -81,8 +81,8 @@ export async function createDiagramFromString(
|
||||
plantUmlBaseURL: string,
|
||||
outputFile = `Diagram-${new Date().toISOString()}`,
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires,unicorn/prefer-module
|
||||
const plantumlEncoder = require('plantuml-encoder');
|
||||
// @ts-expect-error no declarations
|
||||
const plantumlEncoder = await import('plantuml-encoder');
|
||||
const plantUMLCode = plantumlEncoder.encode(`@startuml\n${modelPlantUMLCode}\n@enduml`);
|
||||
const url = `${plantUmlBaseURL}/svg/${plantUMLCode}`;
|
||||
let response;
|
||||
@@ -100,13 +100,10 @@ export async function createDiagramFromString(
|
||||
throw error;
|
||||
}
|
||||
// attach file extension
|
||||
const fileName = `${outputFile}.svg`;
|
||||
try {
|
||||
createWriteStream(fileName).write(response.body);
|
||||
Logger.log(`Writen data to file: ${fileName}`);
|
||||
} catch {
|
||||
throw new Error('Could not write file. Are you missing permissions?');
|
||||
}
|
||||
const fileName = `${outputFile.replace(/[^\w-]/g, '_')}.svg`;
|
||||
|
||||
await writeFile(fileName, response.body);
|
||||
Logger.log(`Writen data to file: ${fileName}`);
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user