Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(new iot): angular package generation flag for MES >= 10.2.7 #467

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
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
33 changes: 20 additions & 13 deletions cmf-cli/Commands/new/IoTCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Cmf.CLI.Services;
using Cmf.CLI.Utilities;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.NamingConventionBinder;
Expand Down Expand Up @@ -47,7 +48,7 @@ public override void Configure(Command cmd)
description: "Location of the HTML Package"
));

cmd.AddOption(new Option<string>(
cmd.AddOption(new Option<bool>(
aliases: new[] { "--isAngularPackage" },
description: "Customization package with angular"
));
Expand Down Expand Up @@ -97,17 +98,15 @@ protected override List<string> GenerateArgs(IDirectoryInfo projectRoot, IDirect
/// <param name="htmlPackageLocation">location of html package</param>
public void Execute(IDirectoryInfo workingDir, string version, string htmlPackageLocation, bool isAngularPackage)
{
if (ExecutionContext.Instance.ProjectConfig.MESVersion.Major > 9)
var mesVersion = ExecutionContext.Instance.ProjectConfig.MESVersion;
if (mesVersion.Major > 9)
{
// (ATL) Automation Task Library Package
// only introduced in v10.2.7
var executeV10ATL = !isAngularPackage &&
(ExecutionContext.Instance.ProjectConfig.MESVersion.Major == 10 &&
ExecutionContext.Instance.ProjectConfig.MESVersion.Minor >= 2 &&
ExecutionContext.Instance.ProjectConfig.MESVersion.Build >= 7);
var executeV10ATL = !isAngularPackage && mesVersion >= new Version(10, 2, 7) && mesVersion < new Version(11, 0, 0);

// only introduced in v11
var executeV11ATL = !isAngularPackage && ExecutionContext.Instance.ProjectConfig.MESVersion.Major == 11;
var executeV11ATL = !isAngularPackage && mesVersion >= new Version(11, 0, 0);

if (executeV10ATL)
{
Expand Down Expand Up @@ -146,11 +145,15 @@ public void ExecuteV10ATL(IDirectoryInfo workingDir, string version)

IFileInfo cmfpackageFile = this.fileSystem.FileInfo.New($"{workingDir}/{packageName}/{CliConstants.CmfPackageFileName}");
var cmfPackage = CmfPackage.Load(cmfpackageFile, setDefaultValues: true, this.fileSystem);
cmfPackage.LoadDependencies(null, null, true);

var iotRoot = cmfPackage.GetFileInfo().Directory;
var iotCustomPackage = iotRoot.LoadCmfPackagesFromSubDirectories(packageType: PackageType.IoT).FirstOrDefault();

var iotCustomPackage = cmfPackage.Dependencies.FirstOrDefault(package => package.CmfPackage?.PackageType == PackageType.IoT).CmfPackage;
if (iotCustomPackage == null)
{
throw new CliException($"Failed to find a CMF Package with type '${PackageType.IoT}' inside folder '{iotRoot.FullName}'");
}

var iotRoot = cmfPackage.GetFileInfo().Directory;
var iotCustomPackageWorkDir = iotCustomPackage.GetFileInfo().Directory;
var iotCustomPackageName = base.GeneratePackageName(iotCustomPackageWorkDir)!.Value.Item1;

Expand Down Expand Up @@ -212,11 +215,15 @@ public void ExecuteV10AngularPackage(IDirectoryInfo workingDir, string version,

IFileInfo cmfpackageFile = this.fileSystem.FileInfo.New($"{workingDir}/{packageName}/{CliConstants.CmfPackageFileName}");
var cmfPackage = CmfPackage.Load(cmfpackageFile, setDefaultValues: true, this.fileSystem);
cmfPackage.LoadDependencies(null, null, true);

var iotCustomPackage = cmfPackage.Dependencies.FirstOrDefault(package => package.CmfPackage?.PackageType == PackageType.IoT).CmfPackage;

var iotRoot = cmfPackage.GetFileInfo().Directory;
var iotCustomPackage = iotRoot.LoadCmfPackagesFromSubDirectories(packageType: PackageType.IoT).FirstOrDefault();

if (iotCustomPackage == null)
{
throw new CliException($"Failed to find a CMF Package with type '${PackageType.IoT}' inside folder '{iotRoot.FullName}'");
}

var iotCustomPackageWorkDir = iotCustomPackage.GetFileInfo().Directory;
var iotCustomPackageName = base.GeneratePackageName(iotCustomPackageWorkDir)!.Value.Item1;

Expand Down
27 changes: 20 additions & 7 deletions tests/Specs/New.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,11 @@ public void Help_FailNoPackage(string mesVersion, bool shouldDisplayError)

[Theory]
[InlineData("9.0.0")]
[InlineData("10.0.0"), Trait("TestCategory", "LongRunning"), Trait("TestCategory", "Internal")]
[InlineData("10.0.0", true, true), Trait("TestCategory", "LongRunning"), Trait("TestCategory", "Internal")]
[InlineData("10.2.0", false), Trait("TestCategory", "LongRunning"), Trait("TestCategory", "Internal")]
public void IoT(string mesVersion, bool htmlPackageLocationFullPath = false, bool isAngularPackage = false)
[InlineData("10.2.5", true), Trait("TestCategory", "LongRunning"), Trait("TestCategory", "Internal")]
[InlineData("10.2.5", true, true), Trait("TestCategory", "LongRunning"), Trait("TestCategory", "Internal")]
[InlineData("10.2.7", true, true), Trait("TestCategory", "LongRunning"), Trait("TestCategory", "Internal")]
[InlineData("10.2.7"), Trait("TestCategory", "LongRunning"), Trait("TestCategory", "Internal")]
public void IoT(string mesVersion, bool htmlPackageLocationFullPath = false, bool isAngularPackageFlag = false)
{
string dir = TestUtilities.GetTmpDirectory();
string packageId = "Cmf.Custom.IoT";
Expand All @@ -322,6 +323,9 @@ public void IoT(string mesVersion, bool htmlPackageLocationFullPath = false, boo
string packageIdData = "Cmf.Custom.IoT.Data";
string packageFolderData = mesVersion == "9.0.0" ? "IoTData" : packageIdData;

// Before v10.2.7, all packages were Angular packages, even if the flag was not passed explicitly
bool isAngularPackage = isAngularPackageFlag || Version.Parse(mesVersion) < new Version(10, 2, 7);

CopyNewFixture(dir, mesVersion: mesVersion);
if (mesVersion == "9.0.0")
{
Expand All @@ -331,10 +335,17 @@ public void IoT(string mesVersion, bool htmlPackageLocationFullPath = false, boo
{
var htmlPackageName = "Cmf.Custom.HTML";
var targetDir = new DirectoryInfo(dir);

TestUtilities.CopyFixturePackage(htmlPackageName, targetDir);
string htmlPackageLocation = htmlPackageLocationFullPath ? htmlPackageName : Path.Join(targetDir.FullName, htmlPackageName);
RunNew(new IoTCommand(), packageId, mesVersion: mesVersion, scaffoldingDir: dir, extraArguments: new string[] { "--htmlPackageLocation", htmlPackageLocation, "--isAngularPackage", "true" });

var extraArguments = new List<string> { "--htmlPackageLocation", htmlPackageLocation };
if (isAngularPackageFlag)
{
extraArguments.Add("--isAngularPackage");
}

RunNew(new IoTCommand(), packageId, mesVersion: mesVersion, scaffoldingDir: dir, extraArguments: extraArguments.ToArray());
}
else
{
Expand Down Expand Up @@ -365,11 +376,13 @@ public void IoT(string mesVersion, bool htmlPackageLocationFullPath = false, boo
else if (isAngularPackage)
{
var relatedPackages = TestUtilities.GetPackage($"{packageId}/{packageFolderPackages}/cmfpackage.json").GetProperty("relatedPackages")[0];
relatedPackages.GetProperty("path").GetString().Should().Be(MockUnixSupport.Path("..\\..\\Cmf.Custom.Html"));
relatedPackages.GetProperty("path").GetString().Should().Be(MockUnixSupport.Path("..\\..\\Cmf.Custom.HTML"));
relatedPackages.GetProperty("preBuild").GetBoolean().Should().BeFalse();
relatedPackages.GetProperty("postBuild").GetBoolean().Should().BeTrue();
relatedPackages.GetProperty("prePack").GetBoolean().Should().BeFalse();
relatedPackages.GetProperty("postPack").GetBoolean().Should().BeTrue();

File.Exists($"{packageId}/{packageFolderPackages}/angular.json").Should().BeTrue();
}
else
{
Expand Down
Loading