@hpcc-js/wasm-graphviz-cli 1.0.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  This package provides a command line interface for the `@hpcc-js/wasm-graphviz` package.
4
4
 
5
5
  To call `@hpcc-js/wasm-graphviz-cli` without installing:
6
+
6
7
  ```sh
7
8
  npx @hpcc-js/wasm-graphviz-cli [options] fileOrDot
8
9
  ```
package/bin/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,57 +1,58 @@
1
1
  {
2
- "name": "@hpcc-js/wasm-graphviz-cli",
3
- "version": "1.0.4",
4
- "description": "hpcc-js - WASM Graphviz Cli",
5
- "type": "module",
6
- "bin": {
7
- "wasm-graphviz-cli": "bin/index.js"
8
- },
9
- "exports": {
10
- ".": {
11
- "types": "./types/index.d.ts",
12
- "import": "./dist/index.js"
13
- }
14
- },
15
- "types": "./types/index.d.ts",
16
- "files": [
17
- "dist/**/*",
18
- "types/**/*"
19
- ],
20
- "scripts": {
21
- "clean": "rimraf ./dist ./types",
22
- "build-types": "tsc --project tsconfig.json --emitDeclarationOnly",
23
- "build-types-watch": "npm run build-types -- --watch",
24
- "build-ts-dev": "esbuild ./src/index.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./bin/index.js --banner:js='#!/usr/bin/env node'",
25
- "build-ts": "npm run build-ts-dev --minify",
26
- "build-ts-watch": "npm run build-ts-dev -- --watch",
27
- "build-dev": "run-p build-types build-ts-dev",
28
- "build": "run-p build-types build-ts",
29
- "lint-skypack": "npx -y @skypack/package-check",
30
- "lint-eslint": "eslint src/**/*.ts",
31
- "lint": "run-p lint-eslint lint-skypack"
32
- },
33
- "dependencies": {
34
- "@hpcc-js/wasm-graphviz": "^1.0.1",
35
- "yargs": "17.7.2"
36
- },
37
- "devDependencies": {
38
- "@hpcc-js/esbuild-plugins": "^1.0.1"
39
- },
40
- "keywords": [
41
- "graphviz",
42
- "typescript",
43
- "webassembly",
44
- "wasm",
45
- "dot",
46
- "neato",
47
- "cli"
48
- ],
49
- "author": "hpcc-systems",
50
- "repository": {
51
- "type": "git",
52
- "url": "git+https://github.com/hpcc-systems/hpcc-js-wasm.git"
53
- },
54
- "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
55
- "license": "Apache-2.0",
56
- "gitHead": "4a93a0ee7a7100d8251f1190628d0511ab4bbb1a"
2
+ "name": "@hpcc-js/wasm-graphviz-cli",
3
+ "version": "1.2.0",
4
+ "description": "hpcc-js - WASM Graphviz Cli",
5
+ "type": "module",
6
+ "bin": {
7
+ "wasm-graphviz-cli": "bin/index.js"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./types/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "main": "./dist/index.js",
16
+ "types": "./types/index.d.ts",
17
+ "files": [
18
+ "dist/**/*",
19
+ "src/**/*",
20
+ "types/**/*"
21
+ ],
22
+ "scripts": {
23
+ "clean": "rimraf ./dist ./types",
24
+ "build-types": "tsc --project tsconfig.json --emitDeclarationOnly",
25
+ "build-types-watch": "npm run build-types -- --watch",
26
+ "build-ts-dev": "esbuild ./src/index.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./bin/index.js --banner:js='#!/usr/bin/env node'",
27
+ "build-ts": "npm run build-ts-dev --minify",
28
+ "build-ts-watch": "npm run build-ts-dev -- --watch",
29
+ "build-dev": "run-p build-types build-ts-dev",
30
+ "build": "run-p build-types build-ts",
31
+ "lint-skypack": "npx -y @skypack/package-check",
32
+ "lint-eslint": "eslint src/**/*.ts",
33
+ "lint": "run-p lint-eslint",
34
+ "update": "npx -y npm-check-updates -u -t minor",
35
+ "update-major": "npx -y npm-check-updates -u"
36
+ },
37
+ "dependencies": {
38
+ "@hpcc-js/wasm-graphviz": "1.2.0",
39
+ "yargs": "17.7.2"
40
+ },
41
+ "keywords": [
42
+ "graphviz",
43
+ "typescript",
44
+ "webassembly",
45
+ "wasm",
46
+ "dot",
47
+ "neato",
48
+ "cli"
49
+ ],
50
+ "author": "hpcc-systems",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/hpcc-systems/hpcc-js-wasm.git"
54
+ },
55
+ "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
56
+ "license": "Apache-2.0",
57
+ "gitHead": "7c8edd51ff7229d9ccb3264bba3485b89f3d2f0d"
57
58
  }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { main } from "./main.ts";
