Skip to content

Commit 0128401

Browse files
committed
fix(package): main points to non existant package
"bin" mode was failing for similar reason Added simple test for CLI Add -v option (GraphViz version) for CLI Fixes #114 Signed-off-by: GordonSmith <[email protected]>
1 parent 2973874 commit 0128401

File tree

4 files changed

+102
-27
lines changed

4 files changed

+102
-27
lines changed

.vscode/launch.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
"configurations": [
77
{
88
"name": "index.html",
9-
"type": "pwa-msedge",
9+
"type": "msedge",
1010
"request": "launch",
1111
"url": "http://localhost:8000/index.html",
1212
"runtimeArgs": [],
1313
"webRoot": "${workspaceRoot}"
1414
},
1515
{
1616
"name": "helloworld.html",
17-
"type": "pwa-msedge",
17+
"type": "msedge",
1818
"request": "launch",
1919
"url": "http://localhost:8000/helloworld.html",
2020
"webRoot": "${workspaceRoot}"
2121
},
2222
{
2323
"name": "test-browser",
24-
"type": "pwa-msedge",
24+
"type": "msedge",
2525
"request": "launch",
2626
"url": "http://localhost:8000/test.html",
2727
"webRoot": "${workspaceRoot}",
@@ -41,7 +41,7 @@
4141
"skipFiles": [
4242
"<node_internals>/**"
4343
],
44-
"type": "pwa-node"
44+
"type": "node"
4545
},
4646
{
4747
"name": "CLI",
@@ -50,12 +50,12 @@
5050
"args": [
5151
"-K neato",
5252
"-n 2",
53-
"./input.dot"
53+
"./src/__tests__/simple.dot"
5454
],
5555
"skipFiles": [
5656
"<node_internals>/**"
5757
],
58-
"type": "pwa-node"
58+
"type": "node"
5959
}
6060
]
6161
}

bin/cli.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
/* eslint-disable @typescript-eslint/no-var-requires */
44

55
const fs = require("fs");
6-
const gvMod = require("../dist/graphviz.node.js");
6+
const { exit } = require("process");
7+
const gvMod = require("../dist/graphviz.js");
78

89
const yargs = require("yargs/yargs")(process.argv.slice(2))
910
.usage("Usage: dot-wasm [options] fileOrDot")
10-
.demandCommand(1, 1)
11+
.demandCommand(0, 1)
1112
.example("dot-wasm -K neato -T xdot ./input.dot", "Execute NEATO layout and outputs XDOT format.")
1213
.alias("K", "layout")
1314
.nargs("K", 1)
@@ -21,6 +22,8 @@ const yargs = require("yargs/yargs")(process.argv.slice(2))
2122
.alias("y", "invert-y")
2223
.nargs("y", 0)
2324
.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")
2427
.help("h")
2528
.alias("h", "help")
2629
.epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
@@ -36,24 +39,35 @@ try {
3639
dot = argv._[0];
3740
}
3841

39-
if (argv.n && argv.layout.trim() !== "neato") {
40-
throw new Error("-n option is only supported with -T neato");
41-
}
42+
if (argv.v) {
43+
gvMod.graphvizVersion().then(version => {
44+
console.log(`GraphViz version: ${version}`);
45+
}).catch(e => {
46+
console.error(e.message);
47+
exit(1);
48+
})
49+
} else {
4250

43-
const ext = {
44-
};
45-
if (argv.n) {
46-
ext.nop = parseInt(argv.n);
47-
}
48-
if (argv.y) {
49-
ext.yInvert = true;
50-
}
51+
if (argv.n && argv.layout.trim() !== "neato") {
52+
throw new Error("-n option is only supported with -T neato");
53+
}
54+
55+
const ext = {
56+
};
57+
if (argv.n) {
58+
ext.nop = parseInt(argv.n);
59+
}
60+
if (argv.y) {
61+
ext.yInvert = true;
62+
}
5163

52-
gvMod.graphviz.layout(dot, argv.format?.trim() ?? "svg", argv.layout?.trim() ?? "dot", ext).then(response => {
53-
console.log(response);
54-
}).catch(e => {
55-
console.error(e.message);
56-
});
64+
gvMod.graphviz.layout(dot, argv.format?.trim() ?? "svg", argv.layout?.trim() ?? "dot", ext).then(response => {
65+
console.log(response);
66+
}).catch(e => {
67+
console.error(e.message);
68+
exit(1);
69+
});
70+
}
5771
} catch (e) {
5872
console.error(`Error: ${e.message}\n`);
5973
yargs.showHelp();

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
"patchwork",
1616
"xml"
1717
],
18-
"main": "dist/index.node.js",
18+
"main": "dist/index.js",
1919
"module": "dist/index.es6",
20-
"module-node": "dist/index.node.es6",
2120
"browser": "dist/index.js",
2221
"unpkg": "dist/index.min.js",
2322
"jsdelivr": "dist/index.min.js",
@@ -64,9 +63,10 @@
6463
"dev-start": "ws",
6564
"lint": "eslint src/**/*.ts",
6665
"lint-fix": "npm run lint -- --fix",
66+
"test-cli": "node ./bin/cli.js -v",
6767
"test-chrome": "karma start --single-run --browsers ChromeHeadless karma.conf.js",
6868
"test-firefox": "karma start --single-run --browsers Firefox karma.conf.js",
69-
"test-node": "mocha ./dist/test.js --reporter spec",
69+
"test-node": "node ./bin/cli.js -v && mocha ./dist/test.js --reporter spec",
7070
"test": "run-p test-chrome test-node",
7171
"tag": "run-s standard-version git-push",
7272
"purge-jsdelivr": "node ./utils/purge-jsdelivr.js",

src/__tests__/simple.dot

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
digraph G {
2+
node [shape=rect];
3+
4+
subgraph cluster_0 {
5+
style=filled;
6+
color=lightgrey;
7+
node [style=filled,color=white];
8+
a0 -> a1 -> a2 -> a3;
9+
label = "process #1";
10+
}
11+
12+
subgraph cluster_1 {
13+
node [style=filled];
14+
b0 -> b1 -> b2 -> b3;
15+
label = "process #2";
16+
color=blue
17+
}
18+
19+
start -> a0;
20+
start -> b0;
21+
a1 -> b3;
22+
b2 -> a3;
23+
a3 -> a0;
24+
a3 -> end;
25+
b3 -> end;
26+
27+
start [shape=Mdiamond];
28+
end [shape=Msquare];
29+
}
30+
`;
31+
32+
export const badDot = `
33+
digraph G {
34+
node [shape=rect];
35+
36+
subgraph cluster_0 {
37+
style=filled;
38+
color=lightgrey;
39+
node [style=filled,color=white];
40+
a0 -> a1 -> a2 -> a3;
41+
label = "process #1";
42+
]
43+
44+
subgraph cluster_1 {
45+
node [style=filled];
46+
b0 -> b1 -> b2 -> b3;
47+
label = "process #2";
48+
color=blue
49+
}
50+
51+
start -> a0;
52+
start -> b0;
53+
a1 -> b3;
54+
b2 -> a3;
55+
a3 -> a0;
56+
a3 -> end;
57+
b3 -> end;
58+
59+
start [shape=Mdiamond];
60+
end [shape=Msquare];
61+
}

0 commit comments

Comments
 (0)