Esempio n. 1
0
        internal async Task <int> Main()
        {
            var plugin = new Name(this.Plugin);

            Definition definition;

            try
            {
                Environment.CurrentDirectory = PathManager.FindResource();

                definition = Definition.Load(Program.DefinitionFile);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Use `nfpm init` to setup NFive in this directory");

                return(1);
            }

            definition.Dependencies?.Remove(plugin);

            var venderPath = Path.Combine(Environment.CurrentDirectory, Program.PluginPath, plugin.Vendor);

            if (Directory.Exists(venderPath))
            {
                var projectPath = Path.Combine(venderPath, plugin.Project);

                if (Directory.Exists(projectPath))
                {
                    Directory.Delete(projectPath, true);
                }

                if (!Directory.EnumerateFileSystemEntries(venderPath).Any())
                {
                    Directory.Delete(venderPath);
                }
            }

            // TODO: Remove orphaned child dependencies

            var graph = new DefinitionGraph();
            await graph.Build(definition);

            await graph.Apply();

            definition.Save(Program.DefinitionFile);
            graph.Save();
            ResourceGenerator.Serialize(graph).Save();

            return(0);
        }
Esempio n. 2
0
        public override async Task <int> Main()
        {
            var definition = LoadDefinition(this.Verbose);

            foreach (var plugin in this.Plugins)
            {
                var name = new Name(plugin);                 // TODO: Handle

                if (definition.Dependencies == null || !definition.Dependencies.ContainsKey(name))
                {
                    continue;
                }

                if (!this.Quiet)
                {
                    Console.WriteLine("- ", name.ToString().White());
                }

                definition.Dependencies.Remove(name);

                Directory.Delete(Path.Combine(Environment.CurrentDirectory, ConfigurationManager.PluginPath, name.Vendor, name.Project), true);
            }

            var graph = new DefinitionGraph();
            await graph.Apply(definition);

            definition.Save(ConfigurationManager.DefinitionFile);
            graph.Save();

            if (PathManager.IsResource())
            {
                ResourceGenerator.Serialize(graph);
            }

            return(0);
        }
Esempio n. 3
0
        public override async Task <int> Main()
        {
            var definition = LoadDefinition();
            var graph      = LoadGraph();

            // New plugins
            if (this.Plugins.Any())
            {
                foreach (var plugin in this.Plugins)
                {
                    var input = plugin;

                    // Local install
                    if (Directory.Exists(plugin) && File.Exists(Path.Combine(plugin, ConfigurationManager.DefinitionFile)))
                    {
                        var path = Path.GetFullPath(plugin);

                        var pluginDefinition = Plugin.Load(Path.Combine(path, ConfigurationManager.DefinitionFile));

                        if (definition.Repositories == null)
                        {
                            definition.Repositories = new List <Repository>();
                        }

                        definition.Repositories.RemoveAll(r => r.Name == pluginDefinition.Name);
                        definition.Repositories.Add(new Repository
                        {
                            Name = pluginDefinition.Name,
                            Type = "local",
                            Path = path
                        });

                        input = pluginDefinition.Name;
                    }

                    var parts = input.Split(new[] { '@' }, 2);
                    var name  = new Name(parts[0].Trim());

                    var versionInput = parts.Length == 2 ? parts[1].Trim() : "*";

                    Models.VersionRange range   = null;
                    Version             version = null;
                    PartialVersion      partial = null;

                    try
                    {
                        partial = new PartialVersion(versionInput);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    var isSpecific = partial?.Major != null && partial.Minor.HasValue && partial.Patch.HasValue;

                    try
                    {
                        range = new Models.VersionRange(versionInput);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    try
                    {
                        version = new Version(versionInput);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    List <Version> versions;
                    try
                    {
                        var adapter = new AdapterBuilder(name, definition).Adapter();
                        versions = (await adapter.GetVersions()).ToList();
                    }
                    catch (WebException ex) when((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
                    {
                        Console.WriteLine("Error ".DarkRed(), $"{name}".Red(), " not found.".DarkRed());

                        return(1);
                    }

                    var versionMatch = range.MaxSatisfying(versions);
                    if (versionMatch == null)
                    {
                        Console.WriteLine("Error ".DarkRed(), $"{name}@{range}".Red(), " not found, available versions: ".DarkRed(), string.Join(" ", versions.Select(v => v.ToString())).Red());

                        return(1);
                    }

                    if (definition.Dependencies == null)
                    {
                        definition.Dependencies = new Dictionary <Name, SDK.Core.Plugins.VersionRange>();
                    }
                    definition.Dependencies[name] = new Models.VersionRange("^" + (isSpecific ? partial.ToZeroVersion() : version ?? versionMatch));

                    Console.WriteLine("+ ", $"{name}@{definition.Dependencies[name]}".White());
                }

                graph = new DefinitionGraph();
                await graph.Apply(definition);

                definition.Save(ConfigurationManager.DefinitionFile);
                graph.Save();
            }
            else
            {
                if (graph != null)
                {
                    await graph.Apply();
                }
                else
                {
                    graph = new DefinitionGraph();

                    await graph.Apply(definition);

                    graph.Save();
                }
            }

            if (PathManager.IsResource())
            {
                ResourceGenerator.Serialize(graph);
            }

            return(0);
        }
Esempio n. 4
0
        internal async Task <int> Main()
        {
            Definition definition;

            try
            {
                Environment.CurrentDirectory = PathManager.FindResource();

                definition = Definition.Load(Program.DefinitionFile);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Use `nfpm init` to setup NFive in this directory");

                return(1);
            }

            DefinitionGraph graph;

            try
            {
                graph = DefinitionGraph.Load();
            }
            catch (FileNotFoundException)
            {
                graph = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to build definition graph (PANIC):", Color.Red);
                Console.WriteLine(ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }

                return(1);
            }

            if (!this.Plugins.Any())
            {
                if (graph != null)
                {
                    await graph.Apply();

                    if (PathManager.IsResource())
                    {
                        ResourceGenerator.Serialize(graph).Save();
                    }
                }
                else
                {
                    graph = new DefinitionGraph();
                    await graph.Build(definition);

                    await graph.Apply();

                    graph.Save();

                    if (PathManager.IsResource())
                    {
                        ResourceGenerator.Serialize(graph).Save();
                    }
                }

                return(0);
            }

            foreach (var plugin in this.Plugins)
            {
                var  parts = plugin.Split(new[] { '@' }, 2);
                Name name;
                var  version = new VersionRange("*");

                try
                {
                    name = new Name(parts[0]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(1);
                }

                if (parts.Length == 2)
                {
                    try
                    {
                        version = new VersionRange(parts[1]);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        return(1);
                    }
                }

                if (definition.Dependencies == null)
                {
                    definition.Dependencies = new Dictionary <Name, VersionRange>();
                }

                if (definition.Dependencies.ContainsKey(name))
                {
                    definition.Dependencies[name] = version;
                }
                else
                {
                    definition.Dependencies.Add(name, version);
                }
            }

            graph = new DefinitionGraph();
            await graph.Build(definition);

            await graph.Apply();

            definition.Save(Program.DefinitionFile);
            graph.Save();

            if (PathManager.IsResource())
            {
                ResourceGenerator.Serialize(graph).Save();
            }

            return(0);
        }