diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs index a1a0ef3..8ee95ea 100644 --- a/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs @@ -10,18 +10,21 @@ public partial class MycroForge { public class Init : Command, ISubCommandOf { + private static readonly Argument NameArgument = + new(name: "name", description: "The name of your project"); + private readonly ProjectContext _context; - + public Init(ProjectContext context) : base("init", "Initialize a basic plugin project") { _context = context; - this.SetHandler(ExecuteAsync); + AddArgument(NameArgument); + this.SetHandler(ExecuteAsync, NameArgument); } - private void ExecuteAsync() + private async Task ExecuteAsync(string name) { - foreach (var plugin in Plugins.Loaded) - Console.WriteLine($"name: {plugin.Name}, command: {plugin.Command}"); + await _context.Bash($"dotnet new m4gp -n {name}"); } } } diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.List.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.List.cs index 56324b0..13da7fb 100644 --- a/MycroForge.CLI/Commands/MycroForge.Plugin.List.cs +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.List.cs @@ -19,7 +19,7 @@ public partial class MycroForge private void ExecuteAsync() { foreach (var plugin in Plugins.Loaded) - Console.WriteLine($"name: {plugin.Name}, command: {plugin.Command}"); + Console.WriteLine($"{plugin.Name}"); } } } diff --git a/MycroForge.CLI/Commands/MycroForge.cs b/MycroForge.CLI/Commands/MycroForge.cs index 7191df2..f51419c 100644 --- a/MycroForge.CLI/Commands/MycroForge.cs +++ b/MycroForge.CLI/Commands/MycroForge.cs @@ -1,11 +1,10 @@ using System.CommandLine; using MycroForge.Core.Contract; -using Core_RootCommand = MycroForge.Core.RootCommand; using RootCommand = MycroForge.Core.RootCommand; namespace MycroForge.CLI.Commands; -public sealed partial class MycroForge : Core_RootCommand +public sealed partial class MycroForge : RootCommand { public override string Name => "m4g"; diff --git a/MycroForge.CLI/Extensions/ServiceCollectionExtensions.cs b/MycroForge.CLI/Extensions/ServiceCollectionExtensions.cs index fccc5ab..59ea70f 100644 --- a/MycroForge.CLI/Extensions/ServiceCollectionExtensions.cs +++ b/MycroForge.CLI/Extensions/ServiceCollectionExtensions.cs @@ -50,6 +50,7 @@ public static class ServiceCollectionExtensions // Register "m4g plugin" services.AddScoped, Commands.MycroForge.Plugin>(); + services.AddScoped, Commands.MycroForge.Plugin.Init>(); services.AddScoped, Commands.MycroForge.Plugin.List>(); services.AddScoped, Commands.MycroForge.Plugin.Install>(); services.AddScoped, Commands.MycroForge.Plugin.Uninstall>(); diff --git a/MycroForge.Core/Contract/ICommandPlugin.cs b/MycroForge.Core/Contract/ICommandPlugin.cs index 084f70e..ca49257 100644 --- a/MycroForge.Core/Contract/ICommandPlugin.cs +++ b/MycroForge.Core/Contract/ICommandPlugin.cs @@ -5,7 +5,6 @@ namespace MycroForge.Core.Contract; public interface ICommandPlugin { public string? Name { get; } - public string Command { get; } public void RegisterServices(IServiceCollection services); } \ No newline at end of file diff --git a/MycroForge.Core/MycroForge.Core.csproj b/MycroForge.Core/MycroForge.Core.csproj index f889ea0..7497971 100644 --- a/MycroForge.Core/MycroForge.Core.csproj +++ b/MycroForge.Core/MycroForge.Core.csproj @@ -5,6 +5,7 @@ enable enable MycroForge.Core + The MycroForge core package 1.0.0 Donné Napo Dev Disciples diff --git a/MycroForge.Core/README.md b/MycroForge.Core/README.md index c4ac56f..2fcae58 100644 --- a/MycroForge.Core/README.md +++ b/MycroForge.Core/README.md @@ -1,5 +1,6 @@ ### Publish to local nuget repo ```shell -dotnet nuget push ./bin/Debug/MycroForge.Core.1.0.0.nupkg --source http://localhost:5555/v3/index.json --api-key password +dotnet build -r Release +dotnet nuget push ./bin/Release/MycroForge.Core.1.0.0.nupkg --source http://localhost:5555/v3/index.json --api-key password ``` \ No newline at end of file diff --git a/MycroForge.Package.PluginTemplate/MycroForge.Package.PluginTemplate.csproj b/MycroForge.Package.PluginTemplate/MycroForge.Package.PluginTemplate.csproj new file mode 100644 index 0000000..f2fb2ba --- /dev/null +++ b/MycroForge.Package.PluginTemplate/MycroForge.Package.PluginTemplate.csproj @@ -0,0 +1,28 @@ + + + + + + MycroForge.Package.PluginTemplate + 1.0 + A template for generating MycroForge plugins + Donné Napo + Template to use when creating a plugin for the MycroForge CLI. + dotnet-new;templates; + https://github.com/mdnapo/myrcoforge + + Template + net8.0 + true + false + content + $(NoWarn);NU5128 + true + + + + + + + + diff --git a/MycroForge.Package.PluginTemplate/README.md b/MycroForge.Package.PluginTemplate/README.md new file mode 100644 index 0000000..6b70900 --- /dev/null +++ b/MycroForge.Package.PluginTemplate/README.md @@ -0,0 +1,15 @@ +### Used resources + +https://www.youtube.com/watch?v=XzD-95qfWJM +https://www.youtube.com/watch?v=rdWZo5PD9Ek +https://learn.microsoft.com/en-us/dotnet/core/tutorials/cli-templates-create-template-package?pivots=dotnet-8-0 + + +### Build the package +`dotnet pack` + +### Push to local nuget +`dotnet nuget push ./bin/Release/MycroForge.Package.PluginTemplate.1.0.0.nupkg --source http://localhost:5555/v3/index.json --api-key password` + +### Install template package from local nuget +`dotnet new install MycroForge.Package.PluginTemplate --nuget-source http://localhost:5555/v3/index.json --force` diff --git a/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/.template.config/template.json b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/.template.config/template.json new file mode 100644 index 0000000..7a6825c --- /dev/null +++ b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/.template.config/template.json @@ -0,0 +1,21 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "Donné Napo", + "defaultName": "My.Plugin", + "name": "MycroForge plugin template", + "description": "Creates a basic MycroForge plugin project", + "projectURL": "https://github.com/mdnapo/mycroforge", + "repository": { + "url": "https://github.com/", + "type": "GitHub" + }, + "classifications": ["Console","Plugin"], + "identity": "MycroForge.PluginTemplate", + "shortName": "m4gp", + "sourceName": "MycroForge.PluginTemplate", + "tags": { + "language": "C#", + "type": "project" + }, + "preferNameDirectory": true +} \ No newline at end of file diff --git a/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/HelloWorldCommand.cs b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/HelloWorldCommand.cs new file mode 100644 index 0000000..f4eca18 --- /dev/null +++ b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/HelloWorldCommand.cs @@ -0,0 +1,36 @@ +using System.CommandLine; +using MycroForge.Core; +using MycroForge.Core.Contract; +using RootCommand = MycroForge.Core.RootCommand; + +namespace MycroForge.PluginTemplate; + +public class HelloWorldCommand : Command, ISubCommandOf +{ + private readonly Argument NameArgument = + new(name: "name", description: "The name of the person to greet"); + + private readonly Option AllCapsOption = + new(aliases: ["-a", "--all-caps"], description: "Print the name in all caps"); + + private readonly ProjectContext _context; + + public HelloWorldCommand(ProjectContext context) : + base("hello", "An example command generated by dotnet new using the m4gp template") + { + _context = context; + AddArgument(NameArgument); + AddOption(AllCapsOption); + this.SetHandler(ExecuteAsync, NameArgument, AllCapsOption); + } + + private async Task ExecuteAsync(string name, bool allCaps) + { + name = allCaps ? name.ToUpper() : name; + + await _context.CreateFile("hello_world.txt", + $"Hello {name}!", + "This file was generated by your custom command!" + ); + } +} \ No newline at end of file diff --git a/MycroForge.Plugin.Template/HelloWorldCommandPlugin.cs b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs similarity index 67% rename from MycroForge.Plugin.Template/HelloWorldCommandPlugin.cs rename to MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs index 274477e..7982dd1 100644 --- a/MycroForge.Plugin.Template/HelloWorldCommandPlugin.cs +++ b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs @@ -2,12 +2,11 @@ using MycroForge.Core.Contract; using RootCommand = MycroForge.Core.RootCommand; -namespace MycroForge.Plugin.Template; +namespace MycroForge.PluginTemplate; public class HelloWorldCommandPlugin : ICommandPlugin { - public string Name => "MycroForge.Plugin.Template"; - public string Command => Constants.MainCommandName; + public string Name => "MycroForge.PluginTemplate"; public void RegisterServices(IServiceCollection services) { diff --git a/MycroForge.Plugin.Template/MycroForge.Plugin.Template.csproj b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/MycroForge.PluginTemplate.csproj similarity index 74% rename from MycroForge.Plugin.Template/MycroForge.Plugin.Template.csproj rename to MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/MycroForge.PluginTemplate.csproj index 86f4080..4943c9c 100644 --- a/MycroForge.Plugin.Template/MycroForge.Plugin.Template.csproj +++ b/MycroForge.Package.PluginTemplate/templates/MycroForge.PluginTemplate/MycroForge.PluginTemplate.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/MycroForge.Plugin.Template.Package/Class1.cs b/MycroForge.Plugin.Template.Package/Class1.cs deleted file mode 100644 index 5bc03f9..0000000 --- a/MycroForge.Plugin.Template.Package/Class1.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace MycroForge.Plugin.Template.Package; - -public class Class1 -{ -} \ No newline at end of file diff --git a/MycroForge.Plugin.Template/Constants.cs b/MycroForge.Plugin.Template/Constants.cs deleted file mode 100644 index 6c9c63b..0000000 --- a/MycroForge.Plugin.Template/Constants.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace MycroForge.Plugin.Template; - -public static class Constants -{ - public const string MainCommandName = "mj"; -} \ No newline at end of file diff --git a/MycroForge.Plugin.Template/HelloWorldCommand.cs b/MycroForge.Plugin.Template/HelloWorldCommand.cs deleted file mode 100644 index 6db9a9a..0000000 --- a/MycroForge.Plugin.Template/HelloWorldCommand.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.CommandLine; -using MycroForge.Core; -using MycroForge.Core.Contract; -using RootCommand = MycroForge.Core.RootCommand; - -namespace MycroForge.Plugin.Template; - -public class HelloWorldCommand : Command, ISubCommandOf -{ - private readonly ProjectContext _context; - - public HelloWorldCommand(ProjectContext context) : - base(Constants.MainCommandName, "Custom command for My Jewellery specific stuff") - { - _context = context; - this.SetHandler(ExecuteAsync); - } - - private async Task ExecuteAsync() - { - await _context.CreateFile("hello_world.txt", - "My Jewellery command plugin is working!" - ); - } -} \ No newline at end of file diff --git a/MycroForge.PluginTemplate/.template.config/template.json b/MycroForge.PluginTemplate/.template.config/template.json new file mode 100644 index 0000000..7a6825c --- /dev/null +++ b/MycroForge.PluginTemplate/.template.config/template.json @@ -0,0 +1,21 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "Donné Napo", + "defaultName": "My.Plugin", + "name": "MycroForge plugin template", + "description": "Creates a basic MycroForge plugin project", + "projectURL": "https://github.com/mdnapo/mycroforge", + "repository": { + "url": "https://github.com/", + "type": "GitHub" + }, + "classifications": ["Console","Plugin"], + "identity": "MycroForge.PluginTemplate", + "shortName": "m4gp", + "sourceName": "MycroForge.PluginTemplate", + "tags": { + "language": "C#", + "type": "project" + }, + "preferNameDirectory": true +} \ No newline at end of file diff --git a/MycroForge.PluginTemplate/HelloWorldCommand.cs b/MycroForge.PluginTemplate/HelloWorldCommand.cs new file mode 100644 index 0000000..f4eca18 --- /dev/null +++ b/MycroForge.PluginTemplate/HelloWorldCommand.cs @@ -0,0 +1,36 @@ +using System.CommandLine; +using MycroForge.Core; +using MycroForge.Core.Contract; +using RootCommand = MycroForge.Core.RootCommand; + +namespace MycroForge.PluginTemplate; + +public class HelloWorldCommand : Command, ISubCommandOf +{ + private readonly Argument NameArgument = + new(name: "name", description: "The name of the person to greet"); + + private readonly Option AllCapsOption = + new(aliases: ["-a", "--all-caps"], description: "Print the name in all caps"); + + private readonly ProjectContext _context; + + public HelloWorldCommand(ProjectContext context) : + base("hello", "An example command generated by dotnet new using the m4gp template") + { + _context = context; + AddArgument(NameArgument); + AddOption(AllCapsOption); + this.SetHandler(ExecuteAsync, NameArgument, AllCapsOption); + } + + private async Task ExecuteAsync(string name, bool allCaps) + { + name = allCaps ? name.ToUpper() : name; + + await _context.CreateFile("hello_world.txt", + $"Hello {name}!", + "This file was generated by your custom command!" + ); + } +} \ No newline at end of file diff --git a/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs b/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs new file mode 100644 index 0000000..7982dd1 --- /dev/null +++ b/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using MycroForge.Core.Contract; +using RootCommand = MycroForge.Core.RootCommand; + +namespace MycroForge.PluginTemplate; + +public class HelloWorldCommandPlugin : ICommandPlugin +{ + public string Name => "MycroForge.PluginTemplate"; + + public void RegisterServices(IServiceCollection services) + { + services.AddScoped, HelloWorldCommand>(); + } +} \ No newline at end of file diff --git a/MycroForge.Plugin.Template.Package/MycroForge.Plugin.Template.Package.csproj b/MycroForge.PluginTemplate/MycroForge.PluginTemplate.csproj similarity index 51% rename from MycroForge.Plugin.Template.Package/MycroForge.Plugin.Template.Package.csproj rename to MycroForge.PluginTemplate/MycroForge.PluginTemplate.csproj index 595335a..4943c9c 100644 --- a/MycroForge.Plugin.Template.Package/MycroForge.Plugin.Template.Package.csproj +++ b/MycroForge.PluginTemplate/MycroForge.PluginTemplate.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/MycroForge.sln b/MycroForge.sln index 0c8f317..8012ccf 100644 --- a/MycroForge.sln +++ b/MycroForge.sln @@ -6,9 +6,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.Core", "MycroFor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.TestPlugin", "MycroForge.TestPlugin\MycroForge.TestPlugin.csproj", "{7C479E68-98FA-4FBC-B5E4-7116015774B3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.Plugin.Template", "MycroForge.Plugin.Template\MycroForge.Plugin.Template.csproj", "{114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.Plugin.Template.Package", "MycroForge.Plugin.Template.Package\MycroForge.Plugin.Template.Package.csproj", "{FF110508-7D12-48DB-9484-8D2A0A5D29B8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.PluginTemplate", "MycroForge.PluginTemplate\MycroForge.PluginTemplate.csproj", "{114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -32,9 +30,5 @@ Global {114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}.Debug|Any CPU.Build.0 = Debug|Any CPU {114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}.Release|Any CPU.ActiveCfg = Release|Any CPU {114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}.Release|Any CPU.Build.0 = Release|Any CPU - {FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/nuget.docker-compose.yml b/nuget.docker-compose.yml new file mode 100644 index 0000000..4da2c8f --- /dev/null +++ b/nuget.docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.8' + +services: + nuget: + image: bagetter/bagetter:latest + container_name: nuget + volumes: + - 'nuget_data:/var/baget' + ports: + - '5555:8080' + +volumes: + nuget_data: \ No newline at end of file