From 7dd432a144173d7d9023c4975eb1f73587424351 Mon Sep 17 00:00:00 2001 From: Krisztian Balla Date: Sat, 27 Jun 2020 22:22:45 +0200 Subject: [PATCH] Error on invalid JAR path --- CHANGELOG | 9 +++++++-- README.md | 15 +++++++++------ package.json | 5 ++++- src/plantuml_pipe.ts | 6 ++++++ test/index.js | 15 +++++++++++++++ 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index df25e9f..88dcf51 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.3.1] - 2020-06-27 +### Added +- Throw error when plantuml.jar cannot be found + ## [1.3.0] - 2020-06-26 ### Fixed - Missing plantuml.jar in package @@ -27,8 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - First version -[Unreleased]: https://github.com/krisztianb/plantuml-pipe/compare/v1.3.0...HEAD -[1.3.0]: https://github.com/krisztianb/plantuml-pipe/releases/tag/v1.2.0 +[Unreleased]: https://github.com/krisztianb/plantuml-pipe/compare/v1.3.1...HEAD +[1.3.1]: https://github.com/krisztianb/plantuml-pipe/releases/tag/v1.3.1 +[1.3.0]: https://github.com/krisztianb/plantuml-pipe/releases/tag/v1.3.0 [1.2.0]: https://github.com/krisztianb/plantuml-pipe/releases/tag/v1.2.0 [1.1.0]: https://github.com/krisztianb/plantuml-pipe/releases/tag/v1.1.0 [1.0.0]: https://github.com/krisztianb/plantuml-pipe/releases/tag/v1.0.0 diff --git a/README.md b/README.md index ec4e08b..57955df 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,24 @@ # plantuml-pipe A PlantUmlPipe instance is a wrapper to a PlantUML JAVA process running in pipe mode. -The object has an input stream (`in`) into which the PlantUML code for one or multiple diagrams can be written -and an output stream (`out`) from which the generated diagrams can be read. +The object has an input stream (`in`) into which the PlantUML code for one or multiple diagrams can be written and +an output streams (`out`) from which the generated diagrams can be read. ## Installation -The module can then be installed using [npm](https://www.npmjs.com/package/plantuml-pipe): +The module includes type definitions for TypeScript. +It can then be installed using [npm](https://www.npmjs.com/package/plantuml-pipe): ```sh $ npm install plantuml-pipe ``` +**Note:** [JAVA](https://www.java.com/) and [Graphviz](https://graphviz.org/) must be installed on your system in +order to use this module. PlantUML however is included with this module. + ## Usage -The following code creates two SVG image files: +The following TypeScript code creates two SVG image files: ```typescript import * as fs from "fs"; @@ -86,8 +90,7 @@ The `PlantUmlPipe` constructor can receive an options object as a parameter. It By default when the PlantUML process encounters an error (eg: because of an error in your PlantUML code), it still generates an image which contains an error message. You can set this option to `true` to disable error image generation. You can then implement an error handling yourself using the normal data event of PlantUMLPipe's - output stream. For every error the data chunk of the event is going to start with the line `ERROR`. - Default: `false` + output stream. For every error the data chunk of the event is going to start with the line `ERROR`. Default: `false` - **javaOptions** diff --git a/package.json b/package.json index 7032c2b..056fdae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plantuml-pipe", - "version": "1.3.0", + "version": "1.3.1", "description": "Generate multiple PlantUML diagrams with one JAVA process", "author": { "name": "KrisztiƔn Balla", @@ -27,6 +27,9 @@ "type": "git", "url": "git+https://github.com/krisztianb/plantuml-pipe.git" }, + "publishConfig": { + "registry": "https://npm.pkg.github.com/" + }, "main": "dist/plantuml_pipe.js", "types": "dist/plantuml_pipe.d.ts", "files": [ diff --git a/src/plantuml_pipe.ts b/src/plantuml_pipe.ts index 9710260..2c4736a 100644 --- a/src/plantuml_pipe.ts +++ b/src/plantuml_pipe.ts @@ -1,5 +1,6 @@ import bsplit from "binary-split"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; +import * as fs from "fs"; import { EOL } from "os"; import * as path from "path"; import split2 from "split2"; @@ -86,6 +87,11 @@ export class PlantUmlPipe { */ constructor(options?: PlantUmlPipeOptions) { const jarPath = options?.jarPath ?? path.join(__dirname, "../vendor/plantuml.jar"); + + if (!fs.existsSync(jarPath)) { + throw new Error("File not found: " + jarPath); + } + const outputFormat = options?.outputFormat ?? "svg"; const delimiter = options?.delimiter ?? "___PLANTUML_DIAGRAM_DELIMITER___"; const split = options?.split ?? true; diff --git a/test/index.js b/test/index.js index 37798ce..757972c 100644 --- a/test/index.js +++ b/test/index.js @@ -21,6 +21,9 @@ testOptionPixelCutOffValue(); console.log("Generating error text file ..."); testOptionNoErrorImages(); +console.log("Calling with invalid JAR path ..."); +testInvalidJarPath(); + // Delete the existing images in the directory function cleanUp() { var directory = __dirname; @@ -90,3 +93,15 @@ function testOptionNoErrorImages() { fs.writeFileSync("./error.svg", chunk); }); } + +// Test calling with invalid JAR path +function testInvalidJarPath() { + try { + new plantuml_piper_1.PlantUmlPipe({ jarPath: "asdf.jar" }); + throw new Error("testInvalidJarPath failed"); + } catch (ex) { + if (!ex.message.startsWith("File not found")) { + throw new Error("testInvalidJarPath failed"); + } + } +}