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

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
@@ -133,14 +133,57 @@ export default {
133
133
 
134
134
  // Generate barrel index files (index.ts, all-imports.ts, all-query-imports.ts).
135
135
  // Default: true
136
- unstable_shouldProduceIndexFiles: false,
136
+ shouldProduceIndexFiles: false,
137
137
 
138
138
  // Force specific definitions to emit `z.any()` instead of a full schema.
139
139
  // Keyed by definition file name. Value can be `true` or a function receiving the schema.
140
- unstable_overrideAsAny: {
140
+ 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
 
@@ -6,17 +6,26 @@ interface CodegenConfigOptions {
6
6
  * @example
7
7
  * { ProtobufAny: true, SomeOther: (schema) => schema.properties?.['@type'] !== undefined }
8
8
  */
9
- unstable_overrideAsAny?: Record<string, boolean | ((schema: Record<string, any>) => boolean)>;
9
+ overrideAsAny?: Record<string, boolean | ((schema: Record<string, any>) => boolean)>;
10
10
  /**
11
11
  * Generate barrel index files (index.ts, all-imports.ts, all-query-imports.ts).
12
12
  * @default true
13
13
  */
14
- unstable_shouldProduceIndexFiles?: boolean;
14
+ shouldProduceIndexFiles?: boolean;
15
15
  /**
16
16
  * Override the base path prepended to all API routes.
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 };
@@ -6,17 +6,26 @@ interface CodegenConfigOptions {
6
6
  * @example
7
7
  * { ProtobufAny: true, SomeOther: (schema) => schema.properties?.['@type'] !== undefined }
8
8
  */
9
- unstable_overrideAsAny?: Record<string, boolean | ((schema: Record<string, any>) => boolean)>;
9
+ overrideAsAny?: Record<string, boolean | ((schema: Record<string, any>) => boolean)>;
10
10
  /**
11
11
  * Generate barrel index files (index.ts, all-imports.ts, all-query-imports.ts).
12
12
  * @default true
13
13
  */
14
- unstable_shouldProduceIndexFiles?: boolean;
14
+ shouldProduceIndexFiles?: boolean;
15
15
  /**
16
16
  * Override the base path prepended to all API routes.
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 };
@@ -109,13 +109,16 @@ var CodegenConfig = class _CodegenConfig {
109
109
  _CodegenConfig.config = loaded.default ?? loaded ?? {};
110
110
  }
111
111
  static shouldProduceIndexFiles() {
112
- return _CodegenConfig.config.unstable_shouldProduceIndexFiles ?? true;
112
+ return _CodegenConfig.config.shouldProduceIndexFiles ?? true;
113
113
  }
114
114
  static getBasePath() {
115
115
  return _CodegenConfig.config.basePath;
116
116
  }
117
117
  static getOverrideAsAny() {
118
- return _CodegenConfig.config.unstable_overrideAsAny;
118
+ return _CodegenConfig.config.overrideAsAny;
119
+ }
120
+ static splitOutputByServiceName() {
121
+ return _CodegenConfig.config.unstable_splitOutputByServiceName ?? false;
119
122
  }
120
123
  /** Reset to defaults — used for testing */
121
124
  static reset() {
@@ -883,6 +886,16 @@ var resolveConflicts = ({ path: path9, generatedMethod, testedGeneratedMethod, e
883
886
  _testedGenMethod += "_admin";
884
887
  }
885
888
  }
889
+ try {
890
+ testConflict(path9, _testedGenMethod, existingMethods);
891
+ } catch (e) {
892
+ const parentSegmentMatch = path9.match(/\/([^/{}]+)\/{[^}]+}\/[^/]*$/);
893
+ if (parentSegmentMatch) {
894
+ const suffix = "_By" + import_lodash.default.upperFirst(import_lodash.default.camelCase(parentSegmentMatch[1]));
895
+ generatedMethod += suffix;
896
+ _testedGenMethod += suffix;
897
+ }
898
+ }
886
899
  testConflict(path9, _testedGenMethod, existingMethods);
887
900
  return generatedMethod;
888
901
  };
@@ -1907,8 +1920,11 @@ var CodeGenerator = class _CodeGenerator {
1907
1920
  const queryImportsSet = /* @__PURE__ */ new Set();
1908
1921
  const apiInfo = { ...api.info, "x-version": api["x-version"]?.version };
1909
1922
  console.log("----------\nGenerating API:", { title: apiInfo.title, version: apiInfo.version });
1923
+ const isSplitByService = CodegenConfig.splitOutputByServiceName();
1924
+ const srcFolder = isSplitByService ? import_path4.default.join(CliParser.getOutputPath(), serviceName) : CliParser.getOutputPath();
1925
+ const targetSrcFolder = `${CliParser.getOutputPath()}/`;
1910
1926
  if (!CliParser.isGenerateSnippetOnly()) {
1911
- ParserUtils.writeXVersion(_CodeGenerator.srcFolder(), api["x-version"], api.info);
1927
+ ParserUtils.writeXVersion(srcFolder, api["x-version"], api.info);
1912
1928
  }
1913
1929
  const parsedInformation = await SwaggerReaderHelpers.parseAllEndpoints({ api, sdkName, serviceName });
1914
1930
  if (CliParser.getSnippetOutputPath()) {
@@ -1934,11 +1950,10 @@ var CodeGenerator = class _CodeGenerator {
1934
1950
  console.log("\nSuccessfully generate SDK snippets only\n----------\n\n");
1935
1951
  return;
1936
1952
  }
1937
- const DIST_DIR = (isAdmin) => `${_CodeGenerator.getGeneratedFolder(isAdmin)}`;
1953
+ const DIST_DIR = (isAdmin) => import_path4.default.join(srcFolder, isAdmin ? "generated-admin" : "generated-public");
1938
1954
  const DIST_DIR_ENDPOINTS = (isAdmin) => import_path4.default.join(DIST_DIR(isAdmin), "endpoints");
1939
1955
  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()}/`;
1956
+ const DIST_DEFINITION_DIR = import_path4.default.join(srcFolder, "generated-definitions");
1942
1957
  _CodeGenerator.prepareDirs(DIST_DEFINITION_DIR, DIST_DIR, DIST_DIR_ENDPOINTS, DIST_DIR_QUERIES);
1943
1958
  const mainApiList = [];
1944
1959
  const generatedDefinitions = [];
@@ -1993,9 +2008,7 @@ var CodeGenerator = class _CodeGenerator {
1993
2008
  }
1994
2009
  mainApiList.push(...apiList);
1995
2010
  if (CodegenConfig.shouldProduceIndexFiles()) {
1996
- indexImportsSet.add(
1997
- ParserUtils.getRelativePathToWebSdkSrcFolder(import_path4.default.join(_CodeGenerator.srcFolder(), serviceNameTitle), targetSrcFolder)
1998
- );
2011
+ indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(import_path4.default.join(srcFolder, serviceNameTitle), targetSrcFolder));
1999
2012
  }
2000
2013
  };
2001
2014
  const writeDefinitions = (api2) => {
@@ -2030,7 +2043,7 @@ var CodeGenerator = class _CodeGenerator {
2030
2043
  if (CodegenConfig.shouldProduceIndexFiles()) {
2031
2044
  const isGenerateWebSocket = CliParser.isGenerateWebSocket();
2032
2045
  const apiIndexBuff = templateApiIndex(serviceNameTitle, mainApiList, isGenerateWebSocket);
2033
- ParserUtils.writeApiMainFile(_CodeGenerator.srcFolder(), serviceNameTitle, apiIndexBuff);
2046
+ ParserUtils.writeApiMainFile(srcFolder, serviceNameTitle, apiIndexBuff);
2034
2047
  }
2035
2048
  console.log("\nCOMPLETED\n----------\n\n");
2036
2049
  return { indexImports: indexImportsSet, queryImports: queryImportsSet };