コード例 #1
0
ファイル: Remove.cs プロジェクト: TheBaconSpace/nfpm
        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);
        }
コード例 #2
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);
        }