UNPKG

create-strapi-app

Version:

Generate a new Strapi application.

1 lines 4.25 kB
{"version":3,"file":"cloud.mjs","sources":["../src/cloud.ts"],"sourcesContent":["import inquirer from 'inquirer';\nimport { cli as cloudCli, services as cloudServices } from '@strapi/cloud-cli';\nimport parseToChalk from './utils/parse-to-chalk';\n\ninterface CloudError {\n response: {\n status: number;\n data: string | object;\n };\n}\n\nfunction assertCloudError(e: unknown): asserts e is CloudError {\n if ((e as CloudError).response === undefined) {\n throw Error('Expected CloudError');\n }\n}\n\nexport async function handleCloudLogin(): Promise<void> {\n const logger = cloudServices.createLogger({\n silent: false,\n debug: process.argv.includes('--debug'),\n timestamp: false,\n });\n const cloudApiService = await cloudServices.cloudApiFactory({ logger });\n const defaultErrorMessage =\n 'An error occurred while trying to interact with Strapi Cloud. Use strapi deploy command once the project is generated.';\n\n try {\n const { data: config } = await cloudApiService.config();\n logger.log(parseToChalk(config.projectCreation.introText));\n } catch (e: unknown) {\n logger.debug(e);\n logger.error(defaultErrorMessage);\n return;\n }\n const { userChoice } = await inquirer.prompt<{ userChoice: string }>([\n {\n type: 'list',\n name: 'userChoice',\n message: `Please log in or sign up.`,\n choices: ['Login/Sign up', 'Skip'],\n },\n ]);\n\n if (userChoice !== 'Skip') {\n const cliContext = {\n logger,\n cwd: process.cwd(),\n };\n\n try {\n await cloudCli.login.action(cliContext);\n } catch (e: Error | CloudError | unknown) {\n logger.debug(e);\n try {\n assertCloudError(e);\n if (e.response.status === 403) {\n const message =\n typeof e.response.data === 'string'\n ? e.response.data\n : 'We are sorry, but we are not able to log you into Strapi Cloud at the moment.';\n logger.warn(message);\n return;\n }\n } catch (e) {\n /* empty */\n }\n logger.error(defaultErrorMessage);\n }\n }\n}\n"],"names":["assertCloudError","e","response","undefined","Error","handleCloudLogin","logger","cloudServices","createLogger","silent","debug","process","argv","includes","timestamp","cloudApiService","cloudApiFactory","defaultErrorMessage","data","config","log","parseToChalk","projectCreation","introText","error","userChoice","inquirer","prompt","type","name","message","choices","c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