DartBuild constructor

DartBuild({
  1. String? appName,
  2. required String mainPath,
  3. String? appVersion,
  4. String? buildPreRelease,
  5. String? buildMetadata,
  6. List<String> buildArgs = const [],
  7. String? releaseFolder,
  8. List<String>? includedPaths,
  9. String? buildFolder,
  10. String? executableName,
  11. String? dartSdkPath,
})

Implementation

DartBuild({
  String? appName,
  required this.mainPath,
  String? appVersion,
  String? buildPreRelease,
  String? buildMetadata,
  this.buildArgs = const [],
  String? releaseFolder,
  List<String>? includedPaths,
  String? buildFolder,
  String? executableName,
  String? dartSdkPath,
})  : dartSdkPath = dartSdkPath ?? 'dart',
      releaseFolder = releaseFolder ?? 'build/releases',
      includedPaths = includedPaths ?? [] {
  _arch = getCpuArchitecture();
  final pubspecStr = File('pubspec.yaml').readAsStringSync();
  final pubspec = Pubspec.parse(pubspecStr);

  final buildVersion = resolveVersion(
    pubspecVersion: pubspec.version,
    appVersion: appVersion,
    buildVersion: null,
    buildPreRelease: buildPreRelease,
    buildMetadata: buildMetadata,
  );

  if (appVersion != null) {
    this.appVersion = appVersion;
  } else {
    this.appVersion = 'v${buildVersion.canonicalizedVersion}';
  }

  if (appName == null) {
    this.appName = pubspec.name;
  } else {
    this.appName = appName;
  }
  if (executableName == null) {
    String execName = this.appName.replaceAll('_', '-');
    if (Platform.isWindows) {
      execName += '.exe';
    }
    this.executableName = execName;
  } else {
    this.executableName = executableName;
  }
  if (buildFolder == null) {
    this.buildFolder = 'bin';
  } else {
    this.buildFolder = buildFolder;
  }
}