@accelbyte/codegen 0.0.0-dev-20260407233405 → 0.0.0-dev-20260408102041

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
@@ -10,20 +10,20 @@ AccelByte Code Generator is a CLI tool that facilitates creating an AccelByte Ty
10
10
  This codegen build a CLI called `accelbyte-codegen` that will be used to generate code from given config.
11
11
 
12
12
  ```
13
- Commands:
14
- accelbyte-codegen download-swaggers Download swaggers JSON files
15
- accelbyte-codegen generate-code Generate code based on downloaded swagger files
13
+ Commands:
14
+ accelbyte-codegen download-swaggers Download swagger JSON files
15
+ accelbyte-codegen generate-code Generate code from downloaded swagger files
16
16
 
17
17
  Options:
18
- --version Show version number [boolean]
19
- --config Path to the config file with backend service URLs. [string] [required]
20
- --swaggersOutput Directory to save the downloaded Swagger JSON files. [string] [required]
21
- --output Directory for the generated code. Required when using the generate-code command. [string]
22
- --help Show help [boolean]
23
- --skipReactQuery Disable React Query code generation. [boolean]
24
- --snippetOutput Generate only code snippets. [boolean]
25
- --snippetOnly Directory for the generated code snippets. Required when generating snippets. [boolean]
26
- --webSocketSchema Path to the WebSocket schema file (schema.json). [string]
18
+ --version Show version number [boolean]
19
+ --config Path to the config file with backend service URLs. [string] [required]
20
+ --swaggersOutput Directory to save the downloaded Swagger JSON files. [string] [required]
21
+ --output Directory for the generated code. Required for generate-code. [string]
22
+ --help Show help [boolean]
23
+ --skipReactQuery Disable React Query code generation. [boolean]
24
+ --snippetOnly Generate only code snippets. [boolean]
25
+ --snippetOutput Directory for the generated code snippets. [string]
26
+ --webSocketSchema Path to the WebSocket schema file (schema.json). [string]
27
27
  ```
28
28
 
29
29
  ### Config file
@@ -140,7 +140,50 @@ export default {
140
140
  unstable_overrideAsAny: {
141
141
  ProtobufAny: true,
142
142
  SomeOther: (schema) => schema.properties?.['@type'] !== undefined
143
- }
143
+ },
144
+
145
+ // Output each swagger set into a subfolder named after its service name.
146
+ // Default: false
147
+ unstable_splitOutputByServiceName: true
148
+ } satisfies CodegenConfigOptions
149
+ ```
150
+
151
+ ### `unstable_splitOutputByServiceName`
152
+
153
+ By default, all swagger sets in `swaggers.json` are generated into the same `--output` directory. When this option is enabled, each set is placed in a subfolder named after its service name (the first element of each inner array).
154
+
155
+ Given a config like:
156
+
157
+ ```json
158
+ [
159
+ ["iam", "iam", "iam.json", "https://example.com/iam/apidocs/api.json"],
160
+ ["platform", "platform", "platform.json", "https://example.com/platform/swagger.json"]
161
+ ]
162
+ ```
163
+
164
+ The output becomes:
165
+
166
+ ```
167
+ sdk/
168
+ iam/
169
+ generated-admin/
170
+ generated-public/
171
+ generated-definitions/
172
+ Iam.ts
173
+ platform/
174
+ generated-admin/
175
+ generated-public/
176
+ generated-definitions/
177
+ Platform.ts
178
+ all-imports.ts ← re-exports from all subfolders
179
+ all-query-imports.ts
180
+ ```
181
+
182
+ Enable via `abcodegen.config.ts`:
183
+
184
+ ```typescript
185
+ export default {
186
+ unstable_splitOutputByServiceName: true
144
187
  } satisfies CodegenConfigOptions
