示例#1
0
 private Version GetActiveVersion()
 {
     try
     {
         var str = File.ReadAllText(_globalContext.ActiveVersionTrackerFilePath);
         return(VersionParser.Parse(str));
     }
     catch (FileNotFoundException)
     {
         return(null);
     }
 }
示例#2
0
        /// <summary>
        /// Get the latest Node version matching a given prefix.
        /// </summary>
        /// <exception cref="ArgumentException"></exception>
        public Version GetLatestNodeVersion(string prefix)
        {
            var    reader = NodeVersionsStreamReader();
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var lineVersion = VersionParser.Parse(line.Split("\t")[0]);
                if (lineVersion.ToString().StartsWith(prefix))
                {
                    return(lineVersion);
                }
            }

            throw new ArgumentException($"NodeJS distribution not found for given prefix: {prefix}");
        }
示例#3
0
        /// <summary>
        /// Get the versions of Node that may be installed.
        /// </summary>
        public List <Version> GetInstallableNodeVersions(string min = "")
        {
            var minVersion = VersionParser.Parse(min != "" ? min : "0.0.0");

            var    versions = new List <Version>();
            var    reader   = NodeVersionsStreamReader();
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var lineVersion = VersionParser.Parse(line.Split("\t")[0]);
                if (lineVersion >= minVersion)
                {
                    versions.Add(lineVersion);
                }
            }

            return(versions);
        }
示例#4
0
        public List <NodeJsVersion> GetInstalledVersions()
        {
            var activeVersion = GetActiveVersion();

            return
                (Directory
                 .GetDirectories(_globalContext.StoragePath, "node-v*", SearchOption.TopDirectoryOnly)
                 .Select(dir =>
            {
                var version = VersionParser.Parse(Regex.Match(dir, @"node-v(\d+\.\d+\.\d+)").Groups[1].Value);
                return new NodeJsVersion
                {
                    Path = dir,
                    Version = version,
                    IsActive = version.Equals(activeVersion)
                };
            })
                 .OrderByDescending(v => v.Version)
                 .ToList());
        }
示例#5
0
 /// <summary>
 /// Get the most recent Node version.
 /// </summary>
 public Version GetLatestNodeVersion()
 {
     return(VersionParser.Parse(NodeVersionsStreamReader().ReadLine()?.Split("\t")[0]));
 }