@polytric/openws-sdkgen 0.0.8 → 0.0.10

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
 
package/dist/main.cjs CHANGED
@@ -390,7 +390,6 @@ async function executePlan(ctx) {
390
390
  const { getData, template, output } = step;
391
391
  if (!getData || !template) continue;
392
392
  const data = getData();
393
- console.log(data);
394
393
  import_node_fs.default.mkdirSync(import_node_path2.default.dirname(output), { recursive: true });
395
394
  const rendered = renderTemplate(template, { ctx: data });
396
395
  import_node_fs.default.writeFileSync(output, await formatRenderedOutput(output, rendered));
@@ -514,7 +513,7 @@ function getNetworkOutputPaths(ctx) {
514
513
  const networkFolder = pascalCase(request.network);
515
514
  return [import_node_path3.default.join(request.outputPath, assemblyName, networkFolder)];
516
515
  }
517
- return [import_node_path3.default.join(request.outputPath, "src", kebabCase(request.network))];
516
+ return [import_node_path3.default.join(request.outputPath, kebabCase(spec.name), kebabCase(request.network))];
518
517
  }
519
518
 
520
519
  // src/main.ts
@@ -534,9 +533,7 @@ async function main() {
534
533
  }
535
534
  return ctx;
536
535
  }
537
- main().then((result) => {
538
- console.log(JSON.stringify(result, null, 2));
539
- }).catch((err) => {
536
+ main().catch((err) => {
540
537
  console.error(err);
541
538
  process.exit(1);
542
539
  });
package/dist/main.js CHANGED
@@ -367,7 +367,6 @@ async function executePlan(ctx) {
367
367
  const { getData, template, output } = step;
368
368
  if (!getData || !template) continue;
369
369
  const data = getData();
370
- console.log(data);
371
370
  fs.mkdirSync(path2.dirname(output), { recursive: true });
372
371
  const rendered = renderTemplate(template, { ctx: data });
373
372
  fs.writeFileSync(output, await formatRenderedOutput(output, rendered));
@@ -491,7 +490,7 @@ function getNetworkOutputPaths(ctx) {
491
490
  const networkFolder = pascalCase(request.network);
492
491
  return [path3.join(request.outputPath, assemblyName, networkFolder)];
493
492
  }
494
- return [path3.join(request.outputPath, "src", kebabCase(request.network))];
493
+ return [path3.join(request.outputPath, kebabCase(spec.name), kebabCase(request.network))];
495
494
  }
496
495
 
497
496
  // src/main.ts
@@ -511,9 +510,7 @@ async function main() {
511
510
  }
512
511
  return ctx;
513
512
  }
514
- main().then((result) => {
515
- console.log(JSON.stringify(result, null, 2));
516
- }).catch((err) => {
513
+ main().catch((err) => {
517
514
  console.error(err);
518
515
  process.exit(1);
519
516
  });
@@ -44,9 +44,8 @@ var import_node_url = require("url");
44
44
  var __dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
45
45
  var TEMPLATE_DIR = import_node_path.default.join(__dirname, "../templates/typescript");
46
46
  var SRC_TEMPLATE_DIR = import_node_path.default.join(TEMPLATE_DIR, "src");
47
- var CORE_TEMPLATE_DIR = import_node_path.default.join(SRC_TEMPLATE_DIR, "core");
48
- var ROLES_TEMPLATE_DIR = import_node_path.default.join(CORE_TEMPLATE_DIR, "roles");
49
- var MODELS_TEMPLATE_DIR = import_node_path.default.join(CORE_TEMPLATE_DIR, "models");
47
+ var ROLES_TEMPLATE_DIR = import_node_path.default.join(SRC_TEMPLATE_DIR, "roles");
48
+ var MODELS_TEMPLATE_DIR = import_node_path.default.join(SRC_TEMPLATE_DIR, "models");
50
49
  var SDK_TEMPLATE_DIR = import_node_path.default.join(SRC_TEMPLATE_DIR, "sdk");
51
50
  function pascalCase(str) {
52
51
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -65,49 +64,18 @@ function createPlan(ctx) {
65
64
  const language = Object.keys(request.target)[0];
66
65
  const isTypeScript = language === "typescript";
67
66
  const extension = isTypeScript ? "ts" : "js";
68
- const packageName = `@${kebabCase(ir.package.project)}/${kebabCase(ir.package.service)}-openws-sdk`;
69
- const plan = [
70
- {
71
- name: `${language} package manifest`,
72
- command: "render",
73
- getData: () => ({
74
- isTypeScript,
75
- packageName,
76
- description: ir.package.description,
77
- version: ir.package.version ?? "0.0.0",
78
- extension
79
- }),
80
- template: import_node_path.default.join(TEMPLATE_DIR, "package.json.ejs"),
81
- output: import_node_path.default.join(request.outputPath, "package.json")
82
- }
83
- ];
84
- if (isTypeScript) {
85
- plan.push(
86
- {
87
- name: `${language} tsconfig`,
88
- command: "render",
89
- getData: () => ({}),
90
- template: import_node_path.default.join(TEMPLATE_DIR, "tsconfig.json.ejs"),
91
- output: import_node_path.default.join(request.outputPath, "tsconfig.json")
92
- },
93
- {
94
- name: `${language} tsup config`,
95
- command: "render",
96
- getData: () => ({}),
97
- template: import_node_path.default.join(TEMPLATE_DIR, "tsup.config.ts.ejs"),
98
- output: import_node_path.default.join(request.outputPath, "tsup.config.ts")
99
- }
100
- );
101
- }
102
- const networkExports = [];
67
+ const serviceFileName = kebabCase(ir.package.service);
68
+ const networkFileName = kebabCase(request.network);
69
+ const packageOutputPath = import_node_path.default.join(request.outputPath, serviceFileName, networkFileName);
70
+ const packageName = `@${kebabCase(ir.package.project)}/${serviceFileName}-${networkFileName}-openws-sdk`;
71
+ const plan = [];
103
72
  const selectedNetworkSpec = spec.networks[request.network];
104
73
  if (!selectedNetworkSpec) {
105
74
  throw new Error(`Network "${request.network}" does not exist in the spec`);
106
75
  }
107
76
  for (const [networkName, networkSpec] of [[request.network, selectedNetworkSpec]]) {
108
- const networkFileName = kebabCase(networkName);
109
- const networkOutputPath = import_node_path.default.join(request.outputPath, "src", networkFileName);
110
- const sdkOutputPath = import_node_path.default.join(request.outputPath, "src", "sdk");
77
+ const sourceOutputPath = import_node_path.default.join(packageOutputPath, "src");
78
+ const sdkOutputPath = import_node_path.default.join(sourceOutputPath, "sdk");
111
79
  const allRoles = Object.values(networkSpec.roles).map(toRoleInfo);
112
80
  const rolesByName = new Map(allRoles.map((role) => [role.roleName, role]));
113
81
  const hostRoles = request.hostRoles.map((hostRole) => {
@@ -120,10 +88,42 @@ function createPlan(ctx) {
120
88
  return role;
121
89
  });
122
90
  const modelScopes = buildModelScopes(buildSpecModels(networkSpec));
123
- networkExports.push({
124
- exportName: camelCase(networkName),
125
- fileName: networkFileName
126
- });
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
+ }
127
127
  plan.push({
128
128
  name: `${language} network ${networkName}`,
129
129
  command: "render",
@@ -137,19 +137,8 @@ function createPlan(ctx) {
137
137
  allRoles,
138
138
  extension
139
139
  }),
140
- template: import_node_path.default.join(CORE_TEMPLATE_DIR, "network.ts.ejs"),
141
- output: import_node_path.default.join(networkOutputPath, `network.${extension}`)
142
- });
143
- plan.push({
144
- name: `${language} network exports ${networkName}`,
145
- command: "render",
146
- getData: () => ({
147
- isTypeScript,
148
- extension,
149
- modelScopes
150
- }),
151
- template: import_node_path.default.join(CORE_TEMPLATE_DIR, "index.ts.ejs"),
152
- output: import_node_path.default.join(networkOutputPath, `index.${extension}`)
140
+ template: import_node_path.default.join(SRC_TEMPLATE_DIR, "network.ts.ejs"),
141
+ output: import_node_path.default.join(sourceOutputPath, `network.${extension}`)
153
142
  });
154
143
  const roleMessagesByName = /* @__PURE__ */ new Map();
155
144
  for (const role of allRoles) {
@@ -174,7 +163,7 @@ function createPlan(ctx) {
174
163
  ...role
175
164
  }),
176
165
  template: import_node_path.default.join(ROLES_TEMPLATE_DIR, "role.ts.ejs"),
177
- output: import_node_path.default.join(networkOutputPath, "roles", `${role.fileName}.${extension}`)
166
+ output: import_node_path.default.join(sourceOutputPath, "roles", `${role.fileName}.${extension}`)
178
167
  });
179
168
  }
180
169
  plan.push({
@@ -186,7 +175,7 @@ function createPlan(ctx) {
186
175
  roles: allRoles
187
176
  }),
188
177
  template: import_node_path.default.join(ROLES_TEMPLATE_DIR, "index.ts.ejs"),
189
- output: import_node_path.default.join(networkOutputPath, "roles", `index.${extension}`)
178
+ output: import_node_path.default.join(sourceOutputPath, "roles", `index.${extension}`)
190
179
  });
191
180
  for (const modelScope of modelScopes) {
192
181
  plan.push({
@@ -199,7 +188,7 @@ function createPlan(ctx) {
199
188
  }),
200
189
  template: import_node_path.default.join(MODELS_TEMPLATE_DIR, "index.ts.ejs"),
201
190
  output: import_node_path.default.join(
202
- networkOutputPath,
191
+ sourceOutputPath,
203
192
  "models",
204
193
  modelScope.fileName,
205
194
  `index.${extension}`
@@ -215,7 +204,7 @@ function createPlan(ctx) {
215
204
  }),
216
205
  template: import_node_path.default.join(MODELS_TEMPLATE_DIR, "model.ts.ejs"),
217
206
  output: import_node_path.default.join(
218
- networkOutputPath,
207
+ sourceOutputPath,
219
208
  "models",
220
209
  modelScope.fileName,
221
210
  `${model.fileName}.${extension}`
@@ -253,7 +242,6 @@ function createPlan(ctx) {
253
242
  extension,
254
243
  handlers: roleHandlers,
255
244
  networkName,
256
- networkFileName,
257
245
  networkDescription: networkSpec.description,
258
246
  networkVersion: networkSpec.version,
259
247
  remoteRoles,
@@ -274,18 +262,18 @@ function createPlan(ctx) {
274
262
  template: import_node_path.default.join(SDK_TEMPLATE_DIR, "index.ts.ejs"),
275
263
  output: import_node_path.default.join(sdkOutputPath, `index.${extension}`)
276
264
  });
265
+ plan.push({
266
+ name: `${language} package exports`,
267
+ command: "render",
268
+ getData: () => ({
269
+ isTypeScript,
270
+ extension,
271
+ modelScopes
272
+ }),
273
+ template: import_node_path.default.join(SRC_TEMPLATE_DIR, "index.ts.ejs"),
274
+ output: import_node_path.default.join(sourceOutputPath, `index.${extension}`)
275
+ });
277
276
  }
278
- plan.push({
279
- name: `${language} package exports`,
280
- command: "render",
281
- getData: () => ({
282
- isTypeScript,
283
- extension,
284
- networkExports
285
- }),
286
- template: import_node_path.default.join(SRC_TEMPLATE_DIR, "index.ts.ejs"),
287
- output: import_node_path.default.join(request.outputPath, "src", `index.${extension}`)
288
- });
289
277
  return {
290
278
  ...ctx,
291
279
  plan
@@ -319,6 +307,33 @@ function buildModelScopes(models) {
319
307
  }
320
308
  return [...scopes.values()];
321
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
+ }
322
337
  function toRoleInfo(role) {
323
338
  const className = pascalCase(role.name);
324
339
  const fileName = kebabCase(role.name);
@@ -4,9 +4,8 @@ import { fileURLToPath } from "url";
4
4
  var __dirname = path.dirname(fileURLToPath(import.meta.url));
5
5
  var TEMPLATE_DIR = path.join(__dirname, "../templates/typescript");
6
6
  var SRC_TEMPLATE_DIR = path.join(TEMPLATE_DIR, "src");
7
- var CORE_TEMPLATE_DIR = path.join(SRC_TEMPLATE_DIR, "core");
8
- var ROLES_TEMPLATE_DIR = path.join(CORE_TEMPLATE_DIR, "roles");
9
- var MODELS_TEMPLATE_DIR = path.join(CORE_TEMPLATE_DIR, "models");
7
+ var ROLES_TEMPLATE_DIR = path.join(SRC_TEMPLATE_DIR, "roles");
8
+ var MODELS_TEMPLATE_DIR = path.join(SRC_TEMPLATE_DIR, "models");
10
9
  var SDK_TEMPLATE_DIR = path.join(SRC_TEMPLATE_DIR, "sdk");
11
10
  function pascalCase(str) {
12
11
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -25,49 +24,18 @@ function createPlan(ctx) {
25
24
  const language = Object.keys(request.target)[0];
26
25
  const isTypeScript = language === "typescript";
27
26
  const extension = isTypeScript ? "ts" : "js";
28
- const packageName = `@${kebabCase(ir.package.project)}/${kebabCase(ir.package.service)}-openws-sdk`;
29
- const plan = [
30
- {
31
- name: `${language} package manifest`,
32
- command: "render",
33
- getData: () => ({
34
- isTypeScript,
35
- packageName,
36
- description: ir.package.description,
37
- version: ir.package.version ?? "0.0.0",
38
- extension
39
- }),
40
- template: path.join(TEMPLATE_DIR, "package.json.ejs"),
41
- output: path.join(request.outputPath, "package.json")
42
- }
43
- ];
44
- if (isTypeScript) {
45
- plan.push(
46
- {
47
- name: `${language} tsconfig`,
48
- command: "render",
49
- getData: () => ({}),
50
- template: path.join(TEMPLATE_DIR, "tsconfig.json.ejs"),
51
- output: path.join(request.outputPath, "tsconfig.json")
52
- },
53
- {
54
- name: `${language} tsup config`,
55
- command: "render",
56
- getData: () => ({}),
57
- template: path.join(TEMPLATE_DIR, "tsup.config.ts.ejs"),
58
- output: path.join(request.outputPath, "tsup.config.ts")
59
- }
60
- );
61
- }
62
- const networkExports = [];
27
+ const serviceFileName = kebabCase(ir.package.service);
28
+ const networkFileName = kebabCase(request.network);
29
+ const packageOutputPath = path.join(request.outputPath, serviceFileName, networkFileName);
30
+ const packageName = `@${kebabCase(ir.package.project)}/${serviceFileName}-${networkFileName}-openws-sdk`;
31
+ const plan = [];
63
32
  const selectedNetworkSpec = spec.networks[request.network];
64
33
  if (!selectedNetworkSpec) {
65
34
  throw new Error(`Network "${request.network}" does not exist in the spec`);
66
35
  }
67
36
  for (const [networkName, networkSpec] of [[request.network, selectedNetworkSpec]]) {
68
- const networkFileName = kebabCase(networkName);
69
- const networkOutputPath = path.join(request.outputPath, "src", networkFileName);
70
- const sdkOutputPath = path.join(request.outputPath, "src", "sdk");
37
+ const sourceOutputPath = path.join(packageOutputPath, "src");
38
+ const sdkOutputPath = path.join(sourceOutputPath, "sdk");
71
39
  const allRoles = Object.values(networkSpec.roles).map(toRoleInfo);
72
40
  const rolesByName = new Map(allRoles.map((role) => [role.roleName, role]));
73
41
  const hostRoles = request.hostRoles.map((hostRole) => {
@@ -80,10 +48,42 @@ function createPlan(ctx) {
80
48
  return role;
81
49
  });
82
50
  const modelScopes = buildModelScopes(buildSpecModels(networkSpec));
83
- networkExports.push({
84
- exportName: camelCase(networkName),
85
- fileName: networkFileName
86
- });
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
+ }
87
87
  plan.push({
88
88
  name: `${language} network ${networkName}`,
89
89
  command: "render",
@@ -97,19 +97,8 @@ function createPlan(ctx) {
97
97
  allRoles,
98
98
  extension
99
99
  }),
100
- template: path.join(CORE_TEMPLATE_DIR, "network.ts.ejs"),
101
- output: path.join(networkOutputPath, `network.${extension}`)
102
- });
103
- plan.push({
104
- name: `${language} network exports ${networkName}`,
105
- command: "render",
106
- getData: () => ({
107
- isTypeScript,
108
- extension,
109
- modelScopes
110
- }),
111
- template: path.join(CORE_TEMPLATE_DIR, "index.ts.ejs"),
112
- output: path.join(networkOutputPath, `index.${extension}`)
100
+ template: path.join(SRC_TEMPLATE_DIR, "network.ts.ejs"),
101
+ output: path.join(sourceOutputPath, `network.${extension}`)
113
102
  });
114
103
  const roleMessagesByName = /* @__PURE__ */ new Map();
115
104
  for (const role of allRoles) {
@@ -134,7 +123,7 @@ function createPlan(ctx) {
134
123
  ...role
135
124
  }),
136
125
  template: path.join(ROLES_TEMPLATE_DIR, "role.ts.ejs"),
137
- output: path.join(networkOutputPath, "roles", `${role.fileName}.${extension}`)
126
+ output: path.join(sourceOutputPath, "roles", `${role.fileName}.${extension}`)
138
127
  });
139
128
  }
140
129
  plan.push({
@@ -146,7 +135,7 @@ function createPlan(ctx) {
146
135
  roles: allRoles
147
136
  }),
148
137
  template: path.join(ROLES_TEMPLATE_DIR, "index.ts.ejs"),
149
- output: path.join(networkOutputPath, "roles", `index.${extension}`)
138
+ output: path.join(sourceOutputPath, "roles", `index.${extension}`)
150
139
  });
151
140
  for (const modelScope of modelScopes) {
152
141
  plan.push({
@@ -159,7 +148,7 @@ function createPlan(ctx) {
159
148
  }),
160
149
  template: path.join(MODELS_TEMPLATE_DIR, "index.ts.ejs"),
161
150
  output: path.join(
162
- networkOutputPath,
151
+ sourceOutputPath,
163
152
  "models",
164
153
  modelScope.fileName,
165
154
  `index.${extension}`
@@ -175,7 +164,7 @@ function createPlan(ctx) {
175
164
  }),
176
165
  template: path.join(MODELS_TEMPLATE_DIR, "model.ts.ejs"),
177
166
  output: path.join(
178
- networkOutputPath,
167
+ sourceOutputPath,
179
168
  "models",
180
169
  modelScope.fileName,
181
170
  `${model.fileName}.${extension}`
@@ -213,7 +202,6 @@ function createPlan(ctx) {
213
202
  extension,
214
203
  handlers: roleHandlers,
215
204
  networkName,
216
- networkFileName,
217
205
  networkDescription: networkSpec.description,
218
206
  networkVersion: networkSpec.version,
219
207
  remoteRoles,
@@ -234,18 +222,18 @@ function createPlan(ctx) {
234
222
  template: path.join(SDK_TEMPLATE_DIR, "index.ts.ejs"),
235
223
  output: path.join(sdkOutputPath, `index.${extension}`)
236
224
  });
225
+ plan.push({
226
+ name: `${language} package exports`,
227
+ command: "render",
228
+ getData: () => ({
229
+ isTypeScript,
230
+ extension,
231
+ modelScopes
232
+ }),
233
+ template: path.join(SRC_TEMPLATE_DIR, "index.ts.ejs"),
234
+ output: path.join(sourceOutputPath, `index.${extension}`)
235
+ });
237
236
  }
238
- plan.push({
239
- name: `${language} package exports`,
240
- command: "render",
241
- getData: () => ({
242
- isTypeScript,
243
- extension,
244
- networkExports
245
- }),
246
- template: path.join(SRC_TEMPLATE_DIR, "index.ts.ejs"),
247
- output: path.join(request.outputPath, "src", `index.${extension}`)
248
- });
249
237
  return {
250
238
  ...ctx,
251
239
  plan
@@ -279,6 +267,33 @@ function buildModelScopes(models) {
279
267
  }
280
268
  return [...scopes.values()];
281
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
+ }
282
297
  function toRoleInfo(role) {
283
298
  const className = pascalCase(role.name);
284
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
26
  "@polytric/openws": "^0.0.4"
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,4 +1,7 @@
1
- <% for (const network of ctx.networkExports) { -%>
2
- export * as <%= network.exportName %> from './<%= network.fileName %><%= ctx.isTypeScript ? '' : '/index.js' %>'
1
+ export * from './network<%= ctx.isTypeScript ? '' : '.js' %>'
2
+ export * from './roles<%= ctx.isTypeScript ? '' : '/index.js' %>'
3
+ export * as roles from './roles<%= ctx.isTypeScript ? '' : '/index.js' %>'
4
+ <% for (const modelScope of ctx.modelScopes) { -%>
5
+ export * as <%= modelScope.varName %>Models from './models/<%= modelScope.fileName %><%= ctx.isTypeScript ? '' : '/index.js' %>'
3
6
  <% } -%>
4
7
  export * as sdk from './sdk<%= ctx.isTypeScript ? '' : '/index.js' %>'
@@ -1,7 +1,6 @@
1
- <% const networkDir = ctx.networkFileName -%>
2
- <% const networkImport = ctx.isTypeScript ? `../${networkDir}/network` : `../${networkDir}/network.js` -%>
3
- <% const modelImportPath = ctx.isTypeScript ? `../${networkDir}/models/${ctx.fileName}` : `../${networkDir}/models/${ctx.fileName}/index.js` -%>
4
- <% const rolesImport = ctx.isTypeScript ? `../${networkDir}/roles` : `../${networkDir}/roles/index.js` -%>
1
+ <% const networkImport = ctx.isTypeScript ? '../network' : '../network.js' -%>
2
+ <% const modelImportPath = ctx.isTypeScript ? `../models/${ctx.fileName}` : `../models/${ctx.fileName}/index.js` -%>
3
+ <% const rolesImport = ctx.isTypeScript ? '../roles' : '../roles/index.js' -%>
5
4
  <% if (ctx.isTypeScript) { -%>
6
5
  import * as WS from '@polytric/openws/class'
7
6
  import * as Fluent from '@polytric/openws/fluent'
@@ -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.8",
3
+ "version": "0.0.10",
4
4
  "description": "OpenWS SDK generator CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -37,7 +37,7 @@
37
37
  "ajv": "^8.17.1",
38
38
  "ejs": "^3.1.10",
39
39
  "prettier": "^3.7.4",
40
- "yargs": "^18.0.0",
40
+ "yargs": "^17.7.2",
41
41
  "@polytric/openws-spec": "0.0.4"
42
42
  },
43
43
  "devDependencies": {
@@ -56,6 +56,7 @@
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"
@@ -1,6 +0,0 @@
1
- export * from './network<%= ctx.isTypeScript ? '' : '.js' %>'
2
- export * from './roles<%= ctx.isTypeScript ? '' : '/index.js' %>'
3
- export * as roles from './roles<%= ctx.isTypeScript ? '' : '/index.js' %>'
4
- <% for (const modelScope of ctx.modelScopes) { -%>
5
- export * as <%= modelScope.varName %>Models from './models/<%= modelScope.fileName %><%= ctx.isTypeScript ? '' : '/index.js' %>'
6
- <% } -%>