@accelbyte/codegen 2.0.0-beta.9 → 2.0.1

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
@@ -1,4 +1,4 @@
1
- # AccelByte Code Generator
1
+ # AccelByte Web SDK Code Generator
2
2
 
3
3
  AccelByte Code Generator is a CLI tool that facilitates creating an AccelByte Web SDK from AccelByte OpenAPI definitions.
4
4
 
@@ -30,10 +30,82 @@ Provide swaggers url you wish to generate, store it in .json format file.
30
30
  ```
31
31
 
32
32
  ## How to Generate
33
- 1. Provide the `config.json` file
34
- 2. Download swagger files
35
- `accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers`
36
- 3. Generate code from swagger files
37
- `accelbyte-codegen generate-code --config ./config.json --swaggersOutput ./swaggers --output ./sdk`
38
- 4. Prettify the files using
39
- `yarn prettier`
33
+
34
+ **Step 1: Set Up Your Node.js Environment** Make sure you have Node.js and npm (Node Package Manager) installed on your system. You can download and install them from the official website: https://nodejs.org/en/
35
+
36
+ __*It is recommended__ to use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install Node.js so you can switch between Node versions more easily
37
+
38
+ **Step 2: Create a New Node.js Project (if needed)** If you are starting a new project, create a new directory and initialize it as a Node.js project. You can do this using the following commands:
39
+ ```
40
+ mkdir my-project
41
+ cd my-project
42
+ npm init
43
+ ```
44
+ Follow the prompts to set up your project's package.json file.
45
+
46
+ **Step 3: Install the Package** To use `@accelbyte/codegen`, you need to install it as a dependency for your project. Run the following command within your project directory:
47
+ ```
48
+ npm install @accelbyte/codegen
49
+ # Or, with yarn:
50
+ yarn add @accelbyte/codegen
51
+ ```
52
+ **Step 4: Configure the Package** Check the documentation or the README of the package for specific configuration instructions.
53
+ 1. Prepare The `CHANGELOG.md` file, create the Changelog file in the root project with `CHANGELOG.md` file name.
54
+ 2. Prepare Config file, Provide the swaggers URL you wish to generate with the format of an Array of array detailed services, so we can add multiple services at the same time, by adding an Array of detailed services into `Config.json` Array like this:
55
+ ```
56
+ [
57
+ [serviceName, aliasName, swaggerFileOutput, swaggerURL],
58
+ [serviceName2, aliasName2, swaggerFileOutput2, swaggerURL2],
59
+ ...
60
+ ]
61
+ ```
62
+ and then store it in .json format file (we suggest placing the file in the root directory). example:
63
+ ```
64
+ [
65
+ ["iam", "Iam", "iam.json", "https://example.com/iam/apidocs/api.json"]
66
+ ]
67
+ ```
68
+ for the Accelbyte Demo environment, this will look like this
69
+ ```
70
+ [
71
+ ["iam", "Iam", "iam.json", "https://demo.accelbyte.io/iam/apidocs/api.json"]
72
+ ]
73
+ ```
74
+
75
+ **Step 5: Download Swagger Files** download the swagger file to the project by executing this command
76
+ ```
77
+ npm exec -- accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers
78
+ # Or, with yarn:
79
+ yarn accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers
80
+ ```
81
+ *note: please adjust the `--config` flag with the path of config.json file that was already set up before, and please specify the swagger output directory by using `--swaggersOutput` flag.
82
+
83
+ **Step 6: Generate Code from Swagger Files** after the swagger file has already been downloaded we can proceed to generating Web SDK code from the Swagger File using this command :
84
+ ```
85
+ npm exec -- accelbyte-codegen generate-code --config ./config.json --swaggersOutput ./swaggers --output ./sdk
86
+ ```
87
+ *note: please adjust the `--config` flag with the path of config.json file that was already set up before, and please specify for the swagger output directory by using `--swaggersOutput` flag, and the directory output of generated SDK using `--output` flag.
88
+ if it is successful the result will look like this, and the WebSDK code should be generated under the/sdk directory
89
+
90
+ ```
91
+ ----------
92
+ Generating API: { title: 'justice-iam-service', version: '7.4.0' }
93
+ !!!! Missing x-version ...
94
+ COMPLETED
95
+ ----------
96
+ ```
97
+
98
+ **Step 7: Prettify the files (Optional)**
99
+
100
+ To prettify the code file using the prettier tool, please install the plugin first by doing this:
101
+ ```
102
+ npm install prettier
103
+ # Or, with yarn:
104
+ yarn add prettier
105
+ ```
106
+ after installing, execute prettier as below
107
+ ```
108
+ npm exec prettier --write swaggers/*.json && prettier --write sdk/**/*
109
+ # Or, with yarn:
110
+ yarn prettier --write swaggers/*.json && prettier --write sdk/**/*
111
+ ```
@@ -149,12 +149,10 @@ export function ${className}(sdk: AccelbyteSDK, args?: ApiArgs) {
149
149
  `;
150
150
  };
151
151
 
