state-machine-cat 11.0.6 → 11.1.1

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.
Files changed (46) hide show
  1. package/README.md +16 -10
  2. package/bin/smcat.mjs +2 -100
  3. package/dist/{esm/cli → cli}/actions.mjs +25 -25
  4. package/dist/cli/execute-command-line.mjs +61 -0
  5. package/dist/version.mjs +1 -0
  6. package/package.json +20 -20
  7. package/dist/esm/version.mjs +0 -1
  8. /package/dist/{esm/cli → cli}/attributes-parser.mjs +0 -0
  9. /package/dist/{esm/cli → cli}/file-name-to-stream.mjs +0 -0
  10. /package/dist/{esm/cli → cli}/normalize.mjs +0 -0
  11. /package/dist/{esm/cli → cli}/validations.mjs +0 -0
  12. /package/dist/{esm/index-node.mjs → index-node.mjs} +0 -0
  13. /package/dist/{esm/index.mjs → index.mjs} +0 -0
  14. /package/dist/{esm/options.mjs → options.mjs} +0 -0
  15. /package/dist/{esm/parse → parse}/index.mjs +0 -0
  16. /package/dist/{esm/parse → parse}/parser-helpers.mjs +0 -0
  17. /package/dist/{esm/parse → parse}/scxml/index.mjs +0 -0
  18. /package/dist/{esm/parse → parse}/scxml/normalize-machine.mjs +0 -0
  19. /package/dist/{esm/parse → parse}/smcat/smcat-parser.mjs +0 -0
  20. /package/dist/{esm/parse → parse}/smcat-ast.schema.mjs +0 -0
  21. /package/dist/{esm/render → render}/dot/attributebuilder.mjs +0 -0
  22. /package/dist/{esm/render → render}/dot/counter.mjs +0 -0
  23. /package/dist/{esm/render → render}/dot/dot.states.template.js +0 -0
  24. /package/dist/{esm/render → render}/dot/dot.template.js +0 -0
  25. /package/dist/{esm/render → render}/dot/index.mjs +0 -0
  26. /package/dist/{esm/render → render}/dot/render-dot-from-ast.mjs +0 -0
  27. /package/dist/{esm/render → render}/dot/state-transformers.mjs +0 -0
  28. /package/dist/{esm/render → render}/dot/transition-transformers.mjs +0 -0
  29. /package/dist/{esm/render → render}/dot/utl.mjs +0 -0
  30. /package/dist/{esm/render → render}/index-node.mjs +0 -0
  31. /package/dist/{esm/render → render}/index.mjs +0 -0
  32. /package/dist/{esm/render → render}/scjson/index.mjs +0 -0
  33. /package/dist/{esm/render → render}/scjson/make-valid-event-names.mjs +0 -0
  34. /package/dist/{esm/render → render}/scjson/make-valid-xml-name.mjs +0 -0
  35. /package/dist/{esm/render → render}/scxml/index.mjs +0 -0
  36. /package/dist/{esm/render → render}/scxml/render-from-scjson.mjs +0 -0
  37. /package/dist/{esm/render → render}/scxml/scxml.states.template.js +0 -0
  38. /package/dist/{esm/render → render}/scxml/scxml.template.js +0 -0
  39. /package/dist/{esm/render → render}/smcat/index.mjs +0 -0
  40. /package/dist/{esm/render → render}/smcat/smcat.template.js +0 -0
  41. /package/dist/{esm/render → render}/vector/dot-to-vector-native.mjs +0 -0
  42. /package/dist/{esm/render → render}/vector/vector-native-dot-with-fallback.mjs +0 -0
  43. /package/dist/{esm/render → render}/vector/vector-with-wasm.mjs +0 -0
  44. /package/dist/{esm/state-machine-model.mjs → state-machine-model.mjs} +0 -0
  45. /package/dist/{esm/transform → transform}/desugar.mjs +0 -0
  46. /package/dist/{esm/transform → transform}/utl.mjs +0 -0
