@tsplc/compiler 0.2.21 → 0.4.0
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 +1 -1
- package/dist/cli.js +280 -223
- package/dist/cli.js.map +12 -12
- package/dist/codesys.js +452 -330
- package/dist/codesys.js.map +24 -24
- package/dist/elaborate-capture.js +112 -7
- package/dist/elaborate-capture.js.map +5 -4
- package/dist/index.js +5682 -5407
- package/dist/index.js.map +39 -37
- package/dist/ir.js +1154 -327
- package/dist/ir.js.map +23 -20
- package/dist/project.js +68 -29
- package/dist/project.js.map +4 -4
- package/dist/retain.js +8 -0
- package/dist/retain.js.map +10 -0
- package/dist/server-check.js +59 -0
- package/dist/server-check.js.map +11 -0
- package/dist/telemetry.js +19 -10
- package/dist/telemetry.js.map +3 -3
- package/package.json +33 -12
- package/src/codesys/config.ts +1 -1
- package/src/codesys/debug.ts +7 -21
- package/src/codesys/engineering.ts +8 -12
- package/src/codesys/global-lists.ts +19 -17
- package/src/codesys/global-names.ts +3 -3
- package/src/codesys/http.ts +37 -34
- package/src/codesys/index.ts +5 -22
- package/src/codesys/instrumentation.ts +3 -1
- package/src/codesys/io-paths.ts +2 -1
- package/src/codesys/manifest.ts +35 -18
- package/src/codesys/numeric.ts +2 -4
- package/src/codesys/plan.ts +94 -26
- package/src/codesys/publication.ts +4 -3
- package/src/codesys/routines.ts +2 -2
- package/src/codesys/sources.ts +1 -0
- package/src/codesys/st-files.ts +86 -50
- package/src/codesys/storage.ts +44 -9
- package/src/codesys/task-access.ts +32 -10
- package/src/codesys/telemetry.ts +93 -46
- package/src/codesys/types.ts +81 -3
- package/src/codesys/vendor.ts +1 -1
- package/src/frontend/analyzer.ts +15 -14
- package/src/frontend/async.ts +23 -21
- package/src/frontend/blocks.ts +7 -6
- package/src/frontend/configuration.ts +8 -6
- package/src/frontend/const-functions.ts +5 -5
- package/src/frontend/cooperative.ts +2 -1
- package/src/frontend/coroutines.ts +24 -21
- package/src/frontend/elaborate/calls.ts +12 -7
- package/src/frontend/elaborate/capture-protocol.ts +103 -0
- package/src/frontend/elaborate/capture.ts +48 -19
- package/src/frontend/elaborate/dialect.ts +2 -2
- package/src/frontend/elaborate/expressions.ts +9 -6
- package/src/frontend/elaborate/frame.ts +1 -1
- package/src/frontend/elaborate/graph.ts +27 -43
- package/src/frontend/elaborate/index.ts +52 -17
- package/src/frontend/elaborate/initializers.ts +3 -2
- package/src/frontend/elaborate/layouts.ts +2 -2
- package/src/frontend/elaborate/model.ts +34 -21
- package/src/frontend/elaborate/retention.ts +206 -0
- package/src/frontend/elaborate/specialize.ts +7 -6
- package/src/frontend/elaborate/statements.ts +47 -38
- package/src/frontend/elaborate/storage.ts +26 -6
- package/src/frontend/exposure.ts +6 -6
- package/src/frontend/expressions.ts +26 -25
- package/src/frontend/intrinsics.ts +3 -3
- package/src/frontend/module-graph.ts +1 -1
- package/src/frontend/positions.ts +2 -1
- package/src/frontend/promise-chains.ts +1 -0
- package/src/frontend/promises.ts +8 -7
- package/src/frontend/routines.ts +3 -2
- package/src/frontend/sdk.ts +2 -2
- package/src/frontend/services.ts +23 -20
- package/src/frontend/statements.ts +8 -6
- package/src/frontend/tasks.ts +11 -6
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +11 -9
- package/src/frontend/typescript.ts +92 -42
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +4 -3
- package/src/ir/allocation.ts +2 -1
- package/src/ir/core-model.ts +38 -8
- package/src/ir/declarations.ts +12 -12
- package/src/ir/domains.ts +8 -8
- package/src/ir/fold.ts +2 -2
- package/src/ir/index.ts +53 -40
- package/src/ir/job-errors.ts +22 -11
- package/src/ir/layouts.ts +3 -2
- package/src/ir/link.ts +6 -24
- package/src/ir/model.ts +3 -2
- package/src/ir/normalization-error.ts +1 -1
- package/src/ir/normalize.ts +19 -12
- package/src/ir/numeric.ts +1 -0
- package/src/{codesys → ir}/operands.ts +2 -6
- package/src/ir/ranges.ts +2 -2
- package/src/ir/routine.ts +35 -20
- package/src/ir/scalars.ts +3 -3
- package/src/ir/share.ts +862 -0
- package/src/ir/temporaries.ts +236 -0
- package/src/ir/types.ts +1 -1
- package/src/project/artifacts.ts +12 -2
- package/src/project/cli.ts +42 -44
- package/src/project/debugger.ts +15 -9
- package/src/project/index.ts +1 -1
- package/src/project/plant.ts +34 -23
- package/src/project/project-commands.ts +92 -73
- package/src/project/project.ts +91 -42
- package/src/project/release.ts +50 -57
- package/src/project/server-check.ts +54 -0
- package/src/project/server.ts +60 -41
- package/src/project/terminal.ts +3 -1
- package/stdlib/retain.ts +2 -0
- package/types/globals.d.ts +1 -0
- package/types/retain.d.ts +6 -0
- package/types/telemetry.d.ts +2 -2
package/dist/cli.js
CHANGED
|
@@ -4,13 +4,19 @@
|
|
|
4
4
|
// packages/compiler/src/project/cli.ts
|
|
5
5
|
import { existsSync as existsSync4 } from "fs";
|
|
6
6
|
import { parseArgs } from "util";
|
|
7
|
-
import { loadTsplcConfig as loadTsplcConfig3 } from "@tsplc/config";
|
|
8
7
|
import { formatDiagnostic, hasErrors as hasErrors4 } from "@tsplc/compiler/ir";
|
|
8
|
+
import { loadTsplcConfig as loadTsplcConfig3 } from "@tsplc/config";
|
|
9
|
+
import { z as z5 } from "zod";
|
|
9
10
|
|
|
10
11
|
// packages/compiler/src/project/debugger.ts
|
|
11
12
|
import { existsSync as existsSync3 } from "node:fs";
|
|
12
13
|
import { relative as relative2, resolve as resolve4 } from "node:path";
|
|
13
14
|
import { serverTokenEnv as serverTokenEnv2 } from "@tsplc/config";
|
|
15
|
+
import { tcpPort } from "@tsplc/config/build";
|
|
16
|
+
import {
|
|
17
|
+
emittedStDirectory as emittedStDirectory3,
|
|
18
|
+
generatedDirectory as generatedDirectory2
|
|
19
|
+
} from "@tsplc/config/project-files";
|
|
14
20
|
import {
|
|
15
21
|
createDebugger,
|
|
16
22
|
createLoginAdapter,
|
|
@@ -19,32 +25,33 @@ import {
|
|
|
19
25
|
opcUaConnection,
|
|
20
26
|
serveDebugger
|
|
21
27
|
} from "@tsplc/debug";
|
|
28
|
+
import { debugManifestFile as debugManifestFile3 } from "@tsplc/debug/manifest";
|
|
22
29
|
|
|
23
30
|
// packages/compiler/src/project/plant.ts
|
|
24
|
-
import {
|
|
25
|
-
AgentOperationError,
|
|
26
|
-
createAgentClient
|
|
27
|
-
} from "@tsplc/agent/client";
|
|
28
31
|
import {
|
|
29
32
|
ask as ask2,
|
|
30
33
|
askCredentials
|
|
31
34
|
} from "@tsplc/agent";
|
|
35
|
+
import {
|
|
36
|
+
AgentOperationError,
|
|
37
|
+
createAgentClient
|
|
38
|
+
} from "@tsplc/agent/client";
|
|
32
39
|
import { LoginUnavailable, noLogin } from "@tsplc/debug";
|
|
33
40
|
import { z as z3 } from "zod";
|
|
34
41
|
|
|
35
42
|
// packages/compiler/src/project/release.ts
|
|
36
43
|
import { existsSync as existsSync2 } from "node:fs";
|
|
37
|
-
import { basename, relative, resolve as resolve3, sep } from "node:path";
|
|
44
|
+
import { basename as basename2, relative, resolve as resolve3, sep } from "node:path";
|
|
38
45
|
import { pathToFileURL } from "node:url";
|
|
46
|
+
import { hasErrors as hasErrors2 } from "@tsplc/compiler/ir";
|
|
39
47
|
import {
|
|
40
48
|
buildTargetFor,
|
|
41
49
|
controllerFor,
|
|
42
50
|
serverTokenEnv
|
|
43
51
|
} from "@tsplc/config";
|
|
44
|
-
import {
|
|
45
|
-
import { contractVariables } from "@tsplc/opcua/contract";
|
|
46
|
-
import { generateProject } from "@tsplc/typegen";
|
|
47
|
-
import { z as z2 } from "zod";
|
|
52
|
+
import { debugManifestFile as debugManifestFile2 } from "@tsplc/debug/manifest";
|
|
53
|
+
import { contractVariables, plcContractSchema } from "@tsplc/opcua/contract";
|
|
54
|
+
import { generatedFiles, generateProject } from "@tsplc/typegen";
|
|
48
55
|
|
|
49
56
|
// packages/compiler/src/project/project.ts
|
|
50
57
|
import {
|
|
@@ -55,32 +62,37 @@ import {
|
|
|
55
62
|
rm as rm2,
|
|
56
63
|
writeFile as writeFile2
|
|
57
64
|
} from "node:fs/promises";
|
|
58
|
-
import { dirname as dirname2, join as join2, resolve } from "node:path";
|
|
65
|
+
import { basename, dirname as dirname2, join as join2, resolve } from "node:path";
|
|
66
|
+
import { installLibraries } from "@tsplc/build";
|
|
67
|
+
import {
|
|
68
|
+
analyze,
|
|
69
|
+
checkHostConfig
|
|
70
|
+
} from "@tsplc/compiler";
|
|
59
71
|
import {
|
|
60
72
|
buildCodesys,
|
|
61
73
|
codesysBuildConfig,
|
|
62
74
|
diagnoseCodesys,
|
|
63
75
|
emitCodesys,
|
|
64
76
|
ioTargets,
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
planCodesys,
|
|
78
|
+
publicationSelectors
|
|
67
79
|
} from "@tsplc/compiler/codesys";
|
|
68
|
-
import {
|
|
80
|
+
import {
|
|
81
|
+
hasErrors,
|
|
82
|
+
normalizeModule
|
|
83
|
+
} from "@tsplc/compiler/ir";
|
|
69
84
|
import {
|
|
70
85
|
compilerConfig,
|
|
71
86
|
loadTsplcConfig,
|
|
72
87
|
simulationConfig
|
|
73
88
|
} from "@tsplc/config";
|
|
89
|
+
import { emittedFiles, emittedStDirectory as emittedStDirectory2 } from "@tsplc/config/project-files";
|
|
90
|
+
import { debugManifestFile } from "@tsplc/debug/manifest";
|
|
74
91
|
import {
|
|
75
92
|
deviceTree,
|
|
76
93
|
loadHardware,
|
|
77
94
|
resolveIo
|
|
78
95
|
} from "@tsplc/typegen";
|
|
79
|
-
import { installLibraries } from "@tsplc/build";
|
|
80
|
-
import {
|
|
81
|
-
hasErrors,
|
|
82
|
-
normalizeModule
|
|
83
|
-
} from "@tsplc/compiler/ir";
|
|
84
96
|
|
|
85
97
|
// packages/compiler/src/project/artifacts.ts
|
|
86
98
|
import { createHash } from "node:crypto";
|
|
@@ -95,6 +107,10 @@ import {
|
|
|
95
107
|
} from "node:fs/promises";
|
|
96
108
|
import { dirname, join } from "node:path";
|
|
97
109
|
import { sha256Digest } from "@tsplc/config/build";
|
|
110
|
+
import {
|
|
111
|
+
emittedStDirectory,
|
|
112
|
+
generatedDirectory
|
|
113
|
+
} from "@tsplc/config/project-files";
|
|
98
114
|
import { z } from "zod";
|
|
99
115
|
var missing = (cause) => cause instanceof Error && ("code" in cause) && cause.code === "ENOENT";
|
|
100
116
|
var digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
@@ -199,8 +215,8 @@ async function engineeringDirectory(path, configFile) {
|
|
|
199
215
|
await inspect(path);
|
|
200
216
|
}
|
|
201
217
|
async function owned(configFile, withdrawReceipt = false) {
|
|
202
|
-
const root = join(dirname(configFile),
|
|
203
|
-
const output = join(
|
|
218
|
+
const root = join(dirname(configFile), generatedDirectory);
|
|
219
|
+
const output = join(dirname(configFile), dirname(emittedStDirectory));
|
|
204
220
|
if (!await directory(root) || !await directory(output)) {
|
|
205
221
|
return { root, output, unknown: [] };
|
|
206
222
|
}
|
|
@@ -233,13 +249,18 @@ async function owned(configFile, withdrawReceipt = false) {
|
|
|
233
249
|
"manifest.json",
|
|
234
250
|
"receipt.json"
|
|
235
251
|
]);
|
|
252
|
+
const checked = new Set;
|
|
236
253
|
for (const file of ownership.files) {
|
|
237
254
|
let parent = output;
|
|
238
255
|
for (const part of file.path.split("/").slice(0, -1)) {
|
|
239
256
|
parent = join(parent, part);
|
|
257
|
+
if (checked.has(parent)) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
240
260
|
if (!await directory(parent)) {
|
|
241
261
|
throw new Error(`Missing generated directory: ${parent}`);
|
|
242
262
|
}
|
|
263
|
+
checked.add(parent);
|
|
243
264
|
}
|
|
244
265
|
const path = join(output, file.path);
|
|
245
266
|
const entry = await lstat(path);
|
|
@@ -325,6 +346,7 @@ async function cleanArtifacts(configFile) {
|
|
|
325
346
|
}
|
|
326
347
|
|
|
327
348
|
// packages/compiler/src/project/project.ts
|
|
349
|
+
var emittedSt = basename(emittedStDirectory2);
|
|
328
350
|
var failure = (origin, code, cause) => ({
|
|
329
351
|
origin,
|
|
330
352
|
code,
|
|
@@ -335,7 +357,18 @@ var buildConfigs = (loaded, options) => options.simulate ? {
|
|
|
335
357
|
loaded: { ...loaded, config: simulationConfig(loaded.config) },
|
|
336
358
|
configured: loaded.config
|
|
337
359
|
} : { loaded };
|
|
338
|
-
|
|
360
|
+
var loadEnvironment = (environment) => ({
|
|
361
|
+
env: environment ?? process.env,
|
|
362
|
+
target: undefined,
|
|
363
|
+
forAgent: false
|
|
364
|
+
});
|
|
365
|
+
async function loadProject(file, {
|
|
366
|
+
loaded,
|
|
367
|
+
buildTarget,
|
|
368
|
+
configured,
|
|
369
|
+
hostConfigDiagnostics,
|
|
370
|
+
environment
|
|
371
|
+
}) {
|
|
339
372
|
let configFile = resolve(file);
|
|
340
373
|
try {
|
|
341
374
|
configFile = await realpath(configFile);
|
|
@@ -343,7 +376,7 @@ async function loadProject(file, { loaded, buildTarget, configured, hostConfigDi
|
|
|
343
376
|
if (hasErrors(diagnostics)) {
|
|
344
377
|
return { configFile, diagnostics };
|
|
345
378
|
}
|
|
346
|
-
const { config: shared, env } = loaded ?? await loadTsplcConfig(configFile);
|
|
379
|
+
const { config: shared, env } = loaded ?? await loadTsplcConfig(configFile, loadEnvironment(environment));
|
|
347
380
|
const root = dirname2(configFile);
|
|
348
381
|
const catalog = await loadHardware(shared, root);
|
|
349
382
|
const config = compilerConfig(shared, resolveIo(shared, catalog), buildTarget);
|
|
@@ -353,7 +386,7 @@ async function loadProject(file, { loaded, buildTarget, configured, hostConfigDi
|
|
|
353
386
|
config: { ...config, ...sourceInput(config, root) },
|
|
354
387
|
project: {
|
|
355
388
|
root,
|
|
356
|
-
env,
|
|
389
|
+
environment: env,
|
|
357
390
|
...shared.debug && { debug: shared.debug },
|
|
358
391
|
...shared.telemetry && { telemetry: shared.telemetry },
|
|
359
392
|
...shared.server && { server: shared.server },
|
|
@@ -380,18 +413,22 @@ function sourceInput(compiler, root) {
|
|
|
380
413
|
}
|
|
381
414
|
async function projectTargets(file = "tsplc.config.ts", options = {}) {
|
|
382
415
|
const configFile = await realpath(resolve(file));
|
|
383
|
-
const { config, env } = options.loaded ?? await loadTsplcConfig(configFile);
|
|
416
|
+
const { config, env } = options.loaded ?? await loadTsplcConfig(configFile, loadEnvironment(options.environment));
|
|
384
417
|
if (!config.compiler) {
|
|
385
418
|
return;
|
|
386
419
|
}
|
|
387
420
|
const source = analyze({
|
|
388
421
|
...sourceInput(config.compiler, dirname2(configFile)),
|
|
389
422
|
services: config.server,
|
|
390
|
-
env
|
|
423
|
+
environment: env
|
|
391
424
|
});
|
|
392
425
|
const core = source.module && normalizeModule(source.module).core;
|
|
393
|
-
return core ?
|
|
426
|
+
return core ? coreTargets(core) : undefined;
|
|
394
427
|
}
|
|
428
|
+
var coreTargets = (core) => ({
|
|
429
|
+
io: ioTargets(core),
|
|
430
|
+
publication: publicationSelectors(core)
|
|
431
|
+
});
|
|
395
432
|
async function checkProject(file = "tsplc.config.ts", options = {}) {
|
|
396
433
|
const loaded = await loadProject(file, options);
|
|
397
434
|
if (!loaded.config || !loaded.project) {
|
|
@@ -410,7 +447,7 @@ async function checkProject(file = "tsplc.config.ts", options = {}) {
|
|
|
410
447
|
tsconfig: config.tsconfig,
|
|
411
448
|
programs: config.programs,
|
|
412
449
|
services: loaded.shared?.server,
|
|
413
|
-
|
|
450
|
+
environment: loaded.project.environment
|
|
414
451
|
});
|
|
415
452
|
if (!source.module) {
|
|
416
453
|
return { ...loaded, diagnostics: source.diagnostics };
|
|
@@ -474,7 +511,7 @@ async function buildProject(file = "tsplc.config.ts", options = {}) {
|
|
|
474
511
|
const outDir = shared?.build && resolve(dirname2(configFile), shared.build.outDir);
|
|
475
512
|
const controllerConfig = outDir ? codesysBuildConfig(checked.plan, bundle, {
|
|
476
513
|
configFile,
|
|
477
|
-
sourceDir: join2(previous.output,
|
|
514
|
+
sourceDir: join2(previous.output, emittedSt),
|
|
478
515
|
outDir,
|
|
479
516
|
controller: options.controller,
|
|
480
517
|
...engineering
|
|
@@ -489,12 +526,12 @@ async function buildProject(file = "tsplc.config.ts", options = {}) {
|
|
|
489
526
|
`
|
|
490
527
|
},
|
|
491
528
|
{
|
|
492
|
-
path:
|
|
529
|
+
path: emittedFiles.ioSymbols,
|
|
493
530
|
content: `${JSON.stringify(bundle.ioSymbols, null, 2)}
|
|
494
531
|
`
|
|
495
532
|
},
|
|
496
533
|
{
|
|
497
|
-
path:
|
|
534
|
+
path: emittedFiles.publication,
|
|
498
535
|
content: `${JSON.stringify(bundle.publication, null, 2)}
|
|
499
536
|
`
|
|
500
537
|
},
|
|
@@ -503,13 +540,21 @@ async function buildProject(file = "tsplc.config.ts", options = {}) {
|
|
|
503
540
|
content: `${JSON.stringify(checked.config, null, 2)}
|
|
504
541
|
`
|
|
505
542
|
},
|
|
506
|
-
...bundle.debug ? [
|
|
507
|
-
|
|
543
|
+
...bundle.debug ? [
|
|
544
|
+
{
|
|
545
|
+
path: debugManifestFile,
|
|
546
|
+
content: `${JSON.stringify(bundle.debug)}
|
|
547
|
+
`
|
|
548
|
+
}
|
|
549
|
+
] : []
|
|
508
550
|
];
|
|
551
|
+
const stagedSt = join2(staging, emittedSt);
|
|
552
|
+
const directories = new Set(artifacts.map((artifact) => dirname2(join2(stagedSt, artifact.path))));
|
|
553
|
+
for (const directory of directories) {
|
|
554
|
+
await mkdir2(directory, { recursive: true });
|
|
555
|
+
}
|
|
509
556
|
for (const artifact of artifacts) {
|
|
510
|
-
|
|
511
|
-
await mkdir2(dirname2(path), { recursive: true });
|
|
512
|
-
await writeFile2(path, artifact.content);
|
|
557
|
+
await writeFile2(join2(stagedSt, artifact.path), artifact.content);
|
|
513
558
|
}
|
|
514
559
|
let vendor;
|
|
515
560
|
if (!options.emitOnly) {
|
|
@@ -518,11 +563,11 @@ async function buildProject(file = "tsplc.config.ts", options = {}) {
|
|
|
518
563
|
try {
|
|
519
564
|
vendor = await buildCodesys(checked.plan, bundle, {
|
|
520
565
|
configFile,
|
|
521
|
-
sourceDir: join2(staging,
|
|
566
|
+
sourceDir: join2(staging, emittedSt),
|
|
522
567
|
outDir: engineeringDir,
|
|
523
568
|
controller: options.controller,
|
|
524
569
|
...engineering
|
|
525
|
-
});
|
|
570
|
+
}, { progress: options.progress });
|
|
526
571
|
} catch (cause) {
|
|
527
572
|
return { diagnostics: diagnoseCodesys(cause, bundle) };
|
|
528
573
|
}
|
|
@@ -553,6 +598,7 @@ async function buildProject(file = "tsplc.config.ts", options = {}) {
|
|
|
553
598
|
directory: previous.output,
|
|
554
599
|
status,
|
|
555
600
|
...controllerConfig && { controllerConfig },
|
|
601
|
+
targets: coreTargets(checked.plan.core),
|
|
556
602
|
diagnostics: [...checked.diagnostics, ...bundle.diagnostics]
|
|
557
603
|
};
|
|
558
604
|
} catch (cause) {
|
|
@@ -600,51 +646,55 @@ async function cleanProject(file = "tsplc.config.ts") {
|
|
|
600
646
|
|
|
601
647
|
// packages/compiler/src/project/server.ts
|
|
602
648
|
import { existsSync } from "node:fs";
|
|
603
|
-
import {
|
|
604
|
-
import { dirname as dirname3, resolve as resolve2, join as join3 } from "node:path";
|
|
649
|
+
import { mkdir as mkdir3, mkdtemp as mkdtemp2, rename as rename2, rm as rm3 } from "node:fs/promises";
|
|
605
650
|
import { createRequire } from "node:module";
|
|
606
|
-
import
|
|
607
|
-
import {
|
|
651
|
+
import { dirname as dirname3, join as join3, resolve as resolve2 } from "node:path";
|
|
652
|
+
import { fileURLToPath } from "node:url";
|
|
653
|
+
import { z as z2 } from "zod";
|
|
608
654
|
var resolveServerModule = (root, name) => name.startsWith(".") || name.startsWith("/") || existsSync(resolve2(root, name)) ? resolve2(root, name) : createRequire(join3(root, "package.json")).resolve(name);
|
|
609
655
|
var kebabCase = (name) => name.replace(/([a-z0-9])([A-Z])|([A-Z])([A-Z][a-z])/g, "$1$3-$2$4").replace(/[^A-Za-z0-9]+/g, "-").replace(/^-|-$/g, "").toLowerCase();
|
|
610
656
|
var serverOutput = (config, root, extension) => resolve2(root, "build/server", `${kebabCase(config.name)}-services${extension}`);
|
|
611
|
-
var
|
|
657
|
+
var serverCheckRequestSchema = z2.strictObject({
|
|
658
|
+
entry: z2.string(),
|
|
659
|
+
root: z2.string()
|
|
660
|
+
});
|
|
661
|
+
var serverCheckResultSchema = z2.strictObject({
|
|
662
|
+
failure: z2.string().nullable()
|
|
663
|
+
});
|
|
664
|
+
var serverCheckScript = () => {
|
|
665
|
+
const script = ["./server-check.ts", "./server-check.js"].map((path) => fileURLToPath(new URL(path, import.meta.url))).find((path) => existsSync(path));
|
|
666
|
+
if (!script) {
|
|
667
|
+
throw new Error("The server type-check script is missing from this build.");
|
|
668
|
+
}
|
|
669
|
+
return script;
|
|
670
|
+
};
|
|
671
|
+
var checkServer = async (config, root) => {
|
|
612
672
|
const runtime = config.server?.runtime;
|
|
613
673
|
if (!runtime) {
|
|
614
674
|
throw new Error("Configure server.runtime to build the server.");
|
|
615
675
|
}
|
|
616
676
|
const entry = resolveServerModule(root, runtime.entry);
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
const diagnostics = [...parsed.errors, ...ts.getPreEmitDiagnostics(program)];
|
|
636
|
-
if (diagnostics.length) {
|
|
637
|
-
throw new Error(ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
638
|
-
getCanonicalFileName: (path) => path,
|
|
639
|
-
getCurrentDirectory: () => root,
|
|
640
|
-
getNewLine: () => `
|
|
641
|
-
`
|
|
642
|
-
}));
|
|
677
|
+
const worker = new Worker(serverCheckScript());
|
|
678
|
+
try {
|
|
679
|
+
const answer = await new Promise((resolve, reject) => {
|
|
680
|
+
worker.onmessage = (event) => resolve(event.data);
|
|
681
|
+
worker.onerror = (event) => reject(new Error(event.message));
|
|
682
|
+
const request = {
|
|
683
|
+
entry,
|
|
684
|
+
root
|
|
685
|
+
};
|
|
686
|
+
worker.postMessage(request);
|
|
687
|
+
});
|
|
688
|
+
const { failure } = serverCheckResultSchema.parse(answer);
|
|
689
|
+
if (failure !== null) {
|
|
690
|
+
throw new Error(failure);
|
|
691
|
+
}
|
|
692
|
+
return { entry, runtime };
|
|
693
|
+
} finally {
|
|
694
|
+
worker.terminate();
|
|
643
695
|
}
|
|
644
|
-
return { entry, runtime };
|
|
645
696
|
};
|
|
646
|
-
var bundleServer = async (config, root) => {
|
|
647
|
-
const { entry } = checkedServerEntry(config, root);
|
|
697
|
+
var bundleServer = async ({ entry }, config, root) => {
|
|
648
698
|
const outFile = serverOutput(config, root, ".js");
|
|
649
699
|
const result = await Bun.build({
|
|
650
700
|
entrypoints: [entry],
|
|
@@ -663,8 +713,7 @@ var bundleServer = async (config, root) => {
|
|
|
663
713
|
await Bun.write(outFile, script);
|
|
664
714
|
return outFile;
|
|
665
715
|
};
|
|
666
|
-
var buildServer = async (config, root) => {
|
|
667
|
-
const { entry, runtime } = checkedServerEntry(config, root);
|
|
716
|
+
var buildServer = async ({ entry, runtime }, config, root) => {
|
|
668
717
|
const windows = runtime.target ? runtime.target.includes("windows") : process.platform === "win32";
|
|
669
718
|
const outFile = serverOutput(config, root, windows ? ".exe" : "");
|
|
670
719
|
await mkdir3(dirname3(outFile), { recursive: true });
|
|
@@ -703,29 +752,27 @@ var releaseVariables = async (config, root) => {
|
|
|
703
752
|
if (!config.typegen) {
|
|
704
753
|
return [];
|
|
705
754
|
}
|
|
706
|
-
const contract =
|
|
707
|
-
symbols: z2.array(z2.object({ name: z2.string(), gvl: z2.string(), type: z2.string() })),
|
|
708
|
-
typeFields: z2.record(z2.string(), z2.array(z2.object({
|
|
709
|
-
field: z2.string(),
|
|
710
|
-
type: z2.string(),
|
|
711
|
-
description: z2.string()
|
|
712
|
-
})))
|
|
713
|
-
}).parse(await import(pathToFileURL(resolve3(root, config.typegen.dir, "plc.ts")).href));
|
|
755
|
+
const contract = plcContractSchema.parse(await import(pathToFileURL(resolve3(root, config.typegen.dir, generatedFiles.contract)).href));
|
|
714
756
|
return contractVariables(contract).map(({ path, type }) => ({ path, type }));
|
|
715
757
|
};
|
|
716
|
-
var prepareRelease = async (file, loaded, flags) => {
|
|
758
|
+
var prepareRelease = async (file, loaded, flags, environment) => {
|
|
717
759
|
const { config, root } = loaded;
|
|
718
760
|
if (!config.compiler) {
|
|
719
761
|
throw new Error("tsplc deploy deploys tsPLC programs; configure compiler.");
|
|
720
762
|
}
|
|
721
763
|
const command = flags.simulate ? "run" : "deploy";
|
|
764
|
+
const serverCheck = config.server?.runtime ? checkServer(config, root) : undefined;
|
|
765
|
+
serverCheck?.catch(() => {
|
|
766
|
+
return;
|
|
767
|
+
});
|
|
722
768
|
const emitted = await buildProject(file, {
|
|
723
769
|
emitOnly: true,
|
|
724
770
|
forController: true,
|
|
725
771
|
frozenLockfile: flags["frozen-lockfile"],
|
|
726
772
|
...buildConfigs(loaded, flags),
|
|
727
773
|
buildTarget: buildTargetFor(command),
|
|
728
|
-
controller: controllerFor(config, command)
|
|
774
|
+
controller: controllerFor(config, command),
|
|
775
|
+
environment
|
|
729
776
|
});
|
|
730
777
|
if (hasErrors2(emitted.diagnostics)) {
|
|
731
778
|
return { diagnostics: emitted.diagnostics };
|
|
@@ -734,14 +781,11 @@ var prepareRelease = async (file, loaded, flags) => {
|
|
|
734
781
|
if (!settings) {
|
|
735
782
|
throw new Error("Configure build settings for deployment.");
|
|
736
783
|
}
|
|
737
|
-
await generateProject(file, {
|
|
738
|
-
loaded,
|
|
739
|
-
targets: await projectTargets(file, { loaded })
|
|
740
|
-
});
|
|
784
|
+
await generateProject(file, { loaded, targets: emitted.targets });
|
|
741
785
|
const portable = (path) => path.split(sep).join("/");
|
|
742
786
|
const libraries = (settings.libraries ?? []).map((library) => ({
|
|
743
787
|
...library,
|
|
744
|
-
release: `libraries/${library.sha256}-${
|
|
788
|
+
release: `libraries/${library.sha256}-${basename2(library.path)}`
|
|
745
789
|
}));
|
|
746
790
|
const files = [
|
|
747
791
|
{ path: "template.project", content: Bun.file(settings.template) },
|
|
@@ -759,37 +803,38 @@ var prepareRelease = async (file, loaded, flags) => {
|
|
|
759
803
|
content: Bun.file(resolve3(settings.sourceDir, source))
|
|
760
804
|
});
|
|
761
805
|
}
|
|
762
|
-
const debugManifest = resolve3(settings.sourceDir,
|
|
806
|
+
const debugManifest = resolve3(settings.sourceDir, debugManifestFile2);
|
|
763
807
|
if (existsSync2(debugManifest)) {
|
|
764
|
-
files.push({ path:
|
|
808
|
+
files.push({ path: debugManifestFile2, content: Bun.file(debugManifest) });
|
|
765
809
|
}
|
|
766
|
-
const serverScript =
|
|
810
|
+
const serverScript = serverCheck && await bundleServer(await serverCheck, config, root);
|
|
767
811
|
const server = serverScript ? {
|
|
768
|
-
path: `server/${
|
|
812
|
+
path: `server/${basename2(serverScript)}`,
|
|
769
813
|
content: Bun.file(serverScript)
|
|
770
814
|
} : undefined;
|
|
771
815
|
if (server) {
|
|
772
816
|
files.push(server);
|
|
773
817
|
}
|
|
818
|
+
const releaseConfig = {
|
|
819
|
+
io: {},
|
|
820
|
+
deviceTree: settings.deviceTree,
|
|
821
|
+
controller: settings.controller,
|
|
822
|
+
libraryReferences: settings.libraryReferences,
|
|
823
|
+
libraries: libraries.map(({ release, ...library }) => ({
|
|
824
|
+
...library,
|
|
825
|
+
path: release
|
|
826
|
+
})),
|
|
827
|
+
task: settings.task,
|
|
828
|
+
tasks: settings.tasks,
|
|
829
|
+
removeObjects: settings.removeObjects,
|
|
830
|
+
symbols: settings.symbols,
|
|
831
|
+
timeouts: settings.timeouts,
|
|
832
|
+
template: "template.project",
|
|
833
|
+
sourceDir: "st",
|
|
834
|
+
entry: `st/${portable(relative(settings.sourceDir, settings.entry))}`
|
|
835
|
+
};
|
|
774
836
|
const manifest = {
|
|
775
|
-
config:
|
|
776
|
-
io: {},
|
|
777
|
-
deviceTree: settings.deviceTree,
|
|
778
|
-
controller: settings.controller,
|
|
779
|
-
libraryReferences: settings.libraryReferences,
|
|
780
|
-
libraries: libraries.map(({ release, ...library }) => ({
|
|
781
|
-
...library,
|
|
782
|
-
path: release
|
|
783
|
-
})),
|
|
784
|
-
task: settings.task,
|
|
785
|
-
tasks: settings.tasks,
|
|
786
|
-
removeObjects: settings.removeObjects,
|
|
787
|
-
symbols: settings.symbols,
|
|
788
|
-
timeouts: settings.timeouts,
|
|
789
|
-
template: "template.project",
|
|
790
|
-
sourceDir: "st",
|
|
791
|
-
entry: `st/${portable(relative(settings.sourceDir, settings.entry))}`
|
|
792
|
-
},
|
|
837
|
+
config: releaseConfig,
|
|
793
838
|
variables: await releaseVariables(config, root),
|
|
794
839
|
server: server?.path,
|
|
795
840
|
debug: config.debug,
|
|
@@ -802,7 +847,9 @@ var prepareRelease = async (file, loaded, flags) => {
|
|
|
802
847
|
// packages/compiler/src/project/terminal.ts
|
|
803
848
|
import { ask } from "@tsplc/agent";
|
|
804
849
|
var choose = async (question, items, label) => {
|
|
805
|
-
items.forEach((item, index) =>
|
|
850
|
+
items.forEach((item, index) => {
|
|
851
|
+
console.log(` ${index + 1}. ${label(item)}`);
|
|
852
|
+
});
|
|
806
853
|
while (true) {
|
|
807
854
|
const item = items[Number(await ask(`${question} [1-${items.length}]: `)) - 1];
|
|
808
855
|
if (item !== undefined) {
|
|
@@ -824,7 +871,7 @@ var timedProgress = () => {
|
|
|
824
871
|
var connect = (env) => {
|
|
825
872
|
const environment = z3.object({
|
|
826
873
|
TSPLC_AGENT_URL: z3.url({
|
|
827
|
-
error: "Configure the target's agent, or set TSPLC_AGENT_URL to the plant agent, such as http://
|
|
874
|
+
error: "Configure the target's agent, or set TSPLC_AGENT_URL to the plant agent, such as http://plant-pc:4850"
|
|
828
875
|
}),
|
|
829
876
|
TSPLC_AGENT_TOKEN: z3.string({
|
|
830
877
|
error: "Set TSPLC_AGENT_TOKEN to the plant agent's token"
|
|
@@ -865,16 +912,16 @@ async function serveProjectDebugger({ config, root, env }, flags) {
|
|
|
865
912
|
if (flags.opcua && !config.monitor) {
|
|
866
913
|
throw new Error("Configure monitor with the controller's OPC UA endpoint to use --opcua.");
|
|
867
914
|
}
|
|
868
|
-
const agentUrl = env
|
|
869
|
-
if (!flags.opcua && !(agentUrl && env
|
|
915
|
+
const agentUrl = env.TSPLC_AGENT_URL;
|
|
916
|
+
if (!flags.opcua && !(agentUrl && env.TSPLC_AGENT_TOKEN)) {
|
|
870
917
|
throw new Error("Set TSPLC_AGENT_URL and TSPLC_AGENT_TOKEN to read through the plant agent's login, or pass --opcua for a local virtual PLC.");
|
|
871
918
|
}
|
|
872
|
-
const file = resolve4(root,
|
|
919
|
+
const file = resolve4(root, emittedStDirectory3, debugManifestFile3);
|
|
873
920
|
if (!existsSync3(file)) {
|
|
874
921
|
throw new Error(`No debug manifest at ${relative2(process.cwd(), file)}: build with debug configured.`);
|
|
875
922
|
}
|
|
876
|
-
const port = Number(flags.port ?? 4870);
|
|
877
|
-
if (!
|
|
923
|
+
const port = tcpPort.safeParse(Number(flags.port ?? 4870));
|
|
924
|
+
if (!port.success) {
|
|
878
925
|
throw new Error("--port must be a TCP port.");
|
|
879
926
|
}
|
|
880
927
|
const manifest = await loadManifest(file);
|
|
@@ -889,13 +936,13 @@ async function serveProjectDebugger({ config, root, env }, flags) {
|
|
|
889
936
|
probe: manifest.build.target,
|
|
890
937
|
endpoint: `the plant agent at ${agentUrl}`
|
|
891
938
|
}),
|
|
892
|
-
stateDirectory: resolve4(root, "
|
|
939
|
+
stateDirectory: resolve4(root, generatedDirectory2, "debug"),
|
|
893
940
|
watch: config.debug?.watch ?? {},
|
|
894
941
|
...serverUrl && token && { server: { url: serverUrl, token } },
|
|
895
942
|
projectRoot: root,
|
|
896
943
|
log
|
|
897
944
|
});
|
|
898
|
-
const server = serveDebugger(debug, { port, log });
|
|
945
|
+
const server = serveDebugger(debug, { port: port.data, log });
|
|
899
946
|
console.log(`tsPLC debugger at ${server.url}`);
|
|
900
947
|
if (!serverUrl || !token) {
|
|
901
948
|
console.log("Not following the server's telemetry and requests: set server.baseUrlEnv or --server-url, and the server's bearer token variable.");
|
|
@@ -909,14 +956,14 @@ async function serveProjectDebugger({ config, root, env }, flags) {
|
|
|
909
956
|
}
|
|
910
957
|
|
|
911
958
|
// packages/compiler/src/project/plant.ts
|
|
912
|
-
import {
|
|
913
|
-
AgentOperationError as AgentOperationError2,
|
|
914
|
-
createAgentClient as createAgentClient2
|
|
915
|
-
} from "@tsplc/agent/client";
|
|
916
959
|
import {
|
|
917
960
|
ask as ask3,
|
|
918
961
|
askCredentials as askCredentials2
|
|
919
962
|
} from "@tsplc/agent";
|
|
963
|
+
import {
|
|
964
|
+
AgentOperationError as AgentOperationError2,
|
|
965
|
+
createAgentClient as createAgentClient2
|
|
966
|
+
} from "@tsplc/agent/client";
|
|
920
967
|
import { LoginUnavailable as LoginUnavailable2, noLogin as noLogin2 } from "@tsplc/debug";
|
|
921
968
|
import { z as z4 } from "zod";
|
|
922
969
|
var plantCommands = [
|
|
@@ -938,7 +985,7 @@ var plantCommand = (name) => plantCommands.find((command) => command === name);
|
|
|
938
985
|
var connect2 = (env) => {
|
|
939
986
|
const environment = z4.object({
|
|
940
987
|
TSPLC_AGENT_URL: z4.url({
|
|
941
|
-
error: "Configure the target's agent, or set TSPLC_AGENT_URL to the plant agent, such as http://
|
|
988
|
+
error: "Configure the target's agent, or set TSPLC_AGENT_URL to the plant agent, such as http://plant-pc:4850"
|
|
942
989
|
}),
|
|
943
990
|
TSPLC_AGENT_TOKEN: z4.string({
|
|
944
991
|
error: "Set TSPLC_AGENT_TOKEN to the plant agent's token"
|
|
@@ -962,9 +1009,9 @@ var selectTarget = async (agent) => {
|
|
|
962
1009
|
const host = choice === manual ? await ask3("Controller address: ") : choice.address;
|
|
963
1010
|
return agent.setTarget({ host, port: choice.port });
|
|
964
1011
|
};
|
|
965
|
-
var controllerCredentials = async (
|
|
966
|
-
const username =
|
|
967
|
-
const password =
|
|
1012
|
+
var controllerCredentials = async (environment, agent, prompt) => {
|
|
1013
|
+
const username = environment.TSPLC_CONTROLLER_USERNAME;
|
|
1014
|
+
const password = environment.TSPLC_CONTROLLER_PASSWORD;
|
|
968
1015
|
if (username && password) {
|
|
969
1016
|
return { username, password };
|
|
970
1017
|
}
|
|
@@ -973,7 +1020,7 @@ var controllerCredentials = async (env, agent, prompt) => {
|
|
|
973
1020
|
}
|
|
974
1021
|
return agent.stored && !agent.initializeUser ? null : prompt();
|
|
975
1022
|
};
|
|
976
|
-
var deploy = async (agent, file, loaded, flags,
|
|
1023
|
+
var deploy = async (agent, file, loaded, flags, environment) => {
|
|
977
1024
|
const status = await agent.status();
|
|
978
1025
|
if (status.login) {
|
|
979
1026
|
throw new Error("A login is open; log out before deploying: tsplc logout");
|
|
@@ -981,7 +1028,7 @@ var deploy = async (agent, file, loaded, flags, env) => {
|
|
|
981
1028
|
const target = !status.target || flags.select ? await selectTarget(agent) : status.target;
|
|
982
1029
|
console.log(`Building the release for ${target.host}…`);
|
|
983
1030
|
const building = timedProgress();
|
|
984
|
-
const { release, diagnostics } = await prepareRelease(file, loaded, flags);
|
|
1031
|
+
const { release, diagnostics } = await prepareRelease(file, loaded, flags, environment);
|
|
985
1032
|
if (!release) {
|
|
986
1033
|
return { diagnostics };
|
|
987
1034
|
}
|
|
@@ -989,7 +1036,7 @@ var deploy = async (agent, file, loaded, flags, env) => {
|
|
|
989
1036
|
if (flags.download && !await confirm("A full download stops the running application while it loads. Continue?", flags)) {
|
|
990
1037
|
throw new Error("Cancelled.");
|
|
991
1038
|
}
|
|
992
|
-
const credentials = await controllerCredentials(
|
|
1039
|
+
const credentials = await controllerCredentials(environment, {
|
|
993
1040
|
stored: status.credentialsStored,
|
|
994
1041
|
initializeUser: flags["initialize-user"] ?? false
|
|
995
1042
|
}, askCredentials2);
|
|
@@ -1010,7 +1057,7 @@ var deploy = async (agent, file, loaded, flags, env) => {
|
|
|
1010
1057
|
return agent.deploy(release, { ...settings, download: true }, timedProgress());
|
|
1011
1058
|
}
|
|
1012
1059
|
};
|
|
1013
|
-
var ensureLogin = async (agent,
|
|
1060
|
+
var ensureLogin = async (agent, environment) => {
|
|
1014
1061
|
const { login, credentialsStored } = await agent.status();
|
|
1015
1062
|
if (login && "state" in login) {
|
|
1016
1063
|
return;
|
|
@@ -1019,7 +1066,7 @@ var ensureLogin = async (agent, env) => {
|
|
|
1019
1066
|
console.log(`The open login failed (${login.error}); replacing it.`);
|
|
1020
1067
|
await agent.logout();
|
|
1021
1068
|
}
|
|
1022
|
-
const credentials = await controllerCredentials(
|
|
1069
|
+
const credentials = await controllerCredentials(environment, { stored: credentialsStored, initializeUser: false }, askCredentials2);
|
|
1023
1070
|
console.log("Logging in. CODESYS takes a few minutes to start; the login stays open until tsplc logout.");
|
|
1024
1071
|
await agent.login(credentials, progress);
|
|
1025
1072
|
};
|
|
@@ -1088,20 +1135,20 @@ var printLogin = (result) => {
|
|
|
1088
1135
|
console.log(`Forced: ${result.forced.join(", ")}`);
|
|
1089
1136
|
}
|
|
1090
1137
|
};
|
|
1091
|
-
var runPlantCommand = async (agent, command, args, flags, project
|
|
1138
|
+
var runPlantCommand = async (agent, command, args, flags, project) => {
|
|
1092
1139
|
const expect = (count, usage) => {
|
|
1093
1140
|
if (args.length !== count) {
|
|
1094
1141
|
throw new Error(`Usage: tsplc ${command} ${usage}`);
|
|
1095
1142
|
}
|
|
1096
1143
|
};
|
|
1097
1144
|
const send = async (loginCommand) => {
|
|
1098
|
-
await ensureLogin(agent,
|
|
1145
|
+
await ensureLogin(agent, project.environment);
|
|
1099
1146
|
printLogin(await agent.command(loginCommand));
|
|
1100
1147
|
};
|
|
1101
1148
|
switch (command) {
|
|
1102
1149
|
case "deploy": {
|
|
1103
1150
|
expect(0, "[--target name] [--download] [--select] [--initialize-user] [--simulate]");
|
|
1104
|
-
const deployed = await deploy(agent, project.file, await project.load(), flags,
|
|
1151
|
+
const deployed = await deploy(agent, project.file, await project.load(), flags, project.environment);
|
|
1105
1152
|
if ("diagnostics" in deployed) {
|
|
1106
1153
|
return deployed;
|
|
1107
1154
|
}
|
|
@@ -1119,7 +1166,7 @@ var runPlantCommand = async (agent, command, args, flags, project, env) => {
|
|
|
1119
1166
|
return printStatus(agent);
|
|
1120
1167
|
case "login":
|
|
1121
1168
|
expect(0, "");
|
|
1122
|
-
await ensureLogin(agent,
|
|
1169
|
+
await ensureLogin(agent, project.environment);
|
|
1123
1170
|
printLogin(await agent.command({ command: "state" }));
|
|
1124
1171
|
return;
|
|
1125
1172
|
case "logout": {
|
|
@@ -1184,28 +1231,27 @@ var runPlantCommand = async (agent, command, args, flags, project, env) => {
|
|
|
1184
1231
|
|
|
1185
1232
|
// packages/compiler/src/project/project-commands.ts
|
|
1186
1233
|
import { resolve as resolve5 } from "node:path";
|
|
1187
|
-
import {
|
|
1188
|
-
buildTargetFor as buildTargetFor2,
|
|
1189
|
-
controllerFor as controllerFor2,
|
|
1190
|
-
loadTsplcConfig as loadTsplcConfig2,
|
|
1191
|
-
rawBuildConfig
|
|
1192
|
-
} from "@tsplc/config";
|
|
1193
1234
|
import {
|
|
1194
1235
|
buildProject as buildSt,
|
|
1236
|
+
checkRawSources,
|
|
1195
1237
|
configureDocker,
|
|
1196
1238
|
configureRuntime,
|
|
1197
|
-
|
|
1239
|
+
inspectProjectController,
|
|
1198
1240
|
installLibraries as installLibraries2,
|
|
1199
|
-
loadSources,
|
|
1200
1241
|
rawEngineeringSettings,
|
|
1201
|
-
resolveConfig,
|
|
1202
1242
|
runProject,
|
|
1203
1243
|
updateController
|
|
1204
1244
|
} from "@tsplc/build";
|
|
1205
1245
|
import { checkHostConfig as checkHostConfig2 } from "@tsplc/compiler";
|
|
1206
1246
|
import { hasErrors as hasErrors3 } from "@tsplc/compiler/ir";
|
|
1247
|
+
import {
|
|
1248
|
+
buildTargetFor as buildTargetFor2,
|
|
1249
|
+
controllerFor as controllerFor2,
|
|
1250
|
+
loadTsplcConfig as loadTsplcConfig2,
|
|
1251
|
+
rawBuildConfig
|
|
1252
|
+
} from "@tsplc/config";
|
|
1253
|
+
import { resolveConfig } from "@tsplc/config/build";
|
|
1207
1254
|
import { generateProject as generateProject2 } from "@tsplc/typegen";
|
|
1208
|
-
import { loadHardware as loadHardware2, resolveIo as resolveIo2 } from "@tsplc/typegen/hardware";
|
|
1209
1255
|
var projectCommands = [
|
|
1210
1256
|
"install",
|
|
1211
1257
|
"typegen",
|
|
@@ -1228,9 +1274,6 @@ class DiagnosticFailure extends Error {
|
|
|
1228
1274
|
}
|
|
1229
1275
|
}
|
|
1230
1276
|
var checkProjectFlags = (command, flags) => {
|
|
1231
|
-
if (flags.format && !["json", "text"].includes(flags.format)) {
|
|
1232
|
-
throw new Error("--format must be json or text.");
|
|
1233
|
-
}
|
|
1234
1277
|
if (flags["emit-only"] && command !== "build") {
|
|
1235
1278
|
throw new Error("--emit-only is supported by build only.");
|
|
1236
1279
|
}
|
|
@@ -1253,28 +1296,39 @@ var checkProjectFlags = (command, flags) => {
|
|
|
1253
1296
|
throw new Error("--emit-only applies to PLC emission only.");
|
|
1254
1297
|
}
|
|
1255
1298
|
};
|
|
1256
|
-
var runProjectCommand = async (command, file, flags,
|
|
1257
|
-
const
|
|
1299
|
+
var runProjectCommand = async (command, file, flags, environment) => {
|
|
1300
|
+
const context = {
|
|
1301
|
+
progress: flags.format === "json" ? "stderr" : "stdout",
|
|
1302
|
+
environment
|
|
1303
|
+
};
|
|
1304
|
+
const { progress } = context;
|
|
1305
|
+
const load = () => loadTsplcConfig2(file, {
|
|
1306
|
+
env: environment,
|
|
1307
|
+
target: flags.target,
|
|
1308
|
+
forAgent: false
|
|
1309
|
+
});
|
|
1258
1310
|
switch (command) {
|
|
1259
1311
|
case "configure":
|
|
1260
|
-
return configure(flags);
|
|
1312
|
+
return configure(flags, progress);
|
|
1261
1313
|
case "clean":
|
|
1262
1314
|
return cleanProject(file);
|
|
1263
1315
|
case "install":
|
|
1264
1316
|
return install(await load(), flags);
|
|
1265
1317
|
case "typegen":
|
|
1266
|
-
return typegen(file, await load(), flags);
|
|
1318
|
+
return typegen(file, await load(), flags, environment);
|
|
1267
1319
|
case "check":
|
|
1268
|
-
return check(file, await loadCheckedConfig(file, load));
|
|
1320
|
+
return check(file, await loadCheckedConfig(file, load), environment);
|
|
1269
1321
|
case "build":
|
|
1270
|
-
return build(file, await loadCheckedConfig(file, load), flags);
|
|
1322
|
+
return build(file, await loadCheckedConfig(file, load), flags, context);
|
|
1271
1323
|
case "run":
|
|
1272
|
-
return run(file, await loadCheckedConfig(file, load), flags);
|
|
1324
|
+
return run(file, await loadCheckedConfig(file, load), flags, context);
|
|
1273
1325
|
case "inspect":
|
|
1274
|
-
return
|
|
1326
|
+
return inspectProjectController(await load(), flags.read, {
|
|
1327
|
+
progress
|
|
1328
|
+
});
|
|
1275
1329
|
case "download":
|
|
1276
1330
|
case "online-change":
|
|
1277
|
-
return updateProgram(command, file, await loadCheckedConfig(file, load), flags);
|
|
1331
|
+
return updateProgram(command, file, await loadCheckedConfig(file, load), flags, context);
|
|
1278
1332
|
}
|
|
1279
1333
|
};
|
|
1280
1334
|
var loadCheckedConfig = async (file, load) => {
|
|
@@ -1284,8 +1338,8 @@ var loadCheckedConfig = async (file, load) => {
|
|
|
1284
1338
|
}
|
|
1285
1339
|
return { loaded: await load(), hostConfigDiagnostics };
|
|
1286
1340
|
};
|
|
1287
|
-
var configure = async (flags) => {
|
|
1288
|
-
await (flags.runtime ? configureRuntime() : configureDocker());
|
|
1341
|
+
var configure = async (flags, progress) => {
|
|
1342
|
+
await (flags.runtime ? configureRuntime({ progress }) : configureDocker({ progress }));
|
|
1289
1343
|
return { ok: true };
|
|
1290
1344
|
};
|
|
1291
1345
|
var install = async ({ config, root }, flags) => ({
|
|
@@ -1293,32 +1347,33 @@ var install = async ({ config, root }, flags) => ({
|
|
|
1293
1347
|
frozen: flags["frozen-lockfile"]
|
|
1294
1348
|
})
|
|
1295
1349
|
});
|
|
1296
|
-
var typegen = async (file, loaded, flags) => {
|
|
1297
|
-
const targets = await projectTargets(file, { loaded });
|
|
1350
|
+
var typegen = async (file, loaded, flags, environment) => {
|
|
1351
|
+
const targets = await projectTargets(file, { loaded, environment });
|
|
1298
1352
|
if (loaded.config.compiler && !flags.check) {
|
|
1299
1353
|
await generateProject2(file, { hardwareOnly: true, loaded, targets });
|
|
1300
|
-
const emitted = await buildProject(file, {
|
|
1354
|
+
const emitted = await buildProject(file, {
|
|
1355
|
+
emitOnly: true,
|
|
1356
|
+
loaded,
|
|
1357
|
+
environment
|
|
1358
|
+
});
|
|
1301
1359
|
if (hasErrors3(emitted.diagnostics)) {
|
|
1302
1360
|
throw new DiagnosticFailure(emitted);
|
|
1303
1361
|
}
|
|
1304
1362
|
}
|
|
1305
1363
|
return generateProject2(file, { check: flags.check, loaded, targets });
|
|
1306
1364
|
};
|
|
1307
|
-
var check = async (file, { loaded, hostConfigDiagnostics }) => {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
return checkProject(file, { loaded, hostConfigDiagnostics });
|
|
1365
|
+
var check = async (file, { loaded, hostConfigDiagnostics }, environment) => {
|
|
1366
|
+
if (loaded.config.compiler) {
|
|
1367
|
+
return checkProject(file, { loaded, hostConfigDiagnostics, environment });
|
|
1311
1368
|
}
|
|
1312
|
-
|
|
1313
|
-
...rawBuildConfig(config),
|
|
1314
|
-
io: resolveIo2(config, await loadHardware2(config, root))
|
|
1315
|
-
}, configFile));
|
|
1316
|
-
return { objects: sources.objects.length };
|
|
1369
|
+
return { objects: (await checkRawSources(loaded)).objects.length };
|
|
1317
1370
|
};
|
|
1318
|
-
var buildPlc = async (command, file, { loaded, hostConfigDiagnostics }, flags) => {
|
|
1371
|
+
var buildPlc = async (command, file, { loaded, hostConfigDiagnostics }, flags, { progress, environment }) => {
|
|
1319
1372
|
const { config } = loaded;
|
|
1320
1373
|
if (config.compiler) {
|
|
1321
|
-
const built = await buildProject(file, {
|
|
1374
|
+
const { targets, ...built } = await buildProject(file, {
|
|
1375
|
+
progress,
|
|
1376
|
+
environment,
|
|
1322
1377
|
emitOnly: flags["emit-only"],
|
|
1323
1378
|
frozenLockfile: flags["frozen-lockfile"],
|
|
1324
1379
|
...buildConfigs(loaded, flags),
|
|
@@ -1329,10 +1384,7 @@ var buildPlc = async (command, file, { loaded, hostConfigDiagnostics }, flags) =
|
|
|
1329
1384
|
if (hasErrors3(built.diagnostics)) {
|
|
1330
1385
|
throw new DiagnosticFailure(built);
|
|
1331
1386
|
}
|
|
1332
|
-
await generateProject2(file, {
|
|
1333
|
-
loaded,
|
|
1334
|
-
targets: await projectTargets(file, { loaded })
|
|
1335
|
-
});
|
|
1387
|
+
await generateProject2(file, { loaded, targets });
|
|
1336
1388
|
return built;
|
|
1337
1389
|
}
|
|
1338
1390
|
if (flags["emit-only"]) {
|
|
@@ -1342,55 +1394,56 @@ var buildPlc = async (command, file, { loaded, hostConfigDiagnostics }, flags) =
|
|
|
1342
1394
|
command,
|
|
1343
1395
|
frozenLockfile: flags["frozen-lockfile"],
|
|
1344
1396
|
simulate: flags.simulate
|
|
1345
|
-
}));
|
|
1397
|
+
}), { progress });
|
|
1346
1398
|
await generateProject2(file, { hardwareOnly: !config.typegen, loaded });
|
|
1347
1399
|
return built;
|
|
1348
1400
|
};
|
|
1349
|
-
var build = async (file, checked, flags) => {
|
|
1401
|
+
var build = async (file, checked, flags, context) => {
|
|
1350
1402
|
const { config, root } = checked.loaded;
|
|
1351
1403
|
if (flags.server) {
|
|
1352
|
-
return buildServer(config, root);
|
|
1404
|
+
return buildServer(await checkServer(config, root), config, root);
|
|
1353
1405
|
}
|
|
1354
|
-
const
|
|
1355
|
-
|
|
1406
|
+
const withServer = !flags.plc && !flags["emit-only"] && config.server?.runtime;
|
|
1407
|
+
const serverCheck = withServer ? checkServer(config, root) : undefined;
|
|
1408
|
+
serverCheck?.catch(() => {
|
|
1409
|
+
return;
|
|
1410
|
+
});
|
|
1411
|
+
const plc = await buildPlc("build", file, checked, flags, context);
|
|
1412
|
+
if (!serverCheck) {
|
|
1356
1413
|
return plc;
|
|
1357
1414
|
}
|
|
1358
|
-
return { ...plc, ...await buildServer(config, root) };
|
|
1415
|
+
return { ...plc, ...await buildServer(await serverCheck, config, root) };
|
|
1359
1416
|
};
|
|
1360
|
-
var run = async (file, checked, flags) => {
|
|
1417
|
+
var run = async (file, checked, flags, context) => {
|
|
1361
1418
|
const { config, configFile } = checked.loaded;
|
|
1362
|
-
const built = await buildPlc("run", file, checked, flags);
|
|
1419
|
+
const built = await buildPlc("run", file, checked, flags, context);
|
|
1363
1420
|
if (!config.build) {
|
|
1364
1421
|
throw new Error("Configure build to run this project.");
|
|
1365
1422
|
}
|
|
1366
|
-
await runProject(resolveConfig(config.compiler ? config.build : rawBuildConfig(config), configFile), config.name);
|
|
1423
|
+
await runProject(resolveConfig(config.compiler ? config.build : rawBuildConfig(config), configFile), config.name, { progress: context.progress });
|
|
1367
1424
|
return built;
|
|
1368
1425
|
};
|
|
1369
|
-
var
|
|
1370
|
-
if (!config.build) {
|
|
1371
|
-
throw new Error("Configure build settings and controller connection.");
|
|
1372
|
-
}
|
|
1373
|
-
return inspectController(resolveConfig({ ...config.build, controller: controllerFor2(config, "inspect") }, configFile), flags.read);
|
|
1374
|
-
};
|
|
1375
|
-
var updateProgram = async (operation, file, checked, flags) => {
|
|
1426
|
+
var updateProgram = async (operation, file, checked, flags, { progress, environment }) => {
|
|
1376
1427
|
const { config } = checked.loaded;
|
|
1377
1428
|
if (!config.build) {
|
|
1378
1429
|
throw new Error("Configure build settings and controller connection.");
|
|
1379
1430
|
}
|
|
1380
|
-
const settings = config.compiler ? await emittedControllerSettings(operation, file, checked, flags) : await rawEngineeringSettings(checked.loaded, {
|
|
1431
|
+
const settings = config.compiler ? await emittedControllerSettings(operation, file, checked, flags, environment) : await rawEngineeringSettings(checked.loaded, {
|
|
1381
1432
|
command: operation,
|
|
1382
1433
|
frozenLockfile: flags["frozen-lockfile"],
|
|
1383
1434
|
simulate: flags.simulate
|
|
1384
1435
|
});
|
|
1385
1436
|
return updateController(settings, operation, {
|
|
1386
1437
|
initializeUser: flags["initialize-user"],
|
|
1387
|
-
read: flags.read
|
|
1438
|
+
read: flags.read,
|
|
1439
|
+
progress
|
|
1388
1440
|
});
|
|
1389
1441
|
};
|
|
1390
|
-
var emittedControllerSettings = async (operation, file, { loaded, hostConfigDiagnostics }, flags) => {
|
|
1442
|
+
var emittedControllerSettings = async (operation, file, { loaded, hostConfigDiagnostics }, flags, environment) => {
|
|
1391
1443
|
const emitted = await buildProject(file, {
|
|
1392
1444
|
emitOnly: true,
|
|
1393
1445
|
forController: true,
|
|
1446
|
+
environment,
|
|
1394
1447
|
frozenLockfile: flags["frozen-lockfile"],
|
|
1395
1448
|
...buildConfigs(loaded, flags),
|
|
1396
1449
|
hostConfigDiagnostics,
|
|
@@ -1419,8 +1472,24 @@ Plant agent (the target's agent, else TSPLC_AGENT_URL; TSPLC_AGENT_TOKEN):
|
|
|
1419
1472
|
Debugger, on http://127.0.0.1, for the built .tsplc/artifacts/st/debug.json; it reads through
|
|
1420
1473
|
the plant agent's login (TSPLC_AGENT_URL, TSPLC_AGENT_TOKEN), or --opcua at config monitor:
|
|
1421
1474
|
tsplc debug [--target name] [--port 4870] [--server-url url] [--opcua]`;
|
|
1475
|
+
var formatSchema = z5.enum(["json", "text"]).optional();
|
|
1476
|
+
var requestedFormat = (argv) => {
|
|
1477
|
+
const index = argv.findIndex((argument) => argument === "--format" || argument.startsWith("--format="));
|
|
1478
|
+
const flag = argv[index];
|
|
1479
|
+
if (index < 0 || flag === undefined) {
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
return flag === "--format" ? argv[index + 1] : flag.slice("--format=".length);
|
|
1483
|
+
};
|
|
1484
|
+
var outputFormat = (format) => {
|
|
1485
|
+
const parsed = formatSchema.safeParse(format);
|
|
1486
|
+
if (!parsed.success) {
|
|
1487
|
+
throw new Error("--format must be json or text.");
|
|
1488
|
+
}
|
|
1489
|
+
return parsed.data;
|
|
1490
|
+
};
|
|
1422
1491
|
async function main() {
|
|
1423
|
-
const { values, positionals } = parseArgs({
|
|
1492
|
+
const { values: parsed, positionals } = parseArgs({
|
|
1424
1493
|
allowPositionals: true,
|
|
1425
1494
|
options: {
|
|
1426
1495
|
config: { type: "string" },
|
|
@@ -1445,6 +1514,10 @@ async function main() {
|
|
|
1445
1514
|
opcua: { type: "boolean" }
|
|
1446
1515
|
}
|
|
1447
1516
|
});
|
|
1517
|
+
const values = {
|
|
1518
|
+
...parsed,
|
|
1519
|
+
format: outputFormat(parsed.format)
|
|
1520
|
+
};
|
|
1448
1521
|
const [name, ...args] = positionals;
|
|
1449
1522
|
const file = values.config ?? "tsplc.config.ts";
|
|
1450
1523
|
if (!name || values.help) {
|
|
@@ -1471,7 +1544,11 @@ async function main() {
|
|
|
1471
1544
|
});
|
|
1472
1545
|
const loaded = existsSync4(file) ? await load() : undefined;
|
|
1473
1546
|
const env = loaded?.env ?? process.env;
|
|
1474
|
-
const failed = await runPlantCommand(connect2(env), plant, args, values, {
|
|
1547
|
+
const failed = await runPlantCommand(connect2(env), plant, args, values, {
|
|
1548
|
+
file,
|
|
1549
|
+
load: loaded ? async () => loaded : load,
|
|
1550
|
+
environment: env
|
|
1551
|
+
});
|
|
1475
1552
|
return failed ? report(failed, values.format) : 0;
|
|
1476
1553
|
}
|
|
1477
1554
|
if (args.length) {
|
|
@@ -1482,27 +1559,7 @@ async function main() {
|
|
|
1482
1559
|
throw new Error(`Unknown command ${name}.`);
|
|
1483
1560
|
}
|
|
1484
1561
|
checkProjectFlags(command, values);
|
|
1485
|
-
|
|
1486
|
-
return report(result, values.format);
|
|
1487
|
-
}
|
|
1488
|
-
async function withProgressOnStderr(enabled, run) {
|
|
1489
|
-
if (!enabled) {
|
|
1490
|
-
return run();
|
|
1491
|
-
}
|
|
1492
|
-
const log = console.log;
|
|
1493
|
-
const previousLogTarget = process.env["TSPLC_LOG_STDERR"];
|
|
1494
|
-
console.log = console.error;
|
|
1495
|
-
process.env["TSPLC_LOG_STDERR"] = "1";
|
|
1496
|
-
try {
|
|
1497
|
-
return await run();
|
|
1498
|
-
} finally {
|
|
1499
|
-
console.log = log;
|
|
1500
|
-
if (previousLogTarget === undefined) {
|
|
1501
|
-
delete process.env["TSPLC_LOG_STDERR"];
|
|
1502
|
-
} else {
|
|
1503
|
-
process.env["TSPLC_LOG_STDERR"] = previousLogTarget;
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1562
|
+
return report(await runProjectCommand(command, file, values, { ...process.env }), values.format);
|
|
1506
1563
|
}
|
|
1507
1564
|
function report(result, format) {
|
|
1508
1565
|
const diagnostics = result.diagnostics ?? [];
|
|
@@ -1522,7 +1579,7 @@ function report(result, format) {
|
|
|
1522
1579
|
try {
|
|
1523
1580
|
process.exitCode = await main();
|
|
1524
1581
|
} catch (cause) {
|
|
1525
|
-
const json = process.argv.
|
|
1582
|
+
const json = requestedFormat(process.argv.slice(2)) === "json";
|
|
1526
1583
|
if (cause instanceof DiagnosticFailure) {
|
|
1527
1584
|
process.exitCode = report(cause.result, json ? "json" : undefined);
|
|
1528
1585
|
} else {
|
|
@@ -1541,5 +1598,5 @@ try {
|
|
|
1541
1598
|
}
|
|
1542
1599
|
}
|
|
1543
1600
|
|
|
1544
|
-
//# debugId=
|
|
1601
|
+
//# debugId=8DAFA492D99A54A364756E2164756E21
|
|
1545
1602
|
//# sourceMappingURL=cli.js.map
|