mirror of https://github.com/dotnet/tye.git
committed by
GitHub
15 changed files with 258 additions and 48 deletions
@ -0,0 +1,39 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System.IO; |
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public class ConfigFileFinder |
||||
|
{ |
||||
|
private static readonly string[] FileFormats = new[] { "tye.yaml", "tye.yml", "*.csproj", "*.fsproj", "*.sln" }; |
||||
|
|
||||
|
public static bool TryFindSupportedFile(string directoryPath, out string? filePath, out string? errorMessage) |
||||
|
{ |
||||
|
foreach (var format in FileFormats) |
||||
|
{ |
||||
|
var files = Directory.GetFiles(directoryPath, format); |
||||
|
|
||||
|
if (files.Length == 1) |
||||
|
{ |
||||
|
errorMessage = null; |
||||
|
filePath = files[0]; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
if (files.Length > 1) |
||||
|
{ |
||||
|
errorMessage = $"More than one matching file was found in directory '{directoryPath}'."; |
||||
|
filePath = default; |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
errorMessage = $"No project project file or solution was found in directory '{directoryPath}'."; |
||||
|
filePath = default; |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
public class GitDetector |
||||
|
{ |
||||
|
public static GitDetector Instance { get; } = new GitDetector(); |
||||
|
|
||||
|
private GitDetector() |
||||
|
{ |
||||
|
IsGitInstalled = new Lazy<Task<bool>>(GetIsGitInstalled); |
||||
|
} |
||||
|
|
||||
|
public Lazy<Task<bool>> IsGitInstalled { get; } |
||||
|
|
||||
|
private async Task<bool> GetIsGitInstalled() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
var result = await ProcessUtil.RunAsync("git", "--version", throwOnError: false); |
||||
|
return result.ExitCode == 0; |
||||
|
} |
||||
|
catch (Exception) |
||||
|
{ |
||||
|
// Unfortunately, process throws
|
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
// See the LICENSE file in the project root for more information.
|
||||
|
|
||||
|
using System.IO; |
||||
|
|
||||
|
namespace Microsoft.Tye |
||||
|
{ |
||||
|
internal static class DirectoryExtensions |
||||
|
{ |
||||
|
// Calling Directory.Delete causes an exception for .git folders:
|
||||
|
// System.UnauthorizedAccessException : Access to the path '17a475ecca365c678e907bd4c73e4c65b341c6' is denied.
|
||||
|
public static void DeleteDirectory(string d) |
||||
|
{ |
||||
|
foreach (var sub in Directory.EnumerateDirectories(d)) |
||||
|
{ |
||||
|
DeleteDirectory(sub); |
||||
|
} |
||||
|
foreach (var f in Directory.EnumerateFiles(d)) |
||||
|
{ |
||||
|
var fi = new FileInfo(f); |
||||
|
fi.Attributes = FileAttributes.Normal; |
||||
|
fi.Delete(); |
||||
|
} |
||||
|
Directory.Delete(d); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue