@tsplc/compiler 0.2.17 → 0.2.19
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 +2 -2
- package/dist/cli.js +920 -943
- package/dist/cli.js.map +13 -10
- package/dist/codesys.js +3893 -3352
- package/dist/codesys.js.map +29 -20
- package/dist/elaborate-capture.js +33 -17
- package/dist/elaborate-capture.js.map +3 -3
- package/dist/index.js +8787 -6855
- package/dist/index.js.map +40 -20
- package/dist/ir.js +1575 -1072
- package/dist/ir.js.map +21 -17
- package/dist/math.js.map +2 -2
- package/dist/project.js +154 -60
- package/dist/project.js.map +5 -5
- package/dist/telemetry.js +27 -9
- package/dist/telemetry.js.map +5 -5
- package/package.json +112 -112
- package/src/codesys/config.ts +50 -0
- package/src/codesys/debug.ts +670 -0
- package/src/codesys/emit.ts +142 -0
- package/src/codesys/engineering.ts +109 -0
- package/src/codesys/expressions.ts +92 -0
- package/src/codesys/global-lists.ts +250 -0
- package/src/codesys/global-names.ts +68 -0
- package/src/codesys/http.ts +890 -0
- package/src/codesys/index.ts +30 -0
- package/src/codesys/instrumentation.ts +430 -0
- package/src/codesys/io-paths.ts +140 -0
- package/src/codesys/manifest.ts +643 -0
- package/src/codesys/names.ts +81 -0
- package/src/codesys/numeric.ts +409 -0
- package/src/codesys/operands.ts +62 -0
- package/src/codesys/plan.ts +605 -0
- package/src/codesys/programs.ts +53 -0
- package/src/codesys/publication.ts +171 -0
- package/src/codesys/routines.ts +603 -0
- package/src/codesys/sources.ts +71 -0
- package/src/codesys/st-files.ts +115 -0
- package/src/codesys/storage.ts +97 -0
- package/src/codesys/symbols.ts +220 -0
- package/src/codesys/task-access.ts +320 -0
- package/src/codesys/telemetry.ts +732 -0
- package/src/codesys/types.ts +250 -0
- package/src/codesys/vendor.ts +150 -0
- package/src/frontend/analyzer.ts +794 -0
- package/src/frontend/async.ts +317 -1137
- package/src/frontend/blocks.ts +537 -403
- package/src/frontend/configuration.ts +176 -144
- package/src/frontend/const-functions.ts +183 -148
- package/src/frontend/cooperative.ts +73 -43
- package/src/frontend/coroutines.ts +1032 -0
- package/src/frontend/elaborate/calls.ts +535 -0
- package/src/frontend/elaborate/capture.ts +157 -101
- package/src/frontend/elaborate/dialect.ts +257 -0
- package/src/frontend/elaborate/expressions.ts +992 -0
- package/src/frontend/elaborate/frame.ts +53 -0
- package/src/frontend/elaborate/graph.ts +116 -71
- package/src/frontend/elaborate/imports.ts +70 -0
- package/src/frontend/elaborate/index.ts +435 -331
- package/src/frontend/elaborate/initializers.ts +198 -0
- package/src/frontend/elaborate/layouts.ts +591 -384
- package/src/frontend/elaborate/model.ts +264 -169
- package/src/frontend/elaborate/specialize.ts +343 -2586
- package/src/frontend/elaborate/statements.ts +606 -0
- package/src/frontend/elaborate/storage.ts +546 -0
- package/src/frontend/elaborate/values.ts +58 -0
- package/src/frontend/elaborate/writes.ts +100 -0
- package/src/frontend/exposure.ts +172 -140
- package/src/frontend/expressions.ts +1383 -0
- package/src/frontend/intrinsics.ts +337 -0
- package/src/frontend/module-graph.ts +89 -59
- package/src/frontend/positions.ts +271 -200
- package/src/frontend/promise-chains.ts +897 -0
- package/src/frontend/promises.ts +390 -747
- package/src/frontend/routines.ts +181 -0
- package/src/frontend/sdk.ts +82 -0
- package/src/frontend/services.ts +506 -372
- package/src/frontend/statements.ts +855 -0
- package/src/frontend/tasks.ts +471 -0
- package/src/frontend/telemetry.ts +174 -0
- package/src/frontend/types.ts +845 -551
- package/src/frontend/typescript.ts +323 -2543
- package/src/index.ts +5 -5
- package/src/ir/aggregates.ts +275 -0
- package/src/ir/allocation.ts +84 -0
- package/src/ir/core-model.ts +146 -0
- package/src/ir/declarations.ts +295 -0
- package/src/ir/diagnostics.ts +61 -0
- package/src/ir/domains.ts +152 -0
- package/src/ir/fold.ts +342 -0
- package/src/ir/index.ts +90 -0
- package/{ir/errors.ts → src/ir/job-errors.ts} +12 -10
- package/src/ir/layouts.ts +181 -0
- package/src/ir/link.ts +354 -0
- package/src/ir/model.ts +386 -0
- package/{ir → src/ir}/normalization-error.ts +4 -4
- package/src/ir/normalize.ts +70 -0
- package/src/ir/numeric.ts +171 -0
- package/src/ir/ranges.ts +256 -0
- package/src/ir/routine.ts +1163 -0
- package/src/ir/scalars.ts +321 -0
- package/src/ir/types.ts +127 -0
- package/src/project/artifacts.ts +342 -0
- package/src/project/cli.ts +177 -0
- package/src/project/debugger.ts +82 -0
- package/src/project/index.ts +6 -0
- package/src/project/plant.ts +467 -0
- package/src/project/project-commands.ts +372 -0
- package/src/project/project.ts +457 -0
- package/src/project/release.ts +153 -0
- package/src/project/server.ts +150 -0
- package/src/project/terminal.ts +32 -0
- package/stdlib/math.ts +14 -10
- package/stdlib/telemetry.ts +71 -47
- package/types/async.d.ts +46 -40
- package/types/data-types.d.ts +26 -26
- package/types/globals.d.ts +41 -38
- package/types/index.d.ts +96 -51
- package/types/plc.d.ts +3 -4
- package/types/telemetry.d.ts +14 -14
- package/backends/codesys/config.ts +0 -54
- package/backends/codesys/debug.ts +0 -509
- package/backends/codesys/emit.ts +0 -1738
- package/backends/codesys/engineering.ts +0 -88
- package/backends/codesys/global-names.ts +0 -49
- package/backends/codesys/http.ts +0 -675
- package/backends/codesys/index.ts +0 -13
- package/backends/codesys/io-paths.ts +0 -105
- package/backends/codesys/manifest.ts +0 -312
- package/backends/codesys/names.ts +0 -76
- package/backends/codesys/numeric.ts +0 -356
- package/backends/codesys/plan.ts +0 -457
- package/backends/codesys/publication.ts +0 -59
- package/backends/codesys/storage.ts +0 -70
- package/backends/codesys/task-access.ts +0 -293
- package/backends/codesys/telemetry.ts +0 -593
- package/backends/codesys/types.ts +0 -179
- package/backends/codesys/vendor.ts +0 -108
- package/ir/aggregates.ts +0 -333
- package/ir/allocation.ts +0 -74
- package/ir/core-model.ts +0 -129
- package/ir/core.ts +0 -64
- package/ir/declarations.ts +0 -208
- package/ir/diagnostics.ts +0 -43
- package/ir/domains.ts +0 -96
- package/ir/index.ts +0 -8
- package/ir/link.ts +0 -185
- package/ir/model.ts +0 -346
- package/ir/routine.ts +0 -859
- package/ir/scalars.ts +0 -675
- package/ir/types.ts +0 -76
- package/project/artifacts.ts +0 -277
- package/project/cli.ts +0 -395
- package/project/index.ts +0 -1
- package/project/plant.ts +0 -509
- package/project/project.ts +0 -358
- package/project/server.ts +0 -113
package/project/cli.ts
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { buildServer } from "./server.ts";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { parseArgs } from "node:util";
|
|
5
|
-
import { relative, resolve } from "node:path";
|
|
6
|
-
import {
|
|
7
|
-
buildTargetFor,
|
|
8
|
-
controllerFor,
|
|
9
|
-
loadTsplcConfig,
|
|
10
|
-
rawBuildConfig,
|
|
11
|
-
simulationConfig,
|
|
12
|
-
} from "@tsplc/config";
|
|
13
|
-
import {
|
|
14
|
-
buildProject as buildSt,
|
|
15
|
-
configureDocker,
|
|
16
|
-
configureRuntime,
|
|
17
|
-
inspectController,
|
|
18
|
-
installLibraries,
|
|
19
|
-
loadSources,
|
|
20
|
-
resolveConfig,
|
|
21
|
-
runProject,
|
|
22
|
-
updateController,
|
|
23
|
-
} from "@tsplc/build";
|
|
24
|
-
import { checkHostConfig } from "@tsplc/compiler";
|
|
25
|
-
import {
|
|
26
|
-
createDebugger,
|
|
27
|
-
createLoginAdapter,
|
|
28
|
-
createOpcUaAdapter,
|
|
29
|
-
loadManifest,
|
|
30
|
-
opcUaConnection,
|
|
31
|
-
serveDebugger,
|
|
32
|
-
} from "@tsplc/debug";
|
|
33
|
-
import { type Diagnostic, formatDiagnostic, hasErrors } from "@tsplc/compiler/ir";
|
|
34
|
-
import { deviceTree } from "@tsplc/typegen";
|
|
35
|
-
import { loadHardware, resolveIo } from "@tsplc/typegen/hardware";
|
|
36
|
-
import { generateProject } from "@tsplc/typegen";
|
|
37
|
-
import {
|
|
38
|
-
connect,
|
|
39
|
-
plantCommands,
|
|
40
|
-
readThroughAgent,
|
|
41
|
-
runPlantCommand,
|
|
42
|
-
serverTokenEnv,
|
|
43
|
-
} from "./plant.ts";
|
|
44
|
-
import { buildProject, checkProject, cleanProject, projectTargets } from "./project.ts";
|
|
45
|
-
|
|
46
|
-
async function main() {
|
|
47
|
-
const { values, positionals } = parseArgs({
|
|
48
|
-
allowPositionals: true,
|
|
49
|
-
options: {
|
|
50
|
-
config: { type: "string" },
|
|
51
|
-
help: { type: "boolean", short: "h" },
|
|
52
|
-
"emit-only": { type: "boolean" },
|
|
53
|
-
format: { type: "string" },
|
|
54
|
-
read: { type: "string", multiple: true },
|
|
55
|
-
"initialize-user": { type: "boolean" },
|
|
56
|
-
"frozen-lockfile": { type: "boolean" },
|
|
57
|
-
check: { type: "boolean" },
|
|
58
|
-
plc: { type: "boolean" },
|
|
59
|
-
server: { type: "boolean" },
|
|
60
|
-
simulate: { type: "boolean" },
|
|
61
|
-
runtime: { type: "boolean" },
|
|
62
|
-
download: { type: "boolean" },
|
|
63
|
-
restore: { type: "boolean" },
|
|
64
|
-
select: { type: "boolean" },
|
|
65
|
-
yes: { type: "boolean", short: "y" },
|
|
66
|
-
port: { type: "string" },
|
|
67
|
-
"server-url": { type: "string" },
|
|
68
|
-
opcua: { type: "boolean" },
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const command = positionals[0],
|
|
72
|
-
file = values.config ?? "tsplc.config.ts";
|
|
73
|
-
if (!command || values.help) {
|
|
74
|
-
console.log(
|
|
75
|
-
`tsplc install|typegen|check|build|run|download|online-change|inspect|clean|configure [--config tsplc.config.ts] [--plc|--server] [--simulate] [--runtime] [--emit-only] [--format json] [--read symbol]
|
|
76
|
-
|
|
77
|
-
Plant agent (TSPLC_AGENT_URL, TSPLC_AGENT_TOKEN):
|
|
78
|
-
tsplc deploy [--download] [--select] [--initialize-user] [--simulate]
|
|
79
|
-
tsplc target | status | login | logout
|
|
80
|
-
tsplc vars [path] | read <expression>... | write <expression> <value>
|
|
81
|
-
tsplc force <expression> <value> | unforce [expression]... [--restore]
|
|
82
|
-
tsplc start | stop | reset warm|cold (-y skips confirmations)
|
|
83
|
-
|
|
84
|
-
Debugger, on http://127.0.0.1, for the built .tsplc/artifacts/st/debug.json; it reads through
|
|
85
|
-
the plant agent's login (TSPLC_AGENT_URL, TSPLC_AGENT_TOKEN), or --opcua at config monitor:
|
|
86
|
-
tsplc debug [--port 4870] [--server-url url] [--opcua]`,
|
|
87
|
-
);
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
if (command === "debug") {
|
|
91
|
-
if (positionals.length > 1)
|
|
92
|
-
throw new Error("Usage: tsplc debug [--port 4870] [--server-url url] [--opcua]");
|
|
93
|
-
await serveProjectDebugger(await loadTsplcConfig(file), values);
|
|
94
|
-
return 0;
|
|
95
|
-
}
|
|
96
|
-
if (plantCommands.has(command)) {
|
|
97
|
-
const failed = await runPlantCommand(command, positionals.slice(1), values, {
|
|
98
|
-
file,
|
|
99
|
-
load: () => loadTsplcConfig(file),
|
|
100
|
-
});
|
|
101
|
-
return failed ? report(failed, values.format) : 0;
|
|
102
|
-
}
|
|
103
|
-
if (positionals.length > 1) throw new Error("Specify one command.");
|
|
104
|
-
if (
|
|
105
|
-
![
|
|
106
|
-
"install",
|
|
107
|
-
"typegen",
|
|
108
|
-
"check",
|
|
109
|
-
"build",
|
|
110
|
-
"run",
|
|
111
|
-
"download",
|
|
112
|
-
"online-change",
|
|
113
|
-
"inspect",
|
|
114
|
-
"clean",
|
|
115
|
-
"configure",
|
|
116
|
-
].includes(command)
|
|
117
|
-
)
|
|
118
|
-
throw new Error(`Unknown command ${command}.`);
|
|
119
|
-
if (values.format && !["json", "text"].includes(values.format))
|
|
120
|
-
throw new Error("--format must be json or text.");
|
|
121
|
-
if (values["emit-only"] && command !== "build")
|
|
122
|
-
throw new Error("--emit-only is supported by build only.");
|
|
123
|
-
if (values.runtime && command !== "configure")
|
|
124
|
-
throw new Error("--runtime applies only to configure.");
|
|
125
|
-
if ((values.plc || values.server) && command !== "build")
|
|
126
|
-
throw new Error("--plc and --server apply only to build.");
|
|
127
|
-
if (values.simulate && !["run", "download", "online-change", "deploy"].includes(command))
|
|
128
|
-
throw new Error("--simulate applies only to run, download, online-change and deploy.");
|
|
129
|
-
if (values.plc && values.server)
|
|
130
|
-
throw new Error("Choose --plc or --server, or omit both for a full build.");
|
|
131
|
-
if (values.server && values["emit-only"])
|
|
132
|
-
throw new Error("--emit-only applies to PLC emission only.");
|
|
133
|
-
const log = console.log,
|
|
134
|
-
previousLogTarget = process.env["TSPLC_LOG_STDERR"];
|
|
135
|
-
if (values.format === "json") {
|
|
136
|
-
console.log = console.error;
|
|
137
|
-
process.env["TSPLC_LOG_STDERR"] = "1";
|
|
138
|
-
}
|
|
139
|
-
let result: unknown;
|
|
140
|
-
try {
|
|
141
|
-
if (command === "configure") {
|
|
142
|
-
await (values.runtime ? configureRuntime() : configureDocker());
|
|
143
|
-
result = { ok: true };
|
|
144
|
-
} else if (command === "clean") {
|
|
145
|
-
result = await cleanProject(file);
|
|
146
|
-
} else {
|
|
147
|
-
if (["check", "build", "run", "download", "online-change"].includes(command)) {
|
|
148
|
-
const diagnostics = checkHostConfig(resolve(file));
|
|
149
|
-
if (hasErrors(diagnostics)) throw new DiagnosticFailure({ diagnostics });
|
|
150
|
-
}
|
|
151
|
-
const loaded = await loadTsplcConfig(file);
|
|
152
|
-
const { config, configFile, root } = loaded;
|
|
153
|
-
// Generated types keep describing the hardware project; only the download omits fieldbus I/O.
|
|
154
|
-
const target = values.simulate ? { ...loaded, config: simulationConfig(config) } : loaded;
|
|
155
|
-
if (command === "install")
|
|
156
|
-
result = {
|
|
157
|
-
libraries: await installLibraries(config.dependencies, root, {
|
|
158
|
-
frozen: values["frozen-lockfile"],
|
|
159
|
-
}),
|
|
160
|
-
};
|
|
161
|
-
else if (command === "typegen") {
|
|
162
|
-
const targets = await projectTargets(file, { loaded });
|
|
163
|
-
if (config.compiler && !values.check) {
|
|
164
|
-
await generateProject(file, { hardwareOnly: true, loaded, targets });
|
|
165
|
-
const emitted = await buildProject(file, { emitOnly: true, loaded });
|
|
166
|
-
if (hasErrors(emitted.diagnostics)) throw new DiagnosticFailure(emitted);
|
|
167
|
-
}
|
|
168
|
-
result = await generateProject(file, { check: values.check, loaded, targets });
|
|
169
|
-
} else if (command === "check") {
|
|
170
|
-
result = config.compiler
|
|
171
|
-
? await checkProject(file, { loaded })
|
|
172
|
-
: {
|
|
173
|
-
objects: (
|
|
174
|
-
await loadSources(
|
|
175
|
-
resolveConfig(
|
|
176
|
-
{
|
|
177
|
-
...rawBuildConfig(config),
|
|
178
|
-
io: resolveIo(config, await loadHardware(config, root)),
|
|
179
|
-
},
|
|
180
|
-
configFile,
|
|
181
|
-
),
|
|
182
|
-
)
|
|
183
|
-
).objects.length,
|
|
184
|
-
};
|
|
185
|
-
} else if (command === "build" && values.server) {
|
|
186
|
-
result = await buildServer(config, root);
|
|
187
|
-
} else if (command === "build" || command === "run") {
|
|
188
|
-
if (config.compiler) {
|
|
189
|
-
const built = await buildProject(file, {
|
|
190
|
-
emitOnly: values["emit-only"],
|
|
191
|
-
frozenLockfile: values["frozen-lockfile"],
|
|
192
|
-
loaded: target,
|
|
193
|
-
...(values.simulate && { configured: config }),
|
|
194
|
-
controller: controllerFor(config, command),
|
|
195
|
-
buildTarget: buildTargetFor(command),
|
|
196
|
-
});
|
|
197
|
-
if (hasErrors(built.diagnostics)) throw new DiagnosticFailure(built);
|
|
198
|
-
await generateProject(file, {
|
|
199
|
-
loaded,
|
|
200
|
-
targets: await projectTargets(file, { loaded }),
|
|
201
|
-
});
|
|
202
|
-
result = built;
|
|
203
|
-
} else {
|
|
204
|
-
if (values["emit-only"]) throw new Error("Raw Structured Text is already emitted.");
|
|
205
|
-
if (!config.build) throw new Error("Configure build settings.");
|
|
206
|
-
const build = rawBuildConfig(config);
|
|
207
|
-
const libraries = await installLibraries(config.dependencies, root, {
|
|
208
|
-
frozen: values["frozen-lockfile"],
|
|
209
|
-
});
|
|
210
|
-
const hardware = await loadHardware(target.config, root);
|
|
211
|
-
result = await buildSt(
|
|
212
|
-
resolveConfig(
|
|
213
|
-
{
|
|
214
|
-
...build,
|
|
215
|
-
libraries,
|
|
216
|
-
io: resolveIo(target.config, hardware),
|
|
217
|
-
deviceTree: await deviceTree(target.config, hardware),
|
|
218
|
-
controller: controllerFor(config, command),
|
|
219
|
-
},
|
|
220
|
-
configFile,
|
|
221
|
-
),
|
|
222
|
-
);
|
|
223
|
-
await generateProject(file, { hardwareOnly: !config.typegen, loaded });
|
|
224
|
-
}
|
|
225
|
-
if (command === "build" && !values.plc && !values["emit-only"] && config.server?.runtime) {
|
|
226
|
-
const backend = await buildServer(config, root);
|
|
227
|
-
result = { ...(typeof result === "object" && result !== null ? result : {}), ...backend };
|
|
228
|
-
}
|
|
229
|
-
if (command === "run") {
|
|
230
|
-
if (!config.build) throw new Error("Configure build to run this project.");
|
|
231
|
-
await runProject(
|
|
232
|
-
resolveConfig(config.compiler ? config.build : rawBuildConfig(config), configFile),
|
|
233
|
-
config.name,
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
} else if (command === "inspect") {
|
|
237
|
-
if (!config.build) throw new Error("Configure build settings and controller connection.");
|
|
238
|
-
// Inspection needs only the connection/baseline. It must remain usable
|
|
239
|
-
// when local sources, descriptors or dependency caches are unavailable.
|
|
240
|
-
result = await inspectController(
|
|
241
|
-
resolveConfig(
|
|
242
|
-
{ ...config.build, controller: controllerFor(config, command) },
|
|
243
|
-
configFile,
|
|
244
|
-
),
|
|
245
|
-
values.read,
|
|
246
|
-
);
|
|
247
|
-
} else if (["download", "online-change"].includes(command)) {
|
|
248
|
-
if (!config.build) throw new Error("Configure build settings and controller connection.");
|
|
249
|
-
let settings: ReturnType<typeof resolveConfig>;
|
|
250
|
-
if (config.compiler) {
|
|
251
|
-
const emitted = await buildProject(file, {
|
|
252
|
-
emitOnly: true,
|
|
253
|
-
forController: true,
|
|
254
|
-
frozenLockfile: values["frozen-lockfile"],
|
|
255
|
-
loaded: target,
|
|
256
|
-
...(values.simulate && { configured: config }),
|
|
257
|
-
buildTarget: buildTargetFor(command),
|
|
258
|
-
});
|
|
259
|
-
if (hasErrors(emitted.diagnostics)) throw new DiagnosticFailure(emitted);
|
|
260
|
-
if (!emitted.controllerConfig)
|
|
261
|
-
throw new Error("Configure build settings for deployment.");
|
|
262
|
-
// Emission already resolves the generated entry/task paths. Passing
|
|
263
|
-
// this through the input schema again would reject its configFile.
|
|
264
|
-
settings = { ...emitted.controllerConfig, io: {} };
|
|
265
|
-
} else
|
|
266
|
-
settings = {
|
|
267
|
-
...resolveConfig(
|
|
268
|
-
{
|
|
269
|
-
...rawBuildConfig(config),
|
|
270
|
-
io: resolveIo(target.config, await loadHardware(target.config, root)),
|
|
271
|
-
},
|
|
272
|
-
configFile,
|
|
273
|
-
),
|
|
274
|
-
libraries: await installLibraries(config.dependencies, root, {
|
|
275
|
-
frozen: values["frozen-lockfile"],
|
|
276
|
-
}),
|
|
277
|
-
};
|
|
278
|
-
result = await updateController(
|
|
279
|
-
{ ...settings, controller: controllerFor(config, command) },
|
|
280
|
-
command as "download" | "online-change",
|
|
281
|
-
{
|
|
282
|
-
initializeUser: values["initialize-user"],
|
|
283
|
-
read: values.read,
|
|
284
|
-
},
|
|
285
|
-
);
|
|
286
|
-
} else throw new Error(`Unknown command ${command}.`);
|
|
287
|
-
}
|
|
288
|
-
} finally {
|
|
289
|
-
console.log = log;
|
|
290
|
-
if (previousLogTarget === undefined) delete process.env["TSPLC_LOG_STDERR"];
|
|
291
|
-
else process.env["TSPLC_LOG_STDERR"] = previousLogTarget;
|
|
292
|
-
}
|
|
293
|
-
return report(result, values.format);
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Serves the debugger for the project's last build until interrupted. It reads the controller
|
|
297
|
-
* through the plant agent's login, or with `--opcua` at the config's `monitor` endpoint, and
|
|
298
|
-
* follows the server's telemetry and requests when the server's base URL (`--server-url`, or
|
|
299
|
-
* `server.baseUrlEnv`) and the PLC's bearer token are in the environment.
|
|
300
|
-
*/
|
|
301
|
-
async function serveProjectDebugger(
|
|
302
|
-
{ config, root }: Awaited<ReturnType<typeof loadTsplcConfig>>,
|
|
303
|
-
flags: { port?: string; "server-url"?: string; opcua?: boolean },
|
|
304
|
-
) {
|
|
305
|
-
if (flags.opcua && !config.monitor)
|
|
306
|
-
throw new Error("Configure monitor with the controller's OPC UA endpoint to use --opcua.");
|
|
307
|
-
const agentUrl = process.env["TSPLC_AGENT_URL"];
|
|
308
|
-
if (!flags.opcua && !(agentUrl && process.env["TSPLC_AGENT_TOKEN"]))
|
|
309
|
-
throw new Error(
|
|
310
|
-
"Set TSPLC_AGENT_URL and TSPLC_AGENT_TOKEN to read through the plant agent's login, or pass --opcua for a local virtual PLC.",
|
|
311
|
-
);
|
|
312
|
-
const file = resolve(root, ".tsplc/artifacts/st/debug.json");
|
|
313
|
-
if (!existsSync(file))
|
|
314
|
-
throw new Error(
|
|
315
|
-
`No debug manifest at ${relative(process.cwd(), file)}: build with debug configured.`,
|
|
316
|
-
);
|
|
317
|
-
const port = Number(flags.port ?? 4870);
|
|
318
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
319
|
-
throw new Error("--port must be a TCP port.");
|
|
320
|
-
const manifest = await loadManifest(file);
|
|
321
|
-
const serverUrl =
|
|
322
|
-
flags["server-url"] ?? (config.server?.baseUrlEnv && process.env[config.server.baseUrlEnv]);
|
|
323
|
-
const tokenEnv = serverTokenEnv(config);
|
|
324
|
-
const token = tokenEnv && process.env[tokenEnv];
|
|
325
|
-
const log = (message: string) => console.log(`${new Date().toISOString()} ${message}`);
|
|
326
|
-
const debug = await createDebugger({
|
|
327
|
-
manifest,
|
|
328
|
-
adapter:
|
|
329
|
-
flags.opcua && config.monitor
|
|
330
|
-
? createOpcUaAdapter(opcUaConnection(config.monitor, { root, env: process.env }))
|
|
331
|
-
: createLoginAdapter({
|
|
332
|
-
read: readThroughAgent(connect()),
|
|
333
|
-
probe: manifest.build.target,
|
|
334
|
-
endpoint: `the plant agent at ${agentUrl}`,
|
|
335
|
-
}),
|
|
336
|
-
stateDirectory: resolve(root, ".tsplc/debug"),
|
|
337
|
-
watch: config.debug?.watch ?? {},
|
|
338
|
-
...(serverUrl && token && { server: { url: serverUrl, token } }),
|
|
339
|
-
projectRoot: root,
|
|
340
|
-
log,
|
|
341
|
-
});
|
|
342
|
-
const server = serveDebugger(debug, { port, log });
|
|
343
|
-
console.log(`tsPLC debugger at ${server.url}`);
|
|
344
|
-
if (!serverUrl || !token)
|
|
345
|
-
console.log(
|
|
346
|
-
"Not following the server's telemetry and requests: set server.baseUrlEnv or --server-url, and the server's bearer token variable.",
|
|
347
|
-
);
|
|
348
|
-
await new Promise((stopped) => {
|
|
349
|
-
process.once("SIGINT", stopped);
|
|
350
|
-
process.once("SIGTERM", stopped);
|
|
351
|
-
});
|
|
352
|
-
await server.stop(true);
|
|
353
|
-
await debug.close();
|
|
354
|
-
}
|
|
355
|
-
class DiagnosticFailure extends Error {
|
|
356
|
-
constructor(readonly result: unknown) {
|
|
357
|
-
super("PLC validation failed.");
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
function report(result: unknown, format?: string) {
|
|
361
|
-
const diagnostics =
|
|
362
|
-
result && typeof result === "object" && "diagnostics" in result
|
|
363
|
-
? (result.diagnostics as Diagnostic[])
|
|
364
|
-
: [];
|
|
365
|
-
const ok = !hasErrors(diagnostics);
|
|
366
|
-
if (format === "json")
|
|
367
|
-
console.log(
|
|
368
|
-
JSON.stringify({ ok, ...(result && typeof result === "object" ? result : { result }) }),
|
|
369
|
-
);
|
|
370
|
-
else {
|
|
371
|
-
for (const diagnostic of diagnostics) console.error(formatDiagnostic(diagnostic));
|
|
372
|
-
if (ok) console.log("tsPLC completed.");
|
|
373
|
-
}
|
|
374
|
-
return ok ? 0 : 1;
|
|
375
|
-
}
|
|
376
|
-
try {
|
|
377
|
-
process.exitCode = await main();
|
|
378
|
-
} catch (cause) {
|
|
379
|
-
// main() may fail before its options parse, so detect JSON output from raw argv.
|
|
380
|
-
const json = process.argv.includes("json") || process.argv.includes("--format=json");
|
|
381
|
-
if (cause instanceof DiagnosticFailure) {
|
|
382
|
-
process.exitCode = report(cause.result, json ? "json" : undefined);
|
|
383
|
-
} else {
|
|
384
|
-
const message = cause instanceof Error ? cause.message : String(cause);
|
|
385
|
-
if (json)
|
|
386
|
-
console.log(
|
|
387
|
-
JSON.stringify({
|
|
388
|
-
ok: false,
|
|
389
|
-
diagnostics: [{ origin: "config", code: "PLC5003", severity: "error", message }],
|
|
390
|
-
}),
|
|
391
|
-
);
|
|
392
|
-
else console.error(message);
|
|
393
|
-
process.exitCode = 1;
|
|
394
|
-
}
|
|
395
|
-
}
|
package/project/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { checkProject, buildProject, cleanProject, projectTargets } from "./project.ts";
|