Skip to content

Commit 3b7ffa6

Browse files
committed
Add ReadMe file to the packaging and update FlowSynx.PluginCore
#8
1 parent 590045d commit 3b7ffa6

5 files changed

Lines changed: 95 additions & 53 deletions

File tree

src/FlowPack/FlowPack.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="FlowSynx.PluginCore" Version="1.2.3" />
17+
<PackageReference Include="FlowSynx.PluginCore" Version="1.2.4" />
1818
</ItemGroup>
1919

2020
</Project>

src/FlowPack/Packager.cs

Lines changed: 91 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,76 +15,120 @@ public Packager(PackOptions options)
1515

1616
public bool Build()
1717
{
18-
string projectPath = _options.ProjectPath;
19-
20-
if (!File.Exists(projectPath) || Path.GetExtension(projectPath) != ".csproj")
21-
throw new FileNotFoundException("Provided file must be a valid .csproj file.");
18+
if (!ValidateProjectPath(out var projectName))
19+
return false;
2220

23-
string projectName = Path.GetFileNameWithoutExtension(projectPath);
24-
string configuration = "Release";
25-
string tempOutput = Path.Combine(Path.GetTempPath(), "publish_output_" + Guid.NewGuid());
26-
Directory.CreateDirectory(tempOutput);
21+
var configuration = "Release";
22+
var tempRoot = CreateTempDirectory("publish_output_");
23+
var outputDir = CreateSubDirectory(tempRoot);
24+
var manifestDir = CreateSubDirectory(tempRoot);
2725

28-
if (_options.Clean)
26+
try
2927
{
30-
RunCommand("dotnet", $"clean \"{projectPath}\" -c {configuration}");
31-
}
28+
if (_options.Clean && !RunCommand("dotnet", $"clean \"{_options.ProjectPath}\" -c {configuration}"))
29+
return false;
3230

33-
if (!RunCommand("dotnet", $"build \"{projectPath}\" -c {configuration}"))
34-
return false;
31+
if (!RunCommand("dotnet", $"build \"{_options.ProjectPath}\" -c {configuration}"))
32+
return false;
3533

36-
if (!RunCommand("dotnet", $"publish \"{projectPath}\" -c {configuration} -o \"{tempOutput}\""))
37-
return false;
34+
if (!RunCommand("dotnet", $"publish \"{_options.ProjectPath}\" -c {configuration} -o \"{outputDir}\""))
35+
return false;
36+
37+
var pluginPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".plugin");
38+
var checksumPath = pluginPath + ".sha256";
39+
40+
var metadata = PluginReflector.ExtractPluginMetadata(outputDir, _options.Verbose);
41+
if (metadata == null)
42+
{
43+
LogError("No valid plugin metadata found.");
44+
return false;
45+
}
46+
47+
var manifestPath = PluginReflector.SaveMetadataToFile(metadata, manifestDir);
48+
49+
ZipFile.CreateFromDirectory(outputDir, pluginPath);
50+
LogInfo($"Plugin created: {pluginPath}");
51+
52+
var checksum = ComputeSha256(pluginPath);
53+
File.WriteAllText(checksumPath, checksum);
54+
LogInfo($"SHA256: {checksum}");
3855

39-
// Create .plugin file from published output
40-
string pluginTempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".plugin");
41-
string pluginMetadataTempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".json");
56+
var finalPackagePath = ResolveOutputPath(projectName);
57+
CreateFinalPackage(finalPackagePath, pluginPath, manifestPath, checksumPath, projectName);
4258

43-
var metadata = PluginReflector.ExtractPluginMetadata(tempOutput, _options.Verbose);
44-
if (metadata == null)
59+
LogInfo($"Final package created: {finalPackagePath}");
60+
return true;
61+
}
62+
finally
63+
{
64+
CleanupTempFiles(tempRoot);
65+
}
66+
}
67+
68+
private bool ValidateProjectPath(out string projectName)
69+
{
70+
projectName = Path.GetFileNameWithoutExtension(_options.ProjectPath);
71+
72+
if (!File.Exists(_options.ProjectPath) || Path.GetExtension(_options.ProjectPath) != ".csproj")
4573
{
46-
Console.WriteLine("No valid plugin metadata found.");
74+
LogError("Provided file must be a valid .csproj file.");
4775
return false;
4876
}
4977

50-
var manifestPath = PluginReflector.SaveMetadataToFile(metadata, tempOutput);
78+
return true;
79+
}
5180

52-
ZipFile.CreateFromDirectory(tempOutput, pluginTempPath);
53-
LogInfo($"Plugin created: {pluginTempPath}");
81+
private string CreateTempDirectory(string prefix)
82+
{
83+
var path = Path.Combine(Path.GetTempPath(), prefix + Guid.NewGuid());
84+
Directory.CreateDirectory(path);
85+
return path;
86+
}
5487

55-
// Compute SHA256
56-
string checksum = ComputeSha256(pluginTempPath);
57-
string checksumPath = pluginTempPath + ".sha256";
58-
File.WriteAllText(checksumPath, checksum);
59-
LogInfo($"SHA256: {checksum}");
88+
private string CreateSubDirectory(string parent)
89+
{
90+
var subDir = Path.Combine(parent, Guid.NewGuid().ToString());
91+
Directory.CreateDirectory(subDir);
92+
return subDir;
93+
}
6094

61-
// Determine final .fspack path
62-
var fspackPath = _options.OutputPath;
63-
if (string.IsNullOrWhiteSpace(fspackPath))
95+
private string ResolveOutputPath(string projectName)
96+
{
97+
if (string.IsNullOrWhiteSpace(_options.OutputPath))
6498
{
65-
fspackPath = Path.Combine(Directory.GetCurrentDirectory(), $"{projectName}.fspack");
99+
return Path.Combine(Directory.GetCurrentDirectory(), $"{projectName}.fspack");
66100
}
67-
else if (!fspackPath.EndsWith(".fspack", StringComparison.OrdinalIgnoreCase))
101+
102+
if (!Path.GetExtension(_options.OutputPath).Equals(".fspack", StringComparison.OrdinalIgnoreCase))
68103
{
69104
throw new InvalidOperationException("Output file must have a .fspack extension.");
70105
}
71106

72-
if (File.Exists(fspackPath)) File.Delete(fspackPath);
73-
using (var archive = ZipFile.Open(fspackPath, ZipArchiveMode.Create))
74-
{
75-
archive.CreateEntryFromFile(pluginTempPath, $"{projectName}.plugin");
76-
archive.CreateEntryFromFile(manifestPath, "manifest.json");
77-
archive.CreateEntryFromFile(checksumPath, $"{projectName}.plugin.sha256");
78-
}
107+
return _options.OutputPath;
108+
}
79109

80-
LogInfo($"Final package created: {fspackPath}");
110+
private void CreateFinalPackage(string packagePath, string pluginPath, string manifestPath, string checksumPath, string projectName)
111+
{
112+
if (File.Exists(packagePath))
113+
File.Delete(packagePath);
81114

82-
// Cleanup
83-
File.Delete(pluginTempPath);
84-
File.Delete(checksumPath);
85-
LogInfo("Cleaned up intermediate files.");
115+
using var archive = ZipFile.Open(packagePath, ZipArchiveMode.Create);
116+
archive.CreateEntryFromFile(pluginPath, $"{projectName}.plugin");
117+
archive.CreateEntryFromFile(manifestPath, "manifest.json");
118+
archive.CreateEntryFromFile(checksumPath, $"{projectName}.plugin.sha256");
119+
}
86120

87-
return true;
121+
private void CleanupTempFiles(string tempRoot)
122+
{
123+
try
124+
{
125+
Directory.Delete(tempRoot, recursive: true);
126+
LogInfo("Cleaned up intermediate files.");
127+
}
128+
catch (Exception ex)
129+
{
130+
LogError($"Failed to cleanup temporary files: {ex.Message}");
131+
}
88132
}
89133

90134
private bool RunCommand(string fileName, string arguments)
@@ -135,16 +179,12 @@ private string ComputeSha256(string filePath)
135179
private void LogInfo(string message)
136180
{
137181
if (_options.Verbose)
138-
{
139182
Console.WriteLine(message);
140-
}
141183
}
142184

143185
private void LogError(string message)
144186
{
145187
if (_options.Verbose)
146-
{
147188
Console.Error.WriteLine(message);
148-
}
149189
}
150190
}

src/FlowPack/PluginMetadata.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class PluginMetadata
1313
public string? ProjectUrl { get; set; }
1414
public string? RepositoryUrl { get; set; }
1515
public string? Copyright { get; set; }
16+
public string? ReadMe { get; set; }
1617
public List<string> Authors { get; set; } = new List<string>();
1718
public List<string> Tags { get; set; } = new List<string>();
1819
}

src/FlowPack/PluginReflector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private static PluginMetadata CreatePluginMetadata(IPlugin plugin)
4747
ProjectUrl = plugin.Metadata.ProjectUrl,
4848
RepositoryUrl = plugin.Metadata.RepositoryUrl,
4949
Copyright = plugin.Metadata.Copyright,
50+
ReadMe = plugin.Metadata.ReadMe,
5051
Authors = plugin.Metadata.Authors ?? new(),
5152
Tags = plugin.Metadata.Tags ?? new()
5253
};

src/FlowPack/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void PrintUsage()
4242
Usage: pack <path-to-csproj> [--output <path>] [--clean] [--verbose]
4343
4444
Options:
45-
--output <zip-path> Specify the path for the output zip file.
45+
--output <fspack-path> Specify the path for the output zip file.
4646
--clean Delete the temporary publish directory after zipping.
4747
--verbose Enable detailed output from commands.
4848
--version, -v Show flowpack version.

0 commit comments

Comments
 (0)