152
- const VersionBumpType = zod.z.enum(["CUTOFF", "RELEASE", "HOTFIX"]);
152
+ const VersionBumpType = zod.z.enum(["CUTOFF", "RELEASE", "HOTFIX", "BREAKING"]);
153
153
  class VersionHelpers {
154
154
  static getNextVersion = ({
155
- codegenVersion,
156
155
  serviceVersion,
157
- predefinedMajorVersion,
158
156
  versionBumpType,
159
157
  sdkVersion,
160
158
  nextPrereleaseId
@@ -168,12 +166,8 @@ class VersionHelpers {
168
166
  throw new Error(`process.env.PRERELEASE_ID should be empty when process.env.VERSION_BUMP_TYPE is "HOTFIX" or "PRELEASE".`);
169
167
  }
170
168
  }
171
- const codegenSemvers = semver.parse(codegenVersion);
172
169
  const serviceSemvers = semver.parse(serviceVersion);
173
170
  const sdkSemvers = semver.parse(sdkVersion);
174
- if (codegenSemvers === null) {
175
- throw new Error(`Invalid codegen version: ${codegenVersion}`);
176
- }
177
171
  if (serviceSemvers === null) {
178
172
  throw new Error(`Invalid service version: ${serviceVersion}`);
179
173
  }
@@ -181,11 +175,16 @@ class VersionHelpers {
181
175
  throw new Error(`Invalid sdk version: ${sdkVersion}`);
182
176
  }
183
177
  const { major: currentMajor, minor: currentMinor, patch: currentPatch, prerelease: currentPrerelease } = sdkSemvers;
184
- const nextMajor = codegenSemvers.major + predefinedMajorVersion;
185
- const shouldResetVersion = nextMajor !== currentMajor;
178
+ let nextMajor = currentMajor;
186
179
  let nextMinor = currentMinor;
187
180
  let nextPatch = currentPatch;
188
181
  switch (versionBumpType) {
182
+ case VersionBumpType.Enum.BREAKING: {
183
+ nextMajor++;
184
+ nextMinor = 0;
185
+ nextPatch = 0;
186
+ break;
187
+ }
189
188
  case VersionBumpType.Enum.CUTOFF: {
190
189
  nextMinor++;
191
190
  nextPatch = 0;
@@ -198,17 +197,13 @@ class VersionHelpers {
198
197
  break;
199
198
  }
200
199
  }
201
- if (shouldResetVersion) {
202
- nextMinor = 0;
203
- nextPatch = 0;
204
- }
205
200
  let nextVersion = [
206
- codegenSemvers.major + predefinedMajorVersion,
201
+ nextMajor,
207
202
  nextMinor,
208
203
  nextPatch
209
204
  ].join(".");
210
205
  if (nextPrereleaseId) {
211
- if (nextMinor !== currentMinor || nextMajor !== currentMajor) {
206
+ if (nextMinor !== currentMinor) {
212
207
  nextVersion += `-${nextPrereleaseId}.0`;
213
208
  } else {
214
209
  if (currentPrerelease.length)
@@ -221,7 +216,7 @@ class VersionHelpers {
221
216
  }
222
217
 
223
218
  const codegenPackageJsonPath = path.join(__dirname, "../package.json");
224
- const codegenPackageJSON = JSON.parse(fs.readFileSync(codegenPackageJsonPath, "utf-8"));
219
+ JSON.parse(fs.readFileSync(codegenPackageJsonPath, "utf-8"));
225
220
  const UNDEFINED_SWAGGER_SEMVER = "0.0.0";
226
221
  const REMOVED_KEYWORDS = [
227
222
  "/admin/",
@@ -346,6 +341,12 @@ class ParserUtils {
346
341
  if (definition?.schema?.type && definition.schema.type === "array") {
347
342
  return `${attrName}${required}: ${definition.schema.items.type ?? "any"}[]`;
348
343
  }
344
+ if (definition.type && definition.type === "file") {
345
+ return `${attrName}${required}: File`;
346
+ }
347
+ if (definition?.schema?.type && definition.schema.type === "file") {
348
+ return `${attrName}${required}: File`;
349
+ }
349
350
  if (definition.type && definition.type) {
350
351
  return `${attrName}${required}: ${definition.type} | null`;
351
352
  }
@@ -531,9 +532,7 @@ class ParserUtils {
531
532
  const currDir = process.cwd();
532
533
  const { packageJSON, pathToPackageJSON } = ParserUtils.getPackageJSONInfo(currDir);
533
534
  const nextSemver = VersionHelpers.getNextVersion({
534
- codegenVersion: codegenPackageJSON.version,
535
535
  serviceVersion: apiInfo["x-version"] || apiInfo.version || UNDEFINED_SWAGGER_SEMVER,
536
- predefinedMajorVersion: packageJSON.predefinedMajorVersion || 0,
537
536
  versionBumpType: process.env.VERSION_BUMP_TYPE,
538
537
  sdkVersion: packageJSON.version,
539
538
  nextPrereleaseId: prereleaseId