create-strapi-app
Version:
Generate a new Strapi application.
1 lines • 5.36 kB
Source Map (JSON)
{"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<boolean> {\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 servers. Use strapi deploy command once the project is generated.';\n\n let cloudApiConfig;\n try {\n const { data: config } = await cloudApiService.config();\n cloudApiConfig = config;\n\n if (!config?.featureFlags?.cloudLoginPromptEnabled) {\n return false;\n }\n\n logger.log(parseToChalk(config.projectCreation.introText));\n } catch (e: unknown) {\n logger.debug(e);\n logger.error(defaultErrorMessage);\n return false;\n }\n const { userChoice } = await inquirer.prompt<{ userChoice: string }>(\n cloudApiConfig.projectCreation?.userChoice || [\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\n if (!userChoice.toLowerCase().includes('skip')) {\n const cliContext = {\n user: { id: '' }, // This will be set later when the user logs in\n logger,\n cwd: process.cwd(),\n ...(cloudApiConfig.projectCreation?.reference && {\n promptExperiment: cloudApiConfig.projectCreation?.reference,\n }),\n };\n\n try {\n await cloudCli.login.action(cliContext, { showDashboardLink: false });\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 servers at the moment.';\n logger.warn(message);\n return false;\n }\n } catch (e) {\n /* empty */\n }\n logger.error(defaultErrorMessage);\n return false;\n }\n\n return true;\n }\n\n return false;\n}\n"],"names":["assertCloudError","e","response","undefined","Error","handleCloudLogin","logger","cloudServices","createLogger","silent","debug","process","argv","includes","timestamp","cloudApiService","cloudApiFactory","defaultErrorMessage","cloudApiConfig","data","config","featureFlags","cloudLoginPromptEnabled","log","parseToChalk","projectCreation","introText","error","userChoice","inquirer","prompt","type","name","message","choices","toLowerCase","cliContext","user","id","cwd","reference","promptExperiment","cloudCli","login","action","showDashboardLink","status","warn"],"mappings":";;;;AAWA,SAASA,iBAAiBC,CAAU,EAAA;AAClC,IAAA,IAAI,CAACA,CAAiBC,QAAQ,KAAKC,SAAW,EAAA;AAC5C,QAAA,MAAMC,KAAM,CAAA,qBAAA,CAAA;AACd;AACF;AAEO,eAAeC,gBAAAA,GAAAA;IACpB,MAAMC,MAAAA,GAASC,QAAcC,CAAAA,YAAY,CAAC;QACxCC,MAAQ,EAAA,KAAA;AACRC,QAAAA,KAAAA,EAAOC,OAAQC,CAAAA,IAAI,CAACC,QAAQ,CAAC,SAAA,CAAA;QAC7BC,SAAW,EAAA;AACb,KAAA,CAAA;AACA,IAAA,MAAMC,eAAkB,GAAA,MAAMR,QAAcS,CAAAA,eAAe,CAAC;AAAEV,QAAAA;AAAO,KAAA,CAAA;AACrE,IAAA,MAAMW,mBACJ,GAAA,0HAAA;IAEF,IAAIC,cAAAA;IACJ,IAAI;AACF,QAAA,MAAM,EAAEC,IAAMC,EAAAA,MAAM,EAAE,GAAG,MAAML,gBAAgBK,MAAM,EAAA;QACrDF,cAAiBE,GAAAA,MAAAA;QAEjB,IAAI,CAACA,MAAQC,EAAAA,YAAAA,EAAcC,uBAAyB,EAAA;YAClD,OAAO,KAAA;AACT;AAEAhB,QAAAA,MAAAA,CAAOiB,GAAG,CAACC,YAAAA,CAAaJ,MAAOK,CAAAA,eAAe,CAACC,SAAS,CAAA,CAAA;AAC1D,KAAA,CAA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