Provides helper methods for compiling the genrated projects and copying the needed files for a package to an output directory
| 20 | { |
| 21 | // Provides helper methods for compiling the genrated projects and copying the needed files for a package to an output directory |
| 22 | public class NodeRTProjectBuildUtils |
| 23 | { |
| 24 | private const string NODE_GYP_CMD_TEMPLATE = "\"cd \"{0}\" & npm install --ignore-scripts & node-gyp rebuild --msvs_version={1}\""; |
| 25 | |
| 26 | // Builds the given project/sln for the given platforms and copies the output & package file to the output directory |
| 27 | public static void BuildWithNodeGyp(string moduleDirectory, VsVersions vsVersion, bool verbose = false) |
| 28 | { |
| 29 | BuildModule(moduleDirectory, vsVersion, verbose); |
| 30 | } |
| 31 | |
| 32 | private static string CreateBuildCmd(string moduleDirectory, VsVersions vsVersion) |
| 33 | { |
| 34 | string versionString; |
| 35 | |
| 36 | switch (vsVersion) |
| 37 | { |
| 38 | case VsVersions.Vs2012: |
| 39 | versionString = "2012"; |
| 40 | break; |
| 41 | case VsVersions.Vs2013: |
| 42 | versionString = "2013"; |
| 43 | break; |
| 44 | case VsVersions.Vs2015: |
| 45 | versionString = "2015"; |
| 46 | break; |
| 47 | case VsVersions.Vs2017: |
| 48 | versionString = "2017"; |
| 49 | break; |
| 50 | default: |
| 51 | throw new Exception("Unknown VS Version"); |
| 52 | } |
| 53 | return String.Format(NODE_GYP_CMD_TEMPLATE, moduleDirectory, versionString); |
| 54 | } |
| 55 | |
| 56 | private static void BuildModule(string moduleDirectory, VsVersions vsVersion, bool verbose) |
| 57 | { |
| 58 | string cmd = CreateBuildCmd(moduleDirectory, vsVersion); |
| 59 | bool result = ExecuteCommand(cmd, verbose); |
| 60 | |
| 61 | if (!result) |
| 62 | throw new Exception("Failed to build project"); |
| 63 | } |
| 64 | |
| 65 | private static bool ExecuteCommand(string cmd, bool verbose) |
| 66 | { |
| 67 | Process process = new Process(); |
| 68 | process.StartInfo.FileName = "cmd.exe"; |
| 69 | process.StartInfo.Arguments = "/c " + cmd; |
| 70 | process.StartInfo.CreateNoWindow = true; |
| 71 | process.StartInfo.UseShellExecute = false; |
| 72 | process.StartInfo.LoadUserProfile = true; |
| 73 | |
| 74 | if (process.StartInfo.EnvironmentVariables.ContainsKey("VisualStudioDir")) |
| 75 | process.StartInfo.EnvironmentVariables.Remove("VisualStudioDir"); |
| 76 | if (process.StartInfo.EnvironmentVariables.ContainsKey("VisualStudioEdition")) |
| 77 | process.StartInfo.EnvironmentVariables.Remove("VisualStudioEdition"); |
| 78 | if (process.StartInfo.EnvironmentVariables.ContainsKey("VisualStudioVersion")) |
| 79 | process.StartInfo.EnvironmentVariables.Remove("VisualStudioVersion"); |
nothing calls this directly
no outgoing calls
no test coverage detected