SHA256
CLI-Fixes: Help/Version vor Build, Content-Check, Default-Envs, Artefakte aus Git
- Program.cs: --help/--version werden vor Config-Laden und Directories.Init geprüft (verhindert Crashes außerhalb eines Site-Verzeichnisses) - Builder.cs: Pre-flight-Check ob content/ existiert; bei Fehlen klare Fehlermeldung + Exit 1 statt unhandled Exception. Build() gibt bool zurück, Program.cs setzt Environment.ExitCode. - BuildConfig.cs: Default-Environments von work/review/staging/deploy auf development/staging/deploy bereinigt (konsistent mit CLI-Aliasen) - .gitignore: build_log.txt/run_log.txt und webstatic.example/dist/ ignoriert; entsprechende Artefakte aus Git entfernt - tests/README.md: Platzhalter für künftige Test-Strategie - plans/01-offensichtliche-fixes.md: Fix-Plan dokumentiert
This commit is contained in:
+3
-4
@@ -22,7 +22,7 @@ public class PathsConfig
|
||||
public string I18n { get; set; } = "i18n.json";
|
||||
}
|
||||
|
||||
/// <summary>Build environment (work/review/staging/deploy) with base URL and CDN.</summary>
|
||||
/// <summary>Build environment (development/staging/deploy) with base URL and CDN.</summary>
|
||||
public class EnvironmentConfig
|
||||
{
|
||||
public string BaseUrl { get; set; } = "http://localhost:8000";
|
||||
@@ -81,9 +81,8 @@ public class BuildConfig
|
||||
},
|
||||
Environments = new()
|
||||
{
|
||||
["work"] = new EnvironmentConfig { BaseUrl = "http://localhost:8000", Cdn = "/assets" },
|
||||
["review"] = new EnvironmentConfig { BaseUrl = "https://review.gitcover.org", Cdn = "https://gitcover.org/assets" },
|
||||
["staging"] = new EnvironmentConfig { BaseUrl = "https://gcbok.gitcover.org", Cdn = "https://gitcover.org/assets" },
|
||||
["development"] = new EnvironmentConfig { BaseUrl = "http://localhost:8000", Cdn = "/assets" },
|
||||
["staging"] = new EnvironmentConfig { BaseUrl = "https://staging.gitcover.org", Cdn = "https://gitcover.org/assets" },
|
||||
["deploy"] = new EnvironmentConfig { BaseUrl = "https://gcbok.org", Cdn = "https://gitcover.org/assets" },
|
||||
},
|
||||
};
|
||||
|
||||
+17
-1
@@ -7,8 +7,22 @@ namespace GCBoK.WebStaticBuilder;
|
||||
/// <summary>Main build orchestrator.</summary>
|
||||
public static class Builder
|
||||
{
|
||||
public static void Build(BuildConfig cfg, EnvironmentConfig env, string envName, bool verbose, bool dryRun)
|
||||
/// <returns><c>true</c> if the build completed; <c>false</c> if it was
|
||||
/// aborted due to a pre-flight check failure (missing content directory).</returns>
|
||||
public static bool Build(BuildConfig cfg, EnvironmentConfig env, string envName, bool verbose, bool dryRun)
|
||||
{
|
||||
// Pre-flight: content directory must exist — otherwise ContentLoader
|
||||
// throws an unhandled DirectoryNotFoundException. Fail gracefully with
|
||||
// an actionable message instead of a stack trace.
|
||||
if (!Directory.Exists(Directories.ContentDir))
|
||||
{
|
||||
Console.Error.WriteLine(
|
||||
$"ERROR: content directory not found: {Directories.ContentDir}");
|
||||
Console.Error.WriteLine(
|
||||
" Specify --root <dir> or --content <dir>.");
|
||||
return false;
|
||||
}
|
||||
|
||||
File.WriteAllText(Directories.BuildLogPath,
|
||||
$"=== Build Started: {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} ===\n");
|
||||
File.AppendAllText(Directories.BuildLogPath,
|
||||
@@ -179,6 +193,8 @@ public static class Builder
|
||||
|
||||
if (cfg.Pagefind) BuildSearchIndex(verbose);
|
||||
else if (verbose) Console.WriteLine(" Pagefind disabled (config).");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string LoadLayout()
|
||||
|
||||
+22
-18
@@ -15,6 +15,22 @@ string? Val(string f)
|
||||
var verbose = Has("--verbose") || Has("-v");
|
||||
var dryRun = Has("--dry-run") || Has("-n");
|
||||
|
||||
// Help / Version — check before any filesystem access to avoid crashes
|
||||
// when invoked outside a site directory (e.g. `webstatic --help` in $HOME).
|
||||
if (argsList.Contains("--help") || argsList.Contains("-h") || argsList.Contains("help"))
|
||||
{
|
||||
PrintHelp();
|
||||
return;
|
||||
}
|
||||
if (argsList.Contains("--version"))
|
||||
{
|
||||
var v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Console.WriteLine($"GCBoK.WebStaticBuilder {v?.ToString() ?? "0.0.0"}");
|
||||
var hash = GitShortHash(AppContext.BaseDirectory);
|
||||
if (hash != null) Console.WriteLine($"commit: {hash}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve config file + site root
|
||||
var configPath = Val("--config");
|
||||
var root = Val("--root") ?? Directory.GetCurrentDirectory();
|
||||
@@ -46,23 +62,6 @@ if (Val("--cdn") is { } cdn) { /* applied to chosen env below */ }
|
||||
|
||||
Directories.Init(cfg, root);
|
||||
|
||||
// Help
|
||||
if (argsList.Contains("--help") || argsList.Contains("-h") || argsList.Contains("help"))
|
||||
{
|
||||
PrintHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
// Version
|
||||
if (argsList.Contains("--version"))
|
||||
{
|
||||
var v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Console.WriteLine($"GCBoK.WebStaticBuilder {v?.ToString() ?? "0.0.0"}");
|
||||
var hash = GitShortHash(AppContext.BaseDirectory);
|
||||
if (hash != null) Console.WriteLine($"commit: {hash}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Self-update (Hermes-Konzept: lokale Aenderungen stashen, pull, mergen, rebuild)
|
||||
if (argsList.Contains("update"))
|
||||
{
|
||||
@@ -115,7 +114,12 @@ if (Val("--base-url") is { } bu2) env.BaseUrl = bu2;
|
||||
if (Val("--cdn") is { } cdn2) env.Cdn = cdn2;
|
||||
|
||||
if (verbose) Console.WriteLine($"GCBoK.WebStaticBuilder — building (env={envName})");
|
||||
Builder.Build(cfg, env, envName, verbose, dryRun);
|
||||
var ok = Builder.Build(cfg, env, envName, verbose, dryRun);
|
||||
if (!ok)
|
||||
{
|
||||
Environment.ExitCode = 1;
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Build completed successfully.");
|
||||
|
||||
static void PrintHelp()
|
||||
|
||||
Reference in New Issue
Block a user