@hpcc-js/wasm-graphviz-cli 1.0.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 ADDED
@@ -0,0 +1,51 @@
1
+ # Command Line Interface
2
+
3
+ To call `dot-wasm` without installing:
4
+ ```sh
5
+ npx -p @hpcc-js/wasm dot-wasm [options] fileOrDot
6
+ ```
7
+
8
+ To install the global command `dot-wasm` via NPM:
9
+ ```sh
10
+ npm install --global @hpcc-js/wasm
11
+ ```
12
+
13
+ Usage:
14
+ ```sh
15
+ Usage: dot-wasm [options] fileOrDot
16
+
17
+ Options:
18
+ --version Show version number [boolean]
19
+ -K, --layout Set layout engine (circo | dot | fdp | sfdp | neato | osage
20
+ | patchwork | twopi | nop | nop2). By default, dot is used.
21
+ -T, --format Set output language to one of the supported formats (svg,
22
+ dot, json, dot_json, xdot_json, plain, plain-ext). By
23
+ default, svg is produced.
24
+ -n, --neato-no-op Sets no-op flag in neato.
25
+ "-n 1" assumes neato nodes have already been positioned and
26
+ all nodes have a pos attribute giving the positions. It
27
+ then performs an optional adjustment to remove node-node
28
+ overlap, depending on the value of the overlap attribute,
29
+ computes the edge layouts, depending on the value of the
30
+ splines attribute, and emits the graph in the appropriate
31
+ format.
32
+ "-n 2" Use node positions as specified, with no adjustment
33
+ to remove node-node overlaps, and use any edge layouts
34
+ already specified by the pos attribute. neato computes an
35
+ edge layout for any edge that does not have a pos
36
+ attribute. As usual, edge layout is guided by the splines
37
+ attribute.
38
+ -y, --invert-y By default, the coordinate system used in generic output
39
+ formats, such as attributed dot, extended dot, plain and
40
+ plain-ext, is the standard cartesian system with the origin
41
+ in the lower left corner, and with increasing y coordinates
42
+ as points move from bottom to top. If the -y flag is used,
43
+ the coordinate system is inverted, so that increasing
44
+ values of y correspond to movement from top to bottom.
45
+ -v Echo GraphViz library version
46
+ -h, --help Show help [boolean]
47
+
48
+ Examples:
49
+ dot-wasm -K neato -T xdot ./input.dot Execute NEATO layout and outputs XDOT
50
+ format.
51
+ ```
package/bin/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import fs from "fs";
2
+ import * as yargs from "yargs";
3
+ import { hideBin } from "yargs/helpers";
4
+ import { Graphviz } from "@hpcc-js/wasm/graphviz";
5
+ const myYargs = yargs.default(hideBin(process.argv));
6
+ myYargs.usage("Usage: dot-wasm [options] fileOrDot").demandCommand(0, 1).example("dot-wasm -K neato -T xdot ./input.dot", "Execute NEATO layout and outputs XDOT format.").alias("K", "layout").nargs("K", 1).describe("K", "Set layout engine (circo | dot | fdp | sfdp | neato | osage | patchwork | twopi | nop | nop2). By default, dot is used.").alias("T", "format").nargs("T", 1).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.").alias("n", "neato-no-op").nargs("n", 1).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.').alias("y", "invert-y").nargs("y", 0).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.").nargs("v", 0).describe("v", "Echo GraphViz library version").help("h").alias("h", "help").epilog("https://github.com/hpcc-systems/hpcc-js-wasm");
7
+ const argv = await myYargs.argv;
8
+ try {
9
+ let dot;
10
+ if (fs.existsSync(argv._[0])) {
11
+ dot = fs.readFileSync(argv._[0], "utf8");
12
+ } else {
13
+ dot = argv._[0];
14
+ }
15
+ const graphviz = await Graphviz.load();
16
+ if (argv.v) {
17
+ console.log(`GraphViz version: ${graphviz.version()}`);
18
+ } else if (dot) {
19
+ if (argv.n && argv.layout.trim() !== "neato") {
20
+ throw new Error("-n option is only supported with -T neato");
21
+ }
22
+ const ext = {};
23
+ if (argv.n) {
24
+ ext.nop = parseInt(argv.n);
25
+ }
26
+ if (argv.y) {
27
+ ext.yInvert = true;
28
+ }
29
+ const response = graphviz.layout(dot, argv.format?.trim() ?? "svg", argv.layout?.trim() ?? "dot", ext);
30
+ console.log(response);
31
+ } else {
32
+ throw new Error("'fileOrDot' is required.");
33
+ }
34
+ } catch (e) {
35
+ console.error(`Error: ${e?.message}
36
+ `);
37
+ myYargs.showHelp();
38
+ }
package/bin/index.mjs ADDED
@@ -0,0 +1,38 @@
1
+ import fs from "fs";
2
+ import * as yargs from "yargs";
3
+ import { hideBin } from "yargs/helpers";
4
+ import { Graphviz } from "@hpcc-js/wasm/graphviz";
5
+ const myYargs = yargs.default(hideBin(process.argv));
6
+ myYargs.usage("Usage: dot-wasm [options] fileOrDot").demandCommand(0, 1).example("dot-wasm -K neato -T xdot ./input.dot", "Execute NEATO layout and outputs XDOT format.").alias("K", "layout").nargs("K", 1).describe("K", "Set layout engine (circo | dot | fdp | sfdp | neato | osage | patchwork | twopi | nop | nop2). By default, dot is used.").alias("T", "format").nargs("T", 1).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.").alias("n", "neato-no-op").nargs("n", 1).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.').alias("y", "invert-y").nargs("y", 0).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.").nargs("v", 0).describe("v", "Echo GraphViz library version").help("h").alias("h", "help").epilog("https://github.com/hpcc-systems/hpcc-js-wasm");
7
+ const argv = await myYargs.argv;
8
+ try {
9
+ let dot;
10
+ if (fs.existsSync(argv._[0])) {
11
+ dot = fs.readFileSync(argv._[0], "utf8");
12
+ } else {
13
+ dot = argv._[0];
14
+ }
15
+ const graphviz = await Graphviz.load();
16
+ if (argv.v) {
17
+ console.log(`GraphViz version: ${graphviz.version()}`);
18
+ } else if (dot) {
19
+ if (argv.n && argv.layout.trim() !== "neato") {
20
+ throw new Error("-n option is only supported with -T neato");
21
+ }
22
+ const ext = {};
23
+ if (argv.n) {
24
+ ext.nop = parseInt(argv.n);
25
+ }
26
+ if (argv.y) {
27
+ ext.yInvert = true;
28
+ }
29
+ const response = graphviz.layout(dot, argv.format?.trim() ?? "svg", argv.layout?.trim() ?? "dot", ext);
30
+ console.log(response);
31
+ } else {
32
+ throw new Error("'fileOrDot' is required.");
33
+ }
34
+ } catch (e) {
35
+ console.error(`Error: ${e?.message}
36
+ `);
37
+ myYargs.showHelp();
38
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@hpcc-js/wasm-graphviz-cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "type": "module",
7
+ "bin": {
8
+ "wasm-graphviz-cli": "bin/index.js"
9
+ },
10
+ "files": [
11
+ "bin/*.*"
12
+ ],
13
+ "scripts": {
14
+ "clean": "rimraf ./bin",
15
+ "build": "esbuild --format=esm --outfile=./bin/index.js ./src/index.ts",
16
+ "lint-eslint": "eslint src/**/*.ts",
17
+ "lint": "run-p lint-eslint",
18
+ "test-cli": "node ./bin/index.js -v",
19
+ "test-cli-help": "node ./bin/index.js",
20
+ "test-node": "node ./bin/index.js -v"
21
+ },
22
+ "author": "",
23
+ "license": "Apache-2.0",
24
+ "dependencies": {
25
+ "@hpcc-js/wasm": "2.18.2",
26
+ "yargs": "17.7.2"
27
+ }
28
+ }