UNPKG

@aws-amplify/cli-internal

Version:
111 lines 4.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Plan = void 0; const amplify_prompts_1 = require("@aws-amplify/amplify-prompts"); const chalk_1 = __importDefault(require("chalk")); const cli_table3_1 = __importDefault(require("cli-table3")); class Plan { constructor(props) { var _a; this.operations = props.operations; this.logger = props.logger; this.title = props.title; this.implications = (_a = props.implications) !== null && _a !== void 0 ? _a : []; } addOperation(operation) { this.operations.push(operation); } async validate() { this.logger.start('Validating'); const entries = []; for (const op of this.operations) { const validation = op.validate(); if (!validation) continue; this.logger.push(validation.description); const result = await validation.run(); this.logger.pop(); entries.push({ description: validation.description, valid: result.valid, report: result.report }); } this.logger.succeed('→ Validating complete'); this.renderValidationResults(entries); return entries.every((e) => e.valid); } async describe() { const grouped = new Map(); for (const op of this.operations) { const lines = await op.describe(); if (lines.length === 0) continue; const label = op.resource ? `Resource: ${op.resource.category}/${op.resource.resourceName} (${op.resource.service})` : 'Project'; if (!grouped.has(label)) grouped.set(label, []); grouped.get(label).push(...lines); } if (grouped.size > 0) { amplify_prompts_1.printer.info(chalk_1.default.bold(chalk_1.default.underline('Operations Summary'))); for (const [label, descriptions] of grouped) { amplify_prompts_1.printer.blankLine(); amplify_prompts_1.printer.info(chalk_1.default.green(chalk_1.default.bold(label))); amplify_prompts_1.printer.blankLine(); let step = 1; for (const description of descriptions) { amplify_prompts_1.printer.info(`${step}. ${description}`); step++; } } } if (this.implications.length > 0) { amplify_prompts_1.printer.blankLine(); amplify_prompts_1.printer.info(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.yellow('Implications')))); amplify_prompts_1.printer.blankLine(); for (const implication of this.implications) { amplify_prompts_1.printer.info(`• ${implication}`); } amplify_prompts_1.printer.blankLine(); } } async execute() { this.logger.info(this.title); for (const op of this.operations) { await op.execute(); } amplify_prompts_1.printer.blankLine(); amplify_prompts_1.printer.success('Done'); } renderValidationResults(entries) { if (entries.length === 0) return; const failed = entries.filter((e) => !e.valid && e.report); if (failed.length > 0) { amplify_prompts_1.printer.blankLine(); amplify_prompts_1.printer.info(chalk_1.default.bold(chalk_1.default.underline('Failed Validations Report'))); amplify_prompts_1.printer.blankLine(); for (let i = 0; i < failed.length; i++) { amplify_prompts_1.printer.info(chalk_1.default.bold(chalk_1.default.red(`✘ ${failed[i].description}`))); amplify_prompts_1.printer.blankLine(); amplify_prompts_1.printer.info(failed[i].report.trimStart()); if (i < failed.length - 1) { amplify_prompts_1.printer.blankLine(); } } } amplify_prompts_1.printer.blankLine(); amplify_prompts_1.printer.info(chalk_1.default.bold(chalk_1.default.underline('Validations Summary'))); amplify_prompts_1.printer.blankLine(); const table = new cli_table3_1.default({ head: ['Validation', 'Status'], style: { head: [] }, }); for (const entry of entries) { const status = entry.valid ? chalk_1.default.green('✔ Passed') : chalk_1.default.red('✘ Failed'); table.push([entry.description, status]); } amplify_prompts_1.printer.info(table.toString()); } } exports.Plan = Plan; //# sourceMappingURL=plan.js.map