Esempio n. 1
0
        public static async Task Run(IEnumerable <string> args)
        {
            var argList = args.ToList();
            HashSet <string> packages = null;

            if (argList.Count > 0)
            {
                if (argList[0] == "--help" || argList[0] == "-h")
                {
                    Help.Upgrade();
                    return;
                }
                else
                {
                    packages = new HashSet <string>(argList, StringComparer.OrdinalIgnoreCase);
                }
            }

            if (!Directory.Exists(BaseDirectory))
            {
                Directory.CreateDirectory(BaseDirectory);
            }

            var entries = await UnpkgJson.Load();

            if (packages != null)
            {
                entries = entries.Where(e => packages.Contains(e.PackageName)).ToArray();
            }

            entries = (await Task.WhenAll(entries.Select(GetDistFile)))
                      .Where((e, d) => VersionComparison.IsGreater(d.Version, e.Version))
                      .Select((e, _) => e)
                      .ToArray();

            foreach (var entry in entries)
            {
                foreach (var file in entry.Files)
                {
                    if (File.Exists(file.LocalPath))
                    {
                        File.Delete(file.LocalPath);
                    }
                }
            }

            await Add.Run(entries.Select(e => e.PackageName));
        }
Esempio n. 2
0
        public static async Task Run(IEnumerable <string> args)
        {
            var argList = args.ToList();

            if (argList[0] == "--help" || argList[0] == "-h")
            {
                Help.Add();
                return;
            }

            if (!Directory.Exists(BaseDirectory))
            {
                Directory.CreateDirectory(BaseDirectory);
            }

            var results = await Task.WhenAll(argList.Select(AddPackage));

            await UnpkgJson.Save(results);
        }
Esempio n. 3
0
        public static async Task <DistFile> Get(string package)
        {
            var response = await Find(package);

            var url = response.RequestMessage.RequestUri.AbsolutePath;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine($"Found {UnpkgJson.CleanVersion(url)}");
                var json = await response.Content.ReadAsStringAsync();

                var distFile = JsonConvert.DeserializeObject <DistFile>(json);
                distFile.BaseUrl = EndPart.Replace(url, string.Empty);
                return(distFile);
            }

            Console.Error.WriteLine($"{url} returned status {(int)response.StatusCode}.");
            return(null);
        }