@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/debugger.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { relative, resolve } from "node:path";
|
|
3
|
-
import
|
|
3
|
+
import type { ParseArgsOptionsConfig } from "node:util";
|
|
4
|
+
import type { AgentClient } from "@tsplc/agent/client";
|
|
5
|
+
import {
|
|
6
|
+
agentUrlEnv,
|
|
7
|
+
type LoadedConfig,
|
|
8
|
+
serverBaseUrl,
|
|
9
|
+
serverTokenEnv,
|
|
10
|
+
} from "@tsplc/config";
|
|
4
11
|
import { tcpPort } from "@tsplc/config/build";
|
|
5
12
|
import {
|
|
6
13
|
emittedStDirectory,
|
|
@@ -8,16 +15,30 @@ import {
|
|
|
8
15
|
} from "@tsplc/config/project-files";
|
|
9
16
|
import {
|
|
10
17
|
createDebugger,
|
|
11
|
-
createLoginAdapter,
|
|
12
18
|
createOpcUaAdapter,
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
loadDebugBuild,
|
|
20
|
+
loginReader,
|
|
15
21
|
opcUaConnection,
|
|
16
22
|
serveDebugger,
|
|
17
23
|
} from "@tsplc/debug";
|
|
18
24
|
import { debugManifestFile } from "@tsplc/debug/manifest";
|
|
25
|
+
import { type Flags, flag } from "./flags";
|
|
19
26
|
import { connect, readThroughAgent } from "./plant";
|
|
20
27
|
|
|
28
|
+
type Monitor = NonNullable<LoadedConfig["config"]["monitor"]>;
|
|
29
|
+
|
|
30
|
+
/** Where the debugger serves without `--port`. */
|
|
31
|
+
const debuggerPort = 4870;
|
|
32
|
+
|
|
33
|
+
/** The flags of `tsplc debug`. */
|
|
34
|
+
export const debugOptions = {
|
|
35
|
+
port: { type: "string" },
|
|
36
|
+
"server-url": { type: "string" },
|
|
37
|
+
opcua: flag,
|
|
38
|
+
} as const satisfies ParseArgsOptionsConfig;
|
|
39
|
+
|
|
40
|
+
export const debugUsage = `[--target name] [--port ${debuggerPort}] [--server-url url] [--opcua]`;
|
|
41
|
+
|
|
21
42
|
/**
|
|
22
43
|
* Serves the debugger for the project's last build until interrupted. It reads the controller
|
|
23
44
|
* through the plant agent's login, or with `--opcua` at the config's `monitor` endpoint, and
|
|
@@ -26,59 +47,52 @@ import { connect, readThroughAgent } from "./plant";
|
|
|
26
47
|
*/
|
|
27
48
|
export async function serveProjectDebugger(
|
|
28
49
|
{ config, root, env }: LoadedConfig,
|
|
29
|
-
flags:
|
|
50
|
+
flags: Flags<typeof debugOptions>,
|
|
30
51
|
) {
|
|
31
52
|
if (flags.opcua && !config.monitor) {
|
|
32
53
|
throw new Error(
|
|
33
54
|
"Configure monitor with the controller's OPC UA endpoint to use --opcua.",
|
|
34
55
|
);
|
|
35
56
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
41
|
-
}
|
|
57
|
+
const reader: { monitor: Monitor } | { agent: AgentClient } =
|
|
58
|
+
flags.opcua && config.monitor
|
|
59
|
+
? { monitor: config.monitor }
|
|
60
|
+
: { agent: connect(env) };
|
|
42
61
|
const file = resolve(root, emittedStDirectory, debugManifestFile);
|
|
43
62
|
if (!existsSync(file)) {
|
|
44
63
|
throw new Error(
|
|
45
|
-
`No debug manifest at ${relative(process.cwd(), file)}: build with
|
|
64
|
+
`No debug manifest at ${relative(process.cwd(), file)}: build the program first, with tsplc build or tsplc build --emit-only.`,
|
|
46
65
|
);
|
|
47
66
|
}
|
|
48
|
-
const port = tcpPort.safeParse(Number(flags.port ??
|
|
67
|
+
const port = tcpPort.safeParse(Number(flags.port ?? debuggerPort));
|
|
49
68
|
if (!port.success) {
|
|
50
69
|
throw new Error("--port must be a TCP port.");
|
|
51
70
|
}
|
|
52
|
-
const
|
|
53
|
-
const serverUrl =
|
|
54
|
-
flags["server-url"] ??
|
|
55
|
-
(config.server?.baseUrlEnv && env[config.server.baseUrlEnv]);
|
|
71
|
+
const serverUrl = flags["server-url"] ?? serverBaseUrl(config, env);
|
|
56
72
|
const tokenEnv = serverTokenEnv(config);
|
|
57
73
|
const token = tokenEnv && env[tokenEnv];
|
|
58
74
|
const log = (message: string) =>
|
|
59
75
|
console.log(`${new Date().toISOString()} ${message}`);
|
|
76
|
+
const build = await loadDebugBuild(file);
|
|
60
77
|
const debug = await createDebugger({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
...build,
|
|
79
|
+
...("monitor" in reader
|
|
80
|
+
? {
|
|
81
|
+
// An OPC UA endpoint reports no forced list.
|
|
82
|
+
adapter: createOpcUaAdapter(
|
|
83
|
+
opcUaConnection(reader.monitor, { root, env }),
|
|
84
|
+
),
|
|
85
|
+
forced: null,
|
|
86
|
+
}
|
|
87
|
+
: loginReader(build.manifest, {
|
|
88
|
+
read: readThroughAgent(reader.agent),
|
|
89
|
+
status: async () => (await reader.agent.status()).login,
|
|
90
|
+
endpoint: `the plant agent at ${env[agentUrlEnv]}`,
|
|
91
|
+
})),
|
|
70
92
|
stateDirectory: resolve(root, generatedDirectory, "debug"),
|
|
71
93
|
watch: config.debug?.watch ?? {},
|
|
72
94
|
...(serverUrl && token && { server: { url: serverUrl, token } }),
|
|
73
95
|
projectRoot: root,
|
|
74
|
-
explanations: await loadExplanations(file, manifest),
|
|
75
|
-
// The forced list comes from the agent's login; an OPC UA endpoint has no such list.
|
|
76
|
-
forced: flags.opcua
|
|
77
|
-
? null
|
|
78
|
-
: async () => {
|
|
79
|
-
const { login } = await connect(env).status();
|
|
80
|
-
return login && "forced" in login ? login.forced : null;
|
|
81
|
-
},
|
|
82
96
|
log,
|
|
83
97
|
});
|
|
84
98
|
const server = serveDebugger(debug, { port: port.data, log });
|
|
@@ -5,11 +5,7 @@ import type {
|
|
|
5
5
|
DeployOptions,
|
|
6
6
|
GitSource,
|
|
7
7
|
} from "@tsplc/agent";
|
|
8
|
-
import {
|
|
9
|
-
type AgentClient,
|
|
10
|
-
AgentOperationError,
|
|
11
|
-
AgentUnreachable,
|
|
12
|
-
} from "@tsplc/agent/client";
|
|
8
|
+
import { type AgentClient, AgentUnreachable } from "@tsplc/agent/client";
|
|
13
9
|
import { describeFinding } from "@tsplc/build";
|
|
14
10
|
import { progress, timedProgress } from "./terminal";
|
|
15
11
|
|
|
@@ -228,13 +224,10 @@ const queued = async (
|
|
|
228
224
|
return followDeployment(agent, created, follow.approval);
|
|
229
225
|
};
|
|
230
226
|
|
|
231
|
-
/**
|
|
232
|
-
* Uploads a built release as a queued deployment and prints its page. An agent without the
|
|
233
|
-
* deployments API deploys it at once instead, as `tsplc deploy` did before.
|
|
234
|
-
*/
|
|
227
|
+
/** Uploads a built release as a queued deployment and prints its page. */
|
|
235
228
|
export const submitDeployment = async (
|
|
236
229
|
agent: AgentClient,
|
|
237
|
-
release: Parameters<AgentClient["
|
|
230
|
+
release: Parameters<AgentClient["queueDeployment"]>[0],
|
|
238
231
|
settings: Omit<DeployOptions, "deployment">,
|
|
239
232
|
request: { mode: DeploymentMode; git: GitSource | null },
|
|
240
233
|
follow: Follow,
|
|
@@ -245,65 +238,15 @@ export const submitDeployment = async (
|
|
|
245
238
|
{ ...settings, deployment: request },
|
|
246
239
|
uploading,
|
|
247
240
|
);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
console.log("Once reviewed, it waits for approval on its page.");
|
|
252
|
-
}
|
|
253
|
-
return queued(agent, created, follow);
|
|
254
|
-
}
|
|
255
|
-
if (request.mode === "review") {
|
|
256
|
-
throw new Error(
|
|
257
|
-
"This plant agent can't review a deployment before applying it; deploy without --review.",
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
console.log("This plant agent can't queue deployments; deploying at once.");
|
|
261
|
-
const deployed = await deployAtOnce(
|
|
262
|
-
agent,
|
|
263
|
-
release,
|
|
264
|
-
settings,
|
|
265
|
-
follow.approval,
|
|
266
|
-
);
|
|
267
|
-
console.log(`Deployed release ${deployed.id} (${deployed.operation}).`);
|
|
268
|
-
return 0;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/** Deploys through `POST /deploy`, offering a full download when only one can deploy. */
|
|
272
|
-
const deployAtOnce = async (
|
|
273
|
-
agent: AgentClient,
|
|
274
|
-
release: Parameters<AgentClient["deploy"]>[0],
|
|
275
|
-
settings: Omit<DeployOptions, "deployment">,
|
|
276
|
-
approval: Approval,
|
|
277
|
-
) => {
|
|
278
|
-
const deploying = timedProgress();
|
|
279
|
-
try {
|
|
280
|
-
return await agent.deploy(release, settings, deploying);
|
|
281
|
-
} catch (error) {
|
|
282
|
-
if (
|
|
283
|
-
!(error instanceof AgentOperationError && error.downloadRequired) ||
|
|
284
|
-
!(
|
|
285
|
-
approval.yes ||
|
|
286
|
-
(await approval.confirm(
|
|
287
|
-
`${error.message}. A full download stops the running application while it loads. Download now?`,
|
|
288
|
-
))
|
|
289
|
-
)
|
|
290
|
-
) {
|
|
291
|
-
throw error;
|
|
292
|
-
}
|
|
293
|
-
return agent.deploy(
|
|
294
|
-
release,
|
|
295
|
-
{ ...settings, download: true },
|
|
296
|
-
timedProgress(),
|
|
297
|
-
);
|
|
241
|
+
uploading("Uploaded");
|
|
242
|
+
if (request.mode === "review" && !follow.wait) {
|
|
243
|
+
console.log("Once reviewed, it waits for approval on its page.");
|
|
298
244
|
}
|
|
245
|
+
return queued(agent, created, follow);
|
|
299
246
|
};
|
|
300
247
|
|
|
301
248
|
/** The deployments `GET /api/deployments` answers, newest first, with the running and last healthy ones. */
|
|
302
|
-
|
|
303
|
-
deployments: DeploymentRecord[];
|
|
304
|
-
current: string | null;
|
|
305
|
-
lastGood: string | null;
|
|
306
|
-
}
|
|
249
|
+
type DeploymentList = Awaited<ReturnType<AgentClient["deployments"]>>;
|
|
307
250
|
|
|
308
251
|
/**
|
|
309
252
|
* Where `tsplc rollback` goes without an id: the newest deployment before the running one that
|
|
@@ -366,8 +309,9 @@ export const printDeployments = async (
|
|
|
366
309
|
return;
|
|
367
310
|
}
|
|
368
311
|
const now = Date.now();
|
|
312
|
+
const header = ["ID", "STATE", "AGE", "RELEASE", "COMMIT", "BY", ""];
|
|
369
313
|
const rows = [
|
|
370
|
-
|
|
314
|
+
header,
|
|
371
315
|
...list.deployments.map((deployment) => [
|
|
372
316
|
deployment.id,
|
|
373
317
|
deployment.state,
|
|
@@ -383,13 +327,13 @@ export const printDeployments = async (
|
|
|
383
327
|
.join(", "),
|
|
384
328
|
]),
|
|
385
329
|
];
|
|
386
|
-
const widths =
|
|
330
|
+
const widths = header.map((_, column) =>
|
|
387
331
|
Math.max(...rows.map((row) => row[column]?.length ?? 0)),
|
|
388
332
|
);
|
|
389
333
|
for (const row of rows) {
|
|
390
334
|
console.log(
|
|
391
335
|
row
|
|
392
|
-
.map((cell, column) => cell.padEnd(widths
|
|
336
|
+
.map((cell, column) => cell.padEnd(widths[column] ?? 0))
|
|
393
337
|
.join(" ")
|
|
394
338
|
.trimEnd(),
|
|
395
339
|
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ParseArgsOptionsConfig, parseArgs } from "node:util";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/** The flags `options` declares, as `parseArgs` reads them. */
|
|
5
|
+
export type Flags<Options extends ParseArgsOptionsConfig> = ReturnType<
|
|
6
|
+
typeof parseArgs<{ options: Options }>
|
|
7
|
+
>["values"];
|
|
8
|
+
|
|
9
|
+
/** A flag that takes no value. */
|
|
10
|
+
export const flag = { type: "boolean" } as const;
|
|
11
|
+
|
|
12
|
+
/** `--format`: JSON results on standard output, or text. */
|
|
13
|
+
export const outputFormatSchema = z.enum(["json", "text"]);
|
|
14
|
+
export type OutputFormat = z.infer<typeof outputFormatSchema>;
|