create-strapi-app
Version:
Generate a new Strapi application.
64 lines (61 loc) • 2 kB
JavaScript
import inquirer from 'inquirer';
import { services, cli } from '@strapi/cloud-cli';
import parseToChalk from './utils/parse-to-chalk.mjs';
function assertCloudError(e) {
if (e.response === undefined) {
throw Error('Expected CloudError');
}
}
async function handleCloudLogin() {
const logger = services.createLogger({
silent: false,
debug: process.argv.includes('--debug'),
timestamp: false
});
const cloudApiService = await 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 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);
}
}
}
export { handleCloudLogin };
//# sourceMappingURL=cloud.mjs.map