-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from christianhelle/download-nswag
Download NSwag CLI on-demand
- Loading branch information
Showing
13 changed files
with
131 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Core.Generators; | ||
|
||
namespace ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Core | ||
{ | ||
public static class NpmHelper | ||
{ | ||
public static string GetNpmPath() | ||
{ | ||
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); | ||
var programFiles64 = programFiles.Replace(" (x86)", newValue: String.Empty); | ||
|
||
var npmCommand = Path.Combine(programFiles, "nodejs\\npm.cmd"); | ||
if (File.Exists(npmCommand)) | ||
return npmCommand; | ||
|
||
npmCommand = Path.Combine(programFiles64, "nodejs\\npm.cmd"); | ||
if (!File.Exists(npmCommand)) | ||
throw new InvalidOperationException("Unable to find NPM. Please install Node.js"); | ||
|
||
return npmCommand; | ||
} | ||
|
||
public static string GetPrefixPath() | ||
=> TryGetNpmPrefixPathFromNpmConfig() ?? | ||
Path.Combine( | ||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), | ||
"npm"); | ||
|
||
private static string TryGetNpmPrefixPathFromNpmConfig() | ||
{ | ||
try | ||
{ | ||
var npm = GetNpmPath(); | ||
string prefix = null; | ||
new ProcessLauncher().Start( | ||
npm, | ||
"config get prefix", | ||
o => prefix += o, | ||
e => Trace.WriteLine(e)); | ||
return prefix; | ||
} | ||
catch (Exception e) | ||
{ | ||
Trace.TraceError(e.ToString()); | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.IO; | ||
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Core; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Tests | ||
{ | ||
[TestClass] | ||
public class NpmHelperTests | ||
{ | ||
[TestMethod] | ||
public void Can_GetNpmPath() | ||
=> NpmHelper.GetNpmPath() | ||
.Should() | ||
.NotBeNullOrWhiteSpace(); | ||
|
||
[TestMethod] | ||
public void FileExists_GetNpmPath() | ||
=> File.Exists(NpmHelper.GetNpmPath()) | ||
.Should() | ||
.BeTrue(); | ||
|
||
[TestMethod] | ||
public void Can_GetNpmPrefixPath() | ||
=> NpmHelper.GetPrefixPath() | ||
.Should() | ||
.NotBeNullOrWhiteSpace(); | ||
|
||
[TestMethod] | ||
public void DirectoryExists_GetNpmPrefixPath() | ||
=> Directory.Exists(NpmHelper.GetPrefixPath()) | ||
.Should() | ||
.BeTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/ApiClientCodeGen.VSIX/Windows/GeneralOptionsPageCustom.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters