Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 2735cac

Browse files
committed
build: get version info from plugin.json
1 parent d65c491 commit 2735cac

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

build/Build.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<ItemGroup>
99
<PackageReference Include="Cake.Compression" Version="0.3.0" />
1010
<PackageReference Include="Cake.Frosting" Version="3.1.0" />
11+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1112
<PackageReference Include="SharpClipboard" Version="3.5.2" />
1213
</ItemGroup>
1314
<ItemGroup>

build/Program.cs

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Threading.Tasks;
56
using Cake.Common;
@@ -13,6 +14,7 @@
1314
using Cake.Core;
1415
using Cake.Core.IO;
1516
using Cake.Frosting;
17+
using Newtonsoft.Json;
1618

1719
namespace Build;
1820

@@ -34,7 +36,7 @@ public class BuildContext : FrostingContext
3436
public Lazy<SolutionParserResult> DefaultSln { get; set; }
3537
public const string DeployFramework = "net7.0-windows";
3638
public string PublishDir = ".dist";
37-
public string PublishVersion = "0.2.4";
39+
public string PublishVersion = "";
3840

3941
public BuildContext(ICakeContext context)
4042
: base(context)
@@ -54,7 +56,7 @@ public override void Setup(BuildContext context, ISetupContext info)
5456

5557
public override void Teardown(BuildContext context, ITeardownContext info)
5658
{
57-
59+
// ignore
5860
}
5961
}
6062

@@ -63,8 +65,7 @@ public sealed class BuildTask : FrostingTask<BuildContext>
6365
{
6466
public override void Run(BuildContext context)
6567
{
66-
var projects = context
67-
.DefaultSln.Value.Projects.Where(p => p.Name.EndsWith("ClipboardR"));
68+
var projects = context.DefaultSln.Value.Projects.Where(p => p.Name.EndsWith("ClipboardR"));
6869
var projectPath = projects.First().Path.FullPath;
6970
context.Information($"Building {projectPath}");
7071
context.DotNetBuild(
@@ -76,9 +77,8 @@ public override void Run(BuildContext context)
7677
Framework = BuildContext.DeployFramework,
7778
NoDependencies = false,
7879
NoIncremental = true,
79-
});
80-
81-
80+
}
81+
);
8282
}
8383
}
8484

@@ -88,12 +88,10 @@ public class PublishTask : FrostingTask<BuildContext>
8888
{
8989
public override void Run(BuildContext context)
9090
{
91-
var project = context
92-
.DefaultSln.Value.Projects
93-
.First(p => p.Name.EndsWith("ClipboardR"));
94-
var srcDir = project.Path.GetDirectory()
95-
.Combine(new DirectoryPath($"bin/publish"));
96-
var dstDir = $"{srcDir.GetParent().GetParent().GetParent().GetParent().FullPath}/{context.PublishDir}";
91+
var project = context.DefaultSln.Value.Projects.First(p => p.Name.EndsWith("ClipboardR"));
92+
var srcDir = project.Path.GetDirectory().Combine(new DirectoryPath($"bin/publish"));
93+
var dstDir =
94+
$"{srcDir.GetParent().GetParent().GetParent().GetParent().FullPath}/{context.PublishDir}";
9795
context.DotNetPublish(
9896
project.Path.FullPath,
9997
new DotNetPublishSettings
@@ -102,17 +100,35 @@ public override void Run(BuildContext context)
102100
Configuration = context.DotNetBuildConfig,
103101
Framework = BuildContext.DeployFramework,
104102
Verbosity = DotNetVerbosity.Minimal,
105-
});
103+
}
104+
);
106105
context.CreateDirectory(dstDir);
107-
var files = context
108-
.GetFiles(@$"{srcDir}/**/(*(c|C)lipboard*.(png|json|dll)|*.png|plugin.json|(*simulator).dll)");
106+
var files = context.GetFiles(
107+
@$"{srcDir}/**/(*(c|C)lipboard*.(png|json|dll)|*.png|plugin.json|(*simulator).dll)"
108+
);
109+
FilePath? versionFile = null;
109110
foreach (var f in files)
111+
{
110112
context.Information($"Adding: {f}");
113+
if (f.ToString().EndsWith("plugin.json"))
114+
versionFile = f;
115+
}
116+
if (versionFile != null)
117+
{
118+
VersionInfo? versionInfoObj = JsonConvert.DeserializeObject<VersionInfo>(
119+
File.ReadAllText(versionFile.ToString())
120+
);
121+
if (versionInfoObj != null)
122+
context.PublishVersion = versionInfoObj.Version;
123+
else
124+
Console.WriteLine("Get version info from plugin.json failed!");
125+
}
111126
context.ZipCompress(
112127
rootPath: srcDir,
113128
outputPath: $"{dstDir}/ClipboardR-v{context.PublishVersion}.zip",
114129
filePaths: files,
115-
level: 9);
130+
level: 9
131+
);
116132
}
117133
}
118134

@@ -124,14 +140,29 @@ public override void Run(BuildContext context)
124140
foreach (var project in context.DefaultSln.Value.Projects)
125141
{
126142
context.Information($"Cleaning {project.Path.GetDirectory().FullPath}...");
127-
context.CleanDirectory($"{project.Path.GetDirectory().FullPath}/bin/{context.DotNetBuildConfig}");
143+
context.CleanDirectory(
144+
$"{project.Path.GetDirectory().FullPath}/bin/{context.DotNetBuildConfig}"
145+
);
128146
}
129147
}
130148
}
131149

132150
[TaskName("Default")]
133151
[IsDependentOn(typeof(CleanTask))]
134152
[IsDependentOn(typeof(BuildTask))]
135-
public class DefaultTask : FrostingTask
153+
[IsDependentOn(typeof(PublishTask))]
154+
public class DefaultTask : FrostingTask { }
155+
156+
public class VersionInfo
136157
{
137-
}
158+
public string ID { get; set; }
159+
public string ActionKeyword { get; set; }
160+
public string Name { get; set; }
161+
public string Description { get; set; }
162+
public string Author { get; set; }
163+
public string Version { get; set; }
164+
public string Language { get; set; }
165+
public string Website { get; set; }
166+
public string IcoPath { get; set; }
167+
public string ExecuteFileName { get; set; }
168+
}

src/ClipboardR/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "ClipboardR",
55
"Description": "A clipboard plugin for Flow.Launcher, support pictures!",
66
"Author": "Rainyl",
7-
"Version": "0.2.4",
7+
"Version": "0.2.5",
88
"Language": "csharp",
99
"Website": "https://github.com/rainyl/Flow.Launcher.Plugin.ClipboardR",
1010
"IcoPath": "Images/clipboard.png",

0 commit comments

Comments
 (0)