configureProjectFiles method

Future<void> configureProjectFiles(
  1. String projectName,
  2. Map<String, dynamic> options
)

Implementation

Future<void> configureProjectFiles(
  String projectName,
  Map<String, dynamic> options,
) async {
  final stateManagement = options['state_management'] as String;
  final router = options['router'] as String;
  final theme = options['theme'] as String;
  final networking = options['networking'] as String? ?? 'none';
  final storage = options['storage'] as String? ?? 'none';
  final localization = options['localization'] as bool? ?? false;

  final bootstrapDir = await _templateResolver.resolve(
    category: 'bootstrap',
    workingDirectory: workingDirectory,
    packageRootOverride: templatesRootOverride,
  );

  final variables = <String, String>{'project_name': projectName};
  final conditions = <String, bool>{
    'riverpod': stateManagement == 'riverpod',
    'bloc': stateManagement == 'bloc',
    'none': stateManagement == 'none',
    'go_router': router == 'go_router',
    'material3': theme == 'material3',
    'l10n': localization,
  };

  await _renderTemplateFile(
    sourceDir: bootstrapDir,
    fileName: 'main.dart',
    targetPath: p.join(projectName, 'lib', 'main.dart'),
    variables: variables,
    conditions: conditions,
  );

  if (stateManagement == 'bloc') {
    await _renderTemplateFile(
      sourceDir: bootstrapDir,
      fileName: 'app_state.dart',
      targetPath: p.join(
        projectName,
        'lib',
        'core',
        'state',
        'app_state.dart',
      ),
      variables: variables,
      conditions: conditions,
    );

    await _renderTemplateFile(
      sourceDir: bootstrapDir,
      fileName: 'app_cubit.dart',
      targetPath: p.join(
        projectName,
        'lib',
        'core',
        'state',
        'app_cubit.dart',
      ),
      variables: variables,
      conditions: conditions,
    );
  }

  await _renderTemplateFile(
    sourceDir: bootstrapDir,
    fileName: 'app.dart',
    targetPath: p.join(projectName, 'lib', 'app', 'app.dart'),
    variables: variables,
    conditions: conditions,
  );

  await _renderTemplateFile(
    sourceDir: bootstrapDir,
    fileName: 'router.dart',
    targetPath: p.join(projectName, 'lib', 'app', 'router.dart'),
    variables: variables,
    conditions: conditions,
  );

  if (networking != 'none') {
    await _renderNetworkFiles(projectName, networking);
  }

  await _renderErrorFiles(projectName, networking);

  if (storage != 'none') {
    await _renderStorageFiles(projectName, storage);
  }

  if (localization) {
    await _renderTemplateFile(
      sourceDir: bootstrapDir,
      fileName: 'l10n.yaml',
      targetPath: p.join(projectName, 'l10n.yaml'),
      variables: variables,
      conditions: conditions,
    );

    Directory(p.join(projectName, 'lib', 'l10n')).createSync(recursive: true);
    await _renderTemplateFile(
      sourceDir: bootstrapDir,
      fileName: 'app_en.arb',
      targetPath: p.join(projectName, 'lib', 'l10n', 'app_en.arb'),
      variables: variables,
      conditions: conditions,
    );
  }

  final analysisOptions =
      options['analysis_options'] as Map<String, dynamic>?;
  if (analysisOptions != null) {
    _renderAnalysisOptions(projectName, analysisOptions);
  }
}