Modified plugin system code
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- The package metadata. Fill in the properties marked as TODO below -->
|
||||
<!-- Follow the instructions on https://learn.microsoft.com/nuget/create-packages/package-authoring-best-practices -->
|
||||
<PackageId>MycroForge.Package.PluginTemplate</PackageId>
|
||||
<PackageVersion>1.0</PackageVersion>
|
||||
<Title>A template for generating MycroForge plugins</Title>
|
||||
<Authors>Donné Napo</Authors>
|
||||
<Description>Template to use when creating a plugin for the MycroForge CLI.</Description>
|
||||
<PackageTags>dotnet-new;templates;</PackageTags>
|
||||
<PackageProjectUrl>https://github.com/mdnapo/myrcoforge</PackageProjectUrl>
|
||||
|
||||
<PackageType>Template</PackageType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IncludeContentInPack>true</IncludeContentInPack>
|
||||
<IncludeBuildOutput>false</IncludeBuildOutput>
|
||||
<ContentTargetFolders>content</ContentTargetFolders>
|
||||
<NoWarn>$(NoWarn);NU5128</NoWarn>
|
||||
<NoDefaultExcludes>true</NoDefaultExcludes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**"/>
|
||||
<Compile Remove="**\*"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
15
MycroForge.Package.PluginTemplate/README.md
Normal file
15
MycroForge.Package.PluginTemplate/README.md
Normal file
@@ -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`
|
||||
@@ -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
|
||||
}
|
||||
@@ -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<RootCommand>
|
||||
{
|
||||
private readonly Argument<string> NameArgument =
|
||||
new(name: "name", description: "The name of the person to greet");
|
||||
|
||||
private readonly Option<bool> 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!"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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<ISubCommandOf<RootCommand>, HelloWorldCommand>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include=".template.config\template.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MycroForge.Core" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user