state-machine-cat 12.0.13 → 12.0.15
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/dist/cli/cli.mjs +170 -0
- package/dist/cli/main.mjs +3 -0
- package/dist/render/dot/render-dot-from-ast.mjs +2 -2
- package/dist/render/smcat/index.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +8 -14
- package/bin/smcat.mjs +0 -5
- package/dist/cli/execute-command-line.mjs +0 -111
- /package/dist/render/dot/{dot.states.template.js → dot.states.template.cjs} +0 -0
- /package/dist/render/dot/{dot.template.js → dot.template.cjs} +0 -0
- /package/dist/render/smcat/{smcat.template.js → smcat.template.cjs} +0 -0
package/dist/cli/cli.mjs
ADDED
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Handlebars from "handlebars/dist/handlebars.runtime.js";
|
|
2
|
-
await import("./dot.template.
|
|
3
|
-
await import("./dot.states.template.
|
|
2
|
+
await import("./dot.template.cjs");
|
|
3
|
+
await import("./dot.states.template.cjs");
|
|
4
4
|
Handlebars.registerPartial(
|
|
5
5
|
"dot.states.template.hbs",
|
|
6
6
|
Handlebars.templates["dot.states.template.hbs"],
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "12.0.
|
|
1
|
+
export const version = "12.0.15";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-machine-cat",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.15",
|
|
4
4
|
"description": "write beautiful state charts",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,14 +17,11 @@
|
|
|
17
17
|
"#*": "./src/*"
|
|
18
18
|
},
|
|
19
19
|
"sideEffects": [
|
|
20
|
-
"dist/render/smcat/smcat.template.
|
|
21
|
-
"dist/render/dot/dot.states.template.
|
|
22
|
-
"dist/render/dot/dot.template.
|
|
23
|
-
"dist/render/scxml/scxml.states.template.js",
|
|
24
|
-
"dist/render/scxml/scxml.template.js"
|
|
20
|
+
"dist/render/smcat/smcat.template.cjs",
|
|
21
|
+
"dist/render/dot/dot.states.template.cjs",
|
|
22
|
+
"dist/render/dot/dot.template.cjs"
|
|
25
23
|
],
|
|
26
24
|
"files": [
|
|
27
|
-
"bin/",
|
|
28
25
|
"dist/",
|
|
29
26
|
"types/",
|
|
30
27
|
"package.json",
|
|
@@ -44,16 +41,13 @@
|
|
|
44
41
|
"author": "Sander Verweij",
|
|
45
42
|
"license": "MIT",
|
|
46
43
|
"bin": {
|
|
47
|
-
"smcat": "
|
|
48
|
-
"
|
|
49
|
-
"sm_cat": "bin/smcat.mjs",
|
|
50
|
-
"state-machine-cat": "bin/smcat.mjs"
|
|
44
|
+
"smcat": "dist/cli/main.mjs",
|
|
45
|
+
"state-machine-cat": "dist/cli/main.mjs"
|
|
51
46
|
},
|
|
52
47
|
"dependencies": {
|
|
53
|
-
"@hpcc-js/wasm-graphviz": "1.
|
|
48
|
+
"@hpcc-js/wasm-graphviz": "1.5.0",
|
|
54
49
|
"ajv": "8.17.1",
|
|
55
|
-
"
|
|
56
|
-
"fast-xml-parser": "4.4.1",
|
|
50
|
+
"fast-xml-parser": "4.5.0",
|
|
57
51
|
"handlebars": "4.7.8",
|
|
58
52
|
"he": "1.2.0",
|
|
59
53
|
"semver": "^7.6.2",
|
package/bin/smcat.mjs
DELETED
|
@@ -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
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|