@tsplc/config 0.5.13 → 0.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -3
- package/dist/build.js +222 -175
- package/dist/build.js.map +9 -8
- package/dist/index.js +401 -341
- package/dist/index.js.map +10 -9
- package/dist/project-files.js +9 -2
- package/dist/project-files.js.map +3 -3
- package/dist/schema.js +237 -196
- package/dist/schema.js.map +6 -6
- package/package.json +2 -1
- package/src/build-schema.ts +64 -61
- package/src/build.ts +11 -10
- package/src/compiler.ts +80 -58
- package/src/config-module.ts +15 -0
- package/src/environment.ts +45 -34
- package/src/index.ts +10 -1
- package/src/loader.ts +10 -23
- package/src/project-files.ts +14 -0
- package/src/schema.ts +162 -118
package/README.md
CHANGED
|
@@ -1,7 +1,37 @@
|
|
|
1
1
|
# @tsplc/config
|
|
2
2
|
|
|
3
|
-
Part of [tsPLC](https://github.com/rip-technologies/tsplc).
|
|
3
|
+
The schema of `tsplc.config.ts`, the file that describes a tsPLC project, with `defineConfig`, the duration helpers and the config loader. Part of [tsPLC](https://github.com/rip-technologies/tsplc).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
bun add @tsplc/config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// tsplc.config.ts
|
|
15
|
+
import { defineConfig, ms } from "@tsplc/config";
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
name: "PartCounter",
|
|
19
|
+
backend: "codesys",
|
|
20
|
+
compiler: {
|
|
21
|
+
programs: { main: { module: "src/main.ts", export: "main" } },
|
|
22
|
+
},
|
|
23
|
+
tasks: [
|
|
24
|
+
{ name: "MainTask", priority: 1, schedule: { kind: "cyclic", interval: ms(10) }, programs: ["main"] },
|
|
25
|
+
],
|
|
26
|
+
io: {
|
|
27
|
+
"io.partSensor": { address: "%IX0.0" },
|
|
28
|
+
"io.binFull": { address: "%QX0.0" },
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
34
|
+
|
|
35
|
+
[Configuration reference](https://github.com/rip-technologies/tsplc/blob/master/docs/04-reference/configuration.md).
|
|
36
|
+
|
|
37
|
+
MIT licensed.
|
package/dist/build.js
CHANGED
|
@@ -11,15 +11,38 @@ var __esm = (fn, res, err) => () => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// packages/config/src/compiler.ts
|
|
14
|
+
import { nanosecondsPerMillisecond } from "@tsplc/iec";
|
|
14
15
|
import { z } from "zod";
|
|
15
|
-
var
|
|
16
|
+
var nanosecondsSchema, durationSchema, sourceExportSchema, taskSchema, scheduleRepeats = (tasks) => {
|
|
17
|
+
const names = new Set;
|
|
18
|
+
const programs = new Set;
|
|
19
|
+
const repeats = [];
|
|
20
|
+
tasks.forEach((task, index) => {
|
|
21
|
+
const name = task.name.toUpperCase();
|
|
22
|
+
if (names.has(name)) {
|
|
23
|
+
repeats.push({ task: index, position: null });
|
|
24
|
+
}
|
|
25
|
+
names.add(name);
|
|
26
|
+
task.programs.forEach((program, position) => {
|
|
27
|
+
const scheduled = program.toUpperCase();
|
|
28
|
+
if (programs.has(scheduled)) {
|
|
29
|
+
repeats.push({ task: index, position });
|
|
30
|
+
}
|
|
31
|
+
programs.add(scheduled);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return repeats;
|
|
35
|
+
}, targetSchema, common, entryConfigSchema, programsConfigSchema;
|
|
16
36
|
var init_compiler = __esm(() => {
|
|
17
|
-
|
|
18
|
-
durationSchema = z.
|
|
37
|
+
nanosecondsSchema = z.string().regex(/^[1-9][0-9]*$/, { abort: true });
|
|
38
|
+
durationSchema = z.strictObject({
|
|
19
39
|
kind: z.literal("duration"),
|
|
20
|
-
nanoseconds:
|
|
21
|
-
})
|
|
22
|
-
sourceExportSchema = z.
|
|
40
|
+
nanoseconds: nanosecondsSchema
|
|
41
|
+
});
|
|
42
|
+
sourceExportSchema = z.strictObject({
|
|
43
|
+
module: z.string().nonempty(),
|
|
44
|
+
export: z.string().nonempty()
|
|
45
|
+
});
|
|
23
46
|
taskSchema = z.strictObject({
|
|
24
47
|
name: z.string().nonempty(),
|
|
25
48
|
schedule: z.strictObject({
|
|
@@ -29,31 +52,36 @@ var init_compiler = __esm(() => {
|
|
|
29
52
|
priority: z.number().int().nonnegative(),
|
|
30
53
|
programs: z.array(z.string().nonempty()).nonempty()
|
|
31
54
|
});
|
|
32
|
-
targetSchema = z.
|
|
33
|
-
kind: z.string().
|
|
55
|
+
targetSchema = z.strictObject({
|
|
56
|
+
kind: z.string().nonempty(),
|
|
34
57
|
options: z.unknown().refine((value) => value !== undefined, {
|
|
35
58
|
message: "Target options are required."
|
|
36
59
|
})
|
|
37
|
-
})
|
|
60
|
+
});
|
|
38
61
|
common = {
|
|
39
|
-
name: z.string().
|
|
40
|
-
tsconfig: z.string().
|
|
41
|
-
tasks: z.array(taskSchema).
|
|
62
|
+
name: z.string().nonempty(),
|
|
63
|
+
tsconfig: z.string().nonempty(),
|
|
64
|
+
tasks: z.array(taskSchema).nonempty(),
|
|
42
65
|
target: targetSchema
|
|
43
66
|
};
|
|
44
|
-
entryConfigSchema = z.
|
|
45
|
-
programsConfigSchema = z.object({
|
|
67
|
+
entryConfigSchema = z.strictObject({
|
|
46
68
|
...common,
|
|
47
|
-
|
|
48
|
-
})
|
|
69
|
+
entry: sourceExportSchema
|
|
70
|
+
});
|
|
71
|
+
programsConfigSchema = z.strictObject({
|
|
72
|
+
...common,
|
|
73
|
+
programs: z.record(z.string().nonempty(), sourceExportSchema)
|
|
74
|
+
});
|
|
49
75
|
});
|
|
50
76
|
|
|
51
77
|
// packages/config/src/build-schema.ts
|
|
78
|
+
import { latestTimeNanoseconds, nanosecondsPerMillisecond as nanosecondsPerMillisecond2 } from "@tsplc/iec";
|
|
79
|
+
import { generatedNamePattern } from "@tsplc/iec/st";
|
|
52
80
|
import { z as z2 } from "zod";
|
|
53
|
-
var commandArgumentSchema, codesysTimeouts, positiveMilliseconds, pathSchema, tcpPort, sha256Digest, envName, wineSchema, localCodesysSchema, dockerImage = "tsplc-build:latest", containerCodesys, iecName, taskPriority, cyclicTasksSchema, ioBindingOptions, directIoBindingSchema, ethernetSchema, assemblyAddress, processImageSchema, channelAddress, deviceTreeSchema, fourPartVersion, controllerSchema, controllerTargetSchema, configSchema, controllerBudgets = (timeouts) => ({
|
|
81
|
+
var commandArgumentSchema, codesysTimeouts, positiveMilliseconds, pathSchema, tcpPort, runtimePort = 11740, gatewayPort = 1217, opcuaPort = 4840, sha256Digest, envName, wineSchema, localCodesysSchema, dockerImage = "tsplc-build:latest", containerCodesys, iecName, taskPriority, cyclicTasksSchema, ioBindingOptions, directIoBindingSchema, ethernetSchema, assemblyAddress, processImageSchema, channelAddress, deviceTreeSchema, fourPartVersion, controllerSchema, controllerTargetSchema, configSchema, controllerBudgets = (timeouts) => ({
|
|
54
82
|
prepare: timeouts.prepare ?? timeouts.build,
|
|
55
83
|
transfer: timeouts.transfer ?? codesysTimeouts.transfer
|
|
56
|
-
}), releaseConfigSchema, engineeringBuildSchema;
|
|
84
|
+
}), releaseConfigSchema, compilerDecided, engineeringBuildSchema;
|
|
57
85
|
var init_build_schema = __esm(() => {
|
|
58
86
|
init_compiler();
|
|
59
87
|
commandArgumentSchema = z2.string().refine((value) => value.trim().length > 0, "Command arguments must not be empty").refine((value) => !/["\r\n\0]/.test(value), "Command arguments must not contain quotes, line breaks, or null bytes");
|
|
@@ -89,42 +117,28 @@ var init_build_schema = __esm(() => {
|
|
|
89
117
|
profile: "CODESYS V3.5 SP22 Patch 3",
|
|
90
118
|
wine: { prefix: "/tmp/codesys-wine", nativeExit: true }
|
|
91
119
|
};
|
|
92
|
-
iecName = z2.string().regex(
|
|
120
|
+
iecName = z2.string().regex(generatedNamePattern);
|
|
93
121
|
taskPriority = z2.number().int().min(0).max(31);
|
|
94
122
|
cyclicTasksSchema = z2.array(z2.strictObject({
|
|
95
123
|
name: iecName,
|
|
96
|
-
intervalNanoseconds:
|
|
97
|
-
if (!nanosecondsPattern.test(value)) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
124
|
+
intervalNanoseconds: nanosecondsSchema.refine((value) => {
|
|
100
125
|
const ns = BigInt(value);
|
|
101
|
-
return ns %
|
|
126
|
+
return ns % nanosecondsPerMillisecond2 === 0n && ns <= latestTimeNanoseconds;
|
|
102
127
|
}, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
|
|
103
128
|
priority: taskPriority,
|
|
104
129
|
programs: z2.array(iecName).nonempty()
|
|
105
130
|
})).nonempty().superRefine((tasks, context) => {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
names.add(task.name.toLowerCase());
|
|
117
|
-
task.programs.forEach((program, position) => {
|
|
118
|
-
if (programs.has(program.toLowerCase())) {
|
|
119
|
-
context.addIssue({
|
|
120
|
-
code: "custom",
|
|
121
|
-
path: [index, "programs", position],
|
|
122
|
-
message: "A program can be scheduled only once"
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
programs.add(program.toLowerCase());
|
|
131
|
+
for (const { task, position } of scheduleRepeats(tasks)) {
|
|
132
|
+
context.addIssue(position === null ? {
|
|
133
|
+
code: "custom",
|
|
134
|
+
path: [task, "name"],
|
|
135
|
+
message: "Task names must be unique"
|
|
136
|
+
} : {
|
|
137
|
+
code: "custom",
|
|
138
|
+
path: [task, "programs", position],
|
|
139
|
+
message: "A program can be scheduled only once"
|
|
126
140
|
});
|
|
127
|
-
}
|
|
141
|
+
}
|
|
128
142
|
});
|
|
129
143
|
ioBindingOptions = {
|
|
130
144
|
inverted: z2.boolean().optional(),
|
|
@@ -216,11 +230,11 @@ var init_build_schema = __esm(() => {
|
|
|
216
230
|
network: pathSchema.default("bridge"),
|
|
217
231
|
gateway: z2.strictObject({
|
|
218
232
|
host: pathSchema,
|
|
219
|
-
port: tcpPort.default(
|
|
233
|
+
port: tcpPort.default(gatewayPort)
|
|
220
234
|
}),
|
|
221
235
|
device: z2.strictObject({
|
|
222
236
|
host: pathSchema,
|
|
223
|
-
port: tcpPort.default(
|
|
237
|
+
port: tcpPort.default(runtimePort)
|
|
224
238
|
}),
|
|
225
239
|
credentials: z2.strictObject({
|
|
226
240
|
usernameEnv: envName,
|
|
@@ -244,24 +258,27 @@ var init_build_schema = __esm(() => {
|
|
|
244
258
|
online: true,
|
|
245
259
|
bulkImport: true
|
|
246
260
|
});
|
|
247
|
-
|
|
261
|
+
compilerDecided = {
|
|
248
262
|
sourceDir: true,
|
|
249
263
|
entry: true,
|
|
250
264
|
outDir: true,
|
|
251
265
|
task: true,
|
|
252
266
|
tasks: true
|
|
253
|
-
}
|
|
267
|
+
};
|
|
268
|
+
engineeringBuildSchema = configSchema.omit(compilerDecided);
|
|
254
269
|
});
|
|
255
270
|
|
|
256
271
|
// packages/config/src/project-files.ts
|
|
257
|
-
|
|
272
|
+
import { z as z4 } from "zod";
|
|
273
|
+
var configFileName = "tsplc.config.ts", generatedDirectory = ".tsplc", emittedStDirectory, ioSymbolsSchema, projectSnapshotFile;
|
|
258
274
|
var init_project_files = __esm(() => {
|
|
259
275
|
emittedStDirectory = `${generatedDirectory}/artifacts/st`;
|
|
276
|
+
ioSymbolsSchema = z4.record(z4.string(), z4.string());
|
|
260
277
|
projectSnapshotFile = `${generatedDirectory}/project.json`;
|
|
261
278
|
});
|
|
262
279
|
|
|
263
280
|
// packages/config/src/schema.ts
|
|
264
|
-
import { z as
|
|
281
|
+
import { z as z5 } from "zod";
|
|
265
282
|
function rawBuildConfig(config) {
|
|
266
283
|
if (config.compiler) {
|
|
267
284
|
throw new Error("Use the compiler build plan for TypeScript projects.");
|
|
@@ -277,75 +294,78 @@ function rawBuildConfig(config) {
|
|
|
277
294
|
}
|
|
278
295
|
return {
|
|
279
296
|
...config.build,
|
|
280
|
-
tasks: cyclicTasksSchema.parse(config.tasks
|
|
281
|
-
name: task.name,
|
|
282
|
-
intervalNanoseconds: task.schedule.interval.nanoseconds,
|
|
283
|
-
priority: task.priority,
|
|
284
|
-
programs: task.programs
|
|
285
|
-
})))
|
|
297
|
+
tasks: cyclicTasksSchema.parse(taskPlan(config.tasks))
|
|
286
298
|
};
|
|
287
299
|
}
|
|
288
|
-
var httpOptionsSchema, ioBindingSchema, assemblySchema, hardwareDeviceSchema, dependencySchema, codesysTaskSchema, monitorSchema, telemetrySchema, debugSchema, typegenSchema, buildTargetSchema, publicationSchema,
|
|
300
|
+
var httpOptionsSchema, ioBindingSchema, assemblySchema, hardwareDeviceSchema, dependencySchema, codesysTaskSchema, monitorSchema, telemetrySchema, debugSchema, typegenSchema, buildTargetSchema, publicationSchema, hmiTarget, hmiControlId, hmiControlSchema, hmiSchema, tsplcConfigSchema, taskPlan = (tasks) => tasks.map((task) => ({
|
|
301
|
+
name: task.name,
|
|
302
|
+
intervalNanoseconds: task.schedule.interval.nanoseconds,
|
|
303
|
+
priority: task.priority,
|
|
304
|
+
programs: task.programs
|
|
305
|
+
}));
|
|
289
306
|
var init_schema = __esm(() => {
|
|
290
307
|
init_build_schema();
|
|
291
308
|
init_compiler();
|
|
292
309
|
init_project_files();
|
|
293
|
-
httpOptionsSchema =
|
|
294
|
-
timeoutMs:
|
|
295
|
-
credentials:
|
|
310
|
+
httpOptionsSchema = z5.strictObject({
|
|
311
|
+
timeoutMs: z5.number().int().positive().max(60000).default(2000),
|
|
312
|
+
credentials: z5.array(z5.strictObject({
|
|
296
313
|
originEnv: envName,
|
|
297
314
|
bearerTokenEnv: envName
|
|
298
315
|
})).default([])
|
|
299
316
|
}).prefault({});
|
|
300
|
-
ioBindingSchema =
|
|
317
|
+
ioBindingSchema = z5.union([
|
|
301
318
|
directIoBindingSchema,
|
|
302
|
-
|
|
303
|
-
device:
|
|
304
|
-
channel:
|
|
319
|
+
z5.strictObject({
|
|
320
|
+
device: z5.string().nonempty(),
|
|
321
|
+
channel: z5.string().nonempty(),
|
|
305
322
|
...ioBindingOptions
|
|
306
323
|
})
|
|
307
324
|
]);
|
|
308
|
-
assemblySchema =
|
|
309
|
-
assembly:
|
|
310
|
-
size:
|
|
325
|
+
assemblySchema = z5.strictObject({
|
|
326
|
+
assembly: z5.number().int().nonnegative().optional(),
|
|
327
|
+
size: z5.number().int().positive().optional(),
|
|
311
328
|
address: assemblyAddress.optional()
|
|
312
329
|
});
|
|
313
|
-
hardwareDeviceSchema =
|
|
314
|
-
file:
|
|
315
|
-
connection:
|
|
330
|
+
hardwareDeviceSchema = z5.strictObject({
|
|
331
|
+
file: z5.string().nonempty(),
|
|
332
|
+
connection: z5.string().nonempty().optional(),
|
|
316
333
|
inputs: assemblySchema.optional(),
|
|
317
334
|
outputs: assemblySchema.optional(),
|
|
318
|
-
modbus:
|
|
335
|
+
modbus: z5.strictObject({
|
|
319
336
|
port: tcpPort.default(502),
|
|
320
|
-
registers:
|
|
337
|
+
registers: z5.record(iecName, z5.number().int().min(0).max(65535))
|
|
321
338
|
}).optional(),
|
|
322
|
-
statusSymbols:
|
|
323
|
-
network:
|
|
324
|
-
address:
|
|
339
|
+
statusSymbols: z5.record(z5.string(), z5.string()).optional(),
|
|
340
|
+
network: z5.strictObject({
|
|
341
|
+
address: z5.ipv4().optional(),
|
|
325
342
|
rpi: durationSchema.refine((rpi) => BigInt(rpi.nanoseconds) % 1000n === 0n, "An RPI must be a whole number of microseconds.").optional()
|
|
326
343
|
}).optional()
|
|
327
344
|
});
|
|
328
|
-
dependencySchema =
|
|
345
|
+
dependencySchema = z5.union([
|
|
329
346
|
fourPartVersion,
|
|
330
|
-
|
|
347
|
+
z5.strictObject({
|
|
331
348
|
version: fourPartVersion,
|
|
332
|
-
company:
|
|
333
|
-
namespace:
|
|
349
|
+
company: z5.string().optional(),
|
|
350
|
+
namespace: z5.string().optional()
|
|
334
351
|
}),
|
|
335
|
-
|
|
352
|
+
z5.strictObject({
|
|
353
|
+
path: z5.string().nonempty(),
|
|
354
|
+
namespace: z5.string().optional()
|
|
355
|
+
})
|
|
336
356
|
]);
|
|
337
357
|
codesysTaskSchema = taskSchema.extend({
|
|
338
358
|
name: iecName,
|
|
339
359
|
priority: taskPriority
|
|
340
360
|
});
|
|
341
|
-
monitorSchema =
|
|
342
|
-
endpoint:
|
|
343
|
-
namespaceUri:
|
|
344
|
-
symbols:
|
|
345
|
-
securityMode:
|
|
346
|
-
securityPolicy:
|
|
347
|
-
certificateDirectory:
|
|
348
|
-
username:
|
|
361
|
+
monitorSchema = z5.strictObject({
|
|
362
|
+
endpoint: z5.string().url(),
|
|
363
|
+
namespaceUri: z5.string().optional(),
|
|
364
|
+
symbols: z5.array(z5.string().nonempty()).optional(),
|
|
365
|
+
securityMode: z5.enum(["None", "Sign", "SignAndEncrypt"]).default("SignAndEncrypt"),
|
|
366
|
+
securityPolicy: z5.enum(["None", "Basic256Sha256"]).optional(),
|
|
367
|
+
certificateDirectory: z5.string().nonempty().default(`${generatedDirectory}/opcua-pki`),
|
|
368
|
+
username: z5.string().nonempty().optional(),
|
|
349
369
|
passwordEnv: envName.optional()
|
|
350
370
|
}).superRefine((monitor, context) => {
|
|
351
371
|
if (monitor.securityPolicy && monitor.securityMode === "None" !== (monitor.securityPolicy === "None")) {
|
|
@@ -373,71 +393,70 @@ var init_schema = __esm(() => {
|
|
|
373
393
|
...monitor,
|
|
374
394
|
securityPolicy: monitor.securityPolicy ?? (monitor.securityMode === "None" ? "None" : "Basic256Sha256")
|
|
375
395
|
}));
|
|
376
|
-
telemetrySchema =
|
|
377
|
-
capacity:
|
|
378
|
-
recordBytes:
|
|
396
|
+
telemetrySchema = z5.strictObject({
|
|
397
|
+
capacity: z5.number().int().min(4).max(4096).default(64),
|
|
398
|
+
recordBytes: z5.number().int().min(128).max(1024).default(512)
|
|
379
399
|
});
|
|
380
|
-
debugSchema =
|
|
381
|
-
trace:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
capacity:
|
|
385
|
-
operands:
|
|
400
|
+
debugSchema = z5.strictObject({
|
|
401
|
+
trace: z5.union([
|
|
402
|
+
z5.literal(false),
|
|
403
|
+
z5.strictObject({
|
|
404
|
+
capacity: z5.number().int().min(16).max(4096).default(256),
|
|
405
|
+
operands: z5.number().int().min(0).max(8).default(4)
|
|
386
406
|
})
|
|
387
407
|
]).default(false),
|
|
388
|
-
writers:
|
|
389
|
-
|
|
390
|
-
|
|
408
|
+
writers: z5.union([
|
|
409
|
+
z5.boolean(),
|
|
410
|
+
z5.strictObject({ paths: z5.array(z5.string().nonempty()).nonempty() })
|
|
391
411
|
]).default(true),
|
|
392
|
-
jobs:
|
|
393
|
-
watch:
|
|
394
|
-
requests:
|
|
395
|
-
capacity:
|
|
396
|
-
bodies:
|
|
412
|
+
jobs: z5.boolean().default(true),
|
|
413
|
+
watch: z5.record(z5.string(), z5.array(z5.string().nonempty())).default({}),
|
|
414
|
+
requests: z5.strictObject({
|
|
415
|
+
capacity: z5.number().int().min(1).max(1e5).default(1000),
|
|
416
|
+
bodies: z5.boolean().default(false)
|
|
397
417
|
}).prefault({})
|
|
398
418
|
});
|
|
399
|
-
typegenSchema =
|
|
400
|
-
types:
|
|
401
|
-
globals:
|
|
402
|
-
dir:
|
|
403
|
-
declarations:
|
|
404
|
-
ioTypes:
|
|
419
|
+
typegenSchema = z5.strictObject({
|
|
420
|
+
types: z5.union([z5.string(), z5.array(z5.string())]).optional(),
|
|
421
|
+
globals: z5.union([z5.string(), z5.array(z5.string())]).optional(),
|
|
422
|
+
dir: z5.string().default("generated"),
|
|
423
|
+
declarations: z5.boolean().default(true),
|
|
424
|
+
ioTypes: z5.boolean().default(true)
|
|
405
425
|
});
|
|
406
|
-
buildTargetSchema =
|
|
407
|
-
publicationSchema =
|
|
408
|
-
production:
|
|
409
|
-
development:
|
|
426
|
+
buildTargetSchema = z5.enum(["production", "development"]);
|
|
427
|
+
publicationSchema = z5.strictObject({
|
|
428
|
+
production: z5.array(z5.string().nonempty()),
|
|
429
|
+
development: z5.array(z5.string().nonempty())
|
|
410
430
|
});
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
kind: z3.literal("button"),
|
|
431
|
+
hmiTarget = z5.string().regex(/^\w+(\.\w+|\[\d+\])+$/);
|
|
432
|
+
hmiControlId = z5.string().nonempty();
|
|
433
|
+
hmiControlSchema = z5.discriminatedUnion("kind", [
|
|
434
|
+
z5.strictObject({
|
|
435
|
+
kind: z5.literal("button"),
|
|
417
436
|
id: hmiControlId,
|
|
418
|
-
label:
|
|
437
|
+
label: z5.string().nonempty(),
|
|
419
438
|
target: hmiTarget,
|
|
420
|
-
tone:
|
|
421
|
-
confirm:
|
|
439
|
+
tone: z5.enum(["start", "stop"]).optional(),
|
|
440
|
+
confirm: z5.boolean().optional()
|
|
422
441
|
}),
|
|
423
|
-
|
|
424
|
-
kind:
|
|
442
|
+
z5.strictObject({
|
|
443
|
+
kind: z5.literal("toggle"),
|
|
425
444
|
id: hmiControlId,
|
|
426
|
-
label:
|
|
445
|
+
label: z5.string().nonempty(),
|
|
427
446
|
target: hmiTarget
|
|
428
447
|
}),
|
|
429
|
-
|
|
430
|
-
kind:
|
|
448
|
+
z5.strictObject({
|
|
449
|
+
kind: z5.literal("slider"),
|
|
431
450
|
id: hmiControlId,
|
|
432
|
-
label:
|
|
451
|
+
label: z5.string().nonempty(),
|
|
433
452
|
target: hmiTarget,
|
|
434
|
-
min:
|
|
435
|
-
max:
|
|
453
|
+
min: z5.number().int(),
|
|
454
|
+
max: z5.number().int()
|
|
436
455
|
})
|
|
437
456
|
]);
|
|
438
|
-
hmiSchema =
|
|
439
|
-
title:
|
|
440
|
-
controls:
|
|
457
|
+
hmiSchema = z5.strictObject({
|
|
458
|
+
title: z5.string().nonempty(),
|
|
459
|
+
controls: z5.array(hmiControlSchema).default([]).superRefine((controls, context) => {
|
|
441
460
|
const seen = new Set;
|
|
442
461
|
controls.forEach((control, index) => {
|
|
443
462
|
if (seen.has(control.id)) {
|
|
@@ -450,22 +469,22 @@ var init_schema = __esm(() => {
|
|
|
450
469
|
seen.add(control.id);
|
|
451
470
|
});
|
|
452
471
|
}),
|
|
453
|
-
conveyors:
|
|
454
|
-
label:
|
|
455
|
-
positions:
|
|
456
|
-
diverters:
|
|
472
|
+
conveyors: z5.array(z5.strictObject({
|
|
473
|
+
label: z5.string().nonempty(),
|
|
474
|
+
positions: z5.number().int().positive(),
|
|
475
|
+
diverters: z5.array(z5.number().int().nonnegative()).default([])
|
|
457
476
|
})).default([])
|
|
458
477
|
});
|
|
459
|
-
tsplcConfigSchema =
|
|
460
|
-
name:
|
|
461
|
-
backend:
|
|
478
|
+
tsplcConfigSchema = z5.strictObject({
|
|
479
|
+
name: z5.string().default("Application"),
|
|
480
|
+
backend: z5.literal("codesys"),
|
|
462
481
|
publish: publicationSchema.optional(),
|
|
463
|
-
server:
|
|
464
|
-
baseUrlEnv:
|
|
465
|
-
transport:
|
|
466
|
-
runtime:
|
|
467
|
-
entry:
|
|
468
|
-
target:
|
|
482
|
+
server: z5.strictObject({
|
|
483
|
+
baseUrlEnv: envName.optional(),
|
|
484
|
+
transport: z5.enum(["http", "opcua"]).default("http"),
|
|
485
|
+
runtime: z5.strictObject({
|
|
486
|
+
entry: z5.string(),
|
|
487
|
+
target: z5.enum([
|
|
469
488
|
"bun-linux-x64",
|
|
470
489
|
"bun-linux-arm64",
|
|
471
490
|
"bun-darwin-x64",
|
|
@@ -474,46 +493,72 @@ var init_schema = __esm(() => {
|
|
|
474
493
|
]).optional()
|
|
475
494
|
}).optional()
|
|
476
495
|
}).optional(),
|
|
477
|
-
compiler:
|
|
478
|
-
tsconfig:
|
|
479
|
-
programs:
|
|
496
|
+
compiler: z5.strictObject({
|
|
497
|
+
tsconfig: z5.string().default("tsconfig.json"),
|
|
498
|
+
programs: z5.record(z5.string(), sourceExportSchema)
|
|
480
499
|
}).optional(),
|
|
481
|
-
tasks:
|
|
500
|
+
tasks: z5.array(codesysTaskSchema).nonempty().optional(),
|
|
482
501
|
build: configSchema.extend({ task: configSchema.shape.task.unwrap().optional() }).optional(),
|
|
483
|
-
codesys:
|
|
502
|
+
codesys: z5.strictObject({
|
|
484
503
|
http: httpOptionsSchema.optional(),
|
|
485
|
-
programNames:
|
|
486
|
-
deviceTree:
|
|
487
|
-
controllers:
|
|
504
|
+
programNames: z5.record(z5.string(), z5.string()).optional(),
|
|
505
|
+
deviceTree: z5.strictObject({ ethernet: ethernetSchema.optional() }).optional(),
|
|
506
|
+
controllers: z5.strictObject({
|
|
488
507
|
production: controllerTargetSchema.optional(),
|
|
489
508
|
development: controllerTargetSchema.optional()
|
|
490
509
|
}).optional()
|
|
491
510
|
}).optional(),
|
|
492
|
-
eds:
|
|
493
|
-
devices:
|
|
494
|
-
io:
|
|
495
|
-
dependencies:
|
|
511
|
+
eds: z5.union([z5.string(), z5.array(z5.string())]).default("eds"),
|
|
512
|
+
devices: z5.record(z5.string(), hardwareDeviceSchema).default({}),
|
|
513
|
+
io: z5.record(z5.string(), ioBindingSchema).default({}),
|
|
514
|
+
dependencies: z5.record(z5.string(), dependencySchema).default({}),
|
|
496
515
|
typegen: typegenSchema.optional(),
|
|
497
516
|
monitor: monitorSchema.optional(),
|
|
498
517
|
hmi: hmiSchema.optional(),
|
|
499
518
|
telemetry: telemetrySchema.optional(),
|
|
500
519
|
debug: debugSchema.optional(),
|
|
501
|
-
targets:
|
|
502
|
-
values:
|
|
503
|
-
agent:
|
|
520
|
+
targets: z5.record(z5.string().nonempty(), z5.strictObject({
|
|
521
|
+
values: z5.record(envName, z5.string()).default({}),
|
|
522
|
+
agent: z5.strictObject({ url: z5.url() }).optional()
|
|
504
523
|
})).default({}),
|
|
505
|
-
secrets:
|
|
506
|
-
service:
|
|
507
|
-
names:
|
|
524
|
+
secrets: z5.strictObject({
|
|
525
|
+
service: z5.string().nonempty(),
|
|
526
|
+
names: z5.array(envName).nonempty()
|
|
508
527
|
}).optional()
|
|
528
|
+
}).superRefine((config, context) => {
|
|
529
|
+
if (config.compiler && !config.tasks) {
|
|
530
|
+
context.addIssue({
|
|
531
|
+
code: "custom",
|
|
532
|
+
path: ["tasks"],
|
|
533
|
+
message: "TypeScript programs require a tasks configuration."
|
|
534
|
+
});
|
|
535
|
+
}
|
|
509
536
|
});
|
|
510
537
|
});
|
|
511
538
|
|
|
512
539
|
// packages/config/src/build.ts
|
|
513
540
|
init_build_schema();
|
|
514
|
-
init_build_schema();
|
|
515
541
|
import { dirname, resolve } from "node:path";
|
|
516
542
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
543
|
+
|
|
544
|
+
// packages/config/src/config-module.ts
|
|
545
|
+
import { z as z3 } from "zod";
|
|
546
|
+
var configModuleSchema = z3.object({
|
|
547
|
+
default: z3.unknown(),
|
|
548
|
+
config: z3.unknown()
|
|
549
|
+
});
|
|
550
|
+
var configExport = (module, path) => {
|
|
551
|
+
const exports = configModuleSchema.parse(module);
|
|
552
|
+
if (exports.default === undefined && exports.config === undefined) {
|
|
553
|
+
throw new Error(`${path} must export a default config`);
|
|
554
|
+
}
|
|
555
|
+
return exports.default ?? exports.config;
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// packages/config/src/build.ts
|
|
559
|
+
init_project_files();
|
|
560
|
+
init_build_schema();
|
|
561
|
+
init_compiler();
|
|
517
562
|
var defineBuildConfig = (config) => config;
|
|
518
563
|
var resolveConfig = (input, configFile) => {
|
|
519
564
|
const parsed = configSchema.parse(input);
|
|
@@ -539,13 +584,9 @@ var resolveConfig = (input, configFile) => {
|
|
|
539
584
|
}
|
|
540
585
|
};
|
|
541
586
|
};
|
|
542
|
-
var loadConfig = async (file =
|
|
587
|
+
var loadConfig = async (file = configFileName) => {
|
|
543
588
|
const path = resolve(file);
|
|
544
|
-
const
|
|
545
|
-
if (module.default === undefined && module.config === undefined) {
|
|
546
|
-
throw new Error(`${path} must export a default config`);
|
|
547
|
-
}
|
|
548
|
-
const input = module.default ?? module.config;
|
|
589
|
+
const input = configExport(await import(pathToFileURL(path).href), path);
|
|
549
590
|
if (input && typeof input === "object" && "build" in input) {
|
|
550
591
|
await Promise.resolve().then(() => init_schema());
|
|
551
592
|
return resolveConfig(rawBuildConfig(tsplcConfigSchema.parse(input)), path);
|
|
@@ -565,14 +606,20 @@ export {
|
|
|
565
606
|
directIoBindingSchema,
|
|
566
607
|
dockerImage,
|
|
567
608
|
engineeringBuildSchema,
|
|
609
|
+
envName,
|
|
568
610
|
ethernetSchema,
|
|
611
|
+
gatewayPort,
|
|
569
612
|
iecName,
|
|
570
613
|
loadConfig,
|
|
614
|
+
opcuaPort,
|
|
571
615
|
releaseConfigSchema,
|
|
572
616
|
resolveConfig,
|
|
617
|
+
runtimePort,
|
|
618
|
+
scheduleRepeats,
|
|
573
619
|
sha256Digest,
|
|
620
|
+
taskPriority,
|
|
574
621
|
tcpPort
|
|
575
622
|
};
|
|
576
623
|
|
|
577
|
-
//# debugId=
|
|
624
|
+
//# debugId=D7687E5B674F844764756E2164756E21
|
|
578
625
|
//# sourceMappingURL=build.js.map
|