Skip to content
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
35 changes: 20 additions & 15 deletions cmf-cli/Commands/init/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,17 @@ public override void Configure(Command cmd)

var nugetVersionOption = new Option<string>("--nugetVersion")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is no longer a required option, what is its default value?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied the default value here and removed the attributions in Execute()

{
Description = "NuGet versions to target. This is usually the MES version",
Required = true
Description = "NuGet versions to target. Defaults to --MESVersion when not specified.",
Required = false,
DefaultValueFactory = argResult => { try { return argResult.GetValue(baseVersionOption); } catch { return null; } }
};
cmd.Add(nugetVersionOption);

var testScenariosNugetVersionOption = new Option<string>("--testScenariosNugetVersion")
Comment thread
manel27 marked this conversation as resolved.
{
Description = "Test Scenarios Nuget Version",
Required = true
Description = "Test Scenarios NuGet version. Defaults to --MESVersion when not specified.",
Required = false,
DefaultValueFactory = argResult => { try { return argResult.GetValue(baseVersionOption); } catch { return null; } }
};
cmd.Add(testScenariosNugetVersionOption);

Expand Down Expand Up @@ -357,6 +359,9 @@ public override void Configure(Command cmd)
internal void Execute(InitArguments x)
{
using var activity = ExecutionContext.ServiceProvider?.GetService<ITelemetryService>()?.StartExtendedActivity(this.GetType().Name);

Log.Information($"Starting scaffolding for MES Version: {x.BaseVersion}");

var args = new List<string>()
{
// engine options
Expand Down Expand Up @@ -496,17 +501,21 @@ internal void Execute(InitArguments x)
args.AddRange(new [] {"--DevTasksVersion", x.DevTasksVersion ?? ""});
args.AddRange(new [] {"--HTMLStarterVersion", x.HTMLStarterVersion ?? ""});
args.AddRange(new [] {"--yoGeneratorVersion", x.yoGeneratorVersion ?? ""});
args.AddRange(new [] {"--ngxSchematicsVersion", x.ngxSchematicsVersion ?? ""});

if (x.nugetVersion != null)
{
args.AddRange(new [] {"--nugetVersion", x.nugetVersion});
}
if (x.testScenariosNugetVersion != null)
if (string.IsNullOrWhiteSpace(x.ngxSchematicsVersion))
{
args.AddRange(new [] {"--testScenariosNugetVersion", x.testScenariosNugetVersion});
var mesVer = Version.Parse(x.BaseVersion);
x.ngxSchematicsVersion = $"release-{mesVer.Major}{mesVer.Minor}{mesVer.Build}";
}

Log.Information($"Using ngx-schematics version: {x.ngxSchematicsVersion}");

args.AddRange(new [] {"--ngxSchematicsVersion", x.ngxSchematicsVersion});

args.AddRange(new [] {"--nugetVersion", x.nugetVersion});

args.AddRange(new [] {"--testScenariosNugetVersion", x.testScenariosNugetVersion});

#region infrastructure

if (x.infrastructure != null)
Expand Down Expand Up @@ -567,10 +576,6 @@ internal void Execute(InitArguments x)
throw new CliException("MES Versions under 10 are no longer supported with the newest version of the CLI. Please use cmf-cli 5.8.0 or lower.");
}

if (string.IsNullOrWhiteSpace(x.ngxSchematicsVersion))
{
throw new CliException("--ngxSchematicsVersion is missing, please specify it.");
}
#endregion

if (x.config != null)
Expand Down
8 changes: 2 additions & 6 deletions cmf-cli/Commands/new/HTMLCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ public void Execute(IDirectoryInfo workingDir, string version)
public void ExecuteV10(IDirectoryInfo workingDir, string version)
{
var ngxSchematicsVersion = ExecutionContext.Instance.ProjectConfig.NGXSchematicsVersion;
if (ngxSchematicsVersion == null)
{
throw new CliException("Seems like the repository scaffolding was run on a previous version of MES. Please re-init for versions 10+.");
}

var baseLayer = ExecutionContext.Instance.ProjectConfig.BaseLayer ?? CliConstants.DefaultBaseLayer;
this.baseWebPackage = baseLayer == BaseLayer.MES
Expand All @@ -108,7 +104,7 @@ public void ExecuteV10(IDirectoryInfo workingDir, string version)
var packageName = base.GeneratePackageName(workingDir)!.Value.Item1;
var packageDir = workingDir.GetDirectories(packageName).First();

var schematicsVersion = ngxSchematicsVersion.ToString() ?? $"@release-{mesVersion.Major}{mesVersion.Minor}{mesVersion.Build}";
var schematicsVersion = !string.IsNullOrEmpty(ngxSchematicsVersion) ? ngxSchematicsVersion : $"release-{mesVersion.Major}{mesVersion.Minor}{mesVersion.Build}";

//After v11 we use Angular default routing
var routing = mesVersion.Major >= 11 ? "true" : "false";
Expand Down Expand Up @@ -147,7 +143,7 @@ public void ExecuteV10(IDirectoryInfo workingDir, string version)
"add", "--registry", ExecutionContext.Instance.ProjectConfig.NPMRegistry.OriginalString,
"--skip-confirmation", $"@criticalmanufacturing/ngx-schematics@{schematicsVersion}",
"--eslint", "--application", baseLayer.ToString(),
"--version", $"release-{mesVersion.Major}{mesVersion.Minor}{mesVersion.Build}"
"--version", schematicsVersion
],
WorkingDirectory = packageDir,
ForceColorOutput = false
Expand Down
6 changes: 1 addition & 5 deletions cmf-cli/Commands/new/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,10 @@ public void Execute(IDirectoryInfo workingDir, string version)
{
int majorVersion = ExecutionContext.Instance.ProjectConfig.MESVersion.Major;
var ngxSchematicsVersion = ExecutionContext.Instance.ProjectConfig.NGXSchematicsVersion;
if (ngxSchematicsVersion == null)
{
throw new CliException("Seems like the repository scaffolding was run on a previous version of MES. Please re-init for versions 10+.");
}

var mesVersion = ExecutionContext.Instance.ProjectConfig.MESVersion;

this.schematicsVersion = ngxSchematicsVersion.ToString() ?? $"@release-{mesVersion.Major}{mesVersion.Minor}{mesVersion.Build}";
this.schematicsVersion = ngxSchematicsVersion ?? $"release-{mesVersion.Major}{mesVersion.Minor}{mesVersion.Build}";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any usage of this here. Where is this used?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If removed the test Help_v11 breaks because it's trying to do a npm install, do you want me to investigate further?


//Switch between v10 and v11 template
switch (majorVersion)
Expand Down
7 changes: 1 addition & 6 deletions cmf-cli/Commands/new/IoTCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ public void ExecuteV10AngularPackage(IDirectoryInfo workingDir, string version,

var ngxSchematicsVersion = ExecutionContext.Instance.ProjectConfig.NGXSchematicsVersion;

if (ngxSchematicsVersion == null)
{
throw new CliException("Seems like the repository scaffolding was run on a previous version of MES. Please re-init for versions 10+.");
}

IDirectoryInfo htmlPackageDir = fileSystem.DirectoryInfo.New(htmlPackageLocation);

if (!htmlPackageDir.Exists) throw new CliException(string.Format(CliMessages.SomePackagesNotFound, string.Join(", ", htmlPackageLocation)));
Expand Down Expand Up @@ -217,7 +212,7 @@ public void ExecuteV10AngularPackage(IDirectoryInfo workingDir, string version,

var mesVersion = ExecutionContext.Instance.ProjectConfig.MESVersion;

var schematicsVersion = ngxSchematicsVersion.ToString() ?? $"@release-{mesVersion.Major}{mesVersion.Minor}{mesVersion.Build}";
var schematicsVersion = ngxSchematicsVersion ?? $"release-{mesVersion.Major}{mesVersion.Minor}{mesVersion.Build}";

Log.Debug($"Creating new IoT Workspace {packageName}");

Expand Down
2 changes: 1 addition & 1 deletion core/Objects/ProjectConfig/ProjectConfigV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ProjectConfigV1
public SemanticVersion DevTasksVersion { get; set; }
public Version HTMLStarterVersion { get; set; }
public SemanticVersion YoGeneratorVersion { get; set; }
public SemanticVersion NGXSchematicsVersion { get; set; }
public string NGXSchematicsVersion { get; set; }
public Version NugetVersion { get; set; }
public Version TestScenariosNugetVersion { get; set; }
[Newtonsoft.Json.JsonConverter(typeof(BooleanJsonConverter))]
Expand Down
87 changes: 81 additions & 6 deletions tests/Specs/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,87 @@ public void Init_Fail_MissingMandatoryArgumentsAndOptions()
TestUtilities.GetParser(cmd).Invoke(Array.Empty<string>(), console);

Assert.Contains("Required argument missing for command: 'x'", console.Error.ToString());
foreach (var optionName in new[]
{
"baseVersion", "nugetVersion", "testScenariosNugetVersion"
})
Assert.Contains("Option '--baseVersion' is required.", console.Error.ToString());
Assert.DoesNotContain("Option '--nugetVersion' is required.", console.Error.ToString());
Assert.DoesNotContain("Option '--testScenariosNugetVersion' is required.", console.Error.ToString());
}

[Fact]
public void Init_NugetVersionsDefaultToMESVersion()
{
var tmp = TestUtilities.GetTmpDirectory();
var projectName = Convert.ToHexString(Guid.NewGuid().ToByteArray()).Substring(0, 8);
var deploymentDir = "\\\\share\\deployment_dir";
var mesVersion = "11.0.0";

var cur = Directory.GetCurrentDirectory();
try
{
Assert.Contains($"Option '--{optionName}' is required.", console.Error.ToString());
var console = new TestConsole();
Directory.SetCurrentDirectory(tmp);

var initCommand = new InitCommand();
var cmd = new Command("x");
initCommand.Configure(cmd);

TestUtilities.GetParser(cmd).Invoke(new[]
{
projectName,
"--infra", TestUtilities.GetFixturePath("init", "infrastructure.json"),
"-c", TestUtilities.GetFixturePath("init", "config.json"),
"--MESVersion", mesVersion,
// --nugetVersion, --testScenariosNugetVersion and --ngxSchematicsVersion are all intentionally omitted
"--deploymentDir", deploymentDir,
}, console);

console.Error.ToString().Should().NotContain("nugetVersion");
console.Error.ToString().Should().NotContain("testScenariosNugetVersion");
console.Error.ToString().Should().NotContain("ngxSchematicsVersion");
Assert.True(File.Exists("cmfpackage.json"), "root cmfpackage is missing");
}
finally
{
Directory.SetCurrentDirectory(cur);
Directory.Delete(tmp, true);
}
}

[Fact]
public void Init_DefaultsNgxSchematicsVersionToDistTag()
{
var tmp = TestUtilities.GetTmpDirectory();
var projectName = Convert.ToHexString(Guid.NewGuid().ToByteArray()).Substring(0, 8);
var deploymentDir = "\\\\share\\deployment_dir";
var mesVersion = "11.1.5";

var cur = Directory.GetCurrentDirectory();
try
{
var console = new TestConsole();
Directory.SetCurrentDirectory(tmp);

var initCommand = new InitCommand();
var cmd = new Command("x");
initCommand.Configure(cmd);

TestUtilities.GetParser(cmd).Invoke(new[]
{
projectName,
"--infra", TestUtilities.GetFixturePath("init", "infrastructure.json"),
"-c", TestUtilities.GetFixturePath("init", "config.json"),
"--MESVersion", mesVersion,
"--deploymentDir", deploymentDir,
}, console);

console.Error.ToString().Should().BeEmpty("command should succeed when --ngxSchematicsVersion is omitted");
Assert.True(File.Exists("cmfpackage.json"), "root cmfpackage is missing");
File.ReadAllText(Path.Join(tmp, ".project-config.json"))
.Should().Contain(@"""NGXSchematicsVersion"": ""release-1115""", "ngxSchematicsVersion should default to the MES dist-tag");
}
finally
{
Directory.SetCurrentDirectory(cur);
Directory.Delete(tmp, true);
}
}

Expand Down Expand Up @@ -226,7 +301,7 @@ public void Init_Fail_MissingOptionsForGTv10()
"--deploymentDir", deploymentDir,
}, console);

Assert.Contains("--ngxSchematicsVersion is missing, please specify it.", console.Error.ToString());
// ngxSchematicsVersion is now auto-resolved from npm when omitted
console.Error.ToString().Should().NotContain("DevTasksVersion is required");
console.Error.ToString().Should().NotContain("HTMLStarterVersion is required");
console.Error.ToString().Should().NotContain("yoGeneratorVersion is required");
Expand Down
Loading