diff --git a/builder/dotnet/ProjectBuilder.cs b/builder/dotnet/ProjectBuilder.cs index a48d75d43..9b419e0c4 100644 --- a/builder/dotnet/ProjectBuilder.cs +++ b/builder/dotnet/ProjectBuilder.cs @@ -77,7 +77,8 @@ namespace BilibiliEvolved.Build public ConcurrentDictionary CachedMinFiles { get; private set; } = new ConcurrentDictionary(); public void UpdateCachedMinFile(string url) { - Console.WriteLine($"Update min url: {url}"); + url = url.Replace(@"\", "/"); + // Console.WriteLine($"Update min url: {url}"); CachedMinFiles[url] = File.ReadAllText(url); } } diff --git a/builder/dotnet/Watcher/PreprocessorWatcher.cs b/builder/dotnet/Watcher/PreprocessorWatcher.cs index 846a39ba6..0aebefb6c 100644 --- a/builder/dotnet/Watcher/PreprocessorWatcher.cs +++ b/builder/dotnet/Watcher/PreprocessorWatcher.cs @@ -33,7 +33,8 @@ namespace BilibiliEvolved.Build.Watcher return !cache.Contains(originalFile); }; } - private void KillExternalWatcher() { + private void KillExternalWatcher() + { if (!externalWatcherProcess.HasExited) { externalWatcherProcess.Kill(); @@ -58,7 +59,9 @@ namespace BilibiliEvolved.Build.Watcher cache.SaveCache(); if (!Path.GetFileNameWithoutExtension(e.FullPath).EndsWith(".vue")) { - File.WriteAllText(ResourceMinifier.GetMinimizedFileName(e.FullPath), Minifier.Minify(PostBuild(content))); + var minFile = ResourceMinifier.GetMinimizedFileName(e.FullPath); + File.WriteAllText(minFile, Minifier.Minify(PostBuild(content))); + builder.UpdateCachedMinFile(minFile); if (e.Name.Contains("dark-slice")) { builder.BuildDarkStyles(); diff --git a/builder/dotnet/Watcher/ResourceWatcher.cs b/builder/dotnet/Watcher/ResourceWatcher.cs index d53cb127a..c2facafef 100644 --- a/builder/dotnet/Watcher/ResourceWatcher.cs +++ b/builder/dotnet/Watcher/ResourceWatcher.cs @@ -23,7 +23,9 @@ namespace BilibiliEvolved.Build.Watcher builder.WriteInfo($"[{Name}] {e.Name} changed."); cache.AddCache(e.FullPath); cache.SaveCache(); - File.WriteAllText(ResourceMinifier.GetMinimizedFileName(e.FullPath), Minifier.Minify(File.ReadAllText(e.FullPath))); + string minFile = ResourceMinifier.GetMinimizedFileName(e.FullPath); + File.WriteAllText(minFile, Minifier.Minify(File.ReadAllText(e.FullPath))); + builder.UpdateCachedMinFile(minFile); if (e.Name.Contains("dark-slice")) { builder.BuildDarkStyles(); } diff --git a/builder/dotnet/Watcher/VueWatcher.cs b/builder/dotnet/Watcher/VueWatcher.cs index 63710623d..c50799e2f 100644 --- a/builder/dotnet/Watcher/VueWatcher.cs +++ b/builder/dotnet/Watcher/VueWatcher.cs @@ -19,6 +19,7 @@ namespace BilibiliEvolved.Build.Watcher private Dictionary> waitRequests = new Dictionary>(); public Task WaitForBuild(string path) { var tcs = new TaskCompletionSource(); + // Console.WriteLine($"add request: {path}"); waitRequests[path] = tcs; return tcs.Task; } @@ -28,9 +29,10 @@ namespace BilibiliEvolved.Build.Watcher if (File.Exists(originalFilename)) { File.Delete(originalFilename); } - if (waitRequests.ContainsKey(e.FullPath)) { - waitRequests[e.FullPath].SetResult(File.ReadAllText(e.FullPath)); - waitRequests.Remove(e.FullPath); + // Console.WriteLine($"test filename: {originalFilename}"); + if (waitRequests.ContainsKey(originalFilename)) { + waitRequests[originalFilename].SetResult(File.ReadAllText(e.FullPath)); + waitRequests.Remove(originalFilename); } } } @@ -40,7 +42,10 @@ namespace BilibiliEvolved.Build.Watcher public VueWatcher() : base($"src{Path.DirectorySeparatorChar}") { GenericFilter = "*.vue"; + } + public override void Start(ProjectBuilder builder) { tsWatcher.Start(builder); + base.Start(builder); } public override void Stop() { base.Stop(); @@ -58,6 +63,7 @@ namespace BilibiliEvolved.Build.Watcher var minFile = $"min{Path.DirectorySeparatorChar + Path.GetFileName(e.FullPath)}.min.js"; var minifier = new JavascriptMinifier(); File.WriteAllText(minFile, minifier.Minify(compiledText.ToString())); + builder.UpdateCachedMinFile(minFile); cache.AddCache(e.FullPath); cache.SaveCache(); } @@ -118,8 +124,8 @@ namespace BilibiliEvolved.Build.Watcher else if (vueFile.ScriptLang == "ts" || vueFile.ScriptLang == "typescript") { var tsFile = path + ".ts"; + var task = tsWatcher.WaitForBuild(tsFile); File.WriteAllText(tsFile, vueFile.Script); - var task = tsWatcher.WaitForBuild(path); var script = task.Result.Replace("export default ", "return {export:Object.assign({template},").Trim().TrimEnd(';'); compiledText.Append($"{script})}}"); } diff --git a/builder/dotnet/Watcher/WatchBuilder.cs b/builder/dotnet/Watcher/WatchBuilder.cs index 9761d2ee5..3ae079fcc 100644 --- a/builder/dotnet/Watcher/WatchBuilder.cs +++ b/builder/dotnet/Watcher/WatchBuilder.cs @@ -85,15 +85,17 @@ namespace BilibiliEvolved.Build.Watcher { StopWatching(); }; - while (input.ToLowerInvariant() != "q") + while (input != null && input.ToLowerInvariant() != "q") { input = Console.ReadLine(); } - StopWatching(); + if (input != null) { + StopWatching(); + } } private void StopWatching() { - watchers.ForEach(w => w.Stop()); + watchers.Where(w => w.IsWatching).ForEach(w => w.Stop()); builder.WriteInfo("Watcher stopped."); Environment.Exit(0); } diff --git a/builder/dotnet/Watcher/Watcher.cs b/builder/dotnet/Watcher/Watcher.cs index 1b1a7b179..8f69893a1 100644 --- a/builder/dotnet/Watcher/Watcher.cs +++ b/builder/dotnet/Watcher/Watcher.cs @@ -92,13 +92,16 @@ namespace BilibiliEvolved.Build.Watcher // throw new ArgumentException($"The path is not relative to cwd. {nameof(fullPath)}={fullPath}, {nameof(cwd)}={cwd}", nameof(fullPath)); // } // } - public void Start(ProjectBuilder builder) + public virtual void Start(ProjectBuilder builder) { if (IsWatching) { return; } IsWatching = true; + if (builder is null) { + throw new NullReferenceException("Project Builder cannot be null"); + } this.builder = builder; if (watcher == null) { @@ -107,7 +110,7 @@ namespace BilibiliEvolved.Build.Watcher { builder.GetBundleFiles(); HandleFileChange(e); - builder.UpdateCachedMinFile(ResourceMinifier.GetMinimizedFileName(e.FullPath)); + // builder.UpdateCachedMinFile(ResourceMinifier.GetMinimizedFileName(e.FullPath)); ChangedFilesHistory.Add(e.FullPath); }, HandleFileChangesPeriod); FileSystemEventHandler handler = (s, e) => diff --git a/builder/dotnet/publish/build.dll b/builder/dotnet/publish/build.dll index fd7471b5f..58ec78ab1 100644 Binary files a/builder/dotnet/publish/build.dll and b/builder/dotnet/publish/build.dll differ