Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static partial class Features
public static partial class PortalExtension
{
public const string EXTENSION_DEPENDENCIES_PROPERTY_NAME = "microserviceDependencies";
public const string PORTAL_TOOLKIT_PACKAGE_NAME = "@beamable/portal-toolkit";
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cli/cli/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ public virtual void Configure(
Commands.AddRootCommand<AccountMeCommand, AccountMeCommandArgs>();
Commands.AddRootCommand<GenerateDocsCommand, GenerateDocsCommandArgs>();
Commands.AddRootCommand<GenerateMkDocsCommand, GenerateMkDocsCommandArgs>();
Commands.AddRootCommand<GenerateWebComponentDocsCommand, GenerateWebComponentDocsCommandArgs>();

// FEDERATION COMMANDS
Commands.AddRootCommand<FederationCommand>();
Expand Down
789 changes: 789 additions & 0 deletions cli/cli/Commands/Docs/GenerateWebComponentDocsCommand.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cli/cli/Commands/Project/NewPortalExtensionCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.CommandLine;
using cli.Portal;
using cli.Services;
using cli.Services.PortalExtension;
using cli.Utils;
using Newtonsoft.Json.Linq;
using Spectre.Console;
Expand Down Expand Up @@ -146,6 +147,8 @@ public override async Task Handle(NewPortalExtensionCommandArgs args)
}

File.WriteAllText(def.AbsolutePackageJsonPath, jObj.ToString(Newtonsoft.Json.Formatting.Indented));

PortalExtensionObserver.InstallDeps(def.AbsolutePath);
}

private static void BuildMountSiteIndex(
Expand Down
2 changes: 1 addition & 1 deletion cli/cli/Services/BeamoLocalSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public string GetToolkitVersion()
var json = File.ReadAllText(AbsolutePackageJsonPath);
var root = Newtonsoft.Json.Linq.JObject.Parse(json);
var depVersion = (root["devDependencies"] as Newtonsoft.Json.Linq.JObject)
?["@beamable/portal-toolkit"]?.ToString();
?[Beamable.Common.Constants.Features.PortalExtension.PORTAL_TOOLKIT_PACKAGE_NAME]?.ToString();

// If the version is a file: reference or other non-semver, resolve from the installed package
if (depVersion != null && !char.IsDigit(depVersion.TrimStart('^', '~')[0]))
Expand Down
13 changes: 13 additions & 0 deletions cli/cli/Services/BeamoLocalSystem_PortalExtension.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Runtime.Serialization;
using Beamable.Common.Content;
using Beamable.Server;
using Beamable.Server.Api.Notifications;
using cli.Portal;
using cli.Services.PortalExtension;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace cli.Services;

Expand Down Expand Up @@ -152,6 +154,14 @@ public class PortalExtensionMountProperties
[JsonProperty("args")] public Dictionary<string, string> Args = new Dictionary<string, string>();
}

[JsonConverter(typeof(StringEnumConverter))]
public enum AutoUpdateToolkitMode
{
[EnumMember(Value = "none")] None,
[EnumMember(Value = "auto")] Auto,
[EnumMember(Value = "warn")] Warn,
}

[Serializable]
public class PortalExtensionPackageProperties
{
Expand All @@ -161,6 +171,9 @@ public class PortalExtensionPackageProperties

[JsonProperty("microserviceDependencies")]
public List<string> MicroserviceDependencies;

[JsonProperty("autoUpdateToolkit")]
public AutoUpdateToolkitMode AutoUpdateToolkit = AutoUpdateToolkitMode.Auto;

[JsonProperty("mount")] public PortalExtensionMountProperties Mount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ public void BuildExtension()
}
}

public void InstallDeps()
public void InstallDeps() => InstallDeps(AppFilesPath);

public static void InstallDeps(string workingDirectoryPath)
{
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
StartProcessResult result = isWindows
? StartProcessUtil.Run("cmd.exe", "/c npm install", workingDirectoryPath: AppFilesPath):
StartProcessUtil.Run("npm", "install", workingDirectoryPath: AppFilesPath);
? StartProcessUtil.Run("cmd.exe", "/c npm install", workingDirectoryPath: workingDirectoryPath)
: StartProcessUtil.Run("npm", "install", workingDirectoryPath: workingDirectoryPath);
if (result.exit != 0)
{
throw new CliException($"Failed to generate portal extension dependencies. \nCheck errors: \n{result.stderr} \nAll logs: {result.stdout}"
Expand Down
32 changes: 30 additions & 2 deletions cli/cli/Services/ProjectContextUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,41 @@ public static List<PortalExtensionDef> FindPortalExtensionProjects(string rootFo

var dir = Path.GetDirectoryName(filePath);

projects.Add(new PortalExtensionDef()
var def = new PortalExtensionDef()
{
Name = info.Name,
Properties = properties,
RelativePath = Path.GetRelativePath(rootFolder, dir),
AbsolutePath = Path.GetFullPath(dir),
});
};

var embeddedVersion = EmbeddedVersionUtil.GetPortalToolkitVersion();
var installedVersion = def.GetToolkitVersion();

if (installedVersion != null && installedVersion != embeddedVersion)
{
switch (properties.AutoUpdateToolkit)
{
case AutoUpdateToolkitMode.Auto:
var packageJson = File.ReadAllText(def.AbsolutePackageJsonPath);
var root = Newtonsoft.Json.Linq.JObject.Parse(packageJson);
if (root["devDependencies"] is Newtonsoft.Json.Linq.JObject devDeps)
{
devDeps[Beamable.Common.Constants.Features.PortalExtension.PORTAL_TOOLKIT_PACKAGE_NAME] = embeddedVersion;
File.WriteAllText(def.AbsolutePackageJsonPath, root.ToString(Newtonsoft.Json.Formatting.Indented));
}
break;
case AutoUpdateToolkitMode.Warn:
Log.Warning("Portal extension {Name} has {Package}@{Installed} but the embedded version is {Embedded}. Update your package.json to match.",
def.Name, Beamable.Common.Constants.Features.PortalExtension.PORTAL_TOOLKIT_PACKAGE_NAME, installedVersion, embeddedVersion);
break;
case AutoUpdateToolkitMode.None:
default:
break;
}
}

projects.Add(def);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Beamable.Server.Common;

public static class EmbeddedVersionUtil
{
static string _cachedPortalToolkitVersion;

public static string GetPortalToolkitVersion()
{
if (_cachedPortalToolkitVersion != null)
return _cachedPortalToolkitVersion;

var resourceName = "beamable.tooling.common.Microservice.VersionManagement.portal-toolkit-version.json";
var assembly = typeof(EmbeddedVersionUtil).Assembly;
using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream == null)
throw new InvalidOperationException($"Embedded resource not found: {resourceName}");
var toolkitVersion = JsonSerializer.Deserialize<ToolkitVersion>(stream);
_cachedPortalToolkitVersion = toolkitVersion.portalToolkitVersion;
return _cachedPortalToolkitVersion;
}

[Serializable]
public class ToolkitVersion
{
[JsonPropertyName("portalToolkitVersion")]
public string portalToolkitVersion;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"portalToolkitVersion": "0.1.4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

<ItemGroup>
<EmbeddedResource Include="Microservice\VersionManagement\collector-version.json" />
<EmbeddedResource Include="Microservice\VersionManagement\portal-toolkit-version.json" />
</ItemGroup>

<ItemGroup>
Expand Down