mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 11:59:48 +00:00
Added method to update copyright year in the license file
This commit is contained in:
parent
c9f2f80524
commit
948b8918f7
@ -15,6 +15,38 @@ public sealed partial class UpdateMetadataCommands
|
|||||||
await this.UpdateTauriVersion();
|
await this.UpdateTauriVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task UpdateLicenceYear(string licenceFilePath)
|
||||||
|
{
|
||||||
|
var currentYear = DateTime.UtcNow.Year.ToString();
|
||||||
|
var lines = await File.ReadAllLinesAsync(licenceFilePath, Encoding.UTF8);
|
||||||
|
|
||||||
|
var found = false;
|
||||||
|
var copyrightYear = string.Empty;
|
||||||
|
var updatedLines = new List<string>(lines.Length);
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var match = FindCopyrightRegex().Match(line);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
copyrightYear = match.Groups["year"].Value;
|
||||||
|
|
||||||
|
if(!found && copyrightYear != currentYear)
|
||||||
|
Console.WriteLine($"- Updating the licence's year in '{Path.GetFileName(licenceFilePath)}' from '{copyrightYear}' to '{currentYear}'.");
|
||||||
|
|
||||||
|
updatedLines.Add(ReplaceCopyrightYearRegex().Replace(line, currentYear));
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
updatedLines.Add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
await File.WriteAllLinesAsync(licenceFilePath, updatedLines, Environment.UTF8_NO_BOM);
|
||||||
|
if (!found)
|
||||||
|
Console.WriteLine($"- Error: No copyright year found in '{Path.GetFileName(licenceFilePath)}'.");
|
||||||
|
else if (copyrightYear == currentYear)
|
||||||
|
Console.WriteLine($"- The copyright year in '{Path.GetFileName(licenceFilePath)}' is already up to date.");
|
||||||
|
}
|
||||||
|
|
||||||
private async Task UpdateTauriVersion()
|
private async Task UpdateTauriVersion()
|
||||||
{
|
{
|
||||||
const int TAURI_VERSION_INDEX = 7;
|
const int TAURI_VERSION_INDEX = 7;
|
||||||
@ -186,4 +218,10 @@ public sealed partial class UpdateMetadataCommands
|
|||||||
|
|
||||||
[GeneratedRegex("""tauri\s+v(?<version>[0-9.]+)""")]
|
[GeneratedRegex("""tauri\s+v(?<version>[0-9.]+)""")]
|
||||||
private static partial Regex TauriVersionRegex();
|
private static partial Regex TauriVersionRegex();
|
||||||
|
|
||||||
|
[GeneratedRegex("""^\s*Copyright\s+(?<year>[0-9]{4})""")]
|
||||||
|
private static partial Regex FindCopyrightRegex();
|
||||||
|
|
||||||
|
[GeneratedRegex("""([0-9]{4})""")]
|
||||||
|
private static partial Regex ReplaceCopyrightYearRegex();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user