@tsplc/compiler 0.5.13 → 0.5.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/README.md +33 -8
- package/dist/cli.js +794 -621
- package/dist/cli.js.map +19 -16
- package/dist/clock.js +5 -2
- package/dist/clock.js.map +5 -4
- package/dist/codesys.js +4162 -4157
- package/dist/codesys.js.map +43 -29
- package/dist/index.js +7852 -6549
- package/dist/index.js.map +53 -50
- package/dist/ir.js +2482 -2277
- package/dist/ir.js.map +28 -25
- package/dist/retain.js +3 -1
- package/dist/retain.js.map +3 -3
- package/dist/signals.js +115 -0
- package/dist/signals.js.map +10 -0
- package/dist/telemetry.js +25 -20
- package/dist/telemetry.js.map +6 -6
- package/package.json +19 -39
- package/src/codesys/config.ts +3 -3
- package/src/codesys/debug.ts +92 -108
- package/src/codesys/emit.ts +100 -88
- package/src/codesys/endpoints.ts +111 -0
- package/src/codesys/engineering.ts +30 -54
- package/src/codesys/explain/expressions.ts +445 -0
- package/src/codesys/explain/flags.ts +134 -0
- package/src/codesys/explain/parameters.ts +53 -0
- package/src/codesys/explain/rows.ts +182 -0
- package/src/codesys/explain/tables.ts +79 -0
- package/src/codesys/explain/tasks.ts +68 -0
- package/src/codesys/explain/writes.ts +497 -0
- package/src/codesys/explain.ts +85 -1401
- package/src/codesys/expressions.ts +41 -33
- package/src/codesys/global-lists.ts +114 -94
- package/src/codesys/global-names.ts +12 -14
- package/src/codesys/http.ts +428 -388
- package/src/codesys/instrumentation.ts +142 -148
- package/src/codesys/io-paths.ts +31 -23
- package/src/codesys/loops.ts +101 -0
- package/src/codesys/manifest.ts +269 -269
- package/src/codesys/names.ts +10 -33
- package/src/codesys/numeric.ts +89 -42
- package/src/codesys/plan.ts +202 -190
- package/src/codesys/programs.ts +23 -16
- package/src/codesys/publication.ts +13 -86
- package/src/codesys/required.ts +8 -0
- package/src/codesys/routines.ts +103 -489
- package/src/codesys/scheduling.ts +96 -0
- package/src/codesys/service-channels.ts +23 -0
- package/src/codesys/sources.ts +34 -28
- package/src/codesys/st-files.ts +112 -105
- package/src/codesys/statements.ts +409 -0
- package/src/codesys/storage.ts +41 -23
- package/src/codesys/symbols.ts +130 -119
- package/src/codesys/task-access.ts +65 -221
- package/src/codesys/telemetry-settings.ts +19 -0
- package/src/codesys/telemetry.ts +185 -148
- package/src/codesys/types.ts +69 -109
- package/src/codesys/vendor.ts +13 -50
- package/src/frontend/analyzer.ts +66 -111
- package/src/frontend/async.ts +316 -128
- package/src/frontend/blocks.ts +178 -154
- package/src/frontend/configuration.ts +49 -153
- package/src/frontend/const-functions.ts +50 -40
- package/src/frontend/control-flow.ts +164 -129
- package/src/frontend/cooperative.ts +17 -9
- package/src/frontend/coroutines.ts +539 -441
- package/src/frontend/dialect-names.ts +104 -0
- package/src/frontend/elaborate/array-searches.ts +77 -69
- package/src/frontend/elaborate/assignments.ts +68 -77
- package/src/frontend/elaborate/calls.ts +878 -512
- package/src/frontend/elaborate/capture-protocol.ts +118 -21
- package/src/frontend/elaborate/capture.ts +196 -109
- package/src/frontend/elaborate/declarations.ts +124 -0
- package/src/frontend/elaborate/dialect.ts +119 -46
- package/src/frontend/elaborate/expressions.ts +763 -442
- package/src/frontend/elaborate/filtered-arrays.ts +127 -91
- package/src/frontend/elaborate/frame.ts +50 -2
- package/src/frontend/elaborate/generics.ts +20 -34
- package/src/frontend/elaborate/graph.ts +13 -87
- package/src/frontend/elaborate/imports.ts +0 -5
- package/src/frontend/elaborate/index.ts +416 -169
- package/src/frontend/elaborate/initializers.ts +64 -42
- package/src/frontend/elaborate/iterators.ts +228 -364
- package/src/frontend/elaborate/layouts.ts +477 -116
- package/src/frontend/elaborate/model.ts +113 -55
- package/src/frontend/elaborate/references.ts +116 -138
- package/src/frontend/elaborate/retention.ts +137 -59
- package/src/frontend/elaborate/specialize.ts +617 -308
- package/src/frontend/elaborate/statements.ts +436 -247
- package/src/frontend/elaborate/storage.ts +280 -213
- package/src/frontend/elaborate/time-constructors.ts +34 -0
- package/src/frontend/elaborate/values.ts +77 -7
- package/src/frontend/elaborate/writes.ts +98 -84
- package/src/frontend/expressions.ts +149 -151
- package/src/frontend/generated-names.ts +3 -3
- package/src/frontend/intrinsics.ts +31 -17
- package/src/frontend/lowering-key.ts +23 -0
- package/src/frontend/module-graph.ts +105 -43
- package/src/frontend/positions.ts +43 -35
- package/src/frontend/promise-chains.ts +226 -266
- package/src/frontend/promises.ts +88 -67
- package/src/frontend/routines.ts +122 -65
- package/src/frontend/sdk.ts +104 -5
- package/src/frontend/services.ts +149 -102
- package/src/frontend/statements.ts +60 -64
- package/src/frontend/tasks.ts +151 -96
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +366 -181
- package/src/frontend/typescript.ts +239 -112
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +90 -75
- package/src/ir/allocation.ts +29 -18
- package/src/ir/conditions.ts +38 -78
- package/src/ir/core-model.ts +128 -11
- package/src/ir/declarations.ts +18 -32
- package/src/ir/diagnostics.ts +25 -18
- package/src/ir/domains.ts +26 -23
- package/src/ir/fold.ts +55 -50
- package/src/ir/identity.ts +10 -0
- package/src/ir/index.ts +31 -7
- package/src/ir/job-errors.ts +30 -8
- package/src/ir/layouts.ts +63 -34
- package/src/ir/link.ts +11 -46
- package/src/ir/model.ts +25 -6
- package/src/ir/normalize.ts +3 -28
- package/src/ir/numeric.ts +45 -18
- package/src/ir/operands.ts +102 -0
- package/src/ir/ranges.ts +242 -67
- package/src/ir/routine.ts +126 -183
- package/src/ir/scalars.ts +29 -25
- package/src/ir/share.ts +323 -343
- package/src/ir/short-circuit.ts +140 -0
- package/src/ir/tables.ts +111 -0
- package/src/ir/temporaries.ts +15 -113
- package/src/ir/types.ts +32 -8
- package/src/project/artifacts.ts +143 -71
- package/src/project/cli.ts +104 -87
- package/src/project/debugger.ts +48 -34
- package/src/project/deployments.ts +12 -68
- package/src/project/flags.ts +14 -0
- package/src/project/plant.ts +293 -225
- package/src/project/project-commands.ts +254 -192
- package/src/project/project.ts +184 -141
- package/src/project/release.ts +22 -28
- package/src/project/server.ts +22 -26
- package/src/project/terminal.ts +13 -2
- package/src/runtime/async.ts +17 -13
- package/src/runtime/launch.ts +5 -2
- package/src/runtime/main.ts +8 -3
- package/src/runtime/missing-file.ts +3 -0
- package/src/runtime/process.ts +24 -19
- package/src/runtime/program.ts +20 -53
- package/src/runtime/retain.ts +18 -10
- package/src/runtime/runtime.ts +47 -60
- package/src/runtime/settings.ts +27 -0
- package/src/runtime/storage.ts +49 -74
- package/src/runtime/symbols.ts +19 -75
- package/src/runtime/telemetry.ts +37 -14
- package/src/runtime/transport.ts +26 -30
- package/stdlib/clock.ts +4 -2
- package/stdlib/plc-time.ts +2 -0
- package/stdlib/retain.ts +2 -0
- package/stdlib/signals.ts +142 -0
- package/stdlib/telemetry.ts +5 -12
- package/types/dialect.d.ts +49 -0
- package/types/globals.d.ts +2 -42
- package/types/index.d.ts +3 -1
- package/types/retain.d.ts +8 -2
- package/types/telemetry.d.ts +3 -0
- package/dist/bun-runtime.js +0 -1472
- package/dist/bun-runtime.js.map +0 -26
- package/dist/elaborate-capture.js +0 -304
- package/dist/elaborate-capture.js.map +0 -11
- package/dist/math.js +0 -24
- package/dist/math.js.map +0 -10
- package/dist/project.js +0 -626
- package/dist/project.js.map +0 -12
- package/dist/server-check.js +0 -59
- package/dist/server-check.js.map +0 -11
- package/src/frontend/exposure.ts +0 -181
- package/src/project/index.ts +0 -6
- package/src/runtime/.runtime-65O4JH/server/router.ts +0 -17
- package/src/runtime/.runtime-65O4JH/src/cell.ts +0 -45
- package/src/runtime/.runtime-65O4JH/src/controller.ts +0 -58
- package/src/runtime/.runtime-65O4JH/src/lane.ts +0 -6
- package/src/runtime/.runtime-65O4JH/src/main.ts +0 -11
- package/src/runtime/.runtime-65O4JH/src/services.ts +0 -8
- package/src/runtime/.runtime-65O4JH/tsconfig.json +0 -13
- package/src/runtime/.runtime-65O4JH/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-Brw2kO/server/router.ts +0 -17
- package/src/runtime/.runtime-Brw2kO/src/cell.ts +0 -45
- package/src/runtime/.runtime-Brw2kO/src/controller.ts +0 -58
- package/src/runtime/.runtime-Brw2kO/src/lane.ts +0 -6
- package/src/runtime/.runtime-Brw2kO/src/main.ts +0 -11
- package/src/runtime/.runtime-Brw2kO/src/services.ts +0 -8
- package/src/runtime/.runtime-Brw2kO/tsconfig.json +0 -13
- package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-NHfu1D/server/router.ts +0 -17
- package/src/runtime/.runtime-NHfu1D/src/cell.ts +0 -45
- package/src/runtime/.runtime-NHfu1D/src/controller.ts +0 -58
- package/src/runtime/.runtime-NHfu1D/src/lane.ts +0 -6
- package/src/runtime/.runtime-NHfu1D/src/main.ts +0 -11
- package/src/runtime/.runtime-NHfu1D/src/services.ts +0 -8
- package/src/runtime/.runtime-NHfu1D/tsconfig.json +0 -13
- package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-VaUSOu/server/router.ts +0 -17
- package/src/runtime/.runtime-VaUSOu/src/cell.ts +0 -45
- package/src/runtime/.runtime-VaUSOu/src/controller.ts +0 -58
- package/src/runtime/.runtime-VaUSOu/src/lane.ts +0 -6
- package/src/runtime/.runtime-VaUSOu/src/main.ts +0 -11
- package/src/runtime/.runtime-VaUSOu/src/services.ts +0 -8
- package/src/runtime/.runtime-VaUSOu/tsconfig.json +0 -13
- package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-WbtNvR/server/router.ts +0 -17
- package/src/runtime/.runtime-WbtNvR/src/cell.ts +0 -45
- package/src/runtime/.runtime-WbtNvR/src/controller.ts +0 -58
- package/src/runtime/.runtime-WbtNvR/src/lane.ts +0 -6
- package/src/runtime/.runtime-WbtNvR/src/main.ts +0 -11
- package/src/runtime/.runtime-WbtNvR/src/services.ts +0 -8
- package/src/runtime/.runtime-WbtNvR/tsconfig.json +0 -13
- package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-ybIxYh/server/router.ts +0 -17
- package/src/runtime/.runtime-ybIxYh/src/cell.ts +0 -45
- package/src/runtime/.runtime-ybIxYh/src/controller.ts +0 -58
- package/src/runtime/.runtime-ybIxYh/src/lane.ts +0 -6
- package/src/runtime/.runtime-ybIxYh/src/main.ts +0 -11
- package/src/runtime/.runtime-ybIxYh/src/services.ts +0 -8
- package/src/runtime/.runtime-ybIxYh/tsconfig.json +0 -13
- package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +0 -31
- package/stdlib/math.ts +0 -23
- package/types/plc.d.ts +0 -4
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
|
+
import type { ParseArgsOptionsConfig } from "node:util";
|
|
2
3
|
import {
|
|
3
|
-
buildProject as buildSt,
|
|
4
4
|
checkRawSources,
|
|
5
|
+
compileStructuredText,
|
|
5
6
|
configureDocker,
|
|
6
7
|
configureRuntime,
|
|
7
8
|
inspectProjectController,
|
|
@@ -11,11 +12,12 @@ import {
|
|
|
11
12
|
runProject,
|
|
12
13
|
updateController,
|
|
13
14
|
} from "@tsplc/build";
|
|
14
|
-
import {
|
|
15
|
+
import { checkHostConfig } from "@tsplc/compiler";
|
|
15
16
|
import { type Diagnostic, hasErrors } from "@tsplc/compiler/ir";
|
|
16
17
|
import {
|
|
17
18
|
buildTargetFor,
|
|
18
19
|
controllerFor,
|
|
20
|
+
type Environment,
|
|
19
21
|
type LoadedConfig,
|
|
20
22
|
loadTsplcConfig,
|
|
21
23
|
rawBuildConfig,
|
|
@@ -23,51 +25,44 @@ import {
|
|
|
23
25
|
import { resolveConfig } from "@tsplc/config/build";
|
|
24
26
|
import { generateProject } from "@tsplc/typegen";
|
|
25
27
|
import { runInBun } from "../runtime/process";
|
|
28
|
+
import { type Flags, flag, type OutputFormat } from "./flags";
|
|
26
29
|
import {
|
|
27
30
|
buildConfigs,
|
|
28
|
-
|
|
31
|
+
buildTypeScriptProject,
|
|
29
32
|
checkProject,
|
|
30
33
|
cleanProject,
|
|
31
34
|
projectTargets,
|
|
32
35
|
} from "./project";
|
|
33
|
-
import { buildServer, checkServer } from "./server";
|
|
36
|
+
import { buildServer, checkServer, startServerCheck } from "./server";
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export const projectCommand = (name: string) =>
|
|
51
|
-
projectCommands.find((command) => command === name);
|
|
38
|
+
/** The flags of the project commands. */
|
|
39
|
+
export const projectOptions = {
|
|
40
|
+
"emit-only": flag,
|
|
41
|
+
read: { type: "string", multiple: true },
|
|
42
|
+
"initialize-user": flag,
|
|
43
|
+
"frozen-lockfile": flag,
|
|
44
|
+
check: flag,
|
|
45
|
+
plc: flag,
|
|
46
|
+
server: flag,
|
|
47
|
+
simulate: flag,
|
|
48
|
+
runtime: flag,
|
|
49
|
+
bun: flag,
|
|
50
|
+
foreground: flag,
|
|
51
|
+
} as const satisfies ParseArgsOptionsConfig;
|
|
52
52
|
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
format?: "json" | "text";
|
|
56
|
-
read?: string[];
|
|
57
|
-
"initialize-user"?: boolean;
|
|
58
|
-
"frozen-lockfile"?: boolean;
|
|
59
|
-
check?: boolean;
|
|
60
|
-
plc?: boolean;
|
|
61
|
-
server?: boolean;
|
|
62
|
-
simulate?: boolean;
|
|
63
|
-
runtime?: boolean;
|
|
64
|
-
bun?: boolean;
|
|
65
|
-
foreground?: boolean;
|
|
53
|
+
export type ProjectFlags = Flags<typeof projectOptions> & {
|
|
54
|
+
format?: OutputFormat;
|
|
66
55
|
target?: string;
|
|
67
|
-
}
|
|
56
|
+
};
|
|
68
57
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Every command result; one whose diagnostics have errors fails the command. `values` are the
|
|
60
|
+
* `--read` expressions' values, which text output prints too.
|
|
61
|
+
*/
|
|
62
|
+
export type CommandResult = object & {
|
|
63
|
+
diagnostics?: readonly Diagnostic[];
|
|
64
|
+
values?: Readonly<Record<string, string>>;
|
|
65
|
+
};
|
|
71
66
|
|
|
72
67
|
/** A result whose diagnostics fail the command; the CLI reports the whole result. */
|
|
73
68
|
export class DiagnosticFailure extends Error {
|
|
@@ -76,103 +71,177 @@ export class DiagnosticFailure extends Error {
|
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* The flags only some commands take, in the order they are checked, with what using one
|
|
76
|
+
* elsewhere is told. `--simulate`, `--frozen-lockfile` and `--initialize-user` are deploy's too, a
|
|
77
|
+
* plant command; the last group belongs to plant commands and the debugger only.
|
|
78
|
+
*/
|
|
79
|
+
const restrictedFlags = [
|
|
80
|
+
["emit-only", "--emit-only is supported by build only."],
|
|
81
|
+
["target", "--target applies only to commands that read the config."],
|
|
82
|
+
["runtime", "--runtime applies only to configure."],
|
|
83
|
+
[
|
|
84
|
+
"bun",
|
|
85
|
+
"--bun applies only to run --simulate: the Bun runtime has no fieldbus, so a plant simulator writes its inputs.",
|
|
86
|
+
],
|
|
87
|
+
["foreground", "--foreground applies only to run --simulate --bun."],
|
|
88
|
+
["plc", "--plc and --server apply only to build."],
|
|
89
|
+
["server", "--plc and --server apply only to build."],
|
|
90
|
+
[
|
|
91
|
+
"simulate",
|
|
92
|
+
"--simulate applies only to run, download, online-change and deploy.",
|
|
93
|
+
],
|
|
94
|
+
["check", "--check applies only to typegen."],
|
|
95
|
+
["read", "--read applies only to inspect, download and online-change."],
|
|
96
|
+
[
|
|
97
|
+
"frozen-lockfile",
|
|
98
|
+
"--frozen-lockfile applies only to install, build, run, download, online-change and deploy.",
|
|
99
|
+
],
|
|
100
|
+
["initialize-user", "--initialize-user applies only to download and deploy."],
|
|
101
|
+
["download", "--download applies only to deploy."],
|
|
102
|
+
["select", "--select applies only to deploy."],
|
|
103
|
+
["review", "--review applies only to deploy and redeploy."],
|
|
104
|
+
["wait", "--wait applies only to deploy, rollback and redeploy."],
|
|
105
|
+
["restore", "--restore applies only to unforce."],
|
|
106
|
+
["yes", "-y applies only to plant agent commands."],
|
|
107
|
+
["port", "--port applies only to debug."],
|
|
108
|
+
["server-url", "--server-url applies only to debug."],
|
|
109
|
+
["opcua", "--opcua applies only to debug."],
|
|
110
|
+
] as const;
|
|
111
|
+
type RestrictedFlag = (typeof restrictedFlags)[number][0];
|
|
112
|
+
|
|
113
|
+
/** A flag that means something only beside another one. */
|
|
114
|
+
const prerequisites: Partial<Record<RestrictedFlag, RestrictedFlag>> = {
|
|
115
|
+
bun: "simulate",
|
|
116
|
+
foreground: "bun",
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
interface ProjectContext {
|
|
120
|
+
file: string;
|
|
121
|
+
flags: ProjectFlags;
|
|
122
|
+
environment: Environment;
|
|
123
|
+
progress: ProgressStream;
|
|
124
|
+
/** The config with the target the flags name, in `environment`. */
|
|
125
|
+
load: () => Promise<LoadedConfig>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
interface ProjectCommandEntry {
|
|
129
|
+
/** The restricted flags it takes. */
|
|
130
|
+
takes: readonly RestrictedFlag[];
|
|
131
|
+
/** Rejects flags that don't go together, before the config loads. */
|
|
132
|
+
check?: (flags: ProjectFlags) => void;
|
|
133
|
+
run: (context: ProjectContext) => Promise<CommandResult>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const projectCommands = {
|
|
137
|
+
install: {
|
|
138
|
+
takes: ["target", "frozen-lockfile"],
|
|
139
|
+
run: async ({ load, flags }) => install(await load(), flags),
|
|
140
|
+
},
|
|
141
|
+
typegen: {
|
|
142
|
+
takes: ["target", "check"],
|
|
143
|
+
run: async ({ load, flags }) => typegen(await load(), flags),
|
|
144
|
+
},
|
|
145
|
+
check: {
|
|
146
|
+
takes: ["target"],
|
|
147
|
+
run: async ({ file, load }) => check(await loadCheckedConfig(file, load)),
|
|
148
|
+
},
|
|
149
|
+
build: {
|
|
150
|
+
takes: ["target", "emit-only", "plc", "server", "frozen-lockfile"],
|
|
151
|
+
check: (flags) => {
|
|
152
|
+
if (flags.plc && flags.server) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
"Choose --plc or --server, or omit both for a full build.",
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (flags.server && flags["emit-only"]) {
|
|
158
|
+
throw new Error("--emit-only applies to PLC emission only.");
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
run: async ({ file, load, flags, progress }) =>
|
|
162
|
+
build(await loadCheckedConfig(file, load), flags, progress),
|
|
163
|
+
},
|
|
164
|
+
run: {
|
|
165
|
+
takes: ["target", "simulate", "bun", "foreground", "frozen-lockfile"],
|
|
166
|
+
run: async ({ file, load, flags, progress }) =>
|
|
167
|
+
run(await loadCheckedConfig(file, load), flags, progress),
|
|
168
|
+
},
|
|
169
|
+
download: {
|
|
170
|
+
takes: ["target", "simulate", "read", "frozen-lockfile", "initialize-user"],
|
|
171
|
+
run: async ({ file, load, flags, progress }) =>
|
|
172
|
+
updateProgram(
|
|
173
|
+
"download",
|
|
174
|
+
await loadCheckedConfig(file, load),
|
|
175
|
+
flags,
|
|
176
|
+
progress,
|
|
177
|
+
),
|
|
178
|
+
},
|
|
179
|
+
"online-change": {
|
|
180
|
+
takes: ["target", "simulate", "read", "frozen-lockfile"],
|
|
181
|
+
run: async ({ file, load, flags, progress }) =>
|
|
182
|
+
updateProgram(
|
|
183
|
+
"online-change",
|
|
184
|
+
await loadCheckedConfig(file, load),
|
|
185
|
+
flags,
|
|
186
|
+
progress,
|
|
187
|
+
),
|
|
188
|
+
},
|
|
189
|
+
inspect: {
|
|
190
|
+
takes: ["target", "read"],
|
|
191
|
+
run: async ({ load, flags, progress }) =>
|
|
192
|
+
inspectProjectController(await load(), flags.read, { progress }),
|
|
193
|
+
},
|
|
194
|
+
clean: { takes: [], run: ({ file }) => cleanProject(file) },
|
|
195
|
+
configure: {
|
|
196
|
+
takes: ["runtime"],
|
|
197
|
+
run: ({ flags, progress, environment }) =>
|
|
198
|
+
configure(flags, progress, environment),
|
|
199
|
+
},
|
|
200
|
+
} satisfies Record<string, ProjectCommandEntry>;
|
|
201
|
+
|
|
202
|
+
export type ProjectCommand = keyof typeof projectCommands;
|
|
203
|
+
|
|
204
|
+
export const isProjectCommand = (name: string): name is ProjectCommand =>
|
|
205
|
+
Object.hasOwn(projectCommands, name);
|
|
206
|
+
|
|
207
|
+
/** Rejects the flags that don't apply to `command`, among every flag the command line parsed. */
|
|
80
208
|
export const checkProjectFlags = (
|
|
81
209
|
command: ProjectCommand,
|
|
82
|
-
flags: ProjectFlags,
|
|
210
|
+
flags: ProjectFlags & Partial<Record<RestrictedFlag, unknown>>,
|
|
83
211
|
) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (flags.bun && (command !== "run" || !flags.simulate)) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
"--bun applies only to run --simulate: the Bun runtime has no fieldbus, so a plant simulator writes its inputs.",
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
if (flags.foreground && !flags.bun) {
|
|
99
|
-
throw new Error("--foreground applies only to run --simulate --bun.");
|
|
100
|
-
}
|
|
101
|
-
if ((flags.plc || flags.server) && command !== "build") {
|
|
102
|
-
throw new Error("--plc and --server apply only to build.");
|
|
103
|
-
}
|
|
104
|
-
// deploy takes --simulate too, but runs as a plant command.
|
|
105
|
-
if (
|
|
106
|
-
flags.simulate &&
|
|
107
|
-
!["run", "download", "online-change"].includes(command)
|
|
108
|
-
) {
|
|
109
|
-
throw new Error(
|
|
110
|
-
"--simulate applies only to run, download, online-change and deploy.",
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
if (flags.plc && flags.server) {
|
|
114
|
-
throw new Error("Choose --plc or --server, or omit both for a full build.");
|
|
115
|
-
}
|
|
116
|
-
if (flags.server && flags["emit-only"]) {
|
|
117
|
-
throw new Error("--emit-only applies to PLC emission only.");
|
|
212
|
+
const entry: ProjectCommandEntry = projectCommands[command];
|
|
213
|
+
for (const [name, message] of restrictedFlags) {
|
|
214
|
+
const prerequisite = prerequisites[name];
|
|
215
|
+
const applies =
|
|
216
|
+
entry.takes.includes(name) &&
|
|
217
|
+
(prerequisite === undefined || flags[prerequisite]);
|
|
218
|
+
if (flags[name] && !applies) {
|
|
219
|
+
throw new Error(message);
|
|
220
|
+
}
|
|
118
221
|
}
|
|
222
|
+
entry.check?.(flags);
|
|
119
223
|
};
|
|
120
224
|
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
progress: ProgressStream;
|
|
124
|
-
environment: CompileEnvironment;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const runProjectCommand = async (
|
|
225
|
+
/** Runs `command` in this process's `environment`, which the config's target values overlay. */
|
|
226
|
+
export const runProjectCommand = (
|
|
128
227
|
command: ProjectCommand,
|
|
129
228
|
file: string,
|
|
130
229
|
flags: ProjectFlags,
|
|
131
|
-
environment:
|
|
132
|
-
): Promise<CommandResult> =>
|
|
133
|
-
|
|
230
|
+
environment: Environment,
|
|
231
|
+
): Promise<CommandResult> =>
|
|
232
|
+
projectCommands[command].run({
|
|
233
|
+
file,
|
|
234
|
+
flags,
|
|
235
|
+
environment,
|
|
134
236
|
// A JSON result owns standard output, so progress goes to standard error.
|
|
135
237
|
progress: flags.format === "json" ? "stderr" : "stdout",
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
target: flags.target,
|
|
144
|
-
forAgent: false,
|
|
145
|
-
});
|
|
146
|
-
switch (command) {
|
|
147
|
-
case "configure":
|
|
148
|
-
return configure(flags, progress);
|
|
149
|
-
case "clean":
|
|
150
|
-
return cleanProject(file);
|
|
151
|
-
case "install":
|
|
152
|
-
return install(await load(), flags);
|
|
153
|
-
case "typegen":
|
|
154
|
-
return typegen(file, await load(), flags, environment);
|
|
155
|
-
case "check":
|
|
156
|
-
return check(file, await loadCheckedConfig(file, load), environment);
|
|
157
|
-
case "build":
|
|
158
|
-
return build(file, await loadCheckedConfig(file, load), flags, context);
|
|
159
|
-
case "run":
|
|
160
|
-
return run(file, await loadCheckedConfig(file, load), flags, context);
|
|
161
|
-
case "inspect":
|
|
162
|
-
return inspectProjectController(await load(), flags.read, {
|
|
163
|
-
progress,
|
|
164
|
-
});
|
|
165
|
-
case "download":
|
|
166
|
-
case "online-change":
|
|
167
|
-
return updateProgram(
|
|
168
|
-
command,
|
|
169
|
-
file,
|
|
170
|
-
await loadCheckedConfig(file, load),
|
|
171
|
-
flags,
|
|
172
|
-
context,
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
238
|
+
load: () =>
|
|
239
|
+
loadTsplcConfig(file, {
|
|
240
|
+
env: environment,
|
|
241
|
+
target: flags.target,
|
|
242
|
+
forAgent: false,
|
|
243
|
+
}),
|
|
244
|
+
});
|
|
176
245
|
|
|
177
246
|
/** A config loaded after its host config check, whose diagnostics the compiler reports. */
|
|
178
247
|
interface CheckedConfig {
|
|
@@ -196,10 +265,14 @@ const loadCheckedConfig = async (
|
|
|
196
265
|
const configure = async (
|
|
197
266
|
flags: Pick<ProjectFlags, "runtime">,
|
|
198
267
|
progress: ProgressStream,
|
|
268
|
+
environment: Environment,
|
|
199
269
|
) => {
|
|
200
270
|
await (flags.runtime
|
|
201
271
|
? configureRuntime({ progress })
|
|
202
|
-
: configureDocker({
|
|
272
|
+
: configureDocker({
|
|
273
|
+
progress,
|
|
274
|
+
winetricksCache: environment.CODESYS_WINETRICKS_CACHE || null,
|
|
275
|
+
}));
|
|
203
276
|
return { ok: true };
|
|
204
277
|
};
|
|
205
278
|
|
|
@@ -213,35 +286,41 @@ const install = async (
|
|
|
213
286
|
});
|
|
214
287
|
|
|
215
288
|
const typegen = async (
|
|
216
|
-
file: string,
|
|
217
289
|
loaded: LoadedConfig,
|
|
218
290
|
flags: Pick<ProjectFlags, "check">,
|
|
219
|
-
environment: CompileEnvironment,
|
|
220
291
|
) => {
|
|
221
|
-
const targets = await projectTargets(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
292
|
+
const targets = await projectTargets(loaded.configFile, loaded);
|
|
293
|
+
// `--check` compares the committed files with this source's contract, so it emits too.
|
|
294
|
+
if (loaded.config.compiler) {
|
|
295
|
+
if (!flags.check) {
|
|
296
|
+
await generateProject(loaded, { hardwareOnly: true, targets });
|
|
297
|
+
}
|
|
298
|
+
const emitted = await buildTypeScriptProject(loaded.configFile, {
|
|
225
299
|
emitOnly: true,
|
|
226
300
|
loaded,
|
|
227
|
-
|
|
301
|
+
hostConfigDiagnostics: checkHostConfig(loaded.configFile),
|
|
228
302
|
});
|
|
229
303
|
if (hasErrors(emitted.diagnostics)) {
|
|
230
304
|
throw new DiagnosticFailure(emitted);
|
|
231
305
|
}
|
|
232
306
|
}
|
|
233
|
-
|
|
307
|
+
const { catalog, io, files } = await generateProject(loaded, {
|
|
308
|
+
check: flags.check,
|
|
309
|
+
targets,
|
|
310
|
+
});
|
|
311
|
+
return { catalog, io, files };
|
|
234
312
|
};
|
|
235
313
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
314
|
+
/** The check's verdict; the plan and the loaded config stay out, since they hold the environment. */
|
|
315
|
+
const check = async (checked: CheckedConfig) => {
|
|
316
|
+
if (checked.loaded.config.compiler) {
|
|
317
|
+
const { configFile, diagnostics } = await checkProject(
|
|
318
|
+
checked.loaded.configFile,
|
|
319
|
+
checked,
|
|
320
|
+
);
|
|
321
|
+
return { configFile, diagnostics };
|
|
243
322
|
}
|
|
244
|
-
return { objects: (await checkRawSources(loaded)).objects.length };
|
|
323
|
+
return { objects: (await checkRawSources(checked.loaded)).objects.length };
|
|
245
324
|
};
|
|
246
325
|
|
|
247
326
|
/**
|
|
@@ -250,34 +329,35 @@ const check = async (
|
|
|
250
329
|
*/
|
|
251
330
|
const buildPlc = async (
|
|
252
331
|
command: "build" | "run",
|
|
253
|
-
file: string,
|
|
254
332
|
{ loaded, hostConfigDiagnostics }: CheckedConfig,
|
|
255
333
|
flags: Pick<ProjectFlags, "emit-only" | "frozen-lockfile" | "simulate">,
|
|
256
|
-
|
|
334
|
+
progress: ProgressStream,
|
|
257
335
|
) => {
|
|
258
|
-
const { config } = loaded;
|
|
336
|
+
const { config, configFile } = loaded;
|
|
259
337
|
if (config.compiler) {
|
|
260
338
|
// The build's analysis already read the targets; `--format json` reports the rest.
|
|
261
|
-
const { targets, services, ...built } = await
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
339
|
+
const { targets, services, ...built } = await buildTypeScriptProject(
|
|
340
|
+
configFile,
|
|
341
|
+
{
|
|
342
|
+
progress,
|
|
343
|
+
emitOnly: flags["emit-only"],
|
|
344
|
+
frozenLockfile: flags["frozen-lockfile"],
|
|
345
|
+
...buildConfigs(loaded, flags),
|
|
346
|
+
hostConfigDiagnostics,
|
|
347
|
+
controller: controllerFor(config, command),
|
|
348
|
+
buildTarget: buildTargetFor(command),
|
|
349
|
+
},
|
|
350
|
+
);
|
|
271
351
|
if (hasErrors(built.diagnostics)) {
|
|
272
352
|
throw new DiagnosticFailure(built);
|
|
273
353
|
}
|
|
274
|
-
await generateProject(
|
|
354
|
+
await generateProject(loaded, { targets });
|
|
275
355
|
return { built, services };
|
|
276
356
|
}
|
|
277
357
|
if (flags["emit-only"]) {
|
|
278
358
|
throw new Error("Raw Structured Text is already emitted.");
|
|
279
359
|
}
|
|
280
|
-
const built = await
|
|
360
|
+
const built = await compileStructuredText(
|
|
281
361
|
await rawEngineeringSettings(loaded, {
|
|
282
362
|
command,
|
|
283
363
|
frozenLockfile: flags["frozen-lockfile"],
|
|
@@ -285,19 +365,18 @@ const buildPlc = async (
|
|
|
285
365
|
}),
|
|
286
366
|
{ progress },
|
|
287
367
|
);
|
|
288
|
-
await generateProject(
|
|
368
|
+
await generateProject(loaded);
|
|
289
369
|
return { built, services: undefined };
|
|
290
370
|
};
|
|
291
371
|
|
|
292
372
|
/** The PLC program and, unless `--plc` or `--emit-only` restricts it, the configured server. */
|
|
293
373
|
const build = async (
|
|
294
|
-
file: string,
|
|
295
374
|
checked: CheckedConfig,
|
|
296
375
|
flags: Pick<
|
|
297
376
|
ProjectFlags,
|
|
298
377
|
"emit-only" | "frozen-lockfile" | "plc" | "server" | "simulate"
|
|
299
378
|
>,
|
|
300
|
-
|
|
379
|
+
progress: ProgressStream,
|
|
301
380
|
) => {
|
|
302
381
|
const { config, root } = checked.loaded;
|
|
303
382
|
if (flags.server) {
|
|
@@ -305,11 +384,8 @@ const build = async (
|
|
|
305
384
|
}
|
|
306
385
|
const withServer =
|
|
307
386
|
!flags.plc && !flags["emit-only"] && config.server?.runtime;
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
// A failed PLC build reports its own diagnostics; the check's outcome is read only after a success.
|
|
311
|
-
serverCheck?.catch(() => undefined);
|
|
312
|
-
const { built: plc } = await buildPlc("build", file, checked, flags, context);
|
|
387
|
+
const serverCheck = withServer ? startServerCheck(config, root) : undefined;
|
|
388
|
+
const { built: plc } = await buildPlc("build", checked, flags, progress);
|
|
313
389
|
if (!serverCheck) {
|
|
314
390
|
return plc;
|
|
315
391
|
}
|
|
@@ -317,19 +393,18 @@ const build = async (
|
|
|
317
393
|
};
|
|
318
394
|
|
|
319
395
|
const run = async (
|
|
320
|
-
file: string,
|
|
321
396
|
checked: CheckedConfig,
|
|
322
397
|
flags: Pick<
|
|
323
398
|
ProjectFlags,
|
|
324
399
|
"frozen-lockfile" | "simulate" | "bun" | "foreground" | "target"
|
|
325
400
|
>,
|
|
326
|
-
|
|
401
|
+
progress: ProgressStream,
|
|
327
402
|
) => {
|
|
328
403
|
if (flags.bun) {
|
|
329
|
-
return runInBunRuntime(
|
|
404
|
+
return runInBunRuntime(checked, flags, progress);
|
|
330
405
|
}
|
|
331
406
|
const { config, configFile } = checked.loaded;
|
|
332
|
-
const { built } = await buildPlc("run",
|
|
407
|
+
const { built } = await buildPlc("run", checked, flags, progress);
|
|
333
408
|
if (!config.build) {
|
|
334
409
|
throw new Error("Configure build to run this project.");
|
|
335
410
|
}
|
|
@@ -339,22 +414,21 @@ const run = async (
|
|
|
339
414
|
configFile,
|
|
340
415
|
),
|
|
341
416
|
config.name,
|
|
342
|
-
{ progress
|
|
417
|
+
{ progress },
|
|
343
418
|
);
|
|
344
419
|
return built;
|
|
345
420
|
};
|
|
346
421
|
|
|
347
422
|
/** Emits the program and runs its TypeScript in the Bun runtime instead of CODESYS. */
|
|
348
423
|
const runInBunRuntime = async (
|
|
349
|
-
file: string,
|
|
350
424
|
checked: CheckedConfig,
|
|
351
425
|
flags: Pick<
|
|
352
426
|
ProjectFlags,
|
|
353
427
|
"frozen-lockfile" | "simulate" | "foreground" | "target"
|
|
354
428
|
>,
|
|
355
|
-
|
|
429
|
+
progress: ProgressStream,
|
|
356
430
|
) => {
|
|
357
|
-
const { config, configFile, root } = checked.loaded;
|
|
431
|
+
const { config, configFile, env, root } = checked.loaded;
|
|
358
432
|
if (!config.compiler) {
|
|
359
433
|
throw new Error(
|
|
360
434
|
"The Bun runtime runs a TypeScript program; this project builds raw Structured Text.",
|
|
@@ -362,10 +436,9 @@ const runInBunRuntime = async (
|
|
|
362
436
|
}
|
|
363
437
|
const { built, services } = await buildPlc(
|
|
364
438
|
"run",
|
|
365
|
-
file,
|
|
366
439
|
checked,
|
|
367
440
|
{ ...flags, "emit-only": true },
|
|
368
|
-
|
|
441
|
+
progress,
|
|
369
442
|
);
|
|
370
443
|
const runtime = await runInBun({
|
|
371
444
|
root,
|
|
@@ -374,9 +447,9 @@ const runInBunRuntime = async (
|
|
|
374
447
|
target: flags.target ?? null,
|
|
375
448
|
services: services ?? {},
|
|
376
449
|
},
|
|
377
|
-
environment:
|
|
450
|
+
environment: env,
|
|
378
451
|
foreground: flags.foreground ?? false,
|
|
379
|
-
progress
|
|
452
|
+
progress,
|
|
380
453
|
});
|
|
381
454
|
return { ...built, runtime };
|
|
382
455
|
};
|
|
@@ -384,26 +457,19 @@ const runInBunRuntime = async (
|
|
|
384
457
|
/** Downloads or online-changes the program on the configured controller. */
|
|
385
458
|
const updateProgram = async (
|
|
386
459
|
operation: "download" | "online-change",
|
|
387
|
-
file: string,
|
|
388
460
|
checked: CheckedConfig,
|
|
389
461
|
flags: Pick<
|
|
390
462
|
ProjectFlags,
|
|
391
463
|
"frozen-lockfile" | "simulate" | "initialize-user" | "read"
|
|
392
464
|
>,
|
|
393
|
-
|
|
465
|
+
progress: ProgressStream,
|
|
394
466
|
) => {
|
|
395
|
-
const { config } = checked.loaded;
|
|
467
|
+
const { config, env } = checked.loaded;
|
|
396
468
|
if (!config.build) {
|
|
397
469
|
throw new Error("Configure build settings and controller connection.");
|
|
398
470
|
}
|
|
399
471
|
const settings = config.compiler
|
|
400
|
-
? await emittedControllerSettings(
|
|
401
|
-
operation,
|
|
402
|
-
file,
|
|
403
|
-
checked,
|
|
404
|
-
flags,
|
|
405
|
-
environment,
|
|
406
|
-
)
|
|
472
|
+
? await emittedControllerSettings(operation, checked, flags)
|
|
407
473
|
: await rawEngineeringSettings(checked.loaded, {
|
|
408
474
|
command: operation,
|
|
409
475
|
frozenLockfile: flags["frozen-lockfile"],
|
|
@@ -413,20 +479,18 @@ const updateProgram = async (
|
|
|
413
479
|
initializeUser: flags["initialize-user"],
|
|
414
480
|
read: flags.read,
|
|
415
481
|
progress,
|
|
482
|
+
environment: env,
|
|
416
483
|
});
|
|
417
484
|
};
|
|
418
485
|
|
|
419
486
|
const emittedControllerSettings = async (
|
|
420
487
|
operation: "download" | "online-change",
|
|
421
|
-
file: string,
|
|
422
488
|
{ loaded, hostConfigDiagnostics }: CheckedConfig,
|
|
423
489
|
flags: Pick<ProjectFlags, "frozen-lockfile" | "simulate">,
|
|
424
|
-
environment: CompileEnvironment,
|
|
425
490
|
) => {
|
|
426
|
-
const emitted = await
|
|
491
|
+
const emitted = await buildTypeScriptProject(loaded.configFile, {
|
|
427
492
|
emitOnly: true,
|
|
428
493
|
forController: true,
|
|
429
|
-
environment,
|
|
430
494
|
frozenLockfile: flags["frozen-lockfile"],
|
|
431
495
|
...buildConfigs(loaded, flags),
|
|
432
496
|
hostConfigDiagnostics,
|
|
@@ -439,7 +503,5 @@ const emittedControllerSettings = async (
|
|
|
439
503
|
if (!emitted.controllerConfig) {
|
|
440
504
|
throw new Error("Configure build settings for deployment.");
|
|
441
505
|
}
|
|
442
|
-
|
|
443
|
-
// this through the input schema again would reject its configFile.
|
|
444
|
-
return { ...emitted.controllerConfig, io: {} };
|
|
506
|
+
return emitted.controllerConfig;
|
|
445
507
|
};
|