2
+
3
+ await main();
package/src/main.ts ADDED
@@ -0,0 +1,69 @@
1
+ import fs from "fs";
2
+ import * as yargs from "yargs";
3
+ import { hideBin } from "yargs/helpers";
4
+ import { Graphviz, Engine, Format, Options } from "@hpcc-js/wasm-graphviz";
5
+
6
+ export async function main() {
7
+
8
+ const myYargs = yargs.default(hideBin(process.argv)) as yargs.Argv<{ vx: boolean, layout: Engine, format: Format, n: string }>;
9
+ myYargs
10
+ .usage("Usage: dot-wasm [options] fileOrDot")
11
+ .demandCommand(0, 1)
12
+ .example("dot-wasm -K neato -T xdot ./input.dot", "Execute NEATO layout and outputs XDOT format.")
13
+ .alias("K", "layout")
14
+ .nargs("K", 1)
15
+ .describe("K", "Set layout engine (circo | dot | fdp | sfdp | neato | osage | patchwork | twopi | nop | nop2). By default, dot is used.")
16
+ .alias("T", "format")
17
+ .nargs("T", 1)
18
+ .describe("T", "Set output language to one of the supported formats (svg | dot | json | dot_json | xdot_json | plain | plain-ext). By default, svg is produced.")
19
+ .alias("n", "neato-no-op")
20
+ .nargs("n", 1)
21
+ .describe("n", "Sets no-op flag in neato. \"-n 1\" assumes neato nodes have already been positioned and all nodes have a pos attribute giving the positions. It then performs an optional adjustment to remove node-node overlap, depending on the value of the overlap attribute, computes the edge layouts, depending on the value of the splines attribute, and emits the graph in the appropriate format.\n\"-n 2\" Use node positions as specified, with no adjustment to remove node-node overlaps, and use any edge layouts already specified by the pos attribute. neato computes an edge layout for any edge that does not have a pos attribute. As usual, edge layout is guided by the splines attribute.")
22
+ .alias("y", "invert-y")
23
+ .nargs("y", 0)
24
+ .describe("y", "By default, the coordinate system used in generic output formats, such as attributed dot, extended dot, plain and plain-ext, is the standard cartesian system with the origin in the lower left corner, and with increasing y coordinates as points move from bottom to top. If the -y flag is used, the coordinate system is inverted, so that increasing values of y correspond to movement from top to bottom.")
25
+ .nargs("v", 0)
26
+ .describe("v", "Echo GraphViz library version")
27
+ .help("h")
28
+ .alias("h", "help")
29
+ .epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
30
+ ;
31
+
32
+ const argv = await myYargs.argv;
33
+
34
+ try {
35
+ let dot;
36
+ if (fs.existsSync(argv._[0] as string)) {
37
+ dot = fs.readFileSync(argv._[0], "utf8");
38
+ } else {
39
+ dot = argv._[0] as string;
40
+ }
41
+ const graphviz = await Graphviz.load();
42
+
43
+ if (argv.v) {
44
+ console.log(`GraphViz version: ${graphviz.version()}`);
45
+ } else if (dot) {
46
+
47
+ if (argv.n && argv.layout.trim() !== "neato") {
48
+ throw new Error("-n option is only supported with -T neato");
49
+ }
50
+
51
+ const ext: Options = {
52
+ };
53
+ if (argv.n) {
54
+ ext.nop = parseInt(argv.n);
55
+ }
56
+ if (argv.y) {
57
+ ext.yInvert = true;
58
+ }
59
+
60
+ const response = graphviz.layout(dot, (argv.format?.trim() ?? "svg") as Format, (argv.layout?.trim() ?? "dot") as Engine, ext);
61
+ console.log(response);
62
+ } else {
63
+ throw new Error("'fileOrDot' is required.");
64
+ }
65
+ } catch (e: any) {
66
+ console.error(`Error: ${e?.message}\n`);
67
+ myYargs.showHelp();
68
+ }
69
+ }