Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ElectronNET.CLI/Commands/AddCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ public Task<bool> ExecuteAsync()
// 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!");

Expand All @@ -90,7 +93,7 @@ public Task<bool> ExecuteAsync()
}

// 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))
{
Expand Down Expand Up @@ -128,7 +131,7 @@ private static bool EditCsProj(string projectFile)

}

Console.WriteLine($"Publish setting added in csproj!");
Console.WriteLine($"Publish setting added in csproj/fsproj!");
return true;
}

Expand Down
27 changes: 15 additions & 12 deletions ElectronNET.CLI/Commands/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,22 @@ public Task<bool> ExecuteAsync()
// 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();

// update config file with the name of the csproj
// ToDo: If the csproj name != application name, this will fail
// 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/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...");
Expand Down Expand Up @@ -158,7 +161,7 @@ private static void EditLaunchSettings(string currentDirectory)
}
}

private static bool EditCsProj(string projectFile)
private static bool EditProjectFile(string projectFile)
{
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
Expand All @@ -174,11 +177,11 @@ private static bool EditCsProj(string projectFile)

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 + "\">" +
Expand All @@ -204,7 +207,7 @@ private static bool EditCsProj(string projectFile)

}

Console.WriteLine($"{ConfigName} added in csproj!");
Console.WriteLine($"{ConfigName} added in csproj/fsproj!");
return true;
}
}
Expand Down