Justin Kotalik
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
36 additions and
3 deletions
-
activate.ps1
-
src/Microsoft.Tye.Core/ConfigFileFinder.cs
-
src/tye/InitHost.cs
-
test/E2ETest/TyeInitTests.cs
|
|
|
@ -13,7 +13,7 @@ if ($MyInvocation.CommandOrigin -eq 'runspace') { |
|
|
|
|
|
|
|
function dtye() { |
|
|
|
$ProjectPath = Join-Path (Join-Path $PSScriptRoot "src") "tye" |
|
|
|
dotnet run --project "$ProjectPath" @args |
|
|
|
dotnet run --project "$ProjectPath" -- @args |
|
|
|
} |
|
|
|
|
|
|
|
function deactivate ([switch]$init) { |
|
|
|
|
|
|
|
@ -10,9 +10,10 @@ namespace Microsoft.Tye |
|
|
|
{ |
|
|
|
private static readonly string[] FileFormats = { "tye.yaml", "tye.yml", "docker-compose.yaml", "docker-compose.yml", "*.csproj", "*.fsproj", "*.sln" }; |
|
|
|
|
|
|
|
public static bool TryFindSupportedFile(string directoryPath, out string? filePath, out string? errorMessage) |
|
|
|
public static bool TryFindSupportedFile(string directoryPath, out string? filePath, out string? errorMessage, string[]? fileFormats = null) |
|
|
|
{ |
|
|
|
foreach (var format in FileFormats) |
|
|
|
fileFormats ??= FileFormats; |
|
|
|
foreach (var format in fileFormats) |
|
|
|
{ |
|
|
|
var files = Directory.GetFiles(directoryPath, format); |
|
|
|
|
|
|
|
|
|
|
|
@ -23,6 +23,23 @@ namespace Microsoft.Tye |
|
|
|
ThrowIfTyeFilePresent(path, "tye.yaml"); |
|
|
|
} |
|
|
|
|
|
|
|
if (force) |
|
|
|
{ |
|
|
|
// Don't use existing tye.yaml if we are force creating it again.
|
|
|
|
// path prior is pointing to the tye.yaml file still, so refind another file that isn't the tye.yaml
|
|
|
|
var hasViableFileType = ConfigFileFinder.TryFindSupportedFile(path?.DirectoryName ?? ".", |
|
|
|
out var filePath, |
|
|
|
out var errorMessage, |
|
|
|
new string[] { "*.csproj", "*.fsproj", "*.sln" }); |
|
|
|
|
|
|
|
if (!hasViableFileType) |
|
|
|
{ |
|
|
|
throw new CommandException(errorMessage!); |
|
|
|
} |
|
|
|
|
|
|
|
path = new FileInfo(filePath); |
|
|
|
} |
|
|
|
|
|
|
|
var template = @"
|
|
|
|
# tye application configuration file |
|
|
|
# read all about it at https://github.com/dotnet/tye
|
|
|
|
|
|
|
|
@ -89,5 +89,20 @@ namespace E2ETest |
|
|
|
|
|
|
|
YamlAssert.Equals(expectedContent, content); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Tye_Init_Force_Works() |
|
|
|
{ |
|
|
|
using var projectDirectory = CopyTestProjectDirectory("single-project"); |
|
|
|
var tyePath = Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"); |
|
|
|
var text = File.ReadAllText(tyePath); |
|
|
|
File.WriteAllText(tyePath, text + "thisisatest"); |
|
|
|
|
|
|
|
var projectFile = new FileInfo(tyePath); |
|
|
|
|
|
|
|
var (content, _) = InitHost.CreateTyeFileContent(projectFile, force: true); |
|
|
|
|
|
|
|
Assert.DoesNotContain("thisisatest", content); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|