Script -- output ports with no code files; replace !...Any with None

This commit is contained in:
Zev Spitz
2022-01-17 23:09:30 +02:00
parent 2d44db49a4
commit 06e1ca2ffc
2 changed files with 21 additions and 6 deletions

View File

@@ -10,6 +10,11 @@ public static class Extensions {
src.Select(x => selector(x.Item1, x.Item2, x.Item3));
public static IEnumerable<(T1, T2, int)> WithIndex<T1, T2>(this IEnumerable<(T1, T2)> src) => src.Select((x, index) => (x.Item1, x.Item2, index));
public static bool None<T>(this IEnumerable<T> src, Func<T, bool>? predicate = null) =>
predicate is null ?
!src.Any() :
!src.Any(predicate);
public static bool IsNullOrWhitespace([NotNullWhen(false)] this string? s) => string.IsNullOrWhiteSpace(s);
[return: NotNullIfNotNull("path")]

View File

@@ -17,6 +17,7 @@ var actions = new (Action action, string description)[] {
(multipleProjs, "Output multiple project files"),
(checkProjects, "Check .csproj/.vbproj files for target framework, nullability etc."),
(checkExecutableProject, "Check that there is at least one executable project per port"),
(noCodeFiles, "Output ports without any code files"),
(printPortInfo, "Print info about a single port"),
(generateMissingSlns, "Generate solution files when missing"),
@@ -87,7 +88,7 @@ void printInfos() {
}
void missingSln() {
var data = infos.Where(x => !x.Slns.Any()).ToArray();
var data = infos.Where(x => x.Slns.None()).ToArray();
foreach (var item in data) {
WriteLine(item.LangPath);
}
@@ -98,7 +99,7 @@ void missingSln() {
void unexpectedSlnName() {
var counter = 0;
foreach (var item in infos) {
if (!item.Slns.Any()) { continue; }
if (item.Slns.None()) { continue; }
var expectedSlnName = $"{item.GameName}.sln";
if (item.Slns.Contains(Combine(item.LangPath, expectedSlnName), StringComparer.InvariantCultureIgnoreCase)) { continue; }
@@ -125,7 +126,7 @@ void multipleSlns() {
}
void missingProj() {
var data = infos.Where(x => !x.Projs.Any()).ToArray();
var data = infos.Where(x => x.Projs.None()).ToArray();
foreach (var item in data) {
WriteLine(item.LangPath);
}
@@ -136,7 +137,7 @@ void missingProj() {
void unexpectedProjName() {
var counter = 0;
foreach (var item in infos) {
if (!item.Projs.Any()) { continue; }
if (item.Projs.None()) { continue; }
var expectedProjName = $"{item.GameName}.{item.ProjExt}";
if (item.Projs.Contains(Combine(item.LangPath, expectedProjName))) { continue; }
@@ -164,7 +165,7 @@ void multipleProjs() {
}
void generateMissingSlns() {
foreach (var item in infos.Where(x => !x.Slns.Any())) {
foreach (var item in infos.Where(x => x.Slns.None())) {
var result = RunProcess("dotnet", $"new sln -n {item.GameName} -o {item.LangPath}");
WriteLine(result);
@@ -177,7 +178,7 @@ void generateMissingSlns() {
}
void generateMissingProjs() {
foreach (var item in infos.Where(x => !x.Projs.Any())) {
foreach (var item in infos.Where(x => x.Projs.None())) {
// We can't use the dotnet command to create a new project using the built-in console template, because part of that template
// is a Program.cs / Program.vb file. If there already are code files, there's no need to add a new empty one; and
// if there's already such a file, it might try to overwrite it.
@@ -284,6 +285,15 @@ void checkExecutableProject() {
}
}
void noCodeFiles() {
var qry = infos
.Where(x => x.CodeFiles.None())
.OrderBy(x => x.Lang);
foreach (var item in qry) {
WriteLine(item.LangPath);
}
}
void tryBuild() {
// if has code files, try to build
}