UNPKG

create-strapi-app

Version:

Generate a new Strapi application.

66 lines (62 loc) 2.05 kB
'use strict'; var inquirer = require('inquirer'); var cloudCli = require('@strapi/cloud-cli'); var parseToChalk = require('./utils/parse-to-chalk.js'); function assertCloudError(e) { if (e.response === undefined) { throw Error('Expected CloudError'); } } async function handleCloudLogin() { const logger = cloudCli.services.createLogger({ silent: false, debug: process.argv.includes('--debug'), timestamp: false }); const cloudApiService = await cloudCli.services.cloudApiFactory({ logger }); const defaultErrorMessage = 'An error occurred while trying to interact with Strapi Cloud. Use strapi deploy command once the project is generated.'; try { const { data: config } = await cloudApiService.config(); logger.log(parseToChalk(config.projectCreation.introText)); } catch (e) { logger.debug(e); logger.error(defaultErrorMessage); return; } const { userChoice } = await inquirer.prompt([ { type: 'list', name: 'userChoice', message: `Please log in or sign up.`, choices: [ 'Login/Sign up', 'Skip' ] } ]); if (userChoice !== 'Skip') { const cliContext = { logger, cwd: process.cwd() }; try { await cloudCli.cli.login.action(cliContext); } catch (e) { logger.debug(e); try { assertCloudError(e); if (e.response.status === 403) { const message = typeof e.response.data === 'string' ? e.response.data : 'We are sorry, but we are not able to log you into Strapi Cloud at the moment.'; logger.warn(message); return; } } catch (e) { /* empty */ } logger.error(defaultErrorMessage); } } } exports.handleCloudLogin = handleCloudLogin; //# sourceMappingURL=cloud.js.map