@tsplc/compiler 0.5.9 → 0.5.10
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 +353 -58
- package/dist/cli.js.map +9 -7
- package/dist/codesys.js +2 -2
- package/dist/codesys.js.map +1 -1
- package/package.json +9 -9
- package/src/project/cli.ts +14 -3
- package/src/project/deployments.ts +443 -0
- package/src/project/git.ts +35 -0
- package/src/project/plant.ts +68 -34
package/dist/cli.js
CHANGED
|
@@ -33,12 +33,304 @@ import {
|
|
|
33
33
|
ask as ask2,
|
|
34
34
|
askCredentials
|
|
35
35
|
} from "@tsplc/agent";
|
|
36
|
+
import { createAgentClient } from "@tsplc/agent/client";
|
|
37
|
+
import { LoginUnavailable, noLogin } from "@tsplc/debug";
|
|
38
|
+
import { z as z4 } from "zod";
|
|
39
|
+
|
|
40
|
+
// packages/compiler/src/project/deployments.ts
|
|
41
|
+
import { spawn } from "node:child_process";
|
|
36
42
|
import {
|
|
37
43
|
AgentOperationError,
|
|
38
|
-
|
|
44
|
+
AgentUnreachable
|
|
39
45
|
} from "@tsplc/agent/client";
|
|
40
|
-
import {
|
|
41
|
-
|
|
46
|
+
import { describeFinding } from "@tsplc/build";
|
|
47
|
+
|
|
48
|
+
// packages/compiler/src/project/terminal.ts
|
|
49
|
+
import { ask } from "@tsplc/agent";
|
|
50
|
+
var choose = async (question, items, label) => {
|
|
51
|
+
items.forEach((item, index) => {
|
|
52
|
+
console.log(` ${index + 1}. ${label(item)}`);
|
|
53
|
+
});
|
|
54
|
+
while (true) {
|
|
55
|
+
const item = items[Number(await ask(`${question} [1-${items.length}]: `)) - 1];
|
|
56
|
+
if (item !== undefined) {
|
|
57
|
+
return item;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var confirm = async (question, flags) => flags.yes || /^y(es)?$/i.test(await ask(`${question} [y/N]: `));
|
|
62
|
+
var progress = (message) => console.log(` ${message}`);
|
|
63
|
+
var timedProgress = () => {
|
|
64
|
+
const start = Date.now();
|
|
65
|
+
return (message) => {
|
|
66
|
+
const seconds = Math.round((Date.now() - start) / 1000);
|
|
67
|
+
progress(`${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")} ${message}`);
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// packages/compiler/src/project/deployments.ts
|
|
72
|
+
var awaitingApprovalExit = 2;
|
|
73
|
+
var reconnectAttempts = 5;
|
|
74
|
+
var reconnectDelay = 1000;
|
|
75
|
+
var stateMessage = (record) => {
|
|
76
|
+
switch (record.state) {
|
|
77
|
+
case "queued":
|
|
78
|
+
return "Queued.";
|
|
79
|
+
case "building":
|
|
80
|
+
return "Building the release…";
|
|
81
|
+
case "applying":
|
|
82
|
+
return record.operation === "download" ? "Downloading the program; the application stops while it loads…" : "Applying the online change…";
|
|
83
|
+
case "starting":
|
|
84
|
+
return "Starting the server…";
|
|
85
|
+
case "verifying":
|
|
86
|
+
return "Checking the deployment's health…";
|
|
87
|
+
default:
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var printFindings = (record) => {
|
|
92
|
+
if (!record.findings.length) {
|
|
93
|
+
progress("No findings.");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
for (const finding of record.findings) {
|
|
97
|
+
progress(`${finding.refuses ? "refuses" : "note"}: ${describeFinding(finding)}`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var decide = async (approval, question) => {
|
|
101
|
+
if (approval.yes) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if (!approval.interactive) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return approval.confirm(question);
|
|
108
|
+
};
|
|
109
|
+
var approve = async (agent, record, reason, { url, approval }) => {
|
|
110
|
+
const download = reason === "downloadRequired";
|
|
111
|
+
if (download) {
|
|
112
|
+
console.log("Only a full download can deploy this release, and a full download stops the running application while it loads.");
|
|
113
|
+
} else {
|
|
114
|
+
console.log("The review found what the online change would do:");
|
|
115
|
+
}
|
|
116
|
+
printFindings(record);
|
|
117
|
+
const approved = await decide(approval, download ? "Download now?" : "Apply it?");
|
|
118
|
+
if (!approved) {
|
|
119
|
+
console.log(approved === null ? `It waits for approval on the dashboard: ${url}` : `It waits for approval or cancellation on the dashboard: ${url}`);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
await agent.approve(record.id, { download });
|
|
123
|
+
console.log(download ? "Approved the full download." : "Approved.");
|
|
124
|
+
return true;
|
|
125
|
+
};
|
|
126
|
+
var followDeployment = async (agent, deployment, approval) => {
|
|
127
|
+
const seen = { after: 0, state: null, approval: null, failures: 0 };
|
|
128
|
+
const onRecord = async (record) => {
|
|
129
|
+
if (record.state !== seen.state) {
|
|
130
|
+
seen.state = record.state;
|
|
131
|
+
const message = stateMessage(record);
|
|
132
|
+
if (message) {
|
|
133
|
+
console.log(message);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (record.state !== "awaitingApproval" || !record.approval) {
|
|
137
|
+
seen.approval = null;
|
|
138
|
+
} else {
|
|
139
|
+
const asked = `${record.approval.reason}: ${record.approval.message}`;
|
|
140
|
+
if (asked !== seen.approval) {
|
|
141
|
+
seen.approval = asked;
|
|
142
|
+
console.log(record.approval.message);
|
|
143
|
+
const approved = await approve(agent, record, record.approval.reason, {
|
|
144
|
+
url: deployment.url,
|
|
145
|
+
approval
|
|
146
|
+
});
|
|
147
|
+
if (!approved) {
|
|
148
|
+
return awaitingApprovalExit;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (record.state === "ready") {
|
|
153
|
+
const { health } = record;
|
|
154
|
+
console.log(health ? `Ready: controller ${health.controller}, server ${health.server}, PLC ${health.plc}.${health.detail ? ` ${health.detail}` : ""}` : "Ready.");
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
if (record.state === "error") {
|
|
158
|
+
throw new Error(`The deployment failed: ${record.error?.message ?? "no reason given"}. ${deployment.url}`);
|
|
159
|
+
}
|
|
160
|
+
if (record.state === "canceled") {
|
|
161
|
+
throw new Error(`The deployment was canceled. ${deployment.url}`);
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
};
|
|
165
|
+
while (true) {
|
|
166
|
+
try {
|
|
167
|
+
for await (const event of agent.deploymentEvents(deployment.id, seen.after)) {
|
|
168
|
+
seen.failures = 0;
|
|
169
|
+
if (event.kind === "record") {
|
|
170
|
+
const exit = await onRecord(event.record);
|
|
171
|
+
if (exit !== undefined) {
|
|
172
|
+
return exit;
|
|
173
|
+
}
|
|
174
|
+
} else if (event.line.seq > seen.after) {
|
|
175
|
+
seen.after = event.line.seq;
|
|
176
|
+
progress(event.line.level === "info" ? event.line.message : `${event.line.level}: ${event.line.message}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (!(error instanceof AgentUnreachable)) {
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
seen.failures += 1;
|
|
185
|
+
if (seen.failures > reconnectAttempts) {
|
|
186
|
+
throw new Error(`Lost the connection to the plant agent; the deployment goes on: ${deployment.url}`);
|
|
187
|
+
}
|
|
188
|
+
await Bun.sleep(reconnectDelay);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var queued = async (agent, created, follow) => {
|
|
192
|
+
console.log(`Deployment ${created.id} queued: ${created.url}`);
|
|
193
|
+
if (!follow.wait) {
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
return followDeployment(agent, created, follow.approval);
|
|
197
|
+
};
|
|
198
|
+
var submitDeployment = async (agent, release, settings, request, follow) => {
|
|
199
|
+
const uploading = timedProgress();
|
|
200
|
+
const created = await agent.queueDeployment(release, { ...settings, deployment: request }, uploading);
|
|
201
|
+
if (created) {
|
|
202
|
+
uploading("Uploaded");
|
|
203
|
+
if (request.mode === "review" && !follow.wait) {
|
|
204
|
+
console.log("Once reviewed, it waits for approval on its page.");
|
|
205
|
+
}
|
|
206
|
+
return queued(agent, created, follow);
|
|
207
|
+
}
|
|
208
|
+
if (request.mode === "review") {
|
|
209
|
+
throw new Error("This plant agent can't review a deployment before applying it; deploy without --review.");
|
|
210
|
+
}
|
|
211
|
+
console.log("This plant agent can't queue deployments; deploying at once.");
|
|
212
|
+
const deployed = await deployAtOnce(agent, release, settings, follow.approval);
|
|
213
|
+
console.log(`Deployed release ${deployed.id} (${deployed.operation}).`);
|
|
214
|
+
return 0;
|
|
215
|
+
};
|
|
216
|
+
var deployAtOnce = async (agent, release, settings, approval) => {
|
|
217
|
+
const deploying = timedProgress();
|
|
218
|
+
try {
|
|
219
|
+
return await agent.deploy(release, settings, deploying);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
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?`))) {
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
return agent.deploy(release, { ...settings, download: true }, timedProgress());
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
var rollbackTarget = ({
|
|
228
|
+
deployments,
|
|
229
|
+
current,
|
|
230
|
+
lastGood
|
|
231
|
+
}) => {
|
|
232
|
+
const index = deployments.findIndex(({ id }) => id === current);
|
|
233
|
+
const running = deployments[index];
|
|
234
|
+
if (!running) {
|
|
235
|
+
return deployments.find(({ id }) => id === lastGood);
|
|
236
|
+
}
|
|
237
|
+
return deployments.slice(index + 1).find((deployment) => deployment.state === "ready" && deployment.activeFrom !== null && deployment.release !== running.release);
|
|
238
|
+
};
|
|
239
|
+
var age = (from, now) => {
|
|
240
|
+
const seconds = Math.max(0, Math.round((now - Date.parse(from)) / 1000));
|
|
241
|
+
if (seconds < 60) {
|
|
242
|
+
return `${seconds}s`;
|
|
243
|
+
}
|
|
244
|
+
if (seconds < 3600) {
|
|
245
|
+
return `${Math.floor(seconds / 60)}m`;
|
|
246
|
+
}
|
|
247
|
+
if (seconds < 48 * 3600) {
|
|
248
|
+
return `${Math.floor(seconds / 3600)}h`;
|
|
249
|
+
}
|
|
250
|
+
return `${Math.floor(seconds / 86400)}d`;
|
|
251
|
+
};
|
|
252
|
+
var commitLabel = (git) => git ? `${git.commit.slice(0, 7)}${git.dirty ? "*" : ""}` : "-";
|
|
253
|
+
var requester = ({ requestedBy }) => requestedBy.user && requestedBy.host ? `${requestedBy.user}@${requestedBy.host}` : requestedBy.user ?? requestedBy.identity.name;
|
|
254
|
+
var printDeployments = async (agent, flags) => {
|
|
255
|
+
const list = await agent.deployments();
|
|
256
|
+
if (flags.format === "json") {
|
|
257
|
+
console.log(JSON.stringify({ ok: true, ...list }));
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (!list.deployments.length) {
|
|
261
|
+
console.log("No deployments yet.");
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const now = Date.now();
|
|
265
|
+
const rows = [
|
|
266
|
+
["ID", "STATE", "AGE", "RELEASE", "COMMIT", "BY", ""],
|
|
267
|
+
...list.deployments.map((deployment) => [
|
|
268
|
+
deployment.id,
|
|
269
|
+
deployment.state,
|
|
270
|
+
age(deployment.createdAt, now),
|
|
271
|
+
deployment.release,
|
|
272
|
+
commitLabel(deployment.git),
|
|
273
|
+
requester(deployment),
|
|
274
|
+
[
|
|
275
|
+
deployment.id === list.current ? "current" : "",
|
|
276
|
+
deployment.id === list.lastGood ? "last good" : ""
|
|
277
|
+
].filter(Boolean).join(", ")
|
|
278
|
+
])
|
|
279
|
+
];
|
|
280
|
+
const widths = rows[0]?.map((_, column) => Math.max(...rows.map((row) => row[column]?.length ?? 0)));
|
|
281
|
+
for (const row of rows) {
|
|
282
|
+
console.log(row.map((cell, column) => cell.padEnd(widths?.[column] ?? 0)).join(" ").trimEnd());
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
var rollBack = async (agent, id, follow) => {
|
|
286
|
+
const target = id ?? rollbackTarget(await agent.deployments())?.id;
|
|
287
|
+
if (!target) {
|
|
288
|
+
throw new Error("No earlier healthy deployment to roll back to; name one: tsplc rollback <id>");
|
|
289
|
+
}
|
|
290
|
+
console.log(`Rolling back to ${target}…`);
|
|
291
|
+
return queued(agent, await agent.rollback(target), follow);
|
|
292
|
+
};
|
|
293
|
+
var redeploy = async (agent, id, mode, follow) => queued(agent, await agent.redeploy(id, mode), follow);
|
|
294
|
+
var openers = {
|
|
295
|
+
darwin: ["open"],
|
|
296
|
+
win32: ["cmd", "/c", "start", ""]
|
|
297
|
+
};
|
|
298
|
+
var openDashboard = (agent, interactive) => {
|
|
299
|
+
const url = new URL("/", agent.url).href;
|
|
300
|
+
console.log(url);
|
|
301
|
+
if (!interactive) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const [command = "xdg-open", ...args] = openers[process.platform] ?? [
|
|
305
|
+
"xdg-open"
|
|
306
|
+
];
|
|
307
|
+
spawn(command, [...args, url], { stdio: "ignore", detached: true }).on("error", () => {}).unref();
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// packages/compiler/src/project/git.ts
|
|
311
|
+
import { execFile } from "node:child_process";
|
|
312
|
+
var git = (directory, args) => new Promise((resolve) => {
|
|
313
|
+
execFile("git", args, { cwd: directory }, (error, stdout) => {
|
|
314
|
+
resolve(error ? null : stdout.trim());
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
var gitSource = async (directory) => {
|
|
318
|
+
const commit = await git(directory, ["rev-parse", "--verify", "HEAD"]);
|
|
319
|
+
if (!commit) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
const [branch, status, message] = await Promise.all([
|
|
323
|
+
git(directory, ["symbolic-ref", "--quiet", "--short", "HEAD"]),
|
|
324
|
+
git(directory, ["status", "--porcelain"]),
|
|
325
|
+
git(directory, ["log", "-1", "--format=%s"])
|
|
326
|
+
]);
|
|
327
|
+
return {
|
|
328
|
+
commit,
|
|
329
|
+
branch: branch || null,
|
|
330
|
+
dirty: status !== "",
|
|
331
|
+
message: message || null
|
|
332
|
+
};
|
|
333
|
+
};
|
|
42
334
|
|
|
43
335
|
// packages/compiler/src/project/release.ts
|
|
44
336
|
import { existsSync as existsSync2 } from "node:fs";
|
|
@@ -886,29 +1178,6 @@ var prepareRelease = async (file, loaded, flags, environment) => {
|
|
|
886
1178
|
return { release: { manifest, files } };
|
|
887
1179
|
};
|
|
888
1180
|
|
|
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
1181
|
// packages/compiler/src/project/plant.ts
|
|
913
1182
|
var connect = (env) => {
|
|
914
1183
|
const environment = z4.object({
|
|
@@ -1007,14 +1276,15 @@ import {
|
|
|
1007
1276
|
ask as ask3,
|
|
1008
1277
|
askCredentials as askCredentials2
|
|
1009
1278
|
} from "@tsplc/agent";
|
|
1010
|
-
import {
|
|
1011
|
-
AgentOperationError as AgentOperationError2,
|
|
1012
|
-
createAgentClient as createAgentClient2
|
|
1013
|
-
} from "@tsplc/agent/client";
|
|
1279
|
+
import { createAgentClient as createAgentClient2 } from "@tsplc/agent/client";
|
|
1014
1280
|
import { LoginUnavailable as LoginUnavailable2, noLogin as noLogin2 } from "@tsplc/debug";
|
|
1015
1281
|
import { z as z5 } from "zod";
|
|
1016
1282
|
var plantCommands = [
|
|
1017
1283
|
"deploy",
|
|
1284
|
+
"deployments",
|
|
1285
|
+
"rollback",
|
|
1286
|
+
"redeploy",
|
|
1287
|
+
"dashboard",
|
|
1018
1288
|
"target",
|
|
1019
1289
|
"status",
|
|
1020
1290
|
"login",
|
|
@@ -1067,7 +1337,7 @@ var controllerCredentials = async (environment, agent, prompt) => {
|
|
|
1067
1337
|
}
|
|
1068
1338
|
return agent.stored && !agent.initializeUser ? null : prompt();
|
|
1069
1339
|
};
|
|
1070
|
-
var deploy = async (agent, file, loaded, flags, environment) => {
|
|
1340
|
+
var deploy = async (agent, file, loaded, flags, environment, follow) => {
|
|
1071
1341
|
const status = await agent.status();
|
|
1072
1342
|
if (status.login) {
|
|
1073
1343
|
throw new Error("A login is open; log out before deploying: tsplc logout");
|
|
@@ -1092,17 +1362,13 @@ var deploy = async (agent, file, loaded, flags, environment) => {
|
|
|
1092
1362
|
download: flags.download ?? false,
|
|
1093
1363
|
initializeUser: flags["initialize-user"] ?? false
|
|
1094
1364
|
};
|
|
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
|
-
}
|
|
1365
|
+
console.log(release.manifest.server ? "Uploading the server and the program…" : "Uploading the program…");
|
|
1366
|
+
return {
|
|
1367
|
+
exitCode: await submitDeployment(agent, release, settings, {
|
|
1368
|
+
mode: flags.review ? "review" : "apply",
|
|
1369
|
+
git: await gitSource(loaded.root)
|
|
1370
|
+
}, follow)
|
|
1371
|
+
};
|
|
1106
1372
|
};
|
|
1107
1373
|
var ensureLogin = async (agent, environment) => {
|
|
1108
1374
|
const { login, credentialsStored } = await agent.status();
|
|
@@ -1183,6 +1449,12 @@ var printLogin = (result) => {
|
|
|
1183
1449
|
}
|
|
1184
1450
|
};
|
|
1185
1451
|
var runPlantCommand = async (agent, command, args, flags, project) => {
|
|
1452
|
+
const approval = {
|
|
1453
|
+
yes: flags.yes ?? false,
|
|
1454
|
+
interactive: project.interactive,
|
|
1455
|
+
confirm: (question) => confirm(question, {})
|
|
1456
|
+
};
|
|
1457
|
+
const follow = { wait: flags.wait ?? false, approval };
|
|
1186
1458
|
const expect = (count, usage) => {
|
|
1187
1459
|
if (args.length !== count) {
|
|
1188
1460
|
throw new Error(`Usage: tsplc ${command} ${usage}`);
|
|
@@ -1193,15 +1465,29 @@ var runPlantCommand = async (agent, command, args, flags, project) => {
|
|
|
1193
1465
|
printLogin(await agent.command(loginCommand));
|
|
1194
1466
|
};
|
|
1195
1467
|
switch (command) {
|
|
1196
|
-
case "deploy":
|
|
1197
|
-
expect(0, "[--target name] [--download] [--select] [--initialize-user] [--simulate]");
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1468
|
+
case "deploy":
|
|
1469
|
+
expect(0, "[--target name] [--download] [--select] [--initialize-user] [--simulate] [--review] [--wait] [-y]");
|
|
1470
|
+
return deploy(agent, project.file, await project.load(), flags, project.environment, follow);
|
|
1471
|
+
case "deployments":
|
|
1472
|
+
expect(0, "[--format json]");
|
|
1473
|
+
return printDeployments(agent, flags);
|
|
1474
|
+
case "rollback":
|
|
1475
|
+
if (args.length > 1) {
|
|
1476
|
+
throw new Error("Usage: tsplc rollback [id] [--wait] [-y]");
|
|
1201
1477
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1478
|
+
return { exitCode: await rollBack(agent, args[0], follow) };
|
|
1479
|
+
case "redeploy": {
|
|
1480
|
+
const [id, ...extra] = args;
|
|
1481
|
+
if (!id || extra.length) {
|
|
1482
|
+
throw new Error("Usage: tsplc redeploy <id> [--review] [--wait] [-y]");
|
|
1483
|
+
}
|
|
1484
|
+
return {
|
|
1485
|
+
exitCode: await redeploy(agent, id, flags.review ? "review" : "apply", follow)
|
|
1486
|
+
};
|
|
1204
1487
|
}
|
|
1488
|
+
case "dashboard":
|
|
1489
|
+
expect(0, "");
|
|
1490
|
+
return openDashboard(agent, project.interactive);
|
|
1205
1491
|
case "target": {
|
|
1206
1492
|
expect(0, "");
|
|
1207
1493
|
const target = await selectTarget(agent);
|
|
@@ -1301,7 +1587,7 @@ import { resolveConfig } from "@tsplc/config/build";
|
|
|
1301
1587
|
import { generateProject as generateProject2 } from "@tsplc/typegen";
|
|
1302
1588
|
|
|
1303
1589
|
// packages/compiler/src/runtime/process.ts
|
|
1304
|
-
import { spawn, spawnSync } from "node:child_process";
|
|
1590
|
+
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
1305
1591
|
import { existsSync as existsSync4, openSync } from "node:fs";
|
|
1306
1592
|
import { mkdir as mkdir4, readFile as readFile2, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
1307
1593
|
import { join as join4, relative as relative3 } from "node:path";
|
|
@@ -1381,7 +1667,7 @@ var runInBun = async (options) => {
|
|
|
1381
1667
|
const command = [runtimeScript(), launchFile];
|
|
1382
1668
|
if (options.foreground) {
|
|
1383
1669
|
log("Running the program in Bun; stop it with Ctrl-C");
|
|
1384
|
-
const child =
|
|
1670
|
+
const child = spawn2(process.execPath, command, {
|
|
1385
1671
|
cwd: options.root,
|
|
1386
1672
|
env: options.environment,
|
|
1387
1673
|
stdio: "inherit"
|
|
@@ -1401,7 +1687,7 @@ var runInBun = async (options) => {
|
|
|
1401
1687
|
return { stopped: true };
|
|
1402
1688
|
}
|
|
1403
1689
|
const output = openSync(logFile, "w");
|
|
1404
|
-
const child =
|
|
1690
|
+
const child = spawn2(process.execPath, command, {
|
|
1405
1691
|
cwd: options.root,
|
|
1406
1692
|
env: options.environment,
|
|
1407
1693
|
detached: true,
|
|
@@ -1681,7 +1967,10 @@ Run the TypeScript program in Bun instead of CODESYS, with OPC UA on opc.tcp://1
|
|
|
1681
1967
|
tsplc run --simulate --bun [--foreground] [--target name]
|
|
1682
1968
|
|
|
1683
1969
|
Plant agent (the target's agent, else TSPLC_AGENT_URL; TSPLC_AGENT_TOKEN):
|
|
1684
|
-
tsplc deploy [--target name] [--download] [--select] [--initialize-user] [--simulate]
|
|
1970
|
+
tsplc deploy [--target name] [--download] [--select] [--initialize-user] [--simulate] [--review] [--wait]
|
|
1971
|
+
tsplc deployments [--format json] | dashboard
|
|
1972
|
+
tsplc rollback [id] [--wait] | redeploy <id> [--review] [--wait]
|
|
1973
|
+
(--wait follows the deployment and exits 2 while it waits for approval; -y approves)
|
|
1685
1974
|
tsplc target | status | login | logout
|
|
1686
1975
|
tsplc vars [path] | read <expression>... | write <expression> <value>
|
|
1687
1976
|
tsplc force <expression> <value> | unforce [expression]... [--restore]
|
|
@@ -1731,7 +2020,9 @@ async function main() {
|
|
|
1731
2020
|
yes: { type: "boolean", short: "y" },
|
|
1732
2021
|
port: { type: "string" },
|
|
1733
2022
|
"server-url": { type: "string" },
|
|
1734
|
-
opcua: { type: "boolean" }
|
|
2023
|
+
opcua: { type: "boolean" },
|
|
2024
|
+
review: { type: "boolean" },
|
|
2025
|
+
wait: { type: "boolean" }
|
|
1735
2026
|
}
|
|
1736
2027
|
});
|
|
1737
2028
|
const values = {
|
|
@@ -1764,12 +2055,16 @@ async function main() {
|
|
|
1764
2055
|
});
|
|
1765
2056
|
const loaded = existsSync5(file) ? await load() : undefined;
|
|
1766
2057
|
const env = loaded?.env ?? process.env;
|
|
1767
|
-
const
|
|
2058
|
+
const outcome = await runPlantCommand(connect2(env), plant, args, values, {
|
|
1768
2059
|
file,
|
|
1769
2060
|
load: loaded ? async () => loaded : load,
|
|
1770
|
-
environment: env
|
|
2061
|
+
environment: env,
|
|
2062
|
+
interactive: process.stdin.isTTY === true
|
|
1771
2063
|
});
|
|
1772
|
-
|
|
2064
|
+
if (!outcome) {
|
|
2065
|
+
return 0;
|
|
2066
|
+
}
|
|
2067
|
+
return "exitCode" in outcome ? outcome.exitCode : report(outcome, values.format);
|
|
1773
2068
|
}
|
|
1774
2069
|
if (args.length) {
|
|
1775
2070
|
throw new Error("Specify one command.");
|
|
@@ -1818,5 +2113,5 @@ try {
|
|
|
1818
2113
|
}
|
|
1819
2114
|
}
|
|
1820
2115
|
|
|
1821
|
-
//# debugId=
|
|
2116
|
+
//# debugId=C96CB304F4B8A8BD64756E2164756E21
|
|
1822
2117
|
//# sourceMappingURL=cli.js.map
|