-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProgram.cs
More file actions
190 lines (175 loc) · 5.92 KB
/
Program.cs
File metadata and controls
190 lines (175 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//var t = Task.FromResult(2);
//var x = new TaskWithData<string, int>("asd", t);
//var a = await x;
//if (a.res == 2)
//{
// Console.WriteLine("asdasd");
// return;
//}
//var t = Task.FromResult(2);
//var x = new TaskWithData<string, int>("asd", t);
//var y = new TaskWithData<string, int>("asd1", Task.FromResult(7));
//var x1=await x;
////var y1=await y;
//var a = await Task.WhenAll(x.GetTask(), y.GetTask());
//if (x1.res == 2)
//{
// Console.WriteLine("asdasd");
// return;
//}
try
{
string originalFolder = @"C:\ignatandrei\rscg_Examples";
if (!Directory.Exists(originalFolder))
{
originalFolder = @"D:\gth\RSCG_Examples";
}
if (!Directory.Exists(originalFolder))
{
originalFolder = @"D:\eu\GitHub\RSCG_Examples";
}
if (!Directory.Exists(originalFolder))
{
throw new DirectoryNotFoundException($"Cannot find the folder {originalFolder}. Please set the correct path to the RSCG_Examples folder.");
}
DbRSCGContext db =new (originalFolder);
var noExamples = db.NoExamples.ToArray();
var examplesRec = db.Examples.ToArray();
if(examplesRec.Length == 0 )
{
throw new InvalidOperationException($"No examples found in the database {originalFolder}. Please ensure that the database is populated with example data.");
}
//var genEx= GeneratorDataRec
// .Data()
// .Select(it =>
// {
// it.Value.ID = it.Key;
// return it.Value;
// })
// .ToArray();
////db.Examples.AddRange(genEx);
////db.SaveChanges();
//var x = 0;
//if (x == 0) return;
Console.WriteLine("New generator?(press enter for none in 5 seconds)");
//var newGen = Console.ReadLine();
var task = Task.Factory.StartNew(Console.ReadLine);
var completedTask = await Task.WhenAny(task, Task.Delay(TimeSpan.FromSeconds(15)));
var newGen = object.ReferenceEquals(task, completedTask) ? task.Result : string.Empty;
if (!string.IsNullOrWhiteSpace(newGen))
{
var f = Path.Combine(originalFolder, "v2");
var staticWeb= Path.Combine(f, "rscg_examples_site", "static");
//await File.WriteAllTextAsync(Path.Combine(staticWeb, "pdfs", $"{newGen}.pdf"), "");
await File.WriteAllTextAsync(Path.Combine(staticWeb, "sources", $"{newGen}.zip"), "");
var examples = Path.Combine(f, "rscg_examples", newGen);
Directory.CreateDirectory(examples);
Directory.CreateDirectory(Path.Combine(examples,"src"));
var images = Path.Combine(f, "book", "examples", "images", newGen);
if(!Directory.Exists(images)) { Directory.CreateDirectory(images); }
await File.WriteAllTextAsync(Path.Combine(examples,"description.json"),
$$"""
{
"generator":{
"name":"{{newGen}}",
"nuget":[
"https://www.nuget.org/packages/{{newGen}}/"
],
"link":"",
"author":"",
"source":""
},
"data":{
"goodFor":[""],
"csprojDemo":"{{newGen}}Demo.csproj",
"csFiles":["Program.cs"],
"excludeDirectoryGenerated":[""],
"includeAdditionalFiles":[""]
},
"links":{
"blog":"",
"video":""
}
}
""");
return;
}
Console.WriteLine("generating data");
MultiGenerator? old = new MultiGenerator(Path.Combine(originalFolder,"v1"));
var oldDesc = await old.AllDescriptions();
//maybe find the old ones if there are new
ArgumentNullException.ThrowIfNull(oldDesc);
oldDesc = oldDesc
.Where(it=>it !=null)
.Select((desc, i) =>
{
if(desc != null) desc.Nr = i;
return desc;
}).ToArray();
//await old.OpenFindIIncremental();
//var text = a
// .Select((desc, i) =>
// {
// if(desc==null)
// return string.Empty;
// var bookmark = desc.Generator.Name.ToLower();
// bookmark = bookmark.Replace(" + ", "--");
// bookmark = bookmark.Replace(" ", "-");
// return $"|{i + 1}| [{desc.Generator.Name}]({desc.Generator.Nuget.First()}) | [v1]( https://ignatandrei.github.io/RSCG_Examples/v1/#rscg-number-{i+1}--{bookmark}) |";
// })
// .Where(it=>it!=null)
// .ToArray();
//var c=string.Join(Environment.NewLine, text);
//if (a.Length>0)
// return;
string folder = Path.Combine(originalFolder,"v2");
var m = new MultiGeneratorV2(folder, noExamples,examplesRec);
//await m.OpenFindIIncremental();
var sources = await m.GatherData();
var all = sources!.Union(m.SourceNoRSCG()).ToArray();
for (int i = 0; i < all.Length; i++)
{
var item = all[i];
if(item.EndsWith("/"))
{
all[i] = item.Substring(0, item.Length - 1);
}
}
var text=string.Join(Environment.NewLine, all);
await m.WriteAllIntoFile("all.csv");
await m.WriteVideo();
await m.WriteCodeTour();
await m.GrabDescriptionFromNuget();
await m.GrabReadMe();
long nr = await m.GenerateMSFT();
Console.WriteLine("RSCG used by MSFT :" + nr);
var lastGenerator = "Blazor.TSRuntime";
await m.WrotePost(lastGenerator);
await m.WroteDocusaurusAll(lastGenerator);
await m.WriteFrontReadMe(oldDesc);
//int x = 1;
//if (x == 1)
// throw new ArgumentException("test");
Console.WriteLine("npm run build");
Console.WriteLine("npm run serve");
Console.WriteLine("Zip, image, html, pdf : y/n");
if (Console.ReadLine() == "y")
{
//await m.WrotePost();
await m.CreateZip();
await m.CreateImageFiles();
await m.CreateHTMLBook();
await m.WrotePDFs();
}
//var m = new MultiGenerator(folder);
//await m.GeneratePost();
//await m.GenerateReadMeForEach();
//await m.GenerateFrontReadMe();
//await m.GenerateForImages(Path.Combine(folder, "docs", "images"));
//await m.GenerateForEmail();
}
catch (Exception ex)
{
Console.WriteLine("!!!!" + ex.Message);
Console.WriteLine("!!!!" + ex.StackTrace);
}