bootstrap method

Future<bool> bootstrap({
  1. required InitConfig config,
  2. required TemplateDefinition template,
})

Bootstraps the project using the provided config and template.

Returns false when project bootstrapping is disabled for the selected template. Otherwise, performs the configured bootstrap operations and returns whether the bootstrap process completed successfully.

Implementation

Future<bool> bootstrap({
  required InitConfig config,
  required TemplateDefinition template,
}) async {
  final bootstrap = template.setup.bootstrap;

  if (!bootstrap.enabled) {
    LoggerService.info(
      'Project bootstrap is not enabled for template '
      '"${template.name}".',
    );

    return false;
  }

  LoggerService.section('Bootstrapping Application');

  final variables = <String, String>{
    'projectName': config.projectName,
  };

  var generatedAny = false;

  final app = bootstrap.app;

  if (app != null) {
    final generated = await _generateBootstrapFile(
      templateRoot: template.name,
      templatePath: app.template,
      outputPath: app.output,
      variables: variables,
    );

    generatedAny = generatedAny || generated;
  }

  final main = bootstrap.main;

  if (main != null) {
    final generated = await _generateBootstrapFile(
      templateRoot: template.name,
      templatePath: main.template,
      outputPath: main.output,
      variables: variables,
    );

    generatedAny = generatedAny || generated;
  }

  return generatedAny;
}