package/README.md CHANGED
@@ -82,9 +82,6 @@ Options:
82
82
  -E --engine <type> dot|circo|fdp|neato|osage|twopi (default: "dot")
83
83
  -d --direction <dir> top-down|bottom-top|left-right|right-left (default: "top-down")
84
84
  -o --output-to <file> File to write to. use - for stdout.
85
- --dot-graph-attrs <string> graph attributes to pass to the dot render engine
86
- --dot-node-attrs <string> node attributes to pass to the dot render engine
87
- --dot-edge-attrs <string> edge attributes to pass to the dot render engine
88
85
  --desugar transform pseudo states into transitions (!experimental!)
89
86
  -l --license Display license and exit
90
87
  -h, --help display help for command
@@ -105,18 +102,27 @@ bin/smcat -T dot docs/sample.smcat -o - | dot -T svg -odoc/sample.svg
105
102
  Leaving the options at the default settings usually deliver the best
106
103
  results already, so if they bewilder you: don't worry.
107
104
 
108
- The `--dot-graph-attrs` (and the node and edge variants thereof) exist in case you want
109
- to override default attributes in the generated picture; e.g. to get a transparent background
110
- and draw edges as line segments instead of splines, use this:
105
+ When you pass the `--desugar` (&tritime; experimental) switch, state-machine-cat will,
106
+ before rendering, transform some pseudo states into transitions - see
107
+ [de-sugaring state machines](docs/desugar.md) for details.
108
+
109
+ In addition to what's documented in the `--help` you can use the following 'advanced'
110
+ options:
111
+
112
+ ```
113
+ --dot-graph-attrs <string> graph attributes to pass to the dot render engine
114
+ --dot-node-attrs <string> node attributes to pass to the dot render engine
115
+ --dot-edge-attrs <string> edge attributes to pass to the dot render engine
116
+ ```
117
+
118
+ With these you can override default attributes in the generated picture; e.g. to
119
+ get a transparent background and draw edges as line segments instead of
120
+ splines, use this:
111
121
 
112
122
  ```sh
113
123
  bin/smcat --dot-graph-attrs "bgcolor=transparent splines=line" docs/sample.smcat
114
124
  ```
115
125
 
116
- When you pass the `--desugar` (&tritime; experimental) switch, state-machine-cat will,
117
- before rendering, transform some pseudo states into transitions - see
118
- [de-sugaring state machines](docs/desugar.md) for details.
119
-
120
126
  ### Syntax highlighting
121
127
 
122
128
  - For editors supporting tree sitter (like atom): there's [tree-sitter-smcat](https://github.com/sverweij/tree-sitter-smcat)
package/bin/smcat.mjs CHANGED
@@ -1,103 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  // @ts-check
3
- import { readFileSync } from "node:fs";
4
- import { program } from "commander";
5
- import satisfies from "semver/functions/satisfies.js";
6
- import actions from "../dist/esm/cli/actions.mjs";
7
- import normalize from "../dist/esm/cli/normalize.mjs";
8
- import validations from "../dist/esm/cli/validations.mjs";
3
+ import executeCommandLine from "../dist/cli/execute-command-line.mjs";
9
4
 
