@rse/gradia 0.9.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.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /*!
3
+ ** Gradia -- Object Graph Diagram Rendering
4
+ ** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
5
+ ** Distributed under MIT license <https://spdx.org/licenses/MIT.html>
6
+ */
7
+ export {};
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ /*!
3
+ ** Gradia -- Object Graph Diagram Rendering
4
+ ** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
5
+ ** Distributed under MIT license <https://spdx.org/licenses/MIT.html>
6
+ */
7
+ /* built-in dependencies */
8
+ import fs from "node:fs";
9
+ import process from "node:process";
10
+ import { fileURLToPath } from "node:url";
11
+ /* external dependencies */
12
+ import { Command, Option } from "commander";
13
+ /* internal dependencies */
14
+ import { configDefaults } from "./gradia-api-config.js";
15
+ import { Gradia, diagramTypes, diagramTypeDefault, diagramFormats, diagramFormatDefault } from "./gradia-api.js";
16
+ /* internal package meta-information */
17
+ const pkg = JSON.parse(fs.readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8"));
18
+ /* establish the command-line interface */
19
+ const program = new Command();
20
+ program.name("gradia")
21
+ .description(pkg.description)
22
+ .version(pkg.version)
23
+ .requiredOption("-o, --output <file>", "output SVG file")
24
+ .addOption(new Option("-t, --type <type>", "diagram type")
25
+ .choices(diagramTypes).default(diagramTypeDefault))
26
+ .addOption(new Option("-f, --format <format>", "output format")
27
+ .choices(diagramFormats).default(diagramFormatDefault))
28
+ .option("-c, --config <name>=<value>", "rendering configuration option (repeatable)", (nv, prev) => prev.concat(nv), [])
29
+ .argument("<input>", "input graph description file")
30
+ .action(async (input, options) => {
31
+ /* parse and validate the rendering configuration options */
32
+ const config = {};
33
+ const store = config;
34
+ for (const nv of options.config) {
35
+ const m = /^([a-z][a-z0-9-]*)=(.*)$/.exec(nv);
36
+ if (m === null)
37
+ throw new Error(`invalid configuration option "${nv}" (expected "<name>=<value>")`);
38
+ const key = m[1];
39
+ if (!Object.hasOwn(configDefaults, key))
40
+ throw new Error(`unknown configuration option "${m[1]}"`);
41
+ store[key] = typeof configDefaults[key] === "boolean" ? m[2] === "true" : m[2];
42
+ }
43
+ /* read the input, render the diagram, and write the output */
44
+ const text = fs.readFileSync(input, "utf8");
45
+ const out = await Gradia.render(text, { type: options.type, format: options.format, config });
46
+ fs.writeFileSync(options.output, out, "utf8");
47
+ });
48
+ /* run the command-line interface */
49
+ program.parseAsync().catch((err) => {
50
+ process.stderr.write(`gradia: ERROR: ${err instanceof Error ? err.message : String(err)}\n`);
51
+ process.exitCode = 1;
52
+ });
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@rse/gradia",
3
+ "description": "Object Graph Diagram Rendering",
4
+ "keywords": [ "object", "graph", "diagram", "rendering", "svg", "layout", "api", "cli" ],
5
+ "publishConfig": { "access": "public" },
6
+ "version": "0.9.0",
7
+ "license": "MIT",
8
+ "author": {
9
+ "name": "Dr. Ralf S. Engelschall",
10
+ "email": "rse@engelschall.com",
11
+ "url": "http://engelschall.com"
12
+ },
13
+ "homepage": "https://github.com/rse/gradia",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/rse/gradia.git"
17
+ },
18
+ "main": "dst/gradia-api.js",
19
+ "types": "dst/gradia-api.d.ts",
20
+ "bin": {
21
+ "gradia": "dst/gradia-cli.js"
22
+ },
23
+ "files": [ "dst" ],
24
+ "type": "module",
25
+ "dependencies": {
26
+ "commander": "15.0.0",
27
+ "@antv/layout": "2.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "eslint": "9.39.5",
31
+ "@eslint/js": "9.39.5",
32
+ "typescript-eslint": "8.67.0",
33
+ "eslint-plugin-promise": "7.3.0",
34
+ "eslint-plugin-import": "2.32.0",
35
+ "neostandard": "0.13.0",
36
+ "globals": "17.11.0",
37
+ "typescript": "6.0.3",
38
+ "@types/node": "26.2.0",
39
+ "@rse/stx": "1.1.6",
40
+ "shx": "0.4.0",
41
+ "nodemon": "3.1.14"
42
+ },
43
+ "engines": {
44
+ "node": ">=22.0.0"
45
+ },
46
+ "allowScripts": {
47
+ "fsevents": true
48
+ },
49
+ "scripts": {
50
+ "start": "stx -v4 -l warning -c etc/stx.conf"
51
+ }
52
+ }