Skip to content

Commit

Permalink
Merge pull request #6 from KuraiAndras/develop
Browse files Browse the repository at this point in the history
Get version from package.json
  • Loading branch information
KuraiAndras authored Apr 7, 2021
2 parents 9b4e5fa + 04dba02 commit b05bc8d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
asmdef
package.json
18 changes: 12 additions & 6 deletions CsprojToAsmdef.Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using System;
using System.IO;
using System.Linq;
using System.Text.Json;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.Git.GitTasks;

[CheckBuildProjectConfigurations]
[ShutdownDotNetAfterServerBuild]
Expand All @@ -21,15 +22,20 @@ partial class Build : NukeBuild

[Solution] readonly Solution Solution = default!;

static string CurrentVersion
string CurrentVersion
{
get
{
var versionText = Git("describe --tags --always").First().Text;
var packagePath = Path.Combine(Solution.Directory, "CsprojToAsmdef", "Assets", "CsprojToAsmdef", "package.json");

return Version.TryParse(versionText, out var version)
? version.ToString()
: "0.1.0";
if (!File.Exists(packagePath)) throw new InvalidOperationException($"package.json does not exist at path: {packagePath}");

var jsonContent = File.ReadAllText(packagePath);
var package = JsonSerializer.Deserialize<PackageJson>(jsonContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });

if (package?.Version is null) throw new InvalidOperationException($"Cloud not deserialize package.json:\n{jsonContent}");

return package.Version;
}
}

Expand Down
6 changes: 6 additions & 0 deletions CsprojToAsmdef.Build/PackageJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sealed class PackageJson
{
public PackageJson(string version) => Version = version;

public string Version { get; }
}
3 changes: 3 additions & 0 deletions CsprojToAsmdef/Assets/CsprojToAsmdef/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.3.6
- Get version during build from package.json

# 0.3.5
- Drop GitVersion

Expand Down
2 changes: 1 addition & 1 deletion CsprojToAsmdef/Assets/CsprojToAsmdef/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.kuraiandras.csprojtoasmdef",
"version": "0.3.5",
"version": "0.3.6",
"displayName": "Csproj To Asmdef",
"unity": "2019.2",
"author": {
Expand Down

0 comments on commit b05bc8d

Please sign in to comment.