This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 163
/
AzureHostSupport.cs
84 lines (73 loc) · 3.04 KB
/
AzureHostSupport.cs
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
using System.Collections.Generic;
using System.CommandLine;
using System.Composition;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using Pretzel.Logic.Commands;
using Pretzel.Logic.Extensions;
namespace Pretzel.Logic.Extensibility.Extensions
{
[Export]
[Shared]
[CommandArgumentsExtension(CommandTypes = new[] { typeof(RecipeCommand) })]
public class AzureHostSupportArguments : ICommandArgumentsExtension
{
public IList<Option> Options { get; } = new[]
{
new Option(new [] { "--azure", "-azure" }, "Enables deploy to azure support")
{
Argument = new Argument<bool>()
}
};
public void BindingCompleted()
{
//Not used
}
public bool Azure { get; set; }
}
[Export(typeof(IAdditionalIngredient))]
public class AzureHostSupport : IAdditionalIngredient
{
private readonly IFileSystem fileSystem;
private readonly IAssembly assembly;
[Import]
public AzureHostSupportArguments Arguments { get; set; }
[ImportingConstructor]
public AzureHostSupport(IFileSystem fileSystem, IAssembly assembly)
{
this.fileSystem = fileSystem;
this.assembly = assembly;
}
public void MixIn(string directory)
{
if (!Arguments.Azure) return;
// Move everything under the _source folder
var sourceFolder = Path.Combine(directory, "_source");
if (!fileSystem.Directory.Exists(sourceFolder))
{
fileSystem.Directory.CreateDirectory(sourceFolder);
}
foreach (var file in fileSystem.Directory.GetFiles(directory))
{
var trimStart = file.Replace(directory, string.Empty).TrimStart(Path.DirectorySeparatorChar);
fileSystem.File.Move(file, Path.Combine(sourceFolder, trimStart));
}
foreach (var directoryToMove in fileSystem.Directory.GetDirectories(directory).Where(n => new DirectoryInfo(n).Name != "_source"))
{
var trimStart = directoryToMove.Replace(directory, string.Empty).TrimStart(Path.DirectorySeparatorChar);
fileSystem.Directory.Move(directoryToMove, Path.Combine(sourceFolder, trimStart));
}
fileSystem.File.WriteAllText(Path.Combine(directory, @"Shim.cs"), Properties.RazorAzure.Shim);
fileSystem.File.WriteAllText(Path.Combine(directory, @"Shim.csproj"), Properties.RazorAzure.ShimProject);
fileSystem.File.WriteAllText(Path.Combine(directory, @"Shim.sln"), Properties.RazorAzure.ShimSolution);
var currentPath = assembly.GetEntryAssemblyLocation();
var destination = Path.Combine(directory, "Pretzel.exe");
if (!fileSystem.File.Exists(destination))
{
fileSystem.File.Copy(currentPath, destination);
}
Tracing.Info("Shim project added to allow deployment to azure websites");
}
}
}