setup method

Future<bool> setup({
  1. required InitConfig config,
  2. required TemplateDefinition template,
  3. bool overwrite = false,
  4. bool runFlutterCommands = true,
})

Sets up the project using the provided config and template.

Returns whether the project setup process completed successfully.

Implementation

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

  if (setup.modules.isEmpty &&
      setup.features.isEmpty &&
      !setup.bootstrap.enabled) {
    LoggerService.warning(
      'No project setup configuration found for template '
      '"${template.name}".',
    );

    return false;
  }

  _validateBootstrapTargets(template);

  final pubspec = PubspecService(runPubGet: runFlutterCommands);

  await _prepareProject(
    config: config,
    runFlutterCommands: runFlutterCommands,
  );

  await _collectTemplateRequirements(
    template: template,
    pubspec: pubspec,
  );

  final moduleRequiresBuildRunner = await _installModules(
    config: config,
    template: template,
    modules: setup.modules,
    pubspec: pubspec,
    overwrite: overwrite,
    defaultsOnly: overwrite,
    runFlutterCommands: runFlutterCommands,
  );

  // Synchronize all collected template and module dependencies once.
  await pubspec.save();

  final featuresGenerated = await _generateFeatures(
    config: config,
    template: template,
    features: setup.features,
    overwrite: overwrite,
    runFlutterCommands: runFlutterCommands,
  );

  await const ProjectBootstrapService().bootstrap(
    config: config,
    template: template,
    overwrite: overwrite,
  );

  if (config.localization.enabled) {
    await _wireLocalization(
      config: config,
      template: template,
    );
  }

  if (runFlutterCommands) {
    await FlutterService(config).postGenerate(
      buildRunner: template.requirements.buildRunner ||
          moduleRequiresBuildRunner ||
          featuresGenerated,
    );
  }

  return true;
}