BootstrapCommandConfigs.fromYaml constructor

BootstrapCommandConfigs.fromYaml(
  1. Map<Object?, Object?> yaml, {
  2. required String workspacePath,
})

Implementation

factory BootstrapCommandConfigs.fromYaml(
  Map<Object?, Object?> yaml, {
  required String workspacePath,
}) {
  final runPubGetInParallel =
      assertKeyIsA<bool?>(
        key: 'runPubGetInParallel',
        map: yaml,
        path: 'command/bootstrap',
      ) ??
      true;

  final runPubGetOffline =
      assertKeyIsA<bool?>(
        key: 'runPubGetOffline',
        map: yaml,
        path: 'command/bootstrap',
      ) ??
      false;

  final enforceLockfile =
      assertKeyIsA<bool?>(
        key: 'enforceLockfile',
        map: yaml,
        path: 'command/bootstrap',
      ) ??
      false;

  // Create a dummy pubspec name to be able to extract the constraints using
  // the pubspec parser.
  final bootstrapConstraints = Pubspec.fromJson(
    {'name': 'bootstrap', ...yaml},
    lenient: true,
  );

  final dependencyOverridePaths = assertListIsA<String>(
    key: 'dependencyOverridePaths',
    map: yaml,
    isRequired: false,
    assertItemIsA: (index, value) => assertIsA<String>(
      value: value,
      index: index,
      path: 'dependencyOverridePaths',
    ),
  );

  final hooksMap = assertKeyIsA<Map<Object?, Object?>?>(
    key: 'hooks',
    map: yaml,
    path: 'command/bootstrap',
  );
  final hooks = hooksMap != null
      ? LifecycleHooks.fromYaml(hooksMap, workspacePath: workspacePath)
      : LifecycleHooks.empty;

  final environment = bootstrapConstraints.environment;
  final dependencies = bootstrapConstraints.dependencies;
  final devDependencies = bootstrapConstraints.devDependencies;

  return BootstrapCommandConfigs(
    runPubGetInParallel: runPubGetInParallel,
    runPubGetOffline: runPubGetOffline,
    enforceLockfile: enforceLockfile,
    environment: environment.isEmpty ? null : environment,
    dependencies: dependencies.isEmpty ? null : dependencies,
    devDependencies: devDependencies.isEmpty ? null : devDependencies,
    dependencyOverridePaths: dependencyOverridePaths
        .map(
          (override) =>
              createGlob(override, currentDirectoryPath: workspacePath),
        )
        .toList(),
    hooks: hooks,
  );
}