Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed Nov 19, 2019
1 parent 847a033 commit 801c6f4
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions EhDbReleaseBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace EhDbReleaseBuilder
{
class Program
{
public static async Task Main(string[] args)
public static void Main(string[] args)
{
Console.WriteLine($@"EhDbReleaseBuilder started.
Source: {args[0]}
Target: {args[1]}
");
var client = new GitHubApiClient(args[0], args[1]);
client.Normalize();
await client.Publish();
client.Publish();
}
}

Expand Down Expand Up @@ -75,18 +75,18 @@ public void Normalize()
_Database.Save();
}

public async Task Publish()
public void Publish()
{
foreach (var item in Directory.CreateDirectory(_Target).GetFiles())
{
item.Delete();
}

await _PublishOne("full");
await _PublishOne("html");
await _PublishOne("raw");
await _PublishOne("text");
await _PublishOne("ast");
_PublishOne("full");
_PublishOne("html");
_PublishOne("raw");
_PublishOne("text");
_PublishOne("ast");

var message = $"{_RepoClient.Head.Sha}";
if (Environment.GetEnvironmentVariable("GITHUB_ACTION") != null)
Expand All @@ -96,7 +96,7 @@ public async Task Publish()
}
}

private async Task _PublishOne(string mid)
private void _PublishOne(string mid)
{
var fulldata = _Serialize(mid);
var byteData = _Encoding.GetBytes(fulldata);
Expand Down Expand Up @@ -150,54 +150,54 @@ private void _WriteFile(byte[] jsonData, string pre, string mid, string suf)
switch (suf)
{
case "json":
using (var json = File.OpenWrite(Path.Combine(_Target, $"{pre}.{mid}.json")))
{
json.Write(jsonData);
json.Flush();
Console.WriteLine($"Created: {pre}.{mid}.json ({json.Position} bytes)");
return;
}
{
using var json = File.OpenWrite(Path.Combine(_Target, $"{pre}.{mid}.json"));
json.Write(jsonData);
json.Flush();
Console.WriteLine($"Created: {pre}.{mid}.json ({json.Position} bytes)");
return;
}
case "json.gz":
using (var gziped = File.OpenWrite(Path.Combine(_Target, $"{pre}.{mid}.json.gz")))
using (var gzip = new GZipStream(gziped, CompressionLevel.Optimal, true))
{
using var gziped = File.OpenWrite(Path.Combine(_Target, $"{pre}.{mid}.json.gz"));
using var gzip = new GZipStream(gziped, CompressionLevel.Optimal, true);
gzip.Write(jsonData);
gzip.Flush();
gziped.Flush();
Console.WriteLine($"Created: {pre}.{mid}.json.gz ({gziped.Position} bytes)");
return;
}
case "js":
{
using var jsonp = File.OpenWrite(Path.Combine(_Target, $"{pre}.{mid}.js"));
if (pre == "diff")
{
gzip.Write(jsonData);
gzip.Flush();
gziped.Flush();
Console.WriteLine($"Created: {pre}.{mid}.json.gz ({gziped.Position} bytes)");
return;
jsonp.Write(_Encoding.GetBytes($"load_ehtagtranslation_{pre}_{mid}("));
jsonp.Write(jsonData);
jsonp.Write(_Encoding.GetBytes(");"));
}
case "js":
using (var jsonp = File.OpenWrite(Path.Combine(_Target, $"{pre}.{mid}.js")))
else
{
if (pre == "diff")
jsonp.Write(_Encoding.GetBytes($"(function(){{var d={{c:'load_ehtagtranslation_{pre}_{mid}',d:'"));
using (var gziped = new MemoryStream())
using (var gzip = new GZipStream(gziped, CompressionLevel.Optimal, true))
{
jsonp.Write(_Encoding.GetBytes($"load_ehtagtranslation_{pre}_{mid}("));
jsonp.Write(jsonData);
jsonp.Write(_Encoding.GetBytes(");"));
gzip.Write(jsonData);
gzip.Flush();
gziped.Flush();
jsonp.Write(_Encoding.GetBytes(Convert.ToBase64String(gziped.GetBuffer(), 0, (int)gziped.Length, Base64FormattingOptions.None)));
}
else
jsonp.Write(_Encoding.GetBytes($"'}};"));
using (var pako = Assembly.GetExecutingAssembly().GetManifestResourceStream("EhDbReleaseBuilder.pako.min.js"))
{
jsonp.Write(_Encoding.GetBytes($"(function(){{var d={{c:'load_ehtagtranslation_{pre}_{mid}',d:'"));
using (var gziped = new MemoryStream())
using (var gzip = new GZipStream(gziped, CompressionLevel.Optimal, true))
{
gzip.Write(jsonData);
gzip.Flush();
gziped.Flush();
jsonp.Write(_Encoding.GetBytes(Convert.ToBase64String(gziped.GetBuffer(), 0, (int)gziped.Length, Base64FormattingOptions.None)));
}
jsonp.Write(_Encoding.GetBytes($"'}};"));
using (var pako = Assembly.GetExecutingAssembly().GetManifestResourceStream("EhDbReleaseBuilder.pako.min.js"))
{
pako.CopyTo(jsonp);
}
jsonp.Write(_Encoding.GetBytes("})();"));
pako.CopyTo(jsonp);
}
jsonp.Flush();
Console.WriteLine($"Created: {pre}.{mid}.js ({jsonp.Position} bytes)");
return;
jsonp.Write(_Encoding.GetBytes("})();"));
}
jsonp.Flush();
Console.WriteLine($"Created: {pre}.{mid}.js ({jsonp.Position} bytes)");
return;
}
default:
throw new ArgumentException("Unsupported suffix.");
}
Expand Down

0 comments on commit 801c6f4

Please sign in to comment.