Skip to content

Commit

Permalink
Added Xamarin Forms Shell template
Browse files Browse the repository at this point in the history
  • Loading branch information
pergerch committed May 14, 2020
1 parent 04a9659 commit 87f841f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 35 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Spatial Focus initialize project wizard

[![Nuget](https://img.shields.io/nuget/v/SpatialFocus.FocusInit)](https://www.nuget.org/packages/SpatialFocus.FocusInit/)

## Install the dotnet tool

```
dotnet tool install --global SpatialFocus.FocusInit --version 0.1.1
dotnet tool install --global SpatialFocus.FocusInit --version 0.2.0
```

Install the tool globally. You can invoke the tool using the following command: `focus-init`
Expand Down
Binary file added docs/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/FocusInit/DotnetCliHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public void AddReferenceToProject(string projectPath, string referenceProjectPat
process.WaitForExit(3000);
}

public string CreateMultiProject(string type)
{
string srcFolder = !string.IsNullOrEmpty(WorkDir) ? WorkDir + "/src" : "src";

string createProjectCmd = $"new {type} -n {SolutionName} -o {srcFolder}";
Process process = Process.Start("dotnet", createProjectCmd);

process.WaitForExit(3000);

return $"{srcFolder}/{SolutionName}";
}

public string CreateProject(string type, string projectSuffix)
{
string srcFolder = !string.IsNullOrEmpty(WorkDir) ? WorkDir + "/src" : "src";
Expand All @@ -47,5 +59,13 @@ public string CreateProject(string type, string projectSuffix)

return $"{srcFolder}/{SolutionName}.{projectSuffix}";
}

public void InstallCustomProjectTemplate(string type)
{
string installTemplateCmd = $"new -i {type}";
Process process = Process.Start("dotnet", installTemplateCmd);

process.WaitForExit(3000);
}
}
}
45 changes: 25 additions & 20 deletions src/FocusInit/FocusInit.csproj
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>

<PackAsTool>true</PackAsTool>
<ToolCommandName>focus-init</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackAsTool>true</PackAsTool>
<ToolCommandName>focus-init</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>

<Version>0.1.1</Version>
<Version>0.2.0</Version>
<PackageId>SpatialFocus.FocusInit</PackageId>
<Title>Spatial Focus initialize project wizard</Title>
<Description>DotNet Tool for initializing an empty folder, create a solution with stylecop, ReSharper and license settings, and optionally add projects.</Description>
<PackageTags>tool, scaffolding, code-style, code-quality</PackageTags>
<PackageProjectUrl>https://github.com/SpatialFocus/SpatialFocus.FocusInit</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/SpatialFocus/FocusInit</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/SpatialFocus/SpatialFocus.FocusInit.git</RepositoryUrl>
<RepositoryUrl>https://github.com/SpatialFocus/FocusInit.git</RepositoryUrl>
<Authors>pergerch,Dresel</Authors>
<Company>SpatialFocus</Company>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
</PropertyGroup>

<ItemGroup>
<Compile Remove="nupkg\**" />
<EmbeddedResource Remove="nupkg\**" />
<None Remove="nupkg\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="nupkg\**" />
<EmbeddedResource Remove="nupkg\**" />
<None Remove="nupkg\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0034" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<None Include="docs\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0034" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
</ItemGroup>

</Project>
37 changes: 23 additions & 14 deletions src/FocusInit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,58 @@ private static void CreateProjects(string solutionName)
Console.WriteLine(" 2) Empty web");
Console.WriteLine(" 3) Web API");
Console.WriteLine(" 4) Web MVC");
Console.WriteLine(" 5) Xamarin Forms Shell (coming soon)");
Console.WriteLine(" 5) Xamarin Forms Shell");
Console.WriteLine(" 6) Blazor Server");
Console.WriteLine(" 7) Blazor Wasm");
i = Prompt.GetInt("Select project type", null, ConsoleColor.DarkCyan);
}
while (i <= 0 || i > 7);

List<string> createdProjects = new List<string>();
List<string> projectsToReference = new List<string>();

switch (i)
{
case 1:
string consoleProject = cliHelper.CreateProject("console", "Console");
cliHelper.AddProjectToSolution(consoleProject);
createdProjects.Add(consoleProject);
projectsToReference.Add(consoleProject);
break;
case 2:
string emptyWebProject = cliHelper.CreateProject("web", "Web");
cliHelper.AddProjectToSolution(emptyWebProject);
createdProjects.Add(emptyWebProject);
projectsToReference.Add(emptyWebProject);
break;
case 3:
string webApiProject = cliHelper.CreateProject("webapi", "Web");
cliHelper.AddProjectToSolution(webApiProject);
createdProjects.Add(webApiProject);
projectsToReference.Add(webApiProject);
break;
case 4:
string mvcProject = cliHelper.CreateProject("mvc", "Web");
cliHelper.AddProjectToSolution(mvcProject);
createdProjects.Add(mvcProject);
projectsToReference.Add(mvcProject);
break;
case 5:
// TODO
return;
// Make sure the Xamarin Forms Shell template is installed
cliHelper.InstallCustomProjectTemplate("SpatialFocus.DotNetNew.XamarinFormsShell::0.1.2");

string xfShellProject = cliHelper.CreateMultiProject("focus-xfshell");

cliHelper.AddProjectToSolution(xfShellProject);
cliHelper.AddProjectToSolution($"{xfShellProject}.Android");
cliHelper.AddProjectToSolution($"{xfShellProject}.iOS");

projectsToReference.Add(xfShellProject);
break;
case 6:
string blazorProject = cliHelper.CreateProject("blazorserver", "Blazor");
cliHelper.AddProjectToSolution(blazorProject);
createdProjects.Add(blazorProject);
projectsToReference.Add(blazorProject);
break;
case 7:
string wasmProject = cliHelper.CreateProject("blazorwasm", "Blazor");
cliHelper.AddProjectToSolution(wasmProject);
createdProjects.Add(wasmProject);
projectsToReference.Add(wasmProject);
break;
}

Expand All @@ -116,12 +125,12 @@ private static void CreateProjects(string solutionName)

cliHelper.AddProjectToSolution(businessProject);

foreach (string project in createdProjects)
foreach (string project in projectsToReference)
{
cliHelper.AddReferenceToProject(project, businessProject);
}

createdProjects.Add(businessProject);
projectsToReference.Add(businessProject);
}

if (Prompt.GetYesNo("Create shared project?", false, ConsoleColor.DarkCyan))
Expand All @@ -130,7 +139,7 @@ private static void CreateProjects(string solutionName)

cliHelper.AddProjectToSolution(sharedProject);

foreach (string project in createdProjects)
foreach (string project in projectsToReference)
{
cliHelper.AddReferenceToProject(project, sharedProject);
}
Expand All @@ -142,7 +151,7 @@ private static void CreateProjects(string solutionName)

cliHelper.AddProjectToSolution(testProject);

foreach (string project in createdProjects)
foreach (string project in projectsToReference)
{
cliHelper.AddReferenceToProject(testProject, project);
}
Expand Down

0 comments on commit 87f841f

Please sign in to comment.