mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Fix bugs
This commit is contained in:
parent
b4637b411a
commit
195be800eb
@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BilibiliEvolved.Build
|
||||
{
|
||||
@ -14,5 +18,21 @@ namespace BilibiliEvolved.Build
|
||||
action(item);
|
||||
}
|
||||
}
|
||||
public static Action Debounce(Action action, int waitTime)
|
||||
{
|
||||
var queue = new ConcurrentQueue<Action>();
|
||||
return async () =>
|
||||
{
|
||||
queue.Enqueue(action);
|
||||
await Task.Delay(waitTime);
|
||||
if (queue.TryDequeue(out var a))
|
||||
{
|
||||
if (queue.Count == 0)
|
||||
{
|
||||
a?.Invoke();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,20 +71,20 @@ namespace BilibiliEvolved.Build
|
||||
}
|
||||
private void buildFile(string path)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var offlineFileText = File.ReadAllText(path);
|
||||
// if (File.Exists(path))
|
||||
// {
|
||||
// var offlineFileText = File.ReadAllText(path);
|
||||
|
||||
var noVersion = new Regex(@"// @version[ ]*(.*)" + Environment.NewLine);
|
||||
var originalOffline = noVersion.Replace(offlineFileText, "");
|
||||
var currentOffline = noVersion.Replace(offlineText, "");
|
||||
// var noVersion = new Regex(@"// @version[ ]*(.*)" + Environment.NewLine);
|
||||
// var originalOffline = noVersion.Replace(offlineFileText, "");
|
||||
// var currentOffline = noVersion.Replace(offlineText, "");
|
||||
|
||||
if (currentOffline == originalOffline)
|
||||
{
|
||||
offlineVersion = noVersion.Match(offlineFileText).Groups[1].Value.Trim();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if (currentOffline == originalOffline)
|
||||
// {
|
||||
// offlineVersion = noVersion.Match(offlineFileText).Groups[1].Value.Trim();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
File.WriteAllText(path, offlineText);
|
||||
}
|
||||
|
||||
@ -33,11 +33,22 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
return !cache.Contains(originalFile);
|
||||
};
|
||||
}
|
||||
public override void Stop()
|
||||
private void KillExternalWatcher() {
|
||||
if (!externalWatcherProcess.HasExited)
|
||||
{
|
||||
externalWatcherProcess.Kill();
|
||||
}
|
||||
}
|
||||
public override void Stop()
|
||||
{
|
||||
KillExternalWatcher();
|
||||
base.Stop();
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
KillExternalWatcher();
|
||||
base.Dispose();
|
||||
}
|
||||
protected override sealed void OnFileChanged(FileSystemEventArgs e)
|
||||
{
|
||||
var originalFile = GetOriginalFilePath(e.FullPath);
|
||||
|
||||
@ -9,7 +9,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BilibiliEvolved.Build.Watcher
|
||||
{
|
||||
public class WatchBuilder {
|
||||
public class WatchBuilder
|
||||
{
|
||||
private List<Watcher> watchers = new List<Watcher>{
|
||||
new ClientWatcher(),
|
||||
new JavaScriptWatcher(),
|
||||
@ -20,23 +21,41 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
new VueWatcher(),
|
||||
};
|
||||
private ProjectBuilder builder = ProjectBuilder.CreateBuilder();
|
||||
public void StartWatching() {
|
||||
public void StartWatching()
|
||||
{
|
||||
builder
|
||||
.BuildClient()
|
||||
.BuildVersions()
|
||||
.BuildMaster();
|
||||
watchers.ForEach(w => w.Start(builder));
|
||||
var rebuild = Extensions.Debounce(() =>
|
||||
{
|
||||
builder
|
||||
.BuildBundle()
|
||||
.BuildPreviewOffline()
|
||||
.BuildOffline()
|
||||
.BuildPreviewData()
|
||||
.BuildFinalOutput();
|
||||
}, 200);
|
||||
watchers.ForEach(w =>
|
||||
{
|
||||
w.Start(builder);
|
||||
w.FileChanged += e => rebuild();
|
||||
w.FileDeleted += e => rebuild();
|
||||
});
|
||||
builder.WriteInfo("Watcher started, input 'q' or press 'Ctrl + C' to exit.");
|
||||
var input = "";
|
||||
Console.CancelKeyPress += (s, e) => {
|
||||
Console.CancelKeyPress += (s, e) =>
|
||||
{
|
||||
StopWatching();
|
||||
};
|
||||
while (input.ToLowerInvariant() != "q") {
|
||||
while (input.ToLowerInvariant() != "q")
|
||||
{
|
||||
input = Console.ReadLine();
|
||||
}
|
||||
StopWatching();
|
||||
}
|
||||
private void StopWatching() {
|
||||
private void StopWatching()
|
||||
{
|
||||
watchers.ForEach(w => w.Stop());
|
||||
builder.WriteInfo("Watcher stopped.");
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
public string GenericFilter { get; set; } = "";
|
||||
public Predicate<string> FileFilter { get; set; } = s => true;
|
||||
public ConcurrentBag<string> ChangedFilesHistory { get; } = new ConcurrentBag<string>();
|
||||
public event Action<FileSystemEventArgs> FileChanged;
|
||||
public event Action<FileSystemEventArgs> FileDeleted;
|
||||
protected abstract void OnFileChanged(FileSystemEventArgs e);
|
||||
protected virtual void OnFileDeleted(FileSystemEventArgs e)
|
||||
{
|
||||
@ -27,10 +29,11 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
{
|
||||
File.Delete(minimizedFilename);
|
||||
}
|
||||
builder
|
||||
.GetBundleFiles()
|
||||
.BuildBundle();
|
||||
RebuildOutputs();
|
||||
builder.GetBundleFiles();
|
||||
// builder
|
||||
// .GetBundleFiles()
|
||||
// .BuildBundle();
|
||||
// RebuildOutputs();
|
||||
}
|
||||
// protected void RebuildBundle()
|
||||
// {
|
||||
@ -53,7 +56,7 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
private bool started = false;
|
||||
// https://github.com/dotnet/corefx/issues/25117
|
||||
private ConcurrentBag<FileSystemEventArgs> changedFiles = new ConcurrentBag<FileSystemEventArgs>();
|
||||
private const int HandleFileChangesPeriod = 200;
|
||||
public const int HandleFileChangesPeriod = 200;
|
||||
private void HandleFileChange(FileSystemEventArgs e)
|
||||
{
|
||||
switch (e.ChangeType)
|
||||
@ -62,10 +65,12 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
case WatcherChangeTypes.Created:
|
||||
// Console.WriteLine($"OnChange {e.Name}");
|
||||
OnFileChanged(e);
|
||||
FileChanged?.Invoke(e);
|
||||
break;
|
||||
case WatcherChangeTypes.Deleted:
|
||||
// Console.WriteLine($"delete {e.Name} {e.ChangeType}");
|
||||
OnFileDeleted(e);
|
||||
FileDeleted?.Invoke(e);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -134,14 +139,16 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
distinctChanges.ForEach(e =>
|
||||
{
|
||||
HandleFileChange(e);
|
||||
builder.UpdateCachedMinFile(e.FullPath);
|
||||
ChangedFilesHistory.Add(e.FullPath);
|
||||
});
|
||||
changedFiles.Clear();
|
||||
builder.BuildBundle();
|
||||
RebuildOutputs();
|
||||
// builder.BuildBundle();
|
||||
// RebuildOutputs();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
public virtual void Stop()
|
||||
{
|
||||
@ -149,7 +156,7 @@ namespace BilibiliEvolved.Build.Watcher
|
||||
started = false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public virtual void Dispose()
|
||||
{
|
||||
cache?.Dispose();
|
||||
watcher?.Dispose();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user