createProject static method

Future<void> createProject(
  1. Client cloudApiClient, {
  2. required CommandLogger logger,
  3. required String projectId,
  4. required bool enableDb,
  5. required String projectDir,
  6. required String configFilePath,
  7. bool skipConfirmation = false,
})

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);
}