Skip to content

Commit

Permalink
fix(migrations): migrate to latest when patch difference between vers…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
RealShadowNova committed Jul 2, 2024
1 parent 67d787d commit 6fb8f7e
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 28 deletions.
29 changes: 19 additions & 10 deletions src/bin/lib/migrateToLatest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ export interface MigrationLatest {
version: string;
}

function isSemverPatchDiff(version1: string, version2: string): boolean {
return version1.split('.').slice(0, 2).join('.') === version2.split('.').slice(0, 2).join('.');
}

export function migrateToLatest(projectJson: Record<string, unknown>, path: string): MigrationResult {
let currentVersion = `v${'typeDocJsonParserVersion' in projectJson ? projectJson.typeDocJsonParserVersion : '2.0.0'}` as string;
const latestVersion = `v${ProjectParser.version}`;
let result: MigrationResult | undefined;

while (currentVersion !== latestVersion) {
if (isSemverPatchDiff(currentVersion, latestVersion)) {
projectJson = latest(projectJson as unknown as Tags.v10_1_0.ProjectJson) as unknown as Record<string, unknown>;
result = { status: MigrationStatus.Latest, path, name: projectJson.name as string, version: projectJson.version as string };
currentVersion = latestVersion;

break;
}

const migration = migrations.find((migration) => migration.from.includes(currentVersion));

if (!migration) {
Expand Down Expand Up @@ -833,15 +845,12 @@ const migrations: Migration[] = [
dependencies: {}
};
}
},
{
from: ['v10.1.0', 'v10.1.1', 'v10.1.2'],
to: 'v10.1.3',
run(projectJson: Tags.v10_1_0.ProjectJson | Tags.v10_1_1.ProjectJson | Tags.v10_1_2.ProjectJson): Tags.v10_1_3.ProjectJson {
return {
...projectJson,
typeDocJsonParserVersion: '10.1.3'
};
}
}
];

function latest(projectJson: Tags.v10_1_0.ProjectJson): ProjectParser.Json {
return {

Check failure on line 852 in src/bin/lib/migrateToLatest.ts

View workflow job for this annotation

GitHub Actions / Generate Documentation

Type '{ typeDocJsonParserVersion: string; id: number; name: string; version: string | null; dependencies: Record<string, string>; readme: string | null; changelog: string | null; classes: Tags.v10_1_0.ClassJson[]; ... 5 more ...; variables: Tags.v10_1_0.VariableJson[]; }' is not assignable to type 'Json'.

Check failure on line 852 in src/bin/lib/migrateToLatest.ts

View workflow job for this annotation

GitHub Actions / Build Documentation

Type '{ typeDocJsonParserVersion: string; id: number; name: string; version: string | null; dependencies: Record<string, string>; readme: string | null; changelog: string | null; classes: Tags.v10_1_0.ClassJson[]; ... 5 more ...; variables: Tags.v10_1_0.VariableJson[]; }' is not assignable to type 'Json'.

Check failure on line 852 in src/bin/lib/migrateToLatest.ts

View workflow job for this annotation

GitHub Actions / Compile Source Code

Type '{ typeDocJsonParserVersion: string; id: number; name: string; version: string | null; dependencies: Record<string, string>; readme: string | null; changelog: string | null; classes: Tags.v10_1_0.ClassJson[]; ... 5 more ...; variables: Tags.v10_1_0.VariableJson[]; }' is not assignable to type 'Json'.
...projectJson,
typeDocJsonParserVersion: ProjectParser.version
};
}
4 changes: 1 addition & 3 deletions src/bin/lib/types/Tags/v10_1_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export namespace v10_1_0 {
abstract: boolean;
typeParameters: Misc.TypeParameterJson[];
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down Expand Up @@ -240,5 +240,3 @@ export namespace v10_1_0 {
value: string;
}
}

export { v10_1_0 as v10_1_1, v10_1_0 as v10_1_2, v10_1_0 as v10_1_3 };
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v2_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export namespace v2_0_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v2_1_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export namespace v2_1_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v2_2_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export namespace v2_2_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v2_3_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export namespace v2_3_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v3_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export namespace v3_0_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v3_1_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export namespace v3_1_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v3_2_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export namespace v3_2_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v4_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export namespace v4_0_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v5_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export namespace v5_0_0 {
external: boolean;
abstract: boolean;
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v6_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export namespace v6_0_0 {
abstract: boolean;
typeParameters: Misc.TypeParameterJson[];
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v7_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export namespace v7_0_0 {
abstract: boolean;
typeParameters: Misc.TypeParameterJson[];
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v7_1_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export namespace v7_1_0 {
abstract: boolean;
typeParameters: Misc.TypeParameterJson[];
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v7_2_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export namespace v7_2_0 {
abstract: boolean;
typeParameters: Misc.TypeParameterJson[];
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v7_3_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export namespace v7_3_0 {
abstract: boolean;
typeParameters: Misc.TypeParameterJson[];
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down
2 changes: 1 addition & 1 deletion src/bin/lib/types/Tags/v8_2_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export namespace v8_2_0 {
abstract: boolean;
typeParameters: Misc.TypeParameterJson[];
extendsType: TypeJson | null;
implementsTypes: TypeJson[];
implementsType: TypeJson[];
construct: ClassJson.ConstructorJson;
properties: ClassJson.PropertyJson[];
methods: ClassJson.MethodJson[];
Expand Down

0 comments on commit 6fb8f7e

Please sign in to comment.