@tsplc/config 0.2.17 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/build.js +164 -133
- package/dist/build.js.map +7 -7
- package/dist/index.js +291 -208
- package/dist/index.js.map +8 -7
- package/dist/schema.js +249 -204
- package/dist/schema.js.map +5 -5
- package/package.json +50 -51
- package/src/build-schema.ts +220 -197
- package/src/build.ts +73 -63
- package/src/compiler.ts +140 -122
- package/src/environment.ts +72 -0
- package/src/index.ts +52 -1
- package/src/loader.ts +33 -15
- package/src/schema.ts +429 -356
- package/templates/provenance.json +6 -6
package/src/build-schema.ts
CHANGED
|
@@ -1,245 +1,268 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { nanosecondsPattern } from "./compiler.ts";
|
|
2
3
|
|
|
3
4
|
export const commandArgumentSchema = z
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
.string()
|
|
6
|
+
.refine(
|
|
7
|
+
(value) => value.trim().length > 0,
|
|
8
|
+
"Command arguments must not be empty",
|
|
9
|
+
)
|
|
10
|
+
.refine(
|
|
11
|
+
(value) => !/["\r\n\0]/.test(value),
|
|
12
|
+
"Command arguments must not contain quotes, line breaks, or null bytes",
|
|
13
|
+
);
|
|
10
14
|
// CODESYS startup and project loading can each take several minutes.
|
|
11
15
|
export const codesysTimeouts = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
build: 20 * 60 * 1000,
|
|
17
|
+
hostCommand: 15_000,
|
|
18
|
+
runtime: 60_000,
|
|
19
|
+
startup: 20 * 60 * 1000,
|
|
20
|
+
stop: 10_000,
|
|
21
|
+
terminate: 5000,
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
const positiveMilliseconds = z.number().int().positive();
|
|
21
25
|
const pathSchema = z.string().trim().nonempty();
|
|
26
|
+
export const tcpPort = z.number().int().min(1).max(65535);
|
|
27
|
+
/** A SHA-256 digest as lowercase hex, the form `node:crypto` writes. */
|
|
28
|
+
export const sha256Digest = z.string().regex(/^[a-f0-9]{64}$/);
|
|
29
|
+
/** The name of an environment variable a credential is read from, so the config never holds it. */
|
|
30
|
+
export const envName = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
|
|
22
31
|
const wineSchema = z.strictObject({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
prefix: pathSchema,
|
|
33
|
+
binary: pathSchema.default("wine"),
|
|
34
|
+
pathBinary: pathSchema.default("winepath"),
|
|
35
|
+
debug: z.string().default("-all"),
|
|
36
|
+
nativeExit: z.boolean().default(false),
|
|
28
37
|
});
|
|
29
38
|
export const localCodesysSchema = z.strictObject({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
executable: commandArgumentSchema,
|
|
40
|
+
profile: commandArgumentSchema,
|
|
41
|
+
wine: wineSchema.optional(),
|
|
42
|
+
commandProcessor: pathSchema.default("cmd.exe"),
|
|
34
43
|
});
|
|
35
44
|
|
|
36
45
|
// `tsplc configure` builds this tag; every project compiles with it.
|
|
37
46
|
export const dockerImage = "tsplc-build:latest";
|
|
38
47
|
export const containerCodesys = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
executable:
|
|
49
|
+
"/tmp/codesys-wine/drive_c/CODESYS-3.5.22.30/CODESYS/Common/CODESYS.exe",
|
|
50
|
+
profile: "CODESYS V3.5 SP22 Patch 3",
|
|
51
|
+
wine: { prefix: "/tmp/codesys-wine", nativeExit: true },
|
|
42
52
|
};
|
|
43
|
-
const iecName = z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/);
|
|
53
|
+
export const iecName = z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/);
|
|
54
|
+
export const taskPriority = z.number().int().min(0).max(31);
|
|
44
55
|
export const cyclicTasksSchema = z
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
56
|
+
.array(
|
|
57
|
+
z.strictObject({
|
|
58
|
+
name: iecName,
|
|
59
|
+
intervalNanoseconds: z
|
|
60
|
+
.string()
|
|
61
|
+
.regex(nanosecondsPattern)
|
|
62
|
+
.refine((value) => {
|
|
63
|
+
// zod runs this refinement even when the pattern fails, and BigInt throws on a non-integer.
|
|
64
|
+
if (!nanosecondsPattern.test(value)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const ns = BigInt(value);
|
|
68
|
+
return ns % 1_000_000n === 0n && ns <= 4_294_967_295_000_000n;
|
|
69
|
+
}, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
|
|
70
|
+
priority: taskPriority,
|
|
71
|
+
programs: z.array(iecName).nonempty(),
|
|
72
|
+
}),
|
|
73
|
+
)
|
|
74
|
+
.nonempty()
|
|
75
|
+
.superRefine((tasks, context) => {
|
|
76
|
+
const names = new Set<string>();
|
|
77
|
+
const programs = new Set<string>();
|
|
78
|
+
tasks.forEach((task, index) => {
|
|
79
|
+
if (names.has(task.name.toLowerCase())) {
|
|
80
|
+
context.addIssue({
|
|
81
|
+
code: "custom",
|
|
82
|
+
path: [index, "name"],
|
|
83
|
+
message: "Task names must be unique",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
names.add(task.name.toLowerCase());
|
|
87
|
+
task.programs.forEach((program, position) => {
|
|
88
|
+
if (programs.has(program.toLowerCase())) {
|
|
89
|
+
context.addIssue({
|
|
90
|
+
code: "custom",
|
|
91
|
+
path: [index, "programs", position],
|
|
92
|
+
message: "A program can be scheduled only once",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
programs.add(program.toLowerCase());
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
87
99
|
export type CyclicTask = z.infer<typeof cyclicTasksSchema>[number];
|
|
88
100
|
/** `inverted` reads a BOOL input as its opposite; `shared` lets several bindings read one input. */
|
|
89
101
|
export const ioBindingOptions = {
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
inverted: z.boolean().optional(),
|
|
103
|
+
shared: z.boolean().optional(),
|
|
92
104
|
};
|
|
93
105
|
/** A process-image address in CODESYS byte addressing, with an optional IEC type. */
|
|
94
106
|
export const directIoBindingSchema = z.strictObject({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
address: z.string().regex(/^%[IQ](?:X\d+\.[0-7]|[BWD]\d+)$/),
|
|
108
|
+
type: z.string().optional(),
|
|
109
|
+
...ioBindingOptions,
|
|
98
110
|
});
|
|
99
111
|
/** The controller's Ethernet interface; omitted settings keep the CODESYS defaults. */
|
|
100
112
|
export const ethernetSchema = z.strictObject({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
interface: z.string().nonempty().optional(),
|
|
114
|
+
address: z.ipv4().optional(),
|
|
115
|
+
subnet: z.ipv4().optional(),
|
|
116
|
+
gateway: z.ipv4().optional(),
|
|
105
117
|
});
|
|
118
|
+
/** The byte where a device's input or output assembly starts in the process image. */
|
|
119
|
+
export const assemblyAddress = z.string().regex(/^%[IQ]B\d+$/);
|
|
106
120
|
const processImageSchema = z.strictObject({
|
|
107
|
-
|
|
108
|
-
|
|
121
|
+
address: assemblyAddress,
|
|
122
|
+
size: z.number().int().positive(),
|
|
109
123
|
});
|
|
124
|
+
/** A bit or byte channel of a generated device tree. */
|
|
125
|
+
const channelAddress = z.string().regex(/^%[IQ](?:X\d+\.[0-7]|B\d+)$/);
|
|
110
126
|
/**
|
|
111
127
|
* An EtherNet/IP scanner tree generated from EDS files. Each adapter's EDS is
|
|
112
128
|
* already reduced to its selected connection and raw byte assemblies, so every
|
|
113
129
|
* payload byte becomes one channel pinned at its region's address plus offset.
|
|
114
130
|
*/
|
|
115
131
|
export const deviceTreeSchema = z.strictObject({
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
132
|
+
ethernet: ethernetSchema.default({}),
|
|
133
|
+
devices: z
|
|
134
|
+
.array(
|
|
135
|
+
z.strictObject({
|
|
136
|
+
name: iecName,
|
|
137
|
+
eds: z.string().nonempty(),
|
|
138
|
+
address: z.ipv4().optional(),
|
|
139
|
+
rpiMicroseconds: z.number().int().positive().optional(),
|
|
140
|
+
inputs: processImageSchema.optional(),
|
|
141
|
+
outputs: processImageSchema.optional(),
|
|
142
|
+
// Registers written over Modbus TCP at the adapter's address, with their pinned channels.
|
|
143
|
+
modbus: z
|
|
144
|
+
.strictObject({
|
|
145
|
+
port: tcpPort,
|
|
146
|
+
registers: z.array(
|
|
147
|
+
z.strictObject({
|
|
148
|
+
name: iecName,
|
|
149
|
+
offset: z.number().int().nonnegative(),
|
|
150
|
+
value: z.string().regex(/^%QW\d+$/),
|
|
151
|
+
write: z.string().regex(/^%QX\d+\.[0-7]$/),
|
|
152
|
+
status: z.string().regex(/^%IB\d+$/),
|
|
153
|
+
requests: z.string().regex(/^%ID\d+$/),
|
|
154
|
+
}),
|
|
155
|
+
),
|
|
156
|
+
})
|
|
157
|
+
.optional(),
|
|
158
|
+
// Channel comments name the logical IO bound at a pinned byte or bit.
|
|
159
|
+
comments: z
|
|
160
|
+
.array(
|
|
161
|
+
z.strictObject({
|
|
162
|
+
address: channelAddress,
|
|
163
|
+
text: z.string().nonempty(),
|
|
164
|
+
}),
|
|
165
|
+
)
|
|
166
|
+
.default([]),
|
|
167
|
+
}),
|
|
168
|
+
)
|
|
169
|
+
.nonempty(),
|
|
170
|
+
// Variables mapped to pinned bit or byte channels, relative to the application.
|
|
171
|
+
mappings: z
|
|
172
|
+
.array(
|
|
173
|
+
z.strictObject({
|
|
174
|
+
address: channelAddress,
|
|
175
|
+
variable: z.string().nonempty(),
|
|
176
|
+
}),
|
|
177
|
+
)
|
|
178
|
+
.default([]),
|
|
163
179
|
});
|
|
164
180
|
export type DeviceTree = z.input<typeof deviceTreeSchema>;
|
|
181
|
+
/** A device or library version as CODESYS repositories spell it: four numbers. */
|
|
182
|
+
export const fourPartVersion = z.string().regex(/^\d+\.\d+\.\d+\.\d+$/);
|
|
165
183
|
/** A controller's device repository identity, as CODESYS shows it under Device > Information. */
|
|
166
184
|
export const controllerSchema = z.strictObject({
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
type: z.number().int().positive(),
|
|
186
|
+
id: z.string().regex(/^[0-9A-F]{4} [0-9A-F]{4}$/),
|
|
187
|
+
version: fourPartVersion,
|
|
170
188
|
});
|
|
171
189
|
export type Controller = z.infer<typeof controllerSchema>;
|
|
172
190
|
/** A controller the build image carries, named instead of spelled as its repository identity. */
|
|
173
|
-
export const controllerTargetSchema = controllerSchema
|
|
174
|
-
|
|
175
|
-
|
|
191
|
+
export const controllerTargetSchema = controllerSchema
|
|
192
|
+
.pick({ version: true })
|
|
193
|
+
.extend({
|
|
194
|
+
target: z.enum(["linux-sl", "virtual-linux-arm64-sl"]),
|
|
195
|
+
});
|
|
176
196
|
export const controllerDevices = {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
} satisfies Record<
|
|
197
|
+
"linux-sl": { type: 4102, id: "0000 0005" },
|
|
198
|
+
"virtual-linux-arm64-sl": { type: 4096, id: "0000 1008" },
|
|
199
|
+
} satisfies Record<
|
|
200
|
+
z.infer<typeof controllerTargetSchema>["target"],
|
|
201
|
+
Omit<Controller, "version">
|
|
202
|
+
>;
|
|
180
203
|
export const configSchema = z.strictObject({
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
204
|
+
io: z.record(z.string(), directIoBindingSchema).optional(),
|
|
205
|
+
deviceTree: deviceTreeSchema.optional(),
|
|
206
|
+
// Replaces the template's controller; the build image must carry its description.
|
|
207
|
+
controller: controllerSchema.optional(),
|
|
208
|
+
libraryReferences: z.array(z.string().nonempty()).default([]),
|
|
209
|
+
libraries: z
|
|
210
|
+
.array(
|
|
211
|
+
z.strictObject({
|
|
212
|
+
title: z.string(),
|
|
213
|
+
company: z.string().optional(),
|
|
214
|
+
version: z.string().optional(),
|
|
215
|
+
namespace: z.string().optional(),
|
|
216
|
+
path: pathSchema,
|
|
217
|
+
sha256: sha256Digest,
|
|
218
|
+
url: z.string().optional(),
|
|
219
|
+
}),
|
|
220
|
+
)
|
|
221
|
+
.optional(),
|
|
222
|
+
docker: z
|
|
223
|
+
.strictObject({
|
|
224
|
+
cpuSet: z
|
|
225
|
+
.string()
|
|
226
|
+
.regex(/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/)
|
|
227
|
+
.optional(),
|
|
228
|
+
})
|
|
229
|
+
.optional(),
|
|
230
|
+
template: pathSchema.optional(),
|
|
231
|
+
sourceDir: pathSchema.default("src"),
|
|
232
|
+
entry: pathSchema.default("src/Main.st"),
|
|
233
|
+
outDir: pathSchema.default("build"),
|
|
234
|
+
task: z.string().nonempty().default("MainTask"),
|
|
235
|
+
tasks: cyclicTasksSchema.optional(),
|
|
236
|
+
removeObjects: z.array(z.string().nonempty()).default([]),
|
|
237
|
+
symbols: z.boolean().default(false),
|
|
238
|
+
online: z
|
|
239
|
+
.strictObject({
|
|
240
|
+
network: pathSchema.default("bridge"),
|
|
241
|
+
gateway: z.strictObject({
|
|
242
|
+
host: pathSchema,
|
|
243
|
+
port: tcpPort.default(1217),
|
|
244
|
+
}),
|
|
245
|
+
device: z.strictObject({
|
|
246
|
+
host: pathSchema,
|
|
247
|
+
port: tcpPort.default(11740),
|
|
248
|
+
}),
|
|
249
|
+
credentials: z
|
|
250
|
+
.strictObject({
|
|
251
|
+
usernameEnv: envName,
|
|
252
|
+
passwordEnv: envName,
|
|
253
|
+
})
|
|
254
|
+
.optional(),
|
|
255
|
+
})
|
|
256
|
+
.optional(),
|
|
257
|
+
timeouts: z
|
|
258
|
+
.strictObject({
|
|
259
|
+
startup: positiveMilliseconds.default(codesysTimeouts.startup),
|
|
260
|
+
build: positiveMilliseconds.default(codesysTimeouts.build),
|
|
261
|
+
stop: positiveMilliseconds.default(codesysTimeouts.stop),
|
|
262
|
+
terminate: positiveMilliseconds.default(codesysTimeouts.terminate),
|
|
263
|
+
hostCommand: positiveMilliseconds.default(codesysTimeouts.hostCommand),
|
|
264
|
+
runtime: positiveMilliseconds.default(codesysTimeouts.runtime),
|
|
265
|
+
})
|
|
266
|
+
.prefault({}),
|
|
244
267
|
});
|
|
245
268
|
export type CodesysBuildConfig = z.input<typeof configSchema>;
|
package/src/build.ts
CHANGED
|
@@ -2,79 +2,89 @@ import { dirname, resolve } from "node:path";
|
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
3
|
import type { z } from "zod";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
configSchema,
|
|
6
|
+
containerCodesys,
|
|
7
|
+
localCodesysSchema,
|
|
8
|
+
type CodesysBuildConfig,
|
|
9
9
|
} from "./build-schema.ts";
|
|
10
10
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
commandArgumentSchema,
|
|
12
|
+
codesysTimeouts,
|
|
13
|
+
dockerImage,
|
|
14
|
+
containerCodesys,
|
|
15
|
+
cyclicTasksSchema,
|
|
16
|
+
directIoBindingSchema,
|
|
17
|
+
ethernetSchema,
|
|
18
|
+
deviceTreeSchema,
|
|
19
|
+
controllerSchema,
|
|
20
|
+
configSchema,
|
|
21
|
+
iecName,
|
|
22
|
+
sha256Digest,
|
|
23
|
+
tcpPort,
|
|
24
|
+
type CyclicTask,
|
|
25
|
+
type DeviceTree,
|
|
26
|
+
type Controller,
|
|
27
|
+
type CodesysBuildConfig,
|
|
25
28
|
} from "./build-schema.ts";
|
|
26
29
|
|
|
27
30
|
export type ResolvedConfig = z.output<typeof configSchema> & {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
template: string;
|
|
32
|
+
configFile: string;
|
|
33
|
+
codesys: z.output<typeof localCodesysSchema>;
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
/** Keep config authoring typed; validation and relative path resolution happen at load. */
|
|
34
|
-
export const defineBuildConfig = (
|
|
37
|
+
export const defineBuildConfig = (
|
|
38
|
+
config: CodesysBuildConfig,
|
|
39
|
+
): CodesysBuildConfig => config;
|
|
35
40
|
|
|
36
|
-
export const resolveConfig = (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
export const resolveConfig = (
|
|
42
|
+
input: unknown,
|
|
43
|
+
configFile: string,
|
|
44
|
+
): ResolvedConfig => {
|
|
45
|
+
const parsed = configSchema.parse(input);
|
|
46
|
+
const root = dirname(resolve(configFile));
|
|
47
|
+
const codesys = localCodesysSchema.parse(containerCodesys);
|
|
48
|
+
return {
|
|
49
|
+
...parsed,
|
|
50
|
+
docker: parsed.docker ?? {},
|
|
51
|
+
configFile: resolve(configFile),
|
|
52
|
+
template: parsed.template
|
|
53
|
+
? resolve(root, parsed.template)
|
|
54
|
+
: fileURLToPath(new URL("../templates/default.project", import.meta.url)),
|
|
55
|
+
removeObjects: parsed.template
|
|
56
|
+
? parsed.removeObjects
|
|
57
|
+
: ["PLC_PRG", ...parsed.removeObjects],
|
|
58
|
+
libraries: parsed.libraries?.map((library) => ({
|
|
59
|
+
...library,
|
|
60
|
+
path: resolve(root, library.path),
|
|
61
|
+
})),
|
|
62
|
+
sourceDir: resolve(root, parsed.sourceDir),
|
|
63
|
+
entry: resolve(root, parsed.entry),
|
|
64
|
+
outDir: resolve(root, parsed.outDir),
|
|
65
|
+
codesys: {
|
|
66
|
+
...codesys,
|
|
67
|
+
executable: resolve(root, codesys.executable),
|
|
68
|
+
wine: codesys.wine
|
|
69
|
+
? { ...codesys.wine, prefix: resolve(root, codesys.wine.prefix) }
|
|
70
|
+
: undefined,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
63
73
|
};
|
|
64
74
|
|
|
65
75
|
export const loadConfig = async (file = "tsplc.config.ts") => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
const path = resolve(file);
|
|
77
|
+
const module = (await import(pathToFileURL(path).href)) as {
|
|
78
|
+
config?: unknown;
|
|
79
|
+
default?: unknown;
|
|
80
|
+
};
|
|
81
|
+
if (module.default === undefined && module.config === undefined) {
|
|
82
|
+
throw new Error(`${path} must export a default config`);
|
|
83
|
+
}
|
|
84
|
+
const input = module.default ?? module.config;
|
|
85
|
+
if (input && typeof input === "object" && "build" in input) {
|
|
86
|
+
const { rawBuildConfig, tsplcConfigSchema } = await import("./schema.ts");
|
|
87
|
+
return resolveConfig(rawBuildConfig(tsplcConfigSchema.parse(input)), path);
|
|
88
|
+
}
|
|
89
|
+
return resolveConfig(input, path);
|
|
80
90
|
};
|