fixTemplatePubspec function

  1. @visibleForTesting
void fixTemplatePubspec(
  1. String projectName,
  2. PubSpec pubSpec,
  3. String pathToPubSpec
)

update the templates dcli version to match the dcli version the user is running. @Throwing(PubSpecException)

Implementation

@visibleForTesting
void fixTemplatePubspec(
    String projectName, PubSpec pubSpec, String pathToPubSpec) {
  final current = pubSpec.dependencies;

  if (current.exists('dcli')) {
    final dcli = current['dcli'];

    if (dcli is DependencyVersioned) {
      (dcli! as DependencyVersioned).versionConstraint = packageVersion;
    }
  }

  pubSpec
    ..name.set(_replaceInvalidCharactersForName(projectName))
    ..saveTo(pathToPubSpec);
}