Skip to content

Commit 8e9ed63

Browse files
committed
chore: scaffolding migration
1 parent a1438c5 commit 8e9ed63

File tree

12 files changed

+266
-0
lines changed

12 files changed

+266
-0
lines changed

packages/amplify-cli/amplify-plugin.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"configure",
77
"console",
88
"delete",
9+
"drift",
910
"diagnose",
1011
"env",
12+
"gen2-migration",
1113
"export",
1214
"help",
1315
"init",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { $TSContext } from '@aws-amplify/amplify-cli-core';
2+
3+
export const run = async (context: $TSContext): Promise<void> => {
4+
return new AmplifyDriftDetector(context).detect();
5+
};
6+
7+
export class AmplifyDriftDetector {
8+
constructor(private readonly context: $TSContext) {}
9+
10+
public async detect(): Promise<void> {
11+
throw new Error('Not implemented');
12+
}
13+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { AmplifyMigrationCloneStep } from './gen2-migration/clone';
2+
import { $TSContext } from '@aws-amplify/amplify-cli-core';
3+
import { AmplifyMigrationStep } from './gen2-migration/_step';
4+
import { printer } from '@aws-amplify/amplify-prompts';
5+
import { AmplifyMigrationCleanupStep } from './gen2-migration/cleanup';
6+
import { AmplifyMigrationDecommissionStep } from './gen2-migration/decommission';
7+
import { AmplifyMigrationGenerateStep } from './gen2-migration/generate';
8+
import { AmplifyMigrationLockStep } from './gen2-migration/lock';
9+
import { AmplifyMigrationRefactorStep } from './gen2-migration/refactor';
10+
import { AmplifyMigrationShiftStep } from './gen2-migration/shift';
11+
12+
const STEPS = {
13+
cleanup: {
14+
class: AmplifyMigrationCleanupStep,
15+
description: 'TODO',
16+
},
17+
clone: {
18+
class: AmplifyMigrationCloneStep,
19+
description: 'TODO',
20+
},
21+
decommission: {
22+
class: AmplifyMigrationDecommissionStep,
23+
description: 'TODO',
24+
},
25+
generate: {
26+
class: AmplifyMigrationGenerateStep,
27+
description: 'TODO',
28+
},
29+
lock: {
30+
class: AmplifyMigrationLockStep,
31+
description: 'TODO',
32+
},
33+
refactor: {
34+
class: AmplifyMigrationRefactorStep,
35+
description: 'TODO',
36+
},
37+
shift: {
38+
class: AmplifyMigrationShiftStep,
39+
description: 'TODO',
40+
},
41+
};
42+
43+
export const run = async (context: $TSContext) => {
44+
const step = STEPS[(context.input.subCommands ?? [])[0]];
45+
if (!step) {
46+
displayHelp(context);
47+
return;
48+
}
49+
50+
shiftParams(context);
51+
52+
const implementation: AmplifyMigrationStep = new step.class(context);
53+
54+
try {
55+
printer.info('Validating');
56+
await implementation.validate();
57+
printer.info('Executing');
58+
await implementation.execute();
59+
} catch (error: unknown) {
60+
printer.warn(`${error}. Rolling back.`);
61+
await implementation.rollback();
62+
throw error;
63+
}
64+
};
65+
66+
function shiftParams(context) {
67+
delete context.parameters.first;
68+
delete context.parameters.second;
69+
delete context.parameters.third;
70+
const { subCommands } = context.input;
71+
/* eslint-disable */
72+
if (subCommands && subCommands.length > 1) {
73+
if (subCommands.length > 1) {
74+
context.parameters.first = subCommands[1];
75+
}
76+
if (subCommands.length > 2) {
77+
context.parameters.second = subCommands[2];
78+
}
79+
if (subCommands.length > 3) {
80+
context.parameters.third = subCommands[3];
81+
}
82+
}
83+
/* eslint-enable */
84+
}
85+
86+
function displayHelp(context: $TSContext) {
87+
context.amplify.showHelp(
88+
'amplify gen2-migration <subcommands>',
89+
Object.entries(STEPS).map(([name, v]) => ({ name, description: v.description })),
90+
);
91+
printer.info('');
92+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { $TSContext } from '@aws-amplify/amplify-cli-core';
2+
3+
export abstract class AmplifyMigrationStep {
4+
constructor(private readonly context: $TSContext) {}
5+
6+
public abstract validate(): Promise<void>;
7+
8+
public abstract execute(): Promise<void>;
9+
10+
public abstract rollback(): Promise<void>;
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { AmplifyDriftDetector } from '../drift';
2+
import { $TSContext } from '@aws-amplify/amplify-cli-core';
3+
import { printer } from '@aws-amplify/amplify-prompts';
4+
5+
export class AmplifyGen2MigrationValidations {
6+
constructor(private readonly context: $TSContext) {}
7+
8+
public async validateDrift(): Promise<void> {
9+
return new AmplifyDriftDetector(this.context).detect();
10+
}
11+
12+
public async validateWorkingDirectory(): Promise<void> {
13+
printer.warn('Not implemented');
14+
}
15+
16+
public async validateDeploymentStatus(): Promise<void> {
17+
printer.warn('Not implemented');
18+
}
19+
20+
public async validateDeploymentVersion(): Promise<void> {
21+
printer.warn('Not implemented');
22+
}
23+
24+
public async validateIsolatedEnvironment(): Promise<void> {
25+
printer.warn('Not implemented');
26+
}
27+
28+
// eslint-disable-next-line spellcheck/spell-checker
29+
public async validateStatefulResources(): Promise<void> {
30+
printer.warn('Not implemented');
31+
}
32+
33+
public async validateIngressTraffic(): Promise<void> {
34+
printer.warn('Not implemented');
35+
}
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AmplifyMigrationStep } from './_step';
2+
import { printer } from '@aws-amplify/amplify-prompts';
3+
4+
export class AmplifyMigrationCleanupStep extends AmplifyMigrationStep {
5+
public async validate(): Promise<void> {
6+
printer.warn('Not implemented');
7+
}
8+
9+
public async execute(): Promise<void> {
10+
printer.warn('Not implemented');
11+
}
12+
13+
public async rollback(): Promise<void> {
14+
printer.warn('Not implemented');
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AmplifyMigrationStep } from './_step';
2+
import { printer } from '@aws-amplify/amplify-prompts';
3+
4+
export class AmplifyMigrationCloneStep extends AmplifyMigrationStep {
5+
public async validate(): Promise<void> {
6+
printer.warn('Not implemented');
7+
}
8+
9+
public async execute(): Promise<void> {
10+
printer.warn('Not implemented');
11+
}
12+
13+
public async rollback(): Promise<void> {
14+
printer.warn('Not implemented');
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AmplifyMigrationStep } from './_step';
2+
import { printer } from '@aws-amplify/amplify-prompts';
3+
4+
export class AmplifyMigrationDecommissionStep extends AmplifyMigrationStep {
5+
public async validate(): Promise<void> {
6+
printer.warn('Not implemented');
7+
}
8+
9+
public async execute(): Promise<void> {
10+
printer.warn('Not implemented');
11+
}
12+
13+
public async rollback(): Promise<void> {
14+
printer.warn('Not implemented');
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AmplifyMigrationStep } from './_step';
2+
import { printer } from '@aws-amplify/amplify-prompts';
3+
4+
export class AmplifyMigrationGenerateStep extends AmplifyMigrationStep {
5+
public async validate(): Promise<void> {
6+
printer.warn('Not implemented');
7+
}
8+
9+
public async execute(): Promise<void> {
10+
printer.warn('Not implemented');
11+
}
12+
13+
public async rollback(): Promise<void> {
14+
printer.warn('Not implemented');
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AmplifyMigrationStep } from './_step';
2+
import { printer } from '@aws-amplify/amplify-prompts';
3+
4+
export class AmplifyMigrationLockStep extends AmplifyMigrationStep {
5+
public async validate(): Promise<void> {
6+
printer.warn('Not implemented');
7+
}
8+
9+
public async execute(): Promise<void> {
10+
printer.warn('Not implemented');
11+
}
12+
13+
public async rollback(): Promise<void> {
14+
printer.warn('Not implemented');
15+
}
16+
}

0 commit comments

Comments
 (0)