state-machine-cat 11.1.0 → 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.
- package/bin/smcat.mjs +2 -109
- package/dist/{esm/cli → cli}/actions.mjs +25 -25
- package/dist/cli/execute-command-line.mjs +61 -0
- package/dist/version.mjs +1 -0
- package/package.json +13 -13
- package/dist/esm/version.mjs +0 -1
- /package/dist/{esm/cli → cli}/attributes-parser.mjs +0 -0
- /package/dist/{esm/cli → cli}/file-name-to-stream.mjs +0 -0
- /package/dist/{esm/cli → cli}/normalize.mjs +0 -0
- /package/dist/{esm/cli → cli}/validations.mjs +0 -0
- /package/dist/{esm/index-node.mjs → index-node.mjs} +0 -0
- /package/dist/{esm/index.mjs → index.mjs} +0 -0
- /package/dist/{esm/options.mjs → options.mjs} +0 -0
- /package/dist/{esm/parse → parse}/index.mjs +0 -0
- /package/dist/{esm/parse → parse}/parser-helpers.mjs +0 -0
- /package/dist/{esm/parse → parse}/scxml/index.mjs +0 -0
- /package/dist/{esm/parse → parse}/scxml/normalize-machine.mjs +0 -0
- /package/dist/{esm/parse → parse}/smcat/smcat-parser.mjs +0 -0
- /package/dist/{esm/parse → parse}/smcat-ast.schema.mjs +0 -0
- /package/dist/{esm/render → render}/dot/attributebuilder.mjs +0 -0
- /package/dist/{esm/render → render}/dot/counter.mjs +0 -0
- /package/dist/{esm/render → render}/dot/dot.states.template.js +0 -0
- /package/dist/{esm/render → render}/dot/dot.template.js +0 -0
- /package/dist/{esm/render → render}/dot/index.mjs +0 -0
- /package/dist/{esm/render → render}/dot/render-dot-from-ast.mjs +0 -0
- /package/dist/{esm/render → render}/dot/state-transformers.mjs +0 -0
- /package/dist/{esm/render → render}/dot/transition-transformers.mjs +0 -0
- /package/dist/{esm/render → render}/dot/utl.mjs +0 -0
- /package/dist/{esm/render → render}/index-node.mjs +0 -0
- /package/dist/{esm/render → render}/index.mjs +0 -0
- /package/dist/{esm/render → render}/scjson/index.mjs +0 -0
- /package/dist/{esm/render → render}/scjson/make-valid-event-names.mjs +0 -0
- /package/dist/{esm/render → render}/scjson/make-valid-xml-name.mjs +0 -0
- /package/dist/{esm/render → render}/scxml/index.mjs +0 -0
- /package/dist/{esm/render → render}/scxml/render-from-scjson.mjs +0 -0
- /package/dist/{esm/render → render}/scxml/scxml.states.template.js +0 -0
- /package/dist/{esm/render → render}/scxml/scxml.template.js +0 -0
- /package/dist/{esm/render → render}/smcat/index.mjs +0 -0
- /package/dist/{esm/render → render}/smcat/smcat.template.js +0 -0
- /package/dist/{esm/render → render}/vector/dot-to-vector-native.mjs +0 -0
- /package/dist/{esm/render → render}/vector/vector-native-dot-with-fallback.mjs +0 -0
- /package/dist/{esm/render → render}/vector/vector-with-wasm.mjs +0 -0
- /package/dist/{esm/state-machine-model.mjs → state-machine-model.mjs} +0 -0
- /package/dist/{esm/transform → transform}/desugar.mjs +0 -0
- /package/dist/{esm/transform → transform}/utl.mjs +0 -0
package/bin/smcat.mjs
CHANGED
|
@@ -1,112 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// @ts-check
|
|
3
|
-
import
|
|
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
|
-
|
|
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
|
-
.addOption(
|
|
72
|
-
// @ts-expect-error Option doesn't exist on Command - probably because it doesn't exist on the typedef
|
|
73
|
-
new program.Option(
|
|
74
|
-
"--dot-graph-attrs <string>",
|
|
75
|
-
"graph attributes to pass to the dot render engine",
|
|
76
|
-
validations.validDotAttrs
|
|
77
|
-
).hideHelp(true)
|
|
78
|
-
)
|
|
79
|
-
.addOption(
|
|
80
|
-
// @ts-expect-error Option doesn't exist on Command - probably because it doesn't exist on the typedef
|
|
81
|
-
new program.Option(
|
|
82
|
-
"--dot-node-attrs <string>",
|
|
83
|
-
"node attributes to pass to the dot render engine",
|
|
84
|
-
validations.validDotAttrs
|
|
85
|
-
).hideHelp(true)
|
|
86
|
-
)
|
|
87
|
-
.addOption(
|
|
88
|
-
// @ts-expect-error Option doesn't exist on Command - probably because it doesn't exist on the typedef
|
|
89
|
-
new program.Option(
|
|
90
|
-
"--dot-edge-attrs <string>",
|
|
91
|
-
"edge attributes to pass to the dot render engine",
|
|
92
|
-
validations.validDotAttrs
|
|
93
|
-
).hideHelp(true)
|
|
94
|
-
)
|
|
95
|
-
.option(
|
|
96
|
-
"--desugar",
|
|
97
|
-
"transform pseudo states into transitions (!experimental!)"
|
|
98
|
-
)
|
|
99
|
-
.option("-l --license", "Display license and exit", () => {
|
|
100
|
-
process.stdout.write(actions.LICENSE);
|
|
101
|
-
process.exit(0);
|
|
102
|
-
})
|
|
103
|
-
.arguments("[infile]")
|
|
104
|
-
.parse(process.argv);
|
|
105
|
-
actions
|
|
106
|
-
.transform(
|
|
107
|
-
validations.validateArguments(normalize(program.args[0], program.opts()))
|
|
108
|
-
)
|
|
109
|
-
.catch(presentError);
|
|
110
|
-
} catch (pError) {
|
|
111
|
-
presentError(pError);
|
|
112
|
-
}
|
|
5
|
+
await executeCommandLine();
|
|
@@ -40,29 +40,29 @@ function getStream(pStream) {
|
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
export
|
|
44
|
-
LICENSE,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
}
|
package/dist/version.mjs
ADDED
|
@@ -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.1.
|
|
3
|
+
"version": "11.1.1",
|
|
4
4
|
"description": "write beautiful state charts",
|
|
5
|
-
"main": "./dist/
|
|
6
|
-
"module": "./dist/
|
|
5
|
+
"main": "./dist/index.mjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": [
|
|
9
9
|
{
|
|
10
|
-
"import": "./dist/
|
|
10
|
+
"import": "./dist/index.mjs"
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
13
|
},
|
|
14
14
|
"sideEffects": [
|
|
15
|
-
"dist/
|
|
16
|
-
"dist/
|
|
17
|
-
"dist/
|
|
18
|
-
"dist/
|
|
19
|
-
"dist/
|
|
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
|
|
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",
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
"ajv": "8.12.0",
|
|
95
95
|
"chalk": "5.2.0",
|
|
96
96
|
"commander": "11.0.0",
|
|
97
|
-
"fast-xml-parser": "4.2.
|
|
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.
|
|
102
|
+
"semver": "^7.5.3",
|
|
103
103
|
"traverse": "0.6.7",
|
|
104
104
|
"wrap-ansi": "8.1.0"
|
|
105
105
|
},
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"chai-json-schema": "1.5.1",
|
|
118
118
|
"chai-xml": "0.4.1",
|
|
119
119
|
"dependency-cruiser": "13.0.4",
|
|
120
|
-
"esbuild": "0.18.
|
|
120
|
+
"esbuild": "0.18.8",
|
|
121
121
|
"eslint": "8.43.0",
|
|
122
122
|
"eslint-config-moving-meadow": "4.0.2",
|
|
123
123
|
"eslint-config-prettier": "8.8.0",
|
package/dist/esm/version.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const version = "11.1.0";
|
|
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
|
|
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
|