Skip to content

Commit

Permalink
feat(init): Add App environment configuration (#425)
Browse files Browse the repository at this point in the history
* feat(init): Add App environment configuration
* Update Init Tests

---------

Co-authored-by: migafgarcia <[email protected]>
  • Loading branch information
2 people authored and joaoopereira committed Dec 5, 2024
1 parent 0dfa3a5 commit a64cf4f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
54 changes: 41 additions & 13 deletions cmf-cli/Commands/init/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal class InitArguments
public string rootPackageName { get; set; }
public string version { get; set; }
public IFileInfo config { get; set; }
public IFileInfo appConfig { get; set; }
public IDirectoryInfo deploymentDir { get; set; }
public string BaseVersion { get; set; }
public string DevTasksVersion { get; set; }
Expand All @@ -51,7 +52,7 @@ internal class InitArguments
public string appDescription { get; set; }
public string appAuthor { get; set; }
public string appLicensedApplication { get; set; }
public string appIcon { get; set; }
public IFileInfo appIcon { get; set; }

// ReSharper restore UnusedAutoPropertyAccessor.Global
// ReSharper restore InconsistentNaming
Expand Down Expand Up @@ -112,6 +113,12 @@ public override void Configure(Command cmd)
isDefault: true,
description: "Configuration file exported from Setup")
{ IsRequired = true });
cmd.AddOption(new Option<IFileInfo>(
aliases: ["--appConfig"],
parseArgument: argResult => Parse<IFileInfo>(argResult),
isDefault: true,
description: "App Configuration file")
{ IsRequired = false });
cmd.AddOption(new Option<RepositoryType>(
aliases: new[] { "-t", "--repositoryType" },
getDefaultValue: () => CliConstants.DefaultRepositoryType,
Expand Down Expand Up @@ -213,8 +220,9 @@ public override void Configure(Command cmd)
description: $"License for new application. {OnlyIfTypeAppWarning}"
) { IsRequired = false });

cmd.AddOption(new Option<string>(
cmd.AddOption(new Option<IFileInfo>(
aliases: new[] { "--appIcon" },
parseArgument: argResult => Parse<IFileInfo>(argResult),
description: $"Application icon. {OnlyIfTypeAppWarning}"
) { IsRequired = false });

Expand Down Expand Up @@ -271,21 +279,20 @@ internal void Execute(InitArguments x)
throw new CliException(string.Join(Environment.NewLine, errors));
}

if (!string.IsNullOrEmpty(x.appIcon) && AppIconUtilities.IsIconValid(x.appIcon))
{
Log.Debug("Given icon meets criteria.");
}
var appIconPath = x.appIcon != null && AppIconUtilities.IsIconValid(x.appIcon.FullName)
? $"assets/{x.appIcon.Name}"
: $"assets/{CliConstants.DefaultAppIcon}";

args.AddRange(new[]
{
"--appName", x.appName,
"--appNameLowerNoSpaces", x.appName.ToLower().Replace(" ", ""),
"--appId", x.appId,
"--appIcon", x.appIcon ?? string.Empty,
"--appIcon", appIconPath,
"--appDescription", x.appDescription,
"--appTargetFramework", x.BaseVersion,
"--appAuthor", x.appAuthor,
"--appLicensedApplication", x.appLicensedApplication,
"--appLicensedApplication", x.appLicensedApplication
});
}

Expand Down Expand Up @@ -410,19 +417,40 @@ internal void Execute(InitArguments x)
{
args.AddRange(ParseConfigFile(x.config));
}


if (x.appConfig != null)
{
args.AddRange(new string[] {"--AppEnvironmentConfig", x.appConfig.Name});
}

this.RunCommand(args);


// Copy app icon to assets
if (x.appIcon != null)
{
var assetsPath = fileSystem.Path.Join(FileSystemUtilities.GetProjectRoot(fileSystem, throwException: true).FullName, "assets");
x.appIcon.CopyTo(fileSystem.Path.Join(assetsPath, x.appIcon.Name));
}

// Copy MES config to Environment Configs
if (x.config != null)
{
var envConfigPath = this.fileSystem.Path.Join(FileSystemUtilities.GetProjectRoot(this.fileSystem, throwException: true).FullName, "EnvironmentConfigs");
x.config.CopyTo(this.fileSystem.Path.Join(envConfigPath, x.config.Name));
this.fileSystem.FileInfo.New(this.fileSystem.Path.Join(envConfigPath, ".gitkeep")).Delete();
fileSystem.FileInfo.New(this.fileSystem.Path.Join(envConfigPath, ".gitkeep")).Delete();
}


// Copy app config to Environment Configs
if (x.appConfig != null)
{
var envConfigPath = this.fileSystem.Path.Join(FileSystemUtilities.GetProjectRoot(this.fileSystem, throwException: true).FullName, "EnvironmentConfigs");
x.appConfig.CopyTo(this.fileSystem.Path.Join(envConfigPath, x.appConfig.Name));
fileSystem.FileInfo.New(this.fileSystem.Path.Join(envConfigPath, ".gitkeep")).Delete();
}

if (x.repositoryType == RepositoryType.App)
{
Log.Information($"Apps need to have an ApplicationVersion package. Make sure you create at least one business package for your application using the addApplicationVersionAssembly flag");
Log.Information("Apps need to have an ApplicationVersion package. Make sure you create at least one business package for your application using the addApplicationVersionAssembly flag");
}
}

Expand Down
1 change: 1 addition & 0 deletions cmf-cli/resources/template_feed/init/.project-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"HTMLPort": "<%= $CLI_PARAM_HTMLPort %>",
"GatewayPort": "<%= $CLI_PARAM_GatewayPort %>",
"ReleaseEnvironmentConfig": "<%= $CLI_PARAM_ReleaseEnvironmentConfig %>",
"AppEnvironmentConfig": "<%= $CLI_PARAM_AppEnvironmentConfig %>",
"ISOLocation": "<%= $CLI_PARAM_ISOLocation_JSON %>",
"DeploymentDir": "<%= $CLI_PARAM_DeploymentDir %>",
"DeliveredRepo": "<%= $CLI_PARAM_DeliveredRepo %>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,12 @@
"datatype": "string",
"defaultValue": "",
"replaces": "<%= $CLI_PARAM_AppIcon %>"
},
"AppEnvironmentConfig": {
"type": "parameter",
"datatype": "string",
"defaultValue": "",
"replaces": "<%= $CLI_PARAM_AppEnvironmentConfig %>"
}
},
"forms": {
Expand Down
1 change: 1 addition & 0 deletions core/Objects/ProjectConfig/ProjectConfigV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ProjectConfigV1
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int? GatewayPort { get; set; }
public string ReleaseEnvironmentConfig { get; set; }
public string AppEnvironmentConfig { get; set; }
public Uri ISOLocation { get; set; }
[Newtonsoft.Json.JsonConverter(typeof(UriConverter))]
public Uri DeploymentDir { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion tests/Specs/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void Init_App()
var appDescription = "Some description";
var targetFramework = "10.2.0";
var licensedApplication = "Test app";
var icon = "";
var icon = $"assets/{CliConstants.DefaultAppIcon}";

var cur = Directory.GetCurrentDirectory();
try
Expand Down

0 comments on commit a64cf4f

Please sign in to comment.