UNPKG

@aws-amplify/cli-internal

Version:
75 lines 3.48 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var _a, _b; Object.defineProperty(exports, "__esModule", { value: true }); exports.initFrontend = void 0; const get_frontend_plugins_1 = require("../extensions/amplify-helpers/get-frontend-plugins"); const input_params_manager_1 = require("../input-params-manager"); const amplify_prompts_1 = require("@aws-amplify/amplify-prompts"); async function initFrontend(context) { if (context.exeInfo.inputParams && context.exeInfo.inputParams.yes && context.exeInfo.existingProjectConfig && context.exeInfo.existingProjectConfig.frontend) { context.exeInfo.projectConfig = context.exeInfo.existingProjectConfig; } else { const frontendPlugins = (0, get_frontend_plugins_1.getFrontendPlugins)(context); let suitableFrontend; let fitToHandleScore = -1; for (const key of Object.keys(frontendPlugins)) { const { scanProject } = await (_a = frontendPlugins[key], Promise.resolve().then(() => __importStar(require(_a)))); const newScore = scanProject(context.exeInfo.localEnvInfo.projectPath); if (newScore > fitToHandleScore) { fitToHandleScore = newScore; suitableFrontend = key; } } const frontend = await getFrontendHandler(context, frontendPlugins, suitableFrontend); context.exeInfo.projectConfig.frontend = frontend; const frontendModule = await (_b = frontendPlugins[frontend], Promise.resolve().then(() => __importStar(require(_b)))); await frontendModule.init(context); } return context; } exports.initFrontend = initFrontend; async function getFrontendHandler(context, frontendPlugins, suitableFrontend) { let frontend; const frontendPluginList = Object.keys(frontendPlugins); const { inputParams } = context.exeInfo; if (inputParams && inputParams.amplify && inputParams.amplify.frontend) { frontend = (0, input_params_manager_1.normalizeFrontendHandlerName)(inputParams.amplify.frontend, frontendPluginList); } if (!frontend && inputParams && inputParams.yes) { frontend = 'javascript'; } if (!frontend) { frontend = amplify_prompts_1.prompter.pick("Choose the type of app that you're building", frontendPluginList, { initial: (0, amplify_prompts_1.byValue)(suitableFrontend), }); } return frontend; } //# sourceMappingURL=a30-initFrontend.js.map