Skip to content

Commit

Permalink
Error on invalid JAR path
Browse files Browse the repository at this point in the history
  • Loading branch information
krisztianb committed Jun 27, 2020
1 parent 62cd3a9 commit 7dd432a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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**

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": [
Expand Down
6 changes: 6 additions & 0 deletions src/plantuml_pipe.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit 7dd432a

Please sign in to comment.