nicevg 0.17.1 → 0.18.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 +12 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +46 -0
- package/dist/cli.js.map +1 -0
- package/native/darwin-arm64/libnicevg_ffi.dylib +0 -0
- package/native/darwin-x64/libnicevg_ffi.dylib +0 -0
- package/native/linux-arm64/libnicevg_ffi.so +0 -0
- package/native/linux-x64/libnicevg_ffi.so +0 -0
- package/native/win32-x64/nicevg_ffi.dll +0 -0
- package/package.json +7 -3
- package/src/cli.ts +51 -0
package/README.md
CHANGED
|
@@ -18,8 +18,20 @@ npm install nicevg
|
|
|
18
18
|
bun add nicevg
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
The package also has the `nicevg` command: install it with `npm install -g nicevg`, or run it once with `npx nicevg` or `bunx nicevg`.
|
|
22
|
+
|
|
21
23
|
## Example
|
|
22
24
|
|
|
25
|
+
### CLI
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
nicevg < diagram.svg > fixed.svg
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
It reads the SVG from stdin and writes the fixed one to stdout. The issues it could not fix go to stderr, and the exit status is `0` with none left, `1` with some, and `2` for invalid SVG.
|
|
32
|
+
|
|
33
|
+
### Library
|
|
34
|
+
|
|
23
35
|
```ts
|
|
24
36
|
import { render, svg, text } from "nicevg";
|
|
25
37
|
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The nicevg command: an SVG diagram on stdin, fixed and arranged by the
|
|
4
|
+
* native library, out on stdout. Issues left go to stderr, one per line;
|
|
5
|
+
* the exit status is 0 with none left, 1 with some, and 2 for bad input.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The nicevg command: an SVG diagram on stdin, fixed and arranged by the
|
|
4
|
+
* native library, out on stdout. Issues left go to stderr, one per line;
|
|
5
|
+
* the exit status is 0 with none left, 1 with some, and 2 for bad input.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { NicevgError, render } from "./index.js";
|
|
9
|
+
const ABOUT = "Repair mechanical layout errors in an SVG diagram read from stdin, move nodes a little so connectors bend, cross and crowd less, and write the result to stdout";
|
|
10
|
+
const USAGE = "Usage: nicevg";
|
|
11
|
+
function main(args) {
|
|
12
|
+
for (const arg of args) {
|
|
13
|
+
if (arg === "-h" || arg === "--help") {
|
|
14
|
+
process.stdout.write(`${ABOUT}\n\n${USAGE}\n\nOptions:\n -h, --help Print help\n -V, --version Print version\n`);
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
if (arg === "-V" || arg === "--version") {
|
|
18
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
19
|
+
process.stdout.write(`nicevg ${version}\n`);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (args.length > 0) {
|
|
24
|
+
process.stderr.write(`error: unexpected argument '${args[0]}' found\n\n${USAGE}\n\nFor more information, try '--help'.\n`);
|
|
25
|
+
return 2;
|
|
26
|
+
}
|
|
27
|
+
let svg;
|
|
28
|
+
try {
|
|
29
|
+
svg = render({ svg: readFileSync(0, "utf8") });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error instanceof NicevgError || (error instanceof Error && "code" in error)) {
|
|
33
|
+
process.stderr.write(`Invalid SVG: ${error.message}\n`);
|
|
34
|
+
return 2;
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
process.stdout.write(`${svg}\n`);
|
|
39
|
+
for (const issue of svg.report.issues) {
|
|
40
|
+
process.stderr.write(`${issue.code}: ${issue.message}\n`);
|
|
41
|
+
}
|
|
42
|
+
return svg.report.valid ? 0 : 1;
|
|
43
|
+
}
|
|
44
|
+
// Set rather than exit, so stdout and stderr finish writing first.
|
|
45
|
+
process.exitCode = main(process.argv.slice(2));
|
|
46
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,KAAK,GACT,iKAAiK,CAAC;AACpK,MAAM,KAAK,GAAG,eAAe,CAAC;AAE9B,SAAS,IAAI,CAAC,IAAc;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,OAAO,KAAK,6EAA6E,CAAC,CAAC;YACxH,OAAO,CAAC,CAAC;QACX,CAAC;QACD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YACxC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAClG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,OAAO,IAAI,CAAC,CAAC;YAC5C,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,IAAI,CAAC,CAAC,CAAC,cAAc,KAAK,2CAA2C,CAAC,CAAC;QAC3H,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,GAAG,CAAC;IACR,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,IAAI,CAAC,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC;YAChF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;YACxD,OAAO,CAAC,CAAC;QACX,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;IACjC,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClC,CAAC;AAED,mEAAmE;AACnE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nicevg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Deterministic checks and repairs for diagrams, given as shapes or SVG, on Bun and Node through native FFI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"diagram",
|
|
7
7
|
"svg",
|
|
8
8
|
"layout",
|
|
9
9
|
"routing",
|
|
10
|
-
"ffi"
|
|
10
|
+
"ffi",
|
|
11
|
+
"cli"
|
|
11
12
|
],
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"homepage": "https://github.com/takagiy/nicevg#readme",
|
|
@@ -19,6 +20,9 @@
|
|
|
19
20
|
"type": "module",
|
|
20
21
|
"main": "./dist/index.js",
|
|
21
22
|
"types": "./dist/index.d.ts",
|
|
23
|
+
"bin": {
|
|
24
|
+
"nicevg": "./dist/cli.js"
|
|
25
|
+
},
|
|
22
26
|
"exports": {
|
|
23
27
|
".": {
|
|
24
28
|
"types": "./dist/index.d.ts",
|
|
@@ -43,7 +47,7 @@
|
|
|
43
47
|
"build:native": "bun run scripts/build-native.ts",
|
|
44
48
|
"build:js": "tsc -p tsconfig.build.json",
|
|
45
49
|
"test": "bun run test:bun && bun run test:node",
|
|
46
|
-
"test:bun": "bun test ./test/bun",
|
|
50
|
+
"test:bun": "bun test --timeout 30000 ./test/bun",
|
|
47
51
|
"test:node": "node --test \"test/node/**/*.test.*\"",
|
|
48
52
|
"typecheck": "tsc --noEmit"
|
|
49
53
|
},
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The nicevg command: an SVG diagram on stdin, fixed and arranged by the
|
|
4
|
+
* native library, out on stdout. Issues left go to stderr, one per line;
|
|
5
|
+
* the exit status is 0 with none left, 1 with some, and 2 for bad input.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
|
|
10
|
+
import { NicevgError, render } from "./index.ts";
|
|
11
|
+
|
|
12
|
+
const ABOUT =
|
|
13
|
+
"Repair mechanical layout errors in an SVG diagram read from stdin, move nodes a little so connectors bend, cross and crowd less, and write the result to stdout";
|
|
14
|
+
const USAGE = "Usage: nicevg";
|
|
15
|
+
|
|
16
|
+
function main(args: string[]): number {
|
|
17
|
+
for (const arg of args) {
|
|
18
|
+
if (arg === "-h" || arg === "--help") {
|
|
19
|
+
process.stdout.write(`${ABOUT}\n\n${USAGE}\n\nOptions:\n -h, --help Print help\n -V, --version Print version\n`);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
if (arg === "-V" || arg === "--version") {
|
|
23
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
24
|
+
process.stdout.write(`nicevg ${version}\n`);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (args.length > 0) {
|
|
29
|
+
process.stderr.write(`error: unexpected argument '${args[0]}' found\n\n${USAGE}\n\nFor more information, try '--help'.\n`);
|
|
30
|
+
return 2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let svg;
|
|
34
|
+
try {
|
|
35
|
+
svg = render({ svg: readFileSync(0, "utf8") });
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error instanceof NicevgError || (error instanceof Error && "code" in error)) {
|
|
38
|
+
process.stderr.write(`Invalid SVG: ${error.message}\n`);
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
process.stdout.write(`${svg}\n`);
|
|
44
|
+
for (const issue of svg.report.issues) {
|
|
45
|
+
process.stderr.write(`${issue.code}: ${issue.message}\n`);
|
|
46
|
+
}
|
|
47
|
+
return svg.report.valid ? 0 : 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Set rather than exit, so stdout and stderr finish writing first.
|
|
51
|
+
process.exitCode = main(process.argv.slice(2));
|