Merge pull request #457 from kojo12228/add-fsharp-support

Search for .csproj and .fsproj in init and add commands
This commit is contained in:
Gregor Biswanger
2020-08-14 12:44:45 +02:00
committed by GitHub
2 changed files with 24 additions and 18 deletions

View File

@@ -75,13 +75,16 @@ namespace ElectronNET.CLI.Commands
// ToDo: Not sure if this runs under linux/macos
ProcessHelper.CmdExecute(@"npx tsc -p ../../", targetFilePath);
// search .csproj
Console.WriteLine($"Search your .csproj to add configure CopyToPublishDirectory to 'Never'");
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();
// search .csproj or .fsproj (.csproj has higher precedence)
Console.WriteLine($"Search your .csproj/.fsproj to add configure CopyToPublishDirectory to 'Never'");
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
.Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
.FirstOrDefault();
Console.WriteLine($"Found your .csproj: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");
var extension = Path.GetExtension(projectFile);
Console.WriteLine($"Found your {extension}: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");
if (!EditCsProj(projectFile)) return false;
if (!EditProjectFile(projectFile)) return false;
Console.WriteLine($"Everything done - happy electronizing with your custom npm packages!");
@@ -90,7 +93,7 @@ namespace ElectronNET.CLI.Commands
}
// ToDo: Cleanup this copy/past code.
private static bool EditCsProj(string projectFile)
private static bool EditProjectFile(string projectFile)
{
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
@@ -128,7 +131,7 @@ namespace ElectronNET.CLI.Commands
}
Console.WriteLine($"Publish setting added in csproj!");
Console.WriteLine($"Publish setting added in csproj/fsproj!");
return true;
}

View File

@@ -70,19 +70,22 @@ namespace ElectronNET.CLI.Commands
// Deploy config file
EmbeddedFileHelper.DeployEmbeddedFileToTargetFile(currentDirectory, DefaultConfigFileName, ConfigName);
// search .csproj
Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();
// search .csproj/.fsproj (.csproj has higher precedence)
Console.WriteLine($"Search your .csproj/fsproj to add the needed {ConfigName}...");
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
.Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
.FirstOrDefault();
// update config file with the name of the csproj
// ToDo: If the csproj name != application name, this will fail
// update config file with the name of the csproj/fsproj
// ToDo: If the csproj/fsproj name != application name, this will fail
string text = File.ReadAllText(targetFilePath);
text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile));
File.WriteAllText(targetFilePath, text);
Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it.");
var extension = Path.GetExtension(projectFile);
Console.WriteLine($"Found your {extension}: {projectFile} - check for existing config or update it.");
if (!EditCsProj(projectFile)) return false;
if (!EditProjectFile(projectFile)) return false;
// search launchSettings.json
Console.WriteLine($"Search your .launchSettings to add our electron debug profile...");
@@ -158,7 +161,7 @@ namespace ElectronNET.CLI.Commands
}
}
private static bool EditCsProj(string projectFile)
private static bool EditProjectFile(string projectFile)
{
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
@@ -174,11 +177,11 @@ namespace ElectronNET.CLI.Commands
if (xmlDocument.ToString().Contains($"Content Update=\"{ConfigName}\""))
{
Console.WriteLine($"{ConfigName} already in csproj.");
Console.WriteLine($"{ConfigName} already in csproj/fsproj.");
return false;
}
Console.WriteLine($"{ConfigName} will be added to csproj.");
Console.WriteLine($"{ConfigName} will be added to csproj/fsproj.");
string itemGroupXmlString = "<ItemGroup>" +
"<Content Update=\"" + ConfigName + "\">" +
@@ -204,7 +207,7 @@ namespace ElectronNET.CLI.Commands
}
Console.WriteLine($"{ConfigName} added in csproj!");
Console.WriteLine($"{ConfigName} added in csproj/fsproj!");
return true;
}
}