setAppPkgRoot function

void setAppPkgRoot (
  1. String app
)

Implementation

void setAppPkgRoot(String app) async {
  // Config.ppLogger.v('getAppPkgRoot');

  // getting launch directory for script is not enough,
  // since the script may be run from some other place, as
  // in the case of pub global installed binaries launched
  // from ~/.pub-cache/global_packages.
  // So we need to find the pkg root directory, which is
  // recorded in ./.packages, which is in the launch dir.

  var currentIsoPkgConfigUri;
  try {
    currentIsoPkgConfigUri = await Isolate.packageConfig;
  } catch (e) {
    print(e);
    Config.ppLogger.e(e);
    exit(0);
  }
  Config.isoHome = path.dirname(currentIsoPkgConfigUri.path);
  // if (Config.debug) {
  //   // e.g. file:///Users/gar/mobileink/dartrix/.packages
  //   Config.ppLogger.v('$app app pkg cfg: $currentIsoPkgConfigUri');
  // }
  // Isolate.packageConfig finds the version 1 .packages file;
  // use that to get the PackageConfig and you get the contents
  // of the version 2 .dart_tool/package_config.json
  // findPackageConfigUri is a fn in package:package_confg
  //PackageConfig
  var pkgConfig = await findPackageConfigUri(currentIsoPkgConfigUri);
  // if (Config.debug) {
  //   // PackageConfig is an object containing list of deps
  //   // Config.debugLogger.d('current iso PackageConfig: $pkgConfig');
  //   debug.debugPackageConfig(pkgConfig);
  // }
  // Now we need to find the dep entry for the app.
  // 'Package': object with keys name, packageUriRoot, and root (=pkgRoot)
  // Package
  var appConfig = pkgConfig.packages.firstWhere((pkg) {
    return pkg.name == Config.appName;
  });
  // Config.logger.i('appConfig: ${appConfig.name} : ${appConfig.root}');
  //String
  Config.appPkgRoot = appConfig.root.path;
  // return Config.appPkgRoot;
}