@polytric/openws-sdkgen 0.0.9 → 0.0.11

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 CHANGED
@@ -52,6 +52,13 @@ The CLI exposes the following options:
52
52
  The generator is wired for:
53
53
 
54
54
  - C# (Unity) with `newtonsoft` serialization templates.
55
+ - JavaScript (Node/browser) packages.
56
+ - TypeScript (Node/browser) packages with declaration output.
57
+
58
+ Generated JavaScript and TypeScript packages include a `tsup` build config and a
59
+ `prepublishOnly` build script. The published package exports ESM (`dist/*.js`) and
60
+ CJS (`dist/*.cjs`) entry points for the root SDK, network metadata, roles, SDK
61
+ adaptors, and payload models.
55
62
 
56
63
  Additional targets are configured through build plans in `tooling/sdkgen/src/plans` and can be expanded as needed.
57
64
 
@@ -68,39 +68,7 @@ function createPlan(ctx) {
68
68
  const networkFileName = kebabCase(request.network);
69
69
  const packageOutputPath = import_node_path.default.join(request.outputPath, serviceFileName, networkFileName);
70
70
  const packageName = `@${kebabCase(ir.package.project)}/${serviceFileName}-${networkFileName}-openws-sdk`;
71
- const plan = [
72
- {
73
- name: `${language} package manifest`,
74
- command: "render",
75
- getData: () => ({
76
- isTypeScript,
77
- packageName,
78
- description: ir.package.description,
79
- version: ir.package.version ?? "0.0.1",
80
- extension
81
- }),
82
- template: import_node_path.default.join(TEMPLATE_DIR, "package.json.ejs"),
83
- output: import_node_path.default.join(packageOutputPath, "package.json")
84
- }
85
- ];
86
- if (isTypeScript) {
87
- plan.push(
88
- {
89
- name: `${language} tsconfig`,
90
- command: "render",
91
- getData: () => ({}),
92
- template: import_node_path.default.join(TEMPLATE_DIR, "tsconfig.json.ejs"),
93
- output: import_node_path.default.join(packageOutputPath, "tsconfig.json")
94
- },
95
- {
96
- name: `${language} tsup config`,
97
- command: "render",
98
- getData: () => ({}),
99
- template: import_node_path.default.join(TEMPLATE_DIR, "tsup.config.ts.ejs"),
100
- output: import_node_path.default.join(packageOutputPath, "tsup.config.ts")
101
- }
102
- );
103
- }
71
+ const plan = [];
104
72
  const selectedNetworkSpec = spec.networks[request.network];
105
73
  if (!selectedNetworkSpec) {
106
74
  throw new Error(`Network "${request.network}" does not exist in the spec`);
@@ -120,6 +88,42 @@ function createPlan(ctx) {
120
88
  return role;
121
89
  });
122
90
  const modelScopes = buildModelScopes(buildSpecModels(networkSpec));
91
+ const packageEntries = buildPackageEntries(extension, allRoles, hostRoles, modelScopes);
92
+ const packageExports = buildPackageExports(packageEntries);
93
+ plan.push(
94
+ {
95
+ name: `${language} package manifest`,
96
+ command: "render",
97
+ getData: () => ({
98
+ isTypeScript,
99
+ packageName,
100
+ description: ir.package.description,
101
+ version: ir.package.version ?? "0.0.1",
102
+ packageExports
103
+ }),
104
+ template: import_node_path.default.join(TEMPLATE_DIR, "package.json.ejs"),
105
+ output: import_node_path.default.join(packageOutputPath, "package.json")
106
+ },
107
+ {
108
+ name: `${language} tsup config`,
109
+ command: "render",
110
+ getData: () => ({
111
+ isTypeScript,
112
+ packageEntries
113
+ }),
114
+ template: import_node_path.default.join(TEMPLATE_DIR, "tsup.config.ts.ejs"),
115
+ output: import_node_path.default.join(packageOutputPath, "tsup.config.ts")
116
+ }
117
+ );
118
+ if (isTypeScript) {
119
+ plan.push({
120
+ name: `${language} tsconfig`,
121
+ command: "render",
122
+ getData: () => ({}),
123
+ template: import_node_path.default.join(TEMPLATE_DIR, "tsconfig.json.ejs"),
124
+ output: import_node_path.default.join(packageOutputPath, "tsconfig.json")
125
+ });
126
+ }
123
127
  plan.push({
124
128
  name: `${language} network ${networkName}`,
125
129
  command: "render",
@@ -303,6 +307,33 @@ function buildModelScopes(models) {
303
307
  }
304
308
  return [...scopes.values()];
305
309
  }
310
+ function buildPackageEntries(extension, allRoles, hostRoles, modelScopes) {
311
+ const entries = {
312
+ index: `src/index.${extension}`,
313
+ network: `src/network.${extension}`,
314
+ "roles/index": `src/roles/index.${extension}`,
315
+ "sdk/index": `src/sdk/index.${extension}`
316
+ };
317
+ for (const role of allRoles) {
318
+ entries[`roles/${role.fileName}`] = `src/roles/${role.fileName}.${extension}`;
319
+ }
320
+ for (const role of hostRoles) {
321
+ entries[`sdk/${role.fileName}`] = `src/sdk/${role.fileName}.${extension}`;
322
+ }
323
+ for (const modelScope of modelScopes) {
324
+ entries[`models/${modelScope.fileName}/index`] = `src/models/${modelScope.fileName}/index.${extension}`;
325
+ for (const model of modelScope.models) {
326
+ entries[`models/${modelScope.fileName}/${model.fileName}`] = `src/models/${modelScope.fileName}/${model.fileName}.${extension}`;
327
+ }
328
+ }
329
+ return entries;
330
+ }
331
+ function buildPackageExports(packageEntries) {
332
+ return Object.keys(packageEntries).map((entryName) => ({
333
+ subpath: entryName === "index" ? "." : `./${entryName.replace(/\/index$/, "")}`,
334
+ outputPath: `./dist/${entryName}`
335
+ }));
336
+ }
306
337
  function toRoleInfo(role) {
307
338
  const className = pascalCase(role.name);
308
339
  const fileName = kebabCase(role.name);
@@ -28,39 +28,7 @@ function createPlan(ctx) {
28
28
  const networkFileName = kebabCase(request.network);
29
29
  const packageOutputPath = path.join(request.outputPath, serviceFileName, networkFileName);
30
30
  const packageName = `@${kebabCase(ir.package.project)}/${serviceFileName}-${networkFileName}-openws-sdk`;
31
- const plan = [
32
- {
33
- name: `${language} package manifest`,
34
- command: "render",
35
- getData: () => ({
36
- isTypeScript,
37
- packageName,
38
- description: ir.package.description,
39
- version: ir.package.version ?? "0.0.1",
40
- extension
41
- }),
42
- template: path.join(TEMPLATE_DIR, "package.json.ejs"),
43
- output: path.join(packageOutputPath, "package.json")
44
- }
45
- ];
46
- if (isTypeScript) {
47
- plan.push(
48
- {
49
- name: `${language} tsconfig`,
50
- command: "render",
51
- getData: () => ({}),
52
- template: path.join(TEMPLATE_DIR, "tsconfig.json.ejs"),
53
- output: path.join(packageOutputPath, "tsconfig.json")
54
- },
55
- {
56
- name: `${language} tsup config`,
57
- command: "render",
58
- getData: () => ({}),
59
- template: path.join(TEMPLATE_DIR, "tsup.config.ts.ejs"),
60
- output: path.join(packageOutputPath, "tsup.config.ts")
61
- }
62
- );
63
- }
31
+ const plan = [];
64
32
  const selectedNetworkSpec = spec.networks[request.network];
65
33
  if (!selectedNetworkSpec) {
66
34
  throw new Error(`Network "${request.network}" does not exist in the spec`);
@@ -80,6 +48,42 @@ function createPlan(ctx) {
80
48
  return role;
81
49
  });
82
50
  const modelScopes = buildModelScopes(buildSpecModels(networkSpec));
51
+ const packageEntries = buildPackageEntries(extension, allRoles, hostRoles, modelScopes);
52
+ const packageExports = buildPackageExports(packageEntries);
53
+ plan.push(
54
+ {
55
+ name: `${language} package manifest`,
56
+ command: "render",
57
+ getData: () => ({
58
+ isTypeScript,
59
+ packageName,
60
+ description: ir.package.description,
61
+ version: ir.package.version ?? "0.0.1",
62
+ packageExports
63
+ }),
64
+ template: path.join(TEMPLATE_DIR, "package.json.ejs"),
65
+ output: path.join(packageOutputPath, "package.json")
66
+ },
67
+ {
68
+ name: `${language} tsup config`,
69
+ command: "render",
70
+ getData: () => ({
71
+ isTypeScript,
72
+ packageEntries
73
+ }),
74
+ template: path.join(TEMPLATE_DIR, "tsup.config.ts.ejs"),
75
+ output: path.join(packageOutputPath, "tsup.config.ts")
76
+ }
77
+ );
78
+ if (isTypeScript) {
79
+ plan.push({
80
+ name: `${language} tsconfig`,
81
+ command: "render",
82
+ getData: () => ({}),
83
+ template: path.join(TEMPLATE_DIR, "tsconfig.json.ejs"),
84
+ output: path.join(packageOutputPath, "tsconfig.json")
85
+ });
86
+ }
83
87
  plan.push({
84
88
  name: `${language} network ${networkName}`,
85
89
  command: "render",
@@ -263,6 +267,33 @@ function buildModelScopes(models) {
263
267
  }
264
268
  return [...scopes.values()];
265
269
  }
270
+ function buildPackageEntries(extension, allRoles, hostRoles, modelScopes) {
271
+ const entries = {
272
+ index: `src/index.${extension}`,
273
+ network: `src/network.${extension}`,
274
+ "roles/index": `src/roles/index.${extension}`,
275
+ "sdk/index": `src/sdk/index.${extension}`
276
+ };
277
+ for (const role of allRoles) {
278
+ entries[`roles/${role.fileName}`] = `src/roles/${role.fileName}.${extension}`;
279
+ }
280
+ for (const role of hostRoles) {
281
+ entries[`sdk/${role.fileName}`] = `src/sdk/${role.fileName}.${extension}`;
282
+ }
283
+ for (const modelScope of modelScopes) {
284
+ entries[`models/${modelScope.fileName}/index`] = `src/models/${modelScope.fileName}/index.${extension}`;
285
+ for (const model of modelScope.models) {
286
+ entries[`models/${modelScope.fileName}/${model.fileName}`] = `src/models/${modelScope.fileName}/${model.fileName}.${extension}`;
287
+ }
288
+ }
289
+ return entries;
290
+ }
291
+ function buildPackageExports(packageEntries) {
292
+ return Object.keys(packageEntries).map((entryName) => ({
293
+ subpath: entryName === "index" ? "." : `./${entryName.replace(/\/index$/, "")}`,
294
+ outputPath: `./dist/${entryName}`
295
+ }));
296
+ }
266
297
  function toRoleInfo(role) {
267
298
  const className = pascalCase(role.name);
268
299
  const fileName = kebabCase(role.name);
@@ -3,39 +3,35 @@
3
3
  "version": <%- JSON.stringify(ctx.version) %>,
4
4
  "description": <%- JSON.stringify(ctx.description ?? '') %>,
5
5
  "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
6
8
  <% if (ctx.isTypeScript) { -%>
7
- "main": "./dist/index.js",
8
9
  "types": "./dist/index.d.ts",
10
+ <% } -%>
9
11
  "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
13
- }
12
+ <% for (let i = 0; i < ctx.packageExports.length; i++) { -%>
13
+ <% const packageExport = ctx.packageExports[i] -%>
14
+ <%- JSON.stringify(packageExport.subpath) %>: {
15
+ <% if (ctx.isTypeScript) { -%>
16
+ "types": <%- JSON.stringify(`${packageExport.outputPath}.d.ts`) %>,
17
+ <% } -%>
18
+ "import": <%- JSON.stringify(`${packageExport.outputPath}.js`) %>,
19
+ "require": <%- JSON.stringify(`${packageExport.outputPath}.cjs`) %>
20
+ },
21
+ <% } -%>
22
+ "./package.json": "./package.json"
14
23
  },
15
- "files": [
16
- "dist"
17
- ],
24
+ "files": ["dist"],
18
25
  "dependencies": {
19
- "@polytric/openws": "^0.0.4"
26
+ "@polytric/openws": "^0.0.5"
20
27
  },
21
28
  "scripts": {
22
29
  "build": "tsup",
23
- "typecheck": "tsc --noEmit"
30
+ "prepublishOnly": "npm run build"<% if (ctx.isTypeScript) { %>,
31
+ "typecheck": "tsc --noEmit"<% } %>
24
32
  },
25
33
  "devDependencies": {
26
34
  "tsup": "^8.5.1",
27
35
  "typescript": "^5.9.3"
28
36
  }
29
- <% } else { -%>
30
- "main": "./src/index.js",
31
- "exports": {
32
- ".": "./src/index.js"
33
- },
34
- "files": [
35
- "src"
36
- ],
37
- "dependencies": {
38
- "@polytric/openws": "^0.0.4"
39
- }
40
- <% } -%>
41
37
  }
@@ -1,10 +1,13 @@
1
1
  import { defineConfig } from 'tsup'
2
2
 
3
3
  export default defineConfig({
4
- entry: ['src/index.ts'],
5
- format: ['esm'],
6
- dts: true,
4
+ entry: <%- JSON.stringify(ctx.packageEntries, null, 4) %>,
5
+ format: ['esm', 'cjs'],
6
+ dts: <%= ctx.isTypeScript ? 'true' : 'false' %>,
7
7
  clean: true,
8
8
  target: 'es2022',
9
9
  outDir: 'dist',
10
+ outExtension({ format }) {
11
+ return { js: format === 'cjs' ? '.cjs' : '.js' }
12
+ },
10
13
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polytric/openws-sdkgen",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "OpenWS SDK generator CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -50,12 +50,13 @@
50
50
  "tsx": "^4.21.0",
51
51
  "typescript": "^5.9.3",
52
52
  "ws": "^8.18.3",
53
- "@polytric/openws": "0.0.4"
53
+ "@polytric/openws": "0.0.5"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "tsup",
57
57
  "typecheck": "tsc --noEmit",
58
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:javascript:node": "node dist/main.cjs --spec ./test/spec.json --out ./generated/javascript/node --project Example --network core --hostRole client --language javascript --environment node",
59
60
  "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",
60
61
  "test:typescript:server": "tsx ./test/typescript/server.ts",
61
62
  "test:typescript:client": "tsx ./test/typescript/client.ts"