mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-02-21 14:14:45 +01:00
BTCPay Extensions Part 2 (#2001)
* BTCPay Extensions Part 2 This PR cleans up the extension system a bit in that: * It renames the test extension to a more uniform name * Allows yo uto have system extensions, which are extensions but bundled by default with the release (and cannot be removed) * Adds a tool to help you generate an extension package from a csproj * Refactors the UI extension points to a view component * Moves some more interfaces to the Abstractions csproj * Rename to plugins
This commit is contained in:
50
BTCPayServer.PluginPacker/Program.cs
Normal file
50
BTCPayServer.PluginPacker/Program.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using BTCPayServer.Contracts;
|
||||
|
||||
namespace BTCPayServer.PluginPacker
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var directory = args[0];
|
||||
var name = args[1];
|
||||
var outputDir = args[2];
|
||||
var outputFile = Path.Combine(outputDir, name);
|
||||
var rootDLLPath = Path.Combine(directory, name +".dll");
|
||||
if (!File.Exists(rootDLLPath) )
|
||||
{
|
||||
throw new Exception($"{rootDLLPath} could not be found");
|
||||
}
|
||||
|
||||
var assembly = Assembly.LoadFrom(rootDLLPath);
|
||||
var extension = GetAllExtensionTypesFromAssembly(assembly).FirstOrDefault();
|
||||
if (extension is null)
|
||||
{
|
||||
throw new Exception($"{rootDLLPath} is not a valid plugin");
|
||||
}
|
||||
|
||||
var loadedPlugin = (IBTCPayServerPlugin)Activator.CreateInstance(extension);
|
||||
var json = JsonSerializer.Serialize(loadedPlugin);
|
||||
Directory.CreateDirectory(outputDir);
|
||||
if (File.Exists(outputFile + ".btcpay"))
|
||||
{
|
||||
File.Delete(outputFile + ".btcpay");
|
||||
}
|
||||
ZipFile.CreateFromDirectory(directory, outputFile + ".btcpay", CompressionLevel.Optimal, false);
|
||||
File.WriteAllText(outputFile + ".btcpay.json", json);
|
||||
}
|
||||
|
||||
private static Type[] GetAllExtensionTypesFromAssembly(Assembly assembly)
|
||||
{
|
||||
return assembly.GetTypes().Where(type =>
|
||||
typeof(IBTCPayServerPlugin).IsAssignableFrom(type) &&
|
||||
!type.IsAbstract).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user