@tsplc/compiler 0.5.9 → 0.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +396 -66
- package/dist/cli.js.map +10 -8
- package/dist/codesys.js +2 -2
- package/dist/codesys.js.map +1 -1
- package/package.json +9 -9
- package/src/project/cli.ts +15 -3
- package/src/project/deployments.ts +443 -0
- package/src/project/git.ts +35 -0
- package/src/project/plant.ts +119 -36
- package/src/project/release.ts +15 -6
- package/src/runtime/.runtime-65O4JH/server/router.ts +17 -0
- package/src/runtime/.runtime-65O4JH/src/cell.ts +45 -0
- package/src/runtime/.runtime-65O4JH/src/controller.ts +58 -0
- package/src/runtime/.runtime-65O4JH/src/lane.ts +6 -0
- package/src/runtime/.runtime-65O4JH/src/main.ts +11 -0
- package/src/runtime/.runtime-65O4JH/src/services.ts +8 -0
- package/src/runtime/.runtime-65O4JH/tsconfig.json +13 -0
- package/src/runtime/.runtime-65O4JH/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-Brw2kO/server/router.ts +17 -0
- package/src/runtime/.runtime-Brw2kO/src/cell.ts +45 -0
- package/src/runtime/.runtime-Brw2kO/src/controller.ts +58 -0
- package/src/runtime/.runtime-Brw2kO/src/lane.ts +6 -0
- package/src/runtime/.runtime-Brw2kO/src/main.ts +11 -0
- package/src/runtime/.runtime-Brw2kO/src/services.ts +8 -0
- package/src/runtime/.runtime-Brw2kO/tsconfig.json +13 -0
- package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-NHfu1D/server/router.ts +17 -0
- package/src/runtime/.runtime-NHfu1D/src/cell.ts +45 -0
- package/src/runtime/.runtime-NHfu1D/src/controller.ts +58 -0
- package/src/runtime/.runtime-NHfu1D/src/lane.ts +6 -0
- package/src/runtime/.runtime-NHfu1D/src/main.ts +11 -0
- package/src/runtime/.runtime-NHfu1D/src/services.ts +8 -0
- package/src/runtime/.runtime-NHfu1D/tsconfig.json +13 -0
- package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-WbtNvR/server/router.ts +17 -0
- package/src/runtime/.runtime-WbtNvR/src/cell.ts +45 -0
- package/src/runtime/.runtime-WbtNvR/src/controller.ts +58 -0
- package/src/runtime/.runtime-WbtNvR/src/lane.ts +6 -0
- package/src/runtime/.runtime-WbtNvR/src/main.ts +11 -0
- package/src/runtime/.runtime-WbtNvR/src/services.ts +8 -0
- package/src/runtime/.runtime-WbtNvR/tsconfig.json +13 -0
- package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +17 -0
- package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +45 -0
- package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +58 -0
- package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +6 -0
- package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +11 -0
- package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +8 -0
- package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +13 -0
- package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +17 -0
- package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +45 -0
- package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +58 -0
- package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +6 -0
- package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +11 -0
- package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +8 -0
- package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +13 -0
- package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +17 -0
- package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +45 -0
- package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +58 -0
- package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +6 -0
- package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +11 -0
- package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +8 -0
- package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +13 -0
- package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +31 -0
- package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +17 -0
- package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +45 -0
- package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +58 -0
- package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +6 -0
- package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +11 -0
- package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +8 -0
- package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +13 -0
- package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +31 -0
package/dist/cli.js
CHANGED
|
@@ -33,13 +33,308 @@ import {
|
|
|
33
33
|
ask as ask2,
|
|
34
34
|
askCredentials
|
|
35
35
|
} from "@tsplc/agent";
|
|
36
|
+
import { createAgentClient } from "@tsplc/agent/client";
|
|
36
37
|
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} from "@tsplc/agent/client";
|
|
38
|
+
releaseEnvironment
|
|
39
|
+
} from "@tsplc/config";
|
|
40
40
|
import { LoginUnavailable, noLogin } from "@tsplc/debug";
|
|
41
41
|
import { z as z4 } from "zod";
|
|
42
42
|
|
|
43
|
+
// packages/compiler/src/project/deployments.ts
|
|
44
|
+
import { spawn } from "node:child_process";
|
|
45
|
+
import {
|
|
46
|
+
AgentOperationError,
|
|
47
|
+
AgentUnreachable
|
|
48
|
+
} from "@tsplc/agent/client";
|
|
49
|
+
import { describeFinding } from "@tsplc/build";
|
|
50
|
+
|
|
51
|
+
// packages/compiler/src/project/terminal.ts
|
|
52
|
+
import { ask } from "@tsplc/agent";
|
|
53
|
+
var choose = async (question, items, label) => {
|
|
54
|
+
items.forEach((item, index) => {
|
|
55
|
+
console.log(` ${index + 1}. ${label(item)}`);
|
|
56
|
+
});
|
|
57
|
+
while (true) {
|
|
58
|
+
const item = items[Number(await ask(`${question} [1-${items.length}]: `)) - 1];
|
|
59
|
+
if (item !== undefined) {
|
|
60
|
+
return item;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var confirm = async (question, flags) => flags.yes || /^y(es)?$/i.test(await ask(`${question} [y/N]: `));
|
|
65
|
+
var progress = (message) => console.log(` ${message}`);
|
|
66
|
+
var timedProgress = () => {
|
|
67
|
+
const start = Date.now();
|
|
68
|
+
return (message) => {
|
|
69
|
+
const seconds = Math.round((Date.now() - start) / 1000);
|
|
70
|
+
progress(`${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")} ${message}`);
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// packages/compiler/src/project/deployments.ts
|
|
75
|
+
var awaitingApprovalExit = 2;
|
|
76
|
+
var reconnectAttempts = 5;
|
|
77
|
+
var reconnectDelay = 1000;
|
|
78
|
+
var stateMessage = (record) => {
|
|
79
|
+
switch (record.state) {
|
|
80
|
+
case "queued":
|
|
81
|
+
return "Queued.";
|
|
82
|
+
case "building":
|
|
83
|
+
return "Building the release…";
|
|
84
|
+
case "applying":
|
|
85
|
+
return record.operation === "download" ? "Downloading the program; the application stops while it loads…" : "Applying the online change…";
|
|
86
|
+
case "starting":
|
|
87
|
+
return "Starting the server…";
|
|
88
|
+
case "verifying":
|
|
89
|
+
return "Checking the deployment's health…";
|
|
90
|
+
default:
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var printFindings = (record) => {
|
|
95
|
+
if (!record.findings.length) {
|
|
96
|
+
progress("No findings.");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
for (const finding of record.findings) {
|
|
100
|
+
progress(`${finding.refuses ? "refuses" : "note"}: ${describeFinding(finding)}`);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var decide = async (approval, question) => {
|
|
104
|
+
if (approval.yes) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
if (!approval.interactive) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
return approval.confirm(question);
|
|
111
|
+
};
|
|
112
|
+
var approve = async (agent, record, reason, { url, approval }) => {
|
|
113
|
+
const download = reason === "downloadRequired";
|
|
114
|
+
if (download) {
|
|
115
|
+
console.log("Only a full download can deploy this release, and a full download stops the running application while it loads.");
|
|
116
|
+
} else {
|
|
117
|
+
console.log("The review found what the online change would do:");
|
|
118
|
+
}
|
|
119
|
+
printFindings(record);
|
|
120
|
+
const approved = await decide(approval, download ? "Download now?" : "Apply it?");
|
|
121
|
+
if (!approved) {
|
|
122
|
+
console.log(approved === null ? `It waits for approval on the dashboard: ${url}` : `It waits for approval or cancellation on the dashboard: ${url}`);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
await agent.approve(record.id, { download });
|
|
126
|
+
console.log(download ? "Approved the full download." : "Approved.");
|
|
127
|
+
return true;
|
|
128
|
+
};
|
|
129
|
+
var followDeployment = async (agent, deployment, approval) => {
|
|
130
|
+
const seen = { after: 0, state: null, approval: null, failures: 0 };
|
|
131
|
+
const onRecord = async (record) => {
|
|
132
|
+
if (record.state !== seen.state) {
|
|
133
|
+
seen.state = record.state;
|
|
134
|
+
const message = stateMessage(record);
|
|
135
|
+
if (message) {
|
|
136
|
+
console.log(message);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (record.state !== "awaitingApproval" || !record.approval) {
|
|
140
|
+
seen.approval = null;
|
|
141
|
+
} else {
|
|
142
|
+
const asked = `${record.approval.reason}: ${record.approval.message}`;
|
|
143
|
+
if (asked !== seen.approval) {
|
|
144
|
+
seen.approval = asked;
|
|
145
|
+
console.log(record.approval.message);
|
|
146
|
+
const approved = await approve(agent, record, record.approval.reason, {
|
|
147
|
+
url: deployment.url,
|
|
148
|
+
approval
|
|
149
|
+
});
|
|
150
|
+
if (!approved) {
|
|
151
|
+
return awaitingApprovalExit;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (record.state === "ready") {
|
|
156
|
+
const { health } = record;
|
|
157
|
+
console.log(health ? `Ready: controller ${health.controller}, server ${health.server}, PLC ${health.plc}.${health.detail ? ` ${health.detail}` : ""}` : "Ready.");
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
if (record.state === "error") {
|
|
161
|
+
throw new Error(`The deployment failed: ${record.error?.message ?? "no reason given"}. ${deployment.url}`);
|
|
162
|
+
}
|
|
163
|
+
if (record.state === "canceled") {
|
|
164
|
+
throw new Error(`The deployment was canceled. ${deployment.url}`);
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
};
|
|
168
|
+
while (true) {
|
|
169
|
+
try {
|
|
170
|
+
for await (const event of agent.deploymentEvents(deployment.id, seen.after)) {
|
|
171
|
+
seen.failures = 0;
|
|
172
|
+
if (event.kind === "record") {
|
|
173
|
+
const exit = await onRecord(event.record);
|
|
174
|
+
if (exit !== undefined) {
|
|
175
|
+
return exit;
|
|
176
|
+
}
|
|
177
|
+
} else if (event.line.seq > seen.after) {
|
|
178
|
+
seen.after = event.line.seq;
|
|
179
|
+
progress(event.line.level === "info" ? event.line.message : `${event.line.level}: ${event.line.message}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (!(error instanceof AgentUnreachable)) {
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
seen.failures += 1;
|
|
188
|
+
if (seen.failures > reconnectAttempts) {
|
|
189
|
+
throw new Error(`Lost the connection to the plant agent; the deployment goes on: ${deployment.url}`);
|
|
190
|
+
}
|
|
191
|
+
await Bun.sleep(reconnectDelay);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var queued = async (agent, created, follow) => {
|
|
195
|
+
console.log(`Deployment ${created.id} queued: ${created.url}`);
|
|
196
|
+
if (!follow.wait) {
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
return followDeployment(agent, created, follow.approval);
|
|
200
|
+
};
|
|
201
|
+
var submitDeployment = async (agent, release, settings, request, follow) => {
|
|
202
|
+
const uploading = timedProgress();
|
|
203
|
+
const created = await agent.queueDeployment(release, { ...settings, deployment: request }, uploading);
|
|
204
|
+
if (created) {
|
|
205
|
+
uploading("Uploaded");
|
|
206
|
+
if (request.mode === "review" && !follow.wait) {
|
|
207
|
+
console.log("Once reviewed, it waits for approval on its page.");
|
|
208
|
+
}
|
|
209
|
+
return queued(agent, created, follow);
|
|
210
|
+
}
|
|
211
|
+
if (request.mode === "review") {
|
|
212
|
+
throw new Error("This plant agent can't review a deployment before applying it; deploy without --review.");
|
|
213
|
+
}
|
|
214
|
+
console.log("This plant agent can't queue deployments; deploying at once.");
|
|
215
|
+
const deployed = await deployAtOnce(agent, release, settings, follow.approval);
|
|
216
|
+
console.log(`Deployed release ${deployed.id} (${deployed.operation}).`);
|
|
217
|
+
return 0;
|
|
218
|
+
};
|
|
219
|
+
var deployAtOnce = async (agent, release, settings, approval) => {
|
|
220
|
+
const deploying = timedProgress();
|
|
221
|
+
try {
|
|
222
|
+
return await agent.deploy(release, settings, deploying);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (!(error instanceof AgentOperationError && error.downloadRequired) || !(approval.yes || await approval.confirm(`${error.message}. A full download stops the running application while it loads. Download now?`))) {
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
return agent.deploy(release, { ...settings, download: true }, timedProgress());
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var rollbackTarget = ({
|
|
231
|
+
deployments,
|
|
232
|
+
current,
|
|
233
|
+
lastGood
|
|
234
|
+
}) => {
|
|
235
|
+
const index = deployments.findIndex(({ id }) => id === current);
|
|
236
|
+
const running = deployments[index];
|
|
237
|
+
if (!running) {
|
|
238
|
+
return deployments.find(({ id }) => id === lastGood);
|
|
239
|
+
}
|
|
240
|
+
return deployments.slice(index + 1).find((deployment) => deployment.state === "ready" && deployment.activeFrom !== null && deployment.release !== running.release);
|
|
241
|
+
};
|
|
242
|
+
var age = (from, now) => {
|
|
243
|
+
const seconds = Math.max(0, Math.round((now - Date.parse(from)) / 1000));
|
|
244
|
+
if (seconds < 60) {
|
|
245
|
+
return `${seconds}s`;
|
|
246
|
+
}
|
|
247
|
+
if (seconds < 3600) {
|
|
248
|
+
return `${Math.floor(seconds / 60)}m`;
|
|
249
|
+
}
|
|
250
|
+
if (seconds < 48 * 3600) {
|
|
251
|
+
return `${Math.floor(seconds / 3600)}h`;
|
|
252
|
+
}
|
|
253
|
+
return `${Math.floor(seconds / 86400)}d`;
|
|
254
|
+
};
|
|
255
|
+
var commitLabel = (git) => git ? `${git.commit.slice(0, 7)}${git.dirty ? "*" : ""}` : "-";
|
|
256
|
+
var requester = ({ requestedBy }) => requestedBy.user && requestedBy.host ? `${requestedBy.user}@${requestedBy.host}` : requestedBy.user ?? requestedBy.identity.name;
|
|
257
|
+
var printDeployments = async (agent, flags) => {
|
|
258
|
+
const list = await agent.deployments();
|
|
259
|
+
if (flags.format === "json") {
|
|
260
|
+
console.log(JSON.stringify({ ok: true, ...list }));
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (!list.deployments.length) {
|
|
264
|
+
console.log("No deployments yet.");
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const now = Date.now();
|
|
268
|
+
const rows = [
|
|
269
|
+
["ID", "STATE", "AGE", "RELEASE", "COMMIT", "BY", ""],
|
|
270
|
+
...list.deployments.map((deployment) => [
|
|
271
|
+
deployment.id,
|
|
272
|
+
deployment.state,
|
|
273
|
+
age(deployment.createdAt, now),
|
|
274
|
+
deployment.release,
|
|
275
|
+
commitLabel(deployment.git),
|
|
276
|
+
requester(deployment),
|
|
277
|
+
[
|
|
278
|
+
deployment.id === list.current ? "current" : "",
|
|
279
|
+
deployment.id === list.lastGood ? "last good" : ""
|
|
280
|
+
].filter(Boolean).join(", ")
|
|
281
|
+
])
|
|
282
|
+
];
|
|
283
|
+
const widths = rows[0]?.map((_, column) => Math.max(...rows.map((row) => row[column]?.length ?? 0)));
|
|
284
|
+
for (const row of rows) {
|
|
285
|
+
console.log(row.map((cell, column) => cell.padEnd(widths?.[column] ?? 0)).join(" ").trimEnd());
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var rollBack = async (agent, id, follow) => {
|
|
289
|
+
const target = id ?? rollbackTarget(await agent.deployments())?.id;
|
|
290
|
+
if (!target) {
|
|
291
|
+
throw new Error("No earlier healthy deployment to roll back to; name one: tsplc rollback <id>");
|
|
292
|
+
}
|
|
293
|
+
console.log(`Rolling back to ${target}…`);
|
|
294
|
+
return queued(agent, await agent.rollback(target), follow);
|
|
295
|
+
};
|
|
296
|
+
var redeploy = async (agent, id, mode, follow) => queued(agent, await agent.redeploy(id, mode), follow);
|
|
297
|
+
var openers = {
|
|
298
|
+
darwin: ["open"],
|
|
299
|
+
win32: ["cmd", "/c", "start", ""]
|
|
300
|
+
};
|
|
301
|
+
var openDashboard = (agent, interactive) => {
|
|
302
|
+
const url = new URL("/", agent.url).href;
|
|
303
|
+
console.log(url);
|
|
304
|
+
if (!interactive) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const [command = "xdg-open", ...args] = openers[process.platform] ?? [
|
|
308
|
+
"xdg-open"
|
|
309
|
+
];
|
|
310
|
+
spawn(command, [...args, url], { stdio: "ignore", detached: true }).on("error", () => {}).unref();
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// packages/compiler/src/project/git.ts
|
|
314
|
+
import { execFile } from "node:child_process";
|
|
315
|
+
var git = (directory, args) => new Promise((resolve) => {
|
|
316
|
+
execFile("git", args, { cwd: directory }, (error, stdout) => {
|
|
317
|
+
resolve(error ? null : stdout.trim());
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
var gitSource = async (directory) => {
|
|
321
|
+
const commit = await git(directory, ["rev-parse", "--verify", "HEAD"]);
|
|
322
|
+
if (!commit) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
const [branch, status, message] = await Promise.all([
|
|
326
|
+
git(directory, ["symbolic-ref", "--quiet", "--short", "HEAD"]),
|
|
327
|
+
git(directory, ["status", "--porcelain"]),
|
|
328
|
+
git(directory, ["log", "-1", "--format=%s"])
|
|
329
|
+
]);
|
|
330
|
+
return {
|
|
331
|
+
commit,
|
|
332
|
+
branch: branch || null,
|
|
333
|
+
dirty: status !== "",
|
|
334
|
+
message: message || null
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
|
|
43
338
|
// packages/compiler/src/project/release.ts
|
|
44
339
|
import { existsSync as existsSync2 } from "node:fs";
|
|
45
340
|
import { basename as basename2, relative, resolve as resolve3, sep } from "node:path";
|
|
@@ -795,8 +1090,9 @@ var releaseVariables = async (config, root) => {
|
|
|
795
1090
|
const contract = plcContractSchema.parse(await import(pathToFileURL(resolve3(root, config.typegen.dir, generatedFiles.contract)).href));
|
|
796
1091
|
return contractVariables(contract).map(({ path, type }) => ({ path, type }));
|
|
797
1092
|
};
|
|
798
|
-
var prepareRelease = async (file, loaded, flags,
|
|
799
|
-
const {
|
|
1093
|
+
var prepareRelease = async (file, loaded, flags, built) => {
|
|
1094
|
+
const project = { ...loaded, env: built.env };
|
|
1095
|
+
const { config, root } = project;
|
|
800
1096
|
if (!config.compiler) {
|
|
801
1097
|
throw new Error("tsplc deploy deploys tsPLC programs; configure compiler.");
|
|
802
1098
|
}
|
|
@@ -809,10 +1105,9 @@ var prepareRelease = async (file, loaded, flags, environment) => {
|
|
|
809
1105
|
emitOnly: true,
|
|
810
1106
|
forController: true,
|
|
811
1107
|
frozenLockfile: flags["frozen-lockfile"],
|
|
812
|
-
...buildConfigs(
|
|
1108
|
+
...buildConfigs(project, flags),
|
|
813
1109
|
buildTarget: buildTargetFor(command),
|
|
814
|
-
controller: controllerFor(config, command)
|
|
815
|
-
environment
|
|
1110
|
+
controller: controllerFor(config, command)
|
|
816
1111
|
});
|
|
817
1112
|
if (hasErrors2(emitted.diagnostics)) {
|
|
818
1113
|
return { diagnostics: emitted.diagnostics };
|
|
@@ -821,7 +1116,7 @@ var prepareRelease = async (file, loaded, flags, environment) => {
|
|
|
821
1116
|
if (!settings) {
|
|
822
1117
|
throw new Error("Configure build settings for deployment.");
|
|
823
1118
|
}
|
|
824
|
-
await generateProject(file, { loaded, targets: emitted.targets });
|
|
1119
|
+
await generateProject(file, { loaded: project, targets: emitted.targets });
|
|
825
1120
|
const portable = (path) => path.split(sep).join("/");
|
|
826
1121
|
const libraries = (settings.libraries ?? []).map((library) => ({
|
|
827
1122
|
...library,
|
|
@@ -881,34 +1176,12 @@ var prepareRelease = async (file, loaded, flags, environment) => {
|
|
|
881
1176
|
server: server?.path,
|
|
882
1177
|
debug: config.debug,
|
|
883
1178
|
serverTokenEnv: serverTokenEnv(config),
|
|
884
|
-
secrets:
|
|
1179
|
+
secrets: built.secrets,
|
|
1180
|
+
values: built.values
|
|
885
1181
|
};
|
|
886
1182
|
return { release: { manifest, files } };
|
|
887
1183
|
};
|
|
888
1184
|
|
|
889
|
-
// packages/compiler/src/project/terminal.ts
|
|
890
|
-
import { ask } from "@tsplc/agent";
|
|
891
|
-
var choose = async (question, items, label) => {
|
|
892
|
-
items.forEach((item, index) => {
|
|
893
|
-
console.log(` ${index + 1}. ${label(item)}`);
|
|
894
|
-
});
|
|
895
|
-
while (true) {
|
|
896
|
-
const item = items[Number(await ask(`${question} [1-${items.length}]: `)) - 1];
|
|
897
|
-
if (item !== undefined) {
|
|
898
|
-
return item;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
var confirm = async (question, flags) => flags.yes || /^y(es)?$/i.test(await ask(`${question} [y/N]: `));
|
|
903
|
-
var progress = (message) => console.log(` ${message}`);
|
|
904
|
-
var timedProgress = () => {
|
|
905
|
-
const start = Date.now();
|
|
906
|
-
return (message) => {
|
|
907
|
-
const seconds = Math.round((Date.now() - start) / 1000);
|
|
908
|
-
progress(`${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")} ${message}`);
|
|
909
|
-
};
|
|
910
|
-
};
|
|
911
|
-
|
|
912
1185
|
// packages/compiler/src/project/plant.ts
|
|
913
1186
|
var connect = (env) => {
|
|
914
1187
|
const environment = z4.object({
|
|
@@ -1007,14 +1280,18 @@ import {
|
|
|
1007
1280
|
ask as ask3,
|
|
1008
1281
|
askCredentials as askCredentials2
|
|
1009
1282
|
} from "@tsplc/agent";
|
|
1283
|
+
import { createAgentClient as createAgentClient2 } from "@tsplc/agent/client";
|
|
1010
1284
|
import {
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
} from "@tsplc/agent/client";
|
|
1285
|
+
releaseEnvironment as releaseEnvironment2
|
|
1286
|
+
} from "@tsplc/config";
|
|
1014
1287
|
import { LoginUnavailable as LoginUnavailable2, noLogin as noLogin2 } from "@tsplc/debug";
|
|
1015
1288
|
import { z as z5 } from "zod";
|
|
1016
1289
|
var plantCommands = [
|
|
1017
1290
|
"deploy",
|
|
1291
|
+
"deployments",
|
|
1292
|
+
"rollback",
|
|
1293
|
+
"redeploy",
|
|
1294
|
+
"dashboard",
|
|
1018
1295
|
"target",
|
|
1019
1296
|
"status",
|
|
1020
1297
|
"login",
|
|
@@ -1026,7 +1303,8 @@ var plantCommands = [
|
|
|
1026
1303
|
"unforce",
|
|
1027
1304
|
"start",
|
|
1028
1305
|
"stop",
|
|
1029
|
-
"reset"
|
|
1306
|
+
"reset",
|
|
1307
|
+
"restart"
|
|
1030
1308
|
];
|
|
1031
1309
|
var plantCommand = (name) => plantCommands.find((command) => command === name);
|
|
1032
1310
|
var connect2 = (env) => {
|
|
@@ -1067,15 +1345,29 @@ var controllerCredentials = async (environment, agent, prompt) => {
|
|
|
1067
1345
|
}
|
|
1068
1346
|
return agent.stored && !agent.initializeUser ? null : prompt();
|
|
1069
1347
|
};
|
|
1070
|
-
var
|
|
1348
|
+
var plantSummary = ({ values, secrets }) => {
|
|
1349
|
+
const named = (noun, names) => names.length ? `${noun}${names.length === 1 ? "" : "s"} ${names.join(", ")}` : null;
|
|
1350
|
+
const parts = [
|
|
1351
|
+
named("variable", Object.keys(values)),
|
|
1352
|
+
named("secret", secrets)
|
|
1353
|
+
].filter((part) => part !== null);
|
|
1354
|
+
return parts.length ? parts.join(" and ") : null;
|
|
1355
|
+
};
|
|
1356
|
+
var deploy = async (agent, file, loaded, flags, environment, follow) => {
|
|
1071
1357
|
const status = await agent.status();
|
|
1072
1358
|
if (status.login) {
|
|
1073
1359
|
throw new Error("A login is open; log out before deploying: tsplc logout");
|
|
1074
1360
|
}
|
|
1075
1361
|
const target = !status.target || flags.select ? await selectTarget(agent) : status.target;
|
|
1362
|
+
const plant = await agent.releaseVariables(loaded.config.secrets?.service ?? null);
|
|
1363
|
+
const built = releaseEnvironment2(loaded.config, { env: environment, values: loaded.values }, plant);
|
|
1076
1364
|
console.log(`Building the release for ${target.host}…`);
|
|
1365
|
+
const held = plantSummary(plant);
|
|
1366
|
+
if (held) {
|
|
1367
|
+
console.log(` With the plant PC's ${held}`);
|
|
1368
|
+
}
|
|
1077
1369
|
const building = timedProgress();
|
|
1078
|
-
const { release, diagnostics } = await prepareRelease(file, loaded, flags,
|
|
1370
|
+
const { release, diagnostics } = await prepareRelease(file, loaded, flags, built);
|
|
1079
1371
|
if (!release) {
|
|
1080
1372
|
return { diagnostics };
|
|
1081
1373
|
}
|
|
@@ -1092,17 +1384,13 @@ var deploy = async (agent, file, loaded, flags, environment) => {
|
|
|
1092
1384
|
download: flags.download ?? false,
|
|
1093
1385
|
initializeUser: flags["initialize-user"] ?? false
|
|
1094
1386
|
};
|
|
1095
|
-
console.log(release.manifest.server ? "
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
throw error;
|
|
1103
|
-
}
|
|
1104
|
-
return agent.deploy(release, { ...settings, download: true }, timedProgress());
|
|
1105
|
-
}
|
|
1387
|
+
console.log(release.manifest.server ? "Uploading the server and the program…" : "Uploading the program…");
|
|
1388
|
+
return {
|
|
1389
|
+
exitCode: await submitDeployment(agent, release, settings, {
|
|
1390
|
+
mode: flags.review ? "review" : "apply",
|
|
1391
|
+
git: await gitSource(loaded.root)
|
|
1392
|
+
}, follow)
|
|
1393
|
+
};
|
|
1106
1394
|
};
|
|
1107
1395
|
var ensureLogin = async (agent, environment) => {
|
|
1108
1396
|
const { login, credentialsStored } = await agent.status();
|
|
@@ -1183,6 +1471,12 @@ var printLogin = (result) => {
|
|
|
1183
1471
|
}
|
|
1184
1472
|
};
|
|
1185
1473
|
var runPlantCommand = async (agent, command, args, flags, project) => {
|
|
1474
|
+
const approval = {
|
|
1475
|
+
yes: flags.yes ?? false,
|
|
1476
|
+
interactive: project.interactive,
|
|
1477
|
+
confirm: (question) => confirm(question, {})
|
|
1478
|
+
};
|
|
1479
|
+
const follow = { wait: flags.wait ?? false, approval };
|
|
1186
1480
|
const expect = (count, usage) => {
|
|
1187
1481
|
if (args.length !== count) {
|
|
1188
1482
|
throw new Error(`Usage: tsplc ${command} ${usage}`);
|
|
@@ -1193,15 +1487,29 @@ var runPlantCommand = async (agent, command, args, flags, project) => {
|
|
|
1193
1487
|
printLogin(await agent.command(loginCommand));
|
|
1194
1488
|
};
|
|
1195
1489
|
switch (command) {
|
|
1196
|
-
case "deploy":
|
|
1197
|
-
expect(0, "[--target name] [--download] [--select] [--initialize-user] [--simulate]");
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1490
|
+
case "deploy":
|
|
1491
|
+
expect(0, "[--target name] [--download] [--select] [--initialize-user] [--simulate] [--review] [--wait] [-y]");
|
|
1492
|
+
return deploy(agent, project.file, await project.load(), flags, project.environment, follow);
|
|
1493
|
+
case "deployments":
|
|
1494
|
+
expect(0, "[--format json]");
|
|
1495
|
+
return printDeployments(agent, flags);
|
|
1496
|
+
case "rollback":
|
|
1497
|
+
if (args.length > 1) {
|
|
1498
|
+
throw new Error("Usage: tsplc rollback [id] [--wait] [-y]");
|
|
1201
1499
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1500
|
+
return { exitCode: await rollBack(agent, args[0], follow) };
|
|
1501
|
+
case "redeploy": {
|
|
1502
|
+
const [id, ...extra] = args;
|
|
1503
|
+
if (!id || extra.length) {
|
|
1504
|
+
throw new Error("Usage: tsplc redeploy <id> [--review] [--wait] [-y]");
|
|
1505
|
+
}
|
|
1506
|
+
return {
|
|
1507
|
+
exitCode: await redeploy(agent, id, flags.review ? "review" : "apply", follow)
|
|
1508
|
+
};
|
|
1204
1509
|
}
|
|
1510
|
+
case "dashboard":
|
|
1511
|
+
expect(0, "");
|
|
1512
|
+
return openDashboard(agent, project.interactive);
|
|
1205
1513
|
case "target": {
|
|
1206
1514
|
expect(0, "");
|
|
1207
1515
|
const target = await selectTarget(agent);
|
|
@@ -1262,6 +1570,18 @@ var runPlantCommand = async (agent, command, args, flags, project) => {
|
|
|
1262
1570
|
throw new Error("Cancelled.");
|
|
1263
1571
|
}
|
|
1264
1572
|
return send({ command: "stop" });
|
|
1573
|
+
case "restart": {
|
|
1574
|
+
if (args.length > 1) {
|
|
1575
|
+
throw new Error("Usage: tsplc restart [warm|cold] [-y]");
|
|
1576
|
+
}
|
|
1577
|
+
const reset = z5.enum(["warm", "cold"]).parse(args[0] ?? "warm");
|
|
1578
|
+
if (!await confirm(`Reset the application (${reset}) and start it again? Its variables go back to their initial values${reset === "warm" ? ", but for retain ones" : ""}.`, flags)) {
|
|
1579
|
+
throw new Error("Cancelled.");
|
|
1580
|
+
}
|
|
1581
|
+
const { state } = await agent.restartController({ reset });
|
|
1582
|
+
console.log(`Reset ${reset}; the application is ${state === "run" ? "running" : state}.`);
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1265
1585
|
case "reset": {
|
|
1266
1586
|
expect(1, "warm|cold");
|
|
1267
1587
|
const kind = z5.enum(["warm", "cold"]).parse(args[0]);
|
|
@@ -1301,7 +1621,7 @@ import { resolveConfig } from "@tsplc/config/build";
|
|
|
1301
1621
|
import { generateProject as generateProject2 } from "@tsplc/typegen";
|
|
1302
1622
|
|
|
1303
1623
|
// packages/compiler/src/runtime/process.ts
|
|
1304
|
-
import { spawn, spawnSync } from "node:child_process";
|
|
1624
|
+
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
1305
1625
|
import { existsSync as existsSync4, openSync } from "node:fs";
|
|
1306
1626
|
import { mkdir as mkdir4, readFile as readFile2, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
1307
1627
|
import { join as join4, relative as relative3 } from "node:path";
|
|
@@ -1381,7 +1701,7 @@ var runInBun = async (options) => {
|
|
|
1381
1701
|
const command = [runtimeScript(), launchFile];
|
|
1382
1702
|
if (options.foreground) {
|
|
1383
1703
|
log("Running the program in Bun; stop it with Ctrl-C");
|
|
1384
|
-
const child =
|
|
1704
|
+
const child = spawn2(process.execPath, command, {
|
|
1385
1705
|
cwd: options.root,
|
|
1386
1706
|
env: options.environment,
|
|
1387
1707
|
stdio: "inherit"
|
|
@@ -1401,7 +1721,7 @@ var runInBun = async (options) => {
|
|
|
1401
1721
|
return { stopped: true };
|
|
1402
1722
|
}
|
|
1403
1723
|
const output = openSync(logFile, "w");
|
|
1404
|
-
const child =
|
|
1724
|
+
const child = spawn2(process.execPath, command, {
|
|
1405
1725
|
cwd: options.root,
|
|
1406
1726
|
env: options.environment,
|
|
1407
1727
|
detached: true,
|
|
@@ -1681,11 +2001,15 @@ Run the TypeScript program in Bun instead of CODESYS, with OPC UA on opc.tcp://1
|
|
|
1681
2001
|
tsplc run --simulate --bun [--foreground] [--target name]
|
|
1682
2002
|
|
|
1683
2003
|
Plant agent (the target's agent, else TSPLC_AGENT_URL; TSPLC_AGENT_TOKEN):
|
|
1684
|
-
tsplc deploy [--target name] [--download] [--select] [--initialize-user] [--simulate]
|
|
2004
|
+
tsplc deploy [--target name] [--download] [--select] [--initialize-user] [--simulate] [--review] [--wait]
|
|
2005
|
+
tsplc deployments [--format json] | dashboard
|
|
2006
|
+
tsplc rollback [id] [--wait] | redeploy <id> [--review] [--wait]
|
|
2007
|
+
(--wait follows the deployment and exits 2 while it waits for approval; -y approves)
|
|
1685
2008
|
tsplc target | status | login | logout
|
|
1686
2009
|
tsplc vars [path] | read <expression>... | write <expression> <value>
|
|
1687
2010
|
tsplc force <expression> <value> | unforce [expression]... [--restore]
|
|
1688
2011
|
tsplc start | stop | reset warm|cold (-y skips confirmations)
|
|
2012
|
+
tsplc restart [warm|cold] resets and starts the application, with or without a login
|
|
1689
2013
|
|
|
1690
2014
|
Debugger, on http://127.0.0.1, for the built .tsplc/artifacts/st/debug.json; it reads through
|
|
1691
2015
|
the plant agent's login (TSPLC_AGENT_URL, TSPLC_AGENT_TOKEN), or --opcua at config monitor:
|
|
@@ -1731,7 +2055,9 @@ async function main() {
|
|
|
1731
2055
|
yes: { type: "boolean", short: "y" },
|
|
1732
2056
|
port: { type: "string" },
|
|
1733
2057
|
"server-url": { type: "string" },
|
|
1734
|
-
opcua: { type: "boolean" }
|
|
2058
|
+
opcua: { type: "boolean" },
|
|
2059
|
+
review: { type: "boolean" },
|
|
2060
|
+
wait: { type: "boolean" }
|
|
1735
2061
|
}
|
|
1736
2062
|
});
|
|
1737
2063
|
const values = {
|
|
@@ -1764,12 +2090,16 @@ async function main() {
|
|
|
1764
2090
|
});
|
|
1765
2091
|
const loaded = existsSync5(file) ? await load() : undefined;
|
|
1766
2092
|
const env = loaded?.env ?? process.env;
|
|
1767
|
-
const
|
|
2093
|
+
const outcome = await runPlantCommand(connect2(env), plant, args, values, {
|
|
1768
2094
|
file,
|
|
1769
2095
|
load: loaded ? async () => loaded : load,
|
|
1770
|
-
environment: env
|
|
2096
|
+
environment: env,
|
|
2097
|
+
interactive: process.stdin.isTTY === true
|
|
1771
2098
|
});
|
|
1772
|
-
|
|
2099
|
+
if (!outcome) {
|
|
2100
|
+
return 0;
|
|
2101
|
+
}
|
|
2102
|
+
return "exitCode" in outcome ? outcome.exitCode : report(outcome, values.format);
|
|
1773
2103
|
}
|
|
1774
2104
|
if (args.length) {
|
|
1775
2105
|
throw new Error("Specify one command.");
|
|
@@ -1818,5 +2148,5 @@ try {
|
|
|
1818
2148
|
}
|
|
1819
2149
|
}
|
|
1820
2150
|
|
|
1821
|
-
//# debugId=
|
|
2151
|
+
//# debugId=4E4AFC84CE5CE5BF64756E2164756E21
|
|
1822
2152
|
//# sourceMappingURL=cli.js.map
|