createProject static method
Subcommand to create a new tenant project.
Implementation
static Future<void> createProject(
final Client cloudApiClient, {
required final CommandLogger logger,
required final String projectId,
required final bool enableDb,
required final String projectDir,
required final String configFilePath,
final bool skipConfirmation = false,
}) async {
if (!skipConfirmation) {
await UserConfirmations.confirmNewProjectCostAcceptance(logger);
}
// Check that the user is on a plan and automatically procure one if not.
// This behavior will be changed in the future.
final planNames = await cloudApiClient.plans.listProcuredPlanNames();
if (planNames.isEmpty) {
await cloudApiClient.plans.procurePlan(planProductName: defaultPlanName);
logger.init('Creating Serverpod Cloud project "$projectId".');
logger.info('On plan: $defaultPlanName');
} else {
logger.init('Creating Serverpod Cloud project "$projectId".');
logger.debug('On plan: ${planNames.first}');
}
try {
await logger.progress(
'Registering Serverpod Cloud project.',
newParagraph: true,
() async {
await cloudApiClient.projects.createProject(
cloudProjectId: projectId,
);
return true;
},
);
} on Exception catch (e, s) {
throw FailureException.nested(
e,
s,
'Request to create a new project failed',
);
}
if (enableDb) {
await logger.progress('Requesting database creation.', () async {
try {
await cloudApiClient.infraResources.enableDatabase(
cloudCapsuleId: projectId,
);
return true;
} on Exception catch (e, s) {
throw FailureException.nested(
e,
s,
'Request to create a database for the new project failed',
);
}
});
}
logger.success('Serverpod Cloud project created.', newParagraph: true);
}