ts-graphviz 1.4.1-dev.c60d6bfba → 1.5.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 +10 -7
- package/lib/adapter/deno/mod.d.ts +5 -9
- package/lib/adapter/deno/mod.js +1 -10
- package/lib/adapter/node/index.cjs +29 -19
- package/lib/adapter/node/index.d.ts +7 -9
- package/lib/adapter/node/index.js +30 -20
- package/lib/adapter/types/index.cjs +1 -0
- package/lib/adapter/types/index.d.ts +107 -0
- package/lib/adapter/types/index.js +0 -0
- package/lib/adapter/utils/index.cjs +59 -0
- package/lib/adapter/utils/index.d.ts +5 -0
- package/lib/adapter/utils/index.js +55 -0
- package/package.json +119 -119
package/README.md
CHANGED
|
@@ -528,13 +528,16 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
528
528
|
<table>
|
|
529
529
|
<tbody>
|
|
530
530
|
<tr>
|
|
531
|
-
<td align="center"><a href="http://blog.kamiazya.tech/"><img src="https://avatars0.githubusercontent.com/u/35218186?v=4?s=100" width="100px;" alt="Yuki Yamazaki"/><br /><sub><b>Yuki Yamazaki</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Code">💻</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Tests">⚠️</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Documentation">📖</a> <a href="#ideas-kamiazya" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
532
|
-
<td align="center"><a href="https://laysent.com"><img src="https://avatars2.githubusercontent.com/u/1191606?v=4?s=100" width="100px;" alt="LaySent"/><br /><sub><b>LaySent</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Alaysent" title="Bug reports">🐛</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=laysent" title="Tests">⚠️</a></td>
|
|
533
|
-
<td align="center"><a href="https://github.com/elasticdotventures"><img src="https://avatars0.githubusercontent.com/u/35611074?v=4?s=100" width="100px;" alt="elasticdotventures"/><br /><sub><b>elasticdotventures</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=elasticdotventures" title="Documentation">📖</a></td>
|
|
534
|
-
<td align="center"><a href="https://github.com/ChristianMurphy"><img src="https://avatars.githubusercontent.com/u/3107513?v=4?s=100" width="100px;" alt="Christian Murphy"/><br /><sub><b>Christian Murphy</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=ChristianMurphy" title="Code">💻</a> <a href="#ideas-ChristianMurphy" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=ChristianMurphy" title="Documentation">📖</a></td>
|
|
535
|
-
<td align="center"><a href="https://github.com/ArtemAdamenko"><img src="https://avatars.githubusercontent.com/u/2178516?v=4?s=100" width="100px;" alt="Artem"/><br /><sub><b>Artem</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3AArtemAdamenko" title="Bug reports">🐛</a></td>
|
|
536
|
-
<td align="center"><a href="https://github.com/fredericohpandolfo"><img src="https://avatars.githubusercontent.com/u/24229136?v=4?s=100" width="100px;" alt="fredericohpandolfo"/><br /><sub><b>fredericohpandolfo</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Afredericohpandolfo" title="Bug reports">🐛</a></td>
|
|
537
|
-
<td align="center"><a href="https://github.com/diegoquinteiro"><img src="https://avatars.githubusercontent.com/u/1878108?v=4?s=100" width="100px;" alt="diegoquinteiro"/><br /><sub><b>diegoquinteiro</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Adiegoquinteiro" title="Bug reports">🐛</a></td>
|
|
531
|
+
<td align="center" valign="top" width="14.28%"><a href="http://blog.kamiazya.tech/"><img src="https://avatars0.githubusercontent.com/u/35218186?v=4?s=100" width="100px;" alt="Yuki Yamazaki"/><br /><sub><b>Yuki Yamazaki</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Code">💻</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Tests">⚠️</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=kamiazya" title="Documentation">📖</a> <a href="#ideas-kamiazya" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
532
|
+
<td align="center" valign="top" width="14.28%"><a href="https://laysent.com"><img src="https://avatars2.githubusercontent.com/u/1191606?v=4?s=100" width="100px;" alt="LaySent"/><br /><sub><b>LaySent</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Alaysent" title="Bug reports">🐛</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=laysent" title="Tests">⚠️</a></td>
|
|
533
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/elasticdotventures"><img src="https://avatars0.githubusercontent.com/u/35611074?v=4?s=100" width="100px;" alt="elasticdotventures"/><br /><sub><b>elasticdotventures</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=elasticdotventures" title="Documentation">📖</a></td>
|
|
534
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ChristianMurphy"><img src="https://avatars.githubusercontent.com/u/3107513?v=4?s=100" width="100px;" alt="Christian Murphy"/><br /><sub><b>Christian Murphy</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=ChristianMurphy" title="Code">💻</a> <a href="#ideas-ChristianMurphy" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ts-graphviz/ts-graphviz/commits?author=ChristianMurphy" title="Documentation">📖</a></td>
|
|
535
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ArtemAdamenko"><img src="https://avatars.githubusercontent.com/u/2178516?v=4?s=100" width="100px;" alt="Artem"/><br /><sub><b>Artem</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3AArtemAdamenko" title="Bug reports">🐛</a></td>
|
|
536
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/fredericohpandolfo"><img src="https://avatars.githubusercontent.com/u/24229136?v=4?s=100" width="100px;" alt="fredericohpandolfo"/><br /><sub><b>fredericohpandolfo</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Afredericohpandolfo" title="Bug reports">🐛</a></td>
|
|
537
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/diegoquinteiro"><img src="https://avatars.githubusercontent.com/u/1878108?v=4?s=100" width="100px;" alt="diegoquinteiro"/><br /><sub><b>diegoquinteiro</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Adiegoquinteiro" title="Bug reports">🐛</a></td>
|
|
538
|
+
</tr>
|
|
539
|
+
<tr>
|
|
540
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/robross0606"><img src="https://avatars.githubusercontent.com/u/2965467?v=4?s=100" width="100px;" alt="robross0606"/><br /><sub><b>robross0606</b></sub></a><br /><a href="#ideas-robross0606" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
538
541
|
</tr>
|
|
539
542
|
</tbody>
|
|
540
543
|
</table>
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface Options {
|
|
4
|
-
format?: Format;
|
|
5
|
-
suppressWarnings?: boolean;
|
|
6
|
-
dotCommand?: string;
|
|
7
|
-
}
|
|
1
|
+
import { Options, Format, Layout } from '../types/index.d.ts';
|
|
8
2
|
|
|
9
3
|
/**
|
|
10
4
|
* Execute the Graphviz dot command and make a Stream of the results.
|
|
11
5
|
*/
|
|
12
|
-
export function toStream(dot: string, options?: Options): Promise<ReadableStream<Uint8Array>>;
|
|
6
|
+
export function toStream<T extends Layout>(dot: string, options?: Options<T>): Promise<ReadableStream<Uint8Array>>;
|
|
13
7
|
|
|
14
8
|
/**
|
|
15
9
|
* Execute the Graphviz dot command and output the results to a file.
|
|
16
10
|
*/
|
|
17
|
-
export function toFile(dot: string, path: string, options?: Options): Promise<void>;
|
|
11
|
+
export function toFile<T extends Layout>(dot: string, path: string, options?: Options<T>): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { Options, Format, Layout };
|
package/lib/adapter/deno/mod.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const args = [
|
|
3
|
-
...(function* () {
|
|
4
|
-
if (suppressWarnings) yield '-q';
|
|
5
|
-
yield `-T${format}`;
|
|
6
|
-
})(),
|
|
7
|
-
];
|
|
8
|
-
return [dotCommand, args];
|
|
9
|
-
}
|
|
10
|
-
|
|
1
|
+
import { commandBuilder } from '../utils/index.js';
|
|
11
2
|
/**
|
|
12
3
|
* Execute the Graphviz dot command and make a Stream of the results.
|
|
13
4
|
*/
|
|
@@ -2,39 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var node_fs = require('node:fs');
|
|
6
5
|
var node_stream = require('node:stream');
|
|
7
|
-
var node_util = require('node:util');
|
|
8
6
|
var node_child_process = require('node:child_process');
|
|
7
|
+
var index_js = require('../utils/index.cjs');
|
|
8
|
+
var node_util = require('node:util');
|
|
9
|
+
var node_fs = require('node:fs');
|
|
9
10
|
|
|
10
|
-
/**
|
|
11
|
-
* @module ts-graphviz/adapter
|
|
12
|
-
* @beta
|
|
13
|
-
*/
|
|
14
|
-
function commandBuilder({ dotCommand = 'dot', suppressWarnings = true, format = 'svg' } = {}) {
|
|
15
|
-
const args = [
|
|
16
|
-
...(function* () {
|
|
17
|
-
if (suppressWarnings) yield '-q';
|
|
18
|
-
yield `-T${format}`;
|
|
19
|
-
})(),
|
|
20
|
-
];
|
|
21
|
-
return [dotCommand, args];
|
|
22
|
-
}
|
|
23
11
|
/**
|
|
24
12
|
* NOTE:
|
|
25
13
|
* The node:stream/promises standard module is not provided in Node 14.
|
|
26
14
|
* Fix Node 14 to use node:stream/promises after LTS ends.
|
|
27
15
|
*/
|
|
28
16
|
const pipeline = node_util.promisify(node_stream.pipeline);
|
|
17
|
+
|
|
29
18
|
/**
|
|
30
19
|
* Execute the Graphviz dot command and make a Stream of the results.
|
|
31
20
|
*/
|
|
32
21
|
async function toStream(dot, options) {
|
|
33
|
-
const [command, args] = commandBuilder(options);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
const [command, args] = index_js.commandBuilder(options ?? {});
|
|
23
|
+
return new Promise(async function toStreamInternal(resolve, reject) {
|
|
24
|
+
const p = node_child_process.spawn(command, args, { stdio: 'pipe' });
|
|
25
|
+
// error handling
|
|
26
|
+
p.on('error', (e) => {
|
|
27
|
+
reject(
|
|
28
|
+
new Error(`Command "${command}" failed.\nMESSAGE:${e.message}`, {
|
|
29
|
+
cause: e,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
const stderrChunks = [];
|
|
34
|
+
p.stderr.on('data', (chunk) => stderrChunks.push(chunk));
|
|
35
|
+
const dist = p.stdout.pipe(new node_stream.PassThrough());
|
|
36
|
+
p.on('close', async (code, signal) => {
|
|
37
|
+
if (code === 0) {
|
|
38
|
+
resolve(dist);
|
|
39
|
+
} else {
|
|
40
|
+
const message = Buffer.concat(stderrChunks).toString();
|
|
41
|
+
reject(new Error(`Command "${command}" failed.\nCODE: ${code}\nSIGNAL: ${signal}\nMESSAGE: ${message}`));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
await pipeline(node_stream.Readable.from([dot]), p.stdin);
|
|
45
|
+
});
|
|
37
46
|
}
|
|
47
|
+
|
|
38
48
|
/**
|
|
39
49
|
* Execute the Graphviz dot command and output the results to a file.
|
|
40
50
|
*/
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
suppressWarnings?: boolean;
|
|
6
|
-
dotCommand?: string;
|
|
7
|
-
}
|
|
2
|
+
import { Layout, Options } from '../types/index.js';
|
|
3
|
+
export { Format, Options } from '../types/index.js';
|
|
4
|
+
|
|
8
5
|
/**
|
|
9
6
|
* Execute the Graphviz dot command and make a Stream of the results.
|
|
10
7
|
*/
|
|
11
|
-
declare function toStream(dot: string, options?: Options): Promise<NodeJS.ReadableStream>;
|
|
8
|
+
declare function toStream<T extends Layout>(dot: string, options?: Options<T>): Promise<NodeJS.ReadableStream>;
|
|
9
|
+
|
|
12
10
|
/**
|
|
13
11
|
* Execute the Graphviz dot command and output the results to a file.
|
|
14
12
|
*/
|
|
15
|
-
declare function toFile(dot: string, path: string, options?: Options): Promise<void>;
|
|
13
|
+
declare function toFile<T extends Layout>(dot: string, path: string, options?: Options<T>): Promise<void>;
|
|
16
14
|
|
|
17
|
-
export {
|
|
15
|
+
export { toFile, toStream };
|
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { pipeline as pipeline$1, Readable } from 'node:stream';
|
|
3
|
-
import { promisify } from 'node:util';
|
|
1
|
+
import { pipeline as pipeline$1, PassThrough, Readable } from 'node:stream';
|
|
4
2
|
import { spawn } from 'node:child_process';
|
|
3
|
+
import { commandBuilder } from '../utils/index.js';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { createWriteStream } from 'node:fs';
|
|
5
6
|
|
|
6
|
-
/**
|
|
7
|
-
* @module ts-graphviz/adapter
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
function commandBuilder({ dotCommand = 'dot', suppressWarnings = true, format = 'svg' } = {}) {
|
|
11
|
-
const args = [
|
|
12
|
-
...(function* () {
|
|
13
|
-
if (suppressWarnings) yield '-q';
|
|
14
|
-
yield `-T${format}`;
|
|
15
|
-
})(),
|
|
16
|
-
];
|
|
17
|
-
return [dotCommand, args];
|
|
18
|
-
}
|
|
19
7
|
/**
|
|
20
8
|
* NOTE:
|
|
21
9
|
* The node:stream/promises standard module is not provided in Node 14.
|
|
22
10
|
* Fix Node 14 to use node:stream/promises after LTS ends.
|
|
23
11
|
*/
|
|
24
12
|
const pipeline = promisify(pipeline$1);
|
|
13
|
+
|
|
25
14
|
/**
|
|
26
15
|
* Execute the Graphviz dot command and make a Stream of the results.
|
|
27
16
|
*/
|
|
28
17
|
async function toStream(dot, options) {
|
|
29
|
-
const [command, args] = commandBuilder(options);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
const [command, args] = commandBuilder(options ?? {});
|
|
19
|
+
return new Promise(async function toStreamInternal(resolve, reject) {
|
|
20
|
+
const p = spawn(command, args, { stdio: 'pipe' });
|
|
21
|
+
// error handling
|
|
22
|
+
p.on('error', (e) => {
|
|
23
|
+
reject(
|
|
24
|
+
new Error(`Command "${command}" failed.\nMESSAGE:${e.message}`, {
|
|
25
|
+
cause: e,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
const stderrChunks = [];
|
|
30
|
+
p.stderr.on('data', (chunk) => stderrChunks.push(chunk));
|
|
31
|
+
const dist = p.stdout.pipe(new PassThrough());
|
|
32
|
+
p.on('close', async (code, signal) => {
|
|
33
|
+
if (code === 0) {
|
|
34
|
+
resolve(dist);
|
|
35
|
+
} else {
|
|
36
|
+
const message = Buffer.concat(stderrChunks).toString();
|
|
37
|
+
reject(new Error(`Command "${command}" failed.\nCODE: ${code}\nSIGNAL: ${signal}\nMESSAGE: ${message}`));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await pipeline(Readable.from([dot]), p.stdin);
|
|
41
|
+
});
|
|
33
42
|
}
|
|
43
|
+
|
|
34
44
|
/**
|
|
35
45
|
* Execute the Graphviz dot command and output the results to a file.
|
|
36
46
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EdgeAttributesObject,
|
|
3
|
+
NodeAttributesObject,
|
|
4
|
+
GraphAttributesObject,
|
|
5
|
+
SubgraphAttributesObject,
|
|
6
|
+
} from '../../common/index.js';
|
|
7
|
+
|
|
8
|
+
type Format = 'png' | 'svg' | 'json' | 'jpg' | 'pdf' | 'xdot' | 'dot' | 'plain' | 'dot_json';
|
|
9
|
+
type Layout = 'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'nop' | 'nop2' | 'osage' | 'patchwork';
|
|
10
|
+
interface NeatoOptions {
|
|
11
|
+
layout: 'neato';
|
|
12
|
+
/**
|
|
13
|
+
* Sets no-op flag in neato.
|
|
14
|
+
*/
|
|
15
|
+
noop?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Reduce graph.
|
|
18
|
+
*/
|
|
19
|
+
reduce?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface FdpOptions {
|
|
22
|
+
layout: 'fdp';
|
|
23
|
+
/**
|
|
24
|
+
* Use grid.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
grid?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Use old attractive force
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
oldAttractive?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Set number of iterations.
|
|
37
|
+
*/
|
|
38
|
+
iterations?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Set unscaled factor
|
|
41
|
+
*/
|
|
42
|
+
unscaledFactor?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Set overlap expansion factor.
|
|
45
|
+
*/
|
|
46
|
+
overlapExpansionFactor?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Set temperature.
|
|
49
|
+
*/
|
|
50
|
+
temperature?: number;
|
|
51
|
+
}
|
|
52
|
+
interface OtherOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Set layout engine.
|
|
55
|
+
*
|
|
56
|
+
* @default 'dot'
|
|
57
|
+
*/
|
|
58
|
+
layout?: Exclude<Layout, 'neato' | 'fdp'>;
|
|
59
|
+
}
|
|
60
|
+
interface CommonOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Set output format.
|
|
63
|
+
*
|
|
64
|
+
* @default 'svg'
|
|
65
|
+
*/
|
|
66
|
+
format?: Format;
|
|
67
|
+
/**
|
|
68
|
+
* If true, set level of message suppression (=1).
|
|
69
|
+
*
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
suppressWarnings?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Path of graphviz dot command.
|
|
75
|
+
*/
|
|
76
|
+
dotCommand?: string;
|
|
77
|
+
attributes?: {
|
|
78
|
+
/**
|
|
79
|
+
* Set edge attribute.
|
|
80
|
+
*/
|
|
81
|
+
edge?: EdgeAttributesObject;
|
|
82
|
+
/**
|
|
83
|
+
* Set node attribute.
|
|
84
|
+
*/
|
|
85
|
+
node?: NodeAttributesObject;
|
|
86
|
+
/**
|
|
87
|
+
* Set graph attribute.
|
|
88
|
+
*/
|
|
89
|
+
graph?: GraphAttributesObject & SubgraphAttributesObject;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Scale input
|
|
93
|
+
*/
|
|
94
|
+
scale?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Use external library.
|
|
97
|
+
*/
|
|
98
|
+
library?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Invert y coordinate in output.
|
|
101
|
+
*/
|
|
102
|
+
y?: boolean;
|
|
103
|
+
}
|
|
104
|
+
type Options<T extends Layout = Layout> = CommonOptions &
|
|
105
|
+
(T extends 'neato' ? NeatoOptions : T extends 'fdp' ? FdpOptions : OtherOptions);
|
|
106
|
+
|
|
107
|
+
export { CommonOptions, FdpOptions, Format, Layout, NeatoOptions, Options, OtherOptions };
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function escapeValue(value) {
|
|
6
|
+
if (value !== true) {
|
|
7
|
+
if (typeof value === 'string' && /\s/g.test(value)) {
|
|
8
|
+
return `="${value}"`;
|
|
9
|
+
} else {
|
|
10
|
+
return `=${value}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
function* args(options) {
|
|
16
|
+
const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
|
|
17
|
+
if (suppressWarnings) yield '-q';
|
|
18
|
+
yield `-T${format}`;
|
|
19
|
+
if (attributes.graph) {
|
|
20
|
+
for (const [key, value] of Object.entries(attributes.graph)) {
|
|
21
|
+
yield `-G${key}${escapeValue(value)}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (attributes.node) {
|
|
25
|
+
for (const [key, value] of Object.entries(attributes.node)) {
|
|
26
|
+
yield `-N${key}${escapeValue(value)}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (attributes.edge) {
|
|
30
|
+
for (const [key, value] of Object.entries(attributes.edge)) {
|
|
31
|
+
yield `-E${key}${escapeValue(value)}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (typeof scale === 'number' && !Number.isNaN(scale)) yield `-s${scale}`;
|
|
35
|
+
if (Array.isArray(library)) for (const lib of library) yield `-l${lib}`;
|
|
36
|
+
if (y === true) yield `-y`;
|
|
37
|
+
if (typeof options.layout === 'string') {
|
|
38
|
+
yield `-K${options.layout}`;
|
|
39
|
+
switch (options.layout) {
|
|
40
|
+
case 'neato':
|
|
41
|
+
const { reduce, noop } = options;
|
|
42
|
+
if (reduce === true) yield '-x';
|
|
43
|
+
if (typeof noop === 'number') yield `-n${noop}`;
|
|
44
|
+
break;
|
|
45
|
+
case 'fdp':
|
|
46
|
+
const { grid, oldAttractive, iterations, unscaledFactor, overlapExpansionFactor, temperature } = options;
|
|
47
|
+
yield ['-L', grid ? '' : 'g', oldAttractive ? 'O' : ''].join('');
|
|
48
|
+
if (typeof iterations === 'number') yield `-Ln${iterations}`;
|
|
49
|
+
if (typeof unscaledFactor === 'number') yield `-LU${unscaledFactor}`;
|
|
50
|
+
if (typeof overlapExpansionFactor === 'number') yield `-LC${overlapExpansionFactor}`;
|
|
51
|
+
if (typeof temperature === 'number') yield `-LT${temperature}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function commandBuilder(options) {
|
|
56
|
+
return [options.dotCommand ?? 'dot', Array.from(args(options))];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.commandBuilder = commandBuilder;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function escapeValue(value) {
|
|
2
|
+
if (value !== true) {
|
|
3
|
+
if (typeof value === 'string' && /\s/g.test(value)) {
|
|
4
|
+
return `="${value}"`;
|
|
5
|
+
} else {
|
|
6
|
+
return `=${value}`;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
function* args(options) {
|
|
12
|
+
const { suppressWarnings = true, format = 'svg', attributes = {}, library = [], y = false, scale } = options;
|
|
13
|
+
if (suppressWarnings) yield '-q';
|
|
14
|
+
yield `-T${format}`;
|
|
15
|
+
if (attributes.graph) {
|
|
16
|
+
for (const [key, value] of Object.entries(attributes.graph)) {
|
|
17
|
+
yield `-G${key}${escapeValue(value)}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (attributes.node) {
|
|
21
|
+
for (const [key, value] of Object.entries(attributes.node)) {
|
|
22
|
+
yield `-N${key}${escapeValue(value)}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (attributes.edge) {
|
|
26
|
+
for (const [key, value] of Object.entries(attributes.edge)) {
|
|
27
|
+
yield `-E${key}${escapeValue(value)}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (typeof scale === 'number' && !Number.isNaN(scale)) yield `-s${scale}`;
|
|
31
|
+
if (Array.isArray(library)) for (const lib of library) yield `-l${lib}`;
|
|
32
|
+
if (y === true) yield `-y`;
|
|
33
|
+
if (typeof options.layout === 'string') {
|
|
34
|
+
yield `-K${options.layout}`;
|
|
35
|
+
switch (options.layout) {
|
|
36
|
+
case 'neato':
|
|
37
|
+
const { reduce, noop } = options;
|
|
38
|
+
if (reduce === true) yield '-x';
|
|
39
|
+
if (typeof noop === 'number') yield `-n${noop}`;
|
|
40
|
+
break;
|
|
41
|
+
case 'fdp':
|
|
42
|
+
const { grid, oldAttractive, iterations, unscaledFactor, overlapExpansionFactor, temperature } = options;
|
|
43
|
+
yield ['-L', grid ? '' : 'g', oldAttractive ? 'O' : ''].join('');
|
|
44
|
+
if (typeof iterations === 'number') yield `-Ln${iterations}`;
|
|
45
|
+
if (typeof unscaledFactor === 'number') yield `-LU${unscaledFactor}`;
|
|
46
|
+
if (typeof overlapExpansionFactor === 'number') yield `-LC${overlapExpansionFactor}`;
|
|
47
|
+
if (typeof temperature === 'number') yield `-LT${temperature}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function commandBuilder(options) {
|
|
52
|
+
return [options.dotCommand ?? 'dot', Array.from(args(options))];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { commandBuilder };
|
package/package.json
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
"name": "ts-graphviz",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"author": "kamiazya <yuki@kamiazya.tech>",
|
|
5
|
+
"description": "Graphviz library for TypeScript.",
|
|
6
|
+
"homepage": "https://ts-graphviz.github.io/ts-graphviz/",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/ts-graphviz/ts-graphviz.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"graphviz",
|
|
14
|
+
"dot"
|
|
15
|
+
],
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/ts-graphviz/ts-graphviz/issues"
|
|
18
|
+
},
|
|
19
|
+
"funding": {
|
|
20
|
+
"type": "github",
|
|
21
|
+
"url": "https://github.com/sponsors/kamiazya"
|
|
22
|
+
},
|
|
23
|
+
"main": "./lib/index.cjs",
|
|
24
|
+
"module": "./lib/index.js",
|
|
25
|
+
"types": "lib/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./lib/index.d.ts",
|
|
30
|
+
"default": "./lib/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./lib/index.d.ts",
|
|
34
|
+
"default": "./lib/index.js"
|
|
35
|
+
}
|
|
11
36
|
},
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
"./ast": {
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./lib/ast/index.d.ts",
|
|
40
|
+
"default": "./lib/ast/index.cjs"
|
|
41
|
+
},
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./lib/ast/index.d.ts",
|
|
44
|
+
"default": "./lib/ast/index.js"
|
|
45
|
+
}
|
|
18
46
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
47
|
+
"./adapter": {
|
|
48
|
+
"browser": {
|
|
49
|
+
"require": "./lib/adapter/browser/index.cjs",
|
|
50
|
+
"import": "./lib/adapter/browser/index.js",
|
|
51
|
+
"types": "./lib/adapter/browser/index.d.ts"
|
|
52
|
+
},
|
|
53
|
+
"deno": {
|
|
54
|
+
"types": "./lib/adapter/deno/mod.d.ts",
|
|
55
|
+
"default": "./lib/adapter/deno/mod.js"
|
|
56
|
+
},
|
|
57
|
+
"node": {
|
|
58
|
+
"require": "./lib/adapter/node/index.cjs",
|
|
59
|
+
"import": "./lib/adapter/node/index.js",
|
|
60
|
+
"types": "./lib/adapter/node/index.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"default": {
|
|
63
|
+
"types": "./lib/adapter/node/index.d.ts",
|
|
64
|
+
"require": "./lib/adapter/node/index.cjs",
|
|
65
|
+
"import": "./lib/adapter/node/index.js"
|
|
66
|
+
}
|
|
22
67
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"types": "./lib/index.d.ts",
|
|
34
|
-
"default": "./lib/index.js"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"./ast": {
|
|
38
|
-
"require": {
|
|
39
|
-
"types": "./lib/ast/index.d.ts",
|
|
40
|
-
"default": "./lib/ast/index.cjs"
|
|
41
|
-
},
|
|
42
|
-
"import": {
|
|
43
|
-
"types": "./lib/ast/index.d.ts",
|
|
44
|
-
"default": "./lib/ast/index.js"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"./adapter": {
|
|
48
|
-
"browser": {
|
|
49
|
-
"require": "./lib/adapter/browser/index.cjs",
|
|
50
|
-
"import": "./lib/adapter/browser/index.js",
|
|
51
|
-
"types": "./lib/adapter/browser/index.d.ts"
|
|
52
|
-
},
|
|
53
|
-
"deno": {
|
|
54
|
-
"types": "./lib/adapter/deno/mod.d.ts",
|
|
55
|
-
"default": "./lib/adapter/deno/mod.js"
|
|
56
|
-
},
|
|
57
|
-
"node": {
|
|
58
|
-
"require": "./lib/adapter/node/index.cjs",
|
|
59
|
-
"import": "./lib/adapter/node/index.js",
|
|
60
|
-
"types": "./lib/adapter/node/index.d.ts"
|
|
61
|
-
},
|
|
62
|
-
"default": {
|
|
63
|
-
"types": "./lib/adapter/node/index.d.ts",
|
|
64
|
-
"require": "./lib/adapter/node/index.cjs",
|
|
65
|
-
"import": "./lib/adapter/node/index.js"
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
"./package.json": "./package.json"
|
|
69
|
-
},
|
|
70
|
-
"typesVersions": {
|
|
71
|
-
"*": {
|
|
72
|
-
"ast": [
|
|
73
|
-
"lib/ast"
|
|
74
|
-
],
|
|
75
|
-
"adapter": [
|
|
76
|
-
"lib/adapter/node"
|
|
77
|
-
]
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"license": "MIT",
|
|
81
|
-
"engines": {
|
|
82
|
-
"node": ">=14.16"
|
|
83
|
-
},
|
|
84
|
-
"scripts": {
|
|
85
|
-
"build:peggy": "peggy --plugin ts-pegjs --extra-options-file src/ast/dot-shim/parser/peggy.options.json -o src/ast/dot-shim/parser/_parse.ts src/ast/dot-shim/parser/dot.peggy",
|
|
86
|
-
"prebuild": "yarn build:peggy",
|
|
87
|
-
"build:deno": "cp -r src/adapter/deno lib/adapter/deno",
|
|
88
|
-
"build:node": "tsc -p tsconfig.build.json && rollup -c",
|
|
89
|
-
"build": "yarn build:node && yarn build:deno",
|
|
90
|
-
"postbuild": "prettier --write ./lib/**/index.{js,cjs,d.ts}",
|
|
91
|
-
"pretest": "yarn build:peggy",
|
|
92
|
-
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
|
|
93
|
-
"format": "eslint --ext ts src --fix && prettier --write './**/*.{ts,js,json,yaml}' '!lib'",
|
|
94
|
-
"lint": "eslint --ext ts src",
|
|
95
|
-
"predoc": "yarn build:peggy",
|
|
96
|
-
"doc": "typedoc"
|
|
97
|
-
},
|
|
98
|
-
"devDependencies": {
|
|
99
|
-
"@rollup/plugin-replace": "^4.0.0",
|
|
100
|
-
"@types/jest": "^28.1.6",
|
|
101
|
-
"@types/jest-specific-snapshot": "^0.5.6",
|
|
102
|
-
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
103
|
-
"@typescript-eslint/parser": "^5.33.0",
|
|
104
|
-
"eslint": "^8.22.0",
|
|
105
|
-
"eslint-config-prettier": "^8.5.0",
|
|
106
|
-
"eslint-plugin-import": "^2.26.0",
|
|
107
|
-
"eslint-plugin-jest": "^26.8.2",
|
|
108
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
109
|
-
"jest": "^28.1.3",
|
|
110
|
-
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
111
|
-
"jest-specific-snapshot": "^5.0.0",
|
|
112
|
-
"peggy": "^2.0.1",
|
|
113
|
-
"prettier": "^2.7.1",
|
|
114
|
-
"prettier-plugin-pegjs": "^0.5.0",
|
|
115
|
-
"rollup": "^2.77.3",
|
|
116
|
-
"rollup-plugin-delete": "^2.0.0",
|
|
117
|
-
"rollup-plugin-dts": "^4.2.2",
|
|
118
|
-
"svgo": "^2.8.0",
|
|
119
|
-
"ts-jest": "^28.0.7",
|
|
120
|
-
"ts-pegjs": "^2.1.0",
|
|
121
|
-
"typedoc": "^0.23.15",
|
|
122
|
-
"typescript": "^4.7.4"
|
|
68
|
+
"./package.json": "./package.json"
|
|
69
|
+
},
|
|
70
|
+
"typesVersions": {
|
|
71
|
+
"*": {
|
|
72
|
+
"ast": [
|
|
73
|
+
"lib/ast"
|
|
74
|
+
],
|
|
75
|
+
"adapter": [
|
|
76
|
+
"lib/adapter/node"
|
|
77
|
+
]
|
|
123
78
|
}
|
|
124
|
-
}
|
|
79
|
+
},
|
|
80
|
+
"license": "MIT",
|
|
81
|
+
"engines": {
|
|
82
|
+
"node": ">=14.16"
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build:peggy": "peggy --plugin ts-pegjs --extra-options-file src/ast/dot-shim/parser/peggy.options.json -o src/ast/dot-shim/parser/_parse.ts src/ast/dot-shim/parser/dot.peggy",
|
|
86
|
+
"prebuild": "yarn build:peggy",
|
|
87
|
+
"build:deno": "mkdir -p lib/adapter/deno && cp -r src/adapter/deno/* lib/adapter/deno && sed -i \"s/index.ts/index.js/g\" lib/adapter/deno/mod.js && sed -i \"s/index.ts/index.d.ts/g\" lib/adapter/deno/mod.d.ts",
|
|
88
|
+
"build:node": "tsc -p tsconfig.build.json && rollup -c",
|
|
89
|
+
"build": "yarn build:node && yarn build:deno",
|
|
90
|
+
"postbuild": "prettier --write ./lib/**/*.{js,cjs,d.ts}",
|
|
91
|
+
"pretest": "yarn build:peggy",
|
|
92
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
|
|
93
|
+
"format": "eslint --ext ts src --fix && prettier --write './**/*.{ts,js,json,yaml}' '!lib'",
|
|
94
|
+
"lint": "eslint --ext ts src",
|
|
95
|
+
"predoc": "yarn build:peggy",
|
|
96
|
+
"doc": "typedoc"
|
|
97
|
+
},
|
|
98
|
+
"devDependencies": {
|
|
99
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
100
|
+
"@types/jest": "^28.1.6",
|
|
101
|
+
"@types/jest-specific-snapshot": "^0.5.6",
|
|
102
|
+
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
103
|
+
"@typescript-eslint/parser": "^5.33.0",
|
|
104
|
+
"eslint": "^8.22.0",
|
|
105
|
+
"eslint-config-prettier": "^8.5.0",
|
|
106
|
+
"eslint-plugin-import": "^2.26.0",
|
|
107
|
+
"eslint-plugin-jest": "^26.8.2",
|
|
108
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
109
|
+
"jest": "^28.1.3",
|
|
110
|
+
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
111
|
+
"jest-specific-snapshot": "^5.0.0",
|
|
112
|
+
"peggy": "^2.0.1",
|
|
113
|
+
"prettier": "^2.7.1",
|
|
114
|
+
"prettier-plugin-pegjs": "^0.5.0",
|
|
115
|
+
"rollup": "^2.77.3",
|
|
116
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
117
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
118
|
+
"svgo": "^2.8.0",
|
|
119
|
+
"ts-jest": "^28.0.7",
|
|
120
|
+
"ts-pegjs": "^2.1.0",
|
|
121
|
+
"typedoc": "^0.23.15",
|
|
122
|
+
"typescript": "^4.7.4"
|
|
123
|
+
}
|
|
124
|
+
}
|