version-anchor.ts 858 B

1234567891011121314151617181920212223242526272829
  1. import { hasCommand, spawnCommand } from './commands';
  2. import { Language } from './localization';
  3. import {
  4. getVersionAndVersionWithoutPatch,
  5. getVersionFromStdout,
  6. ResolvedVersion,
  7. Version,
  8. } from './version-core';
  9. export async function detectAnchorVersion(
  10. language: Language
  11. ): Promise<Version> {
  12. const hasAnchorCli = await hasCommand('anchor');
  13. if (!hasAnchorCli) {
  14. throw new Error(
  15. language.errors.solanaCliNotFound.replace('$command', 'anchor')
  16. );
  17. }
  18. return getVersionFromStdout(spawnCommand('anchor', ['--version']));
  19. }
  20. export function resolveAnchorVersion(
  21. detectedVersion: Version | undefined
  22. ): ResolvedVersion | undefined {
  23. if (!detectedVersion) return undefined;
  24. const [full, withoutPatch] =
  25. getVersionAndVersionWithoutPatch(detectedVersion);
  26. return { full, withoutPatch, detected: detectedVersion };
  27. }