@accelbyte/codegen 2.0.0-beta.3 → 2.0.0-beta.5
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.
|
@@ -55,6 +55,9 @@ class CliParser {
|
|
|
55
55
|
static getSnippetOutputPath = () => {
|
|
56
56
|
return CliParser.instance().argv.snippetOutput;
|
|
57
57
|
};
|
|
58
|
+
static skipVersionSync = () => {
|
|
59
|
+
return CliParser.instance().argv.skipVersionSync;
|
|
60
|
+
};
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
const getImportableVarMap$1 = () => ({
|
|
@@ -155,7 +158,8 @@ class VersionHelpers {
|
|
|
155
158
|
throw new Error(`Invalid sdk version: ${sdkVersion}`);
|
|
156
159
|
}
|
|
157
160
|
const { major: currentMajor, minor: currentMinor, patch: currentPatch, prerelease: currentPrerelease } = sdkSemvers;
|
|
158
|
-
const nextMajor = codegenSemvers.
|
|
161
|
+
const nextMajor = codegenSemvers.major + predefinedMajorVersion;
|
|
162
|
+
const shouldResetVersion = nextMajor !== currentMajor;
|
|
159
163
|
let nextMinor = currentMinor;
|
|
160
164
|
let nextPatch = currentPatch;
|
|
161
165
|
switch (versionBumpType) {
|
|
@@ -171,6 +175,10 @@ class VersionHelpers {
|
|
|
171
175
|
break;
|
|
172
176
|
}
|
|
173
177
|
}
|
|
178
|
+
if (shouldResetVersion) {
|
|
179
|
+
nextMinor = 0;
|
|
180
|
+
nextPatch = 0;
|
|
181
|
+
}
|
|
174
182
|
let nextVersion = [
|
|
175
183
|
codegenSemvers.major + predefinedMajorVersion,
|
|
176
184
|
nextMinor,
|
|
@@ -180,7 +188,7 @@ class VersionHelpers {
|
|
|
180
188
|
if (nextMinor !== currentMinor || nextMajor !== currentMajor) {
|
|
181
189
|
nextVersion += `-${nextPrereleaseId}.0`;
|
|
182
190
|
} else {
|
|
183
|
-
nextVersion += `-${
|
|
191
|
+
nextVersion += `-${currentPrerelease.join(".")}`;
|
|
184
192
|
nextVersion = semver.inc(nextVersion, "prerelease", void 0, nextPrereleaseId);
|
|
185
193
|
}
|
|
186
194
|
}
|
|
@@ -493,16 +501,15 @@ class ParserUtils {
|
|
|
493
501
|
ParserUtils.mkdirIfNotExist(distDir);
|
|
494
502
|
fs__default.writeFileSync(path__default.join(distDir, `all-${isAdminWebSdk ? "admin" : "public"}-imports.ts`), ParserUtils.prependCopyrightHeader(buffer));
|
|
495
503
|
}
|
|
496
|
-
static syncPackageVersion(apiInfo,
|
|
497
|
-
if (
|
|
504
|
+
static syncPackageVersion(apiInfo, skipVersionSync, prereleaseId) {
|
|
505
|
+
if (skipVersionSync)
|
|
498
506
|
return;
|
|
499
|
-
}
|
|
500
507
|
const currDir = process.cwd();
|
|
501
508
|
const { packageJSON, pathToPackageJSON } = ParserUtils.getPackageJSONInfo(currDir);
|
|
502
509
|
const nextSemver = VersionHelpers.getNextVersion({
|
|
503
510
|
codegenVersion: codegenPackageJSON.version,
|
|
504
511
|
serviceVersion: apiInfo["x-version"] || apiInfo.version || UNDEFINED_SWAGGER_SEMVER,
|
|
505
|
-
predefinedMajorVersion: packageJSON.predefinedMajorVersion,
|
|
512
|
+
predefinedMajorVersion: packageJSON.predefinedMajorVersion || 0,
|
|
506
513
|
versionBumpType: process.env.VERSION_BUMP_TYPE,
|
|
507
514
|
sdkVersion: packageJSON.version,
|
|
508
515
|
nextPrereleaseId: prereleaseId
|
|
@@ -587,7 +594,9 @@ class ParserUtils {
|
|
|
587
594
|
${content}`;
|
|
588
595
|
};
|
|
589
596
|
static sortPathParamsByPath = (pathParams, path2) => {
|
|
590
|
-
|
|
597
|
+
const params = path2.match(/{\w*}/g) || [];
|
|
598
|
+
const cleanParams = params.map((param) => param.replace("{", "").replace("}", ""));
|
|
599
|
+
return pathParams.sort((a, b) => cleanParams.indexOf(a.name) - cleanParams.indexOf(b.name));
|
|
591
600
|
};
|
|
592
601
|
}
|
|
593
602
|
const mappedMethod = (httpMethod, isForm) => {
|
|
@@ -1274,6 +1283,7 @@ class CodeGenerator {
|
|
|
1274
1283
|
continue;
|
|
1275
1284
|
}
|
|
1276
1285
|
const [tag] = endpoint.tags;
|
|
1286
|
+
const pathWithBase = `${api.basePath ?? ""}${path2}`;
|
|
1277
1287
|
mapClassMethods[tag] = mapClassMethods[tag] ? mapClassMethods[tag] : {};
|
|
1278
1288
|
const isForm = endpoint.consumes && endpoint.consumes[0] === "application/x-www-form-urlencoded";
|
|
1279
1289
|
const classMethod = ParserUtils.generateNaturalLangMethod({
|
|
@@ -1284,7 +1294,7 @@ class CodeGenerator {
|
|
|
1284
1294
|
existingMethods: mapClassMethods[tag]
|
|
1285
1295
|
});
|
|
1286
1296
|
mapClassMethods[tag][classMethod] = `${path2} ${httpMethod}`;
|
|
1287
|
-
snippetMap[
|
|
1297
|
+
snippetMap[pathWithBase] = snippetMap[pathWithBase] ? snippetMap[pathWithBase] : {};
|
|
1288
1298
|
let description = endpoint.description;
|
|
1289
1299
|
description = description || "";
|
|
1290
1300
|
description = description.replace(/\s+/g, " ");
|
|
@@ -1299,7 +1309,6 @@ class CodeGenerator {
|
|
|
1299
1309
|
arrayDefinitions.push(responseClass);
|
|
1300
1310
|
}
|
|
1301
1311
|
const queryParams = ParserUtils.filterQueryParameters(endpoint.parameters);
|
|
1302
|
-
const pathWithBase = `${api.basePath ?? ""}${path2}`;
|
|
1303
1312
|
const isFormUrlEncoded = ParserUtils.isFormUrlEncoded(httpMethod, endpoint.consumes);
|
|
1304
1313
|
const pathParams = ParserUtils.filterPathParams(endpoint.parameters);
|
|
1305
1314
|
let bodyParams = ParserUtils.filterBodyParams(endpoint.parameters);
|
|
@@ -1342,7 +1351,7 @@ class CodeGenerator {
|
|
|
1342
1351
|
const serviceNameTitle = ParserUtils.convertDashesToTitleCase(serviceName);
|
|
1343
1352
|
const { apiGenName } = ParserUtils.generateApiName(tag);
|
|
1344
1353
|
const resultSnippet = templateSdkSnippet(serviceNameTitle, apiGenName, snippetMethod);
|
|
1345
|
-
snippetMap[
|
|
1354
|
+
snippetMap[pathWithBase][httpMethod] = {
|
|
1346
1355
|
web: resultSnippet,
|
|
1347
1356
|
webGit: GIT_URL + `/sdk-${serviceName}/src/generated-public/${serviceName}/${apiGenName}.ts`,
|
|
1348
1357
|
shell: snippetShell
|
|
@@ -1376,7 +1385,7 @@ class CodeGenerator {
|
|
|
1376
1385
|
ParserUtils.mkdirIfNotExist(DIST_DIR);
|
|
1377
1386
|
ParserUtils.mkdirIfNotExist(DIST_DEFINITION_DIR);
|
|
1378
1387
|
ParserUtils.mkdirIfNotExist(DIST_ENDPOINTS_DIR);
|
|
1379
|
-
ParserUtils.syncPackageVersion(apiInfo, CliParser.
|
|
1388
|
+
ParserUtils.syncPackageVersion(apiInfo, CliParser.skipVersionSync(), process.env.PRERELEASE_ID);
|
|
1380
1389
|
const { apiArgumentsByTag, apiBufferByTag, classBufferByTag, dependenciesByTag, classImports, arrayDefinitions, snippetMap } = await CodeGenerator.iterateApi(api, serviceName);
|
|
1381
1390
|
if (CliParser.getSnippetOutputPath()) {
|
|
1382
1391
|
try {
|