@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
package/src/project/plant.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ParseArgsOptionsConfig } from "node:util";
|
|
1
2
|
import {
|
|
2
3
|
ask,
|
|
3
4
|
askCredentials,
|
|
@@ -6,14 +7,21 @@ import {
|
|
|
6
7
|
type Variable,
|
|
7
8
|
} from "@tsplc/agent";
|
|
8
9
|
import { type AgentClient, createAgentClient } from "@tsplc/agent/client";
|
|
9
|
-
import type
|
|
10
|
-
import type {
|
|
10
|
+
import { type LoginCommand, type LoginResult, resetLabel } from "@tsplc/build";
|
|
11
|
+
import type { Diagnostic } from "@tsplc/compiler/ir";
|
|
11
12
|
import {
|
|
13
|
+
agentTokenEnv,
|
|
14
|
+
agentUrlEnv,
|
|
15
|
+
type Environment,
|
|
12
16
|
type LoadedConfig,
|
|
13
17
|
type PlantVariables,
|
|
14
18
|
releaseEnvironment,
|
|
15
19
|
} from "@tsplc/config";
|
|
20
|
+
import { runtimePort } from "@tsplc/config/build";
|
|
16
21
|
import { LoginUnavailable, noLogin } from "@tsplc/debug";
|
|
22
|
+
import { isWithin } from "@tsplc/iec/st";
|
|
23
|
+
import { arrayIndex, symbolPathSegments } from "@tsplc/opcua/contract";
|
|
24
|
+
import { controllerRestartSchema } from "@tsplc/server/plant-agent";
|
|
17
25
|
import { z } from "zod";
|
|
18
26
|
import {
|
|
19
27
|
type Approval,
|
|
@@ -24,65 +32,47 @@ import {
|
|
|
24
32
|
rollBack,
|
|
25
33
|
submitDeployment,
|
|
26
34
|
} from "./deployments";
|
|
35
|
+
import { type Flags, flag, type OutputFormat } from "./flags";
|
|
27
36
|
import { gitSource } from "./git";
|
|
28
37
|
import { prepareRelease } from "./release";
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"dashboard",
|
|
37
|
-
"target",
|
|
38
|
-
"status",
|
|
39
|
-
"login",
|
|
40
|
-
"logout",
|
|
41
|
-
"vars",
|
|
42
|
-
"read",
|
|
43
|
-
"write",
|
|
44
|
-
"force",
|
|
45
|
-
"unforce",
|
|
46
|
-
"start",
|
|
47
|
-
"stop",
|
|
48
|
-
"reset",
|
|
49
|
-
"restart",
|
|
50
|
-
] as const;
|
|
51
|
-
|
|
52
|
-
export type PlantCommand = (typeof plantCommands)[number];
|
|
38
|
+
import {
|
|
39
|
+
choose,
|
|
40
|
+
confirm,
|
|
41
|
+
confirmOrCancel,
|
|
42
|
+
progress,
|
|
43
|
+
timedProgress,
|
|
44
|
+
} from "./terminal";
|
|
53
45
|
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
/** The flags of the plant commands. */
|
|
47
|
+
export const plantOptions = {
|
|
48
|
+
download: flag,
|
|
49
|
+
review: flag,
|
|
50
|
+
wait: flag,
|
|
51
|
+
"initialize-user": flag,
|
|
52
|
+
restore: flag,
|
|
53
|
+
select: flag,
|
|
54
|
+
simulate: flag,
|
|
55
|
+
yes: { type: "boolean", short: "y" },
|
|
56
|
+
"frozen-lockfile": flag,
|
|
57
|
+
} as const satisfies ParseArgsOptionsConfig;
|
|
56
58
|
|
|
57
|
-
export
|
|
58
|
-
download?: boolean;
|
|
59
|
-
format?: "json" | "text";
|
|
60
|
-
review?: boolean;
|
|
61
|
-
wait?: boolean;
|
|
62
|
-
"initialize-user"?: boolean;
|
|
63
|
-
restore?: boolean;
|
|
64
|
-
select?: boolean;
|
|
65
|
-
simulate?: boolean;
|
|
66
|
-
yes?: boolean;
|
|
67
|
-
"frozen-lockfile"?: boolean;
|
|
68
|
-
}
|
|
59
|
+
export type PlantFlags = Flags<typeof plantOptions> & { format?: OutputFormat };
|
|
69
60
|
|
|
70
|
-
/** The plant agent named by
|
|
61
|
+
/** The plant agent named by `agentUrlEnv` and `agentTokenEnv` in `env`, where a target's agent sets the URL. */
|
|
71
62
|
export const connect = (env: Record<string, string | undefined>) => {
|
|
72
63
|
const environment = z
|
|
73
64
|
.object({
|
|
74
|
-
|
|
75
|
-
error:
|
|
76
|
-
"Configure the target's agent, or set TSPLC_AGENT_URL to the plant agent, such as http://plant-pc:4850",
|
|
65
|
+
[agentUrlEnv]: z.url({
|
|
66
|
+
error: `Configure the target's agent, or set ${agentUrlEnv} to the plant agent, such as http://plant-pc:4850`,
|
|
77
67
|
}),
|
|
78
|
-
|
|
79
|
-
error:
|
|
68
|
+
[agentTokenEnv]: z.string({
|
|
69
|
+
error: `Set ${agentTokenEnv} to the plant agent's token`,
|
|
80
70
|
}),
|
|
81
71
|
})
|
|
82
72
|
.parse(env);
|
|
83
73
|
return createAgentClient({
|
|
84
|
-
url: environment
|
|
85
|
-
token: environment
|
|
74
|
+
url: environment[agentUrlEnv],
|
|
75
|
+
token: environment[agentTokenEnv],
|
|
86
76
|
});
|
|
87
77
|
};
|
|
88
78
|
|
|
@@ -134,7 +124,7 @@ const selectTarget = async (agent: AgentClient): Promise<Target> => {
|
|
|
134
124
|
`Scanning ${network.address}/${network.prefixLength} for CODESYS controllers…`,
|
|
135
125
|
);
|
|
136
126
|
const found = await agent.discover(network.name);
|
|
137
|
-
const manual = { address: "", port:
|
|
127
|
+
const manual = { address: "", port: runtimePort, hostname: null };
|
|
138
128
|
const choice = await choose(
|
|
139
129
|
"Which controller?",
|
|
140
130
|
[...found, manual],
|
|
@@ -154,7 +144,7 @@ const selectTarget = async (agent: AgentClient): Promise<Target> => {
|
|
|
154
144
|
* the controller's user creates the one sent, so it never leaves it to the stored one.
|
|
155
145
|
*/
|
|
156
146
|
export const controllerCredentials = async (
|
|
157
|
-
environment:
|
|
147
|
+
environment: Environment,
|
|
158
148
|
agent: { stored: boolean; initializeUser: boolean },
|
|
159
149
|
prompt: () => Promise<Credentials>,
|
|
160
150
|
): Promise<Credentials | null> => {
|
|
@@ -186,10 +176,8 @@ const plantSummary = ({ values, secrets }: PlantVariables) => {
|
|
|
186
176
|
|
|
187
177
|
const deploy = async (
|
|
188
178
|
agent: AgentClient,
|
|
189
|
-
file: string,
|
|
190
179
|
loaded: LoadedConfig,
|
|
191
180
|
flags: PlantFlags,
|
|
192
|
-
environment: CompileEnvironment,
|
|
193
181
|
follow: Follow,
|
|
194
182
|
) => {
|
|
195
183
|
const status = await agent.status();
|
|
@@ -198,51 +186,37 @@ const deploy = async (
|
|
|
198
186
|
}
|
|
199
187
|
const target =
|
|
200
188
|
!status.target || flags.select ? await selectTarget(agent) : status.target;
|
|
189
|
+
const initializeUser = flags["initialize-user"] ?? false;
|
|
201
190
|
const plant = await agent.releaseVariables(
|
|
202
191
|
loaded.config.secrets?.service ?? null,
|
|
203
192
|
);
|
|
204
|
-
const built = releaseEnvironment(
|
|
205
|
-
loaded.config,
|
|
206
|
-
{ env: environment, values: loaded.values },
|
|
207
|
-
plant,
|
|
208
|
-
);
|
|
193
|
+
const built = releaseEnvironment(loaded.config, loaded, plant);
|
|
209
194
|
console.log(`Building the release for ${target.host}…`);
|
|
210
195
|
const held = plantSummary(plant);
|
|
211
196
|
if (held) {
|
|
212
197
|
console.log(` With the plant PC's ${held}`);
|
|
213
198
|
}
|
|
214
199
|
const building = timedProgress();
|
|
215
|
-
const { release, diagnostics } = await prepareRelease(
|
|
216
|
-
file,
|
|
217
|
-
loaded,
|
|
218
|
-
flags,
|
|
219
|
-
built,
|
|
220
|
-
);
|
|
200
|
+
const { release, diagnostics } = await prepareRelease(loaded, flags, built);
|
|
221
201
|
if (!release) {
|
|
222
202
|
return { diagnostics };
|
|
223
203
|
}
|
|
224
204
|
building("Built");
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
!(await confirm(
|
|
205
|
+
if (flags.download) {
|
|
206
|
+
await confirmOrCancel(
|
|
228
207
|
"A full download stops the running application while it loads. Continue?",
|
|
229
208
|
flags,
|
|
230
|
-
)
|
|
231
|
-
) {
|
|
232
|
-
throw new Error("Cancelled.");
|
|
209
|
+
);
|
|
233
210
|
}
|
|
234
211
|
const credentials = await controllerCredentials(
|
|
235
|
-
|
|
236
|
-
{
|
|
237
|
-
stored: status.credentialsStored,
|
|
238
|
-
initializeUser: flags["initialize-user"] ?? false,
|
|
239
|
-
},
|
|
212
|
+
loaded.env,
|
|
213
|
+
{ stored: status.credentialsStored, initializeUser },
|
|
240
214
|
askCredentials,
|
|
241
215
|
);
|
|
242
216
|
const settings = {
|
|
243
217
|
credentials,
|
|
244
218
|
download: flags.download ?? false,
|
|
245
|
-
initializeUser
|
|
219
|
+
initializeUser,
|
|
246
220
|
};
|
|
247
221
|
console.log(
|
|
248
222
|
release.manifest.server
|
|
@@ -264,10 +238,7 @@ const deploy = async (
|
|
|
264
238
|
};
|
|
265
239
|
|
|
266
240
|
/** Opens a login when none is working; it stays open across commands until `tsplc logout`. */
|
|
267
|
-
const ensureLogin = async (
|
|
268
|
-
agent: AgentClient,
|
|
269
|
-
environment: CompileEnvironment,
|
|
270
|
-
) => {
|
|
241
|
+
const ensureLogin = async (agent: AgentClient, environment: Environment) => {
|
|
271
242
|
const { login, credentialsStored } = await agent.status();
|
|
272
243
|
if (login && "state" in login) {
|
|
273
244
|
return;
|
|
@@ -293,24 +264,15 @@ export const variableChildren = (
|
|
|
293
264
|
prefix: string,
|
|
294
265
|
) => {
|
|
295
266
|
const children = new Map<string, { type?: string; leaves: number }>();
|
|
296
|
-
const start = prefix.toLowerCase();
|
|
297
267
|
for (const { path, type } of variables) {
|
|
298
|
-
|
|
299
|
-
if (
|
|
300
|
-
prefix &&
|
|
301
|
-
!(
|
|
302
|
-
lower === start ||
|
|
303
|
-
lower.startsWith(`${start}.`) ||
|
|
304
|
-
lower.startsWith(`${start}[`)
|
|
305
|
-
)
|
|
306
|
-
) {
|
|
268
|
+
if (prefix && !isWithin(prefix, path)) {
|
|
307
269
|
continue;
|
|
308
270
|
}
|
|
309
271
|
const rest = path.slice(prefix.length).replace(/^\./, "");
|
|
310
272
|
if (rest === "") {
|
|
311
273
|
return [{ name: path, type, leaves: 1 }];
|
|
312
274
|
}
|
|
313
|
-
const name =
|
|
275
|
+
const name = symbolPathSegments(rest)[0] ?? rest;
|
|
314
276
|
const child = children.get(name) ?? { leaves: 0 };
|
|
315
277
|
children.set(name, {
|
|
316
278
|
type: rest === name ? type : undefined,
|
|
@@ -318,9 +280,11 @@ export const variableChildren = (
|
|
|
318
280
|
});
|
|
319
281
|
}
|
|
320
282
|
const indexes = [...children.keys()]
|
|
321
|
-
.
|
|
322
|
-
.
|
|
323
|
-
const listed = [...children].filter(
|
|
283
|
+
.map(arrayIndex)
|
|
284
|
+
.filter((index) => index !== undefined);
|
|
285
|
+
const listed = [...children].filter(
|
|
286
|
+
([name]) => arrayIndex(name) === undefined,
|
|
287
|
+
);
|
|
324
288
|
if (indexes.length) {
|
|
325
289
|
const first = children.get(`[${Math.min(...indexes)}]`);
|
|
326
290
|
listed.unshift([
|
|
@@ -380,65 +344,77 @@ const printLogin = (result: LoginResult) => {
|
|
|
380
344
|
}
|
|
381
345
|
};
|
|
382
346
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
export const runPlantCommand = async (
|
|
388
|
-
agent: AgentClient,
|
|
389
|
-
command: PlantCommand,
|
|
390
|
-
args: string[],
|
|
391
|
-
flags: PlantFlags,
|
|
347
|
+
interface PlantContext {
|
|
348
|
+
agent: AgentClient;
|
|
349
|
+
args: string[];
|
|
350
|
+
flags: PlantFlags;
|
|
392
351
|
project: {
|
|
393
|
-
file: string;
|
|
394
352
|
load: () => Promise<LoadedConfig>;
|
|
395
|
-
/**
|
|
396
|
-
|
|
353
|
+
/**
|
|
354
|
+
* Where a login-backed command reads the controller user: the loaded config's environment
|
|
355
|
+
* in a project, else this process's.
|
|
356
|
+
*/
|
|
357
|
+
environment: Environment;
|
|
397
358
|
/** Someone at a terminal can answer prompts. */
|
|
398
359
|
interactive: boolean;
|
|
399
|
-
},
|
|
400
|
-
) => {
|
|
401
|
-
const approval: Approval = {
|
|
402
|
-
yes: flags.yes ?? false,
|
|
403
|
-
interactive: project.interactive,
|
|
404
|
-
confirm: (question) => confirm(question, {}),
|
|
405
360
|
};
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
361
|
+
follow: Follow;
|
|
362
|
+
/** Throws the command's usage. */
|
|
363
|
+
usage: () => never;
|
|
364
|
+
/** Sends a login command through a login that is open, opening one first if none works. */
|
|
365
|
+
send: (command: LoginCommand) => Promise<void>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
interface PlantCommandEntry {
|
|
369
|
+
/** Its arguments and flags, after `tsplc <command>`. */
|
|
370
|
+
usage: string;
|
|
371
|
+
/** A deployment's compiler diagnostics when the program doesn't compile, the exit code of a command that queues a deployment. */
|
|
372
|
+
run: (
|
|
373
|
+
context: PlantContext,
|
|
374
|
+
) => Promise<
|
|
375
|
+
{ diagnostics: readonly Diagnostic[] } | { exitCode: number } | undefined
|
|
376
|
+
>;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Throws `usage` unless the command has no arguments. */
|
|
380
|
+
const none = ({ args, usage }: PlantContext) => {
|
|
381
|
+
if (args.length) {
|
|
382
|
+
usage();
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const plantCommands = {
|
|
387
|
+
deploy: {
|
|
388
|
+
usage:
|
|
389
|
+
"[--target name] [--download] [--select] [--initialize-user] [--simulate] [--review] [--wait] [-y]",
|
|
390
|
+
run: async (context) => {
|
|
391
|
+
none(context);
|
|
392
|
+
const { agent, project, flags, follow } = context;
|
|
393
|
+
return deploy(agent, await project.load(), flags, follow);
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
deployments: {
|
|
397
|
+
usage: "[--format json]",
|
|
398
|
+
run: async (context) => {
|
|
399
|
+
none(context);
|
|
400
|
+
await printDeployments(context.agent, context.flags);
|
|
401
|
+
return undefined;
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
rollback: {
|
|
405
|
+
usage: "[id] [--wait] [-y]",
|
|
406
|
+
run: async ({ agent, args, follow, usage }) => {
|
|
434
407
|
if (args.length > 1) {
|
|
435
|
-
|
|
408
|
+
usage();
|
|
436
409
|
}
|
|
437
410
|
return { exitCode: await rollBack(agent, args[0], follow) };
|
|
438
|
-
|
|
439
|
-
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
redeploy: {
|
|
414
|
+
usage: "<id> [--review] [--wait] [-y]",
|
|
415
|
+
run: async ({ agent, args: [id, ...extra], flags, follow, usage }) => {
|
|
440
416
|
if (!id || extra.length) {
|
|
441
|
-
|
|
417
|
+
return usage();
|
|
442
418
|
}
|
|
443
419
|
return {
|
|
444
420
|
exitCode: await redeploy(
|
|
@@ -448,36 +424,54 @@ export const runPlantCommand = async (
|
|
|
448
424
|
follow,
|
|
449
425
|
),
|
|
450
426
|
};
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
dashboard: {
|
|
430
|
+
usage: "",
|
|
431
|
+
run: async (context) => {
|
|
432
|
+
none(context);
|
|
433
|
+
openDashboard(context.agent, context.project.interactive);
|
|
434
|
+
return undefined;
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
target: {
|
|
438
|
+
usage: "",
|
|
439
|
+
run: async (context) => {
|
|
440
|
+
none(context);
|
|
441
|
+
const target = await selectTarget(context.agent);
|
|
458
442
|
console.log(`Deployments now go to ${target.host}:${target.port}.`);
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
await
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
443
|
+
return undefined;
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
status: {
|
|
447
|
+
usage: "",
|
|
448
|
+
run: async (context) => {
|
|
449
|
+
none(context);
|
|
450
|
+
await printStatus(context.agent);
|
|
451
|
+
return undefined;
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
login: {
|
|
455
|
+
usage: "",
|
|
456
|
+
run: async (context) => {
|
|
457
|
+
none(context);
|
|
458
|
+
await ensureLogin(context.agent, context.project.environment);
|
|
459
|
+
printLogin(await context.agent.command({ command: "state" }));
|
|
460
|
+
return undefined;
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
logout: {
|
|
464
|
+
usage: "",
|
|
465
|
+
run: async (context) => {
|
|
466
|
+
none(context);
|
|
467
|
+
const { agent, flags } = context;
|
|
471
468
|
const { login } = await agent.status();
|
|
472
469
|
const forced = login && "forced" in login ? login.forced : [];
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
!(await confirm(
|
|
470
|
+
if (forced.length) {
|
|
471
|
+
await confirmOrCancel(
|
|
476
472
|
`Forced: ${forced.join(", ")}. Forces stay on the controller after logout. Log out anyway?`,
|
|
477
473
|
flags,
|
|
478
|
-
)
|
|
479
|
-
) {
|
|
480
|
-
throw new Error("Cancelled.");
|
|
474
|
+
);
|
|
481
475
|
}
|
|
482
476
|
const { failure } = await agent.logout();
|
|
483
477
|
console.log(
|
|
@@ -485,77 +479,151 @@ export const runPlantCommand = async (
|
|
|
485
479
|
? `The login couldn't log out (${failure}); its container was removed.`
|
|
486
480
|
: "Logged out.",
|
|
487
481
|
);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
|
|
482
|
+
return undefined;
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
vars: {
|
|
486
|
+
usage: "[path]",
|
|
487
|
+
run: async ({ agent, args, usage }) => {
|
|
491
488
|
if (args.length > 1) {
|
|
492
|
-
|
|
489
|
+
usage();
|
|
493
490
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
491
|
+
await printVariables(agent, args[0]);
|
|
492
|
+
return undefined;
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
read: {
|
|
496
|
+
usage: "<expression>...",
|
|
497
|
+
run: async ({ args: [first, ...rest], send, usage }) => {
|
|
497
498
|
if (!first) {
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
return send({ command: "read", expressions: [first, ...rest] });
|
|
501
|
-
}
|
|
502
|
-
case "write":
|
|
503
|
-
case "force": {
|
|
504
|
-
const [expression, value, ...extra] = args;
|
|
505
|
-
if (!expression || !value || extra.length) {
|
|
506
|
-
throw new Error(`Usage: tsplc ${command} <expression> <value>`);
|
|
499
|
+
return usage();
|
|
507
500
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
501
|
+
await send({ command: "read", expressions: [first, ...rest] });
|
|
502
|
+
return undefined;
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
write: {
|
|
506
|
+
usage: "<expression> <value>",
|
|
507
|
+
run: (context) => setValue("write", context),
|
|
508
|
+
},
|
|
509
|
+
force: {
|
|
510
|
+
usage: "<expression> <value>",
|
|
511
|
+
run: (context) => setValue("force", context),
|
|
512
|
+
},
|
|
513
|
+
unforce: {
|
|
514
|
+
usage: "[expression]... [--restore]",
|
|
515
|
+
run: async ({ args, flags, send }) => {
|
|
516
|
+
await send({
|
|
512
517
|
command: "unforce",
|
|
513
518
|
expressions: args,
|
|
514
519
|
restore: flags.restore ?? false,
|
|
515
520
|
});
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
521
|
+
return undefined;
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
start: {
|
|
525
|
+
usage: "",
|
|
526
|
+
run: async (context) => {
|
|
527
|
+
none(context);
|
|
528
|
+
await context.send({ command: "start" });
|
|
529
|
+
return undefined;
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
stop: {
|
|
533
|
+
usage: "",
|
|
534
|
+
run: async (context) => {
|
|
535
|
+
none(context);
|
|
536
|
+
await confirmOrCancel(
|
|
537
|
+
"Stop the application on the controller?",
|
|
538
|
+
context.flags,
|
|
539
|
+
);
|
|
540
|
+
await context.send({ command: "stop" });
|
|
541
|
+
return undefined;
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
reset: {
|
|
545
|
+
usage: "warm|cold",
|
|
546
|
+
run: async ({ args, flags, send, usage }) => {
|
|
547
|
+
if (args.length !== 1) {
|
|
548
|
+
usage();
|
|
523
549
|
}
|
|
524
|
-
|
|
525
|
-
|
|
550
|
+
const kind = controllerRestartSchema.shape.reset.parse(args[0]);
|
|
551
|
+
await confirmOrCancel(
|
|
552
|
+
`Reset the application (${kind})? It stops and reinitializes its variables.`,
|
|
553
|
+
flags,
|
|
554
|
+
);
|
|
555
|
+
await send({ command: "reset", kind: resetLabel(kind) });
|
|
556
|
+
return undefined;
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
restart: {
|
|
560
|
+
usage: "[warm|cold] [-y]",
|
|
561
|
+
run: async ({ agent, args, flags, usage }) => {
|
|
526
562
|
if (args.length > 1) {
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
const reset = z.enum(["warm", "cold"]).parse(args[0] ?? "warm");
|
|
530
|
-
if (
|
|
531
|
-
!(await confirm(
|
|
532
|
-
`Reset the application (${reset}) and start it again? Its variables go back to their initial values${reset === "warm" ? ", but for retain ones" : ""}.`,
|
|
533
|
-
flags,
|
|
534
|
-
))
|
|
535
|
-
) {
|
|
536
|
-
throw new Error("Cancelled.");
|
|
563
|
+
usage();
|
|
537
564
|
}
|
|
565
|
+
const reset = controllerRestartSchema.shape.reset.parse(
|
|
566
|
+
args[0] ?? "warm",
|
|
567
|
+
);
|
|
568
|
+
await confirmOrCancel(
|
|
569
|
+
`Reset the application (${reset}) and start it again? Its variables go back to their initial values${reset === "warm" ? ", but for retain ones" : ""}.`,
|
|
570
|
+
flags,
|
|
571
|
+
);
|
|
538
572
|
const { state } = await agent.restartController({ reset });
|
|
539
573
|
console.log(
|
|
540
574
|
`Reset ${reset}; the application is ${state === "run" ? "running" : state}.`,
|
|
541
575
|
);
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
return send({
|
|
556
|
-
command: "reset",
|
|
557
|
-
kind: kind === "warm" ? "Warm" : "Cold",
|
|
558
|
-
});
|
|
559
|
-
}
|
|
576
|
+
return undefined;
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
} satisfies Record<string, PlantCommandEntry>;
|
|
580
|
+
|
|
581
|
+
/** `tsplc write` and `tsplc force`: one expression and its value. */
|
|
582
|
+
async function setValue(
|
|
583
|
+
command: "write" | "force",
|
|
584
|
+
{ args: [expression, value, ...extra], send, usage }: PlantContext,
|
|
585
|
+
) {
|
|
586
|
+
if (!expression || !value || extra.length) {
|
|
587
|
+
return usage();
|
|
560
588
|
}
|
|
589
|
+
await send({ command, values: { [expression]: value } });
|
|
590
|
+
return undefined;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export type PlantCommand = keyof typeof plantCommands;
|
|
594
|
+
|
|
595
|
+
export const isPlantCommand = (name: string): name is PlantCommand =>
|
|
596
|
+
Object.hasOwn(plantCommands, name);
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Runs a command against the plant agent. Returns a deployment's compiler diagnostics when the
|
|
600
|
+
* program doesn't compile, and the exit code of a command that queues a deployment.
|
|
601
|
+
*/
|
|
602
|
+
export const runPlantCommand = (
|
|
603
|
+
agent: AgentClient,
|
|
604
|
+
command: PlantCommand,
|
|
605
|
+
args: string[],
|
|
606
|
+
flags: PlantFlags,
|
|
607
|
+
project: PlantContext["project"],
|
|
608
|
+
) => {
|
|
609
|
+
const entry: PlantCommandEntry = plantCommands[command];
|
|
610
|
+
const approval: Approval = {
|
|
611
|
+
yes: flags.yes ?? false,
|
|
612
|
+
interactive: project.interactive,
|
|
613
|
+
confirm,
|
|
614
|
+
};
|
|
615
|
+
return entry.run({
|
|
616
|
+
agent,
|
|
617
|
+
args,
|
|
618
|
+
flags,
|
|
619
|
+
project,
|
|
620
|
+
follow: { wait: flags.wait ?? false, approval },
|
|
621
|
+
usage: () => {
|
|
622
|
+
throw new Error(`Usage: tsplc ${command} ${entry.usage}`);
|
|
623
|
+
},
|
|
624
|
+
send: async (loginCommand) => {
|
|
625
|
+
await ensureLogin(agent, project.environment);
|
|
626
|
+
printLogin(await agent.command(loginCommand));
|
|
627
|
+
},
|
|
628
|
+
});
|
|
561
629
|
};
|