10
- const $package = JSON.parse(
11
- // eslint-disable-next-line security/detect-non-literal-fs-filename
12
- readFileSync(new URL("../package.json", import.meta.url), "utf8")
13
- );
14
-
15
- /* c8 ignore start */
16
- if (!satisfies(process.versions.node, $package.engines.node)) {
17
- process.stderr.write(
18
- `\nERROR: your node version (${process.versions.node}) is not recent enough.\n`
19
- );
20
- process.stderr.write(
21
- ` state-machine-cat is supported on node ${$package.engines.node}\n\n`
22
- );
23
-
24
- /* eslint node/no-process-exit: 0 */
25
- process.exit(-1);
26
- }
27
- /* c8 ignore stop */
28
-
29
- /**
30
- * @param {any} pError
31
- * @return {void}
32
- */
33
- function presentError(pError) {
34
- process.stderr.write(actions.formatError(pError));
35
-
36
- /* eslint no-process-exit:0 */
37
- process.exit(1);
38
- }
39
-
40
- try {
41
- program
42
- .version($package.version)
43
- .description(
44
- "Write beautiful state charts - https://github.com/sverweij/state-machine-cat"
45
- )
46
- .option(
47
- "-T --output-type <type>",
48
- validations.validOutputTypeRE,
49
- validations.validOutputType,
50
- validations.defaultOutputType
51
- )
52
- .option(
53
- "-I --input-type <type>",
54
- validations.validInputTypeRE,
55
- validations.validInputType,
56
- validations.defaultInputType
57
- )
58
- .option(
59
- "-E --engine <type>",
60
- validations.validEngineRE,
61
- validations.validEngine,
62
- validations.defaultEngine
63
- )
64
- .option(
65
- "-d --direction <dir>",
66
- validations.validDirectionRE,
67
- validations.validDirection,
68
- validations.defaultDirection
69
- )
70
- .option("-o --output-to <file>", "File to write to. use - for stdout.")
71
- .option(
72
- "--dot-graph-attrs <string>",
73
- "graph attributes to pass to the dot render engine",
74
- validations.validDotAttrs
75
- )
76
- .option(
77
- "--dot-node-attrs <string>",
78
- "node attributes to pass to the dot render engine",
79
- validations.validDotAttrs
80
- )
81
- .option(
82
- "--dot-edge-attrs <string>",
83
- "edge attributes to pass to the dot render engine",
84
- validations.validDotAttrs
85
- )
86
- .option(
87
- "--desugar",
88
- "transform pseudo states into transitions (!experimental!)"
89
- )
90
- .option("-l --license", "Display license and exit", () => {
91
- process.stdout.write(actions.LICENSE);
92
- process.exit(0);
93
- })
94
- .arguments("[infile]")
95
- .parse(process.argv);
96
- actions
97
- .transform(
98
- validations.validateArguments(normalize(program.args[0], program.opts()))
99
- )
100
- .catch(presentError);
101
- } catch (pError) {
102
- presentError(pError);
103
- }
5
+ await executeCommandLine();
@@ -40,29 +40,29 @@ function getStream(pStream) {
40
40
  });
41
41
  });
42
42
  }
43
- export default {
44
- LICENSE,
45
- transform(pOptions) {
46
- return getStream(getInStream(pOptions.inputFrom)).then((pInput) => {
47
- const lOutput = smcat.render(pInput, {
48
- inputType: pOptions.inputType,
49
- outputType: pOptions.outputType,
50
- engine: pOptions.engine,
51
- direction: pOptions.direction,
52
- dotGraphAttrs: pOptions.dotGraphAttrs,
53
- dotNodeAttrs: pOptions.dotNodeAttrs,
54
- dotEdgeAttrs: pOptions.dotEdgeAttrs,
55
- desugar: pOptions.desugar,
56
- });
57
- return getOutStream(pOptions.outputTo).write(typeof lOutput === "string"
58
- ? lOutput
59
- : JSON.stringify(lOutput, null, " "), "binary");
43
+ export function displayLicense(pOutStream) {
44
+ pOutStream.write(LICENSE, "utf8");
45
+ }
46
+ export function transform(pOptions) {
47
+ return getStream(getInStream(pOptions.inputFrom)).then((pInput) => {
48
+ const lOutput = smcat.render(pInput, {
49
+ inputType: pOptions.inputType,
50
+ outputType: pOptions.outputType,
51
+ engine: pOptions.engine,
52
+ direction: pOptions.direction,
53
+ dotGraphAttrs: pOptions.dotGraphAttrs,
54
+ dotNodeAttrs: pOptions.dotNodeAttrs,
55
+ dotEdgeAttrs: pOptions.dotEdgeAttrs,
56
+ desugar: pOptions.desugar,
60
57
  });
61
- },
62
- formatError(pError) {
63
- if (Boolean(pError.location)) {
64
- return `\n syntax error on line ${pError.location.start.line}, column ${pError.location.start.column}:\n ${pError.message}\n\n`;
65
- }
66
- return pError.message;
67
- },
68
- };
58
+ return getOutStream(pOptions.outputTo).write(typeof lOutput === "string"
59
+ ? lOutput
60
+ : JSON.stringify(lOutput, null, " "), "binary");
61
+ });
62
+ }
63
+ export function formatError(pError) {
64
+ if (Boolean(pError.location)) {
65
+ return `\n syntax error on line ${pError.location.start.line}, column ${pError.location.start.column}:\n ${pError.message}\n\n`;
66
+ }
67
+ return pError.message;
68
+ }
@@ -0,0 +1,61 @@
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(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
8
+ function presentError(pError, pErrorStream) {
9
+ pErrorStream.write(formatError(pError));
10
+ process.exitCode = 1;
11
+ }
12
+ function parseArguments(pArguments) {
13
+ return new Command()
14
+ .description("Write beautiful state charts - https://github.com/sverweij/state-machine-cat")
15
+ .option("-T, --output-type <type>", validations.validOutputTypeRE, validations.validOutputType, validations.defaultOutputType)
16
+ .option("-I, --input-type <type>", validations.validInputTypeRE, validations.validInputType, validations.defaultInputType)
17
+ .option("-E, --engine <type>", validations.validEngineRE, validations.validEngine, validations.defaultEngine)
18
+ .option("-d, --direction <dir>", validations.validDirectionRE, validations.validDirection, validations.defaultDirection)
19
+ .option("-o --output-to <file>", "File to write to. use - for stdout.")
20
+ .addOption(new Option("--dot-graph-attrs <string>", "graph attributes to pass to the dot render engine")
21
+ .argParser(validations.validDotAttrs)
22
+ .hideHelp(true))
23
+ .addOption(new Option("--dot-node-attrs <string>", "node attributes to pass to the dot render engine")
24
+ .argParser(validations.validDotAttrs)
25
+ .hideHelp(true))
26
+ .addOption(new Option("--dot-edge-attrs <string>", "edge attributes to pass to the dot render engine")
27
+ .argParser(validations.validDotAttrs)
28
+ .hideHelp(true))
29
+ .option("--desugar", "transform pseudo states into transitions (!experimental!)")
30
+ .version($package.version)
31
+ .option("-l, --license", "Display license and exit")
32
+ .arguments("[infile]")
33
+ .parse(pArguments);
34
+ }
35
+ function assertNodeVersion(pCurrentNodeVersion, pSupportedEngines) {
36
+ if (!satisfies(pCurrentNodeVersion, pSupportedEngines)) {
37
+ throw new Error(`\nERROR: your node version (${pCurrentNodeVersion}) is not recent enough.\n` +
38
+ ` state-machine-cat is supported on node ${pSupportedEngines}\n\n`);
39
+ }
40
+ }
41
+ export default async function executeCommandLine(pArguments = process.argv, pOptions) {
42
+ const lOptions = {
43
+ currentNodeVersion: process.versions.node,
44
+ supportedEngines: $package.engines.node,
45
+ outStream: process.stdout,
46
+ errorStream: process.stderr,
47
+ ...pOptions,
48
+ };
49
+ try {
50
+ assertNodeVersion(lOptions.currentNodeVersion, lOptions.supportedEngines);
51
+ const lProgram = parseArguments(pArguments);
52
+ if (lProgram.opts()?.license) {
53
+ displayLicense(lOptions.outStream);
54
+ return;
55
+ }
56
+ await transform(validations.validateArguments(normalize(lProgram.args[0], lProgram.opts())));
57
+ }
58
+ catch (pError) {
59
+ presentError(pError, lOptions.errorStream);
60
+ }
61
+ }
@@ -0,0 +1 @@
1
+ export const version = "11.1.1";
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "state-machine-cat",
3
- "version": "11.0.6",
3
+ "version": "11.1.1",
4
4
  "description": "write beautiful state charts",
5
- "main": "./dist/esm/index.mjs",
6
- "module": "./dist/esm/index.mjs",
5
+ "main": "./dist/index.mjs",
6
+ "module": "./dist/index.mjs",
7
7
  "exports": {
8
8
  ".": [
9
9
  {
10
- "import": "./dist/esm/index.mjs"
10
+ "import": "./dist/index.mjs"
11
11
  }
12
12
  ]
13
13
  },
14
14
  "sideEffects": [
15
- "dist/esm/render/smcat/smcat.template.js",
16
- "dist/esm/render/dot/dot.states.template.js",
17
- "dist/esm/render/dot/dot.template.js",
18
- "dist/esm/render/scxml/scxml.states.template.js",
19
- "dist/esm/render/scxml/scxml.template.js"
15
+ "dist/render/smcat/smcat.template.js",
16
+ "dist/render/dot/dot.states.template.js",
17
+ "dist/render/dot/dot.template.js",
18
+ "dist/render/scxml/scxml.states.template.js",
19
+ "dist/render/scxml/scxml.template.js"
20
20
  ],
21
21
  "scripts": {
22
- "build": "make clean dist pages cli-build && rm -rf dist/esm && tsc",
22
+ "build": "make clean dist pages cli-build && rm -rf dist && tsc",
23
23
  "check": "run-s depcruise lint test:cover",
24
24
  "depcruise": "dependency-cruise bin src test types tools --config config/dependency-cruiser/base.mjs",
25
25
  "depcruise:graph": "run-s depcruise:graph:doc:archi depcruise:graph:doc:deps depcruise:graph:doc:flat-deps",
@@ -93,13 +93,13 @@
93
93
  "@hpcc-js/wasm": "2.13.0",
94
94
  "ajv": "8.12.0",
95
95
  "chalk": "5.2.0",
96
- "commander": "10.0.1",
97
- "fast-xml-parser": "4.2.4",
96
+ "commander": "11.0.0",
97
+ "fast-xml-parser": "4.2.5",
98
98
  "handlebars": "4.7.7",
99
99
  "he": "1.2.0",
100
100
  "indent-string": "5.0.0",
101
101
  "lodash": "4.17.21",
102
- "semver": "^7.5.1",
102
+ "semver": "^7.5.3",
103
103
  "traverse": "0.6.7",
104
104
  "wrap-ansi": "8.1.0"
105
105
  },
@@ -109,16 +109,16 @@
109
109
  "@types/he": "1.2.0",
110
110
  "@types/lodash": "4.14.195",
111
111
  "@types/mocha": "10.0.1",
112
- "@typescript-eslint/eslint-plugin": "5.59.9",
113
- "@typescript-eslint/parser": "5.59.9",
114
- "c8": "7.14.0",
112
+ "@typescript-eslint/eslint-plugin": "5.60.0",
113
+ "@typescript-eslint/parser": "5.60.0",
114
+ "c8": "8.0.0",
115
115
  "chai": "4.3.7",
116
116
  "chai-as-promised": "7.1.1",
117
117
  "chai-json-schema": "1.5.1",
118
118
  "chai-xml": "0.4.1",
119
- "dependency-cruiser": "13.0.3",
120
- "esbuild": "0.17.19",
121
- "eslint": "8.42.0",
119
+ "dependency-cruiser": "13.0.4",
120
+ "esbuild": "0.18.8",
121
+ "eslint": "8.43.0",
122
122
  "eslint-config-moving-meadow": "4.0.2",
123
123
  "eslint-config-prettier": "8.8.0",
124
124
  "eslint-plugin-budapestian": "5.0.1",
@@ -140,7 +140,7 @@
140
140
  "ts-node": "10.9.1",
141
141
  "typescript": "5.1.3",
142
142
  "upem": "8.0.0",
143
- "watskeburt": "0.11.3",
143
+ "watskeburt": "0.11.5",
144
144
  "xml-name-validator": "4.0.0"
145
145
  },
146
146
  "overrides": {
@@ -1 +0,0 @@
1
- export const version = "11.0.6";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes