11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Linq ;
45using System . Threading . Tasks ;
56using Cake . Common ;
1314using Cake . Core ;
1415using Cake . Core . IO ;
1516using Cake . Frosting ;
17+ using Newtonsoft . Json ;
1618
1719namespace 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+ }
0 commit comments