forked from naddison36/tx2uml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileGenerator.js
45 lines (45 loc) · 1.77 KB
/
fileGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateFile = void 0;
const fs_1 = require("fs");
const verror_1 = __importDefault(require("verror"));
const plantuml_1 = require("./plantuml");
const debug = require("debug")("tx2uml");
const generateFile = async (pumlStream, options = {}) => {
const filename = constructFilename(options.filename, options.format);
try {
const outputStream = fs_1.createWriteStream(filename);
if (options.format === "puml") {
pumlStream.pipe(outputStream);
debug(`Plant UML file written to ${filename} in raw puml format`);
}
else if (plantuml_1.outputFormats.includes(options.format)) {
await plantuml_1.streamPlantUml(pumlStream, outputStream, {
format: options.format,
limitSize: 60000,
});
debug(`Plant UML file written to ${filename} in ${options.format} format.`);
}
else {
throw new Error(`Output format ${options.format} is not supported. Only the following formats are supported: ${plantuml_1.outputFormats}.`);
}
}
catch (err) {
throw new verror_1.default(err, `Failed to write to file ${filename}.`);
}
};
exports.generateFile = generateFile;
const constructFilename = (filename, format = "png") => {
if (!filename || filename === "") {
return `output.${format}`;
}
const fileExtension = filename.slice(-4);
if (["puml", ".png", ".svg", ".eps"].includes(fileExtension)) {
return filename;
}
return filename + "." + format;
};
//# sourceMappingURL=fileGenerator.js.map