145
188
  ```
146
189
 
@@ -17,6 +17,15 @@ interface CodegenConfigOptions {
17
17
  * @default `basePath` from the swagger spec
18
18
  */
19
19
  basePath?: string;
20
+ /**
21
+ * When enabled, each swagger set is generated into a subfolder named after its service name
22
+ * inside the output directory, instead of all sets sharing the same root output folder.
23
+ *
24
+ * If swaggers.json contains [["a", "b", "c", "d"]], then the service name is the "a".
25
+ *
26
+ * @default false
27
+ */
28
+ unstable_splitOutputByServiceName?: boolean;
20
29
  }
21
30
 
22
31
  export type { CodegenConfigOptions };
@@ -17,6 +17,15 @@ interface CodegenConfigOptions {
17
17
  * @default `basePath` from the swagger spec
18
18
  */
19
19
  basePath?: string;
20
+ /**
21
+ * When enabled, each swagger set is generated into a subfolder named after its service name
22
+ * inside the output directory, instead of all sets sharing the same root output folder.
23
+ *
24
+ * If swaggers.json contains [["a", "b", "c", "d"]], then the service name is the "a".
25
+ *
26
+ * @default false
27
+ */
28
+ unstable_splitOutputByServiceName?: boolean;
20
29
  }
21
30
 
22
31
  export type { CodegenConfigOptions };
@@ -117,6 +117,9 @@ var CodegenConfig = class _CodegenConfig {
117
117
  static getOverrideAsAny() {
118
118
  return _CodegenConfig.config.unstable_overrideAsAny;
119
119
  }
120
+ static splitOutputByServiceName() {
121
+ return _CodegenConfig.config.unstable_splitOutputByServiceName ?? false;
122
+ }
120
123
  /** Reset to defaults — used for testing */
121
124
  static reset() {
122
125
  _CodegenConfig.config = {};
@@ -1907,8 +1910,11 @@ var CodeGenerator = class _CodeGenerator {
1907
1910
  const queryImportsSet = /* @__PURE__ */ new Set();
1908
1911
  const apiInfo = { ...api.info, "x-version": api["x-version"]?.version };
1909
1912
  console.log("----------\nGenerating API:", { title: apiInfo.title, version: apiInfo.version });
1913
+ const isSplitByService = CodegenConfig.splitOutputByServiceName();
1914
+ const srcFolder = isSplitByService ? import_path4.default.join(CliParser.getOutputPath(), serviceName) : CliParser.getOutputPath();
1915
+ const targetSrcFolder = `${CliParser.getOutputPath()}/`;
1910
1916
  if (!CliParser.isGenerateSnippetOnly()) {
1911
- ParserUtils.writeXVersion(_CodeGenerator.srcFolder(), api["x-version"], api.info);
1917
+ ParserUtils.writeXVersion(srcFolder, api["x-version"], api.info);
1912
1918
  }
1913
1919
  const parsedInformation = await SwaggerReaderHelpers.parseAllEndpoints({ api, sdkName, serviceName });
1914
1920
  if (CliParser.getSnippetOutputPath()) {
@@ -1934,11 +1940,10 @@ var CodeGenerator = class _CodeGenerator {
1934
1940
  console.log("\nSuccessfully generate SDK snippets only\n----------\n\n");
1935
1941
  return;
1936
1942
  }
1937
- const DIST_DIR = (isAdmin) => `${_CodeGenerator.getGeneratedFolder(isAdmin)}`;
1943
+ const DIST_DIR = (isAdmin) => import_path4.default.join(srcFolder, isAdmin ? "generated-admin" : "generated-public");
1938
1944
  const DIST_DIR_ENDPOINTS = (isAdmin) => import_path4.default.join(DIST_DIR(isAdmin), "endpoints");
1939
1945
  const DIST_DIR_QUERIES = (isAdmin) => import_path4.default.join(DIST_DIR(isAdmin), "queries");
1940
- const DIST_DEFINITION_DIR = import_path4.default.join(_CodeGenerator.srcFolder(), "generated-definitions");
1941
- const targetSrcFolder = `${_CodeGenerator.srcFolder()}/`;
1946
+ const DIST_DEFINITION_DIR = import_path4.default.join(srcFolder, "generated-definitions");
1942
1947
  _CodeGenerator.prepareDirs(DIST_DEFINITION_DIR, DIST_DIR, DIST_DIR_ENDPOINTS, DIST_DIR_QUERIES);
1943
1948
  const mainApiList = [];
1944
1949
  const generatedDefinitions = [];
@@ -1993,9 +1998,7 @@ var CodeGenerator = class _CodeGenerator {
1993
1998
  }
1994
1999
  mainApiList.push(...apiList);
1995
2000
  if (CodegenConfig.shouldProduceIndexFiles()) {
1996
- indexImportsSet.add(
1997
- ParserUtils.getRelativePathToWebSdkSrcFolder(import_path4.default.join(_CodeGenerator.srcFolder(), serviceNameTitle), targetSrcFolder)
1998
- );
2001
+ indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(import_path4.default.join(srcFolder, serviceNameTitle), targetSrcFolder));
1999
2002
  }
2000
2003
  };
2001
2004
  const writeDefinitions = (api2) => {
@@ -2030,7 +2033,7 @@ var CodeGenerator = class _CodeGenerator {
2030
2033
  if (CodegenConfig.shouldProduceIndexFiles()) {
2031
2034
  const isGenerateWebSocket = CliParser.isGenerateWebSocket();
2032
2035
  const apiIndexBuff = templateApiIndex(serviceNameTitle, mainApiList, isGenerateWebSocket);
2033
- ParserUtils.writeApiMainFile(_CodeGenerator.srcFolder(), serviceNameTitle, apiIndexBuff);
2036
+ ParserUtils.writeApiMainFile(srcFolder, serviceNameTitle, apiIndexBuff);
2034
2037
  }
2035
2038
  console.log("\nCOMPLETED\n----------\n\n");
2036
2039
  return { indexImports: indexImportsSet, queryImports: queryImportsSet };