state-machine-cat 12.0.12 → 12.0.14

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,170 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { parseArgs } from "node:util";
3
+ import satisfies from "semver/functions/satisfies.js";
4
+ import { formatError, displayLicense, transform } from "./actions.mjs";
5
+ import normalize from "./normalize.mjs";
6
+ import validations from "./validations.mjs";
7
+ const $package = JSON.parse(
8
+ readFileSync(new URL("../../package.json", import.meta.url), "utf8"),
9
+ );
10
+ const HELP_TEXT = `Usage: smcat [options] [infile]
11
+
12
+ Write beautiful state charts - https://github.com/sverweij/state-machine-cat
13
+
14
+ Options:
15
+ -T, --output-type <type> ast|dot|eps|json|oldeps|oldps|oldps2|oldsvg|pdf|
16
+ png|ps|ps2|scjson|scxml|smcat|svg
17
+ (default: "svg")
18
+ -I, --input-type <type> smcat|json|scxml (default: "smcat")
19
+ -E, --engine <type> dot|circo|fdp|neato|osage|twopi (default: "dot")
20
+ -d, --direction <dir> top-down|bottom-top|left-right|right-left (default:
21
+ "top-down")
22
+ -o --output-to <file> File to write to. use - for stdout.
23
+ --desugar transform pseudo states into transitions
24
+ (!experimental!)
25
+ -V, --version output the version number
26
+ -l, --license Display license and exit
27
+ -h, --help display help for command
28
+ `;
29
+ function presentError(pError, pErrorStream) {
30
+ pErrorStream.write(formatError(pError));
31
+ process.exitCode = 1;
32
+ }
33
+ function kebabToCamel(pString) {
34
+ return pString
35
+ .split("-")
36
+ .map((pWord, pIndex) =>
37
+ pIndex === 0
38
+ ? pWord
39
+ : pWord.charAt(0).toUpperCase() + pWord.slice(1).toLowerCase(),
40
+ )
41
+ .join("");
42
+ }
43
+ function camelizeObject(pObject) {
44
+ const lNewObject = {};
45
+ for (const lKey in pObject) {
46
+ if (Object.hasOwn(pObject, lKey)) {
47
+ const camelCaseKey = kebabToCamel(lKey);
48
+ lNewObject[camelCaseKey] = pObject[lKey];
49
+ }
50
+ }
51
+ return lNewObject;
52
+ }
53
+ function parseArguments(pArguments) {
54
+ const lOptions = {
55
+ "output-type": {
56
+ type: "string",
57
+ short: "T",
58
+ default: validations.defaultOutputType,
59
+ },
60
+ "input-type": {
61
+ type: "string",
62
+ short: "I",
63
+ default: validations.defaultInputType,
64
+ },
65
+ engine: {
66
+ type: "string",
67
+ short: "E",
68
+ default: validations.defaultEngine,
69
+ },
70
+ direction: {
71
+ type: "string",
72
+ short: "d",
73
+ default: validations.defaultDirection,
74
+ },
75
+ "output-to": {
76
+ type: "string",
77
+ short: "o",
78
+ },
79
+ "dot-graph-attrs": {
80
+ type: "string",
81
+ },
82
+ "dot-node-attrs": {
83
+ type: "string",
84
+ },
85
+ "dot-edge-attrs": {
86
+ type: "string",
87
+ },
88
+ desugar: {
89
+ type: "boolean",
90
+ default: false,
91
+ },
92
+ license: {
93
+ type: "boolean",
94
+ short: "l",
95
+ default: false,
96
+ },
97
+ help: {
98
+ type: "boolean",
99
+ short: "h",
100
+ default: false,
101
+ },
102
+ version: {
103
+ type: "boolean",
104
+ short: "V",
105
+ default: false,
106
+ },
107
+ };
108
+ const { values, positionals } = parseArgs({
109
+ args: pArguments,
110
+ options: lOptions,
111
+ strict: true,
112
+ allowPositionals: true,
113
+ tokens: false,
114
+ });
115
+ values["output-type"] = validations.validOutputType(values["output-type"]);
116
+ values["input-type"] = validations.validInputType(values["input-type"]);
117
+ values.engine = validations.validEngine(values.engine);
118
+ values.direction = validations.validDirection(values.direction);
119
+ if (values["dot-graph-attrs"])
120
+ values["dot-graph-attrs"] = validations.validDotAttrs(
121
+ values["dot-graph-attrs"],
122
+ );
123
+ if (values["dot-node-attrs"])
124
+ values["dot-node-attrs"] = validations.validDotAttrs(
125
+ values["dot-node-attrs"],
126
+ );
127
+ if (values["dot-edge-attrs"])
128
+ values["dot-edge-attrs"] = validations.validDotAttrs(
129
+ values["dot-edge-attrs"],
130
+ );
131
+ return { values: camelizeObject(values), positionals };
132
+ }
133
+ function assertNodeVersion(pCurrentNodeVersion, pSupportedEngines) {
134
+ if (!satisfies(pCurrentNodeVersion, pSupportedEngines)) {
135
+ throw new Error(
136
+ `\nERROR: your node version (${pCurrentNodeVersion}) is not recent enough.\n` +
137
+ ` state-machine-cat is supported on node ${pSupportedEngines}\n\n`,
138
+ );
139
+ }
140
+ }
141
+ export default async function cli(pArguments = process.argv, pOptions) {
142
+ const lOptions = {
143
+ currentNodeVersion: process.versions.node,
144
+ supportedEngines: $package.engines.node,
145
+ outStream: process.stdout,
146
+ errorStream: process.stderr,
147
+ ...pOptions,
148
+ };
149
+ try {
150
+ assertNodeVersion(lOptions.currentNodeVersion, lOptions.supportedEngines);
151
+ const { values, positionals } = parseArguments(pArguments.slice(2));
152
+ if (values.help) {
153
+ lOptions.outStream.write(HELP_TEXT, "utf8");
154
+ return;
155
+ }
156
+ if (values.version) {
157
+ lOptions.outStream.write(`${$package.version}\n`, "utf8");
158
+ return;
159
+ }
160
+ if (values.license) {
161
+ displayLicense(lOptions.outStream);
162
+ return;
163
+ }
164
+ await transform(
165
+ validations.validateArguments(normalize(positionals[0], values)),
166
+ );
167
+ } catch (pError) {
168
+ presentError(pError, lOptions.errorStream);
169
+ }
170
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import cli from "./cli.mjs";
3
+ await cli();
@@ -1,4 +1,4 @@
1
- import { Graphviz } from "@hpcc-js/wasm/graphviz";
1
+ import { Graphviz } from "@hpcc-js/wasm-graphviz";
2
2
  import options from "../../options.mjs";
3
3
  import ast2dot from "../dot/index.mjs";
4
4
  import dotToVectorNative from "./dot-to-vector-native.mjs";
@@ -1,4 +1,4 @@
1
- import { Graphviz } from "@hpcc-js/wasm/graphviz";
1
+ import { Graphviz } from "@hpcc-js/wasm-graphviz";
2
2
  import options from "../../options.mjs";
3
3
  import ast2dot from "../dot/index.mjs";
4
4
  const OUTPUT_TYPE2FORMAT = {
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "12.0.12";
1
+ export const version = "12.0.14";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-machine-cat",
3
- "version": "12.0.12",
3
+ "version": "12.0.14",
4
4
  "description": "write beautiful state charts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -24,7 +24,6 @@
24
24
  "dist/render/scxml/scxml.template.js"
25
25
  ],
26
26
  "files": [
27
- "bin/",
28
27
  "dist/",
29
28
  "types/",
30
29
  "package.json",
@@ -44,15 +43,12 @@
44
43
  "author": "Sander Verweij",
45
44
  "license": "MIT",
46
45
  "bin": {
47
- "smcat": "bin/smcat.mjs",
48
- "sm-cat": "bin/smcat.mjs",
49
- "sm_cat": "bin/smcat.mjs",
50
- "state-machine-cat": "bin/smcat.mjs"
46
+ "smcat": "dist/cli/main.mjs",
47
+ "state-machine-cat": "dist/cli/main.mjs"
51
48
  },
52
49
  "dependencies": {
53
- "@hpcc-js/wasm": "2.18.0",
50
+ "@hpcc-js/wasm-graphviz": "1.2.0",
54
51
  "ajv": "8.17.1",
55
- "commander": "12.1.0",
56
52
  "fast-xml-parser": "4.4.1",
57
53
  "handlebars": "4.7.8",
58
54
  "he": "1.2.0",
package/bin/smcat.mjs DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- // @ts-check
3
- import executeCommandLine from "../dist/cli/execute-command-line.mjs";
4
-
5
- await executeCommandLine();
@@ -1,111 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { Command, Option } from "commander";
3
- import satisfies from "semver/functions/satisfies.js";
4
- import { formatError, displayLicense, transform } from "./actions.mjs";
5
- import normalize from "./normalize.mjs";
6
- import validations from "./validations.mjs";
7
- const $package = JSON.parse(
8
- readFileSync(new URL("../../package.json", import.meta.url), "utf8"),
9
- );
10
- function presentError(pError, pErrorStream) {
11
- pErrorStream.write(formatError(pError));
12
- process.exitCode = 1;
13
- }
14
- function parseArguments(pArguments) {
15
- return new Command()
16
- .description(
17
- "Write beautiful state charts - https://github.com/sverweij/state-machine-cat",
18
- )
19
- .option(
20
- "-T, --output-type <type>",
21
- validations.validOutputTypeRE,
22
- validations.validOutputType,
23
- validations.defaultOutputType,
24
- )
25
- .option(
26
- "-I, --input-type <type>",
27
- validations.validInputTypeRE,
28
- validations.validInputType,
29
- validations.defaultInputType,
30
- )
31
- .option(
32
- "-E, --engine <type>",
33
- validations.validEngineRE,
34
- validations.validEngine,
35
- validations.defaultEngine,
36
- )
37
- .option(
38
- "-d, --direction <dir>",
39
- validations.validDirectionRE,
40
- validations.validDirection,
41
- validations.defaultDirection,
42
- )
43
- .option("-o --output-to <file>", "File to write to. use - for stdout.")
44
- .addOption(
45
- new Option(
46
- "--dot-graph-attrs <string>",
47
- "graph attributes to pass to the dot render engine",
48
- )
49
- .argParser(validations.validDotAttrs)
50
- .hideHelp(true),
51
- )
52
- .addOption(
53
- new Option(
54
- "--dot-node-attrs <string>",
55
- "node attributes to pass to the dot render engine",
56
- )
57
- .argParser(validations.validDotAttrs)
58
- .hideHelp(true),
59
- )
60
- .addOption(
61
- new Option(
62
- "--dot-edge-attrs <string>",
63
- "edge attributes to pass to the dot render engine",
64
- )
65
- .argParser(validations.validDotAttrs)
66
- .hideHelp(true),
67
- )
68
- .option(
69
- "--desugar",
70
- "transform pseudo states into transitions (!experimental!)",
71
- )
72
- .version($package.version)
73
- .option("-l, --license", "Display license and exit")
74
- .arguments("[infile]")
75
- .parse(pArguments);
76
- }
77
- function assertNodeVersion(pCurrentNodeVersion, pSupportedEngines) {
78
- if (!satisfies(pCurrentNodeVersion, pSupportedEngines)) {
79
- throw new Error(
80
- `\nERROR: your node version (${pCurrentNodeVersion}) is not recent enough.\n` +
81
- ` state-machine-cat is supported on node ${pSupportedEngines}\n\n`,
82
- );
83
- }
84
- }
85
- export default async function executeCommandLine(
86
- pArguments = process.argv,
87
- pOptions,
88
- ) {
89
- const lOptions = {
90
- currentNodeVersion: process.versions.node,
91
- supportedEngines: $package.engines.node,
92
- outStream: process.stdout,
93
- errorStream: process.stderr,
94
- ...pOptions,
95
- };
96
- try {
97
- assertNodeVersion(lOptions.currentNodeVersion, lOptions.supportedEngines);
98
- const lProgram = parseArguments(pArguments);
99
- if (lProgram.opts()?.license) {
100
- displayLicense(lOptions.outStream);
101
- return;
102
- }
103
- await transform(
104
- validations.validateArguments(
105
- normalize(lProgram.args[0], lProgram.opts()),
106
- ),
107
- );
108
- } catch (pError) {
109
- presentError(pError, lOptions.errorStream);
110
- }
111
- }