@polytric/openws-sdkgen 0.0.7 → 0.0.8
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/main.cjs +78 -10
- package/dist/main.js +78 -10
- package/dist/plans/dotnet.d.cts +1 -1
- package/dist/plans/dotnet.d.ts +1 -1
- package/dist/plans/typescript.cjs +14 -2
- package/dist/plans/typescript.d.cts +1 -1
- package/dist/plans/typescript.d.ts +1 -1
- package/dist/plans/typescript.js +14 -2
- package/dist/templates/typescript/src/core/roles/role.ts.ejs +10 -20
- package/dist/{types-BdZPs123.d.cts → types-Bn36WAIG.d.cts} +2 -0
- package/dist/{types-BdZPs123.d.ts → types-Bn36WAIG.d.ts} +2 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ openws-sdkgen \
|
|
|
29
29
|
--spec ./openws-spec.json \
|
|
30
30
|
--out ./generated \
|
|
31
31
|
--project MyCompany \
|
|
32
|
-
--
|
|
32
|
+
--network core \
|
|
33
33
|
--hostRole server \
|
|
34
34
|
--language csharp \
|
|
35
35
|
--environment unity
|
|
@@ -40,7 +40,7 @@ The CLI exposes the following options:
|
|
|
40
40
|
- `--spec` (string): Path to the OpenWS spec JSON file.
|
|
41
41
|
- `--out` (string): Output directory for generated code.
|
|
42
42
|
- `--project` (string): Project/namespace prefix for generated code.
|
|
43
|
-
- `--
|
|
43
|
+
- `--network` (string): Network name to generate.
|
|
44
44
|
- `--hostRole` (string): Participant role name that represents the host side.
|
|
45
45
|
- `--language` (string): Target language (`csharp`, `javascript`, or `typescript`).
|
|
46
46
|
- `--environment` (string|array): Target environment (`unity`, `node`, `browser`).
|
package/dist/main.cjs
CHANGED
|
@@ -148,7 +148,11 @@ function buildIr(ctx) {
|
|
|
148
148
|
const { request, spec } = ctx;
|
|
149
149
|
if (!request) throw new Error("request is required");
|
|
150
150
|
if (!spec) throw new Error("spec is required");
|
|
151
|
-
const { hostRoles } = request;
|
|
151
|
+
const { hostRoles, network } = request;
|
|
152
|
+
const selectedNetworkSpec = spec.networks[network];
|
|
153
|
+
if (!selectedNetworkSpec) {
|
|
154
|
+
throw new Error(`Network "${network}" does not exist in the spec`);
|
|
155
|
+
}
|
|
152
156
|
const ir = {
|
|
153
157
|
package: {
|
|
154
158
|
project: request.project,
|
|
@@ -158,8 +162,16 @@ function buildIr(ctx) {
|
|
|
158
162
|
},
|
|
159
163
|
networks: []
|
|
160
164
|
};
|
|
161
|
-
for (const [networkName, networkSpec] of
|
|
162
|
-
const hostRoleSpecs = hostRoles.map((hostRole) =>
|
|
165
|
+
for (const [networkName, networkSpec] of [[network, selectedNetworkSpec]]) {
|
|
166
|
+
const hostRoleSpecs = hostRoles.map((hostRole) => {
|
|
167
|
+
const hostRoleSpec = networkSpec.roles[hostRole];
|
|
168
|
+
if (!hostRoleSpec) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`Host role "${hostRole}" does not exist in network "${networkName}"`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return hostRoleSpec;
|
|
174
|
+
});
|
|
163
175
|
const otherRoleSpecs = {};
|
|
164
176
|
for (const [roleName, roleSpec] of Object.entries(networkSpec.roles)) {
|
|
165
177
|
if (!hostRoles.includes(roleName)) {
|
|
@@ -285,6 +297,7 @@ var validateBuildRequest = import_schema2.default.obj({
|
|
|
285
297
|
specPath: import_schema2.default.str,
|
|
286
298
|
outputPath: import_schema2.default.str,
|
|
287
299
|
project: import_schema2.default.str,
|
|
300
|
+
network: import_schema2.default.str,
|
|
288
301
|
hostRoles: import_schema2.default.arr(import_schema2.default.str),
|
|
289
302
|
target: import_schema2.default.obj({
|
|
290
303
|
csharp: import_schema2.default.obj({
|
|
@@ -308,6 +321,7 @@ function buildRequest(ctx) {
|
|
|
308
321
|
specPath: import_node_path.default.join(import_node_process.default.cwd(), rawInput.spec),
|
|
309
322
|
outputPath: import_node_path.default.join(import_node_process.default.cwd(), rawInput.out),
|
|
310
323
|
project: rawInput.project,
|
|
324
|
+
network: toCamelCase(rawInput.network),
|
|
311
325
|
hostRoles: rawInput.hostRole.map((r) => toCamelCase(r)),
|
|
312
326
|
target: {
|
|
313
327
|
[rawInput.language]: {
|
|
@@ -327,7 +341,22 @@ function buildRequest(ctx) {
|
|
|
327
341
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
328
342
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
329
343
|
var import_ejs = __toESM(require("ejs"), 1);
|
|
344
|
+
var prettier = __toESM(require("prettier"), 1);
|
|
330
345
|
var rendererCache = {};
|
|
346
|
+
var parserByExtension = {
|
|
347
|
+
".js": "babel",
|
|
348
|
+
".json": "json",
|
|
349
|
+
".ts": "typescript"
|
|
350
|
+
};
|
|
351
|
+
var fallbackFormatOptions = {
|
|
352
|
+
semi: false,
|
|
353
|
+
singleQuote: true,
|
|
354
|
+
tabWidth: 4,
|
|
355
|
+
trailingComma: "es5",
|
|
356
|
+
printWidth: 100,
|
|
357
|
+
arrowParens: "avoid",
|
|
358
|
+
endOfLine: "lf"
|
|
359
|
+
};
|
|
331
360
|
function renderTemplate(templatePath, data) {
|
|
332
361
|
if (rendererCache[templatePath]) {
|
|
333
362
|
return rendererCache[templatePath](data);
|
|
@@ -337,7 +366,17 @@ function renderTemplate(templatePath, data) {
|
|
|
337
366
|
rendererCache[templatePath] = renderer;
|
|
338
367
|
return renderer(data);
|
|
339
368
|
}
|
|
340
|
-
function
|
|
369
|
+
async function formatRenderedOutput(output, content) {
|
|
370
|
+
const parser = parserByExtension[import_node_path2.default.extname(output)];
|
|
371
|
+
if (!parser) return content;
|
|
372
|
+
const config = await prettier.resolveConfig(output, { editorconfig: true });
|
|
373
|
+
return prettier.format(content, {
|
|
374
|
+
...fallbackFormatOptions,
|
|
375
|
+
...config,
|
|
376
|
+
parser
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async function executePlan(ctx) {
|
|
341
380
|
const { plan } = ctx;
|
|
342
381
|
if (!plan) throw new Error("plan is required");
|
|
343
382
|
for (const step of plan) {
|
|
@@ -353,7 +392,8 @@ function executePlan(ctx) {
|
|
|
353
392
|
const data = getData();
|
|
354
393
|
console.log(data);
|
|
355
394
|
import_node_fs.default.mkdirSync(import_node_path2.default.dirname(output), { recursive: true });
|
|
356
|
-
|
|
395
|
+
const rendered = renderTemplate(template, { ctx: data });
|
|
396
|
+
import_node_fs.default.writeFileSync(output, await formatRenderedOutput(output, rendered));
|
|
357
397
|
break;
|
|
358
398
|
}
|
|
359
399
|
}
|
|
@@ -411,6 +451,10 @@ function parseInput(ctx) {
|
|
|
411
451
|
type: "string",
|
|
412
452
|
description: "The project name",
|
|
413
453
|
demandOption: true
|
|
454
|
+
}).option("network", {
|
|
455
|
+
type: "string",
|
|
456
|
+
description: "The network to be generated",
|
|
457
|
+
demandOption: true
|
|
414
458
|
}).option("hostRole", {
|
|
415
459
|
type: "array",
|
|
416
460
|
string: true,
|
|
@@ -440,21 +484,45 @@ function parseInput(ctx) {
|
|
|
440
484
|
|
|
441
485
|
// src/prepare-output.ts
|
|
442
486
|
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
487
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
488
|
+
function pascalCase(str) {
|
|
489
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
490
|
+
}
|
|
491
|
+
function kebabCase(str) {
|
|
492
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-|-$/g, "").toLowerCase();
|
|
493
|
+
}
|
|
443
494
|
function prepareOutput(ctx) {
|
|
444
|
-
const { request } = ctx;
|
|
495
|
+
const { request, spec } = ctx;
|
|
445
496
|
if (!request) throw new Error("request is required");
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
497
|
+
if (!spec) throw new Error("spec is required");
|
|
498
|
+
if (!spec.networks[request.network]) {
|
|
499
|
+
throw new Error(`Network "${request.network}" does not exist in the spec`);
|
|
500
|
+
}
|
|
501
|
+
const cleanupPaths = getNetworkOutputPaths(ctx);
|
|
502
|
+
for (const cleanupPath of cleanupPaths) {
|
|
503
|
+
import_node_fs3.default.rmSync(cleanupPath, { recursive: true, force: true });
|
|
504
|
+
}
|
|
505
|
+
import_node_fs3.default.mkdirSync(request.outputPath, { recursive: true });
|
|
449
506
|
return ctx;
|
|
450
507
|
}
|
|
508
|
+
function getNetworkOutputPaths(ctx) {
|
|
509
|
+
const { request, spec } = ctx;
|
|
510
|
+
if (!request) throw new Error("request is required");
|
|
511
|
+
if (!spec) throw new Error("spec is required");
|
|
512
|
+
if (request.target.csharp) {
|
|
513
|
+
const assemblyName = `${pascalCase(request.project)}.${pascalCase(spec.name)}.Sdk`;
|
|
514
|
+
const networkFolder = pascalCase(request.network);
|
|
515
|
+
return [import_node_path3.default.join(request.outputPath, assemblyName, networkFolder)];
|
|
516
|
+
}
|
|
517
|
+
return [import_node_path3.default.join(request.outputPath, "src", kebabCase(request.network))];
|
|
518
|
+
}
|
|
451
519
|
|
|
452
520
|
// src/main.ts
|
|
453
521
|
var Pipeline = [
|
|
454
522
|
parseInput,
|
|
455
523
|
buildRequest,
|
|
456
|
-
prepareOutput,
|
|
457
524
|
loadSpec,
|
|
525
|
+
prepareOutput,
|
|
458
526
|
buildIr,
|
|
459
527
|
dispatchBuildPlan,
|
|
460
528
|
executePlan
|
package/dist/main.js
CHANGED
|
@@ -125,7 +125,11 @@ function buildIr(ctx) {
|
|
|
125
125
|
const { request, spec } = ctx;
|
|
126
126
|
if (!request) throw new Error("request is required");
|
|
127
127
|
if (!spec) throw new Error("spec is required");
|
|
128
|
-
const { hostRoles } = request;
|
|
128
|
+
const { hostRoles, network } = request;
|
|
129
|
+
const selectedNetworkSpec = spec.networks[network];
|
|
130
|
+
if (!selectedNetworkSpec) {
|
|
131
|
+
throw new Error(`Network "${network}" does not exist in the spec`);
|
|
132
|
+
}
|
|
129
133
|
const ir = {
|
|
130
134
|
package: {
|
|
131
135
|
project: request.project,
|
|
@@ -135,8 +139,16 @@ function buildIr(ctx) {
|
|
|
135
139
|
},
|
|
136
140
|
networks: []
|
|
137
141
|
};
|
|
138
|
-
for (const [networkName, networkSpec] of
|
|
139
|
-
const hostRoleSpecs = hostRoles.map((hostRole) =>
|
|
142
|
+
for (const [networkName, networkSpec] of [[network, selectedNetworkSpec]]) {
|
|
143
|
+
const hostRoleSpecs = hostRoles.map((hostRole) => {
|
|
144
|
+
const hostRoleSpec = networkSpec.roles[hostRole];
|
|
145
|
+
if (!hostRoleSpec) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Host role "${hostRole}" does not exist in network "${networkName}"`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return hostRoleSpec;
|
|
151
|
+
});
|
|
140
152
|
const otherRoleSpecs = {};
|
|
141
153
|
for (const [roleName, roleSpec] of Object.entries(networkSpec.roles)) {
|
|
142
154
|
if (!hostRoles.includes(roleName)) {
|
|
@@ -262,6 +274,7 @@ var validateBuildRequest = S2.obj({
|
|
|
262
274
|
specPath: S2.str,
|
|
263
275
|
outputPath: S2.str,
|
|
264
276
|
project: S2.str,
|
|
277
|
+
network: S2.str,
|
|
265
278
|
hostRoles: S2.arr(S2.str),
|
|
266
279
|
target: S2.obj({
|
|
267
280
|
csharp: S2.obj({
|
|
@@ -285,6 +298,7 @@ function buildRequest(ctx) {
|
|
|
285
298
|
specPath: path.join(process2.cwd(), rawInput.spec),
|
|
286
299
|
outputPath: path.join(process2.cwd(), rawInput.out),
|
|
287
300
|
project: rawInput.project,
|
|
301
|
+
network: toCamelCase(rawInput.network),
|
|
288
302
|
hostRoles: rawInput.hostRole.map((r) => toCamelCase(r)),
|
|
289
303
|
target: {
|
|
290
304
|
[rawInput.language]: {
|
|
@@ -304,7 +318,22 @@ function buildRequest(ctx) {
|
|
|
304
318
|
import fs from "fs";
|
|
305
319
|
import path2 from "path";
|
|
306
320
|
import ejs from "ejs";
|
|
321
|
+
import * as prettier from "prettier";
|
|
307
322
|
var rendererCache = {};
|
|
323
|
+
var parserByExtension = {
|
|
324
|
+
".js": "babel",
|
|
325
|
+
".json": "json",
|
|
326
|
+
".ts": "typescript"
|
|
327
|
+
};
|
|
328
|
+
var fallbackFormatOptions = {
|
|
329
|
+
semi: false,
|
|
330
|
+
singleQuote: true,
|
|
331
|
+
tabWidth: 4,
|
|
332
|
+
trailingComma: "es5",
|
|
333
|
+
printWidth: 100,
|
|
334
|
+
arrowParens: "avoid",
|
|
335
|
+
endOfLine: "lf"
|
|
336
|
+
};
|
|
308
337
|
function renderTemplate(templatePath, data) {
|
|
309
338
|
if (rendererCache[templatePath]) {
|
|
310
339
|
return rendererCache[templatePath](data);
|
|
@@ -314,7 +343,17 @@ function renderTemplate(templatePath, data) {
|
|
|
314
343
|
rendererCache[templatePath] = renderer;
|
|
315
344
|
return renderer(data);
|
|
316
345
|
}
|
|
317
|
-
function
|
|
346
|
+
async function formatRenderedOutput(output, content) {
|
|
347
|
+
const parser = parserByExtension[path2.extname(output)];
|
|
348
|
+
if (!parser) return content;
|
|
349
|
+
const config = await prettier.resolveConfig(output, { editorconfig: true });
|
|
350
|
+
return prettier.format(content, {
|
|
351
|
+
...fallbackFormatOptions,
|
|
352
|
+
...config,
|
|
353
|
+
parser
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
async function executePlan(ctx) {
|
|
318
357
|
const { plan } = ctx;
|
|
319
358
|
if (!plan) throw new Error("plan is required");
|
|
320
359
|
for (const step of plan) {
|
|
@@ -330,7 +369,8 @@ function executePlan(ctx) {
|
|
|
330
369
|
const data = getData();
|
|
331
370
|
console.log(data);
|
|
332
371
|
fs.mkdirSync(path2.dirname(output), { recursive: true });
|
|
333
|
-
|
|
372
|
+
const rendered = renderTemplate(template, { ctx: data });
|
|
373
|
+
fs.writeFileSync(output, await formatRenderedOutput(output, rendered));
|
|
334
374
|
break;
|
|
335
375
|
}
|
|
336
376
|
}
|
|
@@ -388,6 +428,10 @@ function parseInput(ctx) {
|
|
|
388
428
|
type: "string",
|
|
389
429
|
description: "The project name",
|
|
390
430
|
demandOption: true
|
|
431
|
+
}).option("network", {
|
|
432
|
+
type: "string",
|
|
433
|
+
description: "The network to be generated",
|
|
434
|
+
demandOption: true
|
|
391
435
|
}).option("hostRole", {
|
|
392
436
|
type: "array",
|
|
393
437
|
string: true,
|
|
@@ -417,21 +461,45 @@ function parseInput(ctx) {
|
|
|
417
461
|
|
|
418
462
|
// src/prepare-output.ts
|
|
419
463
|
import fs3 from "fs";
|
|
464
|
+
import path3 from "path";
|
|
465
|
+
function pascalCase(str) {
|
|
466
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
467
|
+
}
|
|
468
|
+
function kebabCase(str) {
|
|
469
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-|-$/g, "").toLowerCase();
|
|
470
|
+
}
|
|
420
471
|
function prepareOutput(ctx) {
|
|
421
|
-
const { request } = ctx;
|
|
472
|
+
const { request, spec } = ctx;
|
|
422
473
|
if (!request) throw new Error("request is required");
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
474
|
+
if (!spec) throw new Error("spec is required");
|
|
475
|
+
if (!spec.networks[request.network]) {
|
|
476
|
+
throw new Error(`Network "${request.network}" does not exist in the spec`);
|
|
477
|
+
}
|
|
478
|
+
const cleanupPaths = getNetworkOutputPaths(ctx);
|
|
479
|
+
for (const cleanupPath of cleanupPaths) {
|
|
480
|
+
fs3.rmSync(cleanupPath, { recursive: true, force: true });
|
|
481
|
+
}
|
|
482
|
+
fs3.mkdirSync(request.outputPath, { recursive: true });
|
|
426
483
|
return ctx;
|
|
427
484
|
}
|
|
485
|
+
function getNetworkOutputPaths(ctx) {
|
|
486
|
+
const { request, spec } = ctx;
|
|
487
|
+
if (!request) throw new Error("request is required");
|
|
488
|
+
if (!spec) throw new Error("spec is required");
|
|
489
|
+
if (request.target.csharp) {
|
|
490
|
+
const assemblyName = `${pascalCase(request.project)}.${pascalCase(spec.name)}.Sdk`;
|
|
491
|
+
const networkFolder = pascalCase(request.network);
|
|
492
|
+
return [path3.join(request.outputPath, assemblyName, networkFolder)];
|
|
493
|
+
}
|
|
494
|
+
return [path3.join(request.outputPath, "src", kebabCase(request.network))];
|
|
495
|
+
}
|
|
428
496
|
|
|
429
497
|
// src/main.ts
|
|
430
498
|
var Pipeline = [
|
|
431
499
|
parseInput,
|
|
432
500
|
buildRequest,
|
|
433
|
-
prepareOutput,
|
|
434
501
|
loadSpec,
|
|
502
|
+
prepareOutput,
|
|
435
503
|
buildIr,
|
|
436
504
|
dispatchBuildPlan,
|
|
437
505
|
executePlan
|
package/dist/plans/dotnet.d.cts
CHANGED
package/dist/plans/dotnet.d.ts
CHANGED
|
@@ -100,13 +100,25 @@ function createPlan(ctx) {
|
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
const networkExports = [];
|
|
103
|
-
|
|
103
|
+
const selectedNetworkSpec = spec.networks[request.network];
|
|
104
|
+
if (!selectedNetworkSpec) {
|
|
105
|
+
throw new Error(`Network "${request.network}" does not exist in the spec`);
|
|
106
|
+
}
|
|
107
|
+
for (const [networkName, networkSpec] of [[request.network, selectedNetworkSpec]]) {
|
|
104
108
|
const networkFileName = kebabCase(networkName);
|
|
105
109
|
const networkOutputPath = import_node_path.default.join(request.outputPath, "src", networkFileName);
|
|
106
110
|
const sdkOutputPath = import_node_path.default.join(request.outputPath, "src", "sdk");
|
|
107
111
|
const allRoles = Object.values(networkSpec.roles).map(toRoleInfo);
|
|
108
112
|
const rolesByName = new Map(allRoles.map((role) => [role.roleName, role]));
|
|
109
|
-
const hostRoles =
|
|
113
|
+
const hostRoles = request.hostRoles.map((hostRole) => {
|
|
114
|
+
const role = rolesByName.get(hostRole);
|
|
115
|
+
if (!role) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Host role "${hostRole}" does not exist in network "${networkName}"`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return role;
|
|
121
|
+
});
|
|
110
122
|
const modelScopes = buildModelScopes(buildSpecModels(networkSpec));
|
|
111
123
|
networkExports.push({
|
|
112
124
|
exportName: camelCase(networkName),
|
package/dist/plans/typescript.js
CHANGED
|
@@ -60,13 +60,25 @@ function createPlan(ctx) {
|
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
const networkExports = [];
|
|
63
|
-
|
|
63
|
+
const selectedNetworkSpec = spec.networks[request.network];
|
|
64
|
+
if (!selectedNetworkSpec) {
|
|
65
|
+
throw new Error(`Network "${request.network}" does not exist in the spec`);
|
|
66
|
+
}
|
|
67
|
+
for (const [networkName, networkSpec] of [[request.network, selectedNetworkSpec]]) {
|
|
64
68
|
const networkFileName = kebabCase(networkName);
|
|
65
69
|
const networkOutputPath = path.join(request.outputPath, "src", networkFileName);
|
|
66
70
|
const sdkOutputPath = path.join(request.outputPath, "src", "sdk");
|
|
67
71
|
const allRoles = Object.values(networkSpec.roles).map(toRoleInfo);
|
|
68
72
|
const rolesByName = new Map(allRoles.map((role) => [role.roleName, role]));
|
|
69
|
-
const hostRoles =
|
|
73
|
+
const hostRoles = request.hostRoles.map((hostRole) => {
|
|
74
|
+
const role = rolesByName.get(hostRole);
|
|
75
|
+
if (!role) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Host role "${hostRole}" does not exist in network "${networkName}"`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return role;
|
|
81
|
+
});
|
|
70
82
|
const modelScopes = buildModelScopes(buildSpecModels(networkSpec));
|
|
71
83
|
networkExports.push({
|
|
72
84
|
exportName: camelCase(networkName),
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
<% const modelImportPath = ctx.isTypeScript ? `../models/${ctx.fileName}` : `../models/${ctx.fileName}/index.js` -%>
|
|
2
2
|
<% if (ctx.isTypeScript) { -%>
|
|
3
3
|
<% if (ctx.messages.length > 0) { -%>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<%= message.payloadType %>,
|
|
7
|
-
<%= message.payloadType %>Init,
|
|
8
|
-
<% } -%>
|
|
9
|
-
} from '<%= modelImportPath %>'
|
|
4
|
+
<% const payloadImports = ctx.messages.flatMap(message => [message.payloadType, `${message.payloadType}Init`]) -%>
|
|
5
|
+
import type { <%= payloadImports.join(', ') %> } from '<%= modelImportPath %>'
|
|
10
6
|
<% } -%>
|
|
11
7
|
<% const importedPeerRoles = new Map(); for (const message of ctx.messages) { for (const fromRole of message.fromRoles ?? []) { if (fromRole.roleName !== ctx.roleName) importedPeerRoles.set(fromRole.roleName, fromRole) } } -%>
|
|
12
8
|
<% if (importedPeerRoles.size > 0) { -%>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
<%= fromRole.roleClassName %>,
|
|
16
|
-
<% } -%>
|
|
17
|
-
} from './index'
|
|
9
|
+
<% const peerRoleImports = [...importedPeerRoles.values()].map(fromRole => fromRole.roleClassName) -%>
|
|
10
|
+
import { <%= peerRoleImports.join(', ') %> } from './index'
|
|
18
11
|
<% } -%>
|
|
19
12
|
|
|
20
13
|
export interface <%= ctx.apiName %> {
|
|
@@ -30,12 +23,12 @@ export class <%= ctx.roleClassName %> {
|
|
|
30
23
|
messages: {
|
|
31
24
|
<% for (const message of ctx.messages) { -%>
|
|
32
25
|
<%= message.messageName %>: {
|
|
33
|
-
payload: <%- JSON.stringify(message.schema
|
|
26
|
+
payload: <%- JSON.stringify(message.schema) %>,
|
|
34
27
|
},
|
|
35
28
|
<% } -%>
|
|
36
29
|
},
|
|
37
30
|
}
|
|
38
|
-
static readonly endpoints = <%- JSON.stringify(ctx.endpoints
|
|
31
|
+
static readonly endpoints = <%- JSON.stringify(ctx.endpoints) %>
|
|
39
32
|
}
|
|
40
33
|
|
|
41
34
|
export class <%= ctx.hostRoleClassName %> {
|
|
@@ -60,11 +53,8 @@ export class <%= ctx.hostRoleClassName %> {
|
|
|
60
53
|
<% } else { -%>
|
|
61
54
|
<% const importedPeerRoles = new Map(); for (const message of ctx.messages) { for (const fromRole of message.fromRoles ?? []) { if (fromRole.roleName !== ctx.roleName) importedPeerRoles.set(fromRole.roleName, fromRole) } } -%>
|
|
62
55
|
<% if (importedPeerRoles.size > 0) { -%>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
<%= fromRole.roleClassName %>,
|
|
66
|
-
<% } -%>
|
|
67
|
-
} from './index.js'
|
|
56
|
+
<% const peerRoleImports = [...importedPeerRoles.values()].map(fromRole => fromRole.roleClassName) -%>
|
|
57
|
+
import { <%= peerRoleImports.join(', ') %> } from './index.js'
|
|
68
58
|
<% } -%>
|
|
69
59
|
|
|
70
60
|
export class <%= ctx.roleClassName %> {
|
|
@@ -74,12 +64,12 @@ export class <%= ctx.roleClassName %> {
|
|
|
74
64
|
messages: {
|
|
75
65
|
<% for (const message of ctx.messages) { -%>
|
|
76
66
|
<%= message.messageName %>: {
|
|
77
|
-
payload: <%- JSON.stringify(message.schema
|
|
67
|
+
payload: <%- JSON.stringify(message.schema) %>,
|
|
78
68
|
},
|
|
79
69
|
<% } -%>
|
|
80
70
|
},
|
|
81
71
|
}
|
|
82
|
-
static endpoints = <%- JSON.stringify(ctx.endpoints
|
|
72
|
+
static endpoints = <%- JSON.stringify(ctx.endpoints) %>
|
|
83
73
|
}
|
|
84
74
|
|
|
85
75
|
export class <%= ctx.hostRoleClassName %> {
|
|
@@ -12,6 +12,7 @@ interface RawInput {
|
|
|
12
12
|
spec: string;
|
|
13
13
|
out: string;
|
|
14
14
|
project: string;
|
|
15
|
+
network: string;
|
|
15
16
|
hostRole: string[];
|
|
16
17
|
language: 'csharp' | 'javascript' | 'typescript';
|
|
17
18
|
environment: 'unity' | 'node' | 'browser';
|
|
@@ -21,6 +22,7 @@ interface BuildRequest {
|
|
|
21
22
|
specPath: string;
|
|
22
23
|
outputPath: string;
|
|
23
24
|
project: string;
|
|
25
|
+
network: string;
|
|
24
26
|
hostRoles: string[];
|
|
25
27
|
target: {
|
|
26
28
|
csharp?: {
|
|
@@ -12,6 +12,7 @@ interface RawInput {
|
|
|
12
12
|
spec: string;
|
|
13
13
|
out: string;
|
|
14
14
|
project: string;
|
|
15
|
+
network: string;
|
|
15
16
|
hostRole: string[];
|
|
16
17
|
language: 'csharp' | 'javascript' | 'typescript';
|
|
17
18
|
environment: 'unity' | 'node' | 'browser';
|
|
@@ -21,6 +22,7 @@ interface BuildRequest {
|
|
|
21
22
|
specPath: string;
|
|
22
23
|
outputPath: string;
|
|
23
24
|
project: string;
|
|
25
|
+
network: string;
|
|
24
26
|
hostRoles: string[];
|
|
25
27
|
target: {
|
|
26
28
|
csharp?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polytric/openws-sdkgen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "OpenWS SDK generator CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@pocketgems/schema": "^0.1.3",
|
|
37
37
|
"ajv": "^8.17.1",
|
|
38
38
|
"ejs": "^3.1.10",
|
|
39
|
+
"prettier": "^3.7.4",
|
|
39
40
|
"yargs": "^18.0.0",
|
|
40
41
|
"@polytric/openws-spec": "0.0.4"
|
|
41
42
|
},
|
|
@@ -54,8 +55,8 @@
|
|
|
54
55
|
"scripts": {
|
|
55
56
|
"build": "tsup",
|
|
56
57
|
"typecheck": "tsc --noEmit",
|
|
57
|
-
"test:csharp:unity": "node dist/main.cjs --spec ./test/spec.json --out ./generated/dotnet/unity --project Example --hostRole client --language csharp --environment unity",
|
|
58
|
-
"test:typescript:node": "node dist/main.cjs --spec ./test/spec.json --out ./generated/typescript/node --project Example --hostRole client --language typescript --environment node",
|
|
58
|
+
"test:csharp:unity": "node dist/main.cjs --spec ./test/spec.json --out ./generated/dotnet/unity --project Example --network core --hostRole client --language csharp --environment unity",
|
|
59
|
+
"test:typescript:node": "node dist/main.cjs --spec ./test/spec.json --out ./generated/typescript/node --project Example --network core --hostRole client --language typescript --environment node",
|
|
59
60
|
"test:typescript:server": "tsx ./test/typescript/server.ts",
|
|
60
61
|
"test:typescript:client": "tsx ./test/typescript/client.ts"
|
|
61
62
|
}
|