mirror of
https://github.com/strapi/strapi.git
synced 2025-06-27 00:41:25 +00:00
chore: update cloud cli (#23392)
* chore: update cloud cli * chore: condition to include prompt property * chore: fix verification * fix: lint errors * fix: prettier issue --------- Co-authored-by: Dimitris Messinis <dimitris.messinis@strapi.io> Co-authored-by: Simone Taeggi <startae14@gmail.com>
This commit is contained in:
parent
59bf9b3f30
commit
0cf1e6de90
@ -52,7 +52,7 @@ For more information, see
|
||||
- https://v4.zod.dev/
|
||||
- https://v4.zod.dev/json-schema
|
||||
- https://v4.zod.dev/metadata
|
||||
:::
|
||||
:::
|
||||
|
||||
### [Debug](https://github.com/debug-js/debug)
|
||||
|
||||
|
@ -25,7 +25,7 @@ export async function promptLogin(ctx: CLIContext) {
|
||||
}
|
||||
|
||||
export default async function loginAction(ctx: CLIContext): Promise<boolean> {
|
||||
const { logger } = ctx;
|
||||
const { logger, promptExperiment } = ctx;
|
||||
const tokenService = await tokenServiceFactory(ctx);
|
||||
const existingToken = await tokenService.retrieveToken();
|
||||
const cloudApiService = await cloudApiFactory(ctx, existingToken || undefined);
|
||||
@ -62,7 +62,9 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
|
||||
logger.debug(e);
|
||||
return false;
|
||||
}
|
||||
await trackEvent(ctx, cloudApiService, 'willLoginAttempt', {});
|
||||
await trackEvent(ctx, cloudApiService, 'willLoginAttempt', {
|
||||
...(promptExperiment && { promptExperiment }),
|
||||
});
|
||||
|
||||
logger.debug('🔐 Creating device authentication request...', {
|
||||
client_id: cliConfig.clientId,
|
||||
@ -155,7 +157,10 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
|
||||
'There seems to be a problem with your login information. Please try logging in again.'
|
||||
);
|
||||
spinnerFail();
|
||||
await trackEvent(ctx, cloudApiService, 'didNotLogin', { loginMethod: 'cli' });
|
||||
await trackEvent(ctx, cloudApiService, 'didNotLogin', {
|
||||
loginMethod: 'cli',
|
||||
...(promptExperiment && { promptExperiment }),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
@ -164,7 +169,10 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
|
||||
) {
|
||||
logger.debug(e);
|
||||
spinnerFail();
|
||||
await trackEvent(ctx, cloudApiService, 'didNotLogin', { loginMethod: 'cli' });
|
||||
await trackEvent(ctx, cloudApiService, 'didNotLogin', {
|
||||
loginMethod: 'cli',
|
||||
...(promptExperiment && { promptExperiment }),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Await interval before retrying
|
||||
@ -179,7 +187,10 @@ export default async function loginAction(ctx: CLIContext): Promise<boolean> {
|
||||
'To access your dashboard, please copy and paste the following URL into your web browser:'
|
||||
);
|
||||
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
||||
await trackEvent(ctx, cloudApiService, 'didLogin', { loginMethod: 'cli' });
|
||||
await trackEvent(ctx, cloudApiService, 'didLogin', {
|
||||
loginMethod: 'cli',
|
||||
...(promptExperiment && { promptExperiment }),
|
||||
});
|
||||
};
|
||||
|
||||
await authenticate();
|
||||
|
@ -21,6 +21,8 @@ export type CloudCliConfig = {
|
||||
questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>;
|
||||
defaults: Partial<ProjectAnswers>;
|
||||
introText: string;
|
||||
userChoice?: object;
|
||||
reference?: string;
|
||||
};
|
||||
projectDeployment: {
|
||||
confirmationText: string;
|
||||
@ -34,6 +36,7 @@ export type CloudCliConfig = {
|
||||
export interface CLIContext {
|
||||
cwd: string;
|
||||
logger: Logger;
|
||||
promptExperiment?: string;
|
||||
}
|
||||
|
||||
export type StrapiCloudCommand = (params: {
|
||||
|
@ -16,6 +16,7 @@ function assertCloudError(e: unknown): asserts e is CloudError {
|
||||
}
|
||||
|
||||
export async function handleCloudLogin(): Promise<void> {
|
||||
let cloudApiConfig;
|
||||
const logger = cloudServices.createLogger({
|
||||
silent: false,
|
||||
debug: process.argv.includes('--debug'),
|
||||
@ -27,25 +28,31 @@ export async function handleCloudLogin(): Promise<void> {
|
||||
|
||||
try {
|
||||
const { data: config } = await cloudApiService.config();
|
||||
cloudApiConfig = config;
|
||||
logger.log(parseToChalk(config.projectCreation.introText));
|
||||
} catch (e: unknown) {
|
||||
logger.debug(e);
|
||||
logger.error(defaultErrorMessage);
|
||||
return;
|
||||
}
|
||||
const { userChoice } = await inquirer.prompt<{ userChoice: string }>([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'userChoice',
|
||||
message: `Please log in or sign up.`,
|
||||
choices: ['Login/Sign up', 'Skip'],
|
||||
},
|
||||
]);
|
||||
const { userChoice } = await inquirer.prompt<{ userChoice: string }>(
|
||||
cloudApiConfig.projectCreation?.userChoice || [
|
||||
{
|
||||
type: 'list',
|
||||
name: 'userChoice',
|
||||
message: `Please log in or sign up.`,
|
||||
choices: ['Login/Sign up', 'Skip'],
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
if (userChoice !== 'Skip') {
|
||||
if (!userChoice.toLowerCase().includes('skip')) {
|
||||
const cliContext = {
|
||||
logger,
|
||||
cwd: process.cwd(),
|
||||
...(cloudApiConfig.projectCreation?.reference && {
|
||||
promptExperiment: cloudApiConfig.projectCreation?.reference,
|
||||
}),
|
||||
};
|
||||
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user