UNPKG

@aws-amplify/cli-internal

Version:
129 lines 5.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Assessment = exports.notApplicable = exports.unsupported = exports.supported = void 0; const chalk_1 = __importDefault(require("chalk")); const cli_table3_1 = __importDefault(require("cli-table3")); const amplify_cli_core_1 = require("@aws-amplify/amplify-cli-core"); const GUIDE_LINK = 'https://docs.amplify.aws/react/start/migrate-to-gen2/feature-matrix/'; const supported = () => ({ level: 'supported' }); exports.supported = supported; const unsupported = (note) => ({ level: 'unsupported', note }); exports.unsupported = unsupported; const notApplicable = () => ({ level: 'not-applicable' }); exports.notApplicable = notApplicable; class Assessment { constructor(appName, envName) { this.appName = appName; this.envName = envName; this._resources = []; this._features = []; } recordResource(resource) { this._resources.push(resource); } recordFeature(feature) { this._features.push(feature); } get resources() { return this._resources; } get features() { return this._features; } of(resource, step) { const entry = this._resources.find((ra) => ra.resource.category === resource.category && ra.resource.resourceName === resource.resourceName); if (!entry) { throw new amplify_cli_core_1.AmplifyFault('ResourceAssessmentNotFoundFault', { message: `No assessment recorded for resource '${resource.category}/${resource.resourceName}'`, }); } switch (step) { case 'generate': return entry.generate; case 'refactor': return entry.refactor; } } validFor(step) { switch (step) { case 'generate': return (this._resources.every((ar) => ar.generate.level !== 'unsupported') && this._features.every((fr) => fr.generate.level !== 'unsupported')); case 'refactor': return (this._resources.every((ar) => ar.refactor.level !== 'unsupported') && this._features.every((fr) => fr.refactor.level !== 'unsupported')); } } render() { const lines = []; lines.push(''); lines.push(chalk_1.default.bold(chalk_1.default.cyan(`Assessment For Migrating "${this.appName}" (env: ${this.envName})`))); if (this._resources.length > 0) { lines.push(''); lines.push(chalk_1.default.bold('Resources')); lines.push(''); lines.push(this.renderResourceTable()); lines.push(''); } if (this._features.length > 0) { lines.push(chalk_1.default.bold('Advanced Features')); lines.push(''); lines.push(this.renderFeatureTable()); lines.push(''); } if (this.hasUnsupported()) { lines.push(chalk_1.default.yellow('During migration, unsupported resources/features can be skipped by passing --skip-validations to the command.')); lines.push(''); } lines.push(chalk_1.default.yellow('⚠️ Some features may not be reported by this assessment. More details are available in the migration guide.')); lines.push(''); lines.push(chalk_1.default.yellow(GUIDE_LINK)); lines.push(''); return lines.join('\n'); } hasUnsupported() { return (this._resources.some((ra) => ra.generate.level === 'unsupported' || ra.refactor.level === 'unsupported') || this._features.some((fr) => fr.generate.level === 'unsupported' || fr.refactor.level === 'unsupported')); } renderResourceTable() { const table = new cli_table3_1.default({ head: ['Category', 'Service', 'Resource', 'Generate', 'Refactor'], style: { head: [] }, }); for (const ra of this._resources) { table.push([ ra.resource.category, ra.resource.service, ra.resource.resourceName, Assessment.supportText(ra.generate), Assessment.supportText(ra.refactor), ]); } return table.toString(); } renderFeatureTable() { const table = new cli_table3_1.default({ head: ['Name', 'Path', 'Generate', 'Refactor'], style: { head: [] }, }); for (const fr of this._features) { table.push([fr.feature.name, fr.feature.path, Assessment.supportText(fr.generate), Assessment.supportText(fr.refactor)]); } return table.toString(); } static supportText(support) { switch (support.level) { case 'supported': return '✔'; case 'unsupported': return support.note ? `✘ ${support.note}` : '✘'; case 'not-applicable': return '— (not needed)'; } } } exports.Assessment = Assessment; //# sourceMappingURL=assessment.js.map