@aws-amplify/cli-internal
Version:
Amplify CLI
49 lines • 2.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomCDKForwardRefactorer = void 0;
const amplify_cli_core_1 = require("@aws-amplify/amplify-cli-core");
const forward_category_refactorer_1 = require("../workflow/forward-category-refactorer");
const amplify_prompts_1 = require("@aws-amplify/amplify-prompts");
const utils_1 = require("../../_common/utils");
const CHOICE_SEPERATOR = ' ';
class CustomCDKForwardRefactorer extends forward_category_refactorer_1.ForwardCategoryRefactorer {
async fetchSourceStackId() {
return this.findNestedStack(this.gen1Env, `custom${this.resource.resourceName}`);
}
async fetchDestStackId() {
return this.findNestedStack(this.gen2Branch, `custom${this.resource.resourceName}`);
}
resourceTypes() {
return this.gen1App.statefulResourceTypes;
}
async gen2LogicalId(sourceId, sourceResource, targetResources) {
const candidates = Array.from(targetResources.keys()).filter((r) => targetResources.get(r).Type === sourceResource.Type);
if (candidates.length === 0) {
throw new amplify_cli_core_1.AmplifyError('MigrationError', {
message: `Unable to map Gen1 resource ${sourceId} (${sourceResource.Type}) to Gen2 resource`,
});
}
if (candidates.length === 1) {
return candidates[0];
}
const gen2StackId = (await this.fetchDestStackId());
const gen2Resources = await this.gen2Branch.fetchStackResources(gen2StackId);
function gen2PhysicalResourceId(logicalId) {
var _a;
const physicalId = (_a = gen2Resources.find((r) => r.LogicalResourceId === logicalId)) === null || _a === void 0 ? void 0 : _a.PhysicalResourceId;
if (!physicalId) {
throw new amplify_cli_core_1.AmplifyError('MigrationError', {
message: `Unable to find physical ID of resource ${logicalId} in stack ${(0, utils_1.extractStackNameFromId)(gen2StackId)}`,
});
}
return physicalId;
}
const choices = candidates.map((c) => `${c}${CHOICE_SEPERATOR}(${gen2PhysicalResourceId(c)})`);
this.logger.pause();
const selection = await amplify_prompts_1.prompter.pick(`(${this.resource.category}/${this.resource.resourceName}) Multiple refactor candidates detected. Choose which Gen2 resource corresponds to Gen1 resource '${sourceId}' (${sourceResource.Type})`, choices);
this.logger.resume();
return selection.split(CHOICE_SEPERATOR)[0];
}
}
exports.CustomCDKForwardRefactorer = CustomCDKForwardRefactorer;
//# sourceMappingURL=custom-cdk-forward.js.map