checkForUpdate function

void checkForUpdate()

Implementation

void checkForUpdate() async {
  if (!CliConfig.updateIsCheckingToday()) {
    if (!isDevVersion()) {
      await PubDevApi.getLatestVersionFromPackage('gen_cli')
          .then((versionInPubDev) async {
        await PubspecLock.getVersionCli(disableLog: true)
            .then((versionInstalled) async {
          if (versionInstalled == null) exit(2);

          final v1 = Version.parse(versionInPubDev!);
          final v2 = Version.parse(versionInstalled);
          final needsUpdate = v1.compareTo(v2);
          // needs update.
          if (needsUpdate == 1) {
            LogService.info('新版本可用!当前版本: %s'.trArgs([versionInstalled]));
            //await versionCommand();
            printGetCli();
            final String codeSample = LogService.code('get update');
            LogService.info(
                '${'新版本可用: %s 运行:'.trArgs([versionInPubDev])}${' $codeSample'}',
                false,
                true);
          }
        });
      });
      CliConfig.setUpdateCheckToday();
    }
  }
}