Skip to content

Commit

Permalink
modgen -u
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Sep 3, 2024
1 parent 837f3ab commit 2f0049b
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions TopModel.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
var excludedTags = Array.Empty<string>();
var watchMode = false;
var checkMode = false;
string? updateMode = null;
var schemaMode = false;
var regularCommand = false;
var returnCode = 0;
Expand All @@ -32,19 +33,22 @@
var excludeOption = new Option<IEnumerable<string>>(["-e", "--exclude"], "Tag à ignorer lors de la génération.");
var watchOption = new Option<bool>(["-w", "--watch"], "Lance le générateur en mode 'watch'");
var checkOption = new Option<bool>(["-c", "--check"], "Vérifie que le code généré est conforme au modèle.");
var updateOption = new Option<string>(["-u", "--update"], "Met à jour le module de générateurs spécifié (ou tous les modules si 'all').");
var schemaOption = new Option<bool>(["-s", "--schema"], "Génère le fichier de schéma JSON du fichier de config.");
command.AddOption(fileOption);
command.AddOption(excludeOption);
command.AddOption(watchOption);
command.AddOption(checkOption);
command.AddOption(updateOption);
command.AddOption(schemaOption);
command.SetHandler(
(files, excludes, watch, check, schema) =>
(files, excludes, watch, update, check, schema) =>
{
regularCommand = true;
excludedTags = excludes.ToArray();
watchMode = watch;
checkMode = check;
updateMode = update;
schemaMode = schema;

void HandleFile(FileInfo file)
Expand Down Expand Up @@ -111,6 +115,7 @@ void HandleFile(FileInfo file)
fileOption,
excludeOption,
watchOption,
updateOption,
checkOption,
schemaOption);

Expand Down Expand Up @@ -146,6 +151,15 @@ void HandleFile(FileInfo file)
Console.WriteLine($"de la génération : {string.Join(", ", excludedTags)}.");
}

if (updateMode != null)
{
Console.Write("Mode");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(" update ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine($"activé pour : {updateMode}.");
}

if (watchMode)
{
Console.Write("Mode");
Expand Down Expand Up @@ -182,7 +196,7 @@ void HandleFile(FileInfo file)
static (Type Type, string Name) GetIGenRegInterfaceAndName(Type generator)
{
var configType = GetIGenRegInterface(generator)!.GetGenericArguments()[0];
var configName = configType.Name.Replace("Config", string.Empty).ToCamelCase();
var configName = configType.Name.Replace("Config", string.Empty).ToLower();
return (configType, configName);
}

Expand Down Expand Up @@ -214,6 +228,15 @@ void HandleFile(FileInfo file)
config.CustomGenerators.AddRange(modules.Select(m => Path.GetRelativePath(config.ModelRoot, m)));
}

if (updateMode == "all")
{
topModelLock.Modules = [];
}
else if (updateMode != null)
{
topModelLock.Modules.Remove(updateMode);
}

foreach (var cg in config.CustomGenerators)
{
var csproj = Directory.GetFiles(Path.GetFullPath(cg, new FileInfo(fullName).DirectoryName!), "*.csproj").FirstOrDefault();
Expand Down Expand Up @@ -319,15 +342,28 @@ void HandleFile(FileInfo file)
}

var hasInstalled = false;
var modgenRoot = Path.GetFullPath(".modgen", config.ModelRoot);

if (updateMode == "all" && Directory.Exists(modgenRoot))
{
Directory.Delete(modgenRoot, true);
}
else if (updateMode != null)
{
foreach (var module in Directory.GetFileSystemEntries(modgenRoot).Where(p => p.Split('/').Last().Contains(updateMode)))
{
Directory.Delete(module, true);
}
}

if (deps.Count > 0)
{
var modgenRoot = Path.GetFullPath(".modgen", config.ModelRoot);
Directory.CreateDirectory(modgenRoot);

foreach (var dep in deps)
{
var moduleFolder = Path.Combine(modgenRoot, $"{dep.ConfigKey}.{dep.Version}");

if (!Directory.Exists(moduleFolder))
{
logger.LogInformation($"({dep.ConfigKey}) Installation de {dep.FullName}@{dep.Version} en cours...");
Expand Down

0 comments on commit 2f0049b

Please sign